Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tooltip dom append to body, use to top of layer #8049

Merged
merged 3 commits into from
Jan 9, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions src/component/tooltip/TooltipContent.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ function TooltipContent(container, api) {
this._x = api.getWidth() / 2;
this._y = api.getHeight() / 2;

container.appendChild(el);
document.body.appendChild(el);

this._container = container;

Expand Down Expand Up @@ -254,7 +254,11 @@ TooltipContent.prototype = {

isShow: function () {
return this._show;
}
},

dispose: function () {
this.el.parentNode.removeChild(this.el)
},
};

export default TooltipContent;
30 changes: 18 additions & 12 deletions src/component/tooltip/TooltipView.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ export default echarts.extendComponentView({
}
var tooltipContent = new TooltipContent(api.getDom(), api);
this._tooltipContent = tooltipContent;

this._event = {};
this._viewWidth = document.body.clientWidth;
this._viewHeight = document.body.clientHeight;
},

render: function (tooltipModel, ecModel, api) {
Expand Down Expand Up @@ -91,6 +95,7 @@ export default echarts.extendComponentView({
// If 'none', it is not controlled by mouse totally.
if (triggerOn !== 'none') {
if (triggerOn.indexOf(currTrigger) >= 0) {
this._event = e.event;
this._tryShow(e, dispatchAction);
}
else if (currTrigger === 'leave') {
Expand Down Expand Up @@ -166,15 +171,16 @@ export default echarts.extendComponentView({
this._tryShow({
offsetX: payload.x,
offsetY: payload.y,
target: el
target: el,
event: this._event
}, dispatchAction);
}
else if (dataByCoordSys) {
this._tryShow({
offsetX: payload.x,
offsetY: payload.y,
position: payload.position,
event: {},
event: this._event,
dataByCoordSys: payload.dataByCoordSys,
tooltipOption: payload.tooltipOption
}, dispatchAction);
Expand All @@ -194,7 +200,7 @@ export default echarts.extendComponentView({
offsetY: cy,
position: payload.position,
target: pointInfo.el,
event: {}
event: this._event
}, dispatchAction);
}
}
Expand All @@ -212,7 +218,7 @@ export default echarts.extendComponentView({
offsetY: payload.y,
position: payload.position,
target: api.getZr().findHover(payload.x, payload.y).target,
event: {}
event: this._event
}, dispatchAction);
}
},
Expand Down Expand Up @@ -279,8 +285,8 @@ export default echarts.extendComponentView({
}

// Save mouse x, mouse y. So we can try to keep showing the tip if chart is refreshed
this._lastX = e.offsetX;
this._lastY = e.offsetY;
this._lastX = e.event.pageX;
this._lastY = e.event.pageY;

var dataByCoordSys = e.dataByCoordSys;
if (dataByCoordSys && dataByCoordSys.length) {
Expand Down Expand Up @@ -318,7 +324,7 @@ export default echarts.extendComponentView({
_showAxisTooltip: function (dataByCoordSys, e) {
var ecModel = this._ecModel;
var globalTooltipModel = this._tooltipModel;
var point = [e.offsetX, e.offsetY];
var point = [e.event.pageX, e.event.pageY];
var singleDefaultHTML = [];
var singleParamsList = [];
var singleTooltipModel = buildTooltipModel([
Expand Down Expand Up @@ -442,7 +448,7 @@ export default echarts.extendComponentView({
this._showOrMove(tooltipModel, function () {
this._showTooltipContent(
tooltipModel, defaultHtml, params, asyncTicket,
e.offsetX, e.offsetY, e.position, e.target
e.event.pageX, e.event.pageY, e.position, e.target
);
});

Expand Down Expand Up @@ -478,7 +484,7 @@ export default echarts.extendComponentView({
this._showOrMove(subTooltipModel, function () {
this._showTooltipContent(
subTooltipModel, defaultHtml, subTooltipModel.get('formatterParams') || {},
asyncTicket, e.offsetX, e.offsetY, e.position, el
asyncTicket, e.event.pageX, e.event.pageY, e.position, el
);
});

Expand Down Expand Up @@ -540,8 +546,8 @@ export default echarts.extendComponentView({
* @return {Array.<number>}
*/
_updatePosition: function (tooltipModel, positionExpr, x, y, content, params, el) {
var viewWidth = this._api.getWidth();
var viewHeight = this._api.getHeight();
var viewWidth = this._viewWidth;
var viewHeight = this._viewHeight;
positionExpr = positionExpr || tooltipModel.get('position');

var contentSize = content.getSize();
Expand Down Expand Up @@ -660,7 +666,7 @@ export default echarts.extendComponentView({
if (env.node || env.wxa) {
return;
}
this._tooltipContent.hide();
this._tooltipContent.dispose();
globalListener.unregister('itemTooltip', api);
}
});
Expand Down