UNPKG

@antv/g2plot

Version:

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

158 lines 5.63 kB
import { __assign, __extends } from "tslib"; import * as _ from '@antv/util'; import { registerPlotType } from '../../base/global'; import ViewLayer from '../../base/view-layer'; import { getGeom } from '../../geoms/factory'; import { extractScale } from '../../util/scale'; import Quadrant from './components/quadrant'; import Trendline from './components/trendline'; import { getComponent } from '../../components/factory'; import * as EventParser from './event'; import './components/label/scatter-label'; var G2_GEOM_MAP = { scatter: 'point', }; var PLOT_GEOM_MAP = { point: 'point', }; var ScatterLayer = /** @class */ (function (_super) { __extends(ScatterLayer, _super); function ScatterLayer() { var _this = _super !== null && _super.apply(this, arguments) || this; _this.type = 'scatter'; return _this; } ScatterLayer.getDefaultOptions = function () { return _.deepMix({}, _super.getDefaultOptions.call(this), { pointSize: 4, pointStyle: { strokeOpacity: 1, fillOpacity: 0.4, opacity: 0.65, }, xAxis: { grid: { visible: true, }, line: { visible: true, }, }, yAxis: { grid: { visible: true, }, line: { visible: true, }, }, tooltip: { visible: true, // false 会造成 tooltip 只能显示一条数据,true 会造成 tooltip 在空白区域也会显示 shared: null, crosshairs: { type: 'rect', }, }, label: { visible: false, position: 'top', }, shape: 'circle', }); }; ScatterLayer.prototype.afterRender = function () { _super.prototype.afterRender.call(this); if (this.options.quadrant && this.options.quadrant.visible && !this.quadrant) { if (this.quadrant) { this.quadrant.destroy(); } this.quadrant = new Quadrant(__assign({ view: this.view, plotOptions: this.options }, this.options.quadrant)); this.quadrant.render(); } if (this.options.trendline && this.options.trendline.visible) { this.trendline = new Trendline(__assign({ view: this.view, plotOptions: this.options }, this.options.trendline)); this.trendline.render(); } }; ScatterLayer.prototype.destroy = function () { if (this.quadrant) { this.quadrant.destroy(); this.quadrant = null; } if (this.trendline) { this.trendline.destroy(); this.trendline = null; } _super.prototype.destroy.call(this); }; ScatterLayer.prototype.geometryParser = function (dim, type) { if (dim === 'g2') { return G2_GEOM_MAP[type]; } return PLOT_GEOM_MAP[type]; }; ScatterLayer.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); }; ScatterLayer.prototype.coord = function () { }; ScatterLayer.prototype.annotation = function () { }; ScatterLayer.prototype.addGeometry = function () { var points = getGeom('point', 'circle', { plot: this, }); this.points = points; if (this.options.label && this.options.label.visible) { this.points.label = this.extractLabel(); } if (this.options.tooltip && this.options.tooltip.visible) { this.points.tooltip = this.extractTooltip(); this.setConfig('tooltip', __assign({ showTitle: false }, this.options.tooltip)); } this.setConfig('element', points); }; ScatterLayer.prototype.animation = function () { _super.prototype.animation.call(this); var props = this.options; if (props.animation === false) { /** 关闭动画 */ this.points.animate = false; } }; ScatterLayer.prototype.parseEvents = function (eventParser) { // 气泡图继承散点图时,会存在 eventParser _super.prototype.parseEvents.call(this, eventParser || EventParser); }; ScatterLayer.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.yField], position: 'right', offset: 0 }, label)); return labelConfig; }; ScatterLayer.prototype.extractTooltip = function () { var props = this.options; return { fields: [props.xField, props.yField], }; }; return ScatterLayer; }(ViewLayer)); export default ScatterLayer; registerPlotType('scatter', ScatterLayer); //# sourceMappingURL=layer.js.map