viking7982 commented on code in PR #18436:
URL: https://github.com/apache/echarts/pull/18436#discussion_r1155491195
##########
src/component/tooltip/TooltipHTMLContent.ts:
##########
@@ -291,17 +292,27 @@ class TooltipHTMLContent {
(el as any).domBelongToZr = true;
this.el = el;
const zr = this._zr = api.getZr();
- const appendToBody = this._appendToBody = opt && opt.appendToBody;
- makeStyleCoord(this._styleCoord, zr, appendToBody, api.getWidth() / 2,
api.getHeight() / 2);
-
- if (appendToBody) {
- document.body.appendChild(el);
+ let container: HTMLElement | null = null;
+ if (opt && opt.appendTo) {
+ if(typeof opt.appendTo === 'string') {
+ container = document.querySelector(opt.appendTo)
+ } else if (typeof opt.appendTo === 'function') {
+ container = opt.appendTo(api.getDom())
+ } else if (opt.appendTo instanceof HTMLElement) {
+ container = opt.appendTo
+ }
}
Review Comment:
Thanks. I am not aware of the functions like `isDom` and `isFunction`. I
will use them to simplified my code.
But i have some different idea about the last part `|| api.getDom()`. We
have different logic to calculate the tooltip position in `makeStyleCoord`.
Perviously, it was desided by `appendToBody `, and i changed it to checking the
existance of the custom container. It is hard to choose the correct calculation
logic if we have that fallback.
--
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]