@kirbydesign/designsystem 11.11.3-dev-e7cb27f → 12.0.0-dev-67d5287

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 (282) hide show
  1. package/fesm2022/kirbydesign-designsystem-accordion.mjs +246 -135
  2. package/fesm2022/kirbydesign-designsystem-accordion.mjs.map +1 -1
  3. package/fesm2022/kirbydesign-designsystem-action-group.mjs +229 -134
  4. package/fesm2022/kirbydesign-designsystem-action-group.mjs.map +1 -1
  5. package/fesm2022/kirbydesign-designsystem-avatar.mjs +102 -55
  6. package/fesm2022/kirbydesign-designsystem-avatar.mjs.map +1 -1
  7. package/fesm2022/kirbydesign-designsystem-badge.mjs +85 -42
  8. package/fesm2022/kirbydesign-designsystem-badge.mjs.map +1 -1
  9. package/fesm2022/kirbydesign-designsystem-button.mjs +203 -170
  10. package/fesm2022/kirbydesign-designsystem-button.mjs.map +1 -1
  11. package/fesm2022/kirbydesign-designsystem-calendar.mjs +524 -516
  12. package/fesm2022/kirbydesign-designsystem-calendar.mjs.map +1 -1
  13. package/fesm2022/kirbydesign-designsystem-card.mjs +439 -205
  14. package/fesm2022/kirbydesign-designsystem-card.mjs.map +1 -1
  15. package/fesm2022/kirbydesign-designsystem-chart.mjs +1388 -1469
  16. package/fesm2022/kirbydesign-designsystem-chart.mjs.map +1 -1
  17. package/fesm2022/kirbydesign-designsystem-checkbox.mjs +215 -176
  18. package/fesm2022/kirbydesign-designsystem-checkbox.mjs.map +1 -1
  19. package/fesm2022/kirbydesign-designsystem-config.mjs +50 -96
  20. package/fesm2022/kirbydesign-designsystem-config.mjs.map +1 -1
  21. package/fesm2022/kirbydesign-designsystem-data-table.mjs +180 -83
  22. package/fesm2022/kirbydesign-designsystem-data-table.mjs.map +1 -1
  23. package/fesm2022/kirbydesign-designsystem-divider.mjs +46 -19
  24. package/fesm2022/kirbydesign-designsystem-divider.mjs.map +1 -1
  25. package/fesm2022/kirbydesign-designsystem-dropdown.mjs +878 -752
  26. package/fesm2022/kirbydesign-designsystem-dropdown.mjs.map +1 -1
  27. package/fesm2022/kirbydesign-designsystem-empty-state.mjs +164 -91
  28. package/fesm2022/kirbydesign-designsystem-empty-state.mjs.map +1 -1
  29. package/fesm2022/kirbydesign-designsystem-fab-sheet.mjs +213 -85
  30. package/fesm2022/kirbydesign-designsystem-fab-sheet.mjs.map +1 -1
  31. package/fesm2022/kirbydesign-designsystem-flag.mjs +67 -33
  32. package/fesm2022/kirbydesign-designsystem-flag.mjs.map +1 -1
  33. package/fesm2022/kirbydesign-designsystem-form-field.mjs +1260 -901
  34. package/fesm2022/kirbydesign-designsystem-form-field.mjs.map +1 -1
  35. package/fesm2022/kirbydesign-designsystem-gesture.mjs +38 -23
  36. package/fesm2022/kirbydesign-designsystem-gesture.mjs.map +1 -1
  37. package/fesm2022/kirbydesign-designsystem-header.mjs +422 -182
  38. package/fesm2022/kirbydesign-designsystem-header.mjs.map +1 -1
  39. package/fesm2022/kirbydesign-designsystem-helpers-scss.mjs +16 -14
  40. package/fesm2022/kirbydesign-designsystem-helpers-scss.mjs.map +1 -1
  41. package/fesm2022/kirbydesign-designsystem-helpers.mjs +251 -361
  42. package/fesm2022/kirbydesign-designsystem-helpers.mjs.map +1 -1
  43. package/fesm2022/kirbydesign-designsystem-icon.mjs +881 -303
  44. package/fesm2022/kirbydesign-designsystem-icon.mjs.map +1 -1
  45. package/fesm2022/kirbydesign-designsystem-item-group.mjs +52 -23
  46. package/fesm2022/kirbydesign-designsystem-item-group.mjs.map +1 -1
  47. package/fesm2022/kirbydesign-designsystem-item-sliding.mjs +147 -43
  48. package/fesm2022/kirbydesign-designsystem-item-sliding.mjs.map +1 -1
  49. package/fesm2022/kirbydesign-designsystem-item.mjs +395 -151
  50. package/fesm2022/kirbydesign-designsystem-item.mjs.map +1 -1
  51. package/fesm2022/kirbydesign-designsystem-kirby-app.mjs +136 -54
  52. package/fesm2022/kirbydesign-designsystem-kirby-app.mjs.map +1 -1
  53. package/fesm2022/kirbydesign-designsystem-list.mjs +1185 -697
  54. package/fesm2022/kirbydesign-designsystem-list.mjs.map +1 -1
  55. package/fesm2022/kirbydesign-designsystem-loading-overlay.mjs +166 -76
  56. package/fesm2022/kirbydesign-designsystem-loading-overlay.mjs.map +1 -1
  57. package/fesm2022/kirbydesign-designsystem-menu.mjs +420 -311
  58. package/fesm2022/kirbydesign-designsystem-menu.mjs.map +1 -1
  59. package/fesm2022/kirbydesign-designsystem-modal.mjs +2467 -1912
  60. package/fesm2022/kirbydesign-designsystem-modal.mjs.map +1 -1
  61. package/fesm2022/kirbydesign-designsystem-page.mjs +1505 -923
  62. package/fesm2022/kirbydesign-designsystem-page.mjs.map +1 -1
  63. package/fesm2022/kirbydesign-designsystem-popover.mjs +203 -183
  64. package/fesm2022/kirbydesign-designsystem-popover.mjs.map +1 -1
  65. package/fesm2022/kirbydesign-designsystem-progress-circle.mjs +209 -121
  66. package/fesm2022/kirbydesign-designsystem-progress-circle.mjs.map +1 -1
  67. package/fesm2022/kirbydesign-designsystem-radio.mjs +537 -365
  68. package/fesm2022/kirbydesign-designsystem-radio.mjs.map +1 -1
  69. package/fesm2022/kirbydesign-designsystem-range.mjs +207 -150
  70. package/fesm2022/kirbydesign-designsystem-range.mjs.map +1 -1
  71. package/fesm2022/kirbydesign-designsystem-reorder-list.mjs +217 -104
  72. package/fesm2022/kirbydesign-designsystem-reorder-list.mjs.map +1 -1
  73. package/fesm2022/kirbydesign-designsystem-router-outlet.mjs +113 -38
  74. package/fesm2022/kirbydesign-designsystem-router-outlet.mjs.map +1 -1
  75. package/fesm2022/kirbydesign-designsystem-section-header.mjs +56 -18
  76. package/fesm2022/kirbydesign-designsystem-section-header.mjs.map +1 -1
  77. package/fesm2022/kirbydesign-designsystem-segmented-control.mjs +276 -232
  78. package/fesm2022/kirbydesign-designsystem-segmented-control.mjs.map +1 -1
  79. package/fesm2022/kirbydesign-designsystem-shared-floating.mjs +319 -382
  80. package/fesm2022/kirbydesign-designsystem-shared-floating.mjs.map +1 -1
  81. package/fesm2022/kirbydesign-designsystem-shared-portal.mjs +73 -84
  82. package/fesm2022/kirbydesign-designsystem-shared-portal.mjs.map +1 -1
  83. package/fesm2022/kirbydesign-designsystem-shared.mjs +665 -529
  84. package/fesm2022/kirbydesign-designsystem-shared.mjs.map +1 -1
  85. package/fesm2022/kirbydesign-designsystem-slide-button.mjs +140 -91
  86. package/fesm2022/kirbydesign-designsystem-slide-button.mjs.map +1 -1
  87. package/fesm2022/kirbydesign-designsystem-slide.mjs +360 -158
  88. package/fesm2022/kirbydesign-designsystem-slide.mjs.map +1 -1
  89. package/fesm2022/kirbydesign-designsystem-spinner.mjs +90 -32
  90. package/fesm2022/kirbydesign-designsystem-spinner.mjs.map +1 -1
  91. package/fesm2022/kirbydesign-designsystem-tab-navigation.mjs +348 -181
  92. package/fesm2022/kirbydesign-designsystem-tab-navigation.mjs.map +1 -1
  93. package/fesm2022/kirbydesign-designsystem-tabs.mjs +286 -121
  94. package/fesm2022/kirbydesign-designsystem-tabs.mjs.map +1 -1
  95. package/fesm2022/kirbydesign-designsystem-testing-base.mjs +6232 -3164
  96. package/fesm2022/kirbydesign-designsystem-testing-base.mjs.map +1 -1
  97. package/fesm2022/kirbydesign-designsystem-testing-jasmine.mjs +118 -95
  98. package/fesm2022/kirbydesign-designsystem-testing-jasmine.mjs.map +1 -1
  99. package/fesm2022/kirbydesign-designsystem-testing-jest.mjs +128 -101
  100. package/fesm2022/kirbydesign-designsystem-testing-jest.mjs.map +1 -1
  101. package/fesm2022/kirbydesign-designsystem-testing.mjs +236 -243
  102. package/fesm2022/kirbydesign-designsystem-testing.mjs.map +1 -1
  103. package/fesm2022/kirbydesign-designsystem-toast.mjs +98 -62
  104. package/fesm2022/kirbydesign-designsystem-toast.mjs.map +1 -1
  105. package/fesm2022/kirbydesign-designsystem-toggle-button.mjs +155 -127
  106. package/fesm2022/kirbydesign-designsystem-toggle-button.mjs.map +1 -1
  107. package/fesm2022/kirbydesign-designsystem-toggle.mjs +180 -150
  108. package/fesm2022/kirbydesign-designsystem-toggle.mjs.map +1 -1
  109. package/fesm2022/kirbydesign-designsystem-types.mjs +39 -24
  110. package/fesm2022/kirbydesign-designsystem-types.mjs.map +1 -1
  111. package/fesm2022/kirbydesign-designsystem.mjs +516 -407
  112. package/fesm2022/kirbydesign-designsystem.mjs.map +1 -1
  113. package/icons/svg/megaphone.svg +3 -0
  114. package/package.json +10 -10
  115. package/readme.md +37 -0
  116. package/types/kirbydesign-designsystem-accordion.d.ts +72 -39
  117. package/types/kirbydesign-designsystem-accordion.d.ts.map +1 -1
  118. package/types/kirbydesign-designsystem-action-group.d.ts +46 -39
  119. package/types/kirbydesign-designsystem-action-group.d.ts.map +1 -1
  120. package/types/kirbydesign-designsystem-avatar.d.ts +62 -26
  121. package/types/kirbydesign-designsystem-avatar.d.ts.map +1 -1
  122. package/types/kirbydesign-designsystem-badge.d.ts +30 -19
  123. package/types/kirbydesign-designsystem-badge.d.ts.map +1 -1
  124. package/types/kirbydesign-designsystem-button.d.ts +70 -45
  125. package/types/kirbydesign-designsystem-button.d.ts.map +1 -1
  126. package/types/kirbydesign-designsystem-calendar.d.ts +193 -132
  127. package/types/kirbydesign-designsystem-calendar.d.ts.map +1 -1
  128. package/types/kirbydesign-designsystem-card.d.ts +130 -66
  129. package/types/kirbydesign-designsystem-card.d.ts.map +1 -1
  130. package/types/kirbydesign-designsystem-chart.d.ts +198 -172
  131. package/types/kirbydesign-designsystem-chart.d.ts.map +1 -1
  132. package/types/kirbydesign-designsystem-checkbox.d.ts +96 -68
  133. package/types/kirbydesign-designsystem-checkbox.d.ts.map +1 -1
  134. package/types/kirbydesign-designsystem-config.d.ts +17 -21
  135. package/types/kirbydesign-designsystem-config.d.ts.map +1 -1
  136. package/types/kirbydesign-designsystem-data-table.d.ts +46 -26
  137. package/types/kirbydesign-designsystem-data-table.d.ts.map +1 -1
  138. package/types/kirbydesign-designsystem-divider.d.ts +11 -9
  139. package/types/kirbydesign-designsystem-divider.d.ts.map +1 -1
  140. package/types/kirbydesign-designsystem-dropdown.d.ts +219 -166
  141. package/types/kirbydesign-designsystem-dropdown.d.ts.map +1 -1
  142. package/types/kirbydesign-designsystem-empty-state.d.ts +47 -35
  143. package/types/kirbydesign-designsystem-empty-state.d.ts.map +1 -1
  144. package/types/kirbydesign-designsystem-fab-sheet.d.ts +34 -28
  145. package/types/kirbydesign-designsystem-fab-sheet.d.ts.map +1 -1
  146. package/types/kirbydesign-designsystem-flag.d.ts +18 -13
  147. package/types/kirbydesign-designsystem-flag.d.ts.map +1 -1
  148. package/types/kirbydesign-designsystem-form-field.d.ts +409 -242
  149. package/types/kirbydesign-designsystem-form-field.d.ts.map +1 -1
  150. package/types/kirbydesign-designsystem-gesture.d.ts +41 -46
  151. package/types/kirbydesign-designsystem-gesture.d.ts.map +1 -1
  152. package/types/kirbydesign-designsystem-header.d.ts +102 -64
  153. package/types/kirbydesign-designsystem-header.d.ts.map +1 -1
  154. package/types/kirbydesign-designsystem-helpers-scss.d.ts +6 -8
  155. package/types/kirbydesign-designsystem-helpers-scss.d.ts.map +1 -1
  156. package/types/kirbydesign-designsystem-helpers.d.ts +83 -97
  157. package/types/kirbydesign-designsystem-helpers.d.ts.map +1 -1
  158. package/types/kirbydesign-designsystem-icon.d.ts +63 -59
  159. package/types/kirbydesign-designsystem-icon.d.ts.map +1 -1
  160. package/types/kirbydesign-designsystem-item-group.d.ts +6 -9
  161. package/types/kirbydesign-designsystem-item-group.d.ts.map +1 -1
  162. package/types/kirbydesign-designsystem-item-sliding.d.ts +30 -26
  163. package/types/kirbydesign-designsystem-item-sliding.d.ts.map +1 -1
  164. package/types/kirbydesign-designsystem-item.d.ts +93 -54
  165. package/types/kirbydesign-designsystem-item.d.ts.map +1 -1
  166. package/types/kirbydesign-designsystem-kirby-app.d.ts +18 -19
  167. package/types/kirbydesign-designsystem-kirby-app.d.ts.map +1 -1
  168. package/types/kirbydesign-designsystem-list.d.ts +387 -263
  169. package/types/kirbydesign-designsystem-list.d.ts.map +1 -1
  170. package/types/kirbydesign-designsystem-loading-overlay.d.ts +35 -24
  171. package/types/kirbydesign-designsystem-loading-overlay.d.ts.map +1 -1
  172. package/types/kirbydesign-designsystem-menu.d.ts +119 -69
  173. package/types/kirbydesign-designsystem-menu.d.ts.map +1 -1
  174. package/types/kirbydesign-designsystem-modal.d.ts +577 -455
  175. package/types/kirbydesign-designsystem-modal.d.ts.map +1 -1
  176. package/types/kirbydesign-designsystem-page.d.ts +304 -229
  177. package/types/kirbydesign-designsystem-page.d.ts.map +1 -1
  178. package/types/kirbydesign-designsystem-popover.d.ts +48 -40
  179. package/types/kirbydesign-designsystem-popover.d.ts.map +1 -1
  180. package/types/kirbydesign-designsystem-progress-circle.d.ts +60 -38
  181. package/types/kirbydesign-designsystem-progress-circle.d.ts.map +1 -1
  182. package/types/kirbydesign-designsystem-radio.d.ts +147 -98
  183. package/types/kirbydesign-designsystem-radio.d.ts.map +1 -1
  184. package/types/kirbydesign-designsystem-range.d.ts +90 -45
  185. package/types/kirbydesign-designsystem-range.d.ts.map +1 -1
  186. package/types/kirbydesign-designsystem-reorder-list.d.ts +44 -32
  187. package/types/kirbydesign-designsystem-reorder-list.d.ts.map +1 -1
  188. package/types/kirbydesign-designsystem-router-outlet.d.ts +23 -18
  189. package/types/kirbydesign-designsystem-router-outlet.d.ts.map +1 -1
  190. package/types/kirbydesign-designsystem-section-header.d.ts +5 -8
  191. package/types/kirbydesign-designsystem-section-header.d.ts.map +1 -1
  192. package/types/kirbydesign-designsystem-segmented-control.d.ts +123 -100
  193. package/types/kirbydesign-designsystem-segmented-control.d.ts.map +1 -1
  194. package/types/kirbydesign-designsystem-shared-floating.d.ts +183 -128
  195. package/types/kirbydesign-designsystem-shared-floating.d.ts.map +1 -1
  196. package/types/kirbydesign-designsystem-shared-portal.d.ts +29 -28
  197. package/types/kirbydesign-designsystem-shared-portal.d.ts.map +1 -1
  198. package/types/kirbydesign-designsystem-shared.d.ts +143 -139
  199. package/types/kirbydesign-designsystem-shared.d.ts.map +1 -1
  200. package/types/kirbydesign-designsystem-slide-button.d.ts +43 -34
  201. package/types/kirbydesign-designsystem-slide-button.d.ts.map +1 -1
  202. package/types/kirbydesign-designsystem-slide.d.ts +80 -59
  203. package/types/kirbydesign-designsystem-slide.d.ts.map +1 -1
  204. package/types/kirbydesign-designsystem-spinner.d.ts +13 -14
  205. package/types/kirbydesign-designsystem-spinner.d.ts.map +1 -1
  206. package/types/kirbydesign-designsystem-tab-navigation.d.ts +78 -55
  207. package/types/kirbydesign-designsystem-tab-navigation.d.ts.map +1 -1
  208. package/types/kirbydesign-designsystem-tabs.d.ts +50 -45
  209. package/types/kirbydesign-designsystem-tabs.d.ts.map +1 -1
  210. package/types/kirbydesign-designsystem-testing-base.d.ts +2430 -815
  211. package/types/kirbydesign-designsystem-testing-base.d.ts.map +1 -1
  212. package/types/kirbydesign-designsystem-testing-jasmine.d.ts +9 -10
  213. package/types/kirbydesign-designsystem-testing-jasmine.d.ts.map +1 -1
  214. package/types/kirbydesign-designsystem-testing-jest.d.ts +9 -10
  215. package/types/kirbydesign-designsystem-testing-jest.d.ts.map +1 -1
  216. package/types/kirbydesign-designsystem-testing.d.ts +52 -58
  217. package/types/kirbydesign-designsystem-testing.d.ts.map +1 -1
  218. package/types/kirbydesign-designsystem-toast.d.ts +25 -31
  219. package/types/kirbydesign-designsystem-toast.d.ts.map +1 -1
  220. package/types/kirbydesign-designsystem-toggle-button.d.ts +62 -56
  221. package/types/kirbydesign-designsystem-toggle-button.d.ts.map +1 -1
  222. package/types/kirbydesign-designsystem-toggle.d.ts +71 -63
  223. package/types/kirbydesign-designsystem-toggle.d.ts.map +1 -1
  224. package/types/kirbydesign-designsystem-types.d.ts +15 -22
  225. package/types/kirbydesign-designsystem-types.d.ts.map +1 -1
  226. package/types/kirbydesign-designsystem.d.ts +135 -123
  227. package/types/kirbydesign-designsystem.d.ts.map +1 -1
  228. package/accordion/package.json +0 -4
  229. package/action-group/package.json +0 -4
  230. package/avatar/package.json +0 -4
  231. package/badge/package.json +0 -4
  232. package/button/package.json +0 -4
  233. package/calendar/package.json +0 -4
  234. package/card/package.json +0 -4
  235. package/chart/package.json +0 -4
  236. package/checkbox/package.json +0 -4
  237. package/config/package.json +0 -4
  238. package/data-table/package.json +0 -4
  239. package/divider/package.json +0 -4
  240. package/dropdown/package.json +0 -4
  241. package/empty-state/package.json +0 -4
  242. package/fab-sheet/package.json +0 -4
  243. package/flag/package.json +0 -4
  244. package/form-field/package.json +0 -4
  245. package/gesture/package.json +0 -4
  246. package/header/package.json +0 -4
  247. package/helpers/package.json +0 -4
  248. package/helpers/scss/package.json +0 -4
  249. package/icon/package.json +0 -4
  250. package/item/package.json +0 -4
  251. package/item-group/package.json +0 -4
  252. package/item-sliding/package.json +0 -4
  253. package/kirby-app/package.json +0 -4
  254. package/list/package.json +0 -4
  255. package/loading-overlay/package.json +0 -4
  256. package/menu/package.json +0 -4
  257. package/modal/package.json +0 -4
  258. package/page/package.json +0 -4
  259. package/popover/package.json +0 -4
  260. package/progress-circle/package.json +0 -4
  261. package/radio/package.json +0 -4
  262. package/range/package.json +0 -4
  263. package/reorder-list/package.json +0 -4
  264. package/router-outlet/package.json +0 -4
  265. package/section-header/package.json +0 -4
  266. package/segmented-control/package.json +0 -4
  267. package/shared/floating/package.json +0 -4
  268. package/shared/package.json +0 -4
  269. package/shared/portal/package.json +0 -4
  270. package/slide/package.json +0 -4
  271. package/slide-button/package.json +0 -4
  272. package/spinner/package.json +0 -4
  273. package/tab-navigation/package.json +0 -4
  274. package/tabs/package.json +0 -4
  275. package/testing/package.json +0 -4
  276. package/testing-base/package.json +0 -4
  277. package/testing-jasmine/package.json +0 -4
  278. package/testing-jest/package.json +0 -4
  279. package/toast/package.json +0 -4
  280. package/toggle/package.json +0 -4
  281. package/toggle-button/package.json +0 -4
  282. package/types/package.json +0 -4
