Skip to content

Commit

Permalink
refactor: rename variables: getAppendElement => teleport & customCont…
Browse files Browse the repository at this point in the history
…ainer => container
  • Loading branch information
危翰 committed Apr 3, 2023
1 parent a1b9d0f commit 19f68c5
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 18 deletions.
28 changes: 11 additions & 17 deletions src/component/tooltip/TooltipHTMLContent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -212,14 +212,14 @@ function assembleCssText(tooltipModel: Model<TooltipOption>, enableTransition?:
}

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

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

interface TooltipContentOption {
/**
* 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
* `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.
*/
appendTo: Function | HTMLElement | string
appendToBody: boolean
}

class TooltipHTMLContent {
Expand Down Expand Up @@ -294,14 +292,10 @@ class TooltipHTMLContent {
const zr = this._zr = api.getZr();

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
}
if (opt && opt.appendToBody) {
container = this._container = document.body
} else if (opt && opt.teleport) {
container = this._customContainer = opt.teleport(api.getDom()) || null;
}

makeStyleCoord(this._styleCoord, zr, container, api.getWidth() / 2, api.getHeight() / 2);
Expand Down
3 changes: 2 additions & 1 deletion src/component/tooltip/TooltipView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,8 @@ class TooltipView extends ComponentView {
this._tooltipContent = renderMode === 'richText'
? new TooltipRichContent(api)
: new TooltipHTMLContent(api, {
appendTo: tooltipModel.get('appendToBody', true) ? 'body' : tooltipModel.get('appendTo', true),
getAppendElement: tooltipModel.get('getAppendElement', true),
appendToBody: tooltipModel.get('appendToBody', true)
});
}

Expand Down

0 comments on commit 19f68c5

Please sign in to comment.