codechrl opened a new issue, #21873:
URL: https://github.com/apache/echarts/issues/21873
### Version
6.1.0
### Link to Minimal Reproduction
No hosted link. The script below needs only `echarts` and Node.
### Steps to Reproduce
```js
const echarts = require('echarts');
const data = ['Category label A', 'Category label B'];
function gridLeft(opt) {
const chart = echarts.init(null, null, {renderer: 'svg', ssr: true, width:
600, height: 300});
chart.setOption(Object.assign({
grid: {containLabel: true},
xAxis: {type: 'value'},
yAxis: {type: 'category', data},
series: [{type: 'bar', data: [1, 2]}]
}, opt), true);
const x =
chart.getModel().getComponent('grid').coordinateSystem.getRect().x;
chart.dispose();
return Math.round(x);
}
console.log('global textStyle.fontFamily:', gridLeft({textStyle:
{fontFamily: 'monospace'}}));
console.log('yAxis.axisLabel.fontFamily :', gridLeft({yAxis: {type:
'category', data, axisLabel: {fontFamily: 'monospace'}}}));
```
### Current Behavior
```
global textStyle.fontFamily: 187
yAxis.axisLabel.fontFamily : 290
```
Both charts draw the y axis labels in `monospace`, which the SVG output
shows. With the global `textStyle` the grid leaves 187 px for the labels, the
same as with no font option. Setting the same font on `axisLabel` leaves 290 px.
`getTextRect` in `src/model/mixin/textStyle.ts` reads `fontStyle`,
`fontWeight`, `fontSize` and `fontFamily` with `getShallow` only.
`createTextStyle` falls back to the global `textStyle` for these keys.
`legacyContainLabel.ts` measures axis labels with `getTextRect`, so it measures
a label drawn in a global font with the default font.
The `treemap` breadcrumb and the `visualMap` handle label measure text
through the same function.
### Expected Behavior
The grid reserves the same space whether the font is set on the global
`textStyle` or on `axisLabel`.
### Environment
- OS: Linux (WSL2)
- Node: 22
- Framework: none
### Any additional comments?
I have a fix and will open a PR for it.
--
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]