UNPKG

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