@@ -1,1519 +1,1438 @@
1
- import * as i0 from '@angular/core';
2
- import { Injectable, ViewChild, Input, HostBinding, Component, NgModule } from '@angular/core';
3
- import { ResizeObserverFactory } from '@kirbydesign/designsystem/shared';
4
- import { mergeDeepAll, ColorHelper, DesignTokenHelper, deepCopy, chartConfigHasType } from '@kirbydesign/designsystem/helpers';
5
- import { CategoryScale, LinearScale, TimeScale, BarElement, LineElement, PointElement, BarController, LineController, Filler, Tooltip, Chart, Legend } from 'chart.js';
6
- import 'chartjs-adapter-date-fns';
7
- import annotationPlugin from 'chartjs-plugin-annotation';
8
- import ChartDataLabels from 'chartjs-plugin-datalabels';
9
- import { valueOrDefault } from 'chart.js/helpers';
10
- import { toDate } from 'date-fns';
11
-
1
+ import * as i0 from "@angular/core";
2
+ import { ChangeDetectionStrategy, Component, HostBinding, Injectable, Input, NgModule, ViewChild } from "@angular/core";
3
+ import { ResizeObserverFactory } from "@kirbydesign/designsystem/shared";
4
+ import { ColorHelper, DesignTokenHelper, chartConfigHasType, deepCopy, mergeDeepAll } from "@kirbydesign/designsystem/helpers";
5
+ import { BarController, BarElement, CategoryScale, Chart, Chart as Chart$1, Filler, Legend, LineController, LineElement, LinearScale, PointElement, TimeScale, Tooltip } from "chart.js";
6
+ import "chartjs-adapter-date-fns";
7
+ import annotationPlugin from "chartjs-plugin-annotation";
8
+ import ChartDataLabels from "chartjs-plugin-datalabels";
9
+ import { valueOrDefault } from "chart.js/helpers";
10
+ import { toDate } from "date-fns";
12
11
  function isNumberArray(value) {
13
- return Array.isArray(value) && value.every((item) => typeof item === 'number');
14
- }
15
-
16
- class AnnotationsDelegate {
17
- constructor(chartConfigService) {
18
- this.chartConfigService = chartConfigService;
19
- }
20
- applyDefaultsToAnnotations(annotations) {
21
- return annotations.map((annotation) => {
22
- const annotationTypeDefaults = this.chartConfigService.getAnnotationDefaults(annotation.type);
23
- return mergeDeepAll(annotationTypeDefaults, annotation);
24
- });
25
- }
26
- createAnnotationPluginOptionsObject(annotations) {
27
- const annotationsWithDefaults = this.applyDefaultsToAnnotations(annotations);
28
- return {
29
- plugins: {
30
- annotation: {
31
- annotations: annotationsWithDefaults,
32
- },
33
- },
34
- };
35
- }
36
- getExistingChartAnnotations(chart) {
37
- const annotations = chart.options.plugins?.annotation?.annotations;
38
- /* In browser chart.js might return annotations as a Proxy object; force it to be an array.
39
- Each annotationOption in the resulting array will also be a Proxy object.
40
- But internally chart.js will just work with them as normal values */
41
- if (annotations !== undefined) {
42
- return Object.keys(annotations).map((key) => annotations[key]);
43
- }
44
- else {
45
- return [];
46
- }
47
- }
12
+ return Array.isArray(value) && value.every((item) => typeof item === "number");
48
13
  }
49
-
14
+ var AnnotationsDelegate = class {
15
+ constructor(chartConfigService) {
16
+ this.chartConfigService = chartConfigService;
17
+ }
18
+ applyDefaultsToAnnotations(annotations) {
19
+ return annotations.map((annotation) => {
20
+ const annotationTypeDefaults = this.chartConfigService.getAnnotationDefaults(annotation.type);
21
+ return mergeDeepAll(annotationTypeDefaults, annotation);
22
+ });
23
+ }
24
+ createAnnotationPluginOptionsObject(annotations) {
25
+ return { plugins: { annotation: { annotations: this.applyDefaultsToAnnotations(annotations) } } };
26
+ }
27
+ getExistingChartAnnotations(chart) {
28
+ const annotations = chart.options.plugins?.annotation?.annotations;
29
+ if (annotations !== void 0) return Object.keys(annotations).map((key) => annotations[key]);
30
+ else return [];
31
+ }
32
+ };
50
33
  const { getThemeColorHexString: getThemeColorHexString$5 } = ColorHelper;
51
- const hoverBackgroundColor = getThemeColorHexString$5('primary');
52
- const backgroundColor = getThemeColorHexString$5('secondary');
34
+ const hoverBackgroundColor = getThemeColorHexString$5("primary");
35
+ const backgroundColor = getThemeColorHexString$5("secondary");
53
36
  function scriptedBackgroundColor(context) {
54
- const dataset = context.dataset;
55
- const highlightedElements = dataset?.kirbyOptions?.highlightedElements;
56
- if (highlightedElements && highlightedElements.includes(context.dataIndex)) {
57
- return hoverBackgroundColor;
58
- }
59
- else {
60
- return backgroundColor;
61
- }
37
+ const highlightedElements = context.dataset?.kirbyOptions?.highlightedElements;
38
+ if (highlightedElements && highlightedElements.includes(context.dataIndex)) return hoverBackgroundColor;
39
+ else return backgroundColor;
62
40
  }
63
- // Only adds a hovercolor if an onClick handler is provided
64
41
  function scriptedHoverBackgroundColor(context) {
65
- if (context.chart.options.onClick) {
66
- return hoverBackgroundColor;
67
- }
42
+ if (context.chart.options.onClick) return hoverBackgroundColor;
68
43
  }
69
44
  const CHART_GLOBAL_DEFAULTS = {
70
- maintainAspectRatio: false,
71
- color: getThemeColorHexString$5('black'),
72
- resizeDelay: 10,
73
- elements: {
74
- bar: {
75
- backgroundColor: scriptedBackgroundColor,
76
- hoverBackgroundColor: scriptedHoverBackgroundColor,
77
- },
78
- line: {
79
- borderColor: scriptedBackgroundColor,
80
- borderWidth: 2,
81
- tension: 0.3,
82
- },
83
- },
84
- scales: {
85
- linear: {
86
- display: false,
87
- ticks: {
88
- display: false,
89
- },
90
- },
91
- category: {
92
- display: true,
93
- grid: {
94
- display: false,
95
- },
96
- },
97
- },
98
- font: {
99
- family: 'Roboto',
100
- },
101
- plugins: {
102
- legend: {
103
- display: false,
104
- },
105
- datalabels: {
106
- display: false,
107
- },
108
- tooltip: {
109
- enabled: false,
110
- },
111
- },
45
+ maintainAspectRatio: false,
46
+ color: getThemeColorHexString$5("black"),
47
+ resizeDelay: 10,
48
+ elements: {
49
+ bar: {
50
+ backgroundColor: scriptedBackgroundColor,
51
+ hoverBackgroundColor: scriptedHoverBackgroundColor
52
+ },
53
+ line: {
54
+ borderColor: scriptedBackgroundColor,
55
+ borderWidth: 2,
56
+ tension: .3
57
+ }
58
+ },
59
+ scales: {
60
+ linear: {
61
+ display: false,
62
+ ticks: { display: false }
63
+ },
64
+ category: {
65
+ display: true,
66
+ grid: { display: false }
67
+ }
68
+ },
69
+ font: { family: "Roboto" },
70
+ plugins: {
71
+ legend: { display: false },
72
+ datalabels: { display: false },
73
+ tooltip: { enabled: false }
74
+ }
112
75
  };
113
-
114
- /*
115
- The marker plugin is heavily inspired by https://chartjs-plugin-crosshair.netlify.app
116
- The project appears stale and only the vertical line feature is needed
117
- part of the plugin that was actually needed is implemented here.
118
- */
119
76
  const defaultOptions = {
120
- line: {
121
- color: 'black',
122
- width: 1,
123
- dashPattern: [],
124
- },
125
- snap: {
126
- enabled: false,
127
- },
77
+ line: {
78
+ color: "black",
79
+ width: 1,
80
+ dashPattern: []
81
+ },
82
+ snap: { enabled: false }
128
83
  };
129
84
  const hasMarkerConfiguration = (chart) => {
130
- /*
131
- Hacky solution. Should be fixed in this issue: https://github.com/kirbydesign/designsystem/issues/1967
132
- */
133
- return chart.data.datasets.some((dataset) => !!dataset?.kirbyOptions?.isStockChart);
85
+ return chart.data.datasets.some((dataset) => !!dataset?.kirbyOptions?.isStockChart);
134
86
  };
