@limetech/lime-elements 40.0.3 → 40.1.0
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/CHANGELOG.md +11 -0
- package/dist/cjs/lime-elements.cjs.js +1 -1
- package/dist/cjs/limel-chart.cjs.entry.js +60 -10
- package/dist/cjs/limel-form.cjs.entry.js +1590 -335
- package/dist/cjs/limel-prosemirror-adapter.cjs.entry.js +6 -5
- package/dist/cjs/loader.cjs.js +1 -1
- package/dist/collection/components/chart/chart.js +83 -12
- package/dist/esm/lime-elements.js +1 -1
- package/dist/esm/limel-chart.entry.js +60 -10
- package/dist/esm/limel-form.entry.js +1590 -335
- package/dist/esm/limel-prosemirror-adapter.entry.js +6 -5
- package/dist/esm/loader.js +1 -1
- package/dist/lime-elements/lime-elements.esm.js +1 -1
- package/dist/lime-elements/p-1b25f158.entry.js +13 -0
- package/dist/lime-elements/p-73d9f0f6.entry.js +1 -0
- package/dist/lime-elements/{p-72a1d432.entry.js → p-d3d71a68.entry.js} +1 -1
- package/dist/types/components/chart/chart.d.ts +28 -4
- package/dist/types/components.d.ts +19 -4
- package/package.json +2 -2
- package/dist/lime-elements/p-21b54196.entry.js +0 -13
- package/dist/lime-elements/p-9ed9d0de.entry.js +0 -1
|
@@ -6,6 +6,16 @@ const chartCss = () => `@charset "UTF-8";:host(limel-chart[type=bar]) .chart,:ho
|
|
|
6
6
|
|
|
7
7
|
const PERCENT = 100;
|
|
8
8
|
const DEFAULT_INCREMENT_SIZE = 10;
|
|
9
|
+
/**
|
|
10
|
+
* Types whose items are parts of one whole. They draw no axis, and an item's
|
|
11
|
+
* value or range extent is its share of `maxValue`, or of the combined items.
|
|
12
|
+
*/
|
|
13
|
+
const WHOLE_TYPES = new Set([
|
|
14
|
+
'stacked-bar',
|
|
15
|
+
'pie',
|
|
16
|
+
'doughnut',
|
|
17
|
+
'ring',
|
|
18
|
+
]);
|
|
9
19
|
const Chart = class {
|
|
10
20
|
constructor(hostRef) {
|
|
11
21
|
registerInstance(this, hostRef);
|
|
@@ -34,6 +44,13 @@ const Chart = class {
|
|
|
34
44
|
* Only affects chart types with X and Y axes, such as area, bar, and line charts.
|
|
35
45
|
*/
|
|
36
46
|
this.displayItemValue = false;
|
|
47
|
+
/**
|
|
48
|
+
* Set to `false` to hide the percentage in item tooltips.
|
|
49
|
+
* The percentage is an item's value or range extent as a share of the
|
|
50
|
+
* whole. The whole is `maxValue` when set and the combined items otherwise.
|
|
51
|
+
* Applies to `stacked-bar`, `pie`, `doughnut`, and `ring` charts.
|
|
52
|
+
*/
|
|
53
|
+
this.displayItemPercentage = true;
|
|
37
54
|
/**
|
|
38
55
|
* Defines how items are visualized in the chart.
|
|
39
56
|
*/
|
|
@@ -191,6 +208,12 @@ const Chart = class {
|
|
|
191
208
|
offset: 0,
|
|
192
209
|
};
|
|
193
210
|
}
|
|
211
|
+
if (this.isPartOfWhole()) {
|
|
212
|
+
return {
|
|
213
|
+
size: (this.getValueSpan(item) / totalRange) * PERCENT,
|
|
214
|
+
offset: 0,
|
|
215
|
+
};
|
|
216
|
+
}
|
|
194
217
|
let startValue = 0;
|
|
195
218
|
if (this.isRangeItem(item)) {
|
|
196
219
|
startValue = this.getMinimumValue(item);
|
|
@@ -227,10 +250,7 @@ const Chart = class {
|
|
|
227
250
|
helperLabel: formattedValue,
|
|
228
251
|
elementId: itemId,
|
|
229
252
|
};
|
|
230
|
-
if (this.
|
|
231
|
-
this.type !== 'dot' &&
|
|
232
|
-
this.type !== 'nps' &&
|
|
233
|
-
this.type !== 'scatter') {
|
|
253
|
+
if (this.displayItemPercentage && this.isPartOfWhole()) {
|
|
234
254
|
tooltipProps.label = `${text} (${size.toFixed(PERCENT_DECIMAL)}%)`;
|
|
235
255
|
}
|
|
236
256
|
return (h("limel-tooltip", Object.assign({}, tooltipProps, { openDirection: this.orientation === 'portrait' ? 'right' : 'top' })));
|
|
@@ -240,14 +260,12 @@ const Chart = class {
|
|
|
240
260
|
if (this.range) {
|
|
241
261
|
return this.range;
|
|
242
262
|
}
|
|
263
|
+
if (this.isPartOfWhole()) {
|
|
264
|
+
return this.calculateWholeRange();
|
|
265
|
+
}
|
|
243
266
|
const minRange = Math.min(0, ...this.items.map(this.getMinimumValue));
|
|
244
267
|
const maxRange = Math.max(...this.items.map(this.getMaximumValue));
|
|
245
|
-
const
|
|
246
|
-
let finalMaxRange = (_a = this.maxValue) !== null && _a !== void 0 ? _a : maxRange;
|
|
247
|
-
if ((this.type === 'pie' || this.type === 'doughnut') &&
|
|
248
|
-
!this.maxValue) {
|
|
249
|
-
finalMaxRange = totalSum;
|
|
250
|
-
}
|
|
268
|
+
const finalMaxRange = (_a = this.maxValue) !== null && _a !== void 0 ? _a : maxRange;
|
|
251
269
|
if (!this.axisIncrement) {
|
|
252
270
|
this.axisIncrement = this.calculateAxisIncrement(this.items.map(this.getMaximumValue));
|
|
253
271
|
}
|
|
@@ -261,6 +279,29 @@ const Chart = class {
|
|
|
261
279
|
increment: this.axisIncrement,
|
|
262
280
|
};
|
|
263
281
|
}
|
|
282
|
+
/**
|
|
283
|
+
* The range of a chart whose items are parts of one whole: `maxValue`
|
|
284
|
+
* when set, otherwise the combined item values or range extents. The value
|
|
285
|
+
* is a scale, not a cap, so the combined size can exceed it. The whole is
|
|
286
|
+
* not rounded to an axis step, since these types draw no axis and an item's
|
|
287
|
+
* size has to be its exact share.
|
|
288
|
+
*/
|
|
289
|
+
calculateWholeRange() {
|
|
290
|
+
var _a;
|
|
291
|
+
const sum = this.items.reduce((total, item) => total + this.getValueSpan(item), 0);
|
|
292
|
+
const inferredWhole = sum > 0 ? sum : 1;
|
|
293
|
+
// An explicit zero also falls back to 1, so normalization stays finite.
|
|
294
|
+
const whole = ((_a = this.maxValue) !== null && _a !== void 0 ? _a : inferredWhole) || 1;
|
|
295
|
+
return {
|
|
296
|
+
minValue: 0,
|
|
297
|
+
maxValue: whole,
|
|
298
|
+
totalRange: whole,
|
|
299
|
+
increment: whole,
|
|
300
|
+
};
|
|
301
|
+
}
|
|
302
|
+
isPartOfWhole() {
|
|
303
|
+
return WHOLE_TYPES.has(this.type);
|
|
304
|
+
}
|
|
264
305
|
calculateAxisIncrement(values, steps = DEFAULT_INCREMENT_SIZE) {
|
|
265
306
|
return this.calculateNiceStep(Math.max(...values), steps);
|
|
266
307
|
}
|
|
@@ -314,6 +355,12 @@ const Chart = class {
|
|
|
314
355
|
const value = item.value;
|
|
315
356
|
return Array.isArray(value) ? Math.max(...value) : value;
|
|
316
357
|
}
|
|
358
|
+
getValueSpan(item) {
|
|
359
|
+
const startValue = this.isRangeItem(item)
|
|
360
|
+
? this.getMinimumValue(item)
|
|
361
|
+
: 0;
|
|
362
|
+
return this.getMaximumValue(item) - startValue;
|
|
363
|
+
}
|
|
317
364
|
isRangeItem(item) {
|
|
318
365
|
return Array.isArray(item.value);
|
|
319
366
|
}
|
|
@@ -359,6 +406,9 @@ const Chart = class {
|
|
|
359
406
|
}],
|
|
360
407
|
"maxValue": [{
|
|
361
408
|
"handleChange": 0
|
|
409
|
+
}],
|
|
410
|
+
"type": [{
|
|
411
|
+
"handleChange": 0
|
|
362
412
|
}]
|
|
363
413
|
}; }
|
|
364
414
|
};
|