From 439547b4389101dc4546f198ff00eccea0b0a6f7 Mon Sep 17 00:00:00 2001 From: Starbeamrainbowlabs Date: Thu, 9 May 2019 21:38:42 +0100 Subject: [PATCH] Flip text to the other side of the guage --- client_src/js/Guage.mjs | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/client_src/js/Guage.mjs b/client_src/js/Guage.mjs index ea74c57..4784826 100644 --- a/client_src/js/Guage.mjs +++ b/client_src/js/Guage.mjs @@ -20,7 +20,7 @@ class Guage { render() { let guage_size = { - x: this.canvas.width * 0.1, + x: this.canvas.width * 0.6, y: this.canvas.height * 0.05, width: this.canvas.width * 0.3, height: this.canvas.height * 0.9 @@ -53,7 +53,10 @@ class Guage { gradient.addColorStop(parseFloat(point), gradient_spec[point]); this.context.fillStyle = gradient; - this.context.fillRect(guage_size.x, guage_size.y, guage_size.width, guage_size.height); + this.context.fillRect( + guage_size.x, guage_size.y, + guage_size.width, guage_size.height + ); this.context.restore(); } @@ -69,15 +72,16 @@ class Guage { for (let point in this.spec) { let value = 1 - (parseFloat(point) / this.max); - let draw_x = guage_size.x + guage_size.width + 3; + let text_width = this.context.measureText(point).width; + let draw_x = guage_size.x - 5 - text_width; let draw_y = guage_size.y + (value * guage_size.height); // console.log(`Writing '${point}' to (${draw_x}, ${draw_y})`); this.context.fillText(point, draw_x, draw_y); this.context.beginPath(); - this.context.moveTo(guage_size.x, draw_y); - this.context.lineTo(draw_x, draw_y); + this.context.moveTo(guage_size.x + guage_size.width, draw_y); + this.context.lineTo(draw_x + text_width, draw_y); this.context.stroke(); }