Skip to content

Bug in calculateTickRotation for logarithmic scale #6810

@benmccann

Description

@benmccann

calculateTickRotation calls getPixelForTick(0), which depends on _valueOffset. _valueOffset depends on _length and is set in _configure which is called before fit. However, _length is not properly initialized until fit is called

I'm not exactly sure what the point of _valueOffset is actually. It seems buggy in more ways than one. Why is it dividing the font size by the length? Is this logic correct for both horizontal and vertical scales? Should it take the label rotation into account?

There's sort of a nasty recursive logic here where the axis length depends on the tick rotation and the tick rotation depends on the axis length. And also buildTicks depends on tick capacity depends on axis length depends on tick rotation depends on the number of ticks. This circular logic causes lots of issues, code duplication, and overall makes the logic very hard to understand. For example, see also #6791 (comment). I'd love any ideas on how we break this circular logic. As a chart.js dev, this has probably caused me more frustration than anything else in the codebase

What if we removed calculateTickRotation and the minRotation / maxRotation options and instead had a labelRotation option that was scriptable? That would both drastically simplify our code and give the user more control over the label rotation. E.g. right now the code assumes the user wants 3 pixels of padding, which isn't configurable

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions