D3 Differentiate between click and drag for an element which has a drag behavior

The key bit that’s missing is the check whether the default behaviour of an event has been prevented. That is, there’s a matching sibling to d3.event.preventDefault() — d3.event.defaultPrevented. You need to check this in your click handler to see whether any dragging action is going on. See also the answer to this question.

Add text label to d3 node in Force directed Graph and resize on hover

You are adding a text element inside a circle, that won’t work. You can add groups under the svg element and then append the circle and a text in each group: // Create the groups under svg var gnodes = svg.selectAll(‘g.gnode’) .data(graph.nodes) .enter() .append(‘g’) .classed(‘gnode’, true); // Add one circle in each group var node … Read more

d3.js: tickformat – adding a % sign without multiplying by 100

Update for D3 v4 (using ES6): // Can also be axisTop, axisRight, or axisBottom d3.axisLeft() .tickFormat(d => d + “%”) Original answer for D3 v3: You can create your own format: d3.svg.axis() .tickFormat(function(d) { return d + “%”; }); If you want to get rid of the decimal places: d3.svg.axis() .tickFormat(function(d) { return parseInt(d, 10) … Read more

Change the ticks on x-axis

The default ticks for quantitative scales are multiples of 2, 5 and 10. You appear to want multiples of 6; though unusual, this could make sense depending on the nature of the underlying data. So, while you can use axis.ticks to increase or decrease the tick count, it will always return multiples of 2, 5 … Read more

How/Where do I get geoJSON data for states, provinces, and administrative regions of non-US countries? [closed]

This process is now simplified (July 2014) compared to the steps I see in the accepted answer. It now seems much easier to get this data. I at first floundered around the web hoping I could just download a bunch of standard maps in GeoJSON format, but came up empty other than standard US/Canada offerings. … Read more

D3: How to refresh a chart with new data?

Create one function that (re)draws the pie when it’s created and when it’s updated. New data should be added to pie using enter() and old data should be removed using exit().remove() It is as simple as this: path.enter().append(“path”) .attr(“fill”, function(d, i) { return color(i); }) .attr(“d”, arc) .each(function(d) {this._current = d;} ); path.transition() .attrTween(“d”, arcTween); … Read more

Calculate width of text before drawing the text

I know you asked about D3, but this might be a native solution to your issue. The HTML5 canvas 2D context has some built-in functionality to measure text. You might be able to tap into that to measure text for other APIs like SVG. If it’s not 100% accurate, surely it’s proportional to the correct … Read more

How do I get the width of an svg element using d3js?

<svg class=”svg” height=”3300″ width=”2550″> <image x=”0″ y=”0″ height=”3300″ width=”2550″ xlink:href=”https://stackoverflow.com/questions/19710174/1.jpg”></image> <rect class=”word” id=”15″ x=”118″ y=”259″ width=”182″ height=”28″ text=”Substitute”></rect> </svg> <script> var body = d3.select(“body”); console.log(body); var svg = body.select(“svg”); console.log(svg); console.log(svg.style(“width”)); </script> Just place your script after svg element is loaded by the browser and all will be fine.

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)