Skip to content

Commit 83280da

Browse files
authored
Limit number of LEDS shown in Liveview to pixel width of canvas
Avoids aliasing errors on narrow screens (such as on mobile). Follow-on to discussion in wled#3621 , but broken out into a separate pull request.
1 parent bab4201 commit 83280da

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

wled00/data/liveview.htm

+5-4
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,11 @@
2525
var ctx;
2626
function draw(start, skip, leds, fill) {
2727
c.width = d.documentElement.clientWidth;
28-
let w = (c.width * skip) / (leds.length - start);
29-
for (let i = start; i < leds.length; i += skip) {
30-
ctx.fillStyle = fill(leds,i);
31-
ctx.fillRect(Math.round((i - start) * w / skip), 0, Math.ceil(w), c.height);
28+
var len = Math.min((leds.length - start) / skip, c.width) //limit LEDs to pixel width of canvas
29+
var w = c.width / len;
30+
for (i = 0; i < len; i++) {
31+
ctx.fillStyle = fill(leds, (i * skip) + start);
32+
ctx.fillRect(i * w, 0, w + 1, c.height); // Make each strip overlap by 1 pixel to avoid round-off errors
3233
}
3334
}
3435
function update() { // via HTTP (/json/live)

0 commit comments

Comments
 (0)