Skip to content

Commit d5e7b09

Browse files
committed
fix: filter too small lines for better/faster rendering
1 parent b2bf501 commit d5e7b09

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

Diff for: src/charting/renderer/LineChartRenderer.ts

+11-2
Original file line numberDiff line numberDiff line change
@@ -500,12 +500,21 @@ export class LineChartRenderer extends LineRadarRenderer {
500500
}
501501

502502
const startIndex = lastDrawnIndex;
503-
const nbItems = Math.max(Math.min(colorIndex - firstIndex - lastDrawnIndex+1, lastIndex - (startIndex + firstIndex) + 1), 0);
503+
const nbItems = Math.max(Math.min(colorIndex - firstIndex - lastDrawnIndex + 1, lastIndex - (startIndex + firstIndex) + 1), 0);
504504
if (nbItems === 0) {
505505
continue;
506+
} else if (nbItems <= 2) {
507+
const pxDist = Math.sqrt(
508+
Math.pow(points[(startIndex + nbItems) * 2] - points[startIndex * 2], 2) + Math.pow(points[(startIndex + nbItems) * 2 + 1] - points[startIndex * 2 + 1], 2)
509+
);
510+
if (pxDist <= 2) {
511+
// console.log('filtering line ', index, color.color, nbItems, pxDist);
512+
continue;
513+
}
506514
}
515+
507516
this.mRenderPaint.setColor(color.color);
508-
this.linePath.setLines(points, startIndex * 2, (nbItems) * 2);
517+
this.linePath.setLines(points, startIndex * 2, nbItems * 2);
509518
this.drawPath(c, this.linePath, this.mRenderPaint);
510519
lastDrawnIndex = startIndex + nbItems - 1;
511520
if (colorIndex >= lastIndex) {

0 commit comments

Comments
 (0)