@mozaic-ds/chart 0.1.0-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +16 -0
- package/dist/mozaic-chart.js +9858 -0
- package/dist/mozaic-chart.umd.cjs +22 -0
- package/dist/style.css +1 -0
- package/dist/vite.svg +1 -0
- package/package.json +79 -0
- package/src/assets/base.css +2 -0
- package/src/components/bar/BarChart.stories.ts +298 -0
- package/src/components/bar/BarChart.vue +247 -0
- package/src/components/doughnut/DoughnutChart.stories.ts +80 -0
- package/src/components/doughnut/DoughnutChart.vue +208 -0
- package/src/components/line/LineChart.stories.ts +60 -0
- package/src/components/line/LineChart.vue +245 -0
- package/src/components/radar/RadarChart.stories.ts +346 -0
- package/src/components/radar/RadarChart.vue +265 -0
- package/src/main.ts +6 -0
- package/src/services/BarChartFunctions.ts +126 -0
- package/src/services/ChartsCommonLegend.ts +366 -0
- package/src/services/DoughnutChartFunctions.ts +89 -0
- package/src/services/FormatUtilities.ts +30 -0
- package/src/services/GenericTooltipService.ts +305 -0
- package/src/services/PatternFunctions.ts +25 -0
- package/src/services/RadarChartFunctions.ts +70 -0
- package/src/services/patterns/ChartDesign.ts +27 -0
- package/src/services/patterns/patternCircles.ts +82 -0
- package/src/services/patterns/patternDashedDiagonals.ts +66 -0
- package/src/services/patterns/patternDiagonals.ts +101 -0
- package/src/services/patterns/patternSquares.ts +76 -0
- package/src/services/patterns/patternVerticalLines.ts +61 -0
- package/src/services/patterns/patternZigzag.ts +88 -0
- package/src/types/BarData.ts +11 -0
- package/src/types/ButtonName.ts +7 -0
- package/src/types/Chart.ts +10 -0
- package/src/types/DoughnutData.ts +6 -0
- package/src/types/GenericData.ts +11 -0
- package/src/types/LineChart.ts +5 -0
- package/src/types/RadarData.ts +36 -0
- package/src/types/TooltipChartType.ts +7 -0
- package/src/vite-env.d.ts +7 -0
package/dist/style.css
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
.container[data-v-3e53e20e]{-moz-osx-font-smoothing:grayscale;-webkit-font-smoothing:antialiased;font-weight:400;font-family:Roboto,sans-serif}.main[data-v-3e53e20e]{display:flex;flex-direction:column;justify-content:center;align-items:center;margin-bottom:20px}.container[data-v-6b16e20b]{-moz-osx-font-smoothing:grayscale;-webkit-font-smoothing:antialiased;font-weight:400;font-family:Roboto,sans-serif}.main[data-v-6b16e20b]{display:flex;flex-direction:column;justify-content:center;align-items:center}.container[data-v-2b308814]{-moz-osx-font-smoothing:grayscale;-webkit-font-smoothing:antialiased;font-weight:400;font-family:Roboto,sans-serif}.main[data-v-2b308814]{display:flex;flex-direction:column;justify-content:center;align-items:center;margin-bottom:20px}.container[data-v-9f1e4973]{-moz-osx-font-smoothing:grayscale;-webkit-font-smoothing:antialiased;font-weight:400;font-family:Roboto,sans-serif}.main[data-v-9f1e4973]{height:600px;display:flex;flex-direction:column;justify-content:center;align-items:center}
|
package/dist/vite.svg
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" class="iconify iconify--logos" width="31.88" height="32" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 257"><defs><linearGradient id="IconifyId1813088fe1fbc01fb466" x1="-.828%" x2="57.636%" y1="7.652%" y2="78.411%"><stop offset="0%" stop-color="#41D1FF"></stop><stop offset="100%" stop-color="#BD34FE"></stop></linearGradient><linearGradient id="IconifyId1813088fe1fbc01fb467" x1="43.376%" x2="50.316%" y1="2.242%" y2="89.03%"><stop offset="0%" stop-color="#FFEA83"></stop><stop offset="8.333%" stop-color="#FFDD35"></stop><stop offset="100%" stop-color="#FFA800"></stop></linearGradient></defs><path fill="url(#IconifyId1813088fe1fbc01fb466)" d="M255.153 37.938L134.897 252.976c-2.483 4.44-8.862 4.466-11.382.048L.875 37.958c-2.746-4.814 1.371-10.646 6.827-9.67l120.385 21.517a6.537 6.537 0 0 0 2.322-.004l117.867-21.483c5.438-.991 9.574 4.796 6.877 9.62Z"></path><path fill="url(#IconifyId1813088fe1fbc01fb467)" d="M185.432.063L96.44 17.501a3.268 3.268 0 0 0-2.634 3.014l-5.474 92.456a3.268 3.268 0 0 0 3.997 3.378l24.777-5.718c2.318-.535 4.413 1.507 3.936 3.838l-7.361 36.047c-.495 2.426 1.782 4.5 4.151 3.78l15.304-4.649c2.372-.72 4.652 1.36 4.15 3.788l-11.698 56.621c-.732 3.542 3.979 5.473 5.943 2.437l1.313-2.028l72.516-144.72c1.215-2.423-.88-5.186-3.54-4.672l-25.505 4.922c-2.396.462-4.435-1.77-3.759-4.114l16.646-57.705c.677-2.35-1.37-4.583-3.769-4.113Z"></path></svg>
|
package/package.json
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@mozaic-ds/chart",
|
|
3
|
+
"version": "0.1.0-beta.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"scripts": {
|
|
6
|
+
"build": "vue-tsc && vite build",
|
|
7
|
+
"build-storybook": "storybook build",
|
|
8
|
+
"build:types": "vue-tsc --project tsconfig.types.json --declaration --emitDeclarationOnly --outDir dist/types ",
|
|
9
|
+
"check": "vue-tsc --project tsconfig.types.json --noEmit",
|
|
10
|
+
"chromatic": "npx chromatic --project-token=CHROMATIC_PROJECT_TOKEN",
|
|
11
|
+
"coverage": "vitest run --coverage",
|
|
12
|
+
"dev": "vite",
|
|
13
|
+
"npm:publish": "npm publish --access public",
|
|
14
|
+
"npm:publishBeta": "npm publish --tag beta --access public",
|
|
15
|
+
"prepublishOnly": "npm run build",
|
|
16
|
+
"preview": "vite preview",
|
|
17
|
+
"release": "dotenv release-it",
|
|
18
|
+
"release:beta": "dotenv release-it --preRelease=beta",
|
|
19
|
+
"storybook": "storybook dev -p 6006",
|
|
20
|
+
"test": "vitest"
|
|
21
|
+
},
|
|
22
|
+
"bugs": {
|
|
23
|
+
"url": "https://github.com/adeo/mozaic-chart/issues"
|
|
24
|
+
},
|
|
25
|
+
"homepage": "https://github.com/adeo/mozaic-chart#readme",
|
|
26
|
+
"files": [
|
|
27
|
+
"dist/*",
|
|
28
|
+
"src/*"
|
|
29
|
+
],
|
|
30
|
+
"main": "./dist/mozaic-chart.umd.cjs",
|
|
31
|
+
"module": "./dist/mozaic-chart.js",
|
|
32
|
+
"exports": {
|
|
33
|
+
".": {
|
|
34
|
+
"import": "./dist/mozaic-chart.js",
|
|
35
|
+
"require": "./dist/mozaic-chart.umd.cjs"
|
|
36
|
+
}
|
|
37
|
+
},
|
|
38
|
+
"dependencies": {
|
|
39
|
+
"@mozaic-ds/vue-3": "0.49.3",
|
|
40
|
+
"vue": "^3.2.41"
|
|
41
|
+
},
|
|
42
|
+
"devDependencies": {
|
|
43
|
+
"@babel/core": "^7.22.6",
|
|
44
|
+
"@release-it/conventional-changelog": "^7.0.0",
|
|
45
|
+
"@storybook/addon-essentials": "^7.0.25",
|
|
46
|
+
"@storybook/addon-interactions": "^7.0.25",
|
|
47
|
+
"@storybook/addon-links": "^7.0.25",
|
|
48
|
+
"@storybook/blocks": "^7.0.25",
|
|
49
|
+
"@storybook/testing-library": "^0.2.0",
|
|
50
|
+
"@storybook/vue3": "^7.0.25",
|
|
51
|
+
"@storybook/vue3-vite": "^7.0.25",
|
|
52
|
+
"@vitejs/plugin-vue": "^4.2.3",
|
|
53
|
+
"@vitest/coverage-c8": "^0.32.4",
|
|
54
|
+
"@vue/test-utils": "^2.4.0",
|
|
55
|
+
"babel-loader": "^9.1.2",
|
|
56
|
+
"chart.js": "^4.3.0",
|
|
57
|
+
"chromatic": "^6.19.9",
|
|
58
|
+
"dotenv-cli": "^7.2.1",
|
|
59
|
+
"jsdom": "^22.1.0",
|
|
60
|
+
"react": "^18.2.0",
|
|
61
|
+
"react-dom": "^18.2.0",
|
|
62
|
+
"release-it": "^16.1.3",
|
|
63
|
+
"storybook": "^7.0.25",
|
|
64
|
+
"typescript": "^5.1.6",
|
|
65
|
+
"vite": "^4.3.9",
|
|
66
|
+
"vitest": "^0.32.4",
|
|
67
|
+
"vue-chartjs": "5.2.0",
|
|
68
|
+
"vue-loader": "^17.2.2",
|
|
69
|
+
"vue-tsc": "^1.8.3"
|
|
70
|
+
},
|
|
71
|
+
"keywords": [
|
|
72
|
+
"Adeo",
|
|
73
|
+
"Mozaic Design System",
|
|
74
|
+
"Design System",
|
|
75
|
+
"Vue.js",
|
|
76
|
+
"Vue.js 3",
|
|
77
|
+
"Chart.js"
|
|
78
|
+
]
|
|
79
|
+
}
|
|
@@ -0,0 +1,298 @@
|
|
|
1
|
+
// BarChart.stories.ts
|
|
2
|
+
|
|
3
|
+
import type { Meta, StoryObj } from "@storybook/vue3";
|
|
4
|
+
import BarChart from "./BarChart.vue";
|
|
5
|
+
|
|
6
|
+
const meta = {
|
|
7
|
+
title: "Charts/Bar",
|
|
8
|
+
component: BarChart,
|
|
9
|
+
} satisfies Meta<typeof BarChart>;
|
|
10
|
+
|
|
11
|
+
export default meta;
|
|
12
|
+
type Story = StoryObj<typeof meta>;
|
|
13
|
+
|
|
14
|
+
export const Default = {
|
|
15
|
+
args: {
|
|
16
|
+
width: "500px",
|
|
17
|
+
height: "400px",
|
|
18
|
+
rawTitle: "Bar title",
|
|
19
|
+
firstTooltip: "content",
|
|
20
|
+
secondTooltip: "content2",
|
|
21
|
+
labels: ["Data One", "Data Two", "Data Three"],
|
|
22
|
+
datasets: [
|
|
23
|
+
{
|
|
24
|
+
label: "Data One",
|
|
25
|
+
data: [
|
|
26
|
+
{
|
|
27
|
+
amount: 163790.23,
|
|
28
|
+
rate: 1.719528,
|
|
29
|
+
amountUnit: "€",
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
amount: 217064,
|
|
33
|
+
rate: 2.278815,
|
|
34
|
+
amountUnit: "€",
|
|
35
|
+
},
|
|
36
|
+
{
|
|
37
|
+
amount: 9144447.23,
|
|
38
|
+
rate: 96.0016569,
|
|
39
|
+
amountUnit: "€",
|
|
40
|
+
},
|
|
41
|
+
],
|
|
42
|
+
},
|
|
43
|
+
{
|
|
44
|
+
label: "Data Two",
|
|
45
|
+
data: [
|
|
46
|
+
{
|
|
47
|
+
amount: 103144.22,
|
|
48
|
+
rate: 1.1232806,
|
|
49
|
+
amountUnit: "€",
|
|
50
|
+
},
|
|
51
|
+
{
|
|
52
|
+
amount: 297474.14,
|
|
53
|
+
rate: 3.2396087,
|
|
54
|
+
amountUnit: "€",
|
|
55
|
+
},
|
|
56
|
+
{
|
|
57
|
+
amount: 8781791.1,
|
|
58
|
+
rate: 95.6371107,
|
|
59
|
+
amountUnit: "€",
|
|
60
|
+
},
|
|
61
|
+
],
|
|
62
|
+
},
|
|
63
|
+
],
|
|
64
|
+
unit: "%",
|
|
65
|
+
},
|
|
66
|
+
} satisfies Story;
|
|
67
|
+
|
|
68
|
+
export const MultipleData = {
|
|
69
|
+
args: {
|
|
70
|
+
width: "700px",
|
|
71
|
+
height: "400px",
|
|
72
|
+
rawTitle: "Test title",
|
|
73
|
+
firstTooltip: "content",
|
|
74
|
+
secondTooltip: "content2",
|
|
75
|
+
labels: [
|
|
76
|
+
"Data One",
|
|
77
|
+
"Data Two",
|
|
78
|
+
"Data Three",
|
|
79
|
+
"Data Four",
|
|
80
|
+
"Data Five",
|
|
81
|
+
"Data Six",
|
|
82
|
+
"Data Seven",
|
|
83
|
+
"Data Eight",
|
|
84
|
+
"Data Nine",
|
|
85
|
+
"Data Ten",
|
|
86
|
+
"Data Eleven",
|
|
87
|
+
"Data Twelve",
|
|
88
|
+
],
|
|
89
|
+
datasets: [
|
|
90
|
+
{
|
|
91
|
+
label: "Data One",
|
|
92
|
+
data: [
|
|
93
|
+
{
|
|
94
|
+
amount: 163790.23,
|
|
95
|
+
rate: 1.719528,
|
|
96
|
+
amountUnit: "€",
|
|
97
|
+
},
|
|
98
|
+
{
|
|
99
|
+
amount: 217064,
|
|
100
|
+
rate: 2.278815,
|
|
101
|
+
amountUnit: "€",
|
|
102
|
+
},
|
|
103
|
+
{
|
|
104
|
+
amount: 9144447.23,
|
|
105
|
+
rate: 6.0016569,
|
|
106
|
+
amountUnit: "€",
|
|
107
|
+
},
|
|
108
|
+
{
|
|
109
|
+
amount: 9144447.23,
|
|
110
|
+
rate: 46.0016569,
|
|
111
|
+
amountUnit: "€",
|
|
112
|
+
},
|
|
113
|
+
{
|
|
114
|
+
amount: 9144447.23,
|
|
115
|
+
rate: 66.0016569,
|
|
116
|
+
amountUnit: "€",
|
|
117
|
+
},
|
|
118
|
+
{
|
|
119
|
+
amount: 9144447.23,
|
|
120
|
+
rate: 9.0016569,
|
|
121
|
+
amountUnit: "€",
|
|
122
|
+
},
|
|
123
|
+
{
|
|
124
|
+
amount: 9144447.23,
|
|
125
|
+
rate: 46.0016569,
|
|
126
|
+
amountUnit: "€",
|
|
127
|
+
},
|
|
128
|
+
{
|
|
129
|
+
amount: 9144447.23,
|
|
130
|
+
rate: 26.0016569,
|
|
131
|
+
amountUnit: "€",
|
|
132
|
+
},
|
|
133
|
+
{
|
|
134
|
+
amount: 9144447.23,
|
|
135
|
+
rate: 81.0016569,
|
|
136
|
+
amountUnit: "€",
|
|
137
|
+
},
|
|
138
|
+
{
|
|
139
|
+
amount: 9144447.23,
|
|
140
|
+
rate: 11.0016569,
|
|
141
|
+
amountUnit: "€",
|
|
142
|
+
},
|
|
143
|
+
{
|
|
144
|
+
amount: 9144447.23,
|
|
145
|
+
rate: 90.0016569,
|
|
146
|
+
amountUnit: "€",
|
|
147
|
+
},
|
|
148
|
+
{
|
|
149
|
+
amount: 9144447.23,
|
|
150
|
+
rate: 50.0016569,
|
|
151
|
+
amountUnit: "€",
|
|
152
|
+
},
|
|
153
|
+
],
|
|
154
|
+
},
|
|
155
|
+
{
|
|
156
|
+
label: "Data Two",
|
|
157
|
+
data: [
|
|
158
|
+
{
|
|
159
|
+
amount: 103144.22,
|
|
160
|
+
rate: 1.1232806,
|
|
161
|
+
amountUnit: "€",
|
|
162
|
+
},
|
|
163
|
+
{
|
|
164
|
+
amount: 297474.14,
|
|
165
|
+
rate: 3.2396087,
|
|
166
|
+
amountUnit: "€",
|
|
167
|
+
},
|
|
168
|
+
{
|
|
169
|
+
amount: 8781791.1,
|
|
170
|
+
rate: 95.6371107,
|
|
171
|
+
amountUnit: "€",
|
|
172
|
+
},
|
|
173
|
+
{
|
|
174
|
+
amount: 8781791.1,
|
|
175
|
+
rate: 45.6371107,
|
|
176
|
+
amountUnit: "€",
|
|
177
|
+
},
|
|
178
|
+
{
|
|
179
|
+
amount: 8781791.1,
|
|
180
|
+
rate: 40.6371107,
|
|
181
|
+
amountUnit: "€",
|
|
182
|
+
},
|
|
183
|
+
{
|
|
184
|
+
amount: 8781791.1,
|
|
185
|
+
rate: 6.6371107,
|
|
186
|
+
amountUnit: "€",
|
|
187
|
+
},
|
|
188
|
+
{
|
|
189
|
+
amount: 8781791.1,
|
|
190
|
+
rate: 7.6371107,
|
|
191
|
+
amountUnit: "€",
|
|
192
|
+
},
|
|
193
|
+
{
|
|
194
|
+
amount: 8781791.1,
|
|
195
|
+
rate: 39.6371107,
|
|
196
|
+
amountUnit: "€",
|
|
197
|
+
},
|
|
198
|
+
{
|
|
199
|
+
amount: 8781791.1,
|
|
200
|
+
rate: 30.6371107,
|
|
201
|
+
amountUnit: "€",
|
|
202
|
+
},
|
|
203
|
+
{
|
|
204
|
+
amount: 8781791.1,
|
|
205
|
+
rate: 50.6371107,
|
|
206
|
+
amountUnit: "€",
|
|
207
|
+
},
|
|
208
|
+
{
|
|
209
|
+
amount: 8781791.1,
|
|
210
|
+
rate: 59.6371107,
|
|
211
|
+
amountUnit: "€",
|
|
212
|
+
},
|
|
213
|
+
{
|
|
214
|
+
amount: 8781791.1,
|
|
215
|
+
rate: 4.6371107,
|
|
216
|
+
amountUnit: "€",
|
|
217
|
+
},
|
|
218
|
+
],
|
|
219
|
+
},
|
|
220
|
+
],
|
|
221
|
+
unit: "%",
|
|
222
|
+
},
|
|
223
|
+
} satisfies Story;
|
|
224
|
+
|
|
225
|
+
export const StackedBarChart = {
|
|
226
|
+
args: {
|
|
227
|
+
width: "700px",
|
|
228
|
+
height: "400px",
|
|
229
|
+
firstTooltip: "content",
|
|
230
|
+
secondTooltip: "content2",
|
|
231
|
+
rawTitle: "Stacked Bar Chart Title",
|
|
232
|
+
stacked: true,
|
|
233
|
+
labels: ["Category One", "Category Two", "Category Three"],
|
|
234
|
+
datasets: [
|
|
235
|
+
{
|
|
236
|
+
label: "Dataset One",
|
|
237
|
+
data: [
|
|
238
|
+
{
|
|
239
|
+
amount: 103144.22,
|
|
240
|
+
rate: 100.1232806,
|
|
241
|
+
amountUnit: "€",
|
|
242
|
+
},
|
|
243
|
+
{
|
|
244
|
+
amount: 297474.14,
|
|
245
|
+
rate: 3.2396087,
|
|
246
|
+
amountUnit: "€",
|
|
247
|
+
},
|
|
248
|
+
{
|
|
249
|
+
amount: 8781791.1,
|
|
250
|
+
rate: 95.6371107,
|
|
251
|
+
amountUnit: "€",
|
|
252
|
+
},
|
|
253
|
+
],
|
|
254
|
+
},
|
|
255
|
+
{
|
|
256
|
+
label: "Dataset Two",
|
|
257
|
+
data: [
|
|
258
|
+
{
|
|
259
|
+
amount: 103144.22,
|
|
260
|
+
rate: 1.1232806,
|
|
261
|
+
amountUnit: "€",
|
|
262
|
+
},
|
|
263
|
+
{
|
|
264
|
+
amount: 297474.14,
|
|
265
|
+
rate: 3.2396087,
|
|
266
|
+
amountUnit: "€",
|
|
267
|
+
},
|
|
268
|
+
{
|
|
269
|
+
amount: 8781791.1,
|
|
270
|
+
rate: 95.6371107,
|
|
271
|
+
amountUnit: "€",
|
|
272
|
+
},
|
|
273
|
+
],
|
|
274
|
+
},
|
|
275
|
+
{
|
|
276
|
+
label: "Dataset Three",
|
|
277
|
+
data: [
|
|
278
|
+
{
|
|
279
|
+
amount: 103144.22,
|
|
280
|
+
rate: 1.1232806,
|
|
281
|
+
amountUnit: "€",
|
|
282
|
+
},
|
|
283
|
+
{
|
|
284
|
+
amount: 297474.14,
|
|
285
|
+
rate: 3.2396087,
|
|
286
|
+
amountUnit: "€",
|
|
287
|
+
},
|
|
288
|
+
{
|
|
289
|
+
amount: 8781791.1,
|
|
290
|
+
rate: 95.6371107,
|
|
291
|
+
amountUnit: "€",
|
|
292
|
+
},
|
|
293
|
+
],
|
|
294
|
+
},
|
|
295
|
+
],
|
|
296
|
+
unit: "%",
|
|
297
|
+
},
|
|
298
|
+
} satisfies Story;
|
|
@@ -0,0 +1,247 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<div class="container">
|
|
3
|
+
<div class="main">
|
|
4
|
+
<Bar
|
|
5
|
+
v-if="chartData"
|
|
6
|
+
ref="barChartRef"
|
|
7
|
+
:data="chartData"
|
|
8
|
+
:options="options"
|
|
9
|
+
:plugins="htmlLegendPlugin"
|
|
10
|
+
:style="{ width, height }"
|
|
11
|
+
:chart-id="chartId"
|
|
12
|
+
:cssClasses:="cssClasses"
|
|
13
|
+
:styles="styles"
|
|
14
|
+
/>
|
|
15
|
+
</div>
|
|
16
|
+
<div ref="legendContainer" />
|
|
17
|
+
</div>
|
|
18
|
+
</template>
|
|
19
|
+
|
|
20
|
+
<script setup lang="ts">
|
|
21
|
+
import { computed, ref, watch, PropType } from 'vue';
|
|
22
|
+
import type { Ref } from 'vue';
|
|
23
|
+
import { Bar } from 'vue-chartjs';
|
|
24
|
+
import barChartFunctions from '../../services/BarChartFunctions';
|
|
25
|
+
import type { Context } from '../../services/GenericTooltipService';
|
|
26
|
+
import { GenericTooltipService } from '../../services/GenericTooltipService';
|
|
27
|
+
import { TooltipChartType } from '../../types/TooltipChartType';
|
|
28
|
+
import { formatTicks, formatWithThousandsSeprators } from '../../services/FormatUtilities';
|
|
29
|
+
import { BarElement, CategoryScale, Chart as ChartJS, Legend, LinearScale, Title, Tooltip, Plugin } from 'chart.js';
|
|
30
|
+
import { ButtonName } from '../../types/ButtonName';
|
|
31
|
+
import { BarData } from "../../types/BarData";
|
|
32
|
+
|
|
33
|
+
ChartJS.register(
|
|
34
|
+
Title,
|
|
35
|
+
Tooltip,
|
|
36
|
+
Legend,
|
|
37
|
+
BarElement,
|
|
38
|
+
CategoryScale,
|
|
39
|
+
LinearScale
|
|
40
|
+
);
|
|
41
|
+
|
|
42
|
+
const legendContainer = ref(null);
|
|
43
|
+
const selectMode = ref(false);
|
|
44
|
+
const barDataProps = defineProps({
|
|
45
|
+
chartId: {
|
|
46
|
+
type: String,
|
|
47
|
+
default: "radar-chart",
|
|
48
|
+
},
|
|
49
|
+
rawTitle: {
|
|
50
|
+
type: String,
|
|
51
|
+
default: 'sales',
|
|
52
|
+
},
|
|
53
|
+
unit: {
|
|
54
|
+
type: String,
|
|
55
|
+
default: '%',
|
|
56
|
+
},
|
|
57
|
+
labels: {
|
|
58
|
+
type: Array as PropType<string[]>,
|
|
59
|
+
default: () => []
|
|
60
|
+
},
|
|
61
|
+
datasets: {
|
|
62
|
+
type: Array as PropType<BarData[]>,
|
|
63
|
+
default: () => []
|
|
64
|
+
},
|
|
65
|
+
width: {
|
|
66
|
+
type: String,
|
|
67
|
+
default: '400px',
|
|
68
|
+
},
|
|
69
|
+
height: {
|
|
70
|
+
type: String,
|
|
71
|
+
default: '300px',
|
|
72
|
+
},
|
|
73
|
+
cssClasses: {
|
|
74
|
+
default: "",
|
|
75
|
+
type: String,
|
|
76
|
+
},
|
|
77
|
+
styles: {
|
|
78
|
+
type: Object as PropType<Partial<CSSStyleDeclaration>>,
|
|
79
|
+
default: () => {},
|
|
80
|
+
},
|
|
81
|
+
plugins: {
|
|
82
|
+
type: Array as PropType<Plugin<"bar">[]>,
|
|
83
|
+
default: () => [],
|
|
84
|
+
},
|
|
85
|
+
stacked: {
|
|
86
|
+
type: Boolean,
|
|
87
|
+
default: false,
|
|
88
|
+
},
|
|
89
|
+
firstTooltip: {
|
|
90
|
+
type: String,
|
|
91
|
+
default: 'content'
|
|
92
|
+
},
|
|
93
|
+
secondTooltip: {
|
|
94
|
+
type: String,
|
|
95
|
+
default: 'content2'
|
|
96
|
+
}
|
|
97
|
+
})
|
|
98
|
+
|
|
99
|
+
const {
|
|
100
|
+
onHoverIndex,
|
|
101
|
+
barChartRef,
|
|
102
|
+
reloadChart,
|
|
103
|
+
getOnHoverOptions,
|
|
104
|
+
getStackedDatasets,
|
|
105
|
+
privateGetHtmlLegendPlugin,
|
|
106
|
+
} = barChartFunctions();
|
|
107
|
+
|
|
108
|
+
const chartData = computed(() => {
|
|
109
|
+
const chartsLabels = getChartLabels(indexOfOthersLabelIfNull.value);
|
|
110
|
+
gettooltipContent();
|
|
111
|
+
return {
|
|
112
|
+
labels: chartsLabels,
|
|
113
|
+
datasets: getStackedDatasets(
|
|
114
|
+
barDataProps.datasets.map((dataset, index) => ({
|
|
115
|
+
data: getChartData(index, indexOfOthersLabelIfNull.value),
|
|
116
|
+
label: barDataProps.datasets[index].label
|
|
117
|
+
})
|
|
118
|
+
),
|
|
119
|
+
barDataProps.stacked,
|
|
120
|
+
0
|
|
121
|
+
)
|
|
122
|
+
};
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
let xValue: string;
|
|
126
|
+
let yValue: string;
|
|
127
|
+
|
|
128
|
+
const gettooltipContent = (): void => {
|
|
129
|
+
xValue = barDataProps.firstTooltip;
|
|
130
|
+
yValue = barDataProps.secondTooltip;
|
|
131
|
+
};
|
|
132
|
+
|
|
133
|
+
const indexOfOthersLabelIfNull: Ref<number | null> = computed(() => {
|
|
134
|
+
const labels = barDataProps.labels;
|
|
135
|
+
if (labels.includes('other')) {
|
|
136
|
+
const index = labels.indexOf('other');
|
|
137
|
+
if (barDataProps.datasets[0].data[index].rate + '' === '0' &&
|
|
138
|
+
barDataProps.datasets[1].data[index].rate + '' === '0') {
|
|
139
|
+
return index;
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
return null;
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
const getChartData = (index: number, indexOfValueToHide: number | null, isStacked: boolean = false) => {
|
|
146
|
+
const data = Object.assign([], barDataProps.datasets[index].data);
|
|
147
|
+
if (indexOfValueToHide && indexOfOthersLabelIfNull.value) {
|
|
148
|
+
data.splice(indexOfOthersLabelIfNull.value, 1);
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
return data.map((data: { rate: number }) => data.rate);
|
|
152
|
+
};
|
|
153
|
+
|
|
154
|
+
const getTooltipData = (context: Context) => {
|
|
155
|
+
const datasetIndex = context.tooltip.dataPoints[0].datasetIndex;
|
|
156
|
+
const dataIndex = context.tooltip.dataPoints[0].dataIndex;
|
|
157
|
+
const percent = parseFloat(context.tooltip.body[0].lines[0].split(':')[1].replace(',', '.')).toFixed(2) +
|
|
158
|
+
'% ';
|
|
159
|
+
if (!dataIndex || !datasetIndex) {
|
|
160
|
+
return '';
|
|
161
|
+
}
|
|
162
|
+
const rawdata =
|
|
163
|
+
barDataProps.datasets[datasetIndex].data[dataIndex];
|
|
164
|
+
const data = formatWithThousandsSeprators(rawdata.amount);
|
|
165
|
+
return percent + data + rawdata.amountUnit;
|
|
166
|
+
};
|
|
167
|
+
|
|
168
|
+
const getChartLabels = (indexOfValueToHide: number | null) => {
|
|
169
|
+
const labels = Object.assign([], barDataProps.labels);
|
|
170
|
+
if (indexOfValueToHide) {
|
|
171
|
+
labels.splice(indexOfValueToHide, 1);
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
return labels.map((label: string) => label);
|
|
175
|
+
};
|
|
176
|
+
|
|
177
|
+
const options = computed(() => ({
|
|
178
|
+
// eslint-disable-next-line
|
|
179
|
+
onHover: getOnHoverOptions(),
|
|
180
|
+
elements: {
|
|
181
|
+
bar: {
|
|
182
|
+
borderSkipped: false
|
|
183
|
+
}
|
|
184
|
+
},
|
|
185
|
+
plugins: {
|
|
186
|
+
responsive: true,
|
|
187
|
+
maintainAspectRatio: false,
|
|
188
|
+
legend: {
|
|
189
|
+
display: false,
|
|
190
|
+
},
|
|
191
|
+
title: {
|
|
192
|
+
display: false
|
|
193
|
+
},
|
|
194
|
+
tooltip: {
|
|
195
|
+
enabled: false,
|
|
196
|
+
position: 'nearest' as const,
|
|
197
|
+
external: function (context: Context) {
|
|
198
|
+
new GenericTooltipService().createTooltip(
|
|
199
|
+
context,
|
|
200
|
+
getTooltipData,
|
|
201
|
+
{
|
|
202
|
+
chartType: TooltipChartType.BAR_CHART,
|
|
203
|
+
firstLineLabel: xValue,
|
|
204
|
+
secondLineLabel: yValue
|
|
205
|
+
}
|
|
206
|
+
);
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
},
|
|
210
|
+
scales: {
|
|
211
|
+
x: {
|
|
212
|
+
stacked: true,
|
|
213
|
+
},
|
|
214
|
+
y: {
|
|
215
|
+
stacked: true,
|
|
216
|
+
ticks: {
|
|
217
|
+
callback: function (val: string | number) {
|
|
218
|
+
return formatTicks(val as number, barDataProps.unit);
|
|
219
|
+
},
|
|
220
|
+
maxTicksLimit: 8,
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
}));
|
|
225
|
+
|
|
226
|
+
const htmlLegendPlugin = privateGetHtmlLegendPlugin(legendContainer, selectMode);
|
|
227
|
+
|
|
228
|
+
watch(onHoverIndex, () => {
|
|
229
|
+
reloadChart();
|
|
230
|
+
}, { deep: true });
|
|
231
|
+
</script>
|
|
232
|
+
|
|
233
|
+
<style scoped>
|
|
234
|
+
.container {
|
|
235
|
+
-moz-osx-font-smoothing: grayscale;
|
|
236
|
+
-webkit-font-smoothing: antialiased;
|
|
237
|
+
font-weight: 400;
|
|
238
|
+
font-family: 'Roboto', sans-serif;
|
|
239
|
+
}
|
|
240
|
+
.main {
|
|
241
|
+
display: flex;
|
|
242
|
+
flex-direction: column;
|
|
243
|
+
justify-content: center;
|
|
244
|
+
align-items: center;
|
|
245
|
+
margin-bottom: 20px;
|
|
246
|
+
}
|
|
247
|
+
</style>
|