@watermarkinsights/ripple 5.13.0-alpha.2 → 5.13.0-alpha.4

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.
Files changed (57) hide show
  1. package/dist/ripple/app-globals-B7cOtGhY.js +170 -0
  2. package/dist/ripple/chartFunctions-KaEM0xh0.js +715 -0
  3. package/dist/ripple/functions-Dtrjc9kR.js +18092 -0
  4. package/dist/ripple/index-CU5QNCKv.js +4167 -0
  5. package/dist/ripple/index.esm.js +1 -0
  6. package/dist/ripple/interfaces-CrANcZM9.js +53 -0
  7. package/dist/ripple/intl-BMoOWb_l.js +277 -0
  8. package/dist/ripple/priv-calendar.entry.js +566 -0
  9. package/dist/ripple/priv-chart-popover.entry.js +134 -0
  10. package/dist/ripple/priv-navigator-button.entry.js +24 -0
  11. package/dist/ripple/priv-navigator-item.entry.js +30 -0
  12. package/dist/ripple/priv-option-list.entry.js +385 -0
  13. package/dist/ripple/ripple.css +1645 -0
  14. package/dist/ripple/ripple.esm.js +48 -0
  15. package/dist/ripple/wm-action-menu.entry.js +201 -0
  16. package/dist/ripple/wm-button.entry.js +197 -0
  17. package/dist/ripple/wm-chart-slice.entry.js +18 -0
  18. package/dist/ripple/wm-chart.entry.js +157 -0
  19. package/dist/ripple/wm-date-range.entry.js +477 -0
  20. package/dist/ripple/wm-datepicker.entry.js +247 -0
  21. package/dist/ripple/wm-file-list.entry.js +18 -0
  22. package/dist/ripple/wm-file.entry.js +182 -0
  23. package/dist/ripple/wm-input.entry.js +111 -0
  24. package/dist/ripple/wm-line-chart.entry.js +449 -0
  25. package/dist/ripple/wm-menuitem.entry.js +125 -0
  26. package/dist/ripple/wm-modal-footer.entry.js +44 -0
  27. package/dist/ripple/wm-modal-header.entry.js +36 -0
  28. package/dist/ripple/wm-modal-pss-footer.entry.js +40 -0
  29. package/dist/ripple/wm-modal-pss-header.entry.js +39 -0
  30. package/dist/ripple/wm-modal-pss.entry.js +135 -0
  31. package/dist/ripple/wm-modal.entry.js +133 -0
  32. package/dist/ripple/wm-navigation-hamburger.entry.js +48 -0
  33. package/dist/ripple/wm-navigation-item.entry.js +18 -0
  34. package/dist/ripple/wm-navigation.entry.js +116 -0
  35. package/dist/ripple/wm-navigator.entry.js +368 -0
  36. package/dist/ripple/wm-nested-select.entry.js +308 -0
  37. package/dist/ripple/wm-optgroup.entry.js +68 -0
  38. package/dist/ripple/wm-option.entry.js +171 -0
  39. package/dist/ripple/wm-pagination.entry.js +223 -0
  40. package/dist/ripple/wm-progress-indicator.entry.js +107 -0
  41. package/dist/ripple/wm-progress-monitor.entry.js +71 -0
  42. package/dist/ripple/wm-progress-slice.entry.js +13 -0
  43. package/dist/ripple/wm-search.entry.js +208 -0
  44. package/dist/ripple/wm-select.entry.js +249 -0
  45. package/dist/ripple/wm-snackbar.entry.js +178 -0
  46. package/dist/ripple/wm-tab-item.entry.js +63 -0
  47. package/dist/ripple/wm-tab-list.entry.js +175 -0
  48. package/dist/ripple/wm-tab-panel.entry.js +32 -0
  49. package/dist/ripple/wm-tag-input.entry.js +877 -0
  50. package/dist/ripple/wm-tag-option.entry.js +35 -0
  51. package/dist/ripple/wm-textarea.entry.js +79 -0
  52. package/dist/ripple/wm-timepicker.entry.js +300 -0
  53. package/dist/ripple/wm-toggletip.entry.js +176 -0
  54. package/dist/ripple/wm-uploader.entry.js +313 -0
  55. package/dist/ripple/wm-wrapper.entry.js +17 -0
  56. package/package.json +30 -6
  57. package/dist/types/test-setup.d.ts +0 -0
@@ -0,0 +1,715 @@
1
+ import { h } from './index-CU5QNCKv.js';
2
+ import { i as intl, B as getPosition, u as checkForActiveElInShadow, C as safeMultiplyFloat } from './functions-Dtrjc9kR.js';
3
+
4
+ const colors = {
5
+ salmon: "#ff5f4e",
6
+ cyan: "#19a1a9",
7
+ forest: "#088000",
8
+ sleet: "#7f97ad",
9
+ midnight: "#2e1b46",
10
+ lavender: "#8b86ca",
11
+ periwinkle: "#575195",
12
+ gray: "#6b6b6b",
13
+ };
14
+ const allChartsDetails = {
15
+ // for progress monitor
16
+ doughnut: {
17
+ size: 155,
18
+ colors: [colors.forest, colors.gray],
19
+ thickness: 0.73,
20
+ padding: 25,
21
+ category: "doughnut",
22
+ },
23
+ doughnut1: {
24
+ size: 130,
25
+ colors: [colors.lavender, colors.midnight, colors.gray],
26
+ thickness: 0.5,
27
+ padding: 90,
28
+ category: "doughnut",
29
+ },
30
+ doughnut2: {
31
+ size: 130,
32
+ colors: [colors.periwinkle, colors.cyan, colors.midnight, colors.salmon, colors.gray],
33
+ thickness: 0.5,
34
+ padding: 90,
35
+ category: "doughnut",
36
+ },
37
+ doughnut3: {
38
+ size: 130,
39
+ colors: [colors.lavender, colors.midnight, "#0089e4", colors.forest, "#ea8500", "#d54f41", "#146ca9"],
40
+ thickness: 0.5,
41
+ padding: 90,
42
+ category: "doughnut",
43
+ },
44
+ // for progress monitor
45
+ bar: {
46
+ size: 350,
47
+ colors: [colors.forest, colors.gray],
48
+ padding: 0,
49
+ category: "stackedBar",
50
+ },
51
+ bar2: {
52
+ size: 400,
53
+ colors: [colors.gray, colors.lavender, colors.periwinkle, colors.midnight, colors.cyan, colors.salmon],
54
+ padding: 0,
55
+ category: "stackedBar",
56
+ },
57
+ bar3: {
58
+ size: 300,
59
+ colors: ["#0d696e", colors.cyan, "#8e4129", colors.salmon],
60
+ padding: 0,
61
+ category: "stackedBar",
62
+ },
63
+ bar4: {
64
+ size: 400,
65
+ colors: [colors.salmon, colors.cyan, colors.periwinkle],
66
+ padding: 0,
67
+ category: "stackedBar",
68
+ },
69
+ bar5: {
70
+ size: 400,
71
+ colors: [
72
+ colors.gray, // this is only used if prop notStartedColor is set
73
+ colors.lavender,
74
+ colors.midnight,
75
+ "#0089e4",
76
+ colors.forest,
77
+ "#ea8500",
78
+ "#d54f41",
79
+ "#146ca9",
80
+ ],
81
+ padding: 0,
82
+ category: "stackedBar",
83
+ },
84
+ bar6: {
85
+ size: 400,
86
+ colors: [colors.lavender],
87
+ padding: 0,
88
+ category: "simpleBar",
89
+ },
90
+ bar7: {
91
+ size: 400,
92
+ colors: [colors.periwinkle, colors.cyan, colors.salmon, colors.gray],
93
+ padding: 0,
94
+ category: "simpleBar",
95
+ },
96
+ };
97
+ function showValue(valueFormat) {
98
+ return valueFormat === "percentage" || valueFormat === "amount" ? "show-values" : "";
99
+ }
100
+ const textHiddenMessage = intl.formatMessage({
101
+ id: "chart.hiddenValues",
102
+ defaultMessage: "Values are hidden when too close together.",
103
+ description: "Text displayed when a chart has some values hidden",
104
+ });
105
+ const seeDetailsMessage = intl.formatMessage({
106
+ id: "chart.clickToSeeDetails",
107
+ defaultMessage: "Click or use arrow keys to see details.",
108
+ description: "Text displayed, guiding user to interact to see more details.",
109
+ });
110
+ function abbrNumber(num) {
111
+ return num > 999 || num < -999 ? Math.round(num / 100) / 10 + "K" : num;
112
+ }
113
+ function amountToPercent(val, total, asInt) {
114
+ return asInt ? Math.round((val * 100) / total) : Math.round((val * 10000) / total) / 100; // with 2 decimals
115
+ }
116
+ function amountToDegree(val, total) {
117
+ // In a circle of {total}, determine degrees of slice {val}
118
+ return (val * 360) / total;
119
+ }
120
+ function toFixed(number) {
121
+ return parseFloat((Math.floor(number * 100) / 100).toFixed(2));
122
+ }
123
+ function polarToCartesian(half, radius, startAngle, endAngle) {
124
+ var x = toFixed(half + half * radius * Math.cos((Math.PI * startAngle) / 180));
125
+ var y = toFixed(half + half * radius * Math.sin((Math.PI * startAngle) / 180));
126
+ if (endAngle !== undefined) {
127
+ // if a 2nd angle value was passed, return 2 pairs of coords
128
+ var x2 = toFixed(half + half * radius * Math.cos((Math.PI * endAngle) / 180));
129
+ var y2 = toFixed(half + half * radius * Math.sin((Math.PI * endAngle) / 180));
130
+ return { x1: x, y1: y, x2, y2 };
131
+ }
132
+ return { x, y };
133
+ }
134
+ function getArc(radius, largeArcFlag, x, y, chartSize) {
135
+ var z = toFixed((chartSize / 2) * radius);
136
+ return `A ${z}, ${z} 0 ${largeArcFlag} ${toFixed(x)}, ${toFixed(y)}`;
137
+ }
138
+ function scale(val, inMin, inMax, outMin, outMax) {
139
+ let scaled = ((val - inMin) * (outMax - outMin)) / (inMax - inMin) + outMin;
140
+ // clip the values so that whatever is passed in the output is never smaller than outMin or greater than outMax
141
+ return scaled < outMin ? outMin : scaled > outMax ? outMax : scaled;
142
+ }
143
+ function minSpacing(width) {
144
+ // minimum spacing between 2 ticks, in px
145
+ return scale(width, 300, 900, 70, 150);
146
+ }
147
+ function getMaxTicks(width) {
148
+ return Math.round(width / minSpacing(width));
149
+ }
150
+ function getInterval(largest, maxticks) {
151
+ const minimum = largest / maxticks;
152
+ const magnitude = 10 ** Math.floor(Math.log10(minimum));
153
+ const residual = minimum / magnitude;
154
+ let interval;
155
+ if (residual > 5) {
156
+ interval = 10 * magnitude;
157
+ }
158
+ else if (residual > 3) {
159
+ interval = 5 * magnitude;
160
+ }
161
+ else if (residual > 2) {
162
+ interval = 3 * magnitude;
163
+ }
164
+ else if (residual > 1.5) {
165
+ interval = 2 * magnitude;
166
+ }
167
+ else if (residual > 1) {
168
+ interval = 1.5 * magnitude;
169
+ }
170
+ else {
171
+ interval = magnitude;
172
+ }
173
+ return interval;
174
+ }
175
+ function handleSliceKeyDown(ev) {
176
+ if (this.popoverEl && this.popoverEl.open && ev.key === "Enter") {
177
+ const popoverBtn = this.popoverEl.querySelector("button");
178
+ popoverBtn && popoverBtn.click();
179
+ }
180
+ }
181
+ function handleSliceClick(ev, s) {
182
+ if (this.popoverEl && !this.isTabbing) {
183
+ s.coords = { x: ev.clientX, y: ev.clientY };
184
+ openPopover(this.popoverEl, s);
185
+ highlightSegmentInfo(Array.from(this.el.shadowRoot.querySelectorAll("[data-segmentindex")), s);
186
+ }
187
+ }
188
+ function handleSliceFocus(ev, s) {
189
+ if (this.popoverEl && this.isTabbing) {
190
+ this.focusedSliceId = s.id;
191
+ s.coords = getPosition(ev.target);
192
+ s.coords.x = s.coords.x + 30;
193
+ s.coords.y = s.coords.y + 30;
194
+ openPopover(this.popoverEl, s);
195
+ highlightSegmentInfo(Array.from(this.el.shadowRoot.querySelectorAll("[data-segmentindex")), s);
196
+ }
197
+ }
198
+ function handleChartKeydown(ev) {
199
+ switch (ev.key) {
200
+ // arrow up / left
201
+ case "ArrowUp":
202
+ case "ArrowLeft":
203
+ ev.preventDefault();
204
+ this.isTabbing = true; // shd already be true. just in case user clicked on chart then pressed an arrow key
205
+ focusPrevious.call(this);
206
+ break;
207
+ // arrow right / down
208
+ case "ArrowRight":
209
+ case "ArrowDown":
210
+ ev.preventDefault();
211
+ this.isTabbing = true; // shd already be true. just in case user clicked on chart then pressed an arrow key
212
+ focusNext.call(this);
213
+ break;
214
+ // tab
215
+ case "Tab":
216
+ exitChart.call(this);
217
+ break;
218
+ case "Escape":
219
+ this.popoverEl.open = false;
220
+ this.userIsNavigating = false;
221
+ break;
222
+ }
223
+ }
224
+ function openPopover(popoverEl, s) {
225
+ popoverEl.open = false;
226
+ if (s.title && s.text) {
227
+ popoverEl.sliceDetails = Object.assign({}, s);
228
+ window.setTimeout(() => (popoverEl.open = true), 30);
229
+ }
230
+ }
231
+ function focusNext() {
232
+ const activeEl = checkForActiveElInShadow(document.activeElement);
233
+ const index =
234
+ // if the active el is not in the array the first element gets focused
235
+ (this.sliceEls.indexOf(activeEl) + 1) % this.sliceEls.length;
236
+ focusSlice.call(this, index);
237
+ }
238
+ function focusPrevious() {
239
+ if (this.sliceEls) {
240
+ const activeEl = checkForActiveElInShadow(document.activeElement);
241
+ let index = this.sliceEls.indexOf(activeEl);
242
+ if (index === -1) {
243
+ // not in the array : focus the first slice
244
+ index = 0;
245
+ }
246
+ else if (index === 0) {
247
+ // first slice : focus the last slice
248
+ index = this.sliceEls.length - 1;
249
+ }
250
+ else {
251
+ // anything else: focus previous
252
+ index -= 1;
253
+ }
254
+ focusSlice.call(this, index);
255
+ }
256
+ }
257
+ function focusSlice(index) {
258
+ if (this.sliceEls && this.el) {
259
+ this.userIsNavigating = true;
260
+ // set tabindex of the wrapper to -1 while slices are being focused, to allow for shft-tabbing out of the component directly
261
+ this.componentWrapperEl.tabIndex = -1;
262
+ // @ts-ignore
263
+ this.el.focusable = false; // for Edge
264
+ this.sliceEls.map((p) => {
265
+ p.tabIndex = -1;
266
+ // @ts-ignore
267
+ p.focusable = false; // for Edge
268
+ });
269
+ this.sliceEls[index].tabIndex = 0;
270
+ // @ts-ignore
271
+ this.sliceEls[index].focusable = true; // for Edge
272
+ this.sliceEls[index].focus();
273
+ // for keyboard focus on doughnuts
274
+ this.focusedSliceId = this.sliceEls[index].id;
275
+ window.setTimeout(() => {
276
+ if (this.popoverEl) {
277
+ this.popoverEl.open = true;
278
+ }
279
+ }, 10);
280
+ }
281
+ }
282
+ function exitChart() {
283
+ this.focusedSliceId = undefined;
284
+ this.sliceEls &&
285
+ this.sliceEls.map((p) => {
286
+ p.tabIndex = -1;
287
+ // @ts-ignore
288
+ p.focusable = false; // for Edge
289
+ });
290
+ this.userIsNavigating = false;
291
+ // delay so that we can tab out of component before chart becomes focusable again
292
+ // and in case user was still pressing an arrow key when they pressed tab
293
+ window.setTimeout(() => {
294
+ this.componentWrapperEl.tabIndex = 0;
295
+ // @ts-ignore
296
+ this.el.focusable = true; // for Edge
297
+ if (this.popoverEl) {
298
+ this.popoverEl.open = false;
299
+ }
300
+ }, 100);
301
+ }
302
+ async function getDetails(chartType) {
303
+ this.slicesDetails = [];
304
+ let acc = 0;
305
+ const children = Array.from(this.el.children);
306
+ this.total = children.reduce((total, slice) => (total += parseInt(slice.getAttribute("amount") || "0")), 0);
307
+ let chartColors = [...allChartsDetails[chartType].colors];
308
+ if (this.chartType === "bar2") {
309
+ if (children.length <= 5) {
310
+ // remove lavender
311
+ chartColors.splice(1, 1);
312
+ }
313
+ if (children.length <= 4) {
314
+ // remove midnight
315
+ chartColors.splice(2, 1);
316
+ }
317
+ }
318
+ // Set colors when bar3 has only 2 slices
319
+ if (chartType === "bar3" && children.length === 2) {
320
+ chartColors = [chartColors[1], chartColors[3]];
321
+ }
322
+ // Set colors when doughnut2 has less than 5 slices
323
+ // (rm 2nd neutral color midnight)
324
+ if (chartType === "doughnut2" && children.length < 5) {
325
+ chartColors.splice(2, 1);
326
+ // with 3 slices or less, also remove first color
327
+ // (only pos, neg and unknown remain)
328
+ if (children.length < 4) {
329
+ chartColors.shift();
330
+ }
331
+ }
332
+ // for bar5, first color should be skipped unless notStartedColor is set to true
333
+ if (chartType === "bar5" && !this.notStartedColor) {
334
+ chartColors.shift();
335
+ }
336
+ children.forEach((c, i) => {
337
+ const amount = parseInt(c.getAttribute("amount") || "0");
338
+ const perc = amountToPercent(amount, this.total, true);
339
+ let colorIndex = i;
340
+ // bars in bar6 are all the same color
341
+ if (chartType === "bar6") {
342
+ colorIndex = 0;
343
+ }
344
+ const sliceDetails = {
345
+ amount: amount,
346
+ visualAmount: amount,
347
+ perc: perc,
348
+ legend: c.getAttribute("legend"),
349
+ color: chartColors[colorIndex] || colors.gray,
350
+ offset: acc,
351
+ id: `${this.uid}-${i + 1}`,
352
+ title: c.getAttribute("popover-title"),
353
+ text: c.getAttribute("popover-text"),
354
+ buttonText: c.getAttribute("popover-button-text"),
355
+ sliceRef: c,
356
+ inSmallCluster: false,
357
+ index: i,
358
+ };
359
+ acc += amount;
360
+ this.slicesDetails.push(sliceDetails);
361
+ });
362
+ }
363
+ function sortSlicesDetails(slicesDetails, total) {
364
+ // sort slices by decreasing amount
365
+ let sortedSlicesDetails = [...slicesDetails].sort((a, b) => a.amount === b.amount ? 0 : a.amount > b.amount ? -1 : 1);
366
+ let acc = 0;
367
+ sortedSlicesDetails
368
+ .filter((s) => s.amount > 0)
369
+ .forEach((s, idx) => {
370
+ const prev = sortedSlicesDetails[idx === 0 ? sortedSlicesDetails.length - 1 : idx - 1];
371
+ const next = sortedSlicesDetails[idx === sortedSlicesDetails.length - 1 ? 0 : idx + 1];
372
+ const prevPerc = amountToPercent(prev.amount, total, true);
373
+ const nextPerc = amountToPercent(next.amount, total, true);
374
+ // determine whether the slice is in a cluster of small values
375
+ // to avoid percentage text overlap for small values
376
+ // because <1% slice percentage text has an additional character
377
+ // the inSmallCluster threshold needs to be widened for that slice only
378
+ const neighborLimit = s.perc === 0 ? 8 : 5;
379
+ const isSmall = s.perc < 4;
380
+ const prevIsSmall = prevPerc < neighborLimit;
381
+ const nextIsSmall = nextPerc < neighborLimit;
382
+ let inSmallCluster = isSmall && (prevIsSmall || nextIsSmall);
383
+ s.inSmallCluster = inSmallCluster;
384
+ s.offset = acc;
385
+ acc += s.amount;
386
+ });
387
+ return sortedSlicesDetails;
388
+ }
389
+ function getPathData(amount, offset, chartType) {
390
+ const startAngle = amountToDegree(offset, this.total) - 90; // start at noon, not at 3 o'clock
391
+ const activeAngle = (amount / this.total) * 360;
392
+ let endAngle = startAngle + activeAngle;
393
+ const largeArcFlagOuter = activeAngle > 180 ? "1 1" : "0 1";
394
+ const largeArcFlagInner = activeAngle > 180 ? "1 0" : "0 0";
395
+ const half = this.chartDetails.size / 2;
396
+ const innerRadius = this.chartDetails.thickness;
397
+ const outerRadius = 1;
398
+ const isProgressIndicator = chartType === "doughnut";
399
+ const outerSeparatorOffset = 1.5;
400
+ const innerSeparatorOffset = isProgressIndicator ? 2.25 : 3;
401
+ if (activeAngle === 360) {
402
+ // fix to avoid bad svg shape when the path goes all around (100%)
403
+ endAngle -= 0.01;
404
+ }
405
+ const outerCoords = polarToCartesian(half, outerRadius, startAngle + outerSeparatorOffset, // Addition for slice separator
406
+ endAngle);
407
+ const innerCoords = polarToCartesian(half, innerRadius, startAngle + innerSeparatorOffset, // Addition for slice separator
408
+ endAngle);
409
+ const moveTo = `M ${outerCoords.x1}, ${outerCoords.y1} `;
410
+ const arc1 = getArc(outerRadius, largeArcFlagOuter, outerCoords.x2, outerCoords.y2, this.chartDetails.size);
411
+ const line = ` L ${innerCoords.x2}, ${innerCoords.y2} `;
412
+ const arc2 = getArc(innerRadius, largeArcFlagInner, innerCoords.x1, innerCoords.y1, this.chartDetails.size);
413
+ return moveTo + arc1 + line + arc2 + " z";
414
+ }
415
+ function renderInstructionsText() {
416
+ const chartInstructions = intl.formatMessage({
417
+ id: "chart.instructions",
418
+ defaultMessage: "Use arrow keys to browse elements, press Tab to exit.",
419
+ description: "For screen readers only, instructions on how to interact with the chart component",
420
+ });
421
+ return h("div", { id: "chart-instructions" }, chartInstructions);
422
+ }
423
+ function renderFilter() {
424
+ return (h("defs", null,
425
+ h("filter", { id: "wmHoverDropShadow" },
426
+ h("feGaussianBlur", { stdDeviation: "3" }),
427
+ h("feOffset", { result: "offsetblur" }),
428
+ h("feFlood", { "flood-color": "#333" }),
429
+ h("feComposite", { operator: "in", in2: "offsetblur" }),
430
+ h("feMerge", null,
431
+ h("feMergeNode", null),
432
+ h("feMergeNode", { in: "SourceGraphic" })))));
433
+ }
434
+ function applyMinimumAngle(minimumAngle, slicesDetails, total) {
435
+ const allAngles = slicesDetails.map((s) => amountToDegree(s.amount, total));
436
+ const hasTooSmallAngle = allAngles.some((angle) => angle !== 0 && angle < minimumAngle);
437
+ if (hasTooSmallAngle) {
438
+ // all angles initially sum to 360
439
+ // increase all angles below minimum to meet minimum, sum should now exceed 360
440
+ // all unchanged angles should be proportionally reduced, so they sum to (360 - sum of changed angles)
441
+ // For Example:
442
+ // angles: 100 200 5 4 3 48 = 360, increasedAngles: 100 200 7 7 7 48 = 369
443
+ // unchangedAnglesSum = 348, changedAnglesSum = 21
444
+ // unchangedTargetSum: 360 - 21 = 339, targetDifference: 348 - 339 = 9
445
+ // reductionRatio = 9/339
446
+ // adjustedAngles: 97.345 194.69 7 7 7 46.725 = approx 360
447
+ const increasedAngles = allAngles.map((angle) => (angle == 0 ? angle : Math.max(angle, minimumAngle)));
448
+ const unchangedAnglesSum = increasedAngles.reduce((acc, cur) => acc + (cur > minimumAngle && cur !== 0 ? cur : 0), 0);
449
+ const changedAnglesSum = increasedAngles.reduce((acc, cur) => acc + (cur > minimumAngle && cur !== 0 ? 0 : cur), 0);
450
+ const unchangedTargetSum = 360 - changedAnglesSum;
451
+ const targetDifference = unchangedAnglesSum - unchangedTargetSum;
452
+ const reductionRatio = targetDifference / unchangedTargetSum;
453
+ const adjustedAngles = increasedAngles.map((angle) => angle > minimumAngle ? angle - reductionRatio * angle : angle == 0 ? 0 : minimumAngle);
454
+ // apply new amounts based on adjust angles
455
+ let offsetAcc = 0;
456
+ slicesDetails = slicesDetails.map((s, idx) => {
457
+ const visualAmount = (adjustedAngles[idx] / 360) * total;
458
+ const newOffset = offsetAcc;
459
+ offsetAcc += visualAmount;
460
+ return Object.assign(Object.assign({}, s), { visualAmount: visualAmount, offset: newOffset });
461
+ });
462
+ }
463
+ return slicesDetails;
464
+ }
465
+ function renderDoughnut(chartType) {
466
+ const outerSize = this.chartDetails.size + this.chartDetails.padding;
467
+ const isProgressIndicator = chartType === "doughnut";
468
+ // no sorting in progress indicators
469
+ let slicesDetails = isProgressIndicator ? this.slicesDetails : sortSlicesDetails(this.slicesDetails, this.total);
470
+ slicesDetails = applyMinimumAngle(7, slicesDetails, this.total);
471
+ // perc is only for progress indicator
472
+ const amount = slicesDetails[0].amount;
473
+ let perc = amountToPercent(amount, this.total, true);
474
+ if (perc === 0 && amount > 0) {
475
+ perc = "<1%";
476
+ }
477
+ else if (perc === 100 && amount < this.total) {
478
+ perc = ">99%";
479
+ }
480
+ else {
481
+ perc = perc + "%";
482
+ }
483
+ return (h("div", { class: "chart-wrapper doughnut-wrapper" },
484
+ h("svg", { width: outerSize + "px", height: outerSize + "px", id: `graphic-${this.uid}`, class: "doughnut-svg" },
485
+ renderFilter(),
486
+ slicesDetails.map((s) => renderPath.call(this, s, chartType)),
487
+ renderFocusOutline.call(this),
488
+ isProgressIndicator ? (h("text", { class: "value", x: "50%", y: "50%", "font-size": "1.5rem", "font-weight": "500", "text-anchor": "middle", "dominant-baseline": "middle" }, perc)) : (h("g", { transform: `translate(${this.chartDetails.padding / 2}, ${this.chartDetails.padding / 2})`, "text-anchor": "middle", "dominant-baseline": "middle" }, slicesDetails.map((s) => s.amount > 0 && !s.inSmallCluster ? renderDoughnutText.call(this, s) : ""))))));
489
+ }
490
+ function highlightSegmentInfo(infoEls, s) {
491
+ infoEls.forEach((el) => {
492
+ if (el.dataset.segmentindex && parseInt(el.dataset.segmentindex) !== s.index) {
493
+ el.classList.add("faded");
494
+ }
495
+ else {
496
+ el.classList.remove("faded");
497
+ }
498
+ });
499
+ }
500
+ function removeSegmentInfoHighlight(infoEls) {
501
+ infoEls.forEach((el) => {
502
+ el.classList.remove("faded");
503
+ });
504
+ }
505
+ function renderPath(s, chartType) {
506
+ const percentageValue = amountToPercent(s.amount, this.total, true) + "%";
507
+ return (!isNaN(s.amount) && (h("g", { transform: `translate(${this.chartDetails.padding / 2}, ${this.chartDetails.padding / 2})` },
508
+ h("path", { id: s.id, class: "segment doughnut-segment", fill: s.visualAmount ? s.color : "transparent", d: getPathData.call(this, s.visualAmount, s.offset, chartType), onClick: (ev) => handleSliceClick.call(this, ev, s), onFocus: (ev) => handleSliceFocus.call(this, ev, s), onKeyDown: (ev) => handleSliceKeyDown.call(this, ev), role: "img", "aria-label": `${s.legend}, ${percentageValue}`, "data-segmentindex": s.index }))));
509
+ }
510
+ function renderFocusOutline() {
511
+ return this.isTabbing ? (h("g", { transform: `translate(${this.chartDetails.padding / 2}, ${this.chartDetails.padding / 2})` },
512
+ h("use", { tabindex: -1, id: "kfbg1", xlinkHref: `#${this.focusedSliceId}` }),
513
+ h("use", { tabindex: -1, id: "kfstroke", xlinkHref: `#${this.focusedSliceId}` }),
514
+ h("use", { tabindex: -1, id: "kfbg2", xlinkHref: `#${this.focusedSliceId}` }))) : ("");
515
+ }
516
+ function renderDoughnutText(s) {
517
+ const arcMiddle = amountToDegree(s.offset + s.visualAmount / 2, this.total);
518
+ let { x, y } = polarToCartesian(this.chartDetails.size / 2, 1.4, arcMiddle - 90);
519
+ let val;
520
+ if (s.perc === 0 && s.amount > 0) {
521
+ val = "<1%";
522
+ }
523
+ else if (s.perc === 100 && s.amount < this.total) {
524
+ val = ">99%";
525
+ }
526
+ else {
527
+ val = s.perc + "%";
528
+ }
529
+ return (h("text", { class: "value", x: x + "px", y: y + "px", "data-segmentindex": s.index }, val));
530
+ }
531
+ function renderStackedBar(chartType) {
532
+ const isHybridBar = chartType === "bar";
533
+ // if the text for any value > 0 overlaps with another, hide it and display warning
534
+ const textEls = this.el.shadowRoot.querySelectorAll(".value");
535
+ // if DOM is not ready (no textEls), we need to rerender
536
+ // we don't have to do it here though, because it's already taken care of
537
+ // as a side effect of the observer in componentWillLoad
538
+ // (observers fire on init)
539
+ if (textEls.length > 0) {
540
+ requestAnimationFrame(() => {
541
+ let prevTextEls = [];
542
+ const margin = 4;
543
+ let showMsg = false;
544
+ textEls.forEach((textEl) => {
545
+ textEl.classList.remove("hidden");
546
+ const currentValue = parseInt(textEl.dataset.value);
547
+ // only proceed if there are prevTextEls to check for overlap, and current value is not 0
548
+ if (prevTextEls.length > 0 && currentValue != 0) {
549
+ const currentLeftEdge = textEl.getBoundingClientRect().left - margin;
550
+ // check for overlap with all prevTextEls & hide the smaller value if overlap occurs
551
+ prevTextEls.forEach((prevTextEl) => {
552
+ const prevValue = parseInt(prevTextEl.dataset.value);
553
+ const valuesOverlap = prevTextEl.getBoundingClientRect().right > currentLeftEdge;
554
+ if (valuesOverlap) {
555
+ const smallerValueEl = currentValue < prevValue ? textEl : prevTextEl;
556
+ smallerValueEl.classList.add("hidden");
557
+ showMsg = true;
558
+ }
559
+ });
560
+ }
561
+ // prevTextEls only need to be checked if they are visible and have a non-zero value
562
+ if (!textEl.classList.contains("hidden") && currentValue > 0) {
563
+ prevTextEls.push(textEl);
564
+ }
565
+ });
566
+ // progress monitor doesn't have this message
567
+ (this.isBar || this.isDoughnut) && this.showHiddenValuesMessage(showMsg);
568
+ });
569
+ }
570
+ return (h("div", { class: "chart-wrapper bar-wrapper" },
571
+ isHybridBar ? (h("div", { class: "single-perc" }, amountToPercent(this.slicesDetails[0].amount, this.total, true) + "%")) : (""),
572
+ this.chartType === "bar3" && this.drawAxis(),
573
+ h("div", { class: `inner-stacked-bar-wrapper ${showValue(this.valueFormat)}` },
574
+ !isHybridBar ? (h("div", { class: `values ${this.valueFormat}` }, this.slicesDetails.map((s) => this.renderBarText(s, 5)))) : (""),
575
+ h("div", { class: "stacked-bar-segments-wrapper" }, this.slicesDetails.map((s) => renderStackedBarSegment.call(this, s, 5))),
576
+ isHybridBar ? renderCompletionMessage.call(this) : ""),
577
+ this.chartType === "bar3" ? (h("div", { class: "bar3-axis-label", "aria-hidden": "true" },
578
+ h("span", null, "0%"),
579
+ h("span", null, "100%"))) : ("")));
580
+ }
581
+ function renderStackedBarSegment(s, minimumWidth) {
582
+ const segmentPercentage = amountToPercent(s.amount, this.total, false);
583
+ const barWrapper = this.el.shadowRoot.querySelector(".stacked-bar-segments-wrapper");
584
+ const availableWidth = barWrapper ? barWrapper.offsetWidth : this.el.offsetWidth;
585
+ const meetsSizeMinimum = (segmentPercentage / 100) * availableWidth >= minimumWidth;
586
+ const renderedWidth = meetsSizeMinimum || s.amount == 0 ? `${segmentPercentage}%` : `${minimumWidth}px`;
587
+ let segmentValue = "";
588
+ if (this.valueFormat == "percentage") {
589
+ segmentValue = `${amountToPercent(s.amount, this.total, true)} %`;
590
+ }
591
+ else if (this.valueFormat == "amount") {
592
+ segmentValue = s.amount.toString();
593
+ }
594
+ return (h("div", { class: `segment stacked-bar-segment ${amountToPercent(s.amount, this.total, false) === 0 ? "zero" : ""} ${meetsSizeMinimum ? "" : "fixed-width"}`, style: {
595
+ backgroundColor: s.color,
596
+ width: renderedWidth,
597
+ }, onClick: (ev) => handleSliceClick.call(this, ev, s), onFocus: (ev) => handleSliceFocus.call(this, ev, s), onKeyDown: (ev) => handleSliceKeyDown.call(this, ev), "data-segmentindex": s.index },
598
+ h("span", { class: "sr-only" }, `${s.legend} ${segmentValue}`)));
599
+ }
600
+ function renderSimpleBar(chartType) {
601
+ // find largest number and get interval, numTicks, chartMaxVal for all.
602
+ const largest = this.slicesDetails
603
+ .map((s) => s.amount)
604
+ .reduce((a, b) => {
605
+ return a > b ? a : b;
606
+ });
607
+ const labelWidth = parseInt(getComputedStyle(this.el).getPropertyValue("--labelWidth"), 10);
608
+ const chartPadding = 48;
609
+ const componentWidth = this.el.getBoundingClientRect().width;
610
+ const chartWidth = componentWidth - labelWidth - chartPadding;
611
+ let numTicks = getMaxTicks(chartWidth);
612
+ let interval = getInterval(largest, numTicks);
613
+ // after the algorithm finds an interval, remove extra ticks so that the greater number is always between the last tick and the one before that
614
+ const lastTickVal = numTicks * interval;
615
+ const extraTicks = Math.floor((lastTickVal - largest) / interval);
616
+ numTicks -= extraTicks;
617
+ this.el.style.setProperty("--backgroundSize", 100 / numTicks + "%");
618
+ this.el.style.setProperty("--labelWidth", this.labelWidth);
619
+ if (chartType === "bar7" && !this.showBarLegend) {
620
+ this.el.style.setProperty("--labelWidth", "0px");
621
+ }
622
+ // we have to prep the data here rather than iterate directly in the return statement
623
+ // because CSS grid needs a flat structure, and return functions must
624
+ // have a single parent element
625
+ const rows = [];
626
+ this.slicesDetails.forEach((s) => {
627
+ s.legend && rows.push(renderSimpleBarLegend(s.legend, this.showBarLegend, chartType));
628
+ rows.push(renderSimpleBarItem.call(this, s, interval, numTicks, largest));
629
+ });
630
+ const ticks = [];
631
+ for (let i = 1; i <= numTicks; i++) {
632
+ const tickVal = abbrNumber(safeMultiplyFloat(i, interval));
633
+ ticks.push(h("div", { class: "tick" },
634
+ h("span", null, tickVal)));
635
+ }
636
+ const showGrid = chartType === "bar6" && this.showGrid && this.el.getBoundingClientRect().width > 300;
637
+ return (h("div", { class: "chart-wrapper simple-bar-wrapper" },
638
+ h("div", { class: `chart ${showValue(this.valueFormat)}` },
639
+ showGrid && h("div", { class: "gridlines" }),
640
+ h("div", { class: "rows" }, rows)),
641
+ showGrid && (h("div", { class: "x-axis", "aria-hidden": "true" },
642
+ h("div", { class: "zero" },
643
+ h("span", null, "0")),
644
+ ticks))));
645
+ }
646
+ function renderSimpleBarLegend(legend, show, chartType) {
647
+ // not sure how to collapse the left column to 0 width with CSS grid. text should still be available to SR.
648
+ const hidden = chartType === "bar7" && !show ? " hidden" : "";
649
+ return h("label", { class: `label${hidden}` }, legend);
650
+ }
651
+ function renderSimpleBarItem(s, interval, ticks, largest) {
652
+ const chartMaxVal = this.currentChartType === "bar6" ? interval * ticks : largest;
653
+ const width = amountToPercent(s.amount, chartMaxVal, false);
654
+ const cssWidth = width ? width + "%" : "1px";
655
+ const amt = abbrNumber(s.amount);
656
+ let displayValue = this.valueFormat === "amount" ? amt : "";
657
+ if (this.currentChartType === "bar6" && this.valueFormat === "percentage") {
658
+ displayValue = s.amount + "%";
659
+ }
660
+ else if (this.currentChartType === "bar7" && this.valueFormat === "percentage") {
661
+ displayValue = (this.total === 0 ? "0" : amountToPercent(s.amount, this.total, true)) + "%";
662
+ }
663
+ return (h("div", { class: "bar segment", style: {
664
+ backgroundColor: s.color,
665
+ width: cssWidth,
666
+ }, onClick: (ev) => handleSliceClick.call(this, ev, s), onFocus: (ev) => handleSliceFocus.call(this, ev, s), onKeyDown: (ev) => handleSliceKeyDown.call(this, ev), "data-segmentindex": s.index },
667
+ h("div", { class: "value" }, displayValue)));
668
+ }
669
+ function renderLegend(chartType) {
670
+ // legend is hidden for bar1 and bar6 types regardless of showLegend value
671
+ if (this.showLegend) {
672
+ const showMsg = this.slicesDetails.reduce((hasCluster, cur) => (hasCluster = cur.inSmallCluster ? true : hasCluster), false);
673
+ this.isDoughnut && this.showHiddenValuesMessage(showMsg);
674
+ return (h("div", { class: "legend-wrapper" },
675
+ h("div", { class: `legend ${chartType} ${this.mode === "bar" ? "--top" : "--bottom"}`, "aria-hidden": "true" }, this.slicesDetails.map((s) => {
676
+ const printValue = this.printModeFormat == "amount"
677
+ ? `${s.amount}/${this.total}`
678
+ : `${amountToPercent(s.amount, this.total, true)}%`;
679
+ // when both legend and amount are omitted, the legend is not shown for that particular option (it's been deactivated by the user)
680
+ if (!!s.amount || !!s.legend) {
681
+ return renderLegendItem.call(this, { key: s.legend, color: s.color }, printValue, s);
682
+ }
683
+ })),
684
+ this.isDoughnut && !this.printMode && renderHiddenValuesMessage()));
685
+ }
686
+ }
687
+ function renderLegendItem(legendItem, printValue = "", s = null) {
688
+ const handleLegendItemClick = (ev) => {
689
+ if (s) {
690
+ s.coords = { x: ev.clientX, y: ev.clientY };
691
+ openPopover(this.popoverEl, s);
692
+ highlightSegmentInfo(Array.from(this.el.shadowRoot.querySelectorAll("[data-segmentindex")), s);
693
+ }
694
+ };
695
+ return (h("div", { class: "legend-item", onClick: (ev) => handleLegendItemClick(ev), "data-segmentindex": s ? s.index : null },
696
+ h("div", { class: "legend-color", style: { backgroundColor: legendItem.color } }),
697
+ h("div", { class: "legend-text" },
698
+ legendItem.key,
699
+ printValue && h("span", { class: `print-value ${this.printMode ? "force-visible" : ""}` },
700
+ ": ",
701
+ printValue))));
702
+ }
703
+ function renderCompletionMessage() {
704
+ if (this.completionMessage) {
705
+ return h("div", { class: "completion-message" }, this.completionMessage);
706
+ }
707
+ }
708
+ function renderHiddenValuesMessage() {
709
+ return (h("div", { class: "hidden-values-warning hidden" },
710
+ textHiddenMessage,
711
+ h("br", null),
712
+ seeDetailsMessage));
713
+ }
714
+
715
+ export { allChartsDetails as a, amountToPercent as b, renderSimpleBar as c, renderStackedBar as d, renderDoughnut as e, exitChart as f, getDetails as g, handleChartKeydown as h, renderLegend as i, renderHiddenValuesMessage as j, renderInstructionsText as k, getInterval as l, abbrNumber as m, renderCompletionMessage as n, renderLegendItem as o, removeSegmentInfoHighlight as r };