156 lines
4.2 KiB
JavaScript
156 lines
4.2 KiB
JavaScript
![]() |
function _createSuper(Derived) { return function () { var Super = _getPrototypeOf(Derived), result; if (_isNativeReflectConstruct()) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
|
|||
|
|
|||
|
function _possibleConstructorReturn(self, call) { if (call && (typeof call === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
|
|||
|
|
|||
|
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
|
|||
|
|
|||
|
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } }
|
|||
|
|
|||
|
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
|
|||
|
|
|||
|
function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; subClass.__proto__ = superClass; }
|
|||
|
|
|||
|
var Component = require('../base');
|
|||
|
|
|||
|
var Util = require('../util');
|
|||
|
|
|||
|
var Tooltip = /*#__PURE__*/function (_Component) {
|
|||
|
_inheritsLoose(Tooltip, _Component);
|
|||
|
|
|||
|
var _super = _createSuper(Tooltip);
|
|||
|
|
|||
|
function Tooltip() {
|
|||
|
return _Component.apply(this, arguments) || this;
|
|||
|
}
|
|||
|
|
|||
|
var _proto = Tooltip.prototype;
|
|||
|
|
|||
|
_proto.getDefaultCfg = function getDefaultCfg() {
|
|||
|
var cfg = _Component.prototype.getDefaultCfg.call(this);
|
|||
|
|
|||
|
return Util.mix({}, cfg, {
|
|||
|
/**
|
|||
|
* tooltip container
|
|||
|
* @type {Dom / String}
|
|||
|
*/
|
|||
|
|
|||
|
/**
|
|||
|
* 右下角坐标
|
|||
|
* @type {Number}
|
|||
|
*/
|
|||
|
x: 0,
|
|||
|
|
|||
|
/**
|
|||
|
* y 右下角坐标
|
|||
|
* @type {Number}
|
|||
|
*/
|
|||
|
y: 0,
|
|||
|
|
|||
|
/**
|
|||
|
* tooltip 记录项
|
|||
|
* @type {Array}
|
|||
|
*/
|
|||
|
items: null,
|
|||
|
|
|||
|
/**
|
|||
|
* tooltip 标题
|
|||
|
* @type {Array}
|
|||
|
*/
|
|||
|
titleContent: null,
|
|||
|
|
|||
|
/**
|
|||
|
* 是否展示 title
|
|||
|
* @type {Boolean}
|
|||
|
*/
|
|||
|
showTitle: true,
|
|||
|
|
|||
|
/**
|
|||
|
* 视图范围
|
|||
|
* @type {Object}
|
|||
|
*/
|
|||
|
plotRange: null,
|
|||
|
|
|||
|
/**
|
|||
|
* x轴上,移动到位置的偏移量
|
|||
|
* @type {Number}
|
|||
|
*/
|
|||
|
offset: 10,
|
|||
|
// TODO:支持xy两个方向上的offset
|
|||
|
|
|||
|
/**
|
|||
|
* 时间戳
|
|||
|
* @type {Number}
|
|||
|
*/
|
|||
|
timeStamp: 0,
|
|||
|
|
|||
|
/**
|
|||
|
* 将 tooltip 展示在指定区域内
|
|||
|
* @type {Boolean}
|
|||
|
*/
|
|||
|
inPlot: true,
|
|||
|
|
|||
|
/**
|
|||
|
* tooltip 辅助线配置
|
|||
|
* @type {Object}
|
|||
|
*/
|
|||
|
crosshairs: null
|
|||
|
});
|
|||
|
};
|
|||
|
|
|||
|
_proto.isContentChange = function isContentChange(title, items) {
|
|||
|
var titleContent = this.get('titleContent');
|
|||
|
var lastItems = this.get('items');
|
|||
|
var isChanged = !(title === titleContent && lastItems.length === items.length);
|
|||
|
|
|||
|
if (!isChanged) {
|
|||
|
Util.each(items, function (item, index) {
|
|||
|
var preItem = lastItems[index];
|
|||
|
|
|||
|
for (var key in item) {
|
|||
|
if (item.hasOwnProperty(key)) {
|
|||
|
if (!Util.isObject(item[key]) && item[key] !== preItem[key]) {
|
|||
|
isChanged = true;
|
|||
|
break;
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
if (isChanged) {
|
|||
|
return false;
|
|||
|
}
|
|||
|
});
|
|||
|
}
|
|||
|
|
|||
|
return isChanged;
|
|||
|
};
|
|||
|
|
|||
|
_proto.setContent = function setContent(title, items) {
|
|||
|
var timeStamp = new Date().valueOf();
|
|||
|
this.set('items', items);
|
|||
|
this.set('titleContent', title);
|
|||
|
this.set('timeStamp', timeStamp);
|
|||
|
this.render();
|
|||
|
return this;
|
|||
|
};
|
|||
|
|
|||
|
_proto.setPosition = function setPosition(x, y) {
|
|||
|
this.set('x', x);
|
|||
|
this.set('y', y);
|
|||
|
};
|
|||
|
|
|||
|
_proto.render = function render() {};
|
|||
|
|
|||
|
_proto.clear = function clear() {};
|
|||
|
|
|||
|
_proto.show = function show() {
|
|||
|
this.set('visible', true);
|
|||
|
};
|
|||
|
|
|||
|
_proto.hide = function hide() {
|
|||
|
this.set('visible', false);
|
|||
|
};
|
|||
|
|
|||
|
return Tooltip;
|
|||
|
}(Component);
|
|||
|
|
|||
|
module.exports = Tooltip;
|