"Bundle" interpolation for single-element arrays.

In future we may want to generate some kind of loop, but it's not clear
what orientation such a loop should have, so perhaps a "non-line" like
this is better as a default.
This commit is contained in:
Jason Davies 2012-05-09 22:04:00 +01:00
Родитель 2697a60ba0
Коммит fe6d0fd2f2
4 изменённых файлов: 38 добавлений и 30 удалений

28
d3.v2.js поставляемый
Просмотреть файл

@ -3547,19 +3547,21 @@ function d3_svg_lineBasisClosed(points) {
}
function d3_svg_lineBundle(points, tension) {
var n = points.length - 1,
x0 = points[0][0],
y0 = points[0][1],
dx = points[n][0] - x0,
dy = points[n][1] - y0,
i = -1,
p,
t;
while (++i <= n) {
p = points[i];
t = i / n;
p[0] = tension * p[0] + (1 - tension) * (x0 + t * dx);
p[1] = tension * p[1] + (1 - tension) * (y0 + t * dy);
var n = points.length - 1;
if (n) {
var x0 = points[0][0],
y0 = points[0][1],
dx = points[n][0] - x0,
dy = points[n][1] - y0,
i = -1,
p,
t;
while (++i <= n) {
p = points[i];
t = i / n;
p[0] = tension * p[0] + (1 - tension) * (x0 + t * dx);
p[1] = tension * p[1] + (1 - tension) * (y0 + t * dy);
}
}
return d3_svg_lineBasis(points);
}

8
d3.v2.min.js поставляемый

Различия файлов скрыты, потому что одна или несколько строк слишком длинны

Просмотреть файл

@ -298,19 +298,21 @@ function d3_svg_lineBasisClosed(points) {
}
function d3_svg_lineBundle(points, tension) {
var n = points.length - 1,
x0 = points[0][0],
y0 = points[0][1],
dx = points[n][0] - x0,
dy = points[n][1] - y0,
i = -1,
p,
t;
while (++i <= n) {
p = points[i];
t = i / n;
p[0] = tension * p[0] + (1 - tension) * (x0 + t * dx);
p[1] = tension * p[1] + (1 - tension) * (y0 + t * dy);
var n = points.length - 1;
if (n) {
var x0 = points[0][0],
y0 = points[0][1],
dx = points[n][0] - x0,
dy = points[n][1] - y0,
i = -1,
p,
t;
while (++i <= n) {
p = points[i];
t = i / n;
p[0] = tension * p[0] + (1 - tension) * (x0 + t * dx);
p[1] = tension * p[1] + (1 - tension) * (y0 + t * dy);
}
}
return d3_svg_lineBasis(points);
}

Просмотреть файл

@ -134,6 +134,10 @@ suite.addBatch({
"observes the specified tension": function(line) {
var l = line().interpolate("bundle").tension(1);
assert.pathEqual(l([[0, 0], [1, 1], [2, 0], [3, 1], [4, 0]]), line().interpolate("basis")([[0, 0], [1, 1], [2, 0], [3, 1], [4, 0]]));
},
"supports a single-element array": function(line) {
var l = line().interpolate("bundle").tension(1);
assert.pathEqual(l([[0, 0]]), "M0,0");
}
},