Daniel Chepenko
Daniel Chepenko

Reputation: 2268

d3.js create same svg object with different data

I have a script, that works fine and create a chord diagram I need. But now I want to create the same .svg file on another div but with different matrix. Should I duplicate the same script for a new svg, or I can do in more efficient way?

You can find my code here.

Now my .Js script use drawChordWithMatrix(matrix_T1_T2) to show chord on div with id chart What should I do to run drawChordWithMatrix(matrix_T2_T3) on id chart1

Upvotes: 1

Views: 585

Answers (1)

Cyril Cherian
Cyril Cherian

Reputation: 32327

One way i can think is

1) Move the SVG creation into the drawChordWithMatrix

So you need to pass the id to which you need to attach the SVG. something like this function drawChordWithMatrix(matrix, id), and you create your SVG in the function like this.

var svg = d3.select(id).append("svg")//selecting on basis of ID.
            .attr("width", (width + margin.left + margin.right))
            .attr("height", (height + margin.top + margin.bottom));

2) Next move all functions like fade, fadeOnChord , etc.. into the drawChordWithMatrix so that they all have the same scope.

working code here

Upvotes: 3

Related Questions