Transitioning innerRadius of svg.arc - D3.js - javascript

I have a question, that is closely related to this one.
As opposed to the example, I also need to transition the innerRadius of the sunburst, hence the innerRadius property of the d3.svg.arc(). I know it has to be done in a similar fashion with respect to the transition of the "d" (with attrTween by storing the old innerRadius) but I didn't managed to do it.
Any suggestion? A code snippet would be great!

When you say "sunburst", do you mean a multi-colored Pie, where all the arcs are different? If so, the example "Multiple D3 Pie Charts Mixed In With Common HTML Layout Constructs" transitions the inner radius while drawing the pie (just search for the word transition in the code).
Another option is to look at this "Sunburst Coffee Flavor Wheel" example, which is more complex but shows how to transition multiple arcs, simultaneously.
I hope it helps.
Frank

Related

D3.js Arc Diagram - Tapered Ends

I have an arc diagram that is based on this blocks example, and I'd like to taper the ends of the arc path so that they are hidden behind the circles (or at least aren't wider than the circles themselves).
I have two thoughts and I'm not sure how feasible either of them are: a) modify d3.arc source code so that the resultant svg path has tapered ends, or b) instead of using d3.arc to generate the path, create my own cubic bezier function that takes in the x and y points of the source and target nodes and outputs a a curve that tapers to maybe half of its full width? Both of which I've never done before and would be floundering a bit trying to do.
Any tips, tricks, ideas, or general well wishes would be greatly appreciated.

Draw links to a d3 circle pack layout

I need to be able to draw links between the circles in a circle pack layout, like {source: i, target: j}. I've seen some questions about how to combine this layout with the force layout that made me think It could be a way to achieve this but I haven't had any luck on that path, also what I need is something completely static. Thank you in advance for any suggestions.
I finally could draw lines between nodes by appending them to the svg and calculating each line position based on the radius of the nodes that each line were to connect, but the problem was that the pack layout that I'm using is zoomable, so when I tried to zoom by clicking the lines neither translate nor re-sized (of course, since there was no code performing such things), so I tried to implement a translation function for the lines so they would move along with the zoom, then I saw that it would take some serious geometry to achieve this, so since I'm a lazy programmer and not at all experienced with d3 I tried to come with something more simple... at last I decided to represent the links between the nodes with a different approach (without lines), I used the "mouseover" event so when the pointer is over a node it will highlight (changed circle stroke attribute color and width) the nodes connected to it. This way I achieved my goal and the view looks a lot cleaner without all the lines crossing over it (they were a lot). I know that some may think that this does not answer the original question, and I'm sure that this can be achieved by someone with more experience (and time and patience) using lines and implementing the right calculation, but in my case this solution solves my problem and maybe it could be of help to others.

D3js - Smooth transition between 2 paths

I am 2 very different path and I'd like to smoothly change one to make it look like the other one. I have tried using the .transition() method applied on the "d" attribute but it gives very poor results.
Here is an example:
http://jsfiddle.net/yya0m0s0/1/
The d3 code I used is the following:
var svg = d3.select("body")
.append('svg')
.attr('width', '375px')
.attr('height', '490px');
svg.append('path').attr('d', d_t0);
svg.selectAll('path').transition()
.duration(3500).delay(1000)
.attr('d', d);
What is the best way to create the kind of transformations?
Many thanks
The problem here is that your first path only has 10 segments, and your second has 42 segments. The paths are so different that transitioning between them using the built-in path tweening is impossible.
D3 does a good job of tweening two paths that are similar in structure (same number of segments, and the same types of segments). Things start to get messier the more different the structures are.
Consider this example.
The first two path data d_1 and d_2 have the same number and type of segments, only the endpoints change. The transition between these is seamless.
The second two path data d_3 and d_4 have the same number of segments, but the final segment is a different type (line in d_3, quadratic curve in d_4). The transition is fine for all the points up to the last point, but then the final segment shows the same sort of jumpiness that you experienced in your example. This is because a quadratic curve requires a control-point, which must materialize out of thin air when the transition begins, causing the jump.
The bad news is that the only way around this problem is to create a custom tween function for your path data attribute. The good news is that this is a common issue and smart people have come up with solid solutions.
HERE is a good path tween function that Mike Bostock created.
When implemented on your example it gives a fairly smooth result: JSFiddle
Hope that helps.

D3JS - animate a circle along an svg path at a constant speed

I'd like to move a circle along a path using d3.js. I used the code from Mike Bostocks' website here:
http://bl.ocks.org/KoGor/8162640
I'd like to move my circle at a constant speed along the path and have it moving immediately after it has been added to my svg. I cannot see how to twist the code here to make it work.
Does anybody have an idea how to do this?
Best
You should just add a line
.ease("linear")
after .duration(7500), and you should be all set.
This is documentation on ease(), but you should read all that is related to transitions, while you ate at it...
Here is also a test example for various possibilities related to ease():

Cheese diagram in d3.js

How would you implement this with d3.js:
I started with sunburst diagram, but how to handle pics around circle? How to rotate them? etc. (assume each cheese has its png pic)
To add images, you can use the SVG image tag. The elements added in this way can be translated and rotated in the usual manner. The code you're going to need is essentially the same as for a pie chart with rotated labels, for which you should be able to find plenty of examples.
Here's a quick and dirty modified pie chart example that demonstrates the technique.

Categories