我正在使用 D3.js 绘制 svg 线。我想通过在添加到线路径之前删除重复的 (x,y) 点来提高性能。在 D3 或 javascript 中执行此操作的最佳方法是什么。我正在从 json 文件加载数据,用于此测试,但稍后它可能会出现在服务器上的数组中。
请参阅下面的代码片段和控制台输出。
谢谢你的帮助
var x = d3.scale.linear().domain([xMin, xMax]).rangeRound([0, width]);
var y = d3.scale.linear().domain([yMin, yMax]).rangeRound([height, 0]);
var line = d3.svg.line()
.x(function(d, i) {
var xPoint = x((i + 1) * xMult);
console.log("xPoint= " + xPoint.toString());
return xPoint; })
.y(function(d) {
var yPoint = y(d);
console.log("yPoint= " + yPoint.toString());
return yPoint; })
.interpolate("basis-open")
.tension(0);
...
// Add the valueline path.
g.append("path")
.attr("class", "line")
.attr("d", line(data));
--------------------------------------------------
Console Output from two lines in code above
console.log("xPoint= " + xPoint.toString());
console.log("yPoint= " + yPoint.toString());
----------------------------------------------
xPoint= 0
yPoint= 24
xPoint= 0
yPoint= 24
xPoint= 1
yPoint= 24
xPoint= 1
yPoint= 24
xPoint= 1
yPoint= 24
xPoint= 1
yPoint= 24
xPoint= 2
yPoint= 24
xPoint= 2
yPoint= 25
xPoint= 2
yPoint= 25
xPoint= 2
yPoint= 24
xPoint= 3
yPoint= 25
xPoint= 3
yPoint= 25
xPoint= 3
yPoint= 25
xPoint= 3
yPoint= 25
xPoint= 4
yPoint= 25