【问题标题】:d3.geo.circle angle does not work?d3.geo.circle 角度不起作用?
【发布时间】:2014-09-23 05:43:38
【问题描述】:

所以,我尝试关注 Jason Davies 对Circle clip and projection with D3 orthographic 线程的回答...

我尝试了 3 种不同的可能性:

svg.append("g").attr("class","points")
  .selectAll("path")
    .data(places.features)
    .enter()
    .append("path")
    //THIS COMMENTED PART DOES NOT WORK
    //though the console spits out an array
    /*.datum(function(d){
         console.log(d.geometry.coordinates)
         return d3.geo.circle()
           .origin(d.geometry.coordinates)
           .angle(2)
    })*/

    //THIS UNCOMMENTED PART WORKS
    //and places the circles accordingly with a fixed size radius
    .datum(d3.geo.circle()
      .origin(function(d){return d.geometry.coordinates})
      .angle(2)
    )

    //THIS COMMENTED PART DOES NOT WORK
    //which is a shame, as my goal is to change the angle of each circle
    /*.datum(d3.geo.circle()
          .origin(function(d){return d.geometry.coordinates})
          .angle(function(d){return 2})
    )*/

    .attr("class", "point")
    .attr("d", path)

如何使最后评论的部分生效,以便更改圆的半径?非常感谢。

【问题讨论】:

  • 您能否详细说明它是如何不起作用的?任何错误信息?会发生什么,您预计会发生什么?
  • 它是如何不起作用的:圈子只是没有创建......第一个评论部分没有给我任何消息错误。第二个评论部分说:“Uncaught TypeError: Cannot read property '0' of undefined” 我只是想弄清楚为什么我不能在我的角度属性中放置一个返回函数。
  • 你需要一个function(d),就在.datum()之后,就像第一个评论部分一样。
  • 我知道了 .datum(function(d){ var origin = d.geometry.coordinates var angle = avions[d.properties.index].total_morts/100 return d3.geo.circle() .angle(angle).origin(origin)() } ) 这行得通!诀窍在最后的括号中。为什么会这样呢??
  • 哦,对了,没看到——d3.geo.circle() 是一个工厂函数(即返回函数的函数),您仍然需要调用它。

标签: d3.js


【解决方案1】:

更新到 d3 版本“5.7.0”后,我遇到了同样的问题。 已通过使用 geoCircle.center(center).radius(angle) 而不是 geo.circle().angle(angle) 修复。

Here 你可以找到它的工作原理。

【讨论】:

    猜你喜欢
    • 2013-08-01
    • 2017-03-06
    • 2015-05-26
    • 1970-01-01
    • 1970-01-01
    • 2018-07-16
    • 2014-06-26
    • 2017-06-22
    • 2016-11-24
    相关资源
    最近更新 更多