Fix performance issue with scale overlay tool

This commit is contained in:
Erik Ziegler 2017-06-07 16:49:49 +02:00
parent 239e5ef91e
commit 3c8c52ab1b

View File

@ -4,12 +4,8 @@
'use strict'; 'use strict';
function drawLine(context, startPoint, endPoint, config) { function drawLine(context, startPoint, endPoint, config) {
context.beginPath();
context.strokeStyle = config.color;
context.lineWidth = config.lineWidth;
context.moveTo(startPoint.x, startPoint.y); context.moveTo(startPoint.x, startPoint.y);
context.lineTo(endPoint.x, endPoint.y); context.lineTo(endPoint.x, endPoint.y);
context.stroke();
} }
function drawVerticalScalebarIntervals (context, config) { function drawVerticalScalebarIntervals (context, config) {
@ -26,7 +22,7 @@
x: 0, x: 0,
y: config.verticalLine.start.y + i * config.verticalMinorTick y: config.verticalLine.start.y + i * config.verticalMinorTick
}; };
if (i% 5 === 0) { if (i % 5 === 0) {
endPoint.x = config.verticalLine.start.x - config.majorTickLength; endPoint.x = config.verticalLine.start.x - config.majorTickLength;
} else { } else {
@ -55,7 +51,7 @@
y: 0 y: 0
}; };
if (i% 5 === 0) { if (i % 5 === 0) {
endPoint.y = config.horizontalLine.start.y - config.majorTickLength; endPoint.y = config.horizontalLine.start.y - config.majorTickLength;
} else { } else {
endPoint.y = config.horizontalLine.start.y - config.minorTickLength; endPoint.y = config.horizontalLine.start.y - config.minorTickLength;
@ -77,13 +73,19 @@
y: config.verticalLine.end.y y: config.verticalLine.end.y
}; };
context.beginPath();
context.strokeStyle = config.color;
context.lineWidth = config.lineWidth;
drawLine(context, startPoint, endPoint, config); drawLine(context, startPoint, endPoint, config);
drawVerticalScalebarIntervals(context, config); drawVerticalScalebarIntervals(context, config);
context.stroke();
} }
function drawHorizontalScalebar(context, config) { function drawHorizontalScalebar(context, config) {
const startPoint = { const startPoint = {
x: config.horizontalLine.start.x , x: config.horizontalLine.start.x,
y: config.horizontalLine.start.y y: config.horizontalLine.start.y
}; };
const endPoint = { const endPoint = {
@ -98,9 +100,13 @@
function drawScalebars(context, config){ function drawScalebars(context, config){
context.shadowColor = config.shadowColor; context.shadowColor = config.shadowColor;
context.shadowBlur = config.shadowBlur; context.shadowBlur = config.shadowBlur;
context.strokeStyle = config.color;
context.lineWidth = config.lineWidth;
context.beginPath();
drawVerticalScalebar(context, config); drawVerticalScalebar(context, config);
drawHorizontalScalebar(context, config); drawHorizontalScalebar(context, config);
context.stroke();
} }
// Computes the max bound for scales on the image // Computes the max bound for scales on the image