135
- var MarkerPlugin = {
136
- id: 'marker',
137
- afterInit: function (chart) {
138
- if (!hasMarkerConfiguration(chart)) {
139
- return;
140
- }
141
- const xScaleType = chart.config.options.scales.x.type;
142
- if (xScaleType !== 'linear' &&
143
- xScaleType !== 'time' &&
144
- xScaleType !== 'category' &&
145
- xScaleType !== 'logarithmic') {
146
- return;
147
- }
148
- if (chart.options.plugins.marker === undefined) {
149
- chart.options.plugins.marker = defaultOptions;
150
- }
151
- chart.marker = {
152
- enabled: false,
153
- suppressUpdate: false,
154
- x: null,
155
- originalData: [],
156
- originalXRange: {},
157
- dragStarted: false,
158
- dragStartX: null,
159
- dragEndX: null,
160
- suppressTooltips: false,
161
- ignoreNextEvents: 0,
162
- };
163
- },
164
- getOption: function (chart, category, name) {
165
- return valueOrDefault(chart.options.plugins.marker[category]
166
- ? chart.options.plugins.marker[category][name]
167
- : undefined, defaultOptions[category][name]);
168
- },
169
- getXScale: function (chart) {
170
- return chart.data.datasets.length ? chart.scales[chart.getDatasetMeta(0).xAxisID] : null;
171
- },
172
- getYScale: function (chart) {
173
- return chart.scales[chart.getDatasetMeta(0).yAxisID];
174
- },
175
- afterEvent: function (chart, event) {
176
- if (!hasMarkerConfiguration(chart)) {
177
- return;
178
- }
179
- if (chart.config.options.scales.x.length == 0) {
180
- return;
181
- }
182
- const e = event.event;
183
- const xScaleType = chart.config.options.scales.x.type;
184
- if (xScaleType !== 'linear' &&
185
- xScaleType !== 'time' &&
186
- xScaleType !== 'category' &&
187
- xScaleType !== 'logarithmic') {
188
- return;
189
- }
190
- const xScale = this.getXScale(chart);
191
- if (!xScale) {
192
- return;
193
- }
194
- if (chart.marker.ignoreNextEvents > 0) {
195
- chart.marker.ignoreNextEvents -= 1;
196
- return;
197
- }
198
- chart.marker.enabled =
199
- e.type !== 'mouseout' &&
200
- e.x > xScale.getPixelForValue(xScale.min) &&
201
- e.x < xScale.getPixelForValue(xScale.max);
202
- if (!chart.marker.enabled && !chart.marker.suppressUpdate) {
203
- if (e.x > xScale.getPixelForValue(xScale.max)) {
204
- // suppress future updates to prevent endless redrawing of chart
205
- chart.marker.suppressUpdate = true;
206
- chart.update('none');
207
- }
208
- chart.marker.dragStarted = false; // cancel zoom in progress
209
- return false;
210
- }
211
- chart.marker.suppressUpdate = false;
212
- chart.marker.x = e.x;
213
- chart.draw();
214
- },
215
- doDraw: function (chart) {
216
- if (!hasMarkerConfiguration(chart)) {
217
- return;
218
- }
219
- if (!chart.marker.enabled) {
220
- return;
221
- }
222
- this.drawTraceLine(chart);
223
- this.interpolateValues(chart);
224
- this.drawTracePoints(chart);
225
- return true;
226
- },
227
- beforeDraw: function (chart) {
228
- return this.doDraw(chart);
229
- },
230
- // Logic moved to beforeDraw in order
231
- // for the vertical line to be drawn
232
- // under tooltip and datalabels.
233
- // afterDraw: function(chart) {
234
- // return this.doDraw(chart);
235
- // },
236
- drawTraceLine: function (chart) {
237
- if (!hasMarkerConfiguration(chart)) {
238
- return;
239
- }
240
- const yScale = this.getYScale(chart);
241
- const lineWidth = this.getOption(chart, 'line', 'width');
242
- const color = this.getOption(chart, 'line', 'color');
243
- const dashPattern = this.getOption(chart, 'line', 'dashPattern');
244
- const snapEnabled = this.getOption(chart, 'snap', 'enabled');
245
- let lineX = chart.marker.x;
246
- if (snapEnabled && chart._active.length) {
247
- lineX = chart._active[0].element.x;
248
- }
249
- chart.ctx.beginPath();
250
- chart.ctx.setLineDash(dashPattern);
251
- chart.ctx.moveTo(lineX, yScale.getPixelForValue(yScale.max));
252
- chart.ctx.lineWidth = lineWidth;
253
- chart.ctx.strokeStyle = color;
254
- chart.ctx.lineTo(lineX, yScale.getPixelForValue(yScale.min));
255
- chart.ctx.stroke();
256
- chart.ctx.setLineDash([]);
257
- },
258
- drawTracePoints: function (chart) {
259
- if (!hasMarkerConfiguration(chart)) {
260
- return;
261
- }
262
- for (let chartIndex = 0; chartIndex < chart.data.datasets.length; chartIndex++) {
263
- const dataset = chart.data.datasets[chartIndex];
264
- const meta = chart.getDatasetMeta(chartIndex);
265
- const yScale = chart.scales[meta.yAxisID];
266
- if (meta.hidden || !dataset.interpolate) {
267
- continue;
268
- }
269
- chart.ctx.beginPath();
270
- chart.ctx.arc(chart.marker.x, yScale.getPixelForValue(dataset.interpolatedValue), 3, 0, 2 * Math.PI, false);
271
- chart.ctx.fillStyle = 'white';
272
- chart.ctx.lineWidth = 2;
273
- chart.ctx.strokeStyle = dataset.borderColor;
274
- chart.ctx.fill();
275
- chart.ctx.stroke();
276
- }
277
- },
278
- interpolateValues: function (chart) {
279
- for (let chartIndex = 0; chartIndex < chart.data.datasets.length; chartIndex++) {
280
- const dataset = chart.data.datasets[chartIndex];
281
- const meta = chart.getDatasetMeta(chartIndex);
282
- const xScale = chart.scales[meta.xAxisID];
283
- const xValue = xScale.getValueForPixel(chart.marker.x);
284
- if (meta.hidden || !dataset.interpolate) {
285
- continue;
286
- }
287
- const data = dataset.data;
288
- const index = data.findIndex(function (o) {
289
- return o.x >= xValue;
290
- });
291
- const prev = data[index - 1];
292
- const next = data[index];
293
- if (chart.data.datasets[chartIndex].steppedLine && prev) {
294
- dataset.interpolatedValue = prev.y;
295
- }
296
- else if (prev && next) {
297
- const slope = (next.y - prev.y) / (next.x - prev.x);
298
- dataset.interpolatedValue = prev.y + (xValue - prev.x) * slope;
299
- }
300
- else {
301
- dataset.interpolatedValue = NaN;
302
- }
303
- }
304
- },
87
+ var chartjs_plugin_marker_default = {
88
+ id: "marker",
89
+ afterInit: function(chart) {
90
+ if (!hasMarkerConfiguration(chart)) return;
91
+ const xScaleType = chart.config.options.scales.x.type;
92
+ if (xScaleType !== "linear" && xScaleType !== "time" && xScaleType !== "category" && xScaleType !== "logarithmic") return;
93
+ if (chart.options.plugins.marker === void 0) chart.options.plugins.marker = defaultOptions;
94
+ chart.marker = {
95
+ enabled: false,
96
+ suppressUpdate: false,
97
+ x: null,
98
+ originalData: [],
99
+ originalXRange: {},
100
+ dragStarted: false,
101
+ dragStartX: null,
102
+ dragEndX: null,
103
+ suppressTooltips: false,
104
+ ignoreNextEvents: 0
105
+ };
106
+ },
107
+ getOption: function(chart, category, name) {
108
+ return valueOrDefault(chart.options.plugins.marker[category] ? chart.options.plugins.marker[category][name] : void 0, defaultOptions[category][name]);
109
+ },
110
+ getXScale: function(chart) {
111
+ return chart.data.datasets.length ? chart.scales[chart.getDatasetMeta(0).xAxisID] : null;
112
+ },
113
+ getYScale: function(chart) {
114
+ return chart.scales[chart.getDatasetMeta(0).yAxisID];
115
+ },
116
+ afterEvent: function(chart, event) {
117
+ if (!hasMarkerConfiguration(chart)) return;
118
+ if (chart.config.options.scales.x.length == 0) return;
119
+ const e = event.event;
120
+ const xScaleType = chart.config.options.scales.x.type;
121
+ if (xScaleType !== "linear" && xScaleType !== "time" && xScaleType !== "category" && xScaleType !== "logarithmic") return;
122
+ const xScale = this.getXScale(chart);
123
+ if (!xScale) return;
124
+ if (chart.marker.ignoreNextEvents > 0) {
125
+ chart.marker.ignoreNextEvents -= 1;
126
+ return;
127
+ }
128
+ chart.marker.enabled = e.type !== "mouseout" && e.x > xScale.getPixelForValue(xScale.min) && e.x < xScale.getPixelForValue(xScale.max);
129
+ if (!chart.marker.enabled && !chart.marker.suppressUpdate) {
130
+ if (e.x > xScale.getPixelForValue(xScale.max)) {
131
+ chart.marker.suppressUpdate = true;
132
+ chart.update("none");
133
+ }
134
+ chart.marker.dragStarted = false;
135
+ return false;
136
+ }
137
+ chart.marker.suppressUpdate = false;
138
+ chart.marker.x = e.x;
139
+ chart.draw();
140
+ },
141
+ doDraw: function(chart) {
142
+ if (!hasMarkerConfiguration(chart)) return;
143
+ if (!chart.marker.enabled) return;
144
+ this.drawTraceLine(chart);
145
+ this.interpolateValues(chart);
146
+ this.drawTracePoints(chart);
147
+ return true;
148
+ },
149
+ beforeDraw: function(chart) {
150
+ return this.doDraw(chart);
151
+ },
152
+ drawTraceLine: function(chart) {
153
+ if (!hasMarkerConfiguration(chart)) return;
154
+ const yScale = this.getYScale(chart);
155
+ const lineWidth = this.getOption(chart, "line", "width");
156
+ const color = this.getOption(chart, "line", "color");
157
+ const dashPattern = this.getOption(chart, "line", "dashPattern");
158
+ const snapEnabled = this.getOption(chart, "snap", "enabled");
159
+ let lineX = chart.marker.x;
160
+ if (snapEnabled && chart._active.length) lineX = chart._active[0].element.x;
161
+ chart.ctx.beginPath();
162
+ chart.ctx.setLineDash(dashPattern);
163
+ chart.ctx.moveTo(lineX, yScale.getPixelForValue(yScale.max));
164
+ chart.ctx.lineWidth = lineWidth;
165
+ chart.ctx.strokeStyle = color;
166
+ chart.ctx.lineTo(lineX, yScale.getPixelForValue(yScale.min));
167
+ chart.ctx.stroke();
168
+ chart.ctx.setLineDash([]);
169
+ },
170
+ drawTracePoints: function(chart) {
171
+ if (!hasMarkerConfiguration(chart)) return;
172
+ for (let chartIndex = 0; chartIndex < chart.data.datasets.length; chartIndex++) {
173
+ const dataset = chart.data.datasets[chartIndex];
174
+ const meta = chart.getDatasetMeta(chartIndex);
175
+ const yScale = chart.scales[meta.yAxisID];
176
+ if (meta.hidden || !dataset.interpolate) continue;
177
+ chart.ctx.beginPath();
178
+ chart.ctx.arc(chart.marker.x, yScale.getPixelForValue(dataset.interpolatedValue), 3, 0, 2 * Math.PI, false);
179
+ chart.ctx.fillStyle = "white";
180
+ chart.ctx.lineWidth = 2;
181
+ chart.ctx.strokeStyle = dataset.borderColor;
182
+ chart.ctx.fill();
183
+ chart.ctx.stroke();
184
+ }
185
+ },
186
+ interpolateValues: function(chart) {
187
+ for (let chartIndex = 0; chartIndex < chart.data.datasets.length; chartIndex++) {
188
+ const dataset = chart.data.datasets[chartIndex];
189
+ const meta = chart.getDatasetMeta(chartIndex);
190
+ const xValue = chart.scales[meta.xAxisID].getValueForPixel(chart.marker.x);
191
+ if (meta.hidden || !dataset.interpolate) continue;
192
+ const data = dataset.data;
193
+ const index = data.findIndex(function(o) {
194
+ return o.x >= xValue;
195
+ });
196
+ const prev = data[index - 1];
197
+ const next = data[index];
198
+ if (chart.data.datasets[chartIndex].steppedLine && prev) dataset.interpolatedValue = prev.y;
199
+ else if (prev && next) {
200
+ const slope = (next.y - prev.y) / (next.x - prev.x);
201
+ dataset.interpolatedValue = prev.y + (xValue - prev.x) * slope;
202
+ } else dataset.interpolatedValue = NaN;
203
+ }
204
+ }
305
205
  };
306
-
307
- const CHART_SCALES = [CategoryScale, LinearScale, TimeScale];
308
- const CHART_ELEMENTS = [BarElement, LineElement, PointElement];
206
+ const CHART_SCALES = [
207
+ CategoryScale,
208
+ LinearScale,
209
+ TimeScale
210
+ ];
211
+ const CHART_ELEMENTS = [
212
+ BarElement,
213
+ LineElement,
214
+ PointElement
215
+ ];
309
216
  const CHART_CONTROLLERS = [BarController, LineController];
310
- const CHART_PLUGINS = [annotationPlugin, Filler, ChartDataLabels, Tooltip, MarkerPlugin].map((plugin) => (plugin?.__esModule ? plugin.default : plugin));
311
- /* Order matters; defaults must be merged after register as
312
- register modifies the Chart.defaults objects */
313
- Chart.register(Legend, ...CHART_SCALES, ...CHART_ELEMENTS, ...CHART_CONTROLLERS, ...CHART_PLUGINS);
314
- /* Chart.defaults is read only; set each key modified in
315
- CHART_GLOBAL_DEFAULTS manually */
316
- const mergedDefaults = mergeDeepAll(Chart.defaults, CHART_GLOBAL_DEFAULTS);
217
+ const CHART_PLUGINS = [
218
+ annotationPlugin,
219
+ Filler,
220
+ ChartDataLabels,
221
+ Tooltip,
222
+ chartjs_plugin_marker_default
223
+ ].map((plugin) => plugin?.__esModule ? plugin.default : plugin);
224
+ Chart$1.register(Legend, ...CHART_SCALES, ...CHART_ELEMENTS, ...CHART_CONTROLLERS, ...CHART_PLUGINS);
225
+ const mergedDefaults = mergeDeepAll(Chart$1.defaults, CHART_GLOBAL_DEFAULTS);
317
226
  Object.entries(CHART_GLOBAL_DEFAULTS).forEach(([key]) => {
318
- Chart.defaults[key] = mergedDefaults[key];
227
+ Chart$1.defaults[key] = mergedDefaults[key];
319
228
  });
320
-
321
229
  const { getThemeColorHexString: getThemeColorHexString$4 } = ColorHelper;
322
- /* The chart.js annotation does not allow for changing the
323
- defaults it comes with. In order to have sensible defaults
324
- this object is used instead and manually merged with the
325
- rest of the annotations object */
326
- const borderColor = getThemeColorHexString$4('semi-dark');
230
+ const borderColor = getThemeColorHexString$4("semi-dark");
327
231
  const borderDash = [6, 3];
328
232
  const borderWidth = 1;
329
233
  const CHART_ANNOTATIONS_CONFIG = {
330
- line: {
331
- borderDash,
332
- borderWidth,
333
- borderColor,
334
- },
335
- ellipse: {
336
- borderDash,
337
- borderWidth,
338
- borderColor,
339
- backgroundColor: 'transparent',
340
- },
341
- box: {
342
- borderDash,
343
- borderWidth,
344
- borderColor,
345
- backgroundColor: 'transparent',
346
- },
347
- point: {
348
- backgroundColor: 'initial',
349
- },
350
- };
351
-
352
- /* Allows for adding functionality to interactions chart.js while
353
- preserving the interaction functionality the consumer of the component has
354
- passed by being provided as a callback. */
355
- const CHART_INTERACTION_FUNCTIONS_EXTENSIONS = {
356
- onHover: (_event, activeElements, _chart, callback) => {
357
- if (_chart.options.onClick) {
358
- _chart.canvas.style.cursor = activeElements[0] ? 'pointer' : 'default';
359
- }
360
- if (callback)
361
- callback(_event, activeElements, _chart);
362
- },
234
+ line: {
235
+ borderDash,
236
+ borderWidth,
237
+ borderColor
238
+ },
239
+ ellipse: {
240
+ borderDash,
241
+ borderWidth,
242
+ borderColor,
243
+ backgroundColor: "transparent"
244
+ },
245
+ box: {
246
+ borderDash,
247
+ borderWidth,
248
+ borderColor,
249
+ backgroundColor: "transparent"
250
+ },
251
+ point: { backgroundColor: "initial" }
363
252
  };
364
-
253
+ const CHART_INTERACTION_FUNCTIONS_EXTENSIONS = { onHover: (_event, activeElements, _chart, callback) => {
254
+ if (_chart.options.onClick) _chart.canvas.style.cursor = activeElements[0] ? "pointer" : "default";
255
+ if (callback) callback(_event, activeElements, _chart);
256
+ } };
365
257
  const { fontSize: fontSize$2 } = DesignTokenHelper;
366
258
  const { getThemeColorHexString: getThemeColorHexString$3, getThemeColorRgbString: getThemeColorRgbString$1 } = ColorHelper;
367
- /**
368
- * A filter to read a chartpoint from a Chart.js point context (used for chartdata points). Context is provided by Chart.js.
369
- */
370
259
  const getChartPointFromContext = (context) => {
371
- return context.dataset.data[context.dataIndex];
260
+ return context.dataset.data[context.dataIndex];
372
261
  };
373
262
  const CHART_TYPES_CONFIG = {
374
- bar: {
375
- type: 'bar',
376
- options: {
377
- datasets: {
378
- bar: {
379
- barPercentage: 0.6,
380
- },
381
- line: {
382
- spanGaps: true,
383
- },
384
- },
385
- indexAxis: 'y',
386
- scales: {
387
- y: {
388
- grid: {
389
- drawBorder: false,
390
- },
391
- ticks: {
392
- font: {
393
- size: parseInt(fontSize$2('s')),
394
- },
395
- },
396
- },
397
- },
398
- elements: {
399
- point: {
400
- radius: 0,
401
- },
402
- line: {
403
- borderColor: getThemeColorHexString$3('medium'),
404
- },
405
- },
406
- },
407
- },
408
- column: {
409
- type: 'bar',
410
- options: {
411
- datasets: {
412
- bar: {
413
- barPercentage: 0.6,
414
- },
415
- line: {
416
- spanGaps: true,
417
- },
418
- },
419
- indexAxis: 'x',
420
- scales: {
421
- x: {
422
- grid: {
423
- drawBorder: false,
424
- },
425
- ticks: {
426
- font: {
427
- size: parseInt(fontSize$2('xs')),
428
- },
429
- },
430
- },
431
- },
432
- elements: {
433
- line: {
434
- tension: 0.2,
435
- borderColor: getThemeColorHexString$3('medium'),
436
- },
437
- point: {
438
- radius: 0,
439
- },
440
- },
441
- },
442
- },
443
- line: {
444
- type: 'line',
445
- options: {
446
- backgroundColor: getThemeColorRgbString$1('semi-light', 0.5),
447
- scales: {
448
- x: {
449
- grid: {
450
- borderColor: getThemeColorHexString$3('medium'),
451
- borderWidth: 1,
452
- },
453
- ticks: {
454
- font: {
455
- size: parseInt(fontSize$2('xs')),
456
- },
457
- },
458
- },
459
- },
460
- elements: {
461
- point: {
462
- radius: 0,
463
- },
464
- },
465
- },
466
- },
467
- stock: {
468
- type: 'line',
469
- options: {
470
- responsive: true,
471
- animation: {
472
- duration: 0,
473
- },
474
- layout: {
475
- padding: {
476
- left: 20,
477
- right: 20,
478
- top: 30,
479
- bottom: 0,
480
- },
481
- },
482
- backgroundColor: getThemeColorRgbString$1('semi-light', 0.5),
483
- scales: {
484
- x: {
485
- grid: {
486
- lineWidth: 0,
487
- },
488
- ticks: {
489
- maxRotation: 0,
490
- autoSkipPadding: 120,
491
- font: {
492
- size: parseInt(fontSize$2('xs')),
493
- },
494
- },
495
- },
496
- y: {
497
- position: 'right',
498
- display: true,
499
- grid: {
500
- drawBorder: false,
501
- },
502
- ticks: {
503
- display: true,
504
- font: {
505
- size: parseInt(fontSize$2('xs')),
506
- },
507
- },
508
- },
509
- },
510
- elements: {
511
- line: {
512
- tension: 0, // Smooth curve (0 = no smoothing)
513
- borderWidth: 2,
514
- },
515
- point: {
516
- hitRadius: 20,
517
- radius: 0,
518
- hoverRadius: 0,
519
- hoverBorderWidth: 0,
520
- },
521
- },
522
- normalized: true,
523
- plugins: {
524
- tooltip: {
525
- padding: 10,
526
- enabled: true,
527
- mode: 'index',
528
- intersect: false,
529
- backgroundColor: getThemeColorHexString$3('semi-light'),
530
- titleColor: getThemeColorHexString$3('semi-light-contrast'),
531
- bodyColor: getThemeColorHexString$3('semi-light-contrast'),
532
- caretSize: 0,
533
- bodySpacing: 5,
534
- titleSpacing: 5,
535
- borderColor: 'transparent',
536
- callbacks: {
537
- labelColor: (tooltipItem) => {
538
- return {
539
- backgroundColor: tooltipItem.dataset.borderColor,
540
- borderColor: getThemeColorHexString$3('semi-light'),
541
- borderWidth: 2, // This value must be exactly 2. If it is less, a white "border" will appear, if greater than, a shadow around the box will be shown.
542
- // An issue has been created, requesting a test to check this value doesn´t change: https://github.com/kirbydesign/designsystem/issues/2578
543
- };
544
- },
545
- },
546
- },
547
- datalabels: {
548
- backgroundColor: (context) => context.dataset.borderColor,
549
- color: getThemeColorHexString$3('white'),
550
- borderRadius: 3,
551
- font: {
552
- lineHeight: 1,
553
- size: parseInt(fontSize$2('xs')),
554
- },
555
- padding: {
556
- top: 6,
557
- left: 5,
558
- right: 5,
559
- bottom: 5,
560
- },
561
- offset: 5,
562
- align: (context) => getChartPointFromContext(context)?.datalabel.position,
563
- display: (context) => !!getChartPointFromContext(context)?.datalabel,
564
- formatter: (value) => value.datalabel.value,
565
- },
566
- },
567
- },
568
- },
263
+ bar: {
264
+ type: "bar",
265
+ options: {
266
+ datasets: {
267
+ bar: { barPercentage: .6 },
268
+ line: { spanGaps: true }
269
+ },
270
+ indexAxis: "y",
271
+ scales: { y: {
272
+ grid: { drawBorder: false },
273
+ ticks: { font: { size: parseInt(fontSize$2("s")) } }
274
+ } },
275
+ elements: {
276
+ point: { radius: 0 },
277
+ line: { borderColor: getThemeColorHexString$3("medium") }
278
+ }
279
+ }
280
+ },
281
+ column: {
282
+ type: "bar",
283
+ options: {
284
+ datasets: {
285
+ bar: { barPercentage: .6 },
286
+ line: { spanGaps: true }
287
+ },
288
+ indexAxis: "x",
289
+ scales: { x: {
290
+ grid: { drawBorder: false },
291
+ ticks: { font: { size: parseInt(fontSize$2("xs")) } }
292
+ } },
293
+ elements: {
294
+ line: {
295
+ tension: .2,
296
+ borderColor: getThemeColorHexString$3("medium")
297
+ },
298
+ point: { radius: 0 }
299
+ }
300
+ }
301
+ },
302
+ line: {
303
+ type: "line",
304
+ options: {
305
+ backgroundColor: getThemeColorRgbString$1("semi-light", .5),
306
+ scales: { x: {
307
+ grid: {
308
+ borderColor: getThemeColorHexString$3("medium"),
309
+ borderWidth: 1
310
+ },
311
+ ticks: { font: { size: parseInt(fontSize$2("xs")) } }
312
+ } },
313
+ elements: { point: { radius: 0 } }
314
+ }
315
+ },
316
+ stock: {
317
+ type: "line",
318
+ options: {
319
+ responsive: true,
320
+ animation: { duration: 0 },
321
+ layout: { padding: {
322
+ left: 20,
323
+ right: 20,
324
+ top: 30,
325
+ bottom: 0
326
+ } },
327
+ backgroundColor: getThemeColorRgbString$1("semi-light", .5),
328
+ scales: {
329
+ x: {
330
+ grid: { lineWidth: 0 },
331
+ ticks: {
332
+ maxRotation: 0,
333
+ autoSkipPadding: 120,
334
+ font: { size: parseInt(fontSize$2("xs")) }
335
+ }
336
+ },
337
+ y: {
338
+ position: "right",
339
+ display: true,
340
+ grid: { drawBorder: false },
341
+ ticks: {
342
+ display: true,
343
+ font: { size: parseInt(fontSize$2("xs")) }
344
+ }
345
+ }
346
+ },
347
+ elements: {
348
+ line: {
349
+ tension: 0,
350
+ borderWidth: 2
351
+ },
352
+ point: {
353
+ hitRadius: 20,
354
+ radius: 0,
355
+ hoverRadius: 0,
356
+ hoverBorderWidth: 0
357
+ }
358
+ },
359
+ normalized: true,
360
+ plugins: {
361
+ tooltip: {
362
+ padding: 10,
363
+ enabled: true,
364
+ mode: "index",
365
+ intersect: false,
366
+ backgroundColor: getThemeColorHexString$3("semi-light"),
367
+ titleColor: getThemeColorHexString$3("semi-light-contrast"),
368
+ bodyColor: getThemeColorHexString$3("semi-light-contrast"),
369
+ caretSize: 0,
370
+ bodySpacing: 5,
371
+ titleSpacing: 5,
372
+ borderColor: "transparent",
373
+ callbacks: { labelColor: (tooltipItem) => {
374
+ return {
375
+ backgroundColor: tooltipItem.dataset.borderColor,
376
+ borderColor: getThemeColorHexString$3("semi-light"),
377
+ borderWidth: 2
378
+ };
379
+ } }
380
+ },
381
+ datalabels: {
382
+ backgroundColor: (context) => context.dataset.borderColor,
383
+ color: getThemeColorHexString$3("white"),
384
+ borderRadius: 3,
385
+ font: {
386
+ lineHeight: 1,
387
+ size: parseInt(fontSize$2("xs"))
388
+ },
389
+ padding: {
390
+ top: 6,
391
+ left: 5,
392
+ right: 5,
393
+ bottom: 5
394
+ },
395
+ offset: 5,
396
+ align: (context) => getChartPointFromContext(context)?.datalabel.position,
397
+ display: (context) => !!getChartPointFromContext(context)?.datalabel,
398
+ formatter: (value) => value.datalabel.value
399
+ }
400
+ }
401
+ }
402
+ }
569
403
  };
570
-
571
- class ChartConfigService {
572
- getTypeConfig(chartType) {
573
- /* Deep copy to avoid Chart object modifying parts of CHART_TYPES_CONFIG
574
- as it copies by reference when initialized */
575
- return deepCopy(CHART_TYPES_CONFIG[chartType]);
576
- }
577
- getAnnotationDefaults(type) {
578
- return CHART_ANNOTATIONS_CONFIG[type];
579
- }
580
- /* Our types does not always map 1 to 1 to the same type
581
- that the chart.js chart is actually configured with. Therefore this function
582
- for looking up the ChartJSType of a type. */
583
- chartTypeToChartJSType(chartType) {
584
- return CHART_TYPES_CONFIG[chartType]['type'];
585
- }
586
- applyInteractionFunctionsExtensions(options) {
587
- const interactionFunctionsExtensions = CHART_INTERACTION_FUNCTIONS_EXTENSIONS;
588
- Object.entries(interactionFunctionsExtensions).forEach(([key]) => {
589
- const callback = options[key];
590
- options[key] = (e, a, c) => {
591
- interactionFunctionsExtensions[key](e, a, c, callback);
592
- };
593
- });
594
- return options;
595
- }
596
- getStockChartOptions(dataLabelOptions, locale) {
597
- return {
598
- locale: locale,
599
- plugins: {
600
- tooltip: {
601
- callbacks: {
602
- title: (tooltipItems) => {
603
- const date = toDate(tooltipItems[0]?.raw?.x);
604
- if (date.valueOf()) {
605
- return date.toLocaleTimeString(locale, {
606
- day: 'numeric',
607
- month: 'short',
608
- hour: '2-digit',
609
- minute: '2-digit',
610
- });
611
- }
612
- },
613
- label: (context) => {
614
- // It's not possible to add spacing between color legend and text so we
615
- // prefix with a space.
616
- return ' ' + context.formattedValue + (dataLabelOptions.valueSuffix || '');
617
- },
618
- },
619
- },
620
- },
621
- scales: {
622
- y: {
623
- ticks: {
624
- callback: (value) => {
625
- return value + (dataLabelOptions.valueSuffix || '');
626
- },
627
- },
628
- },
629
- },
630
- };
631
- }
632
- /** @nocollapse */ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.23", ngImport: i0, type: ChartConfigService, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
633
- /** @nocollapse */ static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "21.2.23", ngImport: i0, type: ChartConfigService }); }
634
- }
635
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.23", ngImport: i0, type: ChartConfigService, decorators: [{
636
- type: Injectable
637
- }] });
638
-
639
- class ChartJSService {
640
- constructor(chartConfigService) {
641
- this.chartConfigService = chartConfigService;
642
- this.annotationsDelegate = new AnnotationsDelegate(chartConfigService);
643
- }
644
- renderChart(args) {
645
- const { targetElement, type, data, labels, customOptions, annotations, highlightedElements } = args;
646
- this.highlightedElements = highlightedElements || null;
647
- this.chartType = type;
648
- const datasets = this.createDatasets(data);
649
- const options = this.createOptionsObject({
650
- customOptions,
651
- annotations,
652
- });
653
- const config = this.createConfigurationObject(type, datasets, options, labels);
654
- this.initializeNewChart(targetElement.nativeElement, config);
655
- }
656
- redrawChart() {
657
- this.chart.update();
658
- }
659
- destroyChart() {
660
- this.chart?.destroy();
661
- }
662
- updateData(data) {
663
- const datasets = this.createDatasets(data);
664
- this.chart.data.datasets = datasets;
665
- }
666
- updateLabels(labels) {
667
- /* As labels provided via the 'labels' input property always has
668
- highest priority - we can just set the property directly */
669
- this.chart.data.labels = labels;
670
- }
671
- updateType(type, customOptions) {
672
- if (type === 'bar' || type === 'column') {
673
- /* indexAxis does not update predictably; update by replacing
674
- the chart entirely instead */
675
- this.destructivelyUpdateType(type, customOptions);
676
- }
677
- else {
678
- this.nonDestructivelyUpdateType(type, customOptions);
679
- }
680
- }
681
- updateOptions(customOptions, type) {
682
- const annotations = this.annotationsDelegate.getExistingChartAnnotations(this.chart);
683
- this.chartType = type;
684
- this.chart.options = this.createOptionsObject({ customOptions, annotations });
685
- }
686
- updateAnnotations(annotations) {
687
- const annotationsWithDefaults = this.annotationsDelegate.applyDefaultsToAnnotations(annotations);
688
- this.chart.options.plugins.annotation.annotations = annotationsWithDefaults;
689
- }
690
- updateHighlightedElements(highlightedElements) {
691
- this.highlightedElements = highlightedElements;
692
- const oldDatasets = this.chart.data.datasets;
693
- // Clear old datasets of highlighted elements
694
- oldDatasets.map((dataset) => {
695
- if (dataset?.kirbyOptions?.highlightedElements) {
696
- delete dataset.kirbyOptions.highlightedElements;
697
- }
698
- });
699
- this.chart.data.datasets = this.createDatasets(oldDatasets);
700
- }
701
- createOptionsObject(args) {
702
- const { customOptions, annotations } = args;
703
- const typeConfig = this.chartConfigService.getTypeConfig(this.chartType);
704
- const typeConfigOptions = typeConfig?.options;
705
- const annotationPluginOptions = annotations
706
- ? this.annotationsDelegate.createAnnotationPluginOptionsObject(annotations)
707
- : {};
708
- const mergedOptions = mergeDeepAll(typeConfigOptions, customOptions, annotationPluginOptions);
709
- return this.chartConfigService.applyInteractionFunctionsExtensions(mergedOptions);
710
- }
711
- getDefaultLabels(datasets) {
712
- /*
713
- Chart.js requires labels along the index axis to render anything therefore
714
- use blank labels
715
- */
716
- const largestDataset = datasets.reduce((previousDataset, currentDataset) => previousDataset.data.length > currentDataset.data.length ? previousDataset : currentDataset);
717
- return Array(largestDataset.data.length).fill('');
718
- }
719
- createConfigurationObject(type, datasets, options, labels) {
720
- const typeConfig = this.chartConfigService.getTypeConfig(type);
721
- const indexAxis = typeConfig?.options?.indexAxis ?? 'x';
722
- const labelsToApply = this.getLabelsToApply({ labels, datasets, type, indexAxis });
723
- return mergeDeepAll(typeConfig, {
724
- data: {
725
- labels: labelsToApply,
726
- datasets,
727
- },
728
- options,
729
- });
730
- }
731
- createDatasets(data) {
732
- const datasets = isNumberArray(data) ? [{ data }] : data;
733
- if (this.highlightedElements)
734
- this.addHighlightedElementsToDatasets(this.highlightedElements, datasets);
735
- return datasets;
736
- }
737
- destructivelyUpdateType(type, customOptions) {
738
- const datasets = this.chart.data.datasets;
739
- const labels = this.chart.data.labels; // chart.js stores labels as unknown[]; cast it to ChartLabel[]
740
- const annotations = this.annotationsDelegate.getExistingChartAnnotations(this.chart);
741
- this.chartType = type;
742
- const options = this.createOptionsObject({ customOptions, annotations });
743
- const config = this.createConfigurationObject(type, datasets, options, labels);
744
- const canvasElement = this.chart.canvas;
745
- this.chart.destroy();
746
- this.initializeNewChart(canvasElement, config);
747
- }
748
- nonDestructivelyUpdateType(chartType, customOptions) {
749
- const annotations = this.annotationsDelegate.getExistingChartAnnotations(this.chart);
750
- this.chartType = chartType;
751
- const options = this.createOptionsObject({
752
- customOptions,
753
- annotations,
754
- });
755
- this.chart.options = options;
756
- if (chartConfigHasType(this.chart.config)) {
757
- this.chart.config.type = this.chartConfigService.chartTypeToChartJSType(chartType);
758
- }
759
- }
760
- initializeNewChart(canvasElement, config) {
761
- this.chart = new Chart(canvasElement, config);
762
- }
763
- addHighlightedElementsToDatasets(highlightedElements, datasets) {
764
- highlightedElements.forEach(([datasetIndex, dataIndex]) => {
765
- const dataset = datasets[datasetIndex];
766
- if (!dataset)
767
- return;
768
- if (dataset?.kirbyOptions?.highlightedElements) {
769
- dataset.kirbyOptions.highlightedElements.push(dataIndex);
770
- }
771
- else {
772
- dataset.kirbyOptions = {
773
- ...dataset.kirbyOptions,
774
- highlightedElements: [dataIndex],
775
- };
776
- }
777
- });
778
- }
779
- getLabelsToApply(args) {
780
- const { datasets, labels, indexAxis } = args;
781
- const datasetHasLabels = ({ data }) => !!data?.some((datapoint) => typeof datapoint === 'object' && typeof datapoint[indexAxis] === 'string');
782
- /*
783
- Labels can be provided by the user two ways:
784
- 1. As a seperate ChartLabel[] via the 'labels' input prop - this has highest priority
785
- 2. Together with the dataset via the 'data' input prop - here each datapoint contains
786
- a label for the indexAxis.
787
- For example: { x: 'label1', y: 1} in the case where the index axis is 'x'.
788
-
789
- If no labels are provided then default labels are used.
790
- */
791
- const labelsAreGivenAsSeperateArray = labels !== undefined;
792
- const labelsAreGivenTogetherWithDataset = datasets.some(datasetHasLabels);
793
- if (labelsAreGivenAsSeperateArray) {
794
- return labels;
795
- }
796
- else if (labelsAreGivenTogetherWithDataset) {
797
- return null;
798
- }
799
- else {
800
- return this.getDefaultLabels(datasets);
801
- }
802
- }
803
- /** @nocollapse */ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.23", ngImport: i0, type: ChartJSService, deps: [{ token: ChartConfigService }], target: i0.ɵɵFactoryTarget.Injectable }); }
804
- /** @nocollapse */ static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "21.2.23", ngImport: i0, type: ChartJSService }); }
805
- }
806
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.23", ngImport: i0, type: ChartJSService, decorators: [{
807
- type: Injectable
808
- }], ctorParameters: () => [{ type: ChartConfigService }] });
809
-
404
+ var ChartConfigService = class ChartConfigService {
405
+ getTypeConfig(chartType) {
406
+ return deepCopy(CHART_TYPES_CONFIG[chartType]);
407
+ }
408
+ getAnnotationDefaults(type) {
409
+ return CHART_ANNOTATIONS_CONFIG[type];
410
+ }
411
+ chartTypeToChartJSType(chartType) {
412
+ return CHART_TYPES_CONFIG[chartType]["type"];
413
+ }
414
+ applyInteractionFunctionsExtensions(options) {
415
+ const interactionFunctionsExtensions = CHART_INTERACTION_FUNCTIONS_EXTENSIONS;
416
+ Object.entries(interactionFunctionsExtensions).forEach(([key]) => {
417
+ const callback = options[key];
418
+ options[key] = (e, a, c) => {
419
+ interactionFunctionsExtensions[key](e, a, c, callback);
420
+ };
421
+ });
422
+ return options;
423
+ }
424
+ getStockChartOptions(dataLabelOptions, locale) {
425
+ return {
426
+ locale,
427
+ plugins: { tooltip: { callbacks: {
428
+ title: (tooltipItems) => {
429
+ const date = toDate(tooltipItems[0]?.raw?.x);
430
+ if (date.valueOf()) return date.toLocaleTimeString(locale, {
431
+ day: "numeric",
432
+ month: "short",
433
+ hour: "2-digit",
434
+ minute: "2-digit"
435
+ });
436
+ },
437
+ label: (context) => {
438
+ return " " + context.formattedValue + (dataLabelOptions.valueSuffix || "");
439
+ }
440
+ } } },
441
+ scales: { y: { ticks: { callback: (value) => {
442
+ return value + (dataLabelOptions.valueSuffix || "");
443
+ } } } }
444
+ };
445
+ }
446
+ static {
447
+ this.ɵfac = i0.ɵɵngDeclareFactory({
448
+ minVersion: "12.0.0",
449
+ version: "22.2.2",
450
+ ngImport: i0,
451
+ type: ChartConfigService,
452
+ deps: [],
453
+ target: i0.ɵɵFactoryTarget.Injectable
454
+ });
455
+ }
456
+ static {
457
+ this.ɵprov = i0.ɵɵngDeclareInjectable({
458
+ minVersion: "12.0.0",
459
+ version: "22.2.2",
460
+ ngImport: i0,
461
+ type: ChartConfigService
462
+ });
463
+ }
464
+ };
465
+ i0.ɵɵngDeclareClassMetadata({
466
+ minVersion: "12.0.0",
467
+ version: "22.2.2",
468
+ ngImport: i0,
469
+ type: ChartConfigService,
470
+ decorators: [{ type: Injectable }]
471
+ });
472
+ var ChartJSService = class ChartJSService {
473
+ constructor(chartConfigService) {
474
+ this.chartConfigService = chartConfigService;
475
+ this.annotationsDelegate = new AnnotationsDelegate(chartConfigService);
476
+ }
477
+ renderChart(args) {
478
+ const { targetElement, type, data, labels, customOptions, annotations, highlightedElements } = args;
479
+ this.highlightedElements = highlightedElements || null;
480
+ this.chartType = type;
481
+ const datasets = this.createDatasets(data);
482
+ const options = this.createOptionsObject({
483
+ customOptions,
484
+ annotations
485
+ });
486
+ const config = this.createConfigurationObject(type, datasets, options, labels);
487
+ this.initializeNewChart(targetElement.nativeElement, config);
488
+ }
489
+ redrawChart() {
490
+ this.chart.update();
491
+ }
492
+ destroyChart() {
493
+ this.chart?.destroy();
494
+ }
495
+ updateData(data) {
496
+ const datasets = this.createDatasets(data);
497
+ this.chart.data.datasets = datasets;
498
+ }
499
+ updateLabels(labels) {
500
+ this.chart.data.labels = labels;
501
+ }
502
+ updateType(type, customOptions) {
503
+ if (type === "bar" || type === "column") this.destructivelyUpdateType(type, customOptions);
504
+ else this.nonDestructivelyUpdateType(type, customOptions);
505
+ }
506
+ updateOptions(customOptions, type) {
507
+ const annotations = this.annotationsDelegate.getExistingChartAnnotations(this.chart);
508
+ this.chartType = type;
509
+ this.chart.options = this.createOptionsObject({
510
+ customOptions,
511
+ annotations
512
+ });
513
+ }
514
+ updateAnnotations(annotations) {
515
+ const annotationsWithDefaults = this.annotationsDelegate.applyDefaultsToAnnotations(annotations);
516
+ this.chart.options.plugins.annotation.annotations = annotationsWithDefaults;
517
+ }
518
+ updateHighlightedElements(highlightedElements) {
519
+ this.highlightedElements = highlightedElements;
520
+ const oldDatasets = this.chart.data.datasets;
521
+ oldDatasets.map((dataset) => {
522
+ if (dataset?.kirbyOptions?.highlightedElements) delete dataset.kirbyOptions.highlightedElements;
523
+ });
524
+ this.chart.data.datasets = this.createDatasets(oldDatasets);
525
+ }
526
+ createOptionsObject(args) {
527
+ const { customOptions, annotations } = args;
528
+ const typeConfigOptions = this.chartConfigService.getTypeConfig(this.chartType)?.options;
529
+ const annotationPluginOptions = annotations ? this.annotationsDelegate.createAnnotationPluginOptionsObject(annotations) : {};
530
+ const mergedOptions = mergeDeepAll(typeConfigOptions, customOptions, annotationPluginOptions);
531
+ return this.chartConfigService.applyInteractionFunctionsExtensions(mergedOptions);
532
+ }
533
+ getDefaultLabels(datasets) {
534
+ const largestDataset = datasets.reduce((previousDataset, currentDataset) => previousDataset.data.length > currentDataset.data.length ? previousDataset : currentDataset);
535
+ return Array(largestDataset.data.length).fill("");
536
+ }
537
+ createConfigurationObject(type, datasets, options, labels) {
538
+ const typeConfig = this.chartConfigService.getTypeConfig(type);
539
+ const indexAxis = typeConfig?.options?.indexAxis ?? "x";
540
+ const labelsToApply = this.getLabelsToApply({
541
+ labels,
542
+ datasets,
543
+ type,
544
+ indexAxis
545
+ });
546
+ return mergeDeepAll(typeConfig, {
547
+ data: {
548
+ labels: labelsToApply,
549
+ datasets
550
+ },
551
+ options
552
+ });
553
+ }
554
+ createDatasets(data) {
555
+ const datasets = isNumberArray(data) ? [{ data }] : data;
556
+ if (this.highlightedElements) this.addHighlightedElementsToDatasets(this.highlightedElements, datasets);
557
+ return datasets;
558
+ }
559
+ destructivelyUpdateType(type, customOptions) {
560
+ const datasets = this.chart.data.datasets;
561
+ const labels = this.chart.data.labels;
562
+ const annotations = this.annotationsDelegate.getExistingChartAnnotations(this.chart);
563
+ this.chartType = type;
564
+ const options = this.createOptionsObject({
565
+ customOptions,
566
+ annotations
567
+ });
568
+ const config = this.createConfigurationObject(type, datasets, options, labels);
569
+ const canvasElement = this.chart.canvas;
570
+ this.chart.destroy();
571
+ this.initializeNewChart(canvasElement, config);
572
+ }
573
+ nonDestructivelyUpdateType(chartType, customOptions) {
574
+ const annotations = this.annotationsDelegate.getExistingChartAnnotations(this.chart);
575
+ this.chartType = chartType;
576
+ const options = this.createOptionsObject({
577
+ customOptions,
578
+ annotations
579
+ });
580
+ this.chart.options = options;
581
+ if (chartConfigHasType(this.chart.config)) this.chart.config.type = this.chartConfigService.chartTypeToChartJSType(chartType);
582
+ }
583
+ initializeNewChart(canvasElement, config) {
584
+ this.chart = new Chart$1(canvasElement, config);
585
+ }
586
+ addHighlightedElementsToDatasets(highlightedElements, datasets) {
587
+ highlightedElements.forEach(([datasetIndex, dataIndex]) => {
588
+ const dataset = datasets[datasetIndex];
589
+ if (!dataset) return;
590
+ if (dataset?.kirbyOptions?.highlightedElements) dataset.kirbyOptions.highlightedElements.push(dataIndex);
591
+ else dataset.kirbyOptions = {
592
+ ...dataset.kirbyOptions,
593
+ highlightedElements: [dataIndex]
594
+ };
595
+ });
596
+ }
597
+ getLabelsToApply(args) {
598
+ const { datasets, labels, indexAxis } = args;
599
+ const datasetHasLabels = ({ data }) => !!data?.some((datapoint) => typeof datapoint === "object" && typeof datapoint[indexAxis] === "string");
600
+ const labelsAreGivenAsSeperateArray = labels !== void 0;
601
+ const labelsAreGivenTogetherWithDataset = datasets.some(datasetHasLabels);
602
+ if (labelsAreGivenAsSeperateArray) return labels;
603
+ else if (labelsAreGivenTogetherWithDataset) return null;
604
+ else return this.getDefaultLabels(datasets);
605
+ }
606
+ static {
607
+ this.ɵfac = i0.ɵɵngDeclareFactory({
608
+ minVersion: "12.0.0",
609
+ version: "22.2.2",
610
+ ngImport: i0,
611
+ type: ChartJSService,
612
+ deps: [{ token: ChartConfigService }],
613
+ target: i0.ɵɵFactoryTarget.Injectable
614
+ });
615
+ }
616
+ static {
617
+ this.ɵprov = i0.ɵɵngDeclareInjectable({
618
+ minVersion: "12.0.0",
619
+ version: "22.2.2",
620
+ ngImport: i0,
621
+ type: ChartJSService
622
+ });
623
+ }
624
+ };
625
+ i0.ɵɵngDeclareClassMetadata({
626
+ minVersion: "12.0.0",
627
+ version: "22.2.2",
628
+ ngImport: i0,
629
+ type: ChartJSService,
630
+ decorators: [{ type: Injectable }],
631
+ ctorParameters: () => [{ type: ChartConfigService }]
632
+ });
810
633
  const TEST_CHART_TYPES_CONFIG = {
811
- bar: {
812
- type: 'bar',
813
- options: {
814
- indexAxis: 'y',
815
- elements: {
816
- line: {
817
- borderColor: 'blue',
818
- },
819
- },
820
- },
821
- },
822
- column: {
823
- type: 'bar',
824
- options: {
825
- backgroundColor: 'red',
826
- },
827
- },
828
- line: {
829
- type: 'line',
830
- options: {
831
- backgroundColor: 'blue',
832
- elements: {
833
- line: {
834
- borderColor: 'red',
835
- },
836
- },
837
- },
838
- },
839
- stock: {
840
- type: 'line',
841
- options: {
842
- locale: 'en-US',
843
- responsive: true,
844
- animation: {
845
- duration: 0,
846
- },
847
- layout: {
848
- padding: {
849
- left: 0,
850
- right: 10,
851
- top: 30,
852
- bottom: 0,
853
- },
854
- },
855
- backgroundColor: 'rgba(235, 235, 235, 0.5)',
856
- scales: {
857
- x: {
858
- type: 'time',
859
- time: {
860
- unit: 'day',
861
- displayFormats: {
862
- hour: 'HH:mm',
863
- day: 'MMM d',
864
- },
865
- },
866
- grid: {
867
- lineWidth: 0,
868
- },
869
- ticks: {
870
- maxRotation: 0,
871
- source: 'data',
872
- autoSkipPadding: 40,
873
- font: {
874
- size: 12,
875
- },
876
- },
877
- adapters: {
878
- date: {
879
- locale: {
880
- code: 'en-US',
881
- formatLong: {},
882
- localize: {},
883
- match: {},
884
- options: {
885
- weekStartsOn: 0,
886
- firstWeekContainsDate: 1,
887
- },
888
- },
889
- },
890
- },
891
- },
892
- y: {
893
- position: 'right',
894
- display: true,
895
- grid: {
896
- drawBorder: false,
897
- },
898
- ticks: {
899
- display: true,
900
- font: {
901
- size: 12,
902
- },
903
- },
904
- },
905
- },
906
- elements: {
907
- line: {
908
- tension: 0,
909
- borderWidth: 2,
910
- },
911
- point: {
912
- hitRadius: 20,
913
- radius: 0,
914
- hoverRadius: 0,
915
- hoverBorderWidth: 0,
916
- },
917
- },
918
- normalized: true,
919
- plugins: {
920
- tooltip: {
921
- mode: 'index',
922
- intersect: false,
923
- caretSize: 1,
924
- caretPadding: 12,
925
- displayColors: true,
926
- backgroundColor: '#ebebeb',
927
- padding: 8,
928
- titleColor: 'black',
929
- bodyColor: 'black',
930
- titleFont: {
931
- weight: 'normal',
932
- size: 12,
933
- },
934
- bodyFont: {
935
- size: 16,
936
- weight: 'bold',
937
- },
938
- callbacks: {},
939
- },
940
- // marker: {
941
- // line: {
942
- // color: 'red',
943
- // },
944
- // },
945
- datalabels: {
946
- color: '#ffffff',
947
- borderRadius: 3,
948
- font: {
949
- lineHeight: 1,
950
- size: 12,
951
- },
952
- padding: {
953
- top: 6,
954
- left: 5,
955
- right: 5,
956
- bottom: 5,
957
- },
958
- offset: 5,
959
- },
960
- },
961
- },
962
- },
634
+ bar: {
635
+ type: "bar",
636
+ options: {
637
+ indexAxis: "y",
638
+ elements: { line: { borderColor: "blue" } }
639
+ }
640
+ },
641
+ column: {
642
+ type: "bar",
643
+ options: { backgroundColor: "red" }
644
+ },
645
+ line: {
646
+ type: "line",
647
+ options: {
648
+ backgroundColor: "blue",
649
+ elements: { line: { borderColor: "red" } }
650
+ }
651
+ },
652
+ stock: {
653
+ type: "line",
654
+ options: {
655
+ locale: "en-US",
656
+ responsive: true,
657
+ animation: { duration: 0 },
658
+ layout: { padding: {
659
+ left: 0,
660
+ right: 10,
661
+ top: 30,
662
+ bottom: 0
663
+ } },
664
+ backgroundColor: "rgba(235, 235, 235, 0.5)",
665
+ scales: {
666
+ x: {
667
+ type: "time",
668
+ time: {
669
+ unit: "day",
670
+ displayFormats: {
671
+ hour: "HH:mm",
672
+ day: "MMM d"
673
+ }
674
+ },
675
+ grid: { lineWidth: 0 },
676
+ ticks: {
677
+ maxRotation: 0,
678
+ source: "data",
679
+ autoSkipPadding: 40,
680
+ font: { size: 12 }
681
+ },
682
+ adapters: { date: { locale: {
683
+ code: "en-US",
684
+ formatLong: {},
685
+ localize: {},
686
+ match: {},
687
+ options: {
688
+ weekStartsOn: 0,
689
+ firstWeekContainsDate: 1
690
+ }
691
+ } } }
692
+ },
693
+ y: {
694
+ position: "right",
695
+ display: true,
696
+ grid: { drawBorder: false },
697
+ ticks: {
698
+ display: true,
699
+ font: { size: 12 }
700
+ }
701
+ }
702
+ },
703
+ elements: {
704
+ line: {
705
+ tension: 0,
706
+ borderWidth: 2
707
+ },
708
+ point: {
709
+ hitRadius: 20,
710
+ radius: 0,
711
+ hoverRadius: 0,
712
+ hoverBorderWidth: 0
713
+ }
714
+ },
715
+ normalized: true,
716
+ plugins: {
717
+ tooltip: {
718
+ mode: "index",
719
+ intersect: false,
720
+ caretSize: 1,
721
+ caretPadding: 12,
722
+ displayColors: true,
723
+ backgroundColor: "#ebebeb",
724
+ padding: 8,
725
+ titleColor: "black",
726
+ bodyColor: "black",
727
+ titleFont: {
728
+ weight: "normal",
729
+ size: 12
730
+ },
731
+ bodyFont: {
732
+ size: 16,
733
+ weight: "bold"
734
+ },
735
+ callbacks: {}
736
+ },
737
+ datalabels: {
738
+ color: "#ffffff",
739
+ borderRadius: 3,
740
+ font: {
741
+ lineHeight: 1,
742
+ size: 12
743
+ },
744
+ padding: {
745
+ top: 6,
746
+ left: 5,
747
+ right: 5,
748
+ bottom: 5
749
+ },
750
+ offset: 5
751
+ }
752
+ }
753
+ }
754
+ }
963
755
  };
