d3.js

Add event listener of a method present in another js file

久未见 提交于 2020-02-02 15:00:08
问题 I am accessing few methods written in another js file. So i'm accessing them like this: file1: function minit() { this.addval = function(val1, val2) { return val1 + val2; } function autoexecute(d) { //do something here// //raise event// } }; file2: var con = new minit(); var result = con.addval(2, 3); /* con.autoexecute(function(d) { //Wanna do something like this alert(d); }); */ Above things are working as expected, getting result.. Now, Suppose autoexecute(d) method is invoking

Animate path (line) from last known point to new added point (d3)

﹥>﹥吖頭↗ 提交于 2020-02-02 13:45:26
问题 I'm still learning to program and I'm currently trying out the d3 library. So far I'm pretty happy with the result. fiddle Q: If you check out the link (or part of the code under this question) you should try to plot a point. This is only possible on the x-axis ticks. You'll see it animates but it's not exactly what I want. I just want it to animate the newly added line. I have checked out .enter() and .append() but I was getting errors. I might be doing something wrong. function lines(x, y)

Scale a circle's radius (given in meters) to D3.js d3.geo.mercator map

拥有回忆 提交于 2020-02-02 11:50:56
问题 I am using D3.js and TopoJSON libraries to render a flat SVG map of the world in a small div on a web page. I'm also taking some geographic objects (polygons and circles), and plotting them on this map via lat/long coordinates. This all seems to be working pretty well, however, the circle objects that I am plotting on the map contain a radius element which is given in meters. I cannot find or figure out how to convert/scale this measurement appropriately onto the SVG map. Any help would be

D3 v4 Brush and Zoom on the same element (without mouse events conflicting)

痞子三分冷 提交于 2020-02-01 17:42:40
问题 My goal is to build a D3 (v4) chart that uses both d3-zoom and d3-brush together, as follows: When the mouse is positioned over the x-axis, the user can zoom (with the mouse wheel) or pan (by dragging left and right) When the mouse is positioned over the y-axis, the user can zoom (with the mouse wheel) or pan (by dragging up and down) When the mouse is positioned over the chart body, the user can zoom (with the mouse wheel) or brush to set the x domain to a specific range I have managed to

D3 v4 Brush and Zoom on the same element (without mouse events conflicting)

落爺英雄遲暮 提交于 2020-02-01 17:42:05
问题 My goal is to build a D3 (v4) chart that uses both d3-zoom and d3-brush together, as follows: When the mouse is positioned over the x-axis, the user can zoom (with the mouse wheel) or pan (by dragging left and right) When the mouse is positioned over the y-axis, the user can zoom (with the mouse wheel) or pan (by dragging up and down) When the mouse is positioned over the chart body, the user can zoom (with the mouse wheel) or brush to set the x domain to a specific range I have managed to

Angular 2 typescript d3 type issue: Property 'x' does not exist on type '[number, number]'

蓝咒 提交于 2020-02-01 16:10:11
问题 I am generating a line chart with d3. It works, but typescript code complain about a property not exists in vs. Property 'x' does not exist on type '[number, number]' Looking at the error. It seems like the data point expected is an array with two numbers. But I am passing in an object. D3 should support both I think. Does anyone know how to get rid of this error without changing my data? 回答1: Here is the solution. I need to use generics: 回答2: As said, it's a TypeScript interpretation issue.

Move d3 circles away from center circle - force layout

心已入冬 提交于 2020-02-01 07:26:28
问题 I'm working on d3 to represent nodes in circles, when the size of a circle is changed then the circles around them should move away from the one's size got changed from being overlapped. Consider the red circle above, when its size get changed then the others should move in the green arrow's direction. I tried with force simulation but I'm not able to achieve it and added the code below, I'm not sure what I'm doing wrong, can somebody help please? https://jsfiddle.net/m6s8dk7o/29/ var w = 900

Move d3 circles away from center circle - force layout

柔情痞子 提交于 2020-02-01 07:26:25
问题 I'm working on d3 to represent nodes in circles, when the size of a circle is changed then the circles around them should move away from the one's size got changed from being overlapped. Consider the red circle above, when its size get changed then the others should move in the green arrow's direction. I tried with force simulation but I'm not able to achieve it and added the code below, I'm not sure what I'm doing wrong, can somebody help please? https://jsfiddle.net/m6s8dk7o/29/ var w = 900

How to make a dashed line legend with d3.js

喜欢而已 提交于 2020-01-31 18:14:31
问题 I usually make a line legend by appending a rect giving it a very small height so that it looks like a line. But now I need a dashed line legend. I am not able to do it by my old way. Can anyone show me a quick example of how to make a line legend with append('path') with d3.js? 回答1: You can make it like this with a line DOM: var legend = svg.selectAll(".legend") .data(ageNames.slice().reverse())//data set for legends .enter().append("g") .attr("class", "legend") .attr("transform", function(d

Get distance along polyline from lat/lng point

一个人想着一个人 提交于 2020-01-30 13:18:11
问题 I'm rendering a polyline on a Google map with data that looks like this: data = [ { distance: 3.45, lat: 37.37112776376307, lng: -122.13909476995468, }, ... ]; When hovering over the polyline, I can get the lat / lng coordinates and I want to get the distance along the line based on those coordinates. I haven't found an easy way to do this with the Maps API. I want the distance from the start to an arbitrary point along the polyline ; most answers I've found deal simply with the (shortest)