我有一个脚本,工作正常并创建我需要的和弦图。
但是现在我想在另一个.svg
上创建相同的div
文件但是使用不同的矩阵。
我是否应该为新的svg复制相同的脚本,或者我可以更有效地执行此操作?
您可以找到我的代码here。
现在我的.Js
脚本使用drawChordWithMatrix(matrix_T1_T2)
在id chart
上显示div的和弦
如何在drawChordWithMatrix(matrix_T2_T3)
id chart1
答案 0 :(得分:3)
我能想到的一种方式是
1)将SVG创建移动到drawChordWithMatrix
所以你需要传递你需要附加SVG的id。
像这样的function drawChordWithMatrix(matrix, id)
,你可以像这样在函数中创建你的SVG。
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)接下来将fade,fadeOnChord等所有函数移动到drawChordWithMatrix
中,使它们都具有相同的范围。
工作代码here