@refinitiv-ui/elements 6.9.0-next.0 → 7.0.0-next.1

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 (224) hide show
  1. package/CHANGELOG.md +11 -0
  2. package/cli.mjs +21 -0
  3. package/lib/accordion/index.js +1 -10
  4. package/lib/appstate-bar/index.d.ts +1 -7
  5. package/lib/appstate-bar/index.js +0 -12
  6. package/lib/autosuggest/index.d.ts +1 -24
  7. package/lib/autosuggest/index.js +34 -109
  8. package/lib/autosuggest/themes/halo/dark/index.js +1 -1
  9. package/lib/autosuggest/themes/halo/light/index.js +1 -1
  10. package/lib/autosuggest/themes/solar/charcoal/index.js +1 -1
  11. package/lib/autosuggest/themes/solar/pearl/index.js +1 -1
  12. package/lib/button/themes/halo/dark/index.js +1 -1
  13. package/lib/button/themes/halo/light/index.js +1 -1
  14. package/lib/button/themes/solar/charcoal/index.js +1 -1
  15. package/lib/button/themes/solar/pearl/index.js +1 -1
  16. package/lib/button-bar/index.js +0 -5
  17. package/lib/calendar/index.js +9 -19
  18. package/lib/calendar/themes/halo/dark/index.js +1 -1
  19. package/lib/calendar/themes/halo/light/index.js +1 -1
  20. package/lib/calendar/themes/solar/charcoal/index.js +1 -1
  21. package/lib/calendar/themes/solar/pearl/index.js +1 -1
  22. package/lib/calendar/utils.d.ts +1 -12
  23. package/lib/calendar/utils.js +2 -20
  24. package/lib/canvas/index.js +2 -1
  25. package/lib/card/themes/halo/dark/index.js +1 -1
  26. package/lib/card/themes/halo/light/index.js +1 -1
  27. package/lib/card/themes/solar/charcoal/index.js +1 -1
  28. package/lib/card/themes/solar/pearl/index.js +1 -1
  29. package/lib/chart/bare.d.ts +1 -0
  30. package/lib/chart/bare.js +1 -0
  31. package/lib/chart/custom-elements.json +7 -6
  32. package/lib/chart/custom-elements.md +9 -9
  33. package/lib/chart/elements/chart.d.ts +182 -0
  34. package/lib/chart/elements/chart.js +509 -0
  35. package/lib/chart/helpers/index.d.ts +1 -1
  36. package/lib/chart/helpers/index.js +1 -1
  37. package/lib/chart/helpers/merge.d.ts +1 -1
  38. package/lib/chart/helpers/merge.js +1 -1
  39. package/lib/chart/helpers/types.d.ts +0 -65
  40. package/lib/chart/index.d.ts +1 -192
  41. package/lib/chart/index.js +5 -485
  42. package/lib/chart/plugins/doughnut-center-label.d.ts +22 -3
  43. package/lib/chart/plugins/doughnut-center-label.js +62 -51
  44. package/lib/chart/plugins/index.d.ts +1 -0
  45. package/lib/chart/plugins/index.js +1 -0
  46. package/lib/checkbox/index.js +0 -1
  47. package/lib/checkbox/themes/halo/dark/index.js +1 -1
  48. package/lib/checkbox/themes/halo/light/index.js +1 -1
  49. package/lib/checkbox/themes/solar/charcoal/index.js +1 -1
  50. package/lib/checkbox/themes/solar/pearl/index.js +1 -1
  51. package/lib/clock/index.js +0 -4
  52. package/lib/clock/themes/halo/dark/index.js +1 -1
  53. package/lib/clock/themes/halo/light/index.js +1 -1
  54. package/lib/clock/themes/solar/charcoal/index.js +1 -1
  55. package/lib/clock/themes/solar/pearl/index.js +1 -1
  56. package/lib/color-dialog/index.d.ts +2 -2
  57. package/lib/color-dialog/index.js +2 -2
  58. package/lib/color-picker/index.js +0 -1
  59. package/lib/combo-box/index.js +4 -4
  60. package/lib/combo-box/themes/halo/dark/index.js +1 -1
  61. package/lib/combo-box/themes/halo/light/index.js +1 -1
  62. package/lib/combo-box/themes/solar/charcoal/index.js +1 -1
  63. package/lib/combo-box/themes/solar/pearl/index.js +1 -1
  64. package/lib/datetime-field/index.js +0 -5
  65. package/lib/datetime-picker/index.js +2 -5
  66. package/lib/dialog/custom-elements.json +1 -12
  67. package/lib/dialog/custom-elements.md +3 -4
  68. package/lib/dialog/index.d.ts +10 -42
  69. package/lib/dialog/index.js +20 -79
  70. package/lib/dialog/themes/halo/dark/index.js +1 -1
  71. package/lib/dialog/themes/halo/light/index.js +1 -1
  72. package/lib/dialog/themes/solar/charcoal/index.js +1 -1
  73. package/lib/dialog/themes/solar/pearl/index.js +1 -1
  74. package/lib/email-field/index.js +2 -1
  75. package/lib/email-field/themes/halo/dark/index.js +1 -1
  76. package/lib/email-field/themes/halo/light/index.js +1 -1
  77. package/lib/email-field/themes/solar/charcoal/index.js +1 -1
  78. package/lib/email-field/themes/solar/pearl/index.js +1 -1
  79. package/lib/flag/custom-elements.json +2 -14
  80. package/lib/flag/custom-elements.md +3 -6
  81. package/lib/flag/index.d.ts +21 -9
  82. package/lib/flag/index.js +43 -24
  83. package/lib/heatmap/helpers/color.js +2 -1
  84. package/lib/heatmap/index.js +33 -18
  85. package/lib/icon/custom-elements.json +0 -13
  86. package/lib/icon/custom-elements.md +0 -1
  87. package/lib/icon/index.d.ts +18 -11
  88. package/lib/icon/index.js +41 -29
  89. package/lib/icon/themes/halo/dark/index.js +1 -1
  90. package/lib/icon/themes/halo/light/index.js +1 -1
  91. package/lib/icon/themes/solar/charcoal/index.js +1 -1
  92. package/lib/icon/themes/solar/pearl/index.js +1 -1
  93. package/lib/interactive-chart/index.js +4 -2
  94. package/lib/item/themes/halo/dark/index.js +1 -1
  95. package/lib/item/themes/halo/light/index.js +1 -1
  96. package/lib/item/themes/solar/charcoal/index.js +1 -1
  97. package/lib/item/themes/solar/pearl/index.js +1 -1
  98. package/lib/label/index.js +9 -34
  99. package/lib/layout/index.js +0 -13
  100. package/lib/list/elements/list.js +0 -3
  101. package/lib/list/themes/halo/dark/index.js +2 -2
  102. package/lib/list/themes/halo/light/index.js +2 -2
  103. package/lib/list/themes/solar/charcoal/index.js +2 -2
  104. package/lib/list/themes/solar/pearl/index.js +2 -2
  105. package/lib/multi-input/themes/halo/dark/index.js +1 -1
  106. package/lib/multi-input/themes/halo/light/index.js +1 -1
  107. package/lib/multi-input/themes/solar/charcoal/index.js +1 -1
  108. package/lib/multi-input/themes/solar/pearl/index.js +1 -1
  109. package/lib/notification/elements/notification.d.ts +0 -1
  110. package/lib/notification/elements/notification.js +0 -7
  111. package/lib/notification/themes/halo/dark/index.js +1 -1
  112. package/lib/notification/themes/halo/light/index.js +1 -1
  113. package/lib/notification/themes/solar/charcoal/index.js +1 -1
  114. package/lib/notification/themes/solar/pearl/index.js +1 -1
  115. package/lib/number-field/index.js +17 -12
  116. package/lib/number-field/themes/halo/dark/index.js +1 -1
  117. package/lib/number-field/themes/halo/light/index.js +1 -1
  118. package/lib/number-field/themes/solar/charcoal/index.js +1 -1
  119. package/lib/number-field/themes/solar/pearl/index.js +1 -1
  120. package/lib/overlay/elements/overlay-backdrop.d.ts +1 -8
  121. package/lib/overlay/elements/overlay-backdrop.js +3 -13
  122. package/lib/overlay/elements/overlay-viewport.d.ts +1 -8
  123. package/lib/overlay/elements/overlay-viewport.js +3 -13
  124. package/lib/overlay/elements/overlay.d.ts +0 -8
  125. package/lib/overlay/elements/overlay.js +4 -39
  126. package/lib/overlay/managers/close-manager.js +6 -4
  127. package/lib/overlay/managers/focus-manager.js +2 -1
  128. package/lib/overlay/managers/interaction-lock-manager.js +1 -1
  129. package/lib/overlay/managers/viewport-manager.js +3 -0
  130. package/lib/overlay/managers/zindex-manager.js +1 -1
  131. package/lib/overlay/themes/halo/dark/index.js +1 -1
  132. package/lib/overlay/themes/halo/light/index.js +1 -1
  133. package/lib/overlay/themes/solar/charcoal/index.js +1 -1
  134. package/lib/overlay/themes/solar/pearl/index.js +1 -1
  135. package/lib/overlay-menu/index.js +0 -5
  136. package/lib/overlay-menu/managers/menu-manager.d.ts +0 -1
  137. package/lib/overlay-menu/managers/menu-manager.js +1 -5
  138. package/lib/overlay-menu/themes/halo/dark/index.js +1 -1
  139. package/lib/overlay-menu/themes/halo/light/index.js +1 -1
  140. package/lib/overlay-menu/themes/solar/charcoal/index.js +1 -1
  141. package/lib/overlay-menu/themes/solar/pearl/index.js +1 -1
  142. package/lib/pagination/index.js +0 -2
  143. package/lib/pagination/themes/halo/dark/index.js +1 -1
  144. package/lib/pagination/themes/halo/light/index.js +1 -1
  145. package/lib/pagination/themes/solar/charcoal/index.js +1 -1
  146. package/lib/pagination/themes/solar/pearl/index.js +1 -1
  147. package/lib/password-field/themes/halo/dark/index.js +1 -1
  148. package/lib/password-field/themes/halo/light/index.js +1 -1
  149. package/lib/password-field/themes/solar/charcoal/index.js +1 -1
  150. package/lib/password-field/themes/solar/pearl/index.js +1 -1
  151. package/lib/pill/index.js +1 -1
  152. package/lib/pill/themes/solar/charcoal/index.js +1 -1
  153. package/lib/pill/themes/solar/pearl/index.js +1 -1
  154. package/lib/radio-button/index.js +0 -5
  155. package/lib/radio-button/themes/halo/dark/index.js +1 -1
  156. package/lib/radio-button/themes/halo/light/index.js +1 -1
  157. package/lib/radio-button/themes/solar/charcoal/index.js +1 -1
  158. package/lib/radio-button/themes/solar/pearl/index.js +1 -1
  159. package/lib/rating/index.js +0 -4
  160. package/lib/search-field/themes/halo/dark/index.js +1 -1
  161. package/lib/search-field/themes/halo/light/index.js +1 -1
  162. package/lib/search-field/themes/solar/charcoal/index.js +1 -1
  163. package/lib/search-field/themes/solar/pearl/index.js +1 -1
  164. package/lib/select/index.js +12 -18
  165. package/lib/select/themes/halo/dark/index.js +1 -1
  166. package/lib/select/themes/halo/light/index.js +1 -1
  167. package/lib/select/themes/solar/charcoal/index.js +1 -1
  168. package/lib/select/themes/solar/pearl/index.js +1 -1
  169. package/lib/sidebar-layout/themes/halo/dark/index.js +1 -1
  170. package/lib/sidebar-layout/themes/halo/light/index.js +1 -1
  171. package/lib/sidebar-layout/themes/solar/charcoal/index.js +1 -1
  172. package/lib/sidebar-layout/themes/solar/pearl/index.js +1 -1
  173. package/lib/slider/index.js +16 -9
  174. package/lib/slider/themes/halo/dark/index.js +1 -1
  175. package/lib/slider/themes/halo/light/index.js +1 -1
  176. package/lib/slider/themes/solar/charcoal/index.js +1 -1
  177. package/lib/slider/themes/solar/pearl/index.js +1 -1
  178. package/lib/tab/themes/halo/dark/index.js +1 -1
  179. package/lib/tab/themes/halo/light/index.js +1 -1
  180. package/lib/tab/themes/solar/charcoal/index.js +1 -1
  181. package/lib/tab/themes/solar/pearl/index.js +1 -1
  182. package/lib/tab-bar/index.js +0 -4
  183. package/lib/tab-bar/themes/halo/dark/index.js +1 -1
  184. package/lib/tab-bar/themes/halo/light/index.js +1 -1
  185. package/lib/text-field/index.d.ts +1 -7
  186. package/lib/text-field/index.js +4 -18
  187. package/lib/text-field/themes/halo/dark/index.js +1 -1
  188. package/lib/text-field/themes/halo/light/index.js +1 -1
  189. package/lib/text-field/themes/solar/charcoal/index.js +1 -1
  190. package/lib/text-field/themes/solar/pearl/index.js +1 -1
  191. package/lib/time-picker/index.js +13 -13
  192. package/lib/toggle/index.js +1 -1
  193. package/lib/toggle/themes/halo/dark/index.js +1 -1
  194. package/lib/toggle/themes/halo/light/index.js +1 -1
  195. package/lib/toggle/themes/solar/charcoal/index.js +1 -1
  196. package/lib/toggle/themes/solar/pearl/index.js +1 -1
  197. package/lib/tooltip/elements/title-tooltip.js +1 -2
  198. package/lib/tooltip/elements/tooltip-element.js +1 -1
  199. package/lib/tooltip/index.js +5 -4
  200. package/lib/tooltip/managers/tooltip-manager.js +2 -5
  201. package/lib/tornado-chart/elements/tornado-chart.d.ts +4 -0
  202. package/lib/tornado-chart/elements/tornado-chart.js +9 -2
  203. package/lib/tree/elements/tree.js +0 -2
  204. package/lib/tree/themes/halo/dark/index.js +2 -2
  205. package/lib/tree/themes/halo/light/index.js +2 -2
  206. package/lib/tree/themes/solar/charcoal/index.js +2 -2
  207. package/lib/tree/themes/solar/pearl/index.js +2 -2
  208. package/lib/tree-select/index.js +8 -6
  209. package/lib/tree-select/themes/halo/dark/index.js +1 -1
  210. package/lib/tree-select/themes/halo/light/index.js +1 -1
  211. package/lib/tree-select/themes/solar/charcoal/index.js +1 -1
  212. package/lib/tree-select/themes/solar/pearl/index.js +1 -1
  213. package/lib/version.js +1 -1
  214. package/package.json +32 -32
  215. package/lib/chart/helpers/legend.d.ts +0 -5
  216. package/lib/chart/helpers/legend.js +0 -78
  217. package/lib/config/custom-elements.json +0 -23
  218. package/lib/config/custom-elements.md +0 -8
  219. package/lib/config/elements/config.d.ts +0 -37
  220. package/lib/config/elements/config.js +0 -44
  221. package/lib/config/helpers/context.d.ts +0 -12
  222. package/lib/config/helpers/context.js +0 -2
  223. package/lib/config/index.d.ts +0 -2
  224. package/lib/config/index.js +0 -2
