UNPKG

3.72 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3var tslib_1 = require("tslib");
4var util_1 = require("@antv/util");
5var coordinate_1 = require("../util/coordinate");
6var base_1 = tslib_1.__importDefault(require("./base"));
7/** 引入对应的 ShapeFactory */
8require("./shape/interval");
9var shape_size_1 = require("./util/shape-size");
10var scale_1 = require("../util/scale");
11/**
12 * Interval 几何标记。
13 * 用于绘制柱状图、饼图、条形图、玫瑰图等。
14 */
15var Interval = /** @class */ (function (_super) {
16 tslib_1.__extends(Interval, _super);
17 function Interval(cfg) {
18 var _this = _super.call(this, cfg) || this;
19 _this.type = 'interval';
20 _this.shapeType = 'interval';
21 _this.generatePoints = true;
22 var background = cfg.background;
23 _this.background = background;
24 return _this;
25 }
26 /**
27 * 获取每条数据的 Shape 绘制信息
28 * @param obj 经过分组 -> 数字化 -> adjust 调整后的数据记录
29 * @returns
30 */
31 Interval.prototype.createShapePointsCfg = function (obj) {
32 var cfg = _super.prototype.createShapePointsCfg.call(this, obj);
33 // 计算每个 shape 的 size
34 var size;
35 var sizeAttr = this.getAttribute('size');
36 if (sizeAttr) {
37 size = this.getAttributeValues(sizeAttr, obj)[0];
38 // 归一化
39 var coordinate = this.coordinate;
40 var coordinateWidth = coordinate_1.getXDimensionLength(coordinate);
41 size = size / coordinateWidth;
42 }
43 else {
44 if (!this.defaultSize) {
45 this.defaultSize = shape_size_1.getDefaultSize(this);
46 }
47 size = this.defaultSize;
48 }
49 cfg.size = size;
50 return cfg;
51 };
52 /**
53 * 调整 y 轴的 scale 范围。
54 * 对于 Y 轴为数值轴柱状图,默认从 0 开始 生长。
55 */
56 Interval.prototype.adjustScale = function () {
57 _super.prototype.adjustScale.call(this);
58 var yScale = this.getYScale();
59 // 特殊逻辑:饼图需要填充满整个空间
60 if (this.coordinate.type === 'theta') {
61 yScale.change({
62 nice: false,
63 min: 0,
64 // 发生过 stack 调整,yScale 的 max 被调整过,this.updateStackRange()
65 max: scale_1.getMaxScale(yScale),
66 });
67 }
68 else {
69 // 柱状图数值轴默认从 0 开始
70 var scaleDefs = this.scaleDefs;
71 var field = yScale.field, min = yScale.min, max = yScale.max, type = yScale.type;
72 if (type !== 'time') {
73 // time 类型不做调整
74 // 柱状图的 Y 轴要从 0 开始生长,但是如果用户设置了则以用户的为准
75 if (min > 0 && !util_1.get(scaleDefs, [field, 'min'])) {
76 yScale.change({
77 min: 0,
78 });
79 }
80 // 柱当柱状图全为负值时也需要从 0 开始生长,但是如果用户设置了则以用户的为准
81 if (max <= 0 && !util_1.get(scaleDefs, [field, 'max'])) {
82 yScale.change({
83 max: 0,
84 });
85 }
86 }
87 }
88 };
89 /**
90 * @override
91 */
92 Interval.prototype.getDrawCfg = function (mappingData) {
93 var shapeCfg = _super.prototype.getDrawCfg.call(this, mappingData);
94 shapeCfg.background = this.background;
95 return shapeCfg;
96 };
97 return Interval;
98}(base_1.default));
99exports.default = Interval;
100//# sourceMappingURL=interval.js.map
\No newline at end of file