Improve label capacity calculation in time scale #6297
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Problem 1
Currently
getLabelCapacity
uses thedisplayFormats
for'millisecond'
ifunit
is not specified. This results in less label capacity than actual (and this often happens). The example below shows that the unit is automatically set to'month'
when there are two labels['2015-01-01', '2015-02-01']
.Problem 2
#6265 changed to compute the capacity using the major unit if applicable, but
me._majorUnit
is not set whengetLabelCapacity
is called. Furthermore, it is not always true that the label width of a major tick is larger than that of a minor tick or vise versa.Solution
This PR takes into account the label capacity of both minor and major ticks in
getLabelCapacity
. And,determineUnitForAutoTicks
checks the label capacity for each unit.Potential problem of this change is that more labels will be rotated because
getLabelCapacity
calculates the capacity using rotation. But I think this should be controlled by themaxRotation
option.Master: https://jsfiddle.net/nagix/zdkcaerb/
This PR: https://jsfiddle.net/nagix/5kersouy/
Fixes #5093