Skip to content

Commit 758e993

Browse files
FIX: speedometer number marker logic fix
1 parent 0d4fa8b commit 758e993

2 files changed

Lines changed: 9 additions & 3 deletions

File tree

static/script.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,9 @@ function drawSpeedometer(value) {
142142
ctx.stroke();
143143

144144
drawMarkers(startAngle, endAngle);
145+
// console.log("debug:",startAngle,endAngle)
146+
// drawMarkers(-180, 180);
147+
145148
drawNeedle(value);
146149

147150

@@ -177,11 +180,14 @@ function drawMarkers(startAngle, endAngle) {
177180

178181
ctx.font = '16px Montserrat';
179182
ctx.fillStyle = getCSSVariable('--text');
183+
ctx.textAlign = "center";
184+
ctx.textBaseline = "middle";
180185

181186
markerValues.forEach((markerValue) => {
182187
const markerAngle = startAngle + (markerValue / maxValue) * arcLength;
183-
const xPos = (canvasSize / 2 + Math.cos(markerAngle) * markerRadius) - 16;
184-
const yPos = (canvasSize / 2 + Math.sin(markerAngle) * markerRadius) ;
188+
const xPos = canvasSize / 2 + Math.cos(markerAngle) * markerRadius;
189+
const yPos = canvasSize / 2 + Math.sin(markerAngle) * markerRadius;
190+
// console.log("debug:>>", Math.cos(markerAngle) * markerRadius, (markerValue / maxValue));
185191
ctx.fillText(markerValue.toFixed(1), xPos, yPos);
186192
});
187193
}

static/styles.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,7 @@ a{
305305
height: 100%; */
306306
display: block;
307307
width: 80vw;
308-
max-width: 400px;
308+
max-width: 442px;
309309
height: auto;
310310
}
311311

0 commit comments

Comments
 (0)