UNPKG

@antv/g2plot

Version:

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

186 lines 6.41 kB
import { __assign, __extends } from "tslib"; import * as _ from '@antv/util'; import { registerPlotType } from '../../base/global'; import ViewLayer from '../../base/view-layer'; import { getComponent } from '../../components/factory'; import { getGeom } from '../../geoms/factory'; import { extractScale } from '../../util/scale'; import '../../geoms/heatmap/linear'; import HeatmapLegend from './components/legend'; import HeatmapBackground from './components/background'; import '../scatter/components/label/scatter-label'; var HeatmapLayer = /** @class */ (function (_super) { __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 HeatmapLegend(__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 HeatmapBackground(__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')) { extractScale(scales[props.xField], props.xAxis); } /** 配置y-scale */ scales[props.yField] = {}; if (_.has(props, 'yAxis')) { 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 = 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 = getComponent('label', __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; }(ViewLayer)); export default HeatmapLayer; registerPlotType('heatmap', HeatmapLayer); //# sourceMappingURL=layer.js.map