Chart.js icon indicating copy to clipboard operation
Chart.js copied to clipboard

Timeseries ticks skipped inconsistently when major ticks are enabled and maxRotation = 0

Open mbonaci opened this issue 3 years ago • 3 comments

Expected behavior

Ticks should be uniformly spaced, i.e. uniformly dropped.

Current behavior

Ticks are dropped in an inconsistent way for certain chart widths and consequently the chart looks weird. Both, time and timeseries scale exhibits this behavior.

image

Reproducible sample

https://jsfiddle.net/mbonaci/chwLg02y/21/

Optional extra steps/info to reproduce

No response

Possible solution

No response

Context

No response

chart.js version

v3.7.1

Browser name and version

Chrome v101

Link to your project

No response

mbonaci avatar May 24 '22 12:05 mbonaci

Having a look to jsfiddle and playing with it (thanks @mbonaci ), I think there is another bug, maybe there are both related. Where the backdropColor is activated, it seems is not applied correctly to the tick when the tick is rotated.

image

stockiNail avatar May 25 '22 08:05 stockiNail

@stockiNail interesting, I was just thinking that I haven't tried to turn on backdropColor after I allowed the label rotation. BTW Maybe I'm wrong, but I have a feeling that it wouldn't look good even if the backdrop rectangle had the correct angle, but that's a matter of taste, I guess.

Regarding the original issue, the fact that ticks are not equidistant is a consequence of spacing not being the whole number, so multiplying it with count and then rounding introduces this "entropy": https://github.com/chartjs/Chart.js/blob/v3.7.1/src/core/core.scale.autoskip.js#L146

mbonaci avatar May 25 '22 09:05 mbonaci

It seems that removing maxRotation: 0 (allowing rotation) doesn't prevent the bug, it probably just makes the bug less likely to happen:

image

mbonaci avatar May 25 '22 09:05 mbonaci