Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[perf] simplify line drawing #6575

Merged
merged 2 commits into from Oct 18, 2019
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
41 changes: 21 additions & 20 deletions src/elements/element.line.js
Expand Up @@ -40,7 +40,11 @@ module.exports = Element.extend({
var closePath = me._loop;
var index, previous, currentVM;

if (me._loop && points.length) {
if (!points.length) {
return;
}

if (me._loop) {
for (index = 0; index < points.length; ++index) {
previous = helpers.previousItem(points, index);
// If the line has an open path, shift the point array
Expand Down Expand Up @@ -75,29 +79,26 @@ module.exports = Element.extend({
ctx.beginPath();
lastDrawnIndex = -1;
kurkle marked this conversation as resolved.
Show resolved Hide resolved

for (index = 0; index < points.length; ++index) {
previous = helpers.previousItem(points, index);
// First point moves to it's starting position no matter what
currentVM = points[0]._view;
if (!currentVM.skip) {
ctx.moveTo(currentVM.x, currentVM.y);
lastDrawnIndex = 0;
}

for (index = 1; index < points.length; ++index) {
currentVM = points[index]._view;
previous = lastDrawnIndex === -1 ? helpers.previousItem(points, index) : points[lastDrawnIndex];

// First point moves to it's starting position no matter what
if (index === 0) {
if (!currentVM.skip) {
if (!currentVM.skip) {
if ((lastDrawnIndex !== (index - 1) && !spanGaps) || lastDrawnIndex === -1) {
// There was a gap and this is the first point after the gap
ctx.moveTo(currentVM.x, currentVM.y);
lastDrawnIndex = index;
}
} else {
previous = lastDrawnIndex === -1 ? previous : points[lastDrawnIndex];

if (!currentVM.skip) {
if ((lastDrawnIndex !== (index - 1) && !spanGaps) || lastDrawnIndex === -1) {
// There was a gap and this is the first point after the gap
ctx.moveTo(currentVM.x, currentVM.y);
} else {
// Line to next point
helpers.canvas.lineTo(ctx, previous._view, currentVM);
}
lastDrawnIndex = index;
} else {
// Line to next point
helpers.canvas.lineTo(ctx, previous._view, currentVM);
}
lastDrawnIndex = index;
}
}

Expand Down