UNPKG

@antv/g2plot

Version:

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

188 lines 6.65 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var tslib_1 = require("tslib"); var _ = tslib_1.__importStar(require("@antv/util")); var global_1 = require("../../base/global"); var view_layer_1 = tslib_1.__importDefault(require("../../base/view-layer")); var factory_1 = require("../../components/factory"); var factory_2 = require("../../geoms/factory"); var scale_1 = require("../../util/scale"); require("../../geoms/heatmap/linear"); var legend_1 = tslib_1.__importDefault(require("./components/legend")); var background_1 = tslib_1.__importDefault(require("./components/background")); require("../scatter/components/label/scatter-label"); var HeatmapLayer = /** @class */ (function (_super) { tslib_1.__extends(HeatmapLayer, _super); function HeatmapLayer() { var _this = _super !== null && _super.apply(this, arguments) || this; _this.type = 'heatmap'; _this.count = 0; return _this; } HeatmapLayer.getDefaultOptions = function () { return _.deepMix({}, _super.getDefaultOptions.call(this), { xAxis: { visible: true, autoHideLabel: true, autoRotateLabel: true, autoRotateTitle: false, grid: { visible: false, }, line: { visible: true, }, tickLine: { visible: true, }, label: { visible: true, }, title: { visible: true, offset: 12, }, }, yAxis: { visible: true, autoHideLabel: true, autoRotateLabel: false, autoRotateTitle: true, grid: { visible: false, }, line: { visible: true, }, tickLine: { visible: true, }, label: { visible: true, }, title: { visible: true, offset: 12, }, }, tooltip: { visible: true, crosshairs: { type: 'cross', style: { lineWidth: 2, }, }, }, legend: { visible: true, position: 'bottom-center', }, color: [ 'rgba(33,102,172,0)', 'rgb(103,169,207)', 'rgb(209,229,240)', 'rgb(253,219,199)', 'rgb(239,138,98)', 'rgb(178,24,43)', ], }); }; HeatmapLayer.prototype.afterRender = function () { if (this.options.legend && this.options.legend.visible) { this.heatmapLegend = new legend_1.default(tslib_1.__assign({ view: this.view, plot: this }, this.options.legend)); this.heatmapLegend.render(); this.paddingController.registerPadding(this.heatmapLegend, 'outer'); } if (this.options.background && this.options.padding !== 'auto') { this.background = new background_1.default(tslib_1.__assign({ view: this.view, plot: this }, this.options.background)); this.background.render(); } _super.prototype.afterRender.call(this); this.count += 1; }; HeatmapLayer.prototype.destroy = function () { if (this.heatmapLegend) { this.heatmapLegend.destroy(); this.heatmapLegend = null; } if (this.background) { this.background.destroy(); this.background = null; } _super.prototype.destroy.call(this); }; HeatmapLayer.prototype.scale = function () { var props = this.options; var scales = {}; /** 配置x-scale */ scales[props.xField] = {}; if (_.has(props, 'xAxis')) { scale_1.extractScale(scales[props.xField], props.xAxis); } /** 配置y-scale */ scales[props.yField] = {}; if (_.has(props, 'yAxis')) { scale_1.extractScale(scales[props.yField], props.yAxis); } this.setConfig('scales', scales); _super.prototype.scale.call(this); }; HeatmapLayer.prototype.coord = function () { }; HeatmapLayer.prototype.geometryParser = function (dim, type) { return 'heatmap'; }; HeatmapLayer.prototype.addGeometry = function () { var config = { type: 'linearHeatmap', position: { fields: [this.options.xField, this.options.yField], }, color: { fields: [this.options.colorField], values: this.options.color, }, }; if (this.options.radius) { config.radius = this.options.radius; } if (this.options.intensity) { config.intensity = this.options.intensity; } this.setConfig('element', config); this.addPoint(); }; HeatmapLayer.prototype.addPoint = function () { var props = this.options; var defaultConfig = { visible: false, size: 0 }; if (props.point && props.point.visible) { props.point = _.deepMix(defaultConfig, props.point); } else { props.point = defaultConfig; } var point = factory_2.getGeom('point', 'guide', { plot: this, }); point.active = false; point.label = this.extractLabel(); this.setConfig('element', point); }; HeatmapLayer.prototype.extractLabel = function () { var props = this.options; var label = props.label; if (label && label.visible === false) { return false; } var labelConfig = factory_1.getComponent('label', tslib_1.__assign({ plot: this, labelType: 'scatterLabel', fields: [props.xField, props.yField], position: 'middle', offset: 0 }, label)); return labelConfig; }; HeatmapLayer.prototype.legend = function () { this.setConfig('legends', false); }; HeatmapLayer.prototype.animation = function () { }; return HeatmapLayer; }(view_layer_1.default)); exports.default = HeatmapLayer; global_1.registerPlotType('heatmap', HeatmapLayer); //# sourceMappingURL=layer.js.map