【问题标题】:How to draw Zoomable Sunburst with angular directive?如何使用角度指令绘制可缩放的森伯斯特?
【发布时间】:2015-12-10 13:16:03
【问题描述】:

我是 d3.js 的新手,谁能指导我绘制可缩放的旭日形。

提前致谢!

【问题讨论】:

    标签: angularjs d3.js


    【解决方案1】:

    您可能想查看D3 gallery of examples,特别是可缩放的旭日形: http://bl.ocks.org/mbostock/4348373

    他们示例中的代码:

    <!DOCTYPE html>
    <meta charset="utf-8">
    <style>
    
    path {
      stroke: #fff;
      fill-rule: evenodd;
    }
    
    </style>
    <body>
    <script src="//d3js.org/d3.v3.min.js"></script>
    <script>
    
    var width = 960,
        height = 700,
        radius = Math.min(width, height) / 2;
    
    var x = d3.scale.linear()
        .range([0, 2 * Math.PI]);
    
    var y = d3.scale.sqrt()
        .range([0, radius]);
    
    var color = d3.scale.category20c();
    
    var svg = d3.select("body").append("svg")
        .attr("width", width)
        .attr("height", height)
      .append("g")
        .attr("transform", "translate(" + width / 2 + "," + (height / 2 + 10) + ")");
    
    var partition = d3.layout.partition()
        .value(function(d) { return d.size; });
    
    var arc = d3.svg.arc()
        .startAngle(function(d) { return Math.max(0, Math.min(2 * Math.PI, x(d.x))); })
        .endAngle(function(d) { return Math.max(0, Math.min(2 * Math.PI, x(d.x + d.dx))); })
        .innerRadius(function(d) { return Math.max(0, y(d.y)); })
        .outerRadius(function(d) { return Math.max(0, y(d.y + d.dy)); });
    
    d3.json("/mbostock/raw/4063550/flare.json", function(error, root) {
      if (error) throw error;
    
      var path = svg.selectAll("path")
          .data(partition.nodes(root))
        .enter().append("path")
          .attr("d", arc)
          .style("fill", function(d) { return color((d.children ? d : d.parent).name); })
          .on("click", click);
    
      function click(d) {
        path.transition()
          .duration(750)
          .attrTween("d", arcTween(d));
      }
    });
    
    d3.select(self.frameElement).style("height", height + "px");
    
    // Interpolate the scales!
    function arcTween(d) {
      var xd = d3.interpolate(x.domain(), [d.x, d.x + d.dx]),
          yd = d3.interpolate(y.domain(), [d.y, 1]),
          yr = d3.interpolate(y.range(), [d.y ? 20 : 0, radius]);
      return function(d, i) {
        return i
            ? function(t) { return arc(d); }
            : function(t) { x.domain(xd(t)); y.domain(yd(t)).range(yr(t)); return arc(d); };
      };
    }
    
    </script>
    

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-01-27
    • 1970-01-01
    • 2015-02-27
    • 1970-01-01
    • 1970-01-01
    • 2015-03-05
    相关资源
    最近更新 更多