@@ -1,192 +1 @@
1
- import { JSXInterface } from '../jsx';
2
- /// <reference types="chart.js" />
3
- import { BasicElement, PropertyValues, TemplateResult, CSSResultGroup } from '@refinitiv-ui/core';
4
- import 'chart.js/dist/Chart.bundle.min.js';
5
- import type { ChartJS, ChartConfig, ChartUpdateProps, DatasetColors } from './helpers/types';
6
- import type { Header } from '../header';
7
- import '../header/index.js';
8
- import '../layout/index.js';
9
- declare global {
10
- interface Window {
11
- Chart: ChartJS;
12
- }
13
- }
14
- export type { ChartConfig, ChartUpdateProps };
15
- /**
16
- * Charting component that use ChartJS library
17
- */
18
- export declare class Chart extends BasicElement {
19
- /**
20
- * Element version number
21
- * @returns version number
22
- */
23
- static get version(): string;
24
- /**
25
- * Chart.js object
26
- */
27
- chart: ChartJS | null;
28
- /**
29
- * Chart configurations. Same configuration as ChartJS
30
- * @type {ChartConfig}
31
- */
32
- config: ChartConfig | null;
33
- /**
34
- * Html canvas element
35
- * @type {HTMLCanvasElement}
36
- */
37
- protected canvas: HTMLCanvasElement;
38
- /**
39
- * Get canvas element from shadow roots
40
- */
41
- protected titleElement: Header;
42
- /**
43
- * Required properties, needed for chart to work correctly.
44
- * @returns config
45
- */
46
- protected get requiredConfig(): ChartConfig;
47
- /**
48
- * Safely returns the chart title
49
- * @returns chart title
50
- */
51
- protected get chartTitle(): string;
52
- /**
53
- * Safely returns a dataset array
54
- * @returns dataset array
55
- */
56
- protected get datasets(): Chart.ChartDataSets[];
57
- /**
58
- * List of available chart colors
59
- * @type {string[]}
60
- * @returns {string[]} List of available chart colors
61
- */
62
- get colors(): string[];
63
- /**
64
- * Invoked whenever the element is updated
65
- * @param {PropertyValues} changedProperties Map of changed properties with old values
66
- * @returns {void}
67
- */
68
- protected updated(changedProperties: PropertyValues): void;
69
- /**
70
- * Element connected
71
- * @returns {void}
72
- */
73
- connectedCallback(): void;
74
- /**
75
- * Element disconnected
76
- * @returns {void}
77
- */
78
- disconnectedCallback(): void;
79
- /**
80
- * Themable parts of the config.
81
- * This will be merged into the configuration object.
82
- * @returns {ChartConfig} chart config with theme
83
- */
84
- protected get themableConfig(): ChartConfig;
85
- /**
86
- * Handles a change of configuration object.
87
- * This does not fire when a property of the config object changes,
88
- * for this use this.updateChart() to apply changes.
89
- * @returns {void}
90
- */
91
- protected onConfigChange(): void;
92
- /**
93
- * Get as CSS variable and tries to convert it into a usable number
94
- * @returns {(number|undefined)} The value as a number, or, undefined if NaN.
95
- */
96
- protected cssVarAsNumber(...args: string[]): number | undefined;
97
- /**
98
- * Generates the legend labels on a given chart
99
- * @param {ChartJS} chart Chart.js instance
100
- * @returns {Chart.ChartLegendLabelItem[]} Array of label configurations
101
- */
102
- protected generateLegendLabels: (chart: ChartJS) => Chart.ChartLegendLabelItem[];
103
- /**
104
- * Merges all the different layers of the config.
105
- * @returns {void}
106
- */
107
- protected mergeConfigs(): void;
108
- /**
109
- * Themes the passed-in configuration object
110
- * @returns {void}
111
- */
112
- protected decorateConfig(): void;
113
- /**
114
- * Returns usable information about a dataset
115
- * @param {Chart.ChartDataSets} dataset Chart dataset
116
- * @returns {Chart.ChartDataSets} Information about the dataset
117
- */
118
- protected datasetInfo(dataset: Chart.ChartDataSets): Chart.ChartDataSets;
119
- /**
120
- * Generates internal solid and opaque color set for a dataset
121
- * @param {boolean} isArray Flag to return result in array or not e.g. doughnut, pie, etc
122
- * @param {number} amount Amount of colors required
123
- * @param {number} shift Positional shift of the color start point
124
- * @returns {DatasetColors} Solid and opaque color values
125
- */
126
- protected generateColors(isArray: boolean, amount: number, shift: number): DatasetColors;
127
- /**
128
- * Manages the custom title element
129
- * @returns {void}
130
- */
131
- private manageTitle;
132
- /**
133
- * Creates a chart after config has changed,
134
- * or, the element has been connected to the DOM
135
- * @returns {void}
136
- */
137
- protected createChart(): void;
138
- /**
139
- * Destroys the chart.js object
140
- * @returns True if a chart object has been destroyed
141
- */
142
- protected destroyChart(): boolean;
143
- /**
144
- * Re-renders the chart based on its config
145
- * @param {ChartUpdateProps} config Additional configuration object for the update process.
146
- * @returns {void}
147
- */
148
- private renderChart;
149
- /**
150
- * Update all data, title, scales, legends and re-render the chart based on its config
151
- * @param {ChartUpdateProps=} config Additional configuration for control an animation in the update process.
152
- * @returns {void}
153
- */
154
- updateChart(config?: ChartUpdateProps): void;
155
- /**
156
- * A `CSSResultGroup` that will be used
157
- * to style the host, slotted children
158
- * and the internal template of the element.
159
- * @return CSS template
160
- */
161
- static get styles(): CSSResultGroup;
162
- /**
163
- * Handles resize event of the chart region
164
- * @returns {void}
165
- */
166
- protected onResize(): void;
167
- /**
168
- * A `TemplateResult` that will be used
169
- * to render the updated internal template.
170
- * @return Render template
171
- */
172
- protected render(): TemplateResult;
173
- }
174
- declare global {
175
- interface HTMLElementTagNameMap {
176
- 'ef-chart': Chart;
177
- }
178
- }
179
-
180
- declare global {
181
- interface HTMLElementTagNameMap {
182
- 'ef-chart': Chart;
183
- }
184
-
185
- namespace JSX {
186
- interface IntrinsicElements {
187
- 'ef-chart': Partial<Chart> | JSXInterface.HTMLAttributes<Chart>;
188
- }
189
- }
190
- }
191
-
192
- export {};
1
+ export * from './elements/chart.js';
@@ -1,485 +1,5 @@
1
- /* eslint @typescript-eslint/no-unsafe-call: 0 */
2
- /* eslint @typescript-eslint/no-unsafe-member-access: 0 */
3
- import { __decorate } from "tslib";
4
- import { BasicElement, html, css } from '@refinitiv-ui/core';
5
- import { customElement } from '@refinitiv-ui/core/decorators/custom-element.js';
6
- import { property } from '@refinitiv-ui/core/decorators/property.js';
7
- import { query } from '@refinitiv-ui/core/decorators/query.js';
8
- import { VERSION } from '../version.js';
9
- import { color as parseColor } from '@refinitiv-ui/utils/color.js';
10
- import 'chart.js/dist/Chart.bundle.min.js';
11
- import { legendHelper, merge } from './helpers/index.js';
12
- import '../header/index.js';
13
- import '../layout/index.js';
14
- // Register plugins
15
- import doughnutCenterPlugin from './plugins/doughnut-center-label.js';
16
- window.Chart.pluginService.register(doughnutCenterPlugin);
17
- const CSS_COLOR_PREFIX = '--chart-color-';
18
- const CHART_TYPE_OPAQUE = ['line', 'bubble', 'radar', 'polarArea'];
19
- // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
20
- const DEFAULT_CHART_CONFIG = window.Chart.defaults;
21
- const ELF_CHART_CONFIG = {
22
- polarArea: {
23
- scale: {
24
- ticks: {
25
- showLabelBackdrop: false
26
- }
27
- }
28
- },
29
- radar: {
30
- scale: {
31
- ticks: {
32
- showLabelBackdrop: false
33
- }
34
- }
35
- }
36
- };
37
- // eslint-disable-next-line @typescript-eslint/no-unsafe-call
38
- window.Chart.helpers.merge(DEFAULT_CHART_CONFIG, ELF_CHART_CONFIG);
39
- /**
40
- * Charting component that use ChartJS library
41
- */
42
- let Chart = class Chart extends BasicElement {
43
- constructor() {
44
- super(...arguments);
45
- /**
46
- * Chart.js object
47
- */
48
- this.chart = null;
49
- /**
50
- * Chart configurations. Same configuration as ChartJS
51
- * @type {ChartConfig}
52
- */
53
- this.config = null;
54
- /**
55
- * Generates the legend labels on a given chart
56
- * @param {ChartJS} chart Chart.js instance
57
- * @returns {Chart.ChartLegendLabelItem[]} Array of label configurations
58
- */
59
- this.generateLegendLabels = (chart) => {
60
- if (!this.config?.type) {
61
- return [];
62
- }
63
- const chartOption = DEFAULT_CHART_CONFIG[this.config.type];
64
- if (this.datasets.length
65
- && chartOption.legend
66
- && Array.isArray(this.datasets[0].backgroundColor)) {
67
- let legends = [];
68
- if (chartOption.legend.labels?.generateLabels) {
69
- legends = chartOption.legend.labels?.generateLabels(chart);
70
- }
71
- // Customize for doughnut chart change border color to background color
72
- if (['pie', 'doughnut'].includes(this.config?.type) && this.datasets.length > 1) {
73
- legends.forEach((label) => {
74
- label.strokeStyle = label.fillStyle;
75
- });
76
- }
77
- return legends;
78
- }
79
- return this.datasets.map((dataset, i) => {
80
- const solidFill = !CHART_TYPE_OPAQUE.includes(dataset.type || this.config?.type);
81
- const usePointStyle = chart.options.legend?.labels?.usePointStyle || false;
82
- return {
83
- text: dataset.label,
84
- fillStyle: legendHelper.getLegendFillStyle(dataset, usePointStyle, solidFill),
85
- hidden: !chart.isDatasetVisible(i),
86
- lineCap: dataset.borderCapStyle,
87
- lineDash: dataset.borderDash,
88
- lineDashOffset: dataset.borderDashOffset,
89
- lineJoin: dataset.borderJoinStyle,
90
- lineWidth: Number(dataset.borderWidth) || 0,
91
- strokeStyle: legendHelper.getLegendStrokeStyle(dataset, usePointStyle),
92
- pointStyle: typeof dataset.pointStyle === 'string' ? dataset.pointStyle : undefined,
93
- // Below is extra data used for toggling the datasets
94
- datasetIndex: i
95
- };
96
- });
97
- };
98
- }
99
- /**
100
- * Element version number
101
- * @returns version number
102
- */
103
- static get version() {
104
- return VERSION;
105
- }
106
- /**
107
- * Required properties, needed for chart to work correctly.
108
- * @returns config
109
- */
110
- get requiredConfig() {
111
- return {
112
- options: {
113
- responsive: false,
114
- maintainAspectRatio: false,
115
- title: {
116
- display: false
117
- }
118
- }
119
- };
120
- }
121
- /**
122
- * Safely returns the chart title
123
- * @returns chart title
124
- */
125
- get chartTitle() {
126
- const title = this.config?.options?.title?.text;
127
- if (title) {
128
- return typeof title === 'string' ? title : title.join();
129
- }
130
- return '';
131
- }
132
- /**
133
- * Safely returns a dataset array
134
- * @returns dataset array
135
- */
136
- get datasets() {
137
- return this.config?.data?.datasets || [];
138
- }
139
- /**
140
- * List of available chart colors
141
- * @type {string[]}
142
- * @returns {string[]} List of available chart colors
143
- */
144
- get colors() {
145
- let color;
146
- let index = 0;
147
- const colors = [];
148
- while ((color = this.getComputedVariable(`${CSS_COLOR_PREFIX}${++index}`))) {
149
- colors.push(color);
150
- }
151
- return colors;
152
- }
153
- /**
154
- * Invoked whenever the element is updated
155
- * @param {PropertyValues} changedProperties Map of changed properties with old values
156
- * @returns {void}
157
- */
158
- updated(changedProperties) {
159
- super.updated(changedProperties);
160
- if (changedProperties.has('config')) {
161
- this.onConfigChange();
162
- }
163
- }
164
- /**
165
- * Element connected
166
- * @returns {void}
167
- */
168
- connectedCallback() {
169
- super.connectedCallback();
170
- if (this.canvas) {
171
- this.createChart();
172
- }
173
- }
174
- /**
175
- * Element disconnected
176
- * @returns {void}
177
- */
178
- disconnectedCallback() {
179
- super.disconnectedCallback();
180
- this.destroyChart();
181
- }
182
- /**
183
- * Themable parts of the config.
184
- * This will be merged into the configuration object.
185
- * @returns {ChartConfig} chart config with theme
186
- */
187
- get themableConfig() {
188
- const style = getComputedStyle(this);
189
- // TODO: Try and remove the need for global object modification.
190
- // It's easier to cover all areas by modifying the global object,
191
- // however, if possible, we should look to try and just modify local configs.
192
- // Set font globals
193
- window.Chart.defaults.global.defaultFontColor = style.getPropertyValue('color');
194
- window.Chart.defaults.global.defaultFontFamily = style.getPropertyValue('font-family');
195
- window.Chart.defaults.global.defaultFontSize = Number(style.getPropertyValue('font-size').replace('px', ''));
196
- window.Chart.defaults.global.defaultFontStyle = style.getPropertyValue('font-style');
197
- // Set grid line globals
198
- window.Chart.defaults.scale.gridLines.color = this.getComputedVariable('--grid-line-color', 'transparent');
199
- window.Chart.defaults.scale.gridLines.zeroLineColor = this.getComputedVariable('--zero-line-color', 'transparent');
200
- return {
201
- options: {
202
- animation: {
203
- duration: this.cssVarAsNumber('--animation-duration', '0')
204
- },
205
- elements: {
206
- line: {
207
- borderWidth: this.cssVarAsNumber('--line-width', '1'),
208
- tension: this.cssVarAsNumber('--line-tension', '0.5')
209
- }
210
- },
211
- tooltips: {
212
- backgroundColor: this.getComputedVariable('--tooltip-background-color', 'transparent'),
213
- titleFontColor: this.getComputedVariable('--tooltip-title-color', 'transparent'),
214
- bodyFontColor: this.getComputedVariable('--tooltip-body-color', 'transparent'),
215
- cornerRadius: this.cssVarAsNumber('--tooltip-border-radius', '0'),
216
- caretSize: this.cssVarAsNumber('--tooltip-caret-size', '0'),
217
- xPadding: this.cssVarAsNumber('--tooltip-padding-x', '--tooltip-padding', '0'),
218
- yPadding: this.cssVarAsNumber('--tooltip-padding-y', '--tooltip-padding', '0'),
219
- titleSpacing: this.cssVarAsNumber('--tooltip-title-spacing', '0'),
220
- displayColors: false
221
- },
222
- legend: {
223
- position: ['pie', 'doughnut'].includes(this.config?.type || '') ? 'right' : 'top',
224
- labels: {
225
- boxWidth: this.cssVarAsNumber('--legend-key-box-width', '10'),
226
- generateLabels: this.generateLegendLabels
227
- }
228
- }
229
- }
230
- };
231
- }
232
- /**
233
- * Handles a change of configuration object.
234
- * This does not fire when a property of the config object changes,
235
- * for this use this.updateChart() to apply changes.
236
- * @returns {void}
237
- */
238
- onConfigChange() {
239
- if (this.config) {
240
- this.createChart();
241
- }
242
- }
243
- /**
244
- * Get as CSS variable and tries to convert it into a usable number
245
- * @returns {(number|undefined)} The value as a number, or, undefined if NaN.
246
- */
247
- cssVarAsNumber(...args) {
248
- const result = Number(this.getComputedVariable(...args).replace(/\D+$/, ''));
249
- return isNaN(result) ? undefined : result;
250
- }
251
- /**
252
- * Merges all the different layers of the config.
253
- * @returns {void}
254
- */
255
- mergeConfigs() {
256
- if (!this.config) {
257
- return;
258
- }
259
- merge(this.config, this.themableConfig);
260
- merge(this.config, this.requiredConfig, true);
261
- }
262
- /**
263
- * Themes the passed-in configuration object
264
- * @returns {void}
265
- */
266
- decorateConfig() {
267
- this.mergeConfigs();
268
- const extendColorsIfRequired = (currentColors, infoColors) => {
269
- if (Array.isArray(currentColors) && Array.isArray(infoColors) && currentColors.length < infoColors.length) {
270
- merge(currentColors, infoColors);
271
- }
272
- };
273
- this.datasets.forEach((dataset) => {
274
- const info = this.datasetInfo(dataset);
275
- // make sure that colours are defined for every dataset e.g. when new dataset is added
276
- extendColorsIfRequired(dataset.borderColor, info.borderColor);
277
- extendColorsIfRequired(dataset.backgroundColor, info.backgroundColor);
278
- extendColorsIfRequired(dataset.pointBorderColor, info.pointBorderColor);
279
- extendColorsIfRequired(dataset.pointBackgroundColor, info.pointBackgroundColor);
280
- dataset.borderColor = dataset.borderColor || info.borderColor;
281
- dataset.backgroundColor = dataset.backgroundColor || info.backgroundColor;
282
- dataset.pointBackgroundColor = dataset.pointBackgroundColor || info.pointBackgroundColor;
283
- dataset.pointBorderColor = dataset.pointBorderColor || info.pointBorderColor;
284
- });
285
- }
286
- /**
287
- * Returns usable information about a dataset
288
- * @param {Chart.ChartDataSets} dataset Chart dataset
289
- * @returns {Chart.ChartDataSets} Information about the dataset
290
- */
291
- datasetInfo(dataset) {
292
- const type = dataset.type || this.config?.type;
293
- let index = this.datasets.indexOf(dataset);
294
- const isColorArray = (!!type && ['pie', 'doughnut', 'polarArea'].includes(type)) || type === 'bar' && this.datasets.length === 1;
295
- const isSolidFill = !!type && !CHART_TYPE_OPAQUE.includes(type);
296
- // Doughnut chart using same color sequence for each data in datasets
297
- let borderColor = null;
298
- if (['pie', 'doughnut'].includes(type) && this.datasets.length > 1) {
299
- index = 0;
300
- borderColor = this.getComputedVariable('--multi-dataset-border-color', '#fff');
301
- }
302
- const colors = this.generateColors(isColorArray, isColorArray && dataset.data ? dataset.data.length : 1, index);
303
- return {
304
- type,
305
- borderColor: borderColor || colors.solid,
306
- backgroundColor: isSolidFill ? colors.solid : colors.opaque,
307
- pointBorderColor: colors.solid,
308
- pointBackgroundColor: colors.solid
309
- };
310
- }
311
- /**
312
- * Generates internal solid and opaque color set for a dataset
313
- * @param {boolean} isArray Flag to return result in array or not e.g. doughnut, pie, etc
314
- * @param {number} amount Amount of colors required
315
- * @param {number} shift Positional shift of the color start point
316
- * @returns {DatasetColors} Solid and opaque color values
317
- */
318
- generateColors(isArray, amount, shift) {
319
- let color;
320
- const solid = [];
321
- const opaque = [];
322
- const alpha = Number(this.getComputedVariable('--fill-opacity', '0.2'));
323
- amount = isArray ? amount : 1;
324
- for (let i = shift; i < amount + shift; i++) {
325
- color = this.colors[i % this.colors.length];
326
- solid.push(color);
327
- const opaqueColor = parseColor(color);
328
- if (opaqueColor) {
329
- opaqueColor.opacity = alpha;
330
- opaque.push(opaqueColor.toString());
331
- }
332
- }
333
- return {
334
- solid: isArray ? solid : solid[0],
335
- opaque: isArray ? opaque : opaque[0]
336
- };
337
- }
338
- /**
339
- * Manages the custom title element
340
- * @returns {void}
341
- */
342
- manageTitle() {
343
- this.titleElement.textContent = this.chartTitle;
344
- if (this.chartTitle) {
345
- this.titleElement.style.removeProperty('display');
346
- }
347
- else {
348
- this.titleElement.style.display = 'none';
349
- }
350
- }
351
- /**
352
- * Creates a chart after config has changed,
353
- * or, the element has been connected to the DOM
354
- * @returns {void}
355
- */
356
- createChart() {
357
- const ctx = this.canvas.getContext('2d');
358
- if (ctx && this.config) {
359
- // Are we reusing an old chart canvas?
360
- const isReusingCanvas = this.destroyChart();
361
- // Preparing the resources before create chart
362
- this.decorateConfig();
363
- this.manageTitle();
364
- // Create chart
365
- this.chart = new window.Chart(ctx, this.config);
366
- if (isReusingCanvas) {
367
- // If we're reusing an old chart canvas, we need to resize it.
368
- // Destroying a chart has some strange side-effects on the canvas.
369
- this.chart.resize();
370
- }
371
- }
372
- }
373
- /**
374
- * Destroys the chart.js object
375
- * @returns True if a chart object has been destroyed
376
- */
377
- destroyChart() {
378
- if (this.chart) {
379
- // Destroy the chart
380
- this.chart.destroy();
381
- this.chart = null;
382
- return true;
383
- }
384
- return false;
385
- }
386
- /**
387
- * Re-renders the chart based on its config
388
- * @param {ChartUpdateProps} config Additional configuration object for the update process.
389
- * @returns {void}
390
- */
391
- renderChart(config = { duration: this.cssVarAsNumber('--animation-duration', '0') }) {
392
- if (!this.chart || !this.config) {
393
- return;
394
- }
395
- // Stop any chart.js animations
396
- this.chart.stop();
397
- // Decorate the config object
398
- this.decorateConfig();
399
- // Update internal layout
400
- this.manageTitle();
401
- // Update the chart
402
- this.chart.update(config);
403
- }
404
- /**
405
- * Update all data, title, scales, legends and re-render the chart based on its config
406
- * @param {ChartUpdateProps=} config Additional configuration for control an animation in the update process.
407
- * @returns {void}
408
- */
409
- updateChart(config) {
410
- this.renderChart(config);
411
- }
412
- /**
413
- * A `CSSResultGroup` that will be used
414
- * to style the host, slotted children
415
- * and the internal template of the element.
416
- * @return CSS template
417
- */
418
- static get styles() {
419
- return css `
420
- :host {
421
- display: block;
422
- overflow: hidden;
423
- position: relative;
424
- }
425
- :host::before {
426
- content: '';
427
- display: block;
428
- padding-top: 60%;
429
- min-height: 300px;
430
- box-sizing: border-box;
431
- }
432
- [container] {
433
- position: absolute;
434
- top: 0;
435
- right: 0;
436
- bottom: 0;
437
- left: 0;
438
- }
439
- ef-header {
440
- margin-bottom: 12px;
441
- }
442
- canvas {
443
- position: absolute;
444
- top: 0;
445
- right: 0;
446
- bottom: 0;
447
- left: 0;
448
- }
449
- `;
450
- }
451
- /**
452
- * Handles resize event of the chart region
453
- * @returns {void}
454
- */
455
- onResize() {
456
- this.chart?.resize();
457
- }
458
- /**
459
- * A `TemplateResult` that will be used
460
- * to render the updated internal template.
461
- * @return Render template
462
- */
463
- render() {
464
- return html `
465
- <ef-layout flex container>
466
- <ef-header></ef-header>
467
- <ef-layout part="chart" @resize="${this.onResize}">
468
- <canvas id="canvas"></canvas>
469
- </ef-layout>
470
- </ef-layout>`;
471
- }
472
- };
473
- __decorate([
474
- property({ type: Object })
475
- ], Chart.prototype, "config", void 0);
476
- __decorate([
477
- query('canvas')
478
- ], Chart.prototype, "canvas", void 0);
479
- __decorate([
480
- query('ef-header')
481
- ], Chart.prototype, "titleElement", void 0);
482
- Chart = __decorate([
483
- customElement('ef-chart')
484
- ], Chart);
485
- export { Chart };
1
+ // eslint-disable-next-line import/extensions
2
+ import { Chart } from 'chart.js/auto';
3
+ import { doughnutCenterLabelPlugin } from './plugins/index.js';
4
+ Chart.register(doughnutCenterLabelPlugin);
5
+ export * from './elements/chart.js';