@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.
@@ -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.type !== 'bar' &&
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 totalSum = this.items.reduce((sum, item) => sum + this.getMaximumValue(item), 0);
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
  };