Chart.js: Using pointStyle "rectRot" on retina display causes points to be drawn incorrectly

Created on 20 May 2016  ·  3Comments  ·  Source: chartjs/Chart.js

If you use a pointStyle of "rectRot" and view the chart on a retina display then the points are drawn in the top 25% of the canvas (i.e. the x and y coordinates of the points are halved). This affects Line and Scatter charts.

I'm guessing this has something to do with the rotating of the rectangle for the point.

http://jsbin.com/gebamox/edit?html,output

help wanted bug

Most helpful comment

Yes, just the rectRot.

Potential fix in element.point.js:

case 'rectRot':
    ctx.beginPath();
    size = 1 / Math.SQRT2 * radius;
    ctx.moveTo(x - size, y);
    ctx.lineTo(x, y + size);
    ctx.lineTo(x + size, y);
    ctx.lineTo(x, y - size);
    ctx.closePath(x - size, y);
    ctx.fill();
    break;

This gets rid of need for rotation.

All 3 comments

@nickgoodliff thanks for the report. Only the rectRot point style has this problem, correct?

A note. This can be reproduced on non retina screens as well. Ctrl + mousewheel page zoom increases the window.devicePixelRatio and shows the same issue.

Yes, just the rectRot.

Potential fix in element.point.js:

case 'rectRot':
    ctx.beginPath();
    size = 1 / Math.SQRT2 * radius;
    ctx.moveTo(x - size, y);
    ctx.lineTo(x, y + size);
    ctx.lineTo(x + size, y);
    ctx.lineTo(x, y - size);
    ctx.closePath(x - size, y);
    ctx.fill();
    break;

This gets rid of need for rotation.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

joebirkin picture joebirkin  ·  3Comments

bytesnz picture bytesnz  ·  3Comments

NODRAJ picture NODRAJ  ·  3Comments

akashrajkn picture akashrajkn  ·  3Comments

lbowers picture lbowers  ·  3Comments