964
756
  const TEST_CHART_ANNOTATIONS_CONFIG = {
965
- line: {
966
- borderDash: [6, 3],
967
- },
968
- ellipse: {
969
- borderDash: [3, 6],
970
- },
971
- box: {},
972
- point: {
973
- backgroundColor: 'initial',
974
- },
757
+ line: { borderDash: [6, 3] },
758
+ ellipse: { borderDash: [3, 6] },
759
+ box: {},
760
+ point: { backgroundColor: "initial" }
761
+ };
762
+ var BaseChartComponent = class BaseChartComponent {
763
+ set height(value) {
764
+ this._height = typeof value === "number" ? `${value}px` : value;
765
+ }
766
+ constructor(chartJSService) {
767
+ this.chartJSService = chartJSService;
768
+ this.chartHasBeenRendered = false;
769
+ }
770
+ ngAfterViewInit() {
771
+ const canvasElement = this.canvasElement.nativeElement;
772
+ this.whenElementHasHeightAndWidth(canvasElement).then(() => this.renderChart());
773
+ }
774
+ whenElementHasHeightAndWidth(element) {
775
+ const rectIs2D = ({ width, height }) => height > 0 && width > 0;
776
+ return new Promise((resolve) => {
777
+ const initialClientRect = element.getBoundingClientRect();
778
+ if (rectIs2D(initialClientRect)) resolve();
779
+ const resizeObserver = new ResizeObserverFactory().create(([resizeObserverEntry]) => {
780
+ if (rectIs2D(resizeObserverEntry.contentRect)) {
781
+ resizeObserver.unobserve(element);
782
+ resolve();
783
+ }
784
+ });
785
+ resizeObserver.observe(element);
786
+ });
787
+ }
788
+ ngOnChanges(simpleChanges) {
789
+ if (this.chartHasBeenRendered) {
790
+ let shouldRedrawChart = false;
791
+ const keyUpdateFnPairs = {
792
+ data: () => this.updateData(),
793
+ labels: () => this.updateLabels(),
794
+ type: () => this.updateType(),
795
+ customOptions: () => this.updateCustomOptions(),
796
+ annotations: () => this.updateAnnotations(),
797
+ highlightedElements: () => this.updateHighlightedElements()
798
+ };
799
+ Object.entries(simpleChanges).forEach(([key]) => {
800
+ if (simpleChanges[key].firstChange || !keyUpdateFnPairs[key]) return;
801
+ shouldRedrawChart = true;
802
+ keyUpdateFnPairs[key]();
803
+ });
804
+ if (shouldRedrawChart) this.redrawChart();
805
+ }
806
+ }
807
+ renderChart(additionalArgs) {
808
+ this.chartHasBeenRendered = true;
809
+ this.chartJSService.renderChart({
810
+ targetElement: this.canvasElement,
811
+ type: this.type,
812
+ data: this.data,
813
+ labels: this.labels,
814
+ customOptions: this.customOptions,
815
+ annotations: this.annotations,
816
+ highlightedElements: this.highlightedElements,
817
+ ...additionalArgs
818
+ });
819
+ }
820
+ updateData() {
821
+ this.chartJSService.updateData(this.data);
822
+ }
823
+ updateLabels() {
824
+ this.chartJSService.updateLabels(this.labels);
825
+ }
826
+ updateType() {
827
+ this.chartJSService.updateType(this.type, this.customOptions);
828
+ }
829
+ updateCustomOptions() {
830
+ this.chartJSService.updateOptions(this.customOptions, this.type);
831
+ }
832
+ updateAnnotations() {
833
+ this.chartJSService.updateAnnotations(this.annotations);
834
+ }
835
+ updateHighlightedElements() {
836
+ this.chartJSService.updateHighlightedElements(this.highlightedElements);
837
+ }
838
+ redrawChart() {
839
+ this.chartJSService.redrawChart();
840
+ }
841
+ ngOnDestroy() {
842
+ this.chartJSService.destroyChart();
843
+ }
844
+ static {
845
+ this.ɵfac = i0.ɵɵngDeclareFactory({
846
+ minVersion: "12.0.0",
847
+ version: "22.2.2",
848
+ ngImport: i0,
849
+ type: BaseChartComponent,
850
+ deps: [{ token: ChartJSService }],
851
+ target: i0.ɵɵFactoryTarget.Component
852
+ });
853
+ }
854
+ static {
855
+ this.ɵcmp = i0.ɵɵngDeclareComponent({
856
+ minVersion: "14.0.0",
857
+ version: "22.2.2",
858
+ type: BaseChartComponent,
859
+ isStandalone: true,
860
+ selector: "kirby-base-chart",
861
+ inputs: {
862
+ type: "type",
863
+ data: "data",
864
+ labels: "labels",
865
+ customOptions: "customOptions",
866
+ annotations: "annotations",
867
+ highlightedElements: "highlightedElements",
868
+ height: "height"
869
+ },
870
+ host: { properties: { "style.--kirby-chart-height": "this._height" } },
871
+ viewQueries: [{
872
+ propertyName: "canvasElement",
873
+ first: true,
874
+ predicate: ["chartCanvas"],
875
+ descendants: true
876
+ }],
877
+ usesOnChanges: true,
878
+ ngImport: i0,
879
+ template: "<div class=\"chart-container\">\n <canvas #chartCanvas>\n <!-- Slotted content makes it possible to insert fallback content for screen readers \n https://www.chartjs.org/docs/latest/general/accessibility.html-->\n <ng-content></ng-content>\n </canvas>\n</div>\n",
880
+ styles: [":host div{height:var(--kirby-chart-height, 300px);position:relative}\n"],
881
+ changeDetection: i0.ChangeDetectionStrategy.Eager
882
+ });
883
+ }
884
+ };
885
+ i0.ɵɵngDeclareClassMetadata({
886
+ minVersion: "12.0.0",
887
+ version: "22.2.2",
888
+ ngImport: i0,
889
+ type: BaseChartComponent,
890
+ decorators: [{
891
+ type: Component,
892
+ args: [{
893
+ selector: "kirby-base-chart",
894
+ changeDetection: ChangeDetectionStrategy.Eager,
895
+ template: "<div class=\"chart-container\">\n <canvas #chartCanvas>\n <!-- Slotted content makes it possible to insert fallback content for screen readers \n https://www.chartjs.org/docs/latest/general/accessibility.html-->\n <ng-content></ng-content>\n </canvas>\n</div>\n",
896
+ styles: [":host div{height:var(--kirby-chart-height, 300px);position:relative}\n"]
897
+ }]
898
+ }],
899
+ ctorParameters: () => [{ type: ChartJSService }],
900
+ propDecorators: {
901
+ type: [{ type: Input }],
902
+ data: [{ type: Input }],
903
+ labels: [{ type: Input }],
904
+ customOptions: [{ type: Input }],
905
+ annotations: [{ type: Input }],
906
+ highlightedElements: [{ type: Input }],
907
+ _height: [{
908
+ type: HostBinding,
909
+ args: ["style.--kirby-chart-height"]
910
+ }],
911
+ height: [{ type: Input }],
912
+ canvasElement: [{
913
+ type: ViewChild,
914
+ args: ["chartCanvas"]
915
+ }]
916
+ }
917
+ });
918
+ var ChartComponent = class ChartComponent extends BaseChartComponent {
919
+ constructor() {
920
+ super(...arguments);
921
+ this.type = "column";
922
+ }
923
+ static {
924
+ this.ɵfac = i0.ɵɵngDeclareFactory({
925
+ minVersion: "12.0.0",
926
+ version: "22.2.2",
927
+ ngImport: i0,
928
+ type: ChartComponent,
929
+ deps: null,
930
+ target: i0.ɵɵFactoryTarget.Component
931
+ });
932
+ }
933
+ static {
934
+ this.ɵcmp = i0.ɵɵngDeclareComponent({
935
+ minVersion: "14.0.0",
936
+ version: "22.2.2",
937
+ type: ChartComponent,
938
+ isStandalone: true,
939
+ selector: "kirby-chart",
940
+ inputs: { type: "type" },
941
+ providers: [ChartJSService],
942
+ usesInheritance: true,
943
+ ngImport: i0,
944
+ template: "<div class=\"chart-container\">\n <canvas #chartCanvas>\n <!-- Slotted content makes it possible to insert fallback content for screen readers \n https://www.chartjs.org/docs/latest/general/accessibility.html-->\n <ng-content></ng-content>\n </canvas>\n</div>\n",
945
+ styles: [":host div{height:var(--kirby-chart-height, 300px);position:relative}\n"],
946
+ changeDetection: i0.ChangeDetectionStrategy.Eager
947
+ });
948
+ }
949
+ };
950
+ i0.ɵɵngDeclareClassMetadata({
951
+ minVersion: "12.0.0",
952
+ version: "22.2.2",
953
+ ngImport: i0,
954
+ type: ChartComponent,
955
+ decorators: [{
956
+ type: Component,
957
+ args: [{
958
+ selector: "kirby-chart",
959
+ providers: [ChartJSService],
960
+ changeDetection: ChangeDetectionStrategy.Eager,
961
+ template: "<div class=\"chart-container\">\n <canvas #chartCanvas>\n <!-- Slotted content makes it possible to insert fallback content for screen readers \n https://www.chartjs.org/docs/latest/general/accessibility.html-->\n <ng-content></ng-content>\n </canvas>\n</div>\n",
962
+ styles: [":host div{height:var(--kirby-chart-height, 300px);position:relative}\n"]
963
+ }]
964
+ }],
965
+ propDecorators: { type: [{ type: Input }] }
966
+ });
967
+ var StockChartJSService = class StockChartJSService extends ChartJSService {
968
+ constructor() {
969
+ super(...arguments);
970
+ this.chartType = "stock";
971
+ }
972
+ static {
973
+ this.STOCK_CHART_LOCALE_DEFAULT = "en-US";
974
+ }
975
+ renderChart(args) {
976
+ const { dataLabelOptions, ...superArgs } = args;
977
+ this.dataLabelOptions = dataLabelOptions || null;
978
+ super.renderChart(superArgs);
979
+ }
980
+ get locale() {
981
+ return this.dataLabelOptions?.locale || StockChartJSService.STOCK_CHART_LOCALE_DEFAULT;
982
+ }
983
+ getDefaultLabels(datasets) {
984
+ return datasets.reduce((previousDataset, currentDataset) => previousDataset.data.length > currentDataset.data.length ? previousDataset : currentDataset).data.map((point) => toDate(point.x).toLocaleDateString(this.locale, {
985
+ month: "short",
986
+ day: "numeric"
987
+ }));
988
+ }
989
+ createOptionsObject(args) {
990
+ const superOptions = super.createOptionsObject(args);
991
+ const stockOptions = this.chartConfigService.getStockChartOptions(this.dataLabelOptions, this.locale);
992
+ return mergeDeepAll(stockOptions, superOptions);
993
+ }
994
+ createDatasets(data) {
995
+ let datasets = super.createDatasets(data);
996
+ if (this.dataLabelOptions?.showCurrent || this.dataLabelOptions?.showMax || this.dataLabelOptions?.showMin) datasets = this.addDataLabelsData(datasets);
997
+ return datasets.map((dataset) => ({
998
+ ...dataset,
999
+ kirbyOptions: {
1000
+ ...dataset.kirbyOptions,
1001
+ isStockChart: true
1002
+ }
1003
+ }));
1004
+ }
1005
+ addDataLabelsData(data) {
1006
+ const decorateDataPoint = (set, axis, direction, position) => {
1007
+ const { value, pointer } = this.locateValueIndexInDataset(set, axis, direction);
1008
+ set.data[pointer] = {
1009
+ ...set.data[pointer],
1010
+ datalabel: {
1011
+ value: value + (this.dataLabelOptions.valueSuffix || ""),
1012
+ position
1013
+ }
1014
+ };
1015
+ };
1016
+ data.map((set) => {
1017
+ if (this.dataLabelOptions.showMin) decorateDataPoint(set, "y", "low", "bottom");
1018
+ if (this.dataLabelOptions.showMax) decorateDataPoint(set, "y", "high", "top");
1019
+ if (this.dataLabelOptions.showCurrent) decorateDataPoint(set, "x", "high", "right");
1020
+ });
1021
+ return data;
1022
+ }
1023
+ locateValueIndexInDataset(dataset, axis, direction) {
1024
+ let pointer;
1025
+ let value;
1026
+ dataset.data.forEach((datapoint, index) => {
1027
+ if (direction == "low" && (!value || datapoint[axis] < value)) {
1028
+ value = datapoint["y"];
1029
+ pointer = index;
1030
+ }
1031
+ if (direction == "high" && (!value || datapoint[axis] > value)) {
1032
+ value = datapoint["y"];
1033
+ pointer = index;
1034
+ }
1035
+ });
1036
+ return {
1037
+ value,
1038
+ pointer
1039
+ };
1040
+ }
1041
+ static {
1042
+ this.ɵfac = i0.ɵɵngDeclareFactory({
1043
+ minVersion: "12.0.0",
1044
+ version: "22.2.2",
1045
+ ngImport: i0,
1046
+ type: StockChartJSService,
1047
+ deps: null,
1048
+ target: i0.ɵɵFactoryTarget.Injectable
1049
+ });
1050
+ }
1051
+ static {
1052
+ this.ɵprov = i0.ɵɵngDeclareInjectable({
1053
+ minVersion: "12.0.0",
1054
+ version: "22.2.2",
1055
+ ngImport: i0,
1056
+ type: StockChartJSService
1057
+ });
1058
+ }
1059
+ };
1060
+ i0.ɵɵngDeclareClassMetadata({
1061
+ minVersion: "12.0.0",
1062
+ version: "22.2.2",
1063
+ ngImport: i0,
1064
+ type: StockChartJSService,
1065
+ decorators: [{ type: Injectable }]
1066
+ });
1067
+ var StockChartComponent = class StockChartComponent extends BaseChartComponent {
1068
+ constructor() {
1069
+ super(...arguments);
1070
+ this.type = "stock";
1071
+ }
1072
+ renderChart() {
1073
+ super.renderChart({ dataLabelOptions: this.dataLabelOptions });
1074
+ }
1075
+ static {
1076
+ this.ɵfac = i0.ɵɵngDeclareFactory({
1077
+ minVersion: "12.0.0",
1078
+ version: "22.2.2",
1079
+ ngImport: i0,
1080
+ type: StockChartComponent,
1081
+ deps: null,
1082
+ target: i0.ɵɵFactoryTarget.Component
1083
+ });
1084
+ }
1085
+ static {
1086
+ this.ɵcmp = i0.ɵɵngDeclareComponent({
1087
+ minVersion: "14.0.0",
1088
+ version: "22.2.2",
1089
+ type: StockChartComponent,
1090
+ isStandalone: true,
1091
+ selector: "kirby-stock-chart",
1092
+ inputs: { dataLabelOptions: "dataLabelOptions" },
1093
+ providers: [{
1094
+ provide: ChartJSService,
1095
+ useClass: StockChartJSService
1096
+ }, ChartConfigService],
1097
+ usesInheritance: true,
1098
+ ngImport: i0,
1099
+ template: "<div class=\"chart-container\">\n <canvas #chartCanvas>\n <!-- Slotted content makes it possible to insert fallback content for screen readers \n https://www.chartjs.org/docs/latest/general/accessibility.html-->\n <ng-content></ng-content>\n </canvas>\n</div>\n",
1100
+ styles: [":host div{height:var(--kirby-chart-height, 300px);position:relative}\n"],
1101
+ changeDetection: i0.ChangeDetectionStrategy.Eager
1102
+ });
1103
+ }
1104
+ };
1105
+ i0.ɵɵngDeclareClassMetadata({
1106
+ minVersion: "12.0.0",
1107
+ version: "22.2.2",
1108
+ ngImport: i0,
1109
+ type: StockChartComponent,
1110
+ decorators: [{
1111
+ type: Component,
1112
+ args: [{
1113
+ selector: "kirby-stock-chart",
1114
+ providers: [{
1115
+ provide: ChartJSService,
1116
+ useClass: StockChartJSService
1117
+ }, ChartConfigService],
1118
+ changeDetection: ChangeDetectionStrategy.Eager,
1119
+ template: "<div class=\"chart-container\">\n <canvas #chartCanvas>\n <!-- Slotted content makes it possible to insert fallback content for screen readers \n https://www.chartjs.org/docs/latest/general/accessibility.html-->\n <ng-content></ng-content>\n </canvas>\n</div>\n",
1120
+ styles: [":host div{height:var(--kirby-chart-height, 300px);position:relative}\n"]
1121
+ }]
1122
+ }],
1123
+ propDecorators: { dataLabelOptions: [{ type: Input }] }
1124
+ });
1125
+ var ChartsModule = class ChartsModule {
1126
+ static {
1127
+ this.ɵfac = i0.ɵɵngDeclareFactory({
1128
+ minVersion: "12.0.0",
1129
+ version: "22.2.2",
1130
+ ngImport: i0,
1131
+ type: ChartsModule,
1132
+ deps: [],
1133
+ target: i0.ɵɵFactoryTarget.NgModule
1134
+ });
1135
+ }
1136
+ static {
1137
+ this.ɵmod = i0.ɵɵngDeclareNgModule({
1138
+ minVersion: "14.0.0",
1139
+ version: "22.2.2",
1140
+ ngImport: i0,
1141
+ type: ChartsModule,
1142
+ imports: [ChartComponent, StockChartComponent],
1143
+ exports: [ChartComponent, StockChartComponent]
1144
+ });
1145
+ }
1146
+ static {
1147
+ this.ɵinj = i0.ɵɵngDeclareInjector({
1148
+ minVersion: "12.0.0",
1149
+ version: "22.2.2",
1150
+ ngImport: i0,
1151
+ type: ChartsModule,
1152
+ providers: [ChartConfigService]
1153
+ });
1154
+ }
1155
+ };
1156
+ i0.ɵɵngDeclareClassMetadata({
1157
+ minVersion: "12.0.0",
1158
+ version: "22.2.2",
1159
+ ngImport: i0,
1160
+ type: ChartsModule,
1161
+ decorators: [{
1162
+ type: NgModule,
1163
+ args: [{
1164
+ imports: [ChartComponent, StockChartComponent],
1165
+ exports: [ChartComponent, StockChartComponent],
1166
+ providers: [ChartConfigService]
1167
+ }]
1168
+ }]
1169
+ });
1170
+ var ChartBaseConfig = class {
1171
+ static {
1172
+ this.registerPlugins = () => {};
1173
+ }
975
1174
  };
976
-
977
- class BaseChartComponent {
978
- set height(value) {
979
- this._height = typeof value === 'number' ? `${value}px` : value;
980
- }
981
- constructor(chartJSService) {
982
- this.chartJSService = chartJSService;
983
- this.chartHasBeenRendered = false;
984
- }
985
- ngAfterViewInit() {
986
- /*
987
- A chart is not rendered until it has both a height and a width.
988
- If ChartComponent is slotted in an ionic component it will
989
- not have any height or width on afterViewInit. This will cause
990
- the animation to not be played on first draw.
991
- */
992
- const canvasElement = this.canvasElement.nativeElement;
993
- this.whenElementHasHeightAndWidth(canvasElement).then(() => this.renderChart());
994
- }
995
- whenElementHasHeightAndWidth(element) {
996
- const rectIs2D = ({ width, height }) => height > 0 && width > 0;
997
- return new Promise((resolve) => {
998
- const initialClientRect = element.getBoundingClientRect();
999
- if (rectIs2D(initialClientRect))
1000
- resolve();
1001
- const resizeObserver = new ResizeObserverFactory().create(([resizeObserverEntry]) => {
1002
- if (rectIs2D(resizeObserverEntry.contentRect)) {
1003
- resizeObserver.unobserve(element);
1004
- resolve();
1005
- }
1006
- });
1007
- resizeObserver.observe(element);
1008
- });
1009
- }
1010
- ngOnChanges(simpleChanges) {
1011
- if (this.chartHasBeenRendered) {
1012
- let shouldRedrawChart = false;
1013
- const keyUpdateFnPairs = {
1014
- data: () => this.updateData(),
1015
- labels: () => this.updateLabels(),
1016
- type: () => this.updateType(),
1017
- customOptions: () => this.updateCustomOptions(),
1018
- annotations: () => this.updateAnnotations(),
1019
- highlightedElements: () => this.updateHighlightedElements(),
1020
- };
1021
- Object.entries(simpleChanges).forEach(([key]) => {
1022
- if (simpleChanges[key].firstChange || !keyUpdateFnPairs[key])
1023
- return;
1024
- shouldRedrawChart = true;
1025
- keyUpdateFnPairs[key]();
1026
- });
1027
- if (shouldRedrawChart)
1028
- this.redrawChart();
1029
- }
1030
- }
1031
- renderChart(additionalArgs) {
1032
- this.chartHasBeenRendered = true;
1033
- this.chartJSService.renderChart({
1034
- targetElement: this.canvasElement,
1035
- type: this.type,
1036
- data: this.data,
1037
- labels: this.labels,
1038
- customOptions: this.customOptions,
1039
- annotations: this.annotations,
1040
- highlightedElements: this.highlightedElements,
1041
- ...additionalArgs,
1042
- });
1043
- }
1044
- updateData() {
1045
- this.chartJSService.updateData(this.data);
1046
- }
1047
- updateLabels() {
1048
- this.chartJSService.updateLabels(this.labels);
1049
- }
1050
- updateType() {
1051
- this.chartJSService.updateType(this.type, this.customOptions);
1052
- }
1053
- updateCustomOptions() {
1054
- this.chartJSService.updateOptions(this.customOptions, this.type);
1055
- }
1056
- updateAnnotations() {
1057
- this.chartJSService.updateAnnotations(this.annotations);
1058
- }
1059
- updateHighlightedElements() {
1060
- this.chartJSService.updateHighlightedElements(this.highlightedElements);
1061
- }
1062
- redrawChart() {
1063
- this.chartJSService.redrawChart();
1064
- }
1065
- ngOnDestroy() {
1066
- this.chartJSService.destroyChart();
1067
- }
1068
- /** @nocollapse */ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.23", ngImport: i0, type: BaseChartComponent, deps: [{ token: ChartJSService }], target: i0.ɵɵFactoryTarget.Component }); }
1069
- /** @nocollapse */ static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "21.2.23", type: BaseChartComponent, isStandalone: true, selector: "kirby-base-chart", inputs: { type: "type", data: "data", labels: "labels", customOptions: "customOptions", annotations: "annotations", highlightedElements: "highlightedElements", height: "height" }, host: { properties: { "style.--kirby-chart-height": "this._height" } }, viewQueries: [{ propertyName: "canvasElement", first: true, predicate: ["chartCanvas"], descendants: true }], usesOnChanges: true, ngImport: i0, template: "<div class=\"chart-container\">\n <canvas #chartCanvas>\n <!-- Slotted content makes it possible to insert fallback content for screen readers \n https://www.chartjs.org/docs/latest/general/accessibility.html-->\n <ng-content></ng-content>\n </canvas>\n</div>\n", styles: [":host div{height:var(--kirby-chart-height, 300px);position:relative}\n"] }); }
1070
- }
1071
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.23", ngImport: i0, type: BaseChartComponent, decorators: [{
1072
- type: Component,
1073
- args: [{ selector: 'kirby-base-chart', template: "<div class=\"chart-container\">\n <canvas #chartCanvas>\n <!-- Slotted content makes it possible to insert fallback content for screen readers \n https://www.chartjs.org/docs/latest/general/accessibility.html-->\n <ng-content></ng-content>\n </canvas>\n</div>\n", styles: [":host div{height:var(--kirby-chart-height, 300px);position:relative}\n"] }]
1074
- }], ctorParameters: () => [{ type: ChartJSService }], propDecorators: { type: [{
1075
- type: Input
1076
- }], data: [{
1077
- type: Input
1078
- }], labels: [{
1079
- type: Input
1080
- }], customOptions: [{
1081
- type: Input
1082
- }], annotations: [{
1083
- type: Input
1084
- }], highlightedElements: [{
1085
- type: Input
1086
- }], _height: [{
1087
- type: HostBinding,
1088
- args: ['style.--kirby-chart-height']
1089
- }], height: [{
1090
- type: Input
1091
- }], canvasElement: [{
1092
- type: ViewChild,
1093
- args: ['chartCanvas']
1094
- }] } });
1095
-
1096
- class ChartComponent extends BaseChartComponent {
1097
- constructor() {
1098
- super(...arguments);
1099
- this.type = 'column';
1100
- }
1101
- /** @nocollapse */ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.23", ngImport: i0, type: ChartComponent, deps: null, target: i0.ɵɵFactoryTarget.Component }); }
1102
- /** @nocollapse */ static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "21.2.23", type: ChartComponent, isStandalone: true, selector: "kirby-chart", inputs: { type: "type" }, providers: [ChartJSService], usesInheritance: true, ngImport: i0, template: "<div class=\"chart-container\">\n <canvas #chartCanvas>\n <!-- Slotted content makes it possible to insert fallback content for screen readers \n https://www.chartjs.org/docs/latest/general/accessibility.html-->\n <ng-content></ng-content>\n </canvas>\n</div>\n", styles: [":host div{height:var(--kirby-chart-height, 300px);position:relative}\n"] }); }
1103
- }
1104
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.23", ngImport: i0, type: ChartComponent, decorators: [{
1105
- type: Component,
1106
- args: [{ selector: 'kirby-chart', providers: [ChartJSService], template: "<div class=\"chart-container\">\n <canvas #chartCanvas>\n <!-- Slotted content makes it possible to insert fallback content for screen readers \n https://www.chartjs.org/docs/latest/general/accessibility.html-->\n <ng-content></ng-content>\n </canvas>\n</div>\n", styles: [":host div{height:var(--kirby-chart-height, 300px);position:relative}\n"] }]
1107
- }], propDecorators: { type: [{
1108
- type: Input
1109
- }] } });
1110
-
1111
- class StockChartJSService extends ChartJSService {
1112
- constructor() {
1113
- super(...arguments);
1114
- this.chartType = 'stock';
1115
- }
1116
- static { this.STOCK_CHART_LOCALE_DEFAULT = 'en-US'; }
1117
- renderChart(args) {
1118
- const { dataLabelOptions, ...superArgs } = args;
1119
- this.dataLabelOptions = dataLabelOptions || null;
1120
- super.renderChart(superArgs);
1121
- }
1122
- get locale() {
1123
- return this.dataLabelOptions?.locale || StockChartJSService.STOCK_CHART_LOCALE_DEFAULT;
1124
- }
1125
- getDefaultLabels(datasets) {
1126
- const largestDataset = datasets.reduce((previousDataset, currentDataset) => previousDataset.data.length > currentDataset.data.length ? previousDataset : currentDataset);
1127
- return largestDataset.data.map((point) => toDate(point.x).toLocaleDateString(this.locale, {
1128
- month: 'short',
1129
- day: 'numeric',
1130
- }));
1131
- }
1132
- createOptionsObject(args) {
1133
- const superOptions = super.createOptionsObject(args);
1134
- const stockOptions = this.chartConfigService.getStockChartOptions(this.dataLabelOptions, this.locale);
1135
- return mergeDeepAll(stockOptions, superOptions);
1136
- }
1137
- createDatasets(data) {
1138
- let datasets = super.createDatasets(data);
1139
- /*
1140
- Hacky solution. Should be fixed in this issue:
1141
- https://github.com/kirbydesign/designsystem/issues/1967
1142
- */
1143
- // We need to modify the datasets in order to add datalabels.
1144
- if (this.dataLabelOptions?.showCurrent ||
1145
- this.dataLabelOptions?.showMax ||
1146
- this.dataLabelOptions?.showMin) {
1147
- datasets = this.addDataLabelsData(datasets);
1148
- }
1149
- return datasets.map((dataset) => ({
1150
- ...dataset,
1151
- kirbyOptions: { ...dataset.kirbyOptions, isStockChart: true },
1152
- }));
1153
- }
1154
- /**
1155
- * Decorate ChartDataset with properties to allow for datalabels.
1156
- *
1157
- * @param data
1158
- * @returns ChartDataset[]
1159
- */
1160
- addDataLabelsData(data) {
1161
- const decorateDataPoint = (set, axis, direction, position) => {
1162
- const { value, pointer } = this.locateValueIndexInDataset(set, axis, direction);
1163
- set.data[pointer] = {
1164
- ...set.data[pointer],
1165
- datalabel: {
1166
- value: value + (this.dataLabelOptions.valueSuffix || ''),
1167
- position,
1168
- },
1169
- };
1170
- };
1171
- data.map((set) => {
1172
- if (this.dataLabelOptions.showMin) {
1173
- decorateDataPoint(set, 'y', 'low', 'bottom');
1174
- }
1175
- if (this.dataLabelOptions.showMax) {
1176
- decorateDataPoint(set, 'y', 'high', 'top');
1177
- }
1178
- if (this.dataLabelOptions.showCurrent) {
1179
- decorateDataPoint(set, 'x', 'high', 'right');
1180
- }
1181
- });
1182
- return data;
1183
- }
1184
- locateValueIndexInDataset(dataset, axis, direction) {
1185
- let pointer;
1186
- let value;
1187
- dataset.data.forEach((datapoint, index) => {
1188
- if (direction == 'low' && (!value || datapoint[axis] < value)) {
1189
- value = datapoint['y'];
1190
- pointer = index;
1191
- }
1192
- if (direction == 'high' && (!value || datapoint[axis] > value)) {
1193
- value = datapoint['y'];
1194
- pointer = index;
1195
- }
1196
- });
1197
- return { value, pointer };
1198
- }
1199
- /** @nocollapse */ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.23", ngImport: i0, type: StockChartJSService, deps: null, target: i0.ɵɵFactoryTarget.Injectable }); }
1200
- /** @nocollapse */ static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "21.2.23", ngImport: i0, type: StockChartJSService }); }
1201
- }
1202
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.23", ngImport: i0, type: StockChartJSService, decorators: [{
1203
- type: Injectable
1204
- }] });
1205
-
1206
- class StockChartComponent extends BaseChartComponent {
1207
- constructor() {
1208
- super(...arguments);
1209
- this.type = 'stock';
1210
- }
1211
- renderChart() {
1212
- super.renderChart({ dataLabelOptions: this.dataLabelOptions });
1213
- }
1214
- /** @nocollapse */ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.23", ngImport: i0, type: StockChartComponent, deps: null, target: i0.ɵɵFactoryTarget.Component }); }
1215
- /** @nocollapse */ static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "21.2.23", type: StockChartComponent, isStandalone: true, selector: "kirby-stock-chart", inputs: { dataLabelOptions: "dataLabelOptions" }, providers: [{ provide: ChartJSService, useClass: StockChartJSService }, ChartConfigService], usesInheritance: true, ngImport: i0, template: "<div class=\"chart-container\">\n <canvas #chartCanvas>\n <!-- Slotted content makes it possible to insert fallback content for screen readers \n https://www.chartjs.org/docs/latest/general/accessibility.html-->\n <ng-content></ng-content>\n </canvas>\n</div>\n", styles: [":host div{height:var(--kirby-chart-height, 300px);position:relative}\n"] }); }
1216
- }
1217
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.23", ngImport: i0, type: StockChartComponent, decorators: [{
1218
- type: Component,
1219
- args: [{ selector: 'kirby-stock-chart', providers: [{ provide: ChartJSService, useClass: StockChartJSService }, ChartConfigService], template: "<div class=\"chart-container\">\n <canvas #chartCanvas>\n <!-- Slotted content makes it possible to insert fallback content for screen readers \n https://www.chartjs.org/docs/latest/general/accessibility.html-->\n <ng-content></ng-content>\n </canvas>\n</div>\n", styles: [":host div{height:var(--kirby-chart-height, 300px);position:relative}\n"] }]
1220
- }], propDecorators: { dataLabelOptions: [{
1221
- type: Input
1222
- }] } });
1223
-
1224
- class ChartsModule {
1225
- /** @nocollapse */ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.23", ngImport: i0, type: ChartsModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule }); }
1226
- /** @nocollapse */ static { this.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "21.2.23", ngImport: i0, type: ChartsModule, imports: [ChartComponent, StockChartComponent], exports: [ChartComponent, StockChartComponent] }); }
1227
- /** @nocollapse */ static { this.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "21.2.23", ngImport: i0, type: ChartsModule, providers: [ChartConfigService] }); }
1228
- }
1229
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.23", ngImport: i0, type: ChartsModule, decorators: [{
1230
- type: NgModule,
1231
- args: [{
1232
- imports: [ChartComponent, StockChartComponent],
1233
- exports: [ChartComponent, StockChartComponent],
1234
- providers: [ChartConfigService],
1235
- }]
1236
- }] });
1237
-
1238
- class ChartBaseConfig {
1239
- static { this.registerPlugins = () => { }; }
1240
- }
1241
-
1242
1175
  const { getThemeColorHexString: getThemeColorHexString$2 } = ColorHelper;
