UNPKG

@antv/g2plot

Version:

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

230 lines 7.31 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"); var EventParser = tslib_1.__importStar(require("./event")); var GEOM_MAP = { area: 'area', line: 'line', point: 'point', }; var RadarLayer = /** @class */ (function (_super) { tslib_1.__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')) { scale_1.extractScale(scales[props.angleField], props.angleAxis); } /** 配置y-scale */ scales[props.radiusField] = {}; if (_.has(props, 'radiusAxis')) { scale_1.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 = factory_1.getComponent('axis', { plot: this, dim: 'angle', }); var yAxis_parser = factory_1.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 = factory_2.getGeom('area', 'main', { plot: this, }); this.setConfig('element', area); this.area = area; } /** 配置线 */ if (props.line && props.line.visible) { var line = factory_2.getGeom('line', 'guide', { plot: this, }); this.setConfig('element', line); this.line = line; } /** 配置点 */ if (props.point && props.point.visible) { var point = factory_2.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; }(view_layer_1.default)); exports.default = RadarLayer; global_1.registerPlotType('radar', RadarLayer); //# sourceMappingURL=layer.js.map