Skip to content

Commit 19f68c5

Browse files
author
危翰
committed
refactor: rename variables: getAppendElement => teleport & customContainer => container
1 parent a1b9d0f commit 19f68c5

File tree

2 files changed

+13
-18
lines changed

2 files changed

+13
-18
lines changed

src/component/tooltip/TooltipHTMLContent.ts

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -212,14 +212,14 @@ function assembleCssText(tooltipModel: Model<TooltipOption>, enableTransition?:
212212
}
213213

214214
// If not able to make, do not modify the input `out`.
215-
function makeStyleCoord(out: number[], zr: ZRenderType, container: HTMLElement | null, zrX: number, zrY: number) {
215+
function makeStyleCoord(out: number[], zr: ZRenderType, customContainer: HTMLElement | null, zrX: number, zrY: number) {
216216
const zrPainter = zr && zr.painter;
217217

218-
if (container) {
218+
if (customContainer) {
219219
const zrViewportRoot = zrPainter && zrPainter.getViewportRoot();
220220
if (zrViewportRoot) {
221221
// Some APPs might use scale on body, so we support CSS transform here.
222-
transformLocalCoord(out, zrViewportRoot, container, zrX, zrY);
222+
transformLocalCoord(out, zrViewportRoot, customContainer, zrX, zrY);
223223
}
224224
}
225225
else {
@@ -241,13 +241,11 @@ function makeStyleCoord(out: number[], zr: ZRenderType, container: HTMLElement |
241241

242242
interface TooltipContentOption {
243243
/**
244-
* Choose a DOM element which the tooltip element will be located in order to
245-
* avoid some overflow clip but intrude outside of the container.
246-
*
247-
* this config can be either a DomElement, a function to choose a element
248-
* or a selector string used by query delector to local a element
244+
* `false`: the DOM element will be inside the container. Default value.
245+
* `true`: the DOM element will be appended to HTML body, which avoid
246+
* some overflow clip but intrude outside of the container.
249247
*/
250-
appendTo: Function | HTMLElement | string
248+
appendToBody: boolean
251249
}
252250

253251
class TooltipHTMLContent {
@@ -294,14 +292,10 @@ class TooltipHTMLContent {
294292
const zr = this._zr = api.getZr();
295293

296294
let container: HTMLElement | null = null;
297-
if (opt && opt.appendTo) {
298-
if(typeof opt.appendTo === 'string') {
299-
container = document.querySelector(opt.appendTo)
300-
} else if (typeof opt.appendTo === 'function') {
301-
container = opt.appendTo(api.getDom())
302-
} else if (opt.appendTo instanceof HTMLElement) {
303-
container = opt.appendTo
304-
}
295+
if (opt && opt.appendToBody) {
296+
container = this._container = document.body
297+
} else if (opt && opt.teleport) {
298+
container = this._customContainer = opt.teleport(api.getDom()) || null;
305299
}
306300

307301
makeStyleCoord(this._styleCoord, zr, container, api.getWidth() / 2, api.getHeight() / 2);

src/component/tooltip/TooltipView.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,8 @@ class TooltipView extends ComponentView {
172172
this._tooltipContent = renderMode === 'richText'
173173
? new TooltipRichContent(api)
174174
: new TooltipHTMLContent(api, {
175-
appendTo: tooltipModel.get('appendToBody', true) ? 'body' : tooltipModel.get('appendTo', true),
175+
getAppendElement: tooltipModel.get('getAppendElement', true),
176+
appendToBody: tooltipModel.get('appendToBody', true)
176177
});
177178
}
178179

0 commit comments

Comments
 (0)