fix(scale.time): respect per-unit displayFormat in getLabelForValue#12276
Open
xianjianlf2 wants to merge 1 commit into
Open
fix(scale.time): respect per-unit displayFormat in getLabelForValue#12276xianjianlf2 wants to merge 1 commit into
xianjianlf2 wants to merge 1 commit into
Conversation
getLabelForValue always formatted values with the `datetime` displayFormat, ignoring the displayFormat configured for the currently resolved time unit. Format with `displayFormats[this._unit]` (falling back to `datetime`) so the returned label respects the configured per-unit format, while `tooltipFormat` keeps precedence. Fixes chartjs#12128
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
TimeScale#getLabelForValuealways formatted the value with thedatetimedisplayFormat, ignoring the displayFormat configured for the currently resolved time unit. As reported in #12128 (with a pointer toscale.time.js:502), a value returned bygetLabelForValuetherefore did not match the format the user configured for the active unit.Root cause
The
datetimeformat key was hardcoded, so per-unitdisplayFormats(e.g.day,hour) were never used.Fix
Format the value with the displayFormat of the currently resolved unit, falling back to
datetimewhen no per-unit format is configured.tooltipFormatkeeps precedence, exactly as before.Tests
getLabelForValueuses the current unit's displayFormat, and thattooltipFormatstill wins.datetimeformat) and were corrected to the format of the active unit. These assertions encoded the exact behaviour reported ingetLabelForValuereturns the wrong format in time scale #12128.Fixes #12128