iobroker.vis2-materialdesign 0.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.
Files changed (164) hide show
  1. package/LICENSE +22 -0
  2. package/README.md +198 -0
  3. package/admin/admin.d.ts +93 -0
  4. package/admin/i18n/de.json +985 -0
  5. package/admin/i18n/en.json +985 -0
  6. package/admin/i18n/es.json +985 -0
  7. package/admin/i18n/fr.json +985 -0
  8. package/admin/i18n/it.json +985 -0
  9. package/admin/i18n/nl.json +985 -0
  10. package/admin/i18n/pl.json +985 -0
  11. package/admin/i18n/pt.json +985 -0
  12. package/admin/i18n/ru.json +985 -0
  13. package/admin/i18n/uk.json +985 -0
  14. package/admin/i18n/zh-cn.json +985 -0
  15. package/admin/img/info-big.png +0 -0
  16. package/admin/index_m.html +456 -0
  17. package/admin/index_m.js +1018 -0
  18. package/admin/lib/clipboard-polyfill.promise.js +16 -0
  19. package/admin/lib/colors.json +1304 -0
  20. package/admin/lib/colorsDark.json +1304 -0
  21. package/admin/lib/defaultcolors.json +22 -0
  22. package/admin/lib/defaultcolorsDark.json +22 -0
  23. package/admin/lib/defaultfontSizes.json +14 -0
  24. package/admin/lib/defaultfonts.json +14 -0
  25. package/admin/lib/fontSizes.json +380 -0
  26. package/admin/lib/fonts.json +386 -0
  27. package/admin/lib/monolith.min.css +1 -0
  28. package/admin/lib/pickr.min.js +5 -0
  29. package/admin/materialdesign-widgets-click-sound.mp3 +0 -0
  30. package/admin/style.css +31 -0
  31. package/admin/tsconfig.json +9 -0
  32. package/admin/vis-materialdesign.png +0 -0
  33. package/admin/vis-materialdesign_16_9.png +0 -0
  34. package/admin/words.js +11949 -0
  35. package/io-package.json +184 -0
  36. package/package.json +71 -0
  37. package/widgets/materialdesign/css/widgets.css +7174 -0
  38. package/widgets/materialdesign/css/widgets.min.css +1 -0
  39. package/widgets/materialdesign/img/IoBroker_Logo.png +0 -0
  40. package/widgets/materialdesign/img/bar_chart.png +0 -0
  41. package/widgets/materialdesign/img/calendar.png +0 -0
  42. package/widgets/materialdesign/img/pie_chart.png +0 -0
  43. package/widgets/materialdesign/img/prev_alerts.png +0 -0
  44. package/widgets/materialdesign/img/prev_autocomplete.png +0 -0
  45. package/widgets/materialdesign/img/prev_color_schemes.png +0 -0
  46. package/widgets/materialdesign/img/prev_dialog_view.png +0 -0
  47. package/widgets/materialdesign/img/prev_grid_views.png +0 -0
  48. package/widgets/materialdesign/img/prev_icon.png +0 -0
  49. package/widgets/materialdesign/img/prev_iconlist.png +0 -0
  50. package/widgets/materialdesign/img/prev_input.png +0 -0
  51. package/widgets/materialdesign/img/prev_json_chart.png +0 -0
  52. package/widgets/materialdesign/img/prev_line_history_chart.png +0 -0
  53. package/widgets/materialdesign/img/prev_list.png +0 -0
  54. package/widgets/materialdesign/img/prev_masonry_views.png +0 -0
  55. package/widgets/materialdesign/img/prev_select_bool.png +0 -0
  56. package/widgets/materialdesign/img/prev_select_value.png +0 -0
  57. package/widgets/materialdesign/img/prev_table.png +0 -0
  58. package/widgets/materialdesign/img/prev_top_app_bar_nav_drawer.png +0 -0
  59. package/widgets/materialdesign/img/prev_version.png +0 -0
  60. package/widgets/materialdesign/img/preview.jpg +0 -0
  61. package/widgets/materialdesign/js/materialdesign.js +56 -0
  62. package/widgets/materialdesign/js/widgets/materialdesign.00.helper.js +1229 -0
  63. package/widgets/materialdesign/js/widgets/materialdesign.00.vue.helper.js +710 -0
  64. package/widgets/materialdesign/js/widgets/materialdesign.alerts.js +177 -0
  65. package/widgets/materialdesign/js/widgets/materialdesign.autocomplete.js +263 -0
  66. package/widgets/materialdesign/js/widgets/materialdesign.button.js +1617 -0
  67. package/widgets/materialdesign/js/widgets/materialdesign.calendar.js +472 -0
  68. package/widgets/materialdesign/js/widgets/materialdesign.card.js +276 -0
  69. package/widgets/materialdesign/js/widgets/materialdesign.chart.bar.js +389 -0
  70. package/widgets/materialdesign/js/widgets/materialdesign.chart.helper.js +494 -0
  71. package/widgets/materialdesign/js/widgets/materialdesign.chart.json.js +621 -0
  72. package/widgets/materialdesign/js/widgets/materialdesign.chart.line.js +552 -0
  73. package/widgets/materialdesign/js/widgets/materialdesign.chart.pie.js +380 -0
  74. package/widgets/materialdesign/js/widgets/materialdesign.checkbox.js +281 -0
  75. package/widgets/materialdesign/js/widgets/materialdesign.colorschemes.js +129 -0
  76. package/widgets/materialdesign/js/widgets/materialdesign.dialog.js +384 -0
  77. package/widgets/materialdesign/js/widgets/materialdesign.iconList.js +873 -0
  78. package/widgets/materialdesign/js/widgets/materialdesign.list.js +503 -0
  79. package/widgets/materialdesign/js/widgets/materialdesign.materialdesignicons.js +7055 -0
  80. package/widgets/materialdesign/js/widgets/materialdesign.progress.js +413 -0
  81. package/widgets/materialdesign/js/widgets/materialdesign.roundslider.js +267 -0
  82. package/widgets/materialdesign/js/widgets/materialdesign.select.js +243 -0
  83. package/widgets/materialdesign/js/widgets/materialdesign.slider.js +363 -0
  84. package/widgets/materialdesign/js/widgets/materialdesign.switch.js +284 -0
  85. package/widgets/materialdesign/js/widgets/materialdesign.table.js +688 -0
  86. package/widgets/materialdesign/js/widgets/materialdesign.textfield.js +260 -0
  87. package/widgets/materialdesign/js/widgets/materialdesign.topappbarnav.js +747 -0
  88. package/widgets/materialdesign/js/widgets/materialdesign.value.js +369 -0
  89. package/widgets/materialdesign/js/widgets/materialdesign.views.js +827 -0
  90. package/widgets/materialdesign/js/widgets/materialdesign.viseditor.js +1088 -0
  91. package/widgets/materialdesign/js/widgets.min.js +1 -0
  92. package/widgets/materialdesign/lib/Chart.css +47 -0
  93. package/widgets/materialdesign/lib/Chart.js +16151 -0
  94. package/widgets/materialdesign/lib/VueTheMask.umd.js +556 -0
  95. package/widgets/materialdesign/lib/chartjs-plugin-datalabels.js +1385 -0
  96. package/widgets/materialdesign/lib/chroma.js +3225 -0
  97. package/widgets/materialdesign/lib/fonts/material-design-icons/materialdesignicons-webfont.ttf +0 -0
  98. package/widgets/materialdesign/lib/fonts/material-design-icons/materialdesignicons.css +27457 -0
  99. package/widgets/materialdesign/lib/fonts/material-design-icons/materialdesignicons.min.css +1 -0
  100. package/widgets/materialdesign/lib/fonts/material-icons/MaterialIcons-Regular.ttf +0 -0
  101. package/widgets/materialdesign/lib/fonts/material-icons/material-icons.css +31 -0
  102. package/widgets/materialdesign/lib/he.js +345 -0
  103. package/widgets/materialdesign/lib/jquery.initialize.js +156 -0
  104. package/widgets/materialdesign/lib/jquery.knob.js +820 -0
  105. package/widgets/materialdesign/lib/jquery.mobile-events.js +940 -0
  106. package/widgets/materialdesign/lib/material-components-web.css +10011 -0
  107. package/widgets/materialdesign/lib/material-components-web.js +22651 -0
  108. package/widgets/materialdesign/lib/math.js +41 -0
  109. package/widgets/materialdesign/lib/moment-duration-format.js +1737 -0
  110. package/widgets/materialdesign/lib/myUnderscore.js +1695 -0
  111. package/widgets/materialdesign/lib/raw/moment-with-locales.min.js +28 -0
  112. package/widgets/materialdesign/lib/raw/round-slider.js +271 -0
  113. package/widgets/materialdesign/lib/raw/sentry/bundle.min.js +3 -0
  114. package/widgets/materialdesign/lib/raw/sentry/captureconsole.min.js +2 -0
  115. package/widgets/materialdesign/lib/raw/sentry/dedupe.min.js +2 -0
  116. package/widgets/materialdesign/lib/svg-inject.js +697 -0
  117. package/widgets/materialdesign/lib/vue.js +11965 -0
  118. package/widgets/materialdesign/lib/vuetify.js +43729 -0
  119. package/widgets/materialdesign/lib.min.css +1 -0
  120. package/widgets/materialdesign/lib.min.js +6285 -0
  121. package/widgets/materialdesign.html +1063 -0
  122. package/widgets/vis2-materialdesign/assets/MaterialDesignButtonAdition-BOasvewn.js +1 -0
  123. package/widgets/vis2-materialdesign/assets/MaterialDesignButtonAditionVertical-CfxLrjtz.js +1 -0
  124. package/widgets/vis2-materialdesign/assets/MaterialDesignButtonLink-DFOHalVe.js +1 -0
  125. package/widgets/vis2-materialdesign/assets/MaterialDesignButtonLinkVertical-bLBc2Zj6.js +1 -0
  126. package/widgets/vis2-materialdesign/assets/MaterialDesignButtonNavigation-loocTeHA.js +1 -0
  127. package/widgets/vis2-materialdesign/assets/MaterialDesignButtonNavigationVertical-wKivh3mz.js +1 -0
  128. package/widgets/vis2-materialdesign/assets/MaterialDesignButtonState-DyuzNIZY.js +1 -0
  129. package/widgets/vis2-materialdesign/assets/MaterialDesignButtonStateMulti-D9YVumU3.js +1 -0
  130. package/widgets/vis2-materialdesign/assets/MaterialDesignButtonStateMultiVertical-J7SUuXNA.js +1 -0
  131. package/widgets/vis2-materialdesign/assets/MaterialDesignButtonStateVertical-EhVri-Bj.js +1 -0
  132. package/widgets/vis2-materialdesign/assets/MaterialDesignButtonToggle-CLxaT9SA.js +1 -0
  133. package/widgets/vis2-materialdesign/assets/MaterialDesignButtonToggleVertical-4zI4T-cI.js +1 -0
  134. package/widgets/vis2-materialdesign/assets/MaterialDesignButtons-BHDA55zY.js +1 -0
  135. package/widgets/vis2-materialdesign/assets/MaterialDesignCheckbox-Dwl43BB6.js +1 -0
  136. package/widgets/vis2-materialdesign/assets/MaterialDesignIcon-07Jl1QSv.js +1 -0
  137. package/widgets/vis2-materialdesign/assets/MaterialDesignIconButtonAdition-DkyLUAuu.js +1 -0
  138. package/widgets/vis2-materialdesign/assets/MaterialDesignIconButtonLink-CFh_41FT.js +1 -0
  139. package/widgets/vis2-materialdesign/assets/MaterialDesignIconButtonNavigation-CLvhcORZ.js +1 -0
  140. package/widgets/vis2-materialdesign/assets/MaterialDesignIconButtonSlider-TfUJKNib.js +1 -0
  141. package/widgets/vis2-materialdesign/assets/MaterialDesignIconButtonState-Con_l2iN.js +1 -0
  142. package/widgets/vis2-materialdesign/assets/MaterialDesignIconButtonStateMulti-DuakGd7h.js +1 -0
  143. package/widgets/vis2-materialdesign/assets/MaterialDesignIconButtonToggle-B3Yxo-Ii.js +1 -0
  144. package/widgets/vis2-materialdesign/assets/MaterialDesignSwitch-BPSYRrDe.js +1 -0
  145. package/widgets/vis2-materialdesign/assets/MaterialDesignValue-D5sJ-iyi.js +1 -0
  146. package/widgets/vis2-materialdesign/assets/_virtual_mf-localSharedImportMap___mfe_internal__vis2MaterialDesignWidgets-BFI0756z.js +1 -0
  147. package/widgets/vis2-materialdesign/assets/_virtual_mf___mfe_internal__vis2MaterialDesignWidgets__loadShare__react__loadShare__.js-4V-ZaKyJ.js +1 -0
  148. package/widgets/vis2-materialdesign/assets/_virtual_mf___mfe_internal__vis2MaterialDesignWidgets__loadShare__react_mf_1_jsx_mf_2_runtime__loadShare__.js-Eu2aWCKd.js +1 -0
  149. package/widgets/vis2-materialdesign/assets/_virtual_mf___mfe_internal__vis2MaterialDesignWidgets__loadShare__react_mf_2_dom__loadShare__.js-D3wyrTEe.js +8 -0
  150. package/widgets/vis2-materialdesign/assets/hostInit-CP4jqDxy.js +1 -0
  151. package/widgets/vis2-materialdesign/assets/index-jMDUG1V1.js +1 -0
  152. package/widgets/vis2-materialdesign/assets/mf-entry-bootstrap-0-5bdbe7bd.js +35 -0
  153. package/widgets/vis2-materialdesign/assets/rolldown-runtime-CNC7AqOf.js +1 -0
  154. package/widgets/vis2-materialdesign/assets/translations-CYT3A7CQ.js +1 -0
  155. package/widgets/vis2-materialdesign/assets/virtualExposes-BFTZrXtp.js +1 -0
  156. package/widgets/vis2-materialdesign/assets/virtual_mf-REMOTE_ENTRY_ID___mfe_internal__vis2MaterialDesignWidgets__customWidgets_js-BOvf1QCd.js +4 -0
  157. package/widgets/vis2-materialdesign/assets/virtual_mf-exposes-ssr___mfe_internal__vis2MaterialDesignWidgets__customWidgets_js-vY7qHvFF.js +2 -0
  158. package/widgets/vis2-materialdesign/assets/virtual_mf-exposes___mfe_internal__vis2MaterialDesignWidgets__customWidgets_js-C28iDRsy.js +2 -0
  159. package/widgets/vis2-materialdesign/assets/vite-preload-helper-DuG8C5Si.js +1 -0
  160. package/widgets/vis2-materialdesign/assets/widgetUtils-D_-xivaB.js +1 -0
  161. package/widgets/vis2-materialdesign/customWidgets.js +1 -0
  162. package/widgets/vis2-materialdesign/customWidgets.ssr.js +1 -0
  163. package/widgets/vis2-materialdesign/materialdesign-widgets-click-sound.mp3 +0 -0
  164. package/widgets/vis2-materialdesign/mf-stats.json +1 -0
