Repository navigation
fix(types): add axis properties to CallbackDataParams. close #17561 - #21836
Prakhar1Ojha wants to merge 2 commits into
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. |
TARUNTEjjjj
left a comment
There was a problem hiding this comment.
AI-assisted review with independent integration validation on the current head. Details and tested scope are in the inline comment.
| $vars: ['name', 'value'], | ||
| axisDim: 'x', | ||
| axisIndex: 0, | ||
| axisType: 'categoryAxis', |
There was a problem hiding this comment.
The new declarations work in actual axis-tooltip callbacks too: I checked setOption plus dispatchAction({type: 'showTip', seriesIndex: 0, dataIndex: 1}) for category, value, and time x axes, using a formatter typed with CallbackDataParams. All six axis fields are populated and the value/label types match these declarations.
One useful adjustment to this fixture: the runtime category callback reports axisType: 'xAxis.category', and axisValue is the category string (e.g. 'Monday'), rather than 'categoryAxis' and ordinal index 1. My live cases returned category 'B', numeric 20, and the time-axis timestamp 1704153600000, each with a string label. Using runtime-shaped fixture values—or adding a live callback assertion—would keep the example aligned with the API being exposed.
The existing test and the three-case integration check pass in Jest/jsdom on Node 26.13.0. No browser rendering is claimed. AI-assisted review and local validation with OpenAI Codex.
There was a problem hiding this comment.
Good catch, @TARUNTEjjjj! I've updated the test fixture to use runtime-shaped values (axisType: 'xAxis.category' and string axisValue: 'Monday'), and added coverage for numeric and timestamp axis values (xAxis.value and xAxis.time). Unit tests and type checking pass cleanly.
There was a problem hiding this comment.
Checked the updated head (48f73be) locally:
test/ut/spec/util/types.test.tsnow aligns with runtime shapes (axisType: 'xAxis.category',axisValue: 'Monday') and covers numeric (xAxis.value) and timestamp (xAxis.time) axes.npm run checktype,npm run lint,npm run checkheader,npm run build:lib, and the Jest UT suite (27suites /196tests, including bothCallbackDataParamstests) all pass.- Re-checked live
echarts.init(..., { renderer: 'svg' })+dispatchAction({ type: 'showTip', seriesIndex: 0, dataIndex: 1 })in jsdom (withHTMLCanvasElement.prototype.getContextstubbed formeasureText) acrosscategory,value, andtimex-axes; runtimeaxisDim,axisIndex,axisType,axisId,axisValue, andaxisValueLabelmatch the updated declarations and test fixtures.
(AI-assisted validation; full browser visual suite was not run.)
…properties Signed-off-by: Prakhar1Ojha <pjha2737@gmail.com>
Brief Information
This pull request is in the type of:
What does this PR do?
Add axis context properties (
axisDim,axisIndex,axisType,axisId,axisValue,axisValueLabel) to the publicCallbackDataParamstype definition.Fixed issues
Details
Before: What was the problem?
At runtime, whenever tooltips or formatters are invoked in an axis context (e.g.,
trigger: 'axis'), ECharts populates axis context properties onto callback parameters (axisDim,axisIndex,axisType,axisId,axisValue, andaxisValueLabelinsrc/component/tooltip/TooltipView.ts:587-595).However, the public TypeScript interface
CallbackDataParamsinsrc/util/types.tsomitted these optional properties. As a consequence, TypeScript users writing custom formatter functions (such asformatter: (params: CallbackDataParams) => ...) experienced compile-time errors:Property 'axisValueLabel' does not exist on type 'CallbackDataParams'.After: How does it behave after the fixing?
axisDim,axisIndex,axisType,axisId,axisValue, andaxisValueLabelproperties onCallbackDataParamsinsrc/util/types.ts.TooltipCallbackDataParamsinsrc/component/tooltip/TooltipView.tsto directly aliasCallbackDataParams.test/ut/spec/util/types.test.tsverifying thataxisValueandaxisValueLabelcan be accessed onCallbackDataParamswithout compiler or runtime diagnostics.Document Info
Misc
Security Checking
ZRender Changes
Related test cases or examples to use the new APIs
test/ut/spec/util/types.test.tsMerging options
Other information
npm run checktype: passed (0 errors)npm run checkheader: passed (0 errors)npm run lint: passed (0 errors, 0 warnings)