【发布时间】:2018-07-12 22:03:02
【问题描述】:
我有一条由用户使用 D3.js 绘制的路径。
我想在我的用户绘制的路径上定义一个 dasharray,但是,当它改变它的形状和长度时,dash 的行为不一致,并且间隙正在移动并变得更小。
这是一个代码笔:
https://codepen.io/Richacinas/pen/YjXpBE
随意fork..绘制用户路径的函数就是这个:
DrawItGraph.prototype.draw = function() {
...
var pos = this.d3.mouse(event.target)
if (pos[1] > this.chartHeight) return
var date = this.clamp(this.middleValue + 2629743, this.maxValue, this.convection.x.invert(pos[0]))
var value = this.clamp(0, this.convection.y.domain()[1], this.convection.y.invert(pos[1]))
this.userData.forEach(function (d) {
if (Math.round(Math.abs(d.date - date) / 60000000) < 50) {
d.value = value
d.defined = true
}
})
this.yourDataSel.at({d: this.line.defined(this.format('defined'))(this.userData)})
if (this.d3.mean(this.userData, this.format('defined')) === 1) {
this.graphCompleted = true
}
}
我怀疑我必须根据路径长度动态更改 stroke-dashoffset 和/或 stroke-dasharray,但是,我不知道正确的公式是什么...
非常感谢
【问题讨论】:
标签: javascript d3.js svg