d3v4-径向图-重构和增强

时间:2020-06-02 03:33:27

标签: javascript d3.js

enter image description here

我正在基于https://bl.ocks.org/alandunning/4c36eb1abdb248de34c64f5672afd857-

改进此径向图

我已经创建了这两个版本-但想集成一些数据源

  • options对象感到多余,因为这些项目可能来自HTML片段本身作为数据属性。
  • cfg-感觉也很多余,并且正在干扰来自数据属性(例如宽度/高度)的变量-其中一些是动态计算的(例如弧度)。

我也很奇怪如何将数据复制为变量d-然后对原始数据对象本身执行此过程-是否需要进行变量的克隆-图表的其余部分不能使用新修改的数据变量?

        d.forEach(function(y, x){
          dataValues = [];
          radial.selectAll(".nodes")
          .data(y, function(j, i){
            dataValues.push([
            cfg.w/2*(1-(parseFloat(Math.max(j.value, 0))/cfg.maxValue)*cfg.factor*Math.sin(i*cfg.radians/total)), 
            cfg.h/2*(1-(parseFloat(Math.max(j.value, 0))/cfg.maxValue)*cfg.factor*Math.cos(i*cfg.radians/total))
            ]);
          });

          dataValues.push(dataValues[0]);

//版本1 https://jsfiddle.net/z47c06u8/

//版本2-具有工具提示和y轴 https://jsfiddle.net/er8pwj95/1/

0 个答案:

没有答案