cx 24.10.4 → 24.10.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/charts.js +103 -20
- package/dist/manifest.js +690 -690
- package/package.json +1 -1
- package/src/charts/axis/Axis.d.ts +113 -110
- package/src/charts/axis/Axis.js +30 -10
- package/src/charts/axis/CategoryAxis.d.ts +27 -24
- package/src/charts/axis/CategoryAxis.js +235 -212
|
@@ -1,212 +1,235 @@
|
|
|
1
|
-
import { Axis } from "./Axis";
|
|
2
|
-
import { VDOM } from "../../ui/Widget";
|
|
3
|
-
import { isUndefined } from "../../util/isUndefined";
|
|
4
|
-
import { isArray } from "../../util/isArray";
|
|
5
|
-
|
|
6
|
-
export class CategoryAxis extends Axis {
|
|
7
|
-
declareData() {
|
|
8
|
-
super.declareData(...arguments, {
|
|
9
|
-
inverted: undefined,
|
|
10
|
-
uniform: undefined,
|
|
11
|
-
names: undefined,
|
|
12
|
-
values: undefined,
|
|
13
|
-
minSize: undefined,
|
|
14
|
-
categoryCount: undefined,
|
|
15
|
-
});
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
initInstance(context, instance) {
|
|
19
|
-
instance.calculator = new CategoryScale();
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
explore(context, instance) {
|
|
23
|
-
super.explore(context, instance);
|
|
24
|
-
var { values, names, inverted, uniform, minSize } = instance.data;
|
|
25
|
-
instance.calculator.reset(inverted, uniform, values, names, minSize);
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
reportData(context, instance) {
|
|
29
|
-
instance.set("categoryCount", instance.calculator.valueList.length);
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
render(context, instance, key) {
|
|
33
|
-
var { data, calculator } = instance;
|
|
34
|
-
|
|
35
|
-
if (!data.bounds.valid()) return null;
|
|
36
|
-
|
|
37
|
-
var formatter = (v) => calculator.names[v] || v;
|
|
38
|
-
|
|
39
|
-
return (
|
|
40
|
-
<g key={key} className={data.classNames} style={data.style}>
|
|
41
|
-
{this.renderTicksAndLabels(context, instance, formatter)}
|
|
42
|
-
</g>
|
|
43
|
-
);
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
CategoryAxis.prototype.baseClass = "categoryaxis";
|
|
48
|
-
CategoryAxis.prototype.anchors = "0 1 1 0";
|
|
49
|
-
CategoryAxis.prototype.vertical = false;
|
|
50
|
-
CategoryAxis.prototype.inverted = false;
|
|
51
|
-
CategoryAxis.prototype.uniform = false;
|
|
52
|
-
CategoryAxis.prototype.labelOffset = 10;
|
|
53
|
-
CategoryAxis.prototype.labelRotation = 0;
|
|
54
|
-
CategoryAxis.prototype.labelAnchor = "auto";
|
|
55
|
-
CategoryAxis.prototype.labelDx = "auto";
|
|
56
|
-
CategoryAxis.prototype.labelDy = "auto";
|
|
57
|
-
CategoryAxis.prototype.minSize = 1;
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
delete this.
|
|
68
|
-
this.
|
|
69
|
-
this.
|
|
70
|
-
this.
|
|
71
|
-
this.
|
|
72
|
-
this.
|
|
73
|
-
this.
|
|
74
|
-
this.
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
this.
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
this.
|
|
153
|
-
this.
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
if (this.
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
if (
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
return
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
);
|
|
211
|
-
|
|
212
|
-
}
|
|
1
|
+
import { Axis } from "./Axis";
|
|
2
|
+
import { VDOM } from "../../ui/Widget";
|
|
3
|
+
import { isUndefined } from "../../util/isUndefined";
|
|
4
|
+
import { isArray } from "../../util/isArray";
|
|
5
|
+
|
|
6
|
+
export class CategoryAxis extends Axis {
|
|
7
|
+
declareData() {
|
|
8
|
+
super.declareData(...arguments, {
|
|
9
|
+
inverted: undefined,
|
|
10
|
+
uniform: undefined,
|
|
11
|
+
names: undefined,
|
|
12
|
+
values: undefined,
|
|
13
|
+
minSize: undefined,
|
|
14
|
+
categoryCount: undefined,
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
initInstance(context, instance) {
|
|
19
|
+
instance.calculator = new CategoryScale();
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
explore(context, instance) {
|
|
23
|
+
super.explore(context, instance);
|
|
24
|
+
var { values, names, inverted, uniform, minSize } = instance.data;
|
|
25
|
+
instance.calculator.reset(inverted, uniform, values, names, minSize, this.minTickDistance, this.minLabelDistance);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
reportData(context, instance) {
|
|
29
|
+
instance.set("categoryCount", instance.calculator.valueList.length);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
render(context, instance, key) {
|
|
33
|
+
var { data, calculator } = instance;
|
|
34
|
+
|
|
35
|
+
if (!data.bounds.valid()) return null;
|
|
36
|
+
|
|
37
|
+
var formatter = (v) => calculator.names[v] || v;
|
|
38
|
+
|
|
39
|
+
return (
|
|
40
|
+
<g key={key} className={data.classNames} style={data.style}>
|
|
41
|
+
{this.renderTicksAndLabels(context, instance, formatter)}
|
|
42
|
+
</g>
|
|
43
|
+
);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
CategoryAxis.prototype.baseClass = "categoryaxis";
|
|
48
|
+
CategoryAxis.prototype.anchors = "0 1 1 0";
|
|
49
|
+
CategoryAxis.prototype.vertical = false;
|
|
50
|
+
CategoryAxis.prototype.inverted = false;
|
|
51
|
+
CategoryAxis.prototype.uniform = false;
|
|
52
|
+
CategoryAxis.prototype.labelOffset = 10;
|
|
53
|
+
CategoryAxis.prototype.labelRotation = 0;
|
|
54
|
+
CategoryAxis.prototype.labelAnchor = "auto";
|
|
55
|
+
CategoryAxis.prototype.labelDx = "auto";
|
|
56
|
+
CategoryAxis.prototype.labelDy = "auto";
|
|
57
|
+
CategoryAxis.prototype.minSize = 1;
|
|
58
|
+
CategoryAxis.prototype.minLabelDistanceHorizontal = 0;
|
|
59
|
+
CategoryAxis.prototype.minLabelDistanceVertical = 0;
|
|
60
|
+
CategoryAxis.prototype.minTickDistance = 0;
|
|
61
|
+
|
|
62
|
+
Axis.alias("category", CategoryAxis);
|
|
63
|
+
|
|
64
|
+
class CategoryScale {
|
|
65
|
+
reset(inverted, uniform, values, names, minSize, minTickDistance, minLabelDistance) {
|
|
66
|
+
this.padding = 0.5;
|
|
67
|
+
delete this.min;
|
|
68
|
+
delete this.max;
|
|
69
|
+
delete this.minValue;
|
|
70
|
+
delete this.maxValue;
|
|
71
|
+
this.minSize = minSize;
|
|
72
|
+
this.valuesMap = {};
|
|
73
|
+
this.valueList = [];
|
|
74
|
+
this.inverted = inverted;
|
|
75
|
+
this.uniform = uniform;
|
|
76
|
+
this.valueStacks = {};
|
|
77
|
+
this.names = {};
|
|
78
|
+
this.minTickDistance = minTickDistance;
|
|
79
|
+
this.minLabelDistance = minLabelDistance;
|
|
80
|
+
|
|
81
|
+
if (values) {
|
|
82
|
+
if (isArray(values)) values.forEach((v) => this.acknowledge(v));
|
|
83
|
+
else if (typeof values == "object")
|
|
84
|
+
for (var k in values) {
|
|
85
|
+
this.acknowledge(k);
|
|
86
|
+
this.names[k] = values[k];
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
if (names) {
|
|
91
|
+
if (isArray(names)) {
|
|
92
|
+
values = values || [];
|
|
93
|
+
names.forEach((name, index) => {
|
|
94
|
+
var value = values[index];
|
|
95
|
+
this.names[value != null ? value : index] = name;
|
|
96
|
+
});
|
|
97
|
+
} else this.names = names;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
decodeValue(n) {
|
|
102
|
+
return n;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
encodeValue(v) {
|
|
106
|
+
return v;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
map(v, offset = 0) {
|
|
110
|
+
var index = this.valuesMap[v] || 0;
|
|
111
|
+
|
|
112
|
+
return this.origin + (index + offset - this.min + this.padding) * this.factor;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
measure(a, b) {
|
|
116
|
+
this.a = a;
|
|
117
|
+
this.b = b;
|
|
118
|
+
|
|
119
|
+
if (this.min == null) this.min = this.minValue || 0;
|
|
120
|
+
|
|
121
|
+
if (this.max == null) this.max = !isNaN(this.maxValue) ? this.maxValue : 100;
|
|
122
|
+
|
|
123
|
+
var sign = this.inverted ? -1 : 1;
|
|
124
|
+
|
|
125
|
+
if (this.max - this.min + 1 < this.minSize) {
|
|
126
|
+
this.factor = (sign * (this.b - this.a)) / this.minSize;
|
|
127
|
+
this.origin = (this.b + this.a) * 0.5 - (this.factor * (this.max - this.min + 1)) / 2;
|
|
128
|
+
} else {
|
|
129
|
+
this.factor = (sign * (this.b - this.a)) / (this.max - this.min + 2 * this.padding);
|
|
130
|
+
this.origin = (this.a * (1 + sign)) / 2 + (this.b * (1 - sign)) / 2; //a || b
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
this.tickSizes = [];
|
|
134
|
+
let tickMultiplier = [1, 2, 5];
|
|
135
|
+
let absFactor = Math.abs(this.factor);
|
|
136
|
+
for (let base = 1; base < 10000 && this.tickSizes.length < 2; base *= 10) {
|
|
137
|
+
for (let m of tickMultiplier) {
|
|
138
|
+
if (base * m * absFactor >= this.minTickDistance && this.tickSizes.length == 0)
|
|
139
|
+
this.tickSizes.push(base * m);
|
|
140
|
+
if (base * m * absFactor >= this.minLabelDistance) {
|
|
141
|
+
this.tickSizes.push(base * m);
|
|
142
|
+
break;
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
hash() {
|
|
149
|
+
return {
|
|
150
|
+
origin: this.origin,
|
|
151
|
+
factor: this.factor,
|
|
152
|
+
min: this.min,
|
|
153
|
+
minSize: this.minSize,
|
|
154
|
+
padding: this.padding,
|
|
155
|
+
values: this.valueList.join(":"),
|
|
156
|
+
names: JSON.stringify(this.names),
|
|
157
|
+
};
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
isSame(x) {
|
|
161
|
+
var h = this.hash();
|
|
162
|
+
var same = x && !Object.keys(h).some((k) => x[k] !== h[k]);
|
|
163
|
+
this.shouldUpdate = !same;
|
|
164
|
+
return same;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
acknowledge(value, width = 0, offset = 0) {
|
|
168
|
+
var index = this.valuesMap[value];
|
|
169
|
+
if (isUndefined(index)) {
|
|
170
|
+
index = this.valueList.length;
|
|
171
|
+
this.valueList.push(value);
|
|
172
|
+
this.valuesMap[value] = index;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
if (this.minValue == null || index < this.minValue) {
|
|
176
|
+
this.minValue = index;
|
|
177
|
+
this.padding = Math.max(this.padding, Math.abs(offset - width / 2));
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
if (this.maxValue == null || index > this.maxValue) {
|
|
181
|
+
this.maxValue = index;
|
|
182
|
+
this.padding = Math.max(this.padding, Math.abs(offset + width / 2));
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
book(value, name) {
|
|
187
|
+
if (this.uniform) value = 0;
|
|
188
|
+
|
|
189
|
+
var stack = this.valueStacks[value];
|
|
190
|
+
if (!stack)
|
|
191
|
+
stack = this.valueStacks[value] = {
|
|
192
|
+
index: {},
|
|
193
|
+
count: 0,
|
|
194
|
+
};
|
|
195
|
+
if (!stack.index.hasOwnProperty(name)) stack.index[name] = stack.count++;
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
locate(value, name) {
|
|
199
|
+
if (this.uniform) value = 0;
|
|
200
|
+
|
|
201
|
+
var stack = this.valueStacks[value];
|
|
202
|
+
if (!stack) return [0, 1];
|
|
203
|
+
|
|
204
|
+
return [stack.index[name], stack.count];
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
trackValue(v, offset = 0, constrain = false) {
|
|
208
|
+
let index = Math.round((v - this.origin) / this.factor - offset + this.min - this.padding);
|
|
209
|
+
if (index < this.min) index = this.min;
|
|
210
|
+
if (index > this.max) index = this.max;
|
|
211
|
+
return this.valueList[index];
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
findTickSize(minPxDist) {
|
|
215
|
+
for (let tickSize of this.tickSizes) if (tickSize * Math.abs(this.factor) >= minPxDist) return tickSize;
|
|
216
|
+
return 1;
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
getTickSizes() {
|
|
220
|
+
return this.tickSizes;
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
getTicks(tickSizes) {
|
|
224
|
+
return tickSizes.map((size) => this.valueList.filter((_, i) => i % size == 0));
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
mapGridlines() {
|
|
228
|
+
let result = [];
|
|
229
|
+
if (this.tickSizes.length == 0) return result;
|
|
230
|
+
let step = this.tickSizes[0];
|
|
231
|
+
for (let index = this.min; index <= this.max + 1; index += step)
|
|
232
|
+
result.push(this.origin + (index - 0.5 - this.min + this.padding) * this.factor);
|
|
233
|
+
return result;
|
|
234
|
+
}
|
|
235
|
+
}
|