UNPKG

@antv/g2plot

Version:

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

184 lines 6.14 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 responsiveMethods from './apply-responsive'; import './apply-responsive/theme'; import './component/label/column-label'; import * as EventParser from './event'; import './theme'; var G2_GEOM_MAP = { column: 'interval', }; var PLOT_GEOM_MAP = { interval: 'column', }; var BaseColumnLayer = /** @class */ (function (_super) { __extends(BaseColumnLayer, _super); function BaseColumnLayer() { var _this = _super !== null && _super.apply(this, arguments) || this; _this.type = 'column'; return _this; } BaseColumnLayer.getDefaultOptions = function () { return _.deepMix({}, _super.getDefaultOptions.call(this), { xAxis: { visible: true, tickLine: { visible: false, }, title: { visible: true, }, }, yAxis: { title: { visible: true, }, label: { visible: true, }, grid: { visible: true, }, }, tooltip: { visible: true, shared: true, crosshairs: { type: 'rect', }, }, label: { visible: false, position: 'top', adjustColor: true, }, legend: { visible: true, position: 'top-left', }, }); }; BaseColumnLayer.prototype.getOptions = function (props) { var options = _super.prototype.getOptions.call(this, props); // @ts-ignore var defaultOptions = this.constructor.getDefaultOptions(); return _.deepMix({}, options, defaultOptions, props); }; BaseColumnLayer.prototype.beforeInit = function () { _super.prototype.beforeInit.call(this); /** 响应式图形 */ if (this.options.responsive && this.options.padding !== 'auto') { this.applyResponsive('preRender'); } }; BaseColumnLayer.prototype.afterRender = function () { /** 响应式 */ if (this.options.responsive && this.options.padding !== 'auto') { this.applyResponsive('afterRender'); } _super.prototype.afterRender.call(this); }; BaseColumnLayer.prototype.geometryParser = function (dim, type) { if (dim === 'g2') { return G2_GEOM_MAP[type]; } return PLOT_GEOM_MAP[type]; }; BaseColumnLayer.prototype.scale = function () { var options = this.options; var scales = {}; /** 配置x-scale */ scales[options.xField] = { type: 'cat' }; if (_.has(options, 'xAxis')) { extractScale(scales[options.xField], options.xAxis); } /** 配置y-scale */ scales[options.yField] = {}; if (_.has(options, 'yAxis')) { extractScale(scales[options.yField], options.yAxis); } this.setConfig('scales', scales); _super.prototype.scale.call(this); }; BaseColumnLayer.prototype.coord = function () { }; BaseColumnLayer.prototype.adjustColumn = function (column) { return; }; BaseColumnLayer.prototype.addGeometry = function () { var options = this.options; var column = getGeom('interval', 'main', { positionFields: [options.xField, options.yField], plot: this, }); if (options.label) { column.label = this.extractLabel(); } this.adjustColumn(column); this.column = column; this.setConfig('element', column); }; BaseColumnLayer.prototype.animation = function () { _super.prototype.animation.call(this); if (this.options.animation === false) { /** 关闭动画 */ this.column.animate = false; } }; BaseColumnLayer.prototype.parseEvents = function (eventParser) { _super.prototype.parseEvents.call(this, EventParser); }; BaseColumnLayer.prototype.extractLabel = function () { var props = this.options; var defaultOptions = this.getLabelOptionsByPosition(props.label.position); var label = _.deepMix({}, defaultOptions, this.options.label); if (label.visible === false) { return false; } var labelConfig = getComponent('label', __assign({ plot: this, labelType: 'columnLabel', fields: [this.options.yField] }, label)); return labelConfig; }; BaseColumnLayer.prototype.applyResponsive = function (stage) { var _this = this; var methods = responsiveMethods[stage]; _.each(methods, function (r) { var responsive = r; responsive.method(_this); }); }; BaseColumnLayer.prototype.getLabelOptionsByPosition = function (position) { if (position === 'middle') { return { offset: 0, style: { textBaseline: 'middle', }, }; } if (position === 'top') { return { offset: 4, style: { textBaseline: 'bottom', }, }; } if (position === 'bottom') { return { offset: 4, style: { textBaseline: 'bottom', }, }; } return { offset: 0 }; }; return BaseColumnLayer; }(ViewLayer)); export default BaseColumnLayer; registerPlotType('column', BaseColumnLayer); //# sourceMappingURL=layer.js.map