@@ -0,0 +1,1385 @@
1
+ /*!
2
+ * chartjs-plugin-datalabels v0.7.0
3
+ * https://chartjs-plugin-datalabels.netlify.com
4
+ * (c) 2019 Chart.js Contributors
5
+ * Released under the MIT license
6
+ */
7
+ (function (global, factory) {
8
+ typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory(require('chart.js')) :
9
+ typeof define === 'function' && define.amd ? define(['chart.js'], factory) :
10
+ (global = global || self, global.ChartDataLabels = factory(global.Chart));
11
+ }(this, function (Chart) { 'use strict';
12
+
13
+ Chart = Chart && Chart.hasOwnProperty('default') ? Chart['default'] : Chart;
14
+
15
+ var helpers = Chart.helpers;
16
+
17
+ var devicePixelRatio = (function() {
18
+ if (typeof window !== 'undefined') {
19
+ if (window.devicePixelRatio) {
20
+ return window.devicePixelRatio;
21
+ }
22
+
23
+ // devicePixelRatio is undefined on IE10
24
+ // https://stackoverflow.com/a/20204180/8837887
25
+ // https://github.com/chartjs/chartjs-plugin-datalabels/issues/85
26
+ var screen = window.screen;
27
+ if (screen) {
28
+ return (screen.deviceXDPI || 1) / (screen.logicalXDPI || 1);
29
+ }
30
+ }
31
+
32
+ return 1;
33
+ }());
34
+
35
+ var utils = {
36
+ // @todo move this in Chart.helpers.toTextLines
37
+ toTextLines: function(inputs) {
38
+ var lines = [];
39
+ var input;
40
+
41
+ inputs = [].concat(inputs);
42
+ while (inputs.length) {
43
+ input = inputs.pop();
44
+ if (typeof input === 'string') {
45
+ lines.unshift.apply(lines, input.split('\n'));
46
+ } else if (Array.isArray(input)) {
47
+ inputs.push.apply(inputs, input);
48
+ } else if (!helpers.isNullOrUndef(inputs)) {
49
+ lines.unshift('' + input);
50
+ }
51
+ }
52
+
53
+ return lines;
54
+ },
55
+
56
+ // @todo move this method in Chart.helpers.canvas.toFont (deprecates helpers.fontString)
57
+ // @see https://developer.mozilla.org/en-US/docs/Web/CSS/font
58
+ toFontString: function(font) {
59
+ if (!font || helpers.isNullOrUndef(font.size) || helpers.isNullOrUndef(font.family)) {
60
+ return null;
61
+ }
62
+
63
+ return (font.style ? font.style + ' ' : '')
64
+ + (font.weight ? font.weight + ' ' : '')
65
+ + font.size + 'px '
66
+ + font.family;
67
+ },
68
+
69
+ // @todo move this in Chart.helpers.canvas.textSize
70
+ // @todo cache calls of measureText if font doesn't change?!
71
+ textSize: function(ctx, lines, font) {
72
+ var items = [].concat(lines);
73
+ var ilen = items.length;
74
+ var prev = ctx.font;
75
+ var width = 0;
76
+ var i;
77
+
78
+ ctx.font = font.string;
79
+
80
+ for (i = 0; i < ilen; ++i) {
81
+ width = Math.max(ctx.measureText(items[i]).width, width);
82
+ }
83
+
84
+ ctx.font = prev;
85
+
86
+ return {
87
+ height: ilen * font.lineHeight,
88
+ width: width
89
+ };
90
+ },
91
+
92
+ // @todo move this method in Chart.helpers.options.toFont
93
+ parseFont: function(value) {
94
+ var global = Chart.defaults.global;
95
+ var size = helpers.valueOrDefault(value.size, global.defaultFontSize);
96
+ var font = {
97
+ family: helpers.valueOrDefault(value.family, global.defaultFontFamily),
98
+ lineHeight: helpers.options.toLineHeight(value.lineHeight, size),
99
+ size: size,
100
+ style: helpers.valueOrDefault(value.style, global.defaultFontStyle),
101
+ weight: helpers.valueOrDefault(value.weight, null),
102
+ string: ''
103
+ };
104
+
105
+ font.string = utils.toFontString(font);
106
+ return font;
107
+ },
108
+
109
+ /**
110
+ * Returns value bounded by min and max. This is equivalent to max(min, min(value, max)).
111
+ * @todo move this method in Chart.helpers.bound
112
+ * https://doc.qt.io/qt-5/qtglobal.html#qBound
113
+ */
114
+ bound: function(min, value, max) {
115
+ return Math.max(min, Math.min(value, max));
116
+ },
117
+
118
+ /**
119
+ * Returns an array of pair [value, state] where state is:
120
+ * * -1: value is only in a0 (removed)
121
+ * * 1: value is only in a1 (added)
122
+ */
123
+ arrayDiff: function(a0, a1) {
124
+ var prev = a0.slice();
125
+ var updates = [];
126
+ var i, j, ilen, v;
127
+
128
+ for (i = 0, ilen = a1.length; i < ilen; ++i) {
129
+ v = a1[i];
130
+ j = prev.indexOf(v);
131
+
132
+ if (j === -1) {
133
+ updates.push([v, 1]);
134
+ } else {
135
+ prev.splice(j, 1);
136
+ }
137
+ }
138
+
139
+ for (i = 0, ilen = prev.length; i < ilen; ++i) {
140
+ updates.push([prev[i], -1]);
141
+ }
142
+
143
+ return updates;
144
+ },
145
+
146
+ /**
147
+ * https://github.com/chartjs/chartjs-plugin-datalabels/issues/70
148
+ */
149
+ rasterize: function(v) {
150
+ return Math.round(v * devicePixelRatio) / devicePixelRatio;
151
+ }
152
+ };
153
+
154
+ function orient(point, origin) {
155
+ var x0 = origin.x;
156
+ var y0 = origin.y;
157
+
158
+ if (x0 === null) {
159
+ return {x: 0, y: -1};
160
+ }
161
+ if (y0 === null) {
162
+ return {x: 1, y: 0};
163
+ }
164
+
165
+ var dx = point.x - x0;
166
+ var dy = point.y - y0;
167
+ var ln = Math.sqrt(dx * dx + dy * dy);
168
+
169
+ return {
170
+ x: ln ? dx / ln : 0,
171
+ y: ln ? dy / ln : -1
172
+ };
173
+ }
174
+
175
+ function aligned(x, y, vx, vy, align) {
176
+ switch (align) {
177
+ case 'center':
178
+ vx = vy = 0;
179
+ break;
180
+ case 'bottom':
181
+ vx = 0;
182
+ vy = 1;
183
+ break;
184
+ case 'right':
185
+ vx = 1;
186
+ vy = 0;
187
+ break;
188
+ case 'left':
189
+ vx = -1;
190
+ vy = 0;
191
+ break;
192
+ case 'top':
193
+ vx = 0;
194
+ vy = -1;
195
+ break;
196
+ case 'start':
197
+ vx = -vx;
198
+ vy = -vy;
199
+ break;
200
+ case 'end':
201
+ // keep natural orientation
202
+ break;
203
+ default:
204
+ // clockwise rotation (in degree)
205
+ align *= (Math.PI / 180);
206
+ vx = Math.cos(align);
207
+ vy = Math.sin(align);
208
+ break;
209
+ }
210
+
211
+ return {
212
+ x: x,
213
+ y: y,
214
+ vx: vx,
215
+ vy: vy
216
+ };
217
+ }
218
+
219
+ // Line clipping (Cohen–Sutherland algorithm)
220
+ // https://en.wikipedia.org/wiki/Cohen–Sutherland_algorithm
221
+
222
+ var R_INSIDE = 0;
223
+ var R_LEFT = 1;
224
+ var R_RIGHT = 2;
225
+ var R_BOTTOM = 4;
226
+ var R_TOP = 8;
227
+
228
+ function region(x, y, rect) {
229
+ var res = R_INSIDE;
230
+
231
+ if (x < rect.left) {
232
+ res |= R_LEFT;
233
+ } else if (x > rect.right) {
234
+ res |= R_RIGHT;
235
+ }
236
+ if (y < rect.top) {
237
+ res |= R_TOP;
238
+ } else if (y > rect.bottom) {
239
+ res |= R_BOTTOM;
240
+ }
241
+
242
+ return res;
243
+ }
244
+
245
+ function clipped(segment, area) {
246
+ var x0 = segment.x0;
247
+ var y0 = segment.y0;
248
+ var x1 = segment.x1;
249
+ var y1 = segment.y1;
250
+ var r0 = region(x0, y0, area);
251
+ var r1 = region(x1, y1, area);
252
+ var r, x, y;
253
+
254
+ // eslint-disable-next-line no-constant-condition
255
+ while (true) {
256
+ if (!(r0 | r1) || (r0 & r1)) {
257
+ // both points inside or on the same side: no clipping
258
+ break;
259
+ }
260
+
261
+ // at least one point is outside
262
+ r = r0 || r1;
263
+
264
+ if (r & R_TOP) {
265
+ x = x0 + (x1 - x0) * (area.top - y0) / (y1 - y0);
266
+ y = area.top;
267
+ } else if (r & R_BOTTOM) {
268
+ x = x0 + (x1 - x0) * (area.bottom - y0) / (y1 - y0);
269
+ y = area.bottom;
270
+ } else if (r & R_RIGHT) {
271
+ y = y0 + (y1 - y0) * (area.right - x0) / (x1 - x0);
272
+ x = area.right;
273
+ } else if (r & R_LEFT) {
274
+ y = y0 + (y1 - y0) * (area.left - x0) / (x1 - x0);
275
+ x = area.left;
276
+ }
277
+
278
+ if (r === r0) {
279
+ x0 = x;
280
+ y0 = y;
281
+ r0 = region(x0, y0, area);
282
+ } else {
283
+ x1 = x;
284
+ y1 = y;
285
+ r1 = region(x1, y1, area);
286
+ }
287
+ }
288
+
289
+ return {
290
+ x0: x0,
291
+ x1: x1,
292
+ y0: y0,
293
+ y1: y1
294
+ };
295
+ }
296
+
297
+ function compute(range, config) {
298
+ var anchor = config.anchor;
299
+ var segment = range;
300
+ var x, y;
301
+
302
+ if (config.clamp) {
303
+ segment = clipped(segment, config.area);
304
+ }
305
+
306
+ if (anchor === 'start') {
307
+ x = segment.x0;
308
+ y = segment.y0;
309
+ } else if (anchor === 'end') {
310
+ x = segment.x1;
311
+ y = segment.y1;
312
+ } else {
313
+ x = (segment.x0 + segment.x1) / 2;
314
+ y = (segment.y0 + segment.y1) / 2;
315
+ }
316
+
317
+ return aligned(x, y, range.vx, range.vy, config.align);
318
+ }
319
+
320
+ var positioners = {
321
+ arc: function(vm, config) {
322
+ var angle = (vm.startAngle + vm.endAngle) / 2;
323
+ var vx = Math.cos(angle);
324
+ var vy = Math.sin(angle);
325
+ var r0 = vm.innerRadius;
326
+ var r1 = vm.outerRadius;
327
+
328
+ return compute({
329
+ x0: vm.x + vx * r0,
330
+ y0: vm.y + vy * r0,
331
+ x1: vm.x + vx * r1,
332
+ y1: vm.y + vy * r1,
333
+ vx: vx,
334
+ vy: vy
335
+ }, config);
336
+ },
337
+
338
+ point: function(vm, config) {
339
+ var v = orient(vm, config.origin);
340
+ var rx = v.x * vm.radius;
341
+ var ry = v.y * vm.radius;
342
+
343
+ return compute({
344
+ x0: vm.x - rx,
345
+ y0: vm.y - ry,
346
+ x1: vm.x + rx,
347
+ y1: vm.y + ry,
348
+ vx: v.x,
349
+ vy: v.y
350
+ }, config);
351
+ },
352
+
353
+ rect: function(vm, config) {
354
+ var v = orient(vm, config.origin);
355
+ var x = vm.x;
356
+ var y = vm.y;
357
+ var sx = 0;
358
+ var sy = 0;
359
+
360
+ if (vm.horizontal) {
361
+ x = Math.min(vm.x, vm.base);
362
+ sx = Math.abs(vm.base - vm.x);
363
+ } else {
364
+ y = Math.min(vm.y, vm.base);
365
+ sy = Math.abs(vm.base - vm.y);
366
+ }
367
+
368
+ return compute({
369
+ x0: x,
370
+ y0: y + sy,
371
+ x1: x + sx,
372
+ y1: y,
373
+ vx: v.x,
374
+ vy: v.y
375
+ }, config);
376
+ },
377
+
378
+ fallback: function(vm, config) {
379
+ var v = orient(vm, config.origin);
380
+
381
+ return compute({
382
+ x0: vm.x,
383
+ y0: vm.y,
384
+ x1: vm.x,
385
+ y1: vm.y,
386
+ vx: v.x,
387
+ vy: v.y
388
+ }, config);
389
+ }
390
+ };
391
+
392
+ var helpers$1 = Chart.helpers;
393
+ var rasterize = utils.rasterize;
394
+
395
+ function boundingRects(model) {
396
+ var borderWidth = model.borderWidth || 0;
397
+ var padding = model.padding;
398
+ var th = model.size.height;
399
+ var tw = model.size.width;
400
+ var tx = -tw / 2;
401
+ var ty = -th / 2;
402
+
403
+ return {
404
+ frame: {
405
+ x: tx - padding.left - borderWidth,
406
+ y: ty - padding.top - borderWidth,
407
+ w: tw + padding.width + borderWidth * 2,
408
+ h: th + padding.height + borderWidth * 2
409
+ },
410
+ text: {
411
+ x: tx,
412
+ y: ty,
413
+ w: tw,
414
+ h: th
415
+ }
416
+ };
417
+ }
418
+
419
+ function getScaleOrigin(el) {
420
+ var horizontal = el._model.horizontal;
421
+ var scale = el._scale || (horizontal && el._xScale) || el._yScale;
422
+
423
+ if (!scale) {
424
+ return null;
425
+ }
426
+
427
+ if (scale.xCenter !== undefined && scale.yCenter !== undefined) {
428
+ return {x: scale.xCenter, y: scale.yCenter};
429
+ }
430
+
431
+ var pixel = scale.getBasePixel();
432
+ return horizontal ?
433
+ {x: pixel, y: null} :
434
+ {x: null, y: pixel};
435
+ }
436
+
437
+ function getPositioner(el) {
438
+ if (el instanceof Chart.elements.Arc) {
439
+ return positioners.arc;
440
+ }
441
+ if (el instanceof Chart.elements.Point) {
442
+ return positioners.point;
443
+ }
444
+ if (el instanceof Chart.elements.Rectangle) {
445
+ return positioners.rect;
446
+ }
447
+ return positioners.fallback;
448
+ }
449
+
450
+ function drawFrame(ctx, rect, model) {
451
+ var bgColor = model.backgroundColor;
452
+ var borderColor = model.borderColor;
453
+ var borderWidth = model.borderWidth;
454
+
455
+ if (!bgColor && (!borderColor || !borderWidth)) {
456
+ return;
457
+ }
458
+
459
+ ctx.beginPath();
460
+
461
+ helpers$1.canvas.roundedRect(
462
+ ctx,
463
+ rasterize(rect.x) + borderWidth / 2,
464
+ rasterize(rect.y) + borderWidth / 2,
465
+ rasterize(rect.w) - borderWidth,
466
+ rasterize(rect.h) - borderWidth,
467
+ model.borderRadius);
468
+
469
+ ctx.closePath();
470
+
471
+ if (bgColor) {
472
+ ctx.fillStyle = bgColor;
473
+ ctx.fill();
474
+ }
475
+
476
+ if (borderColor && borderWidth) {
477
+ ctx.strokeStyle = borderColor;
478
+ ctx.lineWidth = borderWidth;
479
+ ctx.lineJoin = 'miter';
480
+ ctx.stroke();
481
+ }
482
+ }
483
+
484
+ function textGeometry(rect, align, font) {
485
+ var h = font.lineHeight;
486
+ var w = rect.w;
487
+ var x = rect.x;
488
+ var y = rect.y + h / 2;
489
+
490
+ if (align === 'center') {
491
+ x += w / 2;
492
+ } else if (align === 'end' || align === 'right') {
493
+ x += w;
494
+ }
495
+
496
+ return {
497
+ h: h,
498
+ w: w,
499
+ x: x,
500
+ y: y
501
+ };
502
+ }
503
+
504
+ function drawTextLine(ctx, text, cfg) {
505
+ var shadow = ctx.shadowBlur;
506
+ var stroked = cfg.stroked;
507
+ var x = rasterize(cfg.x);
508
+ var y = rasterize(cfg.y);
509
+ var w = rasterize(cfg.w);
510
+
511
+ if (stroked) {
512
+ ctx.strokeText(text, x, y, w);
513
+ }
514
+
515
+ if (cfg.filled) {
516
+ if (shadow && stroked) {
517
+ // Prevent drawing shadow on both the text stroke and fill, so
518
+ // if the text is stroked, remove the shadow for the text fill.
519
+ ctx.shadowBlur = 0;
520
+ }
521
+
522
+ ctx.fillText(text, x, y, w);
523
+
524
+ if (shadow && stroked) {
525
+ ctx.shadowBlur = shadow;
526
+ }
527
+ }
528
+ }
529
+
530
+ function drawText(ctx, lines, rect, model) {
531
+ var align = model.textAlign;
532
+ var color = model.color;
533
+ var filled = !!color;
534
+ var font = model.font;
535
+ var ilen = lines.length;
536
+ var strokeColor = model.textStrokeColor;
537
+ var strokeWidth = model.textStrokeWidth;
538
+ var stroked = strokeColor && strokeWidth;
539
+ var i;
540
+
541
+ if (!ilen || (!filled && !stroked)) {
542
+ return;
543
+ }
544
+
545
+ // Adjust coordinates based on text alignment and line height
546
+ rect = textGeometry(rect, align, font);
547
+
548
+ ctx.font = font.string;
549
+ ctx.textAlign = align;
550
+ ctx.textBaseline = 'middle';
551
+ ctx.shadowBlur = model.textShadowBlur;
552
+ ctx.shadowColor = model.textShadowColor;
553
+
554
+ if (filled) {
555
+ ctx.fillStyle = color;
556
+ }
557
+ if (stroked) {
558
+ ctx.lineJoin = 'round';
559
+ ctx.lineWidth = strokeWidth;
560
+ ctx.strokeStyle = strokeColor;
561
+ }
562
+
563
+ for (i = 0, ilen = lines.length; i < ilen; ++i) {
564
+ drawTextLine(ctx, lines[i], {
565
+ stroked: stroked,
566
+ filled: filled,
567
+ w: rect.w,
568
+ x: rect.x,
569
+ y: rect.y + rect.h * i
570
+ });
571
+ }
572
+ }
573
+
574
+ var Label = function(config, ctx, el, index) {
575
+ var me = this;
576
+
577
+ me._config = config;
578
+ me._index = index;
579
+ me._model = null;
580
+ me._rects = null;
581
+ me._ctx = ctx;
582
+ me._el = el;
583
+ };
584
+
585
+ helpers$1.extend(Label.prototype, {
586
+ /**
587
+ * @private
588
+ */
589
+ _modelize: function(display, lines, config, context) {
590
+ var me = this;
591
+ var index = me._index;
592
+ var resolve = helpers$1.options.resolve;
593
+ var font = utils.parseFont(resolve([config.font, {}], context, index));
594
+ var color = resolve([config.color, Chart.defaults.global.defaultFontColor], context, index);
595
+
596
+ return {
597
+ align: resolve([config.align, 'center'], context, index),
598
+ anchor: resolve([config.anchor, 'center'], context, index),
599
+ area: context.chart.chartArea,
600
+ backgroundColor: resolve([config.backgroundColor, null], context, index),
601
+ borderColor: resolve([config.borderColor, null], context, index),
602
+ borderRadius: resolve([config.borderRadius, 0], context, index),
603
+ borderWidth: resolve([config.borderWidth, 0], context, index),
604
+ clamp: resolve([config.clamp, false], context, index),
605
+ clip: resolve([config.clip, false], context, index),
606
+ color: color,
607
+ display: display,
608
+ font: font,
609
+ lines: lines,
610
+ offset: resolve([config.offset, 0], context, index),
611
+ opacity: resolve([config.opacity, 1], context, index),
612
+ origin: getScaleOrigin(me._el),
613
+ padding: helpers$1.options.toPadding(resolve([config.padding, 0], context, index)),
614
+ positioner: getPositioner(me._el),
615
+ rotation: resolve([config.rotation, 0], context, index) * (Math.PI / 180),
616
+ size: utils.textSize(me._ctx, lines, font),
617
+ textAlign: resolve([config.textAlign, 'start'], context, index),
618
+ textShadowBlur: resolve([config.textShadowBlur, 0], context, index),
619
+ textShadowColor: resolve([config.textShadowColor, color], context, index),
620
+ textStrokeColor: resolve([config.textStrokeColor, color], context, index),
621
+ textStrokeWidth: resolve([config.textStrokeWidth, 0], context, index)
622
+ };
623
+ },
624
+
625
+ update: function(context) {
626
+ var me = this;
627
+ var model = null;
628
+ var rects = null;
629
+ var index = me._index;
630
+ var config = me._config;
631
+ var value, label, lines;
632
+
633
+ // We first resolve the display option (separately) to avoid computing
634
+ // other options in case the label is hidden (i.e. display: false).
635
+ var display = helpers$1.options.resolve([config.display, true], context, index);
636
+
637
+ if (display) {
638
+ value = context.dataset.data[index];
639
+ label = helpers$1.valueOrDefault(helpers$1.callback(config.formatter, [value, context]), value);
640
+ lines = helpers$1.isNullOrUndef(label) ? [] : utils.toTextLines(label);
641
+
642
+ if (lines.length) {
643
+ model = me._modelize(display, lines, config, context);
644
+ rects = boundingRects(model);
645
+ }
646
+ }
647
+
648
+ me._model = model;
649
+ me._rects = rects;
650
+ },
651
+
652
+ geometry: function() {
653
+ return this._rects ? this._rects.frame : {};
654
+ },
655
+
656
+ rotation: function() {
657
+ return this._model ? this._model.rotation : 0;
658
+ },
659
+
660
+ visible: function() {
661
+ return this._model && this._model.opacity;
662
+ },
663
+
664
+ model: function() {
665
+ return this._model;
666
+ },
667
+
668
+ draw: function(chart, center) {
669
+ var me = this;
670
+ var ctx = chart.ctx;
671
+ var model = me._model;
672
+ var rects = me._rects;
673
+ var area;
674
+
675
+ if (!this.visible()) {
676
+ return;
677
+ }
678
+
679
+ ctx.save();
680
+
681
+ if (model.clip) {
682
+ area = model.area;
683
+ ctx.beginPath();
684
+ ctx.rect(
685
+ area.left,
686
+ area.top,
687
+ area.right - area.left,
688
+ area.bottom - area.top);
689
+ ctx.clip();
690
+ }
691
+
692
+ ctx.globalAlpha = utils.bound(0, model.opacity, 1);
693
+ ctx.translate(rasterize(center.x), rasterize(center.y));
694
+ ctx.rotate(model.rotation);
695
+
696
+ drawFrame(ctx, rects.frame, model);
697
+ drawText(ctx, model.lines, rects.text, model);
698
+
699
+ ctx.restore();
700
+ }
701
+ });
702
+
703
+ var helpers$2 = Chart.helpers;
704
+
705
+ var MIN_INTEGER = Number.MIN_SAFE_INTEGER || -9007199254740991; // eslint-disable-line es/no-number-minsafeinteger
706
+ var MAX_INTEGER = Number.MAX_SAFE_INTEGER || 9007199254740991; // eslint-disable-line es/no-number-maxsafeinteger
707
+
708
+ function rotated(point, center, angle) {
709
+ var cos = Math.cos(angle);
710
+ var sin = Math.sin(angle);
711
+ var cx = center.x;
712
+ var cy = center.y;
713
+
714
+ return {
715
+ x: cx + cos * (point.x - cx) - sin * (point.y - cy),
716
+ y: cy + sin * (point.x - cx) + cos * (point.y - cy)
717
+ };
718
+ }
719
+
720
+ function projected(points, axis) {
721
+ var min = MAX_INTEGER;
722
+ var max = MIN_INTEGER;
723
+ var origin = axis.origin;
724
+ var i, pt, vx, vy, dp;
725
+
726
+ for (i = 0; i < points.length; ++i) {
727
+ pt = points[i];
728
+ vx = pt.x - origin.x;
729
+ vy = pt.y - origin.y;
730
+ dp = axis.vx * vx + axis.vy * vy;
731
+ min = Math.min(min, dp);
732
+ max = Math.max(max, dp);
733
+ }
734
+
735
+ return {
736
+ min: min,
737
+ max: max
738
+ };
739
+ }
740
+
741
+ function toAxis(p0, p1) {
742
+ var vx = p1.x - p0.x;
743
+ var vy = p1.y - p0.y;
744
+ var ln = Math.sqrt(vx * vx + vy * vy);
745
+
746
+ return {
747
+ vx: (p1.x - p0.x) / ln,
748
+ vy: (p1.y - p0.y) / ln,
749
+ origin: p0,
750
+ ln: ln
751
+ };
752
+ }
753
+
754
+ var HitBox = function() {
755
+ this._rotation = 0;
756
+ this._rect = {
757
+ x: 0,
758
+ y: 0,
759
+ w: 0,
760
+ h: 0
761
+ };
762
+ };
763
+
764
+ helpers$2.extend(HitBox.prototype, {
765
+ center: function() {
766
+ var r = this._rect;
767
+ return {
768
+ x: r.x + r.w / 2,
769
+ y: r.y + r.h / 2
770
+ };
771
+ },
772
+
773
+ update: function(center, rect, rotation) {
774
+ this._rotation = rotation;
775
+ this._rect = {
776
+ x: rect.x + center.x,
777
+ y: rect.y + center.y,
778
+ w: rect.w,
779
+ h: rect.h
780
+ };
781
+ },
782
+
783
+ contains: function(point) {
784
+ var me = this;
785
+ var margin = 1;
786
+ var rect = me._rect;
787
+
788
+ point = rotated(point, me.center(), -me._rotation);
789
+
790
+ return !(point.x < rect.x - margin
791
+ || point.y < rect.y - margin
792
+ || point.x > rect.x + rect.w + margin * 2
793
+ || point.y > rect.y + rect.h + margin * 2);
794
+ },
795
+
796
+ // Separating Axis Theorem
797
+ // https://gamedevelopment.tutsplus.com/tutorials/collision-detection-using-the-separating-axis-theorem--gamedev-169
798
+ intersects: function(other) {
799
+ var r0 = this._points();
800
+ var r1 = other._points();
801
+ var axes = [
802
+ toAxis(r0[0], r0[1]),
803
+ toAxis(r0[0], r0[3])
804
+ ];
805
+ var i, pr0, pr1;
806
+
807
+ if (this._rotation !== other._rotation) {
808
+ // Only separate with r1 axis if the rotation is different,
809
+ // else it's enough to separate r0 and r1 with r0 axis only!
810
+ axes.push(
811
+ toAxis(r1[0], r1[1]),
812
+ toAxis(r1[0], r1[3])
813
+ );
814
+ }
815
+
816
+ for (i = 0; i < axes.length; ++i) {
817
+ pr0 = projected(r0, axes[i]);
818
+ pr1 = projected(r1, axes[i]);
819
+
820
+ if (pr0.max < pr1.min || pr1.max < pr0.min) {
821
+ return false;
822
+ }
823
+ }
824
+
825
+ return true;
826
+ },
827
+
828
+ /**
829
+ * @private
830
+ */
831
+ _points: function() {
832
+ var me = this;
833
+ var rect = me._rect;
834
+ var angle = me._rotation;
835
+ var center = me.center();
836
+
837
+ return [
838
+ rotated({x: rect.x, y: rect.y}, center, angle),
839
+ rotated({x: rect.x + rect.w, y: rect.y}, center, angle),
840
+ rotated({x: rect.x + rect.w, y: rect.y + rect.h}, center, angle),
841
+ rotated({x: rect.x, y: rect.y + rect.h}, center, angle)
842
+ ];
843
+ }
844
+ });
845
+
846
+ function coordinates(view, model, geometry) {
847
+ var point = model.positioner(view, model);
848
+ var vx = point.vx;
849
+ var vy = point.vy;
850
+
851
+ if (!vx && !vy) {
852
+ // if aligned center, we don't want to offset the center point
853
+ return {x: point.x, y: point.y};
854
+ }
855
+
856
+ var w = geometry.w;
857
+ var h = geometry.h;
858
+
859
+ // take in account the label rotation
860
+ var rotation = model.rotation;
861
+ var dx = Math.abs(w / 2 * Math.cos(rotation)) + Math.abs(h / 2 * Math.sin(rotation));
862
+ var dy = Math.abs(w / 2 * Math.sin(rotation)) + Math.abs(h / 2 * Math.cos(rotation));
863
+
864
+ // scale the unit vector (vx, vy) to get at least dx or dy equal to
865
+ // w or h respectively (else we would calculate the distance to the
866
+ // ellipse inscribed in the bounding rect)
867
+ var vs = 1 / Math.max(Math.abs(vx), Math.abs(vy));
868
+ dx *= vx * vs;
869
+ dy *= vy * vs;
870
+
871
+ // finally, include the explicit offset
872
+ dx += model.offset * vx;
873
+ dy += model.offset * vy;
874
+
875
+ return {
876
+ x: point.x + dx,
877
+ y: point.y + dy
878
+ };
879
+ }
880
+
881
+ function collide(labels, collider) {
882
+ var i, j, s0, s1;
883
+
884
+ // IMPORTANT Iterate in the reverse order since items at the end of the
885
+ // list have an higher weight/priority and thus should be less impacted
886
+ // by the overlapping strategy.
887
+
888
+ for (i = labels.length - 1; i >= 0; --i) {
889
+ s0 = labels[i].$layout;
890
+
891
+ for (j = i - 1; j >= 0 && s0._visible; --j) {
892
+ s1 = labels[j].$layout;
893
+
894
+ if (s1._visible && s0._box.intersects(s1._box)) {
895
+ collider(s0, s1);
896
+ }
897
+ }
898
+ }
899
+
900
+ return labels;
901
+ }
902
+
903
+ function compute$1(labels) {
904
+ var i, ilen, label, state, geometry, center;
905
+
906
+ // Initialize labels for overlap detection
907
+ for (i = 0, ilen = labels.length; i < ilen; ++i) {
908
+ label = labels[i];
909
+ state = label.$layout;
910
+
911
+ if (state._visible) {
912
+ geometry = label.geometry();
913
+ center = coordinates(label._el._model, label.model(), geometry);
914
+ state._box.update(center, geometry, label.rotation());
915
+ }
916
+ }
917
+
918
+ // Auto hide overlapping labels
919
+ return collide(labels, function(s0, s1) {
920
+ var h0 = s0._hidable;
921
+ var h1 = s1._hidable;
922
+
923
+ if ((h0 && h1) || h1) {
924
+ s1._visible = false;
925
+ } else if (h0) {
926
+ s0._visible = false;
927
+ }
928
+ });
929
+ }
930
+
931
+ var layout = {
932
+ prepare: function(datasets) {
933
+ var labels = [];
934
+ var i, j, ilen, jlen, label;
935
+
936
+ for (i = 0, ilen = datasets.length; i < ilen; ++i) {
937
+ for (j = 0, jlen = datasets[i].length; j < jlen; ++j) {
938
+ label = datasets[i][j];
939
+ labels.push(label);
940
+ label.$layout = {
941
+ _box: new HitBox(),
942
+ _hidable: false,
943
+ _visible: true,
944
+ _set: i,
945
+ _idx: j
946
+ };
947
+ }
948
+ }
949
+
950
+ // TODO New `z` option: labels with a higher z-index are drawn
951
+ // of top of the ones with a lower index. Lowest z-index labels
952
+ // are also discarded first when hiding overlapping labels.
953
+ labels.sort(function(a, b) {
954
+ var sa = a.$layout;
955
+ var sb = b.$layout;
956
+
957
+ return sa._idx === sb._idx
958
+ ? sb._set - sa._set
959
+ : sb._idx - sa._idx;
960
+ });
961
+
962
+ this.update(labels);
963
+
964
+ return labels;
965
+ },
966
+
967
+ update: function(labels) {
968
+ var dirty = false;
969
+ var i, ilen, label, model, state;
970
+
971
+ for (i = 0, ilen = labels.length; i < ilen; ++i) {
972
+ label = labels[i];
973
+ model = label.model();
974
+ state = label.$layout;
975
+ state._hidable = model && model.display === 'auto';
976
+ state._visible = label.visible();
977
+ dirty |= state._hidable;
978
+ }
979
+
980
+ if (dirty) {
981
+ compute$1(labels);
982
+ }
983
+ },
984
+
985
+ lookup: function(labels, point) {
986
+ var i, state;
987
+
988
+ // IMPORTANT Iterate in the reverse order since items at the end of
989
+ // the list have an higher z-index, thus should be picked first.
990
+
991
+ for (i = labels.length - 1; i >= 0; --i) {
992
+ state = labels[i].$layout;
993
+
994
+ if (state && state._visible && state._box.contains(point)) {
995
+ return labels[i];
996
+ }
997
+ }
998
+
999
+ return null;
1000
+ },
1001
+
1002
+ draw: function(chart, labels) {
1003
+ var i, ilen, label, state, geometry, center;
1004
+
1005
+ for (i = 0, ilen = labels.length; i < ilen; ++i) {
1006
+ label = labels[i];
1007
+ state = label.$layout;
1008
+
1009
+ if (state._visible) {
1010
+ geometry = label.geometry();
1011
+ center = coordinates(label._el._view, label.model(), geometry);
1012
+ state._box.update(center, geometry, label.rotation());
1013
+ label.draw(chart, center);
1014
+ }
1015
+ }
1016
+ }
1017
+ };
1018
+
1019
+ var helpers$3 = Chart.helpers;
1020
+
1021
+ var formatter = function(value) {
1022
+ if (helpers$3.isNullOrUndef(value)) {
1023
+ return null;
1024
+ }
1025
+
1026
+ var label = value;
1027
+ var keys, klen, k;
1028
+ if (helpers$3.isObject(value)) {
1029
+ if (!helpers$3.isNullOrUndef(value.label)) {
1030
+ label = value.label;
1031
+ } else if (!helpers$3.isNullOrUndef(value.r)) {
1032
+ label = value.r;
1033
+ } else {
1034
+ label = '';
1035
+ keys = Object.keys(value);
1036
+ for (k = 0, klen = keys.length; k < klen; ++k) {
1037
+ label += (k !== 0 ? ', ' : '') + keys[k] + ': ' + value[keys[k]];
1038
+ }
1039
+ }
1040
+ }
1041
+
1042
+ return '' + label;
1043
+ };
1044
+
1045
+ /**
1046
+ * IMPORTANT: make sure to also update tests and TypeScript definition
1047
+ * files (`/test/specs/defaults.spec.js` and `/types/options.d.ts`)
1048
+ */
1049
+
1050
+ var defaults = {
1051
+ align: 'center',
1052
+ anchor: 'center',
1053
+ backgroundColor: null,
1054
+ borderColor: null,
1055
+ borderRadius: 0,
1056
+ borderWidth: 0,
1057
+ clamp: false,
1058
+ clip: false,
1059
+ color: undefined,
1060
+ display: true,
1061
+ font: {
1062
+ family: undefined,
1063
+ lineHeight: 1.2,
1064
+ size: undefined,
1065
+ style: undefined,
1066
+ weight: null
1067
+ },
1068
+ formatter: formatter,
1069
+ labels: undefined,
1070
+ listeners: {},
1071
+ offset: 4,
1072
+ opacity: 1,
1073
+ padding: {
1074
+ top: 4,
1075
+ right: 4,
1076
+ bottom: 4,
1077
+ left: 4
1078
+ },
1079
+ rotation: 0,
1080
+ textAlign: 'start',
1081
+ textStrokeColor: undefined,
1082
+ textStrokeWidth: 0,
1083
+ textShadowBlur: 0,
1084
+ textShadowColor: undefined
1085
+ };
1086
+
1087
+ /**
1088
+ * @see https://github.com/chartjs/Chart.js/issues/4176
1089
+ */
1090
+
1091
+ var helpers$4 = Chart.helpers;
1092
+ var EXPANDO_KEY = '$datalabels';
1093
+ var DEFAULT_KEY = '$default';
1094
+
1095
+ function configure(dataset, options) {
1096
+ var override = dataset.datalabels;
1097
+ var listeners = {};
1098
+ var configs = [];
1099
+ var labels, keys;
1100
+
1101
+ if (override === false) {
1102
+ return null;
1103
+ }
1104
+ if (override === true) {
1105
+ override = {};
1106
+ }
1107
+
1108
+ options = helpers$4.merge({}, [options, override]);
1109
+ labels = options.labels || {};
1110
+ keys = Object.keys(labels);
1111
+ delete options.labels;
1112
+
1113
+ if (keys.length) {
1114
+ keys.forEach(function(key) {
1115
+ if (labels[key]) {
1116
+ configs.push(helpers$4.merge({}, [
1117
+ options,
1118
+ labels[key],
1119
+ {_key: key}
1120
+ ]));
1121
+ }
1122
+ });
1123
+ } else {
1124
+ // Default label if no "named" label defined.
1125
+ configs.push(options);
1126
+ }
1127
+
1128
+ // listeners: {<event-type>: {<label-key>: <fn>}}
1129
+ listeners = configs.reduce(function(target, config) {
1130
+ helpers$4.each(config.listeners || {}, function(fn, event) {
1131
+ target[event] = target[event] || {};
1132
+ target[event][config._key || DEFAULT_KEY] = fn;
1133
+ });
1134
+
1135
+ delete config.listeners;
1136
+ return target;
1137
+ }, {});
1138
+
1139
+ return {
1140
+ labels: configs,
1141
+ listeners: listeners
1142
+ };
1143
+ }
1144
+
1145
+ function dispatchEvent(chart, listeners, label) {
1146
+ if (!listeners) {
1147
+ return;
1148
+ }
1149
+
1150
+ var context = label.$context;
1151
+ var groups = label.$groups;
1152
+ var callback;
1153
+
1154
+ if (!listeners[groups._set]) {
1155
+ return;
1156
+ }
1157
+
1158
+ callback = listeners[groups._set][groups._key];
1159
+ if (!callback) {
1160
+ return;
1161
+ }
1162
+
1163
+ if (helpers$4.callback(callback, [context]) === true) {
1164
+ // Users are allowed to tweak the given context by injecting values that can be
1165
+ // used in scriptable options to display labels differently based on the current
1166
+ // event (e.g. highlight an hovered label). That's why we update the label with
1167
+ // the output context and schedule a new chart render by setting it dirty.
1168
+ chart[EXPANDO_KEY]._dirty = true;
1169
+ label.update(context);
1170
+ }
1171
+ }
1172
+
1173
+ function dispatchMoveEvents(chart, listeners, previous, label) {
1174
+ var enter, leave;
1175
+
1176
+ if (!previous && !label) {
1177
+ return;
1178
+ }
1179
+
1180
+ if (!previous) {
1181
+ enter = true;
1182
+ } else if (!label) {
1183
+ leave = true;
1184
+ } else if (previous !== label) {
1185
+ leave = enter = true;
1186
+ }
1187
+
1188
+ if (leave) {
1189
+ dispatchEvent(chart, listeners.leave, previous);
1190
+ }
1191
+ if (enter) {
1192
+ dispatchEvent(chart, listeners.enter, label);
1193
+ }
1194
+ }
1195
+
1196
+ function handleMoveEvents(chart, event) {
1197
+ var expando = chart[EXPANDO_KEY];
1198
+ var listeners = expando._listeners;
1199
+ var previous, label;
1200
+
1201
+ if (!listeners.enter && !listeners.leave) {
1202
+ return;
1203
+ }
1204
+
1205
+ if (event.type === 'mousemove') {
1206
+ label = layout.lookup(expando._labels, event);
1207
+ } else if (event.type !== 'mouseout') {
1208
+ return;
1209
+ }
1210
+
1211
+ previous = expando._hovered;
1212
+ expando._hovered = label;
1213
+ dispatchMoveEvents(chart, listeners, previous, label);
1214
+ }
1215
+
1216
+ function handleClickEvents(chart, event) {
1217
+ var expando = chart[EXPANDO_KEY];
1218
+ var handlers = expando._listeners.click;
1219
+ var label = handlers && layout.lookup(expando._labels, event);
1220
+ if (label) {
1221
+ dispatchEvent(chart, handlers, label);
1222
+ }
1223
+ }
1224
+
1225
+ // https://github.com/chartjs/chartjs-plugin-datalabels/issues/108
1226
+ function invalidate(chart) {
1227
+ if (chart.animating) {
1228
+ return;
1229
+ }
1230
+
1231
+ // `chart.animating` can be `false` even if there is animation in progress,
1232
+ // so let's iterate all animations to find if there is one for the `chart`.
1233
+ var animations = Chart.animationService.animations;
1234
+ for (var i = 0, ilen = animations.length; i < ilen; ++i) {
1235
+ if (animations[i].chart === chart) {
1236
+ return;
1237
+ }
1238
+ }
1239
+
1240
+ // No render scheduled: trigger a "lazy" render that can be canceled in case
1241
+ // of hover interactions. The 1ms duration is a workaround to make sure an
1242
+ // animation is created so the controller can stop it before any transition.
1243
+ chart.render({duration: 1, lazy: true});
1244
+ }
1245
+
1246
+ Chart.defaults.global.plugins.datalabels = defaults;
1247
+
1248
+ var plugin = {
1249
+ id: 'datalabels',
1250
+
1251
+ beforeInit: function(chart) {
1252
+ chart[EXPANDO_KEY] = {
1253
+ _actives: []
1254
+ };
1255
+ },
1256
+
1257
+ beforeUpdate: function(chart) {
1258
+ var expando = chart[EXPANDO_KEY];
1259
+ expando._listened = false;
1260
+ expando._listeners = {}; // {<event-type>: {<dataset-index>: {<label-key>: <fn>}}}
1261
+ expando._datasets = []; // per dataset labels: [Label[]]
1262
+ expando._labels = []; // layouted labels: Label[]
1263
+ },
1264
+
1265
+ afterDatasetUpdate: function(chart, args, options) {
1266
+ var datasetIndex = args.index;
1267
+ var expando = chart[EXPANDO_KEY];
1268
+ var labels = expando._datasets[datasetIndex] = [];
1269
+ var visible = chart.isDatasetVisible(datasetIndex);
1270
+ var dataset = chart.data.datasets[datasetIndex];
1271
+ var config = configure(dataset, options);
1272
+ var elements = args.meta.data || [];
1273
+ var ctx = chart.ctx;
1274
+ var i, j, ilen, jlen, cfg, key, el, label;
1275
+
1276
+ ctx.save();
1277
+
1278
+ for (i = 0, ilen = elements.length; i < ilen; ++i) {
1279
+ el = elements[i];
1280
+ el[EXPANDO_KEY] = [];
1281
+
1282
+ if (visible && el && !el.hidden && !el._model.skip) {
1283
+ for (j = 0, jlen = config.labels.length; j < jlen; ++j) {
1284
+ cfg = config.labels[j];
1285
+ key = cfg._key;
1286
+
1287
+ label = new Label(cfg, ctx, el, i);
1288
+ label.$groups = {
1289
+ _set: datasetIndex,
1290
+ _key: key || DEFAULT_KEY
1291
+ };
1292
+ label.$context = {
1293
+ active: false,
1294
+ chart: chart,
1295
+ dataIndex: i,
1296
+ dataset: dataset,
1297
+ datasetIndex: datasetIndex
1298
+ };
1299
+
1300
+ label.update(label.$context);
1301
+ el[EXPANDO_KEY].push(label);
1302
+ labels.push(label);
1303
+ }
1304
+ }
1305
+ }
1306
+
1307
+ ctx.restore();
1308
+
1309
+ // Store listeners at the chart level and per event type to optimize
1310
+ // cases where no listeners are registered for a specific event.
1311
+ helpers$4.merge(expando._listeners, config.listeners, {
1312
+ merger: function(event, target, source) {
1313
+ target[event] = target[event] || {};
1314
+ target[event][args.index] = source[event];
1315
+ expando._listened = true;
1316
+ }
1317
+ });
1318
+ },
1319
+
1320
+ afterUpdate: function(chart, options) {
1321
+ chart[EXPANDO_KEY]._labels = layout.prepare(
1322
+ chart[EXPANDO_KEY]._datasets,
1323
+ options);
1324
+ },
1325
+
1326
+ // Draw labels on top of all dataset elements
1327
+ // https://github.com/chartjs/chartjs-plugin-datalabels/issues/29
1328
+ // https://github.com/chartjs/chartjs-plugin-datalabels/issues/32
1329
+ afterDatasetsDraw: function(chart) {
1330
+ layout.draw(chart, chart[EXPANDO_KEY]._labels);
1331
+ },
1332
+
1333
+ beforeEvent: function(chart, event) {
1334
+ // If there is no listener registered for this chart, `listened` will be false,
1335
+ // meaning we can immediately ignore the incoming event and avoid useless extra
1336
+ // computation for users who don't implement label interactions.
1337
+ if (chart[EXPANDO_KEY]._listened) {
1338
+ switch (event.type) {
1339
+ case 'mousemove':
1340
+ case 'mouseout':
1341
+ handleMoveEvents(chart, event);
1342
+ break;
1343
+ case 'click':
1344
+ handleClickEvents(chart, event);
1345
+ break;
1346
+ default:
1347
+ }
1348
+ }
1349
+ },
1350
+
1351
+ afterEvent: function(chart) {
1352
+ var expando = chart[EXPANDO_KEY];
1353
+ var previous = expando._actives;
1354
+ var actives = expando._actives = chart.lastActive || []; // public API?!
1355
+ var updates = utils.arrayDiff(previous, actives);
1356
+ var i, ilen, j, jlen, update, label, labels;
1357
+
1358
+ for (i = 0, ilen = updates.length; i < ilen; ++i) {
1359
+ update = updates[i];
1360
+ if (update[1]) {
1361
+ labels = update[0][EXPANDO_KEY] || [];
1362
+ for (j = 0, jlen = labels.length; j < jlen; ++j) {
1363
+ label = labels[j];
1364
+ label.$context.active = (update[1] === 1);
1365
+ label.update(label.$context);
1366
+ }
1367
+ }
1368
+ }
1369
+
1370
+ if (expando._dirty || updates.length) {
1371
+ layout.update(expando._labels);
1372
+ invalidate(chart);
1373
+ }
1374
+
1375
+ delete expando._dirty;
1376
+ }
1377
+ };
1378
+
1379
+ // TODO Remove at version 1, we shouldn't automatically register plugins.
1380
+ // https://github.com/chartjs/chartjs-plugin-datalabels/issues/42
1381
+ Chart.plugins.register(plugin);
1382
+
1383
+ return plugin;
1384
+
1385
+ }));