【发布时间】:2015-01-03 19:19:43
【问题描述】:
我觉得我在这里要疯了。我一直盯着看,一定是漏掉了一些明显的东西。
我希望弯曲的路径是蓝色的,而单词下面的直线路径是红色的。
我注意到我总是设置描边宽度、描边和填充,所以我做了一个辅助方法
lineColor = (color, node) ->
node
.attr 'stroke', color
.attr 'stroke-width', 2
.attr 'fill', 'none'
然后画出这样的路径
#curvy
lineColor 'blue', svg
.append 'path'
.attr 'd', line indentations
像这样
#underline
lineColor 'red', svg
.append 'path'
.attr 'd', usageLine usageCol
你会认为第一行是蓝色,第二行是红色,但它们都是红色(或最后使用的任何颜色)!
我不明白,这里没有延迟执行,如果我将 stroke 命令放在函数之外的每个节点上,它就可以工作。
我错过了什么?
编辑: Here's the same thing without the helper function - everything's working great.
【问题讨论】:
-
@muistooshort 我也是这么想的,但是颜色变量会在它被调用时绑定。那只是javascript。我不确定,但我认为 d3 将元素写入为
append被调用并依赖浏览器优化来不破坏布局
标签: d3.js coffeescript