d3.js

How to get a path centroid d3

断了今生、忘了曾经 提交于 2020-12-05 12:05:53
问题 I cant use the .centroid() method because its returns [NaN,Nan]. I dont know what is the right data format. var pathh = d3.geo.path(); d3.selectAll("path.line") .each(function (d, i) { var centroid = pathh.centroid(d); console.log('Centroid at: ', d,+ centroid[0] + ', ' + centroid[1]); }); My data format is: One object is one point(vertex) of the polygon 0: Object area_id: "IVP001" vertex_id: "37451" x: "100" y: "100" 1: Object area_id: "IVP001" vertex_id: "37452" x: "150" y: "120" 2: Object

Set initial d3 zoom based on boundary dynamically - V4

主宰稳场 提交于 2020-12-01 07:27:07
问题 I have a large number of nodes to display on the page, most of the times the circles goes off the visible area of the screen due to node placements. Is there a way to set the initial zoom level based on the whole boundary box of nodes dynamically so that all the nodes fits on the visible area of the screen? Updated: I have added a fiddle for this https://jsfiddle.net/navinleon/6ygaxoyq/3/ var svg = d3.select("svg"), width = +svg.attr("width"), height = +svg.attr("height"); var zoom = d3.zoom(

Set initial d3 zoom based on boundary dynamically - V4

删除回忆录丶 提交于 2020-12-01 07:26:13
问题 I have a large number of nodes to display on the page, most of the times the circles goes off the visible area of the screen due to node placements. Is there a way to set the initial zoom level based on the whole boundary box of nodes dynamically so that all the nodes fits on the visible area of the screen? Updated: I have added a fiddle for this https://jsfiddle.net/navinleon/6ygaxoyq/3/ var svg = d3.select("svg"), width = +svg.attr("width"), height = +svg.attr("height"); var zoom = d3.zoom(