以下代碼從數據生成路徑。我已經在d3.js中定義了一條路徑,它繪製正確,但.getTotalLength()未定義
var path = gameBoard.append('path')
.attr("id", "snake" + snakeIndex)
.attr("d", interpolator(data))
.attr('stroke-width', snakeStroke)
.attr('fill', 'none')
.attr('stroke', config.snakeColor);
數據定義的曲線路徑正確繪製。
這裏失敗getTotalLength()沒有被定義:
var totalLength = path.getTotalLength();
此外沒有定義getPointAlongLength()或者:
var point = path.getPointAtLength(position);
我完全同意你,如果你刪除了v3的味道,因爲沒有跡象表明實際使用的版本。 *'路徑'是D3選擇*應該足夠v3和v4。此外,'path.node()'是並且是獲取節點的首選方法,無需擺弄選擇的內部工作。 – altocumulus