UNPKG

@antv/g2plot

Version:

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

186 lines 6.38 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 apply_responsive_1 = tslib_1.__importDefault(require("./apply-responsive")); require("./apply-responsive/theme"); require("./component/label/column-label"); var EventParser = tslib_1.__importStar(require("./event")); require("./theme"); var G2_GEOM_MAP = { column: 'interval', }; var PLOT_GEOM_MAP = { interval: 'column', }; var BaseColumnLayer = /** @class */ (function (_super) { tslib_1.__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')) { scale_1.extractScale(scales[options.xField], options.xAxis); } /** 配置y-scale */ scales[options.yField] = {}; if (_.has(options, 'yAxis')) { scale_1.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 = factory_2.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 = factory_1.getComponent('label', tslib_1.__assign({ plot: this, labelType: 'columnLabel', fields: [this.options.yField] }, label)); return labelConfig; }; BaseColumnLayer.prototype.applyResponsive = function (stage) { var _this = this; var methods = apply_responsive_1.default[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; }(view_layer_1.default)); exports.default = BaseColumnLayer; global_1.registerPlotType('column', BaseColumnLayer); //# sourceMappingURL=layer.js.map