Skip to content

Commit

Permalink
refactor: update based on cr
Browse files Browse the repository at this point in the history
  • Loading branch information
危翰 committed Apr 3, 2023
1 parent b624276 commit 7cd4240
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 24 deletions.
34 changes: 13 additions & 21 deletions src/component/tooltip/TooltipHTMLContent.ts
Expand Up @@ -17,7 +17,7 @@
* under the License.
*/

import { isString, indexOf, each, bind, isArray, isDom } from 'zrender/src/core/util';
import { isString, indexOf, each, bind, isFunction, isArray, isDom } from 'zrender/src/core/util';
import { normalizeEvent } from 'zrender/src/core/event';
import { transformLocalCoord } from 'zrender/src/core/dom';
import env from 'zrender/src/core/env';
Expand Down Expand Up @@ -241,9 +241,9 @@ function makeStyleCoord(out: number[], zr: ZRenderType, container: HTMLElement |

interface TooltipContentOption {
/**
* Choose a DOM element which the tooltip element will be located in order to
* 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
*/
Expand All @@ -254,7 +254,6 @@ class TooltipHTMLContent {

el: HTMLDivElement;

private _api: ExtensionAPI;
private _container: HTMLElement | null = null;

private _show: boolean = false;
Expand Down Expand Up @@ -293,26 +292,19 @@ class TooltipHTMLContent {
this.el = el;
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
}
}
const appendTo = opt.appendTo;
const container = (
isString(appendTo)
? document.querySelector(appendTo)
: isDom(appendTo)
? appendTo
: isFunction(appendTo) && appendTo()
) || api.getDom();

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

if (container) {
container.appendChild(el);
} else {
api.getDom().appendChild(el);
}

this._api = api
container.appendChild(el);
this._container = container;

// FIXME
Expand Down Expand Up @@ -361,7 +353,7 @@ class TooltipHTMLContent {
update(tooltipModel: Model<TooltipOption>) {
// FIXME
// Move this logic to ec main?
const container = this._api.getDom();
const container = this._container;
const position = getComputedStyle(container, 'position');
const domStyle = container.style;
if (domStyle.position !== 'absolute' && position !== 'absolute') {
Expand Down
6 changes: 3 additions & 3 deletions src/component/tooltip/TooltipModel.ts
Expand Up @@ -61,16 +61,16 @@ export interface TooltipOption extends CommonTooltipOption<TopLevelFormatterPara
renderMode?: 'auto' | TooltipRenderMode // TODO richText renamed canvas?

/**
* If append popup dom to document.body
* Only available when renderMode is html
* Use `appendTo: 'body'` instead.
* @deprecated
*/
appendToBody?: boolean

/**
* If append popup dom to some other dom element
* Only available when renderMode is html
*/
appendTo?: Function | string | HTMLElement
appendTo?: ((el? :HTMLElement) => HTMLElement | undefined | null) | string | HTMLElement


/**
Expand Down

0 comments on commit 7cd4240

Please sign in to comment.