Skip to content

Commit

Permalink
fix: #12812
Browse files Browse the repository at this point in the history
  • Loading branch information
liulinboyi committed Jun 23, 2020
1 parent a9653ea commit 3dbaf64
Show file tree
Hide file tree
Showing 4 changed files with 433 additions and 7 deletions.
20 changes: 18 additions & 2 deletions src/component/tooltip/TooltipContent.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,8 @@ function makeStyleCoord(out, zr, appendToBody, zrX, zrY) {
out[1] += viewportRootOffset.offsetTop;
}
}
out[2] = out[0] / zr.getWidth(); // The ratio of left to width
out[3] = out[1] / zr.getHeight(); // The ratio of top to height
}

/**
Expand All @@ -169,7 +171,7 @@ function TooltipContent(container, api, opt) {
var zr = this._zr = api.getZr();
var appendToBody = this._appendToBody = opt && opt.appendToBody;

this._styleCoord = [0, 0];
this._styleCoord = [0, 0, 0, 0]; // [left, top, left/width, top/height]

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

Expand Down Expand Up @@ -240,7 +242,7 @@ TooltipContent.prototype = {
/**
* Update when tooltip is rendered
*/
update: function () {
update: function (tooltipModel) {
// FIXME
// Move this logic to ec main?
var container = this._container;
Expand All @@ -250,11 +252,25 @@ TooltipContent.prototype = {
if (domStyle.position !== 'absolute' && stl.position !== 'absolute') {
domStyle.position = 'relative';
}
var alwaysShowContent = tooltipModel.get('alwaysShowContent');
alwaysShowContent && this._moveTooltipIfResized();
// Hide the tooltip
// PENDING
// this.hide();
},

/**
* when alwaysShowContent is true change or rotation window size and restore will move tooltip
* @private
*/
_moveTooltipIfResized: function () {
var ratioX = this._styleCoord[2]; // The ratio of left to width
var ratioY = this._styleCoord[3]; // The ratio of top to height
var realX = ratioX * this._zr.getWidth();
var realY = ratioY * this._zr.getHeight();
this.moveTo(realX, realY);
},

show: function (tooltipModel) {
clearTimeout(this._hideTimeout);
var el = this.el;
Expand Down
35 changes: 31 additions & 4 deletions src/component/tooltip/TooltipRichContent.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,25 @@ import * as zrUtil from 'zrender/src/core/util';
// import Group from 'zrender/src/container/Group';
import Text from 'zrender/src/graphic/Text';


function makeStyleCoord(out, zr, zrX, zrY) {
out[0] = zrX;
out[1] = zrY;
out[2] = out[0] / zr.getWidth(); // The ratio of left to width
out[3] = out[1] / zr.getHeight(); // The ratio of top to height
}

/**
* @alias module:echarts/component/tooltip/TooltipRichContent
* @constructor
*/
function TooltipRichContent(api) {

this._zr = api.getZr();
var zr = this._zr = api.getZr();

this._styleCoord = [0, 0, 0, 0]; // [left, top, left/width, top/height]

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

this._show = false;

Expand All @@ -50,8 +62,21 @@ TooltipRichContent.prototype = {
/**
* Update when tooltip is rendered
*/
update: function () {
// noop
update: function (tooltipModel) {
var alwaysShowContent = tooltipModel.get('alwaysShowContent');
alwaysShowContent && this._moveTooltipIfResized();
},

/**
* when alwaysShowContent is true change or rotation window size and restore will move tooltip
* @private
*/
_moveTooltipIfResized: function () {
var ratioX = this._styleCoord[2]; // The ratio of left to width
var ratioY = this._styleCoord[3]; // The ratio of top to height
var realX = ratioX * this._zr.getWidth();
var realY = ratioY * this._zr.getHeight();
this.moveTo(realX, realY);
},

show: function (tooltipModel) {
Expand Down Expand Up @@ -150,7 +175,9 @@ TooltipRichContent.prototype = {

moveTo: function (x, y) {
if (this.el) {
this.el.attr('position', [x, y]);
var styleCoord = this._styleCoord;
makeStyleCoord(styleCoord, this._zr, x, y);
this.el.attr('position', [styleCoord[0], styleCoord[1]]);
}
},

Expand Down
2 changes: 1 addition & 1 deletion src/component/tooltip/TooltipView.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ export default echarts.extendComponentView({
this._alwaysShowContent = tooltipModel.get('alwaysShowContent');

var tooltipContent = this._tooltipContent;
tooltipContent.update();
tooltipContent.update(tooltipModel);
tooltipContent.setEnterable(tooltipModel.get('enterable'));

this._initGlobalListener();
Expand Down
Loading

0 comments on commit 3dbaf64

Please sign in to comment.