plainheart commented on code in PR #18436:
URL: https://github.com/apache/echarts/pull/18436#discussion_r1159294785
##########
src/component/tooltip/TooltipHTMLContent.ts:
##########
@@ -241,23 +247,25 @@ function makeStyleCoord(out: number[], zr: ZRenderType,
appendToBody: boolean, z
interface TooltipContentOption {
/**
- * `false`: the DOM element will be inside the container. Default value.
- * `true`: the DOM element will be appended to HTML body, which avoid
- * some overflow clip but intrude outside of the container.
+ * Choose a DOM element which the tooltip element will be located in order
to
+ * avoid some overflow clip but intrude outside of the container.
+ *
+ * this config can be either a DomElement, a function to choose a element
+ * or a selector string used by query delector to local a element
*/
- appendToBody: boolean
+ appendTo: ((el?: HTMLElement) => HTMLElement | undefined | null) |
HTMLElement | string
Review Comment:
> Also, we want to manage all common tooltip config for different charts in
a single config file. And I cannot use `myChart.getDom()` in that config file.
Looks reasonable to do so if you split the option and chart instance and
thus can't call the chart API. But is it possible and practical to override the
`appendTo` function in the chart instantiation block? Like this,
_**options.json**_
```json
{
"xAxis": {
"type": "category",
"data": ["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"]
},
"yAxis": {
"type": "value"
},
"series": [
{
"data": [150, 230, 224, 218, 135, 147, 260],
"type": "line"
}
],
"tooltip": {
"trigger": "axis"
}
}
```
_**chart.js**_
```js
const myChart = echarts.init(chartContainer)
const option = /* imported option JSON from somewhere */
// override the `appendTo` function
option.tooltip.appendTo = () => {
const container = myChart.getDom()
return container.closest('.scroll-container')
}
myChart.setOption(option)
```
It should be able to do the same job but might not look easy and elegant.
--
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]