Repository navigation
Conversation
|
Thanks for your contribution! Please DO NOT commit the files in dist, i18n, and ssr/client/dist folders in a non-release pull request. These folders are for release use only. To reviewers: If this PR is going to be described in the changelog in the future release, please make sure this PR has one of the following labels: This message is shown because the PR description doesn't contain the document related template. |
This branch has not been deployed
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.
Brief Information
This pull request is in the type of:
What does this PR do?
Support formatter functions in the time axis label formatter dictionary, so a function can be used for a single time unit or level instead of only as a top-level formatter.
Fixed issues
Details
Before: What was the problem?
A time axis
axisLabel.formattergiven as a per-level dictionary of functions, e.g.did not work:
parseTimeAxisLabelFormatterDictionarysilently dropped the functions (they fell through to the default-template branch), so the labels were rendered with the default templates and the callbacks were never called. A function used inside a leveled template array, e.g.day: ['{d}', fn], was even worse: it survived into the parsed dictionary andleveledFormatpassed it toformatas a string template, throwing(template || "").replace is not a functionand leaving the axis blank.After: How does it behave after the fixing?
A formatter function can now be used in place of a string template at any position of the dictionary: per time unit (
{year: fn, ...}), in the nested dictionary form ({day: {year: fn}}), or as an element of a leveled template array ({day: ['{d}', fn]}). The function is called with(value, index, extra)like a top-level formatter function, and its return value is used as the template for placeholder substitution, matching the existing top-level formatter behavior.The dictionary builder now keeps function values as-is, and the string-concatenation and
{primary|...}highlight logic only applies to string templates, so functions are never coerced to strings.Tests
New
leveledFormattests intest/ut/spec/util/time.test.ts(5 cases):(value, index, extra)arguments passed to the function;All 5 new tests fail on the unmodified code (the flat-dictionary functions are ignored, the array form throws) and pass with the fix.
test/ut/spec/util/time.test.ts: 20/20 pass;test/ut/spec/scale+test/ut/spec/util: 61/61 pass;test/ut/spec/component: 30/30 pass.npx tsc --noEmitand ESLint on the changed files are clean.