xh123637 opened a new pull request, #21820:
URL: https://github.com/apache/echarts/pull/21820
## Brief Information
This pull request is in the type of:
- [x] bug fixing
- [ ] new feature
- [ ] others
### What does this PR do?
Fix `symbolType.indexOf is not a function` when `symbol` / `symbolSize` are
given as functions on radar data items, and make data-item symbol callbacks
work for all series.
### Fixed issues
- #20471: symbol and symbolSize do not support function
## Details
### Before: What was the problem?
The documentation says `symbol` and `symbolSize` accept a callback `(value,
params) => string | number`. Series-level callbacks worked, but a callback on a
data item crashed rendering:
```
TypeError: symbolType.indexOf is not a function
at createSymbol (src/util/symbol.ts:345)
at createSymbol (src/chart/radar/RadarView.ts:60)
```
For example, this radar option threw on `setOption`:
```js
series: [{
type: 'radar',
data: [{
value: [80, 90, 70],
symbol: function () { return 'triangle'; },
symbolSize: function () { return 12; }
}]
}]
```
### After: How does it behave after the fixing?
Data-item symbol callbacks are invoked per data item and the returned values
become the item visuals, so the radar renders the `triangle` symbol at size 12.
The same fix also covers other series: a line series with a data-item `symbol`
callback threw the identical error before this change.
### Root cause
`seriesSymbolTask` (`src/visual/symbol.ts`) invokes series-level symbol
callbacks per data item, but `dataSymbolTask` in the same file copied data-item
option values into the item visuals verbatim. A function-valued `symbol`
therefore reached `RadarView.createSymbol` (and `Symbol.updateData` for other
series) as the raw function, and `createSymbol` called
`symbolType.indexOf('empty')` on it.
### Changes
- `src/visual/symbol.ts`: in `dataSymbolTask`, invoke function-valued
`symbol`, `symbolSize`, `symbolRotate` and `symbolOffset` item options with
`(rawValue, params)` — the same arguments `seriesSymbolTask` uses — and store
the result as the item visual.
- `test/ut/spec/series/radar.test.ts`: new tests. The data-item test asserts
the callbacks are called with the raw value and data index, and that the
resolved item visuals are `'triangle'` and `12`. A series-level test guards the
existing behavior.
### Tests
- New test fails on the unmodified code (`TypeError: symbolType.indexOf is
not a function`) and passes with the fix.
- `test/ut/spec/series/radar.test.ts`: 2/2 pass.
- Full unit suite: 27 suites, 196 tests, all pass.
- `tsc --noEmit` clean, ESLint clean on both touched files.
Not verified: the HTML visual test cases (no browser here) and `npm run
test:dts:fast`.
--
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]