UNPKG

@antv/g2plot

Version:

G2 Plot, a market of plots built with the Grammar of Graphics'

78 lines 2.6 kB
import { __extends } from "tslib"; import EventEmitter from '@antv/event-emitter'; var HeatmapBackground = /** @class */ (function (_super) { __extends(HeatmapBackground, _super); function HeatmapBackground(cfg) { var _this = _super.call(this) || this; _this.options = cfg; _this.view = _this.options.view; _this.init(); return _this; } HeatmapBackground.prototype.init = function () { var coord = this.view.get('coord'); this.width = coord.width; this.height = coord.height; this.x = coord.start.x; this.y = coord.end.y; var plotContainer = this.options.plot.container; this.container = plotContainer.addGroup(); this.container.setZIndex(-100); }; HeatmapBackground.prototype.render = function () { if (this.options.type === 'color') { this.renderColorBackground(); } else if (this.options.type === 'image') { this.renderImageBackground(); } else if (this.options.callback) { var callbackCfg = { x: this.x, y: this.y, width: this.width, height: this.height, container: this.container, }; this.options.callback(callbackCfg); } }; HeatmapBackground.prototype.renderColorBackground = function () { this.container.addShape('rect', { attrs: { x: this.x, y: this.y, width: this.width, height: this.height, fill: this.options.value, }, }); }; HeatmapBackground.prototype.renderImageBackground = function () { this.container.addShape('image', { attrs: { x: this.x, y: this.y, width: this.width, height: this.height, img: this.options.src, }, }); }; HeatmapBackground.prototype.clear = function () { if (this.container) { this.container.clear(); this.emit('background:clear'); } }; HeatmapBackground.prototype.destroy = function () { if (this.container) { this.container.remove(); // 使用callback定制的html background需要自己监听销毁事件自行销毁 this.emit('background:destroy'); } }; return HeatmapBackground; }(EventEmitter)); export default HeatmapBackground; //# sourceMappingURL=background.js.map