I am working with Angular 2 D3 v4 and trying to add a zoom feature to a force layout map
import * as d3 from 'd3';
import * as d3Force from 'd3-force';
import * as d3Shape from 'd3-shape';
import * as d3Zoom from 'd3-zoom';
import { D3ZoomEvent } from 'd3-zoom';
import * as d3Drag from 'd3-drag';
import {D3DragEvent} from 'd3-drag';
import * as d3Selection from 'd3-selection';
this.svg = this.host.select("svg > g");
this.svg = this.host.append("svg")
.attr("width", this.width)
.attr("height", this.height)
.append("g");
this.defs = this.host.select("svg").append("defs");
this.svg.append("g").attr("class", "links");
this.svg.append("g").attr("class", "nodes");
this.svg.call(d3Zoom.zoom().on("zoom", this.zoomed));
zoomed() {
var evt:d3Zoom.D3ZoomEvent<any, any> = d3.event as d3Zoom.D3ZoomEvent<any, any>;
var tr = evt.transform;
this.svg.attr("transform", tr);
this.svg.selectAll("text").attr("transform", "scale(" + 1/tr.k + ")");
this.svg.selectAll("path").style("stroke-width", 2/tr.k);
this.svg.selectAll("circle").style("stroke-width", 2/tr.k);
}
Just adding this line causes an error at runtime related to "button"
Here is the error
TypeError: Cannot read property 'button' of null
------------- Elapsed: 13088 ms; At: Thu Jan 12 2017 15:09:33 GMT-0800 (PST) -------------
I am unable to resolve this. Any help, please?