UNPKG

@antv/g2plot

Version:

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

228 lines 7.09 kB
import { __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 * as EventParser from './event'; var GEOM_MAP = { area: 'area', line: 'line', point: 'point', }; var RadarLayer = /** @class */ (function (_super) { __extends(RadarLayer, _super); function RadarLayer() { var _this = _super !== null && _super.apply(this, arguments) || this; _this.type = 'radar'; return _this; } RadarLayer.getDefaultOptions = function () { return _.deepMix({}, _super.getDefaultOptions.call(this), { width: 400, height: 400, title: { visible: false, }, description: { visible: false, }, forceFit: true, padding: 'auto', radius: 0.8, smooth: false, line: { visible: true, size: 2, style: { opacity: 1, }, }, area: { visible: true, style: { opacity: 0.25, }, }, point: { visible: false, size: 4, shape: 'point', style: { opacity: 1, }, }, angleAxis: { visible: true, autoHideLabel: false, autoRotateLabel: true, autoRotateTitle: true, line: { visible: false, }, tickLine: { visible: false, }, grid: { visible: true, style: { lineDash: [0, 0], }, }, label: { visible: true, offset: 8, }, title: { visible: false, }, }, radiusAxis: { min: 0, visible: true, autoHideLabel: false, autoRotateLabel: true, autoRotateTitle: true, line: { visible: true, }, tickLine: { visible: true, }, gridType: 'line', grid: { visible: true, style: { lineDash: [0, 0], }, }, label: { visible: true, }, title: { visible: false, }, }, label: { visible: false, type: 'point', }, legend: { visible: true, position: 'left-top', }, tooltip: { visible: true, shared: true, crosshairs: null, }, }); }; RadarLayer.prototype.init = function () { var props = this.options; props.xField = props.angleField; props.yField = props.radiusField; _super.prototype.init.call(this); }; RadarLayer.prototype.getOptions = function (props) { var options = _super.prototype.getOptions.call(this, props); // @ts-ignore var defaultOptions = this.constructor.getDefaultOptions(); return _.deepMix({}, options, defaultOptions, props); }; RadarLayer.prototype.geometryParser = function (dim, type) { return GEOM_MAP[type]; }; RadarLayer.prototype.scale = function () { var props = this.options; var scales = {}; /** 配置x-scale */ scales[props.angleField] = {}; if (_.has(props, 'angleAxis')) { extractScale(scales[props.angleField], props.angleAxis); } /** 配置y-scale */ scales[props.radiusField] = {}; if (_.has(props, 'radiusAxis')) { extractScale(scales[props.radiusField], props.radiusAxis); } this.setConfig('scales', scales); _super.prototype.scale.call(this); }; RadarLayer.prototype.coord = function () { var props = this.options; var coordConfig = { type: 'polar', cfg: { radius: props.radius, }, }; this.setConfig('coord', coordConfig); }; RadarLayer.prototype.axis = function () { var props = this.options; var xAxis_parser = getComponent('axis', { plot: this, dim: 'angle', }); var yAxis_parser = getComponent('axis', { plot: this, dim: 'radius', }); var axesConfig = { fields: {} }; axesConfig.fields[props.angleField] = xAxis_parser; axesConfig.fields[props.radiusField] = yAxis_parser; /** 存储坐标轴配置项到config */ this.setConfig('axes', axesConfig); }; RadarLayer.prototype.addGeometry = function () { var props = this.options; /** 配置面积 */ if (props.area.visible) { var area = getGeom('area', 'main', { plot: this, }); this.setConfig('element', area); this.area = area; } /** 配置线 */ if (props.line && props.line.visible) { var line = getGeom('line', 'guide', { plot: this, }); this.setConfig('element', line); this.line = line; } /** 配置点 */ if (props.point && props.point.visible) { var point = getGeom('point', 'guide', { plot: this, }); this.setConfig('element', point); this.point = point; } }; RadarLayer.prototype.label = function () { }; RadarLayer.prototype.annotation = function () { }; RadarLayer.prototype.animation = function () { _super.prototype.animation.call(this); var props = this.options; if (props.animation === false) { // 关闭动画 if (this.area) this.area.animate = false; if (this.line) this.line.animate = false; if (this.point) this.point.animate = false; } }; RadarLayer.prototype.parseEvents = function (eventParser) { _super.prototype.parseEvents.call(this, EventParser); }; return RadarLayer; }(ViewLayer)); export default RadarLayer; registerPlotType('radar', RadarLayer); //# sourceMappingURL=layer.js.map