perf: Speed up track feature.
This reduces the amount of calculations needed to construct line
features.
MODIFY
src/lineFeature.js
src/lineFeature.js
@@ -46,9 +46,12 @@ var util = require('./util');
* divided by the sine of half the angle between segments, then a bevel join
* is used instead. This is a single value that applies to all lines. If a
* function, it is called with `(data)`.
- * @property {boolean|function} [uniformLine=false] Boolean indicating if each
- * line has a uniform style (uniform stroke color, opacity, and width). Can
- * vary by line.
+ * @property {boolean|string|function} [uniformLine=false] Boolean indicating
+ * if each line has a uniform style (uniform stroke color, opacity, and
+ * width). Can vary by line. A value of `'drop'` will modify rendered
+ * vertex order by dropping duplicates and setting later values to zero
+ * opacity. This can be faster but makes it so updating the style array
+ * can no longer be used.
* @property {number|function} [antialiasing] Antialiasing distance in pixels.
* Values must be non-negative. A value greater than 1 will produce a
* visible gradient. This is a single value that applies to all lines.

MODIFY
src/trackFeature.js
src/trackFeature.js
@@ -816,7 +816,9 @@ var trackFeature = function (arg) {
{
track: util.identityFunction,
position: util.identityFunction,
- time: (d, i) => (d.t !== undefined ? d.t : i)
+ time: (d, i) => (d.t !== undefined ? d.t : i),
+ uniformLine: 'drop',
+ closed: false
},
arg.style === undefined ? {} : arg.style
);

MODIFY
src/webgl/lineFeature.js
src/webgl/lineFeature.js
@@ -269,6 +269,7 @@ var webgl_lineFeature = function (arg) {
closedVal = closed[i];
firstPosIdx3 = posIdx3;
maxj = lineItem.length + (closedVal === 2 ? 1 : 0);
+ let skipped = 0;
for (j = 0; j < maxj; j += 1, posIdx3 += 3) {
lidx = j;
if (j === lineItem.length) {
@@ -329,9 +330,17 @@ var webgl_lineFeature = function (arg) {
}
if (j) {
+ if (uniform === 'drop' && j > 1 && position[vert[0].pos] === position[vert[1].pos] && position[vert[0].pos + 1] === position[vert[1].pos + 1]) {
+ skipped += 1;
+ continue;
+ }
/* zero out the z position. This can be changed if we handle it in
* the shader. */
for (k = 0; k < orderLen; k += 1, dest += 1, dest3 += 3) {
+ if (uniform === 'drop' && vert[0].strokeOpacity <= 0 && vert[1].strokeOpacity <= 0) {
+ strokeOpacityBuf[dest] = -1;
+ continue;
+ }
orderk0 = order[k][0];
v1 = vert[orderk0];
v2 = vert[1 - orderk0];
@@ -370,6 +379,11 @@ var webgl_lineFeature = function (arg) {
}
}
}
+ if (skipped) {
+ for (k = 0; k < skipped * orderLen; k += 1, dest += 1, dest3 += 3) {
+ strokeOpacityBuf[dest] = -1;
+ }
+ }
}
if (!onlyStyle) {

perf: Speed up track feature.

This reduces the amount of calculations needed to construct line
features.