fix(visualMap): match piecewise categories on a category axis dimension - #21768
Open
jayzhou2309 wants to merge 2 commits into
Open
jayzhou2309 wants to merge 2 commits into
jayzhou2309 wants to merge 2 commits into
Conversation
A dimension encoded onto a category axis stores ordinal numbers, so piecewise categories never matched and every item fell out of range. Map the ordinal back to its category string in categories mode.
|
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. |
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?
Make a piecewise
visualMapwithcategorieswork when itsdimensionis also encoded onto a category axis.Fixed issues
Details
Before: What was the problem?
When a dimension is encoded onto a category axis, the data store keeps ordinal numbers (0, 1, ...) for it, not the category strings. Two visualMap paths read that stored value and pass it to
VisualMapping.findPieceIndex, which compares it with the piece value'teacher':incrementalApplyVisualinsrc/visual/visualSolution.ts(the series visual encoding). No piece matched, so every item was out of range, got symbol'none', and the series disappeared.PiecewiseModel.findTargetDataIndices(hover highlight from the visualMap pieces). It found no data items.The same option works when the dimension is not on a category axis, because the store then keeps the raw strings.
After: How does it behave after the fixing?
In
categoriesmode, both paths map the ordinal number back to its category string through the dimension'sOrdinalMeta, the same waySeriesDatareads a category.VisualMapModel.isCategoryMode()returnsfalseby default, andPiecewiseModelreturnstruewhen it is incategoriesmode. So continuous visualMaps andpieces/splitNumberintervals on an ordinal dimension still match on the ordinal index, as they do today.A regression test in
test/ut/spec/component/visualMap/piecewiseCategories.test.tsuses the option from the issue (a dataset,encode: {y: 'profession'}on a category yAxis,categories: ['teacher', 'doctor']):['none', 'none', 'none']where['diamond', 'circle', 'diamond']is expected, andfindTargetDataIndicesreturns[]for each piece.npm test): 196 of 196 pass withTZ=UTC. With the machine's local timezone,util/time › roundTime_localefails the same way without this change.npx tsc --noEmitandeslinton the changed files are clean.Not verified: rendering in a browser. The tests check the item visuals and the hover target indices, which the scatter view and the piecewise view read.
Open PR #21715 also edits
src/visual/visualSolution.ts, but inapplyVisual, notincrementalApplyVisual. The two changes do not overlap.Document Info
One of the following should be checked.
Misc
Security Checking
ZRender Changes
Related test cases or examples to use the new APIs
test/ut/spec/component/visualMap/piecewiseCategories.test.tsMerging options
Other information
AI disclosure: an AI agent (Claude Code) reproduced the issue on
master, wrote the test and the fix, and rannpx jest --config test/ut/jest.config.cjs,npx eslint, andnpx tsc --noEmit.🤖 Written and posted by an AI agent (Claude Code) on behalf of @jayzhou2309.