cx 24.3.3 → 24.3.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.
@@ -1,252 +1,252 @@
1
- import { BoundedObject } from "../../svg/BoundedObject";
2
- import { VDOM } from "../../ui/Widget";
3
- import { isUndefined } from "../../util/isUndefined";
4
- import { parseStyle } from "../../util/parseStyle";
5
-
6
- export class Axis extends BoundedObject {
7
- init() {
8
- if (this.labelAnchor == "auto") this.labelAnchor = this.vertical ? (this.secondary ? "start" : "end") : "middle";
9
-
10
- if (this.labelDx == "auto") this.labelDx = 0;
11
-
12
- if (this.labelDy == "auto") this.labelDy = this.vertical ? "0.4em" : this.secondary ? 0 : "0.8em";
13
-
14
- if (isUndefined(this.minLabelDistance))
15
- this.minLabelDistance = this.vertical ? this.minLabelDistanceVertical : this.minLabelDistanceHorizontal;
16
-
17
- if (this.labelLineCountDyFactor == "auto")
18
- this.labelLineCountDyFactor = this.vertical ? -this.labelLineHeight / 2 : this.secondary ? -1 : 0;
19
-
20
- this.lineStyle = parseStyle(this.lineStyle);
21
- this.tickStyle = parseStyle(this.tickStyle);
22
- this.labelStyle = parseStyle(this.labelStyle);
23
-
24
- super.init();
25
- }
26
-
27
- declareData() {
28
- super.declareData(
29
- {
30
- anchors: undefined,
31
- hideLabels: undefined,
32
- hideLine: undefined,
33
- hideTicks: undefined,
34
- labelRotation: undefined,
35
- labelAnchor: undefined,
36
- lineStyle: undefined,
37
- lineClass: undefined,
38
- labelStyle: undefined,
39
- labelClass: undefined,
40
- tickStyle: undefined,
41
- tickClass: undefined,
42
- },
43
- ...arguments
44
- );
45
- }
46
-
47
- prepareData(context, instance) {
48
- super.prepareData(context, instance);
49
- if (this.onCreateLabelFormatter)
50
- instance.labelFormatter = instance.invoke("onCreateLabelFormatter", context, instance);
51
- }
52
-
53
- report(context, instance) {
54
- return instance.calculator;
55
- }
56
-
57
- renderTicksAndLabels(context, instance, valueFormatter) {
58
- if (this.hidden) return false;
59
-
60
- var { data, calculator, labelFormatter } = instance;
61
- var { bounds } = data;
62
- let { CSS, baseClass } = this;
63
- var size = calculator.findTickSize(this.minLabelDistance);
64
-
65
- var labelClass = CSS.expand(CSS.element(baseClass, "label"), data.labelClass);
66
- var offsetClass = CSS.element(baseClass, "label-offset");
67
-
68
- var x1,
69
- y1,
70
- x2,
71
- y2,
72
- tickSize = this.tickSize;
73
-
74
- if (this.vertical) {
75
- x1 = x2 = this.secondary ? bounds.r : bounds.l;
76
- y1 = bounds.b;
77
- y2 = bounds.t;
78
- } else {
79
- x1 = bounds.l;
80
- x2 = bounds.r;
81
- y1 = y2 = this.secondary ? bounds.t : bounds.b;
82
- }
83
-
84
- var res = [null, null];
85
-
86
- if (!data.hideLine) {
87
- res[0] = (
88
- <line
89
- key="line"
90
- className={CSS.expand(CSS.element(baseClass, "line"), data.lineClass)}
91
- style={data.lineStyle}
92
- x1={x1}
93
- y1={y1}
94
- x2={x2}
95
- y2={y2}
96
- />
97
- );
98
- }
99
-
100
- var t = [];
101
- if (size > 0 && !data.hideLabels) {
102
- var ticks = calculator.getTicks([size]);
103
- ticks.forEach((serie, si) => {
104
- serie.forEach((v, i) => {
105
- var s = calculator.map(v);
106
-
107
- if (this.secondary) {
108
- x1 = this.vertical ? bounds.r : s;
109
- y1 = this.vertical ? s : bounds.t;
110
- x2 = this.vertical ? bounds.r + tickSize : s;
111
- y2 = this.vertical ? s : bounds.t - tickSize;
112
- } else {
113
- x1 = this.vertical ? bounds.l : s;
114
- y1 = this.vertical ? s : bounds.b;
115
- x2 = this.vertical ? bounds.l - tickSize : s;
116
- y2 = this.vertical ? s : bounds.b + tickSize;
117
- }
118
-
119
- t.push(`M ${x1} ${y1} L ${x2} ${y2}`);
120
-
121
- var x, y;
122
- if (this.secondary) {
123
- x = this.vertical ? bounds.r + this.labelOffset : s;
124
- y = this.vertical ? s : bounds.t - this.labelOffset;
125
- } else {
126
- x = this.vertical ? bounds.l - this.labelOffset : s;
127
- y = this.vertical ? s : bounds.b + this.labelOffset;
128
- }
129
-
130
- var transform = data.labelRotation ? `rotate(${data.labelRotation} ${x} ${y})` : null;
131
- var formattedValue = valueFormatter(v);
132
- var lines = labelFormatter ? labelFormatter(formattedValue, v) : this.wrapLines(formattedValue);
133
- res.push(
134
- <text
135
- key={`label-${si}-${i}`}
136
- className={labelClass}
137
- style={data.labelStyle}
138
- x={x}
139
- y={y}
140
- textAnchor={data.labelAnchor}
141
- transform={transform}
142
- >
143
- {this.renderLabels(lines, x, this.labelDy, this.labelDx, offsetClass)}
144
- </text>
145
- );
146
- });
147
- });
148
- }
149
-
150
- if (!data.hideTicks) {
151
- res[1] = (
152
- <path
153
- key="ticks"
154
- className={CSS.expand(CSS.element(baseClass, "ticks"), data.tickClass)}
155
- style={data.tickStyle}
156
- d={t.join(" ")}
157
- />
158
- );
159
- }
160
-
161
- return res;
162
- }
163
-
164
- wrapLines(str) {
165
- if (!this.labelWrap || typeof str != "string") return [{ text: str }];
166
-
167
- let parts = str.split(" ");
168
- if (parts.length == 0) return null;
169
-
170
- let lines = [];
171
- let line = null;
172
- for (let i = 0; i < parts.length; i++) {
173
- if (!line) line = parts[i];
174
- else if (parts[i].length + line.length < this.labelMaxLineLength) line += " " + parts[i];
175
- else {
176
- lines.push({ text: line });
177
- line = parts[i];
178
- }
179
- }
180
- lines.push({ text: line });
181
- return lines;
182
- }
183
-
184
- renderLabels(lines, x, dy, dx, offsetClass) {
185
- let offset = this.labelLineCountDyFactor * (lines.length - 1);
186
- let result = [];
187
-
188
- if (lines.length > 1 && dy != null) {
189
- result.push(
190
- <tspan key={-2} className={offsetClass} dy={dy}>
191
- _
192
- </tspan>
193
- );
194
- }
195
-
196
- lines.forEach((p, i) => {
197
- result.push(
198
- <tspan
199
- key={i}
200
- dy={lines.length > 1 ? `${i == 0 ? offset : this.labelLineHeight}em` : dy}
201
- x={x}
202
- style={p.style}
203
- className={p.className}
204
- dx={dx}
205
- >
206
- {p.text}
207
- </tspan>
208
- );
209
- });
210
- return result;
211
- }
212
-
213
- prepare(context, instance) {
214
- super.prepare(context, instance);
215
- var { bounds } = instance.data;
216
- var [a, b] = !this.vertical ? [bounds.l, bounds.r] : [bounds.b, bounds.t];
217
- instance.calculator.measure(a, b);
218
- if (this.onMeasured) instance.invoke("onMeasured", instance.calculator.hash(), instance);
219
- if (!instance.calculator.isSame(instance.cached.axis)) instance.markShouldUpdate(context);
220
- }
221
-
222
- cleanup(context, instance) {
223
- var { cached, calculator } = instance;
224
- cached.axis = calculator.hash();
225
- }
226
- }
227
-
228
- Axis.prototype.anchors = "0 1 1 0";
229
- Axis.prototype.styled = true;
230
- Axis.prototype.vertical = false;
231
- Axis.prototype.secondary = false;
232
- Axis.prototype.inverted = false;
233
- Axis.prototype.hidden = false;
234
- Axis.prototype.hideLabels = false;
235
- Axis.prototype.hideTicks = false;
236
- Axis.prototype.hideLine = false;
237
-
238
- Axis.prototype.tickSize = 3;
239
- Axis.prototype.minTickDistance = 25;
240
- Axis.prototype.minLabelDistanceVertical = 40;
241
- Axis.prototype.minLabelDistanceHorizontal = 50;
242
- Axis.prototype.labelOffset = 10;
243
- Axis.prototype.labelRotation = 0;
244
- Axis.prototype.labelAnchor = "auto";
245
- Axis.prototype.labelDx = "auto";
246
- Axis.prototype.labelDy = "auto";
247
- Axis.prototype.labelWrap = false;
248
- Axis.prototype.labelLineCountDyFactor = "auto";
249
- Axis.prototype.labelLineHeight = 1;
250
- Axis.prototype.labelMaxLineLength = 10;
251
-
252
- Axis.namespace = "ui.svg.chart.axis";
1
+ import { BoundedObject } from "../../svg/BoundedObject";
2
+ import { VDOM } from "../../ui/Widget";
3
+ import { isUndefined } from "../../util/isUndefined";
4
+ import { parseStyle } from "../../util/parseStyle";
5
+
6
+ export class Axis extends BoundedObject {
7
+ init() {
8
+ if (this.labelAnchor == "auto") this.labelAnchor = this.vertical ? (this.secondary ? "start" : "end") : "middle";
9
+
10
+ if (this.labelDx == "auto") this.labelDx = 0;
11
+
12
+ if (this.labelDy == "auto") this.labelDy = this.vertical ? "0.4em" : this.secondary ? 0 : "0.8em";
13
+
14
+ if (isUndefined(this.minLabelDistance))
15
+ this.minLabelDistance = this.vertical ? this.minLabelDistanceVertical : this.minLabelDistanceHorizontal;
16
+
17
+ if (this.labelLineCountDyFactor == "auto")
18
+ this.labelLineCountDyFactor = this.vertical ? -this.labelLineHeight / 2 : this.secondary ? -1 : 0;
19
+
20
+ this.lineStyle = parseStyle(this.lineStyle);
21
+ this.tickStyle = parseStyle(this.tickStyle);
22
+ this.labelStyle = parseStyle(this.labelStyle);
23
+
24
+ super.init();
25
+ }
26
+
27
+ declareData() {
28
+ super.declareData(
29
+ {
30
+ anchors: undefined,
31
+ hideLabels: undefined,
32
+ hideLine: undefined,
33
+ hideTicks: undefined,
34
+ labelRotation: undefined,
35
+ labelAnchor: undefined,
36
+ lineStyle: undefined,
37
+ lineClass: undefined,
38
+ labelStyle: undefined,
39
+ labelClass: undefined,
40
+ tickStyle: undefined,
41
+ tickClass: undefined,
42
+ },
43
+ ...arguments
44
+ );
45
+ }
46
+
47
+ prepareData(context, instance) {
48
+ super.prepareData(context, instance);
49
+ if (this.onCreateLabelFormatter)
50
+ instance.labelFormatter = instance.invoke("onCreateLabelFormatter", context, instance);
51
+ }
52
+
53
+ report(context, instance) {
54
+ return instance.calculator;
55
+ }
56
+
57
+ renderTicksAndLabels(context, instance, valueFormatter) {
58
+ if (this.hidden) return false;
59
+
60
+ var { data, calculator, labelFormatter } = instance;
61
+ var { bounds } = data;
62
+ let { CSS, baseClass } = this;
63
+ var size = calculator.findTickSize(this.minLabelDistance);
64
+
65
+ var labelClass = CSS.expand(CSS.element(baseClass, "label"), data.labelClass);
66
+ var offsetClass = CSS.element(baseClass, "label-offset");
67
+
68
+ var x1,
69
+ y1,
70
+ x2,
71
+ y2,
72
+ tickSize = this.tickSize;
73
+
74
+ if (this.vertical) {
75
+ x1 = x2 = this.secondary ? bounds.r : bounds.l;
76
+ y1 = bounds.b;
77
+ y2 = bounds.t;
78
+ } else {
79
+ x1 = bounds.l;
80
+ x2 = bounds.r;
81
+ y1 = y2 = this.secondary ? bounds.t : bounds.b;
82
+ }
83
+
84
+ var res = [null, null];
85
+
86
+ if (!data.hideLine) {
87
+ res[0] = (
88
+ <line
89
+ key="line"
90
+ className={CSS.expand(CSS.element(baseClass, "line"), data.lineClass)}
91
+ style={data.lineStyle}
92
+ x1={x1}
93
+ y1={y1}
94
+ x2={x2}
95
+ y2={y2}
96
+ />
97
+ );
98
+ }
99
+
100
+ var t = [];
101
+ if (size > 0 && !data.hideLabels) {
102
+ var ticks = calculator.getTicks([size]);
103
+ ticks.forEach((serie, si) => {
104
+ serie.forEach((v, i) => {
105
+ var s = calculator.map(v);
106
+
107
+ if (this.secondary) {
108
+ x1 = this.vertical ? bounds.r : s;
109
+ y1 = this.vertical ? s : bounds.t;
110
+ x2 = this.vertical ? bounds.r + tickSize : s;
111
+ y2 = this.vertical ? s : bounds.t - tickSize;
112
+ } else {
113
+ x1 = this.vertical ? bounds.l : s;
114
+ y1 = this.vertical ? s : bounds.b;
115
+ x2 = this.vertical ? bounds.l - tickSize : s;
116
+ y2 = this.vertical ? s : bounds.b + tickSize;
117
+ }
118
+
119
+ t.push(`M ${x1} ${y1} L ${x2} ${y2}`);
120
+
121
+ var x, y;
122
+ if (this.secondary) {
123
+ x = this.vertical ? bounds.r + this.labelOffset : s;
124
+ y = this.vertical ? s : bounds.t - this.labelOffset;
125
+ } else {
126
+ x = this.vertical ? bounds.l - this.labelOffset : s;
127
+ y = this.vertical ? s : bounds.b + this.labelOffset;
128
+ }
129
+
130
+ var transform = data.labelRotation ? `rotate(${data.labelRotation} ${x} ${y})` : null;
131
+ var formattedValue = valueFormatter(v);
132
+ var lines = labelFormatter ? labelFormatter(formattedValue, v) : this.wrapLines(formattedValue);
133
+ res.push(
134
+ <text
135
+ key={`label-${si}-${i}`}
136
+ className={labelClass}
137
+ style={data.labelStyle}
138
+ x={x}
139
+ y={y}
140
+ textAnchor={data.labelAnchor}
141
+ transform={transform}
142
+ >
143
+ {this.renderLabels(lines, x, this.labelDy, this.labelDx, offsetClass)}
144
+ </text>
145
+ );
146
+ });
147
+ });
148
+ }
149
+
150
+ if (!data.hideTicks) {
151
+ res[1] = (
152
+ <path
153
+ key="ticks"
154
+ className={CSS.expand(CSS.element(baseClass, "ticks"), data.tickClass)}
155
+ style={data.tickStyle}
156
+ d={t.join(" ")}
157
+ />
158
+ );
159
+ }
160
+
161
+ return res;
162
+ }
163
+
164
+ wrapLines(str) {
165
+ if (!this.labelWrap || typeof str != "string") return [{ text: str }];
166
+
167
+ let parts = str.split(" ");
168
+ if (parts.length == 0) return null;
169
+
170
+ let lines = [];
171
+ let line = null;
172
+ for (let i = 0; i < parts.length; i++) {
173
+ if (!line) line = parts[i];
174
+ else if (parts[i].length + line.length < this.labelMaxLineLength) line += " " + parts[i];
175
+ else {
176
+ lines.push({ text: line });
177
+ line = parts[i];
178
+ }
179
+ }
180
+ lines.push({ text: line });
181
+ return lines;
182
+ }
183
+
184
+ renderLabels(lines, x, dy, dx, offsetClass) {
185
+ let offset = this.labelLineCountDyFactor * (lines.length - 1);
186
+ let result = [];
187
+
188
+ if (lines.length > 1 && dy != null) {
189
+ result.push(
190
+ <tspan key={-2} className={offsetClass} dy={dy}>
191
+ _
192
+ </tspan>
193
+ );
194
+ }
195
+
196
+ lines.forEach((p, i) => {
197
+ result.push(
198
+ <tspan
199
+ key={i}
200
+ dy={lines.length > 1 ? `${i == 0 ? offset : this.labelLineHeight}em` : dy}
201
+ x={x}
202
+ style={p.style}
203
+ className={p.className}
204
+ dx={dx}
205
+ >
206
+ {p.text}
207
+ </tspan>
208
+ );
209
+ });
210
+ return result;
211
+ }
212
+
213
+ prepare(context, instance) {
214
+ super.prepare(context, instance);
215
+ var { bounds } = instance.data;
216
+ var [a, b] = !this.vertical ? [bounds.l, bounds.r] : [bounds.b, bounds.t];
217
+ instance.calculator.measure(a, b);
218
+ if (this.onMeasured) instance.invoke("onMeasured", instance.calculator.hash(), instance);
219
+ if (!instance.calculator.isSame(instance.cached.axis)) instance.markShouldUpdate(context);
220
+ }
221
+
222
+ cleanup(context, instance) {
223
+ var { cached, calculator } = instance;
224
+ cached.axis = calculator.hash();
225
+ }
226
+ }
227
+
228
+ Axis.prototype.anchors = "0 1 1 0";
229
+ Axis.prototype.styled = true;
230
+ Axis.prototype.vertical = false;
231
+ Axis.prototype.secondary = false;
232
+ Axis.prototype.inverted = false;
233
+ Axis.prototype.hidden = false;
234
+ Axis.prototype.hideLabels = false;
235
+ Axis.prototype.hideTicks = false;
236
+ Axis.prototype.hideLine = false;
237
+
238
+ Axis.prototype.tickSize = 3;
239
+ Axis.prototype.minTickDistance = 25;
240
+ Axis.prototype.minLabelDistanceVertical = 40;
241
+ Axis.prototype.minLabelDistanceHorizontal = 50;
242
+ Axis.prototype.labelOffset = 10;
243
+ Axis.prototype.labelRotation = 0;
244
+ Axis.prototype.labelAnchor = "auto";
245
+ Axis.prototype.labelDx = "auto";
246
+ Axis.prototype.labelDy = "auto";
247
+ Axis.prototype.labelWrap = false;
248
+ Axis.prototype.labelLineCountDyFactor = "auto";
249
+ Axis.prototype.labelLineHeight = 1;
250
+ Axis.prototype.labelMaxLineLength = 10;
251
+
252
+ Axis.namespace = "ui.svg.chart.axis";
@@ -1,21 +1,20 @@
1
- @import "axis/variables";
2
-
3
- $cx-default-swimlanes-lane-background-color: #f1f1f1;
4
-
5
- $cx-dependencies: map-merge(
6
- $cx-dependencies,
7
- (
8
- "cx/charts/Bar": "cx/charts/palette",
9
- "cx/charts/BarGraph": "cx/charts/palette",
10
- "cx/charts/Column": "cx/charts/palette",
11
- "cx/charts/ColumnGraph": "cx/charts/palette",
12
- "cx/charts/LineGraph": "cx/charts/palette",
13
- "cx/charts/ColorMap": "cx/charts/palette",
14
- "cx/charts/ScatterGraph": "cx/charts/palette",
15
- "cx/charts/BubbleGraph": "cx/charts/palette",
16
- "cx/charts/MarkerLine": "cx/charts/palette",
17
- "cx/charts/Marker": "cx/charts/palette",
18
- "cx/charts/PieChart": "cx/charts/palette",
19
- "cx/charts/Swimlanes": "cx/charts/Swimlanes",
20
- )
21
- );
1
+ @import "axis/variables";
2
+
3
+ $cx-default-swimlanes-lane-background-color: #f1f1f1;
4
+
5
+ $cx-dependencies: map-merge(
6
+ $cx-dependencies,
7
+ (
8
+ "cx/charts/Bar": "cx/charts/palette",
9
+ "cx/charts/BarGraph": "cx/charts/palette",
10
+ "cx/charts/Column": "cx/charts/palette",
11
+ "cx/charts/ColumnGraph": "cx/charts/palette",
12
+ "cx/charts/LineGraph": "cx/charts/palette",
13
+ "cx/charts/ColorMap": "cx/charts/palette",
14
+ "cx/charts/ScatterGraph": "cx/charts/palette",
15
+ "cx/charts/BubbleGraph": "cx/charts/palette",
16
+ "cx/charts/MarkerLine": "cx/charts/palette",
17
+ "cx/charts/Marker": "cx/charts/palette",
18
+ "cx/charts/PieChart": "cx/charts/palette",
19
+ )
20
+ );