我想在d3做一些橡皮筋球 ,我觉得这很容易,因为我记得看到Jason Davies的例子 (顶部的第二个),但看起来它实际上更复杂。
贾森以垂直乐队为榜样的例子很直接:
let band = [2, -2].map((d, i) => { let stripe = d3.range(-180, 180).map((x) => [x, d]) stripe.push(stripe[0]) return i ? stripe.reverse() : stripe })所以我首先制作一个像这样的垂直乐队:
let band = [2, -2].map((d, i) => { let stripe = d3.range(-90, 90).map((y) => [d, y]) stripe.push(stripe[0]) return i ? stripe.reverse() : stripe })但是,相反,我得到了每个杆子上都会关闭的奇怪形状(它应该也是被填充的,而不是抚摸):
我的最终目标是简单地指定一个点,一个角度和一个宽度(在我的例子中为4),它将返回在全球范围内绘制一个带所需的坐标。
谢谢。
I'm trying to do some kind of rubber band ball in d3, I thought it was going to be easy because I remember seeing Jason Davies example (the 2nd one at the top) but it looks like it was more complex actually.
Jason's example for a vertical band is quite straightfoward:
let band = [2, -2].map((d, i) => { let stripe = d3.range(-180, 180).map((x) => [x, d]) stripe.push(stripe[0]) return i ? stripe.reverse() : stripe })So I starting by making a vertical band like this:
let band = [2, -2].map((d, i) => { let stripe = d3.range(-90, 90).map((y) => [d, y]) stripe.push(stripe[0]) return i ? stripe.reverse() : stripe })But instead, I get this weird shape that closes on each pole (it's supposed to be filled too, not stroked):
My end goal would be to simply specify a point, an angle and a width (4 in my example) and it would return the coordinates necessary to draw a band around the globe.
Thanks.
最满意答案
所以这是一个相当简单的问题,因为d3。 我用角度为90°(默认)和随机点的d3.geo.circle ,因此:
let circle = d3.geo.circle() .origin(coords)()由于d3.geo.circle返回一个多边形,我需要编辑它的属性:
circle.type = 'LineString' circle.coordinates = circle.coordinates[0]这是最终结果:
So it was a fairly simple problem because of d3. I used d3.geo.circle with an angle of 90° (default) and a random point, so:
let circle = d3.geo.circle() .origin(coords)()Since d3.geo.circle returns a polygon, I needed to edit it's properties:
circle.type = 'LineString' circle.coordinates = circle.coordinates[0]Here's the final result:
更多推荐
发布评论