1243
- /**
1244
- * This class is still experimental. Feel free to use it, but please note that it is still subject to breaking changes.
1245
- */
1246
- class BarChartConfig extends ChartBaseConfig {
1247
- static { this.BAR_CHART_LOCALE_DEFAULT = 'en-US'; }
1248
- static { this.baseConfig = {
1249
- type: 'bar',
1250
- data: {
1251
- datasets: [],
1252
- },
1253
- options: {
1254
- datasets: {
1255
- bar: {
1256
- barPercentage: 0.6,
1257
- },
1258
- line: {
1259
- spanGaps: true,
1260
- },
1261
- },
1262
- indexAxis: 'x',
1263
- scales: {
1264
- y: {
1265
- grid: {
1266
- drawBorder: false,
1267
- },
1268
- },
1269
- x: {},
1270
- },
1271
- elements: {
1272
- point: {
1273
- radius: 0,
1274
- },
1275
- line: {
1276
- borderColor: getThemeColorHexString$2('medium'),
1277
- },
1278
- },
1279
- },
1280
- }; }
1281
- }
1282
-
1176
+ var BarChartConfig = class extends ChartBaseConfig {
1177
+ static {
1178
+ this.BAR_CHART_LOCALE_DEFAULT = "en-US";
1179
+ }
1180
+ static {
1181
+ this.baseConfig = {
1182
+ type: "bar",
1183
+ data: { datasets: [] },
1184
+ options: {
1185
+ datasets: {
1186
+ bar: { barPercentage: .6 },
1187
+ line: { spanGaps: true }
1188
+ },
1189
+ indexAxis: "x",
1190
+ scales: {
1191
+ y: { grid: { drawBorder: false } },
1192
+ x: {}
1193
+ },
1194
+ elements: {
1195
+ point: { radius: 0 },
1196
+ line: { borderColor: getThemeColorHexString$2("medium") }
1197
+ }
1198
+ }
1199
+ };
1200
+ }
1201
+ };
1283
1202
  const { getThemeColorHexString: getThemeColorHexString$1 } = ColorHelper;
1284
1203
  const { fontSize: fontSize$1 } = DesignTokenHelper;
1285
1204
  const getDataLabelPosition = (data, dataIndex) => {
1286
- const scatterPointDataYvalues = data.map((scatterDatapoint) => scatterDatapoint.y);
1287
- const minValue = Math.min(...scatterPointDataYvalues);
1288
- const minValueIndex = scatterPointDataYvalues.indexOf(minValue);
1289
- if (dataIndex === minValueIndex) {
1290
- return 'bottom';
1291
- }
1292
- const maxValue = Math.max(...scatterPointDataYvalues);
1293
- const maxValueIndex = scatterPointDataYvalues.indexOf(maxValue);
1294
- if (dataIndex === maxValueIndex) {
1295
- return 'top';
1296
- }
1297
- return null;
1205
+ const scatterPointDataYvalues = data.map((scatterDatapoint) => scatterDatapoint.y);
1206
+ const minValue = Math.min(...scatterPointDataYvalues);
1207
+ if (dataIndex === scatterPointDataYvalues.indexOf(minValue)) return "bottom";
1208
+ const maxValue = Math.max(...scatterPointDataYvalues);
1209
+ if (dataIndex === scatterPointDataYvalues.indexOf(maxValue)) return "top";
1210
+ return null;
1298
1211
  };
1299
1212
  const dataLabelsPluginConfig = {
1300
- backgroundColor: '#005c3c',
1301
- color: getThemeColorHexString$1('white'),
1302
- borderRadius: 3,
1303
- font: {
1304
- lineHeight: 1,
1305
- size: parseInt(fontSize$1('xs')),
1306
- },
1307
- padding: {
1308
- top: 6,
1309
- left: 5,
1310
- right: 5,
1311
- bottom: 5,
1312
- },
1313
- offset: 5,
1314
- align: (context) => getDataLabelPosition(context.dataset.data, context.dataIndex),
1315
- display: (context) => {
1316
- return showDataLabel(context);
1317
- },
1318
- formatter: (dataPoint) => dataPoint.y.toString(),
1213
+ backgroundColor: "#005c3c",
1214
+ color: getThemeColorHexString$1("white"),
1215
+ borderRadius: 3,
1216
+ font: {
1217
+ lineHeight: 1,
1218
+ size: parseInt(fontSize$1("xs"))
1219
+ },
1220
+ padding: {
1221
+ top: 6,
1222
+ left: 5,
1223
+ right: 5,
1224
+ bottom: 5
1225
+ },
1226
+ offset: 5,
1227
+ align: (context) => getDataLabelPosition(context.dataset.data, context.dataIndex),
1228
+ display: (context) => {
1229
+ return showDataLabel(context);
1230
+ },
1231
+ formatter: (dataPoint) => dataPoint.y.toString()
1319
1232
  };
1320
1233
  function showDataLabel(context) {
1321
- const data = [...context.dataset.data];
1322
- const yValues = data.map((dataPoints) => dataPoints.y);
1323
- const minValue = Math.min(...yValues);
1324
- const minValueIndex = yValues.indexOf(minValue);
1325
- const maxValue = Math.max(...yValues);
1326
- const maxValueIndex = yValues.indexOf(maxValue);
1327
- return context.dataIndex === maxValueIndex || context.dataIndex === minValueIndex;
1234
+ const yValues = [...context.dataset.data].map((dataPoints) => dataPoints.y);
1235
+ const minValue = Math.min(...yValues);
1236
+ const minValueIndex = yValues.indexOf(minValue);
1237
+ const maxValue = Math.max(...yValues);
1238
+ const maxValueIndex = yValues.indexOf(maxValue);
1239
+ return context.dataIndex === maxValueIndex || context.dataIndex === minValueIndex;
1328
1240
  }
1329
-
1330
- const verticalLineId = 'verticalLine';
1241
+ const verticalLineId = "verticalLine";
1331
1242
  const getVerticalLinePluginConfig = {
1332
- id: verticalLineId,
1333
- drawTime: 'beforeDraw',
1334
- defaults: {
1335
- width: 1,
1336
- color: 'black',
1337
- },
1338
- afterInit: (chart) => {
1339
- chart[verticalLineId] = {
1340
- x: 0,
1341
- y: 0,
1342
- };
1343
- },
1344
- afterEvent: (chart, args) => {
1345
- const { inChartArea } = args;
1346
- const { x, y } = args.event;
1347
- chart[verticalLineId] = { x, y, draw: inChartArea };
1348
- chart.draw();
1349
- },
1350
- beforeDraw: (chart, _, options) => {
1351
- const { ctx } = chart;
1352
- const { top, bottom } = chart.chartArea;
1353
- const { x, draw } = chart[verticalLineId];
1354
- if (!draw)
1355
- return;
1356
- ctx.save();
1357
- ctx.beginPath();
1358
- ctx.lineWidth = options.width;
1359
- ctx.strokeStyle = options.color;
1360
- ctx.moveTo(x, bottom);
1361
- ctx.lineTo(x, top);
1362
- ctx.stroke();
1363
- ctx.restore();
1364
- },
1243
+ id: verticalLineId,
1244
+ drawTime: "beforeDraw",
1245
+ defaults: {
1246
+ width: 1,
1247
+ color: "black"
1248
+ },
1249
+ afterInit: (chart) => {
1250
+ chart[verticalLineId] = {
1251
+ x: 0,
1252
+ y: 0
1253
+ };
1254
+ },
1255
+ afterEvent: (chart, args) => {
1256
+ const { inChartArea } = args;
1257
+ const { x, y } = args.event;
1258
+ chart[verticalLineId] = {
1259
+ x,
1260
+ y,
1261
+ draw: inChartArea
1262
+ };
1263
+ chart.draw();
1264
+ },
1265
+ beforeDraw: (chart, _, options) => {
1266
+ const { ctx } = chart;
1267
+ const { top, bottom } = chart.chartArea;
1268
+ const { x, draw } = chart[verticalLineId];
1269
+ if (!draw) return;
1270
+ ctx.save();
1271
+ ctx.beginPath();
1272
+ ctx.lineWidth = options.width;
1273
+ ctx.strokeStyle = options.color;
1274
+ ctx.moveTo(x, bottom);
1275
+ ctx.lineTo(x, top);
1276
+ ctx.stroke();
1277
+ ctx.restore();
1278
+ }
1365
1279
  };
1366
-
1367
1280
  const { getThemeColorHexString, getThemeColorRgbString } = ColorHelper;
1368
1281
  const { fontSize } = DesignTokenHelper;
1369
- /**
1370
- * This class is still experimental. Feel free to use it, but please note that it is still subject to breaking changes.
1371
- */
1372
- class StockChartConfig extends ChartBaseConfig {
1373
- static { this.STOCK_CHART_LOCALE_DEFAULT = 'en-US'; }
1374
- static { this.scales = [CategoryScale, LinearScale, TimeScale]; }
1375
- static { this.elements = [BarElement, LineElement, PointElement]; }
1376
- static { this.controllers = [BarController, LineController]; }
1377
- static { this.plugins = [annotationPlugin, Filler, Tooltip]; }
1378
- static { this.registeredElements = [
1379
- ...this.scales,
1380
- ...this.controllers,
1381
- ...this.elements,
1382
- ...this.plugins,
1383
- ]; }
1384
- static { this.pluginsRegistered = false; }
1385
- static registerPlugins() {
1386
- if (StockChartConfig.pluginsRegistered) {
1387
- return;
1388
- }
1389
- this.registeredElements.forEach((scale) => {
1390
- Chart.register(scale);
1391
- });
1392
- StockChartConfig.pluginsRegistered = true;
1393
- }
1394
- static { this.baseConfig = {
1395
- type: 'line',
1396
- data: {
1397
- datasets: [],
1398
- },
1399
- options: {
1400
- responsive: true,
1401
- animation: {
1402
- duration: 0,
1403
- },
1404
- layout: {
1405
- padding: {
1406
- left: 20,
1407
- right: 20,
1408
- top: 30,
1409
- bottom: 0,
1410
- },
1411
- },
1412
- backgroundColor: getThemeColorRgbString('semi-light', 0.5),
1413
- scales: {
1414
- x: {
1415
- adapters: {
1416
- date: {
1417
- locale: StockChartConfig.STOCK_CHART_LOCALE_DEFAULT,
1418
- },
1419
- },
1420
- grid: {
1421
- lineWidth: 0,
1422
- },
1423
- ticks: {
1424
- maxRotation: 0,
1425
- autoSkipPadding: 120,
1426
- font: {
1427
- size: parseInt(fontSize('xs')),
1428
- },
1429
- callback(tickValue) {
1430
- const dateInMiliseconds = parseInt(this.getLabelForValue(parseInt(tickValue + '')));
1431
- return getChartStockShortDate(dateInMiliseconds, StockChartConfig.STOCK_CHART_LOCALE_DEFAULT);
1432
- },
1433
- },
1434
- },
1435
- y: {
1436
- position: 'right',
1437
- display: true,
1438
- grid: {
1439
- drawBorder: false,
1440
- },
1441
- ticks: {
1442
- display: true,
1443
- font: {
1444
- size: parseInt(fontSize('xs')),
1445
- },
1446
- },
1447
- },
1448
- },
1449
- elements: {
1450
- line: {
1451
- tension: 0, // Smooth curve (0 = no smoothing)
1452
- borderWidth: 2,
1453
- },
1454
- point: {
1455
- hitRadius: 20,
1456
- radius: 0,
1457
- hoverRadius: 0,
1458
- hoverBorderWidth: 0,
1459
- },
1460
- },
1461
- normalized: true,
1462
- plugins: {},
1463
- },
1464
- }; }
1465
- static { this.tooltipPlugin = {
1466
- padding: 10,
1467
- enabled: true,
1468
- mode: 'index',
1469
- intersect: false,
1470
- backgroundColor: getThemeColorHexString('semi-light'),
1471
- titleColor: getThemeColorHexString('semi-light-contrast'),
1472
- bodyColor: getThemeColorHexString('semi-light-contrast'),
1473
- caretSize: 0,
1474
- bodySpacing: 5,
1475
- titleSpacing: 5,
1476
- borderColor: 'transparent',
1477
- callbacks: {
1478
- title: (toolTipItem) => {
1479
- const dateInMiliseconds = parseInt(toolTipItem[0].label); // TODO: Right now we use index === 0. I expect multiple datasets will change this
1480
- return getChartStockShortDateTime(dateInMiliseconds, StockChartConfig.STOCK_CHART_LOCALE_DEFAULT);
1481
- },
1482
- label: (context) => context.parsed.y.toString(),
1483
- labelColor: (tooltipItem) => {
1484
- return {
1485
- backgroundColor: tooltipItem.dataset.borderColor,
1486
- borderColor: getThemeColorHexString('semi-light'),
1487
- borderWidth: 2, // This value must be exactly 2. If it is less, a white "border" will appear, if greater than, a shadow around the box will be shown.
1488
- // An issue has been created, requesting a test to check this value doesn´t change: https://github.com/kirbydesign/designsystem/issues/2578
1489
- };
1490
- },
1491
- },
1492
- }; }
1493
- static { this.dataLabelsPluginConfig = dataLabelsPluginConfig; }
1494
- static { this.verticalLinePluginConfig = getVerticalLinePluginConfig; }
1495
- static { this.getDataLabelPosition = getDataLabelPosition; }
1496
- }
1282
+ var StockChartConfig = class StockChartConfig extends ChartBaseConfig {
1283
+ static {
1284
+ this.STOCK_CHART_LOCALE_DEFAULT = "en-US";
1285
+ }
1286
+ static {
1287
+ this.scales = [
1288
+ CategoryScale,
1289
+ LinearScale,
1290
+ TimeScale
1291
+ ];
1292
+ }
1293
+ static {
1294
+ this.elements = [
1295
+ BarElement,
1296
+ LineElement,
1297
+ PointElement
1298
+ ];
1299
+ }
1300
+ static {
1301
+ this.controllers = [BarController, LineController];
1302
+ }
1303
+ static {
1304
+ this.plugins = [
1305
+ annotationPlugin,
1306
+ Filler,
1307
+ Tooltip
1308
+ ];
1309
+ }
1310
+ static {
1311
+ this.registeredElements = [
1312
+ ...this.scales,
1313
+ ...this.controllers,
1314
+ ...this.elements,
1315
+ ...this.plugins
1316
+ ];
1317
+ }
1318
+ static {
1319
+ this.pluginsRegistered = false;
1320
+ }
1321
+ static registerPlugins() {
1322
+ if (StockChartConfig.pluginsRegistered) return;
1323
+ this.registeredElements.forEach((scale) => {
1324
+ Chart.register(scale);
1325
+ });
1326
+ StockChartConfig.pluginsRegistered = true;
1327
+ }
1328
+ static {
1329
+ this.baseConfig = {
1330
+ type: "line",
1331
+ data: { datasets: [] },
1332
+ options: {
1333
+ responsive: true,
1334
+ animation: { duration: 0 },
1335
+ layout: { padding: {
1336
+ left: 20,
1337
+ right: 20,
1338
+ top: 30,
1339
+ bottom: 0
1340
+ } },
1341
+ backgroundColor: getThemeColorRgbString("semi-light", .5),
1342
+ scales: {
1343
+ x: {
1344
+ adapters: { date: { locale: StockChartConfig.STOCK_CHART_LOCALE_DEFAULT } },
1345
+ grid: { lineWidth: 0 },
1346
+ ticks: {
1347
+ maxRotation: 0,
1348
+ autoSkipPadding: 120,
1349
+ font: { size: parseInt(fontSize("xs")) },
1350
+ callback(tickValue) {
1351
+ const dateInMiliseconds = parseInt(this.getLabelForValue(parseInt(tickValue + "")));
1352
+ return getChartStockShortDate(dateInMiliseconds, StockChartConfig.STOCK_CHART_LOCALE_DEFAULT);
1353
+ }
1354
+ }
1355
+ },
1356
+ y: {
1357
+ position: "right",
1358
+ display: true,
1359
+ grid: { drawBorder: false },
1360
+ ticks: {
1361
+ display: true,
1362
+ font: { size: parseInt(fontSize("xs")) }
1363
+ }
1364
+ }
1365
+ },
1366
+ elements: {
1367
+ line: {
1368
+ tension: 0,
1369
+ borderWidth: 2
1370
+ },
1371
+ point: {
1372
+ hitRadius: 20,
1373
+ radius: 0,
1374
+ hoverRadius: 0,
1375
+ hoverBorderWidth: 0
1376
+ }
1377
+ },
1378
+ normalized: true,
1379
+ plugins: {}
1380
+ }
1381
+ };
1382
+ }
1383
+ static {
1384
+ this.tooltipPlugin = {
1385
+ padding: 10,
1386
+ enabled: true,
1387
+ mode: "index",
1388
+ intersect: false,
1389
+ backgroundColor: getThemeColorHexString("semi-light"),
1390
+ titleColor: getThemeColorHexString("semi-light-contrast"),
1391
+ bodyColor: getThemeColorHexString("semi-light-contrast"),
1392
+ caretSize: 0,
1393
+ bodySpacing: 5,
1394
+ titleSpacing: 5,
1395
+ borderColor: "transparent",
1396
+ callbacks: {
1397
+ title: (toolTipItem) => {
1398
+ const dateInMiliseconds = parseInt(toolTipItem[0].label);
1399
+ return getChartStockShortDateTime(dateInMiliseconds, StockChartConfig.STOCK_CHART_LOCALE_DEFAULT);
1400
+ },
1401
+ label: (context) => context.parsed.y.toString(),
1402
+ labelColor: (tooltipItem) => {
1403
+ return {
1404
+ backgroundColor: tooltipItem.dataset.borderColor,
1405
+ borderColor: getThemeColorHexString("semi-light"),
1406
+ borderWidth: 2
1407
+ };
1408
+ }
1409
+ }
1410
+ };
1411
+ }
1412
+ static {
1413
+ this.dataLabelsPluginConfig = dataLabelsPluginConfig;
1414
+ }
1415
+ static {
1416
+ this.verticalLinePluginConfig = getVerticalLinePluginConfig;
1417
+ }
1418
+ static {
1419
+ this.getDataLabelPosition = getDataLabelPosition;
1420
+ }
1421
+ };
1497
1422
  const getChartStockShortDate = (dateInMiliseconds, locale) => {
1498
- const newDate = new Date(dateInMiliseconds);
1499
- return newDate.toLocaleDateString(locale, {
1500
- day: 'numeric',
1501
- month: 'short',
1502
- });
1423
+ return new Date(dateInMiliseconds).toLocaleDateString(locale, {
1424
+ day: "numeric",
1425
+ month: "short"
1426
+ });
1503
1427
  };
1504
1428
  const getChartStockShortDateTime = (dateInMiliseconds, locale) => {
1505
- const newDate = new Date(dateInMiliseconds);
1506
- return newDate.toLocaleDateString(locale, {
1507
- day: 'numeric',
1508
- month: 'short',
1509
- hour: '2-digit',
1510
- minute: '2-digit',
1511
- });
1429
+ return new Date(dateInMiliseconds).toLocaleDateString(locale, {
1430
+ day: "numeric",
1431
+ month: "short",
1432
+ hour: "2-digit",
1433
+ minute: "2-digit"
1434
+ });
1512
1435
  };
1513
-
1514
- /**
1515
- * Generated bundle index. Do not edit.
1516
- */
1517
-
1518
1436
  export { BarChartConfig, BaseChartComponent, ChartComponent, ChartConfigService, ChartJSService, ChartsModule, StockChartComponent, StockChartConfig, TEST_CHART_ANNOTATIONS_CONFIG, TEST_CHART_TYPES_CONFIG, isNumberArray };
1519
- //# sourceMappingURL=kirbydesign-designsystem-chart.mjs.map
1437
+
1438
+ //# sourceMappingURL=kirbydesign-designsystem-chart.mjs.map