@watermarkinsights/ripple 3.0.1 → 3.0.2-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.
Files changed (81) hide show
  1. package/dist/cjs/{global-ccb9500c.js → global-1e540de6.js} +1 -1
  2. package/dist/cjs/loader.cjs.js +2 -2
  3. package/dist/cjs/priv-datepicker.cjs.entry.js +1 -1
  4. package/dist/cjs/ripple.cjs.js +2 -2
  5. package/dist/cjs/wm-datepicker.cjs.entry.js +25 -30
  6. package/dist/collection/components/wm-datepicker/priv-datepicker/priv-datepicker.css +9 -0
  7. package/dist/collection/components/wm-datepicker/wm-datepicker.js +26 -32
  8. package/dist/esm/{global-4f914bb2.js → global-d6b49e98.js} +1 -1
  9. package/dist/esm/loader.js +2 -2
  10. package/dist/esm/priv-datepicker.entry.js +1 -1
  11. package/dist/esm/ripple.js +2 -2
  12. package/dist/esm/wm-datepicker.entry.js +25 -30
  13. package/dist/ripple/p-129d94fa.entry.js +1 -0
  14. package/dist/ripple/{p-454ad552.entry.js → p-c0fe5201.entry.js} +1 -1
  15. package/dist/ripple/{p-69a73e86.js → p-e3843249.js} +1 -1
  16. package/dist/ripple/ripple.esm.js +1 -1
  17. package/dist/types/components/wm-datepicker/wm-datepicker.d.ts +3 -3
  18. package/package.json +1 -1
  19. package/dist/cjs/app-globals-a07327ae.js +0 -47
  20. package/dist/cjs/css-shim-a7379e2b.js +0 -6
  21. package/dist/cjs/dom-3e7d9c3b.js +0 -75
  22. package/dist/cjs/functions-65513c61.js +0 -8360
  23. package/dist/cjs/global-06317e3f.js +0 -36
  24. package/dist/cjs/global-f6930bb0.js +0 -38
  25. package/dist/cjs/index-8dea8c13.js +0 -2976
  26. package/dist/cjs/shadow-css-09555044.js +0 -391
  27. package/dist/esm/app-globals-f62991a4.js +0 -45
  28. package/dist/esm/css-shim-bbdf0cc6.js +0 -4
  29. package/dist/esm/dom-1f98a75f.js +0 -73
  30. package/dist/esm/functions-316c1b23.js +0 -8340
  31. package/dist/esm/global-03372f70.js +0 -34
  32. package/dist/esm/global-fedbc323.js +0 -36
  33. package/dist/esm/index-e34aa595.js +0 -2938
  34. package/dist/esm/shadow-css-67b66845.js +0 -389
  35. package/dist/ripple/app-globals-b5693c90.js +0 -45
  36. package/dist/ripple/app-globals-d72c2d3c.js +0 -45
  37. package/dist/ripple/app-globals-f62991a4.js +0 -45
  38. package/dist/ripple/css-shim-bbdf0cc6.js +0 -4
  39. package/dist/ripple/dom-1f98a75f.js +0 -73
  40. package/dist/ripple/functions-316c1b23.js +0 -8340
  41. package/dist/ripple/http-service-5d037e16.js +0 -52
  42. package/dist/ripple/index-20b65f86.js +0 -2938
  43. package/dist/ripple/index-e34aa595.js +0 -2938
  44. package/dist/ripple/interfaces-50753346.js +0 -51
  45. package/dist/ripple/p-0c2498f4.js +0 -1
  46. package/dist/ripple/p-42ca2e15.entry.js +0 -1
  47. package/dist/ripple/p-e91befe3.js +0 -1
  48. package/dist/ripple/priv-chart-popover.entry.js +0 -85
  49. package/dist/ripple/priv-datepicker.entry.js +0 -668
  50. package/dist/ripple/priv-navigator-button.entry.js +0 -25
  51. package/dist/ripple/priv-navigator-item.entry.js +0 -30
  52. package/dist/ripple/ripple.css +0 -84
  53. package/dist/ripple/shadow-css-67b66845.js +0 -389
  54. package/dist/ripple/wm-action-menu.entry.js +0 -202
  55. package/dist/ripple/wm-button.entry.js +0 -148
  56. package/dist/ripple/wm-chart-slice.entry.js +0 -18
  57. package/dist/ripple/wm-chart.entry.js +0 -504
  58. package/dist/ripple/wm-datepicker.entry.js +0 -258
  59. package/dist/ripple/wm-input.entry.js +0 -106
  60. package/dist/ripple/wm-menuitem.entry.js +0 -114
  61. package/dist/ripple/wm-modal-footer.entry.js +0 -39
  62. package/dist/ripple/wm-modal-header.entry.js +0 -41
  63. package/dist/ripple/wm-modal.entry.js +0 -145
  64. package/dist/ripple/wm-navigator.entry.js +0 -275
  65. package/dist/ripple/wm-network-uploader.entry.js +0 -427
  66. package/dist/ripple/wm-option.entry.js +0 -119
  67. package/dist/ripple/wm-pagination.entry.js +0 -172
  68. package/dist/ripple/wm-search.entry.js +0 -227
  69. package/dist/ripple/wm-select.entry.js +0 -362
  70. package/dist/ripple/wm-snackbar.entry.js +0 -156
  71. package/dist/ripple/wm-tab-item.entry.js +0 -78
  72. package/dist/ripple/wm-tab-list.entry.js +0 -201
  73. package/dist/ripple/wm-tab-panel.entry.js +0 -38
  74. package/dist/ripple/wm-tag-input.entry.js +0 -534
  75. package/dist/ripple/wm-timepicker.entry.js +0 -382
  76. package/dist/ripple/wm-toggletip.entry.js +0 -124
  77. package/dist/ripple/wm-uploader.entry.js +0 -338
  78. package/dist/ripple/wm-wrapper.entry.js +0 -17
  79. package/dist/types/components/wm-tag-input/wm-tag-input.d.ts~ds312_tagInputMaxTags +0 -87
  80. package/dist/types/components.d.ts~ds312_tagInputMaxTags +0 -879
  81. package/dist/types/stencil-public-runtime.d.ts~ds312_tagInputMaxTags +0 -1555
@@ -1,504 +0,0 @@
1
- import { r as registerInstance, i as forceUpdate, h, f as Host, g as getElement } from './index-e34aa595.js';
2
- import { g as generateId, d as debounce, c as checkForActiveElInShadow, f as findParentWithScrollbar, e as getPosition, i as intl } from './functions-316c1b23.js';
3
-
4
- const wmChartCss = ".component-wrapper{display:flex;flex-direction:column;align-items:center;font-size:0.875rem;position:relative;}.component-wrapper .label{display:block;margin:0;padding-bottom:0.25rem;font-weight:500;position:relative}.component-wrapper .label .subinfo{display:block;font-weight:normal;font-style:italic;bottom:0.25rem;width:100%;color:#6b6b6b}.component-wrapper .legend-wrapper{display:flex;flex-direction:column;justify-content:center;align-items:center;text-align:center}.component-wrapper .legend-wrapper .legend{display:flex;align-items:center;flex-wrap:wrap;text-align:center;padding-top:0.25rem;padding-bottom:0.75rem;box-sizing:border-box}.component-wrapper .legend-wrapper .legend.--top{margin-top:-0.75rem}.component-wrapper .legend-wrapper .legend.--top .legend-item{padding-top:0.75rem}.component-wrapper .legend-wrapper .legend.--top .legend-color{top:0.75rem}.component-wrapper .legend-wrapper .legend.--bottom{margin-bottom:-0.75rem}.component-wrapper .legend-wrapper .legend.--bottom .legend-item{padding-bottom:0.75rem}.component-wrapper .legend-wrapper .legend.--bottom .legend-color{top:-0.75rem}.component-wrapper .legend-wrapper .legend .legend-item{position:relative}.component-wrapper .legend-wrapper .legend .legend-item:not(:last-of-type){padding-right:1.25rem}.component-wrapper .legend-wrapper .legend .legend-text{padding-left:1rem;line-height:1}.component-wrapper .legend-wrapper .legend .legend-color{position:absolute;left:0;bottom:0;margin:auto;width:0.6875rem;height:0.6875rem}.component-wrapper .legend-wrapper .cluster-warning{font-size:0.75rem;font-style:italic;max-width:100%}.component-wrapper .chart-svg{overflow:visible}.component-wrapper .chart-svg:active,.component-wrapper .chart-svg:hover,.component-wrapper .chart-svg:focus{outline:none;-webkit-box-shadow:none;-moz-box-shadow:none;box-shadow:none}.component-wrapper .chart-svg::-moz-focus-inner{border:0;outline:none}.component-wrapper .chart-svg path:active,.component-wrapper .chart-svg path:hover,.component-wrapper .chart-svg path:focus,.component-wrapper .chart-svg rect:active,.component-wrapper .chart-svg rect:hover,.component-wrapper .chart-svg rect:focus{outline:none;-webkit-box-shadow:none;-moz-box-shadow:none;box-shadow:none;filter:url(#wmHoverDropShadow)}.component-wrapper .chart-svg path::-moz-focus-inner,.component-wrapper .chart-svg rect::-moz-focus-inner{border:0;outline:none}.component-wrapper .bar-wrapper{flex-grow:1;width:100%}.component-wrapper .bar-wrapper rect{height:30px}.component-wrapper .doughnut-wrapper .chart-svg{-webkit-border-radius:4px;-moz-border-radius:4px;-ms-border-radius:4px;border-radius:4px}.component-wrapper.doughnut1 label,.component-wrapper.doughnut1 .label-text,.component-wrapper.doughnut2 label,.component-wrapper.doughnut2 .label-text,.component-wrapper.doughnut3 label,.component-wrapper.doughnut3 .label-text{position:absolute !important;width:1px !important;height:1px !important;padding:0 !important;border:0 !important;overflow:hidden !important;clip:rect(0, 0, 0, 0) !important;clip-path:inset(50%) !important;white-space:nowrap !important;margin:-1px !important}.component-wrapper.doughnut0{align-items:center}.component-wrapper.doughnut0 label{text-align:center;width:100%;padding-bottom:1.5rem}.component-wrapper.doughnut0 label .subinfo{position:absolute}.component-wrapper.doughnut0 .legend{display:flex}.component-wrapper.doughnut0 .completion-message{padding-top:0.625rem}.component-wrapper .bar-svg{width:100%}.component-wrapper .bar-svg foreignObject{width:100%;height:30px;overflow:visible}.component-wrapper.bar1{padding:1.25rem;position:relative;align-items:flex-start}.component-wrapper.bar1 label{display:flex;flex-direction:column}.component-wrapper.bar1 label .subinfo{position:initial}.component-wrapper.bar1 .legend{display:none}.component-wrapper.bar1 .completion-message{position:absolute;right:1.25rem;bottom:0}.component-wrapper.bar1 .bar-wrapper{display:flex;align-items:center}.component-wrapper.bar1 .bar-wrapper .single-perc{width:4rem}.component-wrapper.bar1 .bar-wrapper .chart-svg{flex:1;height:30px}@media screen and (min-width: 768px){.component-wrapper.bar1{flex-direction:row;align-items:center}.component-wrapper.bar1 label{width:12rem;text-align:left;padding-right:1.25rem;padding-bottom:0}.component-wrapper.bar1 .completion-message{right:5.75rem}.component-wrapper.bar1 .bar-wrapper{flex-direction:row-reverse}.component-wrapper.bar1 .bar-wrapper .single-perc{text-align:center;padding-left:0.5rem}}.component-wrapper.bar2,.component-wrapper.bar3,.component-wrapper.bar4,.component-wrapper.bar5{align-items:flex-start}.component-wrapper.bar2 .legend,.component-wrapper.bar4 .legend,.component-wrapper.bar5 .legend{padding-bottom:0}.component-wrapper.bar2 .chart-svg,.component-wrapper.bar4 .chart-svg,.component-wrapper.bar5 .chart-svg{height:30px;margin-top:20px;margin-bottom:0}.component-wrapper.bar2 .chart-svg.show-values,.component-wrapper.bar4 .chart-svg.show-values,.component-wrapper.bar5 .chart-svg.show-values{height:60px;margin-top:0;margin-bottom:0}.component-wrapper.bar2 .chart-svg .percs,.component-wrapper.bar4 .chart-svg .percs,.component-wrapper.bar5 .chart-svg .percs{transform:translateY(24px);text-anchor:middle}.component-wrapper.bar3 .legend{padding-bottom:1.25rem}.component-wrapper.bar3 .svg-wrapper{position:relative;height:100px}.component-wrapper.bar3 .svg-wrapper .chart-svg{position:absolute;top:35px;left:0;right:0;bottom:0;height:30px}.component-wrapper.bar3 .svg-wrapper .chart-svg text{fill:#4a4a4a}.component-wrapper.bar3 .svg-wrapper .chart-svg .percs{transform:translateY(-4px);text-anchor:middle}.component-wrapper.bar3 .svg-wrapper .axis{position:absolute;top:0;left:0;height:90px;width:100%;overflow:visible;transform:translateY(90px)}.component-wrapper.bar3 .svg-wrapper .axis line{stroke:#eeedf4;stroke-width:1px}.component-wrapper.bar3 .svg-wrapper .axis text{transform:translate(4px, 24px);text-anchor:middle}:host(:focus){outline:none}:host(:focus) .chart-svg.user-is-tabbing:not(.show-values){-webkit-box-shadow:0 2px 2px 0 rgba(244, 243, 246, 0.2), 0 2px 2px 0 rgba(0, 0, 0, 0.1), 0 0 4px 3px #61279e;-moz-box-shadow:0 2px 2px 0 rgba(244, 243, 246, 0.2), 0 2px 2px 0 rgba(0, 0, 0, 0.1), 0 0 4px 3px #61279e;box-shadow:0 2px 2px 0 rgba(244, 243, 246, 0.2), 0 2px 2px 0 rgba(0, 0, 0, 0.1), 0 0 4px 3px #61279e}:host(:focus) .chart-svg.user-is-tabbing:not(.show-values)::-moz-focus-inner{border:0}:host(:focus) .chart-svg.user-is-tabbing.show-values .tabbing-focus{-webkit-box-shadow:0 2px 2px 0 rgba(244, 243, 246, 0.2), 0 2px 2px 0 rgba(0, 0, 0, 0.1), 0 0 4px 3px #61279e;-moz-box-shadow:0 2px 2px 0 rgba(244, 243, 246, 0.2), 0 2px 2px 0 rgba(0, 0, 0, 0.1), 0 0 4px 3px #61279e;box-shadow:0 2px 2px 0 rgba(244, 243, 246, 0.2), 0 2px 2px 0 rgba(0, 0, 0, 0.1), 0 0 4px 3px #61279e;width:100%;height:30px}:host(:focus) .chart-svg.user-is-tabbing.show-values .tabbing-focus::-moz-focus-inner{border:0}:host(:focus) .chart-svg.user-is-tabbing.show-values .focus-offset{transform:translateY(30px)}";
5
-
6
- const Chart = class {
7
- constructor(hostRef) {
8
- registerInstance(this, hostRef);
9
- this.chartType = "doughnut1";
10
- this.showLegend = true;
11
- this.notStartedColor = false;
12
- this.isTabbing = false;
13
- this.uid = generateId();
14
- this.slicesData = [];
15
- this.colors = {
16
- salmon: "#ff5f4e",
17
- cyan: "#19a1a9",
18
- sleet: "#7f97ad",
19
- midnight: "#2e1b46",
20
- lavender: "#8b86ca",
21
- };
22
- this.types = {
23
- doughnut0: {
24
- size: 155,
25
- colors: [this.colors.cyan, "#bfbfbf"],
26
- thickness: 0.73,
27
- padding: 25,
28
- isBar: false,
29
- },
30
- doughnut1: {
31
- size: 130,
32
- colors: [this.colors.lavender, this.colors.midnight, "#d4d4d4"],
33
- thickness: 0.5,
34
- padding: 90,
35
- isBar: false,
36
- },
37
- doughnut2: {
38
- size: 130,
39
- colors: [this.colors.cyan, this.colors.salmon, "#d4d4d4"],
40
- thickness: 0.5,
41
- padding: 90,
42
- isBar: false,
43
- },
44
- doughnut3: {
45
- size: 130,
46
- colors: [this.colors.lavender, this.colors.midnight, "#919834", "#c177cf", "#c16e00", "#029af2", "#2a6993"],
47
- thickness: 0.5,
48
- padding: 90,
49
- isBar: false,
50
- },
51
- bar1: {
52
- size: 350,
53
- colors: [this.colors.cyan, "#bfbfbf"],
54
- padding: 0,
55
- isBar: true,
56
- },
57
- bar2: {
58
- size: 400,
59
- colors: ["#d4d4d4", this.colors.sleet, this.colors.cyan, this.colors.salmon],
60
- padding: 0,
61
- isBar: true,
62
- },
63
- bar3: {
64
- size: 300,
65
- colors: ["#0d696e", this.colors.cyan, "#8e4129", this.colors.salmon],
66
- padding: 0,
67
- isBar: true,
68
- },
69
- bar4: {
70
- size: 400,
71
- colors: ["#d4d4d4", this.colors.sleet, "#33a919"],
72
- padding: 0,
73
- isBar: true,
74
- },
75
- bar5: {
76
- size: 400,
77
- colors: [
78
- "#d4d4d4",
79
- this.colors.lavender,
80
- this.colors.midnight,
81
- "#919834",
82
- "#c177cf",
83
- "#c16e00",
84
- "#029af2",
85
- "#2a6993",
86
- ],
87
- padding: 0,
88
- isBar: true,
89
- },
90
- };
91
- /* LIFECYCLE METHODS + EVENTS FROM THE CHILDREN */
92
- this.debouncedUpdate = debounce(async () => {
93
- this.setHybridType();
94
- await this.getData();
95
- forceUpdate(this.el);
96
- }, 30);
97
- this.debouncedSliceUpdate = debounce(async () => {
98
- await this.getData();
99
- forceUpdate(this.el);
100
- }, 100);
101
- }
102
- toggleTabbingOn() {
103
- this.isTabbing = true;
104
- }
105
- toggleTabbingOff() {
106
- this.isTabbing = false;
107
- }
108
- handleKeydown(ev) {
109
- switch (ev.keyCode) {
110
- // arrow up / left
111
- case 37:
112
- case 38:
113
- ev.preventDefault();
114
- this.isTabbing = true; // shd already be true. just in case user clicked on chart then pressed an arrow key
115
- this.focusPrevious();
116
- break;
117
- // arrow right / down
118
- case 39:
119
- case 40:
120
- ev.preventDefault();
121
- this.isTabbing = true; // shd already be true. just in case user clicked on chart then pressed an arrow key
122
- this.focusNext();
123
- break;
124
- // tab
125
- case 9:
126
- this.exitChart();
127
- break;
128
- case 27:
129
- this.popoverEl.open = false;
130
- break;
131
- }
132
- }
133
- focusNext() {
134
- const activeEl = checkForActiveElInShadow(document.activeElement);
135
- const index =
136
- // if the active el is not in the array the first element gets focused
137
- (this.sliceEls.indexOf(activeEl) + 1) % this.sliceEls.length;
138
- this.focusSlice(index);
139
- }
140
- focusPrevious() {
141
- if (this.sliceEls) {
142
- const activeEl = checkForActiveElInShadow(document.activeElement);
143
- let index = this.sliceEls.indexOf(activeEl);
144
- if (index === -1) {
145
- // not in the array : focus the first slice
146
- index = 0;
147
- }
148
- else if (index === 0) {
149
- // first slice : focus the last slice
150
- index = this.sliceEls.length - 1;
151
- }
152
- else {
153
- // anything else: focus previous
154
- index -= 1;
155
- }
156
- this.focusSlice(index);
157
- }
158
- }
159
- focusSlice(index) {
160
- if (this.sliceEls && this.el) {
161
- if (this.popoverEl) {
162
- this.popoverEl.open = false;
163
- }
164
- this.el.tabIndex = -1;
165
- // @ts-ignore
166
- this.el.focusable = false; // for Edge
167
- this.sliceEls.map((p) => {
168
- p.tabIndex = -1;
169
- // @ts-ignore
170
- p.focusable = false; // for Edge
171
- });
172
- this.sliceEls[index].tabIndex = 0;
173
- // @ts-ignore
174
- this.sliceEls[index].focusable = true; // for Edge
175
- this.sliceEls[index].focus();
176
- window.setTimeout(() => {
177
- if (this.popoverEl) {
178
- this.popoverEl.open = true;
179
- }
180
- }, 10);
181
- }
182
- }
183
- exitChart() {
184
- this.sliceEls &&
185
- this.sliceEls.map((p) => {
186
- p.tabIndex = -1;
187
- // @ts-ignore
188
- p.focusable = false; // for Edge
189
- });
190
- // delay so that we can tab out of component before chart becomes focusable again
191
- // and in case user was still pressing an arrow key when they pressed tab
192
- window.setTimeout(() => {
193
- if (this.el) {
194
- this.el.tabIndex = 0;
195
- // @ts-ignore
196
- this.el.focusable = true; // for Edge
197
- if (this.popoverEl) {
198
- this.popoverEl.open = false;
199
- }
200
- }
201
- }, 100);
202
- }
203
- openPopover(s) {
204
- if (!!this.popoverEl && !!s.title && !!s.text) {
205
- this.popoverEl.popoverTitle = s.title;
206
- this.popoverEl.popoverText = s.text;
207
- this.popoverEl.buttonText = s.buttonText;
208
- this.popoverEl.coords = s.coords;
209
- this.popoverEl.sliceRef = s.sliceRef;
210
- window.setTimeout(() => {
211
- if (this.popoverEl) {
212
- this.popoverEl.open = true;
213
- }
214
- }, 30);
215
- const debouncedClosePopover = debounce(async () => {
216
- this.popoverEl.open = false;
217
- }, 10);
218
- // set up event listeners for scrolling
219
- // to close popover on page scroll
220
- document.addEventListener("scroll", () => {
221
- debouncedClosePopover();
222
- });
223
- // ... and on parent scroll
224
- const scrollableParent = findParentWithScrollbar(this.el);
225
- if (!!scrollableParent) {
226
- scrollableParent.addEventListener("scroll", () => {
227
- debouncedClosePopover();
228
- });
229
- }
230
- }
231
- }
232
- /* UTILS */
233
- amountToPercent(val, asInt) {
234
- return asInt ? Math.round((val * 100) / this.total) : Math.round((val * 10000) / this.total) / 100; // with 2 decimals
235
- }
236
- amountToDegree(val) {
237
- return (val * 360) / this.total;
238
- }
239
- toFixed(number) {
240
- var val = parseFloat((Math.floor(number * 100) / 100).toFixed(2));
241
- return val;
242
- }
243
- polarToCartesian(half, radius, startAngle, endAngle) {
244
- var x = this.toFixed(half + half * radius * Math.cos((Math.PI * startAngle) / 180));
245
- var y = this.toFixed(half + half * radius * Math.sin((Math.PI * startAngle) / 180));
246
- if (endAngle !== undefined) {
247
- // if a 2nd angle value was passed, return 2 pairs of coords
248
- var x2 = this.toFixed(half + half * radius * Math.cos((Math.PI * endAngle) / 180));
249
- var y2 = this.toFixed(half + half * radius * Math.sin((Math.PI * endAngle) / 180));
250
- return { x1: x, y1: y, x2, y2 };
251
- }
252
- return { x, y };
253
- }
254
- /* CRUNCH THE NUMBERS */
255
- getPathData(amount, offset) {
256
- var startAngle = this.amountToDegree(offset) - 90; // start at noon, not at 3 o'clock
257
- var activeAngle = (amount / this.total) * 360;
258
- var endAngle = startAngle + activeAngle;
259
- var largeArcFlagOuter = activeAngle > 180 ? "1 1" : "0 1";
260
- var largeArcFlagInner = activeAngle > 180 ? "1 0" : "0 0";
261
- var half = this.chartData.size / 2;
262
- var innerRadius = this.chartData.thickness;
263
- var outerRadius = 1;
264
- if (activeAngle === 360) {
265
- // fix to avoid bad svg shape when the path goes all around (100%)
266
- endAngle -= 0.01;
267
- }
268
- var outerCoords = this.polarToCartesian(half, outerRadius, startAngle + 1.5, // 1.5 for slice separator
269
- endAngle);
270
- var innerCoords = this.polarToCartesian(half, innerRadius, startAngle + 3, // 3 for slice separator
271
- endAngle);
272
- const moveTo = `M ${outerCoords.x1}, ${outerCoords.y1} `;
273
- const arc1 = this.getArc(outerRadius, largeArcFlagOuter, outerCoords.x2, outerCoords.y2);
274
- const line = ` L ${innerCoords.x2}, ${innerCoords.y2} `;
275
- const arc2 = this.getArc(innerRadius, largeArcFlagInner, innerCoords.x1, innerCoords.y1);
276
- return moveTo + arc1 + line + arc2 + " z";
277
- }
278
- getArc(radius, largeArcFlag, x, y) {
279
- var z = this.toFixed((this.chartData.size / 2) * radius);
280
- return `A ${z}, ${z} 0 ${largeArcFlag} ${this.toFixed(x)}, ${this.toFixed(y)}`;
281
- }
282
- setHybridType() {
283
- this.hybridType = window.innerWidth > 1340 ? "doughnut0" : "bar1";
284
- }
285
- getType() {
286
- return this.chartType === "hybrid" ? this.hybridType : this.chartType;
287
- }
288
- /* GET THE DATA */
289
- async getData() {
290
- this.slicesData = [];
291
- let acc = 0;
292
- const children = this.el.querySelectorAll("wm-chart-slice");
293
- this.total = Array.from(children).reduce((total, slice) => (total += parseInt(slice.getAttribute("amount") || "0")), 0);
294
- children.forEach((c, i) => {
295
- const amount = parseInt(c.getAttribute("amount") || "0");
296
- const perc = this.amountToPercent(amount, true);
297
- // determine whether the slice is in a cluster of small values
298
- // to avoid percentage text overlap for small values
299
- const prev = children[i === 0 ? children.length - 1 : i - 1];
300
- const prevPerc = this.amountToPercent(parseInt(prev.getAttribute("amount") || "0"), true);
301
- const next = children[i === children.length - 1 ? 0 : i + 1];
302
- const nextPerc = this.amountToPercent(parseInt(next.getAttribute("amount") || "0"), true);
303
- const isSmall = perc < 4;
304
- const prevIsSmall = prevPerc < 5;
305
- const nextIsSmall = nextPerc < 5;
306
- let inSmallCluster = isSmall && (prevIsSmall || nextIsSmall);
307
- // because <1% slice percentage text has an additional character
308
- // the inSmallCluster threshold needs to be widened for that slice only
309
- const lessThanOnePerc = perc === 0 && amount > 0;
310
- if (lessThanOnePerc && (nextPerc < 8 || prevPerc < 8)) {
311
- inSmallCluster = true;
312
- }
313
- // for bar5, first color should be skipped unless notStartedColor is set to true
314
- const ind = this.getType() === "bar5" ? (this.notStartedColor ? i : i + 1) : i;
315
- const color = this.types[this.getType()].colors[ind];
316
- const sliceData = {
317
- amount: amount,
318
- perc: perc,
319
- legend: c.getAttribute("legend"),
320
- color: color || "#d4d4d4",
321
- offset: acc,
322
- id: `${this.uid}-${i + 1}`,
323
- title: c.getAttribute("popover-title"),
324
- text: c.getAttribute("popover-text"),
325
- buttonText: c.getAttribute("popover-button-text"),
326
- sliceRef: c,
327
- inSmallCluster: inSmallCluster,
328
- };
329
- acc += amount;
330
- this.slicesData.push(sliceData);
331
- });
332
- this.chartData = this.types[this.getType()];
333
- }
334
- getSliceEls() {
335
- if (this.svgEl) {
336
- this.sliceEls = Array.from(this.svgEl.querySelectorAll(this.chartData.isBar ? "rect" : "path"));
337
- }
338
- }
339
- handleResize() {
340
- if (this.chartType === "hybrid") {
341
- this.debouncedUpdate();
342
- }
343
- }
344
- async componentWillLoad() {
345
- if (!this.label) {
346
- throw new Error("For accessibility purposes, you must provide a label for the chart. See https://components.watermarkinsights.com/chart for more information.");
347
- }
348
- if (this.chartType === "hybrid") {
349
- this.setHybridType();
350
- }
351
- await this.getData();
352
- }
353
- componentDidLoad() {
354
- this.getSliceEls();
355
- }
356
- componentDidUpdate() {
357
- this.getSliceEls();
358
- }
359
- handleSliceUpdate() {
360
- this.debouncedSliceUpdate();
361
- }
362
- /* RENDERING */
363
- renderFilter() {
364
- return (h("defs", null, h("filter", { id: "wmHoverDropShadow" }, h("feGaussianBlur", { stdDeviation: "3" }), h("feOffset", { result: "offsetblur" }), h("feFlood", { "flood-color": "#333" }), h("feComposite", { operator: "in", in2: "offsetblur" }), h("feMerge", null, h("feMergeNode", null), h("feMergeNode", { in: "SourceGraphic" })))));
365
- }
366
- // DOUGHNUT
367
- renderDoughnut() {
368
- const outerSize = this.chartData.size + this.chartData.padding;
369
- return (h("div", { class: "svg-wrapper doughnut-wrapper" }, h("svg", { width: outerSize + "px", height: outerSize + "px", ref: (el) => (this.svgEl = el), id: `graphic-${this.uid}`, class: `chart-svg doughnut-svg ${this.isTabbing ? "user-is-tabbing" : ""}` }, this.renderFilter(), this.slicesData.map((s) => this.renderPath(s)), this.getType() === "doughnut0" ? (h("text", { class: "value", x: "50%", y: "50%", "font-size": "1.5rem", "font-weight": "500", "text-anchor": "middle", "dominant-baseline": "middle" }, this.amountToPercent(this.slicesData[0].amount, true) + "%")) : (h("g", { transform: `translate(${this.chartData.padding / 2}, ${this.chartData.padding / 2})`, "text-anchor": "middle", "dominant-baseline": "middle" }, this.slicesData.map((s) => (s.amount > 0 ? this.renderDoughnutText(s) : "")))))));
370
- }
371
- renderPath(s) {
372
- return (h("g", { transform: `translate(${this.chartData.padding / 2}, ${this.chartData.padding / 2})` }, h("path", { id: s.id, fill: s.amount ? s.color : "transparent", d: this.getPathData(s.amount, s.offset), onClick: (ev) => {
373
- if (this.popoverEl) {
374
- if (!this.isTabbing) {
375
- s.coords = { x: ev.clientX, y: ev.clientY };
376
- this.openPopover(s);
377
- }
378
- }
379
- }, onFocus: (ev) => {
380
- if (this.popoverEl) {
381
- if (this.isTabbing) {
382
- s.coords = getPosition(ev.target);
383
- this.openPopover(s);
384
- }
385
- }
386
- }, onKeyDown: (ev) => {
387
- if (this.popoverEl && this.popoverEl.open && ev.keyCode === 13) {
388
- const popoverBtn = this.popoverEl.querySelector("button");
389
- popoverBtn && popoverBtn.click();
390
- }
391
- } }), h("text", { class: "sr-only" }, s.legend)));
392
- }
393
- renderDoughnutText(s) {
394
- if (!s.inSmallCluster) {
395
- const arcMiddle = this.amountToDegree(s.offset + s.amount / 2);
396
- let { x, y } = this.polarToCartesian(this.chartData.size / 2, 1.4, arcMiddle - 90);
397
- return (h("text", { class: "value", x: x + "px", y: y + "px" }, `${s.perc > 0 ? s.perc : "<1"}%`));
398
- }
399
- }
400
- // BAR
401
- renderBar() {
402
- return (h("div", { class: "svg-wrapper bar-wrapper" }, this.getType() === "bar1" ? (h("div", { class: "single-perc" }, this.amountToPercent(this.slicesData[0].amount, true) + "%")) : (""), this.drawAxis(), h("svg", { ref: (el) => (this.svgEl = el), id: `graphic-${this.uid}`, class: {
403
- "chart-svg bar-svg": true,
404
- "user-is-tabbing": this.isTabbing,
405
- "show-values": this.showValues === "percentage" || this.showValues === "amount",
406
- } }, this.renderFilter(), h("foreignObject", { class: this.getType() === "bar2" || this.getType() === "bar4" || this.getType() === "bar5" ? "focus-offset" : "" }, h("div", {
407
- // @ts-ignore
408
- xmlns: "http://www.w3.org/1999/xhtml", class: "tabbing-focus"
409
- })), this.slicesData.map((s, idx) => this.renderRect(s, idx)), this.getType() !== "bar1" ? (h("g", { class: "percs" }, this.slicesData.map((s) => (s.perc > 0 ? this.renderBarText(s) : "")))) : (""))));
410
- }
411
- renderRect(s, idx) {
412
- let y;
413
- switch (this.getType()) {
414
- case "bar2":
415
- case "bar4":
416
- case "bar5":
417
- y = this.showValues === "percentage" || this.showValues === "amount" ? "30px" : "0";
418
- break;
419
- default:
420
- y = "0";
421
- }
422
- return (h("g", { class: "barcontainer" }, h("style", null, ` #${s.id} {
423
- fill:${s.color};
424
- x: ${`${this.amountToPercent(s.offset, false)}%`};
425
- y: ${y};
426
- height: 30px;
427
- width: calc(${this.amountToPercent(s.amount, false)}%${idx !== this.slicesData.length - 1 ? " - 2px" : ""});
428
- }`), h("rect", { id: s.id, onClick: (ev) => {
429
- if (this.popoverEl) {
430
- if (!this.isTabbing) {
431
- s.coords = { x: ev.clientX, y: ev.clientY };
432
- this.openPopover(s);
433
- }
434
- }
435
- }, onFocus: (ev) => {
436
- if (this.popoverEl) {
437
- if (this.isTabbing) {
438
- s.coords = getPosition(ev.target);
439
- this.openPopover(s);
440
- }
441
- }
442
- }, onKeyDown: (ev) => {
443
- if (this.popoverEl && this.popoverEl.open && ev.keyCode === 13) {
444
- const popoverBtn = this.popoverEl.querySelector("button");
445
- popoverBtn && popoverBtn.click();
446
- }
447
- } }), h("text", { class: "sr-only" }, s.legend)));
448
- }
449
- renderBarText(s) {
450
- let val;
451
- if (this.showValues === "percentage") {
452
- val = s.perc + "%";
453
- }
454
- else if (this.showValues === "amount") {
455
- val = s.amount;
456
- }
457
- else {
458
- return;
459
- }
460
- return (h("text", { class: "value", x: `${this.amountToPercent(s.offset, false) + this.amountToPercent(s.amount, false) / 2}%` }, val));
461
- }
462
- drawAxis() {
463
- if (this.getType() === "bar3") {
464
- return (h("svg", { class: "axis" }, h("line", { x1: "0", x2: "100%", y1: "0", y2: "0" }), h("line", { x1: "0", x2: "0", y1: "0", y2: "-85px" }), h("line", { class: "tick", x1: "0.5", x2: "0.5", y1: "0", y2: "6" }), h("text", { x: "0.5", y: "-6" }, "0%"), h("line", { class: "tick", x1: "100%", x2: "100%", y1: "0", y2: "6" }), h("text", { x: "100%", y: "-6" }, "100%")));
465
- }
466
- }
467
- renderCompletionMessage() {
468
- if (this.chartType === "hybrid" && this.completionMessage) {
469
- return h("span", { class: "completion-message" }, this.completionMessage);
470
- }
471
- }
472
- renderLegend() {
473
- // legend is hidden for bar1 type regardless of showLegend value
474
- if (this.showLegend) {
475
- const hasCluster = this.slicesData.reduce((hasCluster, cur) => (hasCluster = cur.inSmallCluster ? true : hasCluster), false);
476
- return (h("div", { class: "legend-wrapper" }, h("div", { class: `legend ${this.chartData.isBar ? "--top" : "--bottom"}`, "aria-hidden": "true" }, this.total > 0
477
- ? this.slicesData.map((s) => {
478
- // when both legend and amount are omitted, the legend is not shown for that particular option (it's been deactivated by the user)
479
- if (!!s.amount || !!s.legend) {
480
- return (h("div", { class: "legend-item" }, h("div", { class: "legend-color", style: { "background-color": s.color } }), h("div", { class: "legend-text" }, s.legend)));
481
- }
482
- })
483
- : ""), !this.chartData.isBar && hasCluster ? (h("div", { class: "cluster-warning" }, intl.formatMessage({
484
- id: "chart.hiddenPercentages",
485
- defaultMessage: "Percentages smaller than 5% are not shown when too close to each other.",
486
- }), h("br", null), intl.formatMessage({
487
- id: "chart.clickToSeeDetails",
488
- defaultMessage: "Click or use arrow keys to see details.",
489
- }))) : ("")));
490
- }
491
- }
492
- render() {
493
- return (h(Host, { role: "application", "aria-label": this.label +
494
- ", " +
495
- intl.formatMessage({
496
- id: "chart.interactiveChart",
497
- defaultMessage: "Interactive chart. Use arrow keys to browse elements, press Tab to exit.",
498
- }), tabindex: "0" }, h("div", { class: `component-wrapper ${this.getType()}` }, h("label", { class: "label", id: `label-${this.uid}`, htmlFor: `graphic-${this.uid}` }, h("span", { class: "label-text" }, this.label), this.subinfo ? h("span", { class: "subinfo" }, this.subinfo) : ""), this.chartData.isBar ? this.renderLegend() : "", this.total > 0 && this.chartData.isBar ? this.renderBar() : this.renderDoughnut(), !this.chartData.isBar ? this.renderLegend() : "", h("priv-chart-popover", { class: this.isTabbing ? "user-is-tabbing" : "", ref: (el) => (this.popoverEl = el) }), this.renderCompletionMessage())));
499
- }
500
- get el() { return getElement(this); }
501
- };
502
- Chart.style = wmChartCss;
503
-
504
- export { Chart as wm_chart };