Looking at a graph with measurements from -100 to 0 and 0 to 100, I am facing a challenge in adjusting the ball's position calculation based on the gradientDataChart input. This input can have a value between -100 and 100, but the issue lies in proportionality; depending on the screen size, the ball keeps disappearing. Initially, I used a distance of 16, which worked well for a width of 586px.
To explore this further, I ran some tests here.
In the code snippet provided, setting 38 for 900 pixels width seemed to work fine. However, when I tried it with 1000 pixels, the positioning got completely off track... It definitely needs to be responsive:
var widthDefault = 900, metric = -100, calcPos = 38 * ((metric / widthDefault) * 100);
ctx.beginPath();
canvas.width = widthDefault;
ctx.translate(calcPos, 0);
var centerX = canvas.width / 2;
var centerY = canvas.height / 2;
ctx.arc(centerX, centerY, 24, 0, Math.PI * 2, false);
ctx.fillStyle ="#ffffff";
ctx.fill()
ctx.font = 'bold 14pt sans-serif';
ctx.textAlign = 'center';
ctx.strokeStyle ='#622BCF'
ctx.stroke();
ctx.fillStyle ="#622bcf80";
ctx.fillText(`${medida}`, centerX, centerY+8);
ctx.globalCompositeOperation = 'destination-over';
Here is an image example: https://i.sstatic.net/c78vS.png