Thanatos9404 opened a new pull request, #21795: URL: https://github.com/apache/echarts/pull/21795
<!-- Please fill in the following information to help us review your PR more efficiently. --> ## Brief Information This pull request is in the type of: - [x] bug fixing - [ ] new feature - [ ] others ### What does this PR do? Makes the slider timeline use `progress.label.formatter` and `emphasis.label.formatter` for the label text in those states. ### Fixed issues - #18673: Timeline-progress-label formatter not returning expected value ## Details ### Before: What was the problem? `timeline.progress.label` and `timeline.emphasis.label` are documented with a `formatter`, but setting it had no effect. In `SliderTimelineView._renderAxisLabel` the label text only comes from `label.formatter`, and the `progress` and `emphasis` states only get a text style from their label models (`createTextStyle(progressLabelModel)`), without any `text`. So a label in progress could turn red, but it kept its normal text. <!-- ADD SCREENSHOT HERE IF APPLICABLE. --> ### After: How does it behave after the fixing? When `progress.label` or `emphasis.label` has its own `formatter`, the text of that state is now formatted with it. It goes through the same `makeLabelFormatter` path as `label.formatter`, so the formatter gets the same `(value, index)` arguments and supports the same templates. A `formatter` on a data item's `progress.label` is used too, like the other per-item state styles. When a state has no `formatter`, its style gets no `text` at all, so the label keeps its normal text as before. `makeLabelFormatter` gets an optional label model argument so the timeline can reuse it for the state formatters. Existing callers are unchanged. Tests: - `test/ut/spec/component/timeline/label.test.ts` covers the progress text with a string template, the callback getting the same arguments as `label.formatter` (on a category and a value axis), the text following `timelineChange`, the emphasis text (also on top of progress, and back to the progress text afterwards), a data item formatter, and a guard that states without a formatter keep the normal text. Six of the seven fail on `release` (the guard passes there too) and all seven pass with this change. - A new case at the bottom of `test/timeline-case.html` for a visual check. <!-- ADD SCREENSHOT HERE IF APPLICABLE. --> ## Document Info One of the following should be checked. - [x] This PR doesn't relate to document changes - [ ] The document should be updated later - [ ] The document changes have been made in apache/echarts-doc#xxx ## Misc ### Security Checking - [ ] This PR uses security-sensitive Web APIs. <!-- PLEASE CHECK IT AGAINST: <https://github.com/apache/echarts/wiki/Security-Checklist-for-Code-Contributors> --> ### ZRender Changes - [ ] This PR depends on ZRender changes (ecomfe/zrender#xxx). ### Related test cases or examples to use the new APIs `test/timeline-case.html` (new case at the bottom) and `test/ut/spec/component/timeline/label.test.ts`. ### Merging options - [ ] Please squash the commits into a single one when merging. ### Other information Left out of this PR: - `progress.label.rotate`, which helgasoft also mentioned on the issue. Rotation is set on the label element, not in the text style, so it needs a different change. I kept this PR to the formatter. - Styling only the current label differently (the second request in the issue) would be a new option. - While testing I noticed that with `axisType: 'time'` (the default) or `'value'`, `_renderAxisLabel` takes the tick value as the data index (`const dataIndex = labelItem.tick.value;`), but the tick value is only the index on a category axis. So the `progress` state of a label is checked against the tick value: on a time axis it never switches on, and on a value axis it is only right when the values happen to equal their indexes. The progress text is set up correctly there, but it only shows when the state switches on, and the same goes for every other `progress.label` style. The same root cause makes clicking a label or a tick jump to the wrong index, which looks like #19137 (closed as stale). Since that isn't specific to the formatter, I'd rather handle it separately. The issue reporter says their progress labels already change style, so the progress state does switch on in their chart and this PR covers their case. Not tested: I ran the jest suite, `npm run lint` and `npm run checktype` on Windows with Node 24 (CI uses Node 20). I did not run `npm run test:visual` or `npm run test:dts`. I only checked the new HTML case by hand in Chromium, with a local `dist/echarts.js` build that is not part of this PR. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
