我想从官方文档中应用"常规更新模式"来更新鼠标事件的svg路径(但可以是按钮或其他).
但路径只是添加而不是更新.我认为这就是为什么我没有正确使用enter和exit属性,但经过一些不同的试验,我无法让它工作.
这是一个jsfiddle.
我的js代码在这里:
var shapeCoords = [
[10, 10], [100, 10], [100, 100], [10, 100]
];
$(function() {
var container = $('#container');
// D3
console.log("D3: ", d3);
var svg = d3.select('#container')
.append('svg:svg')
.attr('height', 600)
.attr('width', 800);
var line = d3.svg.line()
.x(function(d) { return d[0]; })
.y(function(d) { return d[1]; })
.interpolate('linear');
function render() {
svg.data(shapeCoords)
.append('svg:path')
.attr('d', line(shapeCoords) + 'Z')
.style('stroke-width', 1)
.style('stroke', 'steelblue');
}
render();
var mouseIsDown = false;
container.on('mousedown …Run Code Online (Sandbox Code Playgroud)