@mozaic-ds/chart 0.1.0-beta.4 → 0.1.0-beta.6
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/dist/mozaic-chart.js +1809 -1624
- package/dist/mozaic-chart.umd.cjs +11 -11
- package/dist/style.css +1 -1
- package/package.json +15 -8
- package/src/components/bar/BarChart.stories.ts +7 -10
- package/src/components/bar/BarChart.vue +194 -130
- package/src/components/doughnut/DoughnutChart.stories.ts +1 -0
- package/src/components/doughnut/DoughnutChart.vue +155 -99
- package/src/components/line/LineChart.vue +293 -257
- package/src/components/radar/RadarChart.stories.ts +2 -2
- package/src/components/radar/RadarChart.vue +204 -146
- package/src/services/DoughnutChartFunctions.ts +97 -56
- package/src/services/RadarChartFunctions.ts +13 -11
- package/src/stories/Changelog.mdx +6 -0
- package/src/stories/Contributing.mdx +101 -0
- package/src/stories/GettingStarted.mdx +92 -0
- package/src/stories/SupportAndOnboarding.mdx +44 -0
package/dist/style.css
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
.mc-checkbox{align-items:center;display:flex}.mc-checkbox__label{font-size:1rem;line-height:1.125;cursor:pointer;margin-left:.5rem;color:#000}.mc-checkbox__input{font-family:LeroyMerlin,sans-serif;font-weight:400;box-sizing:border-box;outline:none;-webkit-appearance:none;-moz-appearance:none;appearance:none;padding:0;margin:0;box-shadow:none;border:none;min-width:20px;min-height:20px;width:1.25rem;height:1.25rem;border-radius:4px;border:2px solid #666666;background-color:#fff;position:relative;transition:all .2s ease;cursor:pointer}.mc-checkbox__input[type=number]::-webkit-inner-spin-button,.mc-checkbox__input[type=number]::-webkit-outer-spin-button{-webkit-appearance:none;-moz-appearance:none;appearance:none;margin:0}.mc-checkbox__input[type=number]{-moz-appearance:textfield}.mc-checkbox__input[type=search]::-webkit-search-decoration:hover,.mc-checkbox__input[type=search]::-webkit-search-cancel-button:hover{cursor:pointer}.mc-checkbox__input::-ms-check{background-color:#fff;border:2px solid #666666;border-radius:4px;color:#fff}.mc-checkbox__input:hover{border-color:#191919}.mc-checkbox__input:hover::-ms-check{border-color:#191919}.mc-checkbox__input:focus{box-shadow:0 0 0 .125rem #fff,0 0 0 .25rem #0b96cc}.mc-checkbox__input:focus::-ms-check{box-shadow:0 0 0 .125rem #fff,0 0 0 .25rem #0b96cc}.mc-checkbox__input:checked,.mc-checkbox__input:indeterminate{background-color:#46a610;border-color:#46a610;background-size:1rem 1rem}.mc-checkbox__input:checked{background-image:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' height='1rem' width='1rem' fill='%23ffffff' viewBox='0 0 16 16'%3E%3Cpath d='M7.63 11.21a1 1 0 0 1-1.38 0l-2.92-2.6a1 1 0 1 1 1.34-1.48l2.22 2 4.41-4.34a1 1 0 1 1 1.4 1.42z'/%3E%3C/svg%3E");background-position:center center}.mc-checkbox__input:checked::-ms-check{background-color:#46a610;border-color:#46a610}.mc-checkbox__input:checked:hover:not(:disabled){border-color:#035010}.mc-checkbox__input:checked:hover:not(:disabled)::-ms-check{border-color:#035010}.mc-checkbox__input:indeterminate{background-image:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' height='1rem' width='1rem' fill='%23ffffff' viewBox='0 0 16 16'%3E%3Cpath d='M12 9H4a1 1 0 010-2h8a1 1 0 010 2z'/%3E%3C/svg%3E")}.mc-checkbox__input:disabled{background-color:#e6e6e6;border-color:#e6e6e6;cursor:not-allowed}.mc-checkbox__input:disabled::-ms-check{background-color:#e6e6e6;border-color:#e6e6e6}.mc-checkbox__input:disabled:checked{background-image:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' height='1rem' width='1rem' fill='%23999999' viewBox='0 0 16 16'%3E%3Cpath d='M7.63 11.21a1 1 0 0 1-1.38 0l-2.92-2.6a1 1 0 1 1 1.34-1.48l2.22 2 4.41-4.34a1 1 0 1 1 1.4 1.42z'/%3E%3C/svg%3E")}.mc-checkbox__input:disabled:indeterminate{background-image:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' height='1rem' width='1rem' fill='%23999999' viewBox='0 0 16 16'%3E%3Cpath d='M12 9H4a1 1 0 010-2h8a1 1 0 010 2z'/%3E%3C/svg%3E")}.mc-checkbox__input:disabled+.mc-checkbox__label{color:gray}.mc-checkbox__input.is-invalid{border-color:#c61112}.mc-checkbox__input.is-invalid::-ms-check{border-color:#c61112}.mc-checkbox__input.is-invalid:hover{border-color:#530000}.mc-checkbox__input.is-invalid:hover::-ms-check{border-color:#530000}.container[data-v-
|
|
1
|
+
.mc-checkbox{align-items:center;display:flex}.mc-checkbox__label{font-size:1rem;line-height:1.125;cursor:pointer;margin-left:.5rem;color:#000}.mc-checkbox__input{font-family:LeroyMerlin,sans-serif;font-weight:400;box-sizing:border-box;outline:none;-webkit-appearance:none;-moz-appearance:none;appearance:none;padding:0;margin:0;box-shadow:none;border:none;min-width:20px;min-height:20px;width:1.25rem;height:1.25rem;border-radius:4px;border:2px solid #666666;background-color:#fff;position:relative;transition:all .2s ease;cursor:pointer}.mc-checkbox__input[type=number]::-webkit-inner-spin-button,.mc-checkbox__input[type=number]::-webkit-outer-spin-button{-webkit-appearance:none;-moz-appearance:none;appearance:none;margin:0}.mc-checkbox__input[type=number]{-moz-appearance:textfield}.mc-checkbox__input[type=search]::-webkit-search-decoration:hover,.mc-checkbox__input[type=search]::-webkit-search-cancel-button:hover{cursor:pointer}.mc-checkbox__input::-ms-check{background-color:#fff;border:2px solid #666666;border-radius:4px;color:#fff}.mc-checkbox__input:hover{border-color:#191919}.mc-checkbox__input:hover::-ms-check{border-color:#191919}.mc-checkbox__input:focus{box-shadow:0 0 0 .125rem #fff,0 0 0 .25rem #0b96cc}.mc-checkbox__input:focus::-ms-check{box-shadow:0 0 0 .125rem #fff,0 0 0 .25rem #0b96cc}.mc-checkbox__input:checked,.mc-checkbox__input:indeterminate{background-color:#46a610;border-color:#46a610;background-size:1rem 1rem}.mc-checkbox__input:checked{background-image:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' height='1rem' width='1rem' fill='%23ffffff' viewBox='0 0 16 16'%3E%3Cpath d='M7.63 11.21a1 1 0 0 1-1.38 0l-2.92-2.6a1 1 0 1 1 1.34-1.48l2.22 2 4.41-4.34a1 1 0 1 1 1.4 1.42z'/%3E%3C/svg%3E");background-position:center center}.mc-checkbox__input:checked::-ms-check{background-color:#46a610;border-color:#46a610}.mc-checkbox__input:checked:hover:not(:disabled){border-color:#035010}.mc-checkbox__input:checked:hover:not(:disabled)::-ms-check{border-color:#035010}.mc-checkbox__input:indeterminate{background-image:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' height='1rem' width='1rem' fill='%23ffffff' viewBox='0 0 16 16'%3E%3Cpath d='M12 9H4a1 1 0 010-2h8a1 1 0 010 2z'/%3E%3C/svg%3E")}.mc-checkbox__input:disabled{background-color:#e6e6e6;border-color:#e6e6e6;cursor:not-allowed}.mc-checkbox__input:disabled::-ms-check{background-color:#e6e6e6;border-color:#e6e6e6}.mc-checkbox__input:disabled:checked{background-image:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' height='1rem' width='1rem' fill='%23999999' viewBox='0 0 16 16'%3E%3Cpath d='M7.63 11.21a1 1 0 0 1-1.38 0l-2.92-2.6a1 1 0 1 1 1.34-1.48l2.22 2 4.41-4.34a1 1 0 1 1 1.4 1.42z'/%3E%3C/svg%3E")}.mc-checkbox__input:disabled:indeterminate{background-image:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' height='1rem' width='1rem' fill='%23999999' viewBox='0 0 16 16'%3E%3Cpath d='M12 9H4a1 1 0 010-2h8a1 1 0 010 2z'/%3E%3C/svg%3E")}.mc-checkbox__input:disabled+.mc-checkbox__label{color:gray}.mc-checkbox__input.is-invalid{border-color:#c61112}.mc-checkbox__input.is-invalid::-ms-check{border-color:#c61112}.mc-checkbox__input.is-invalid:hover{border-color:#530000}.mc-checkbox__input.is-invalid:hover::-ms-check{border-color:#530000}.container[data-v-a434559f]{-moz-osx-font-smoothing:grayscale;-webkit-font-smoothing:antialiased;font-weight:400;font-family:Roboto,sans-serif}.main[data-v-a434559f]{display:flex;flex-direction:column;justify-content:center;align-items:center;margin-bottom:20px}.container[data-v-b01e346c]{-moz-osx-font-smoothing:grayscale;-webkit-font-smoothing:antialiased;font-weight:400;font-family:Roboto,sans-serif}.main[data-v-b01e346c]{display:flex;flex-direction:column;justify-content:center;align-items:center}.container[data-v-e7d1ba6e]{-moz-osx-font-smoothing:grayscale;-webkit-font-smoothing:antialiased;font-weight:400;font-family:Roboto,sans-serif}.main[data-v-e7d1ba6e]{display:flex;flex-direction:column;justify-content:center;align-items:center;margin-bottom:20px}.container[data-v-06bd1f32]{-moz-osx-font-smoothing:grayscale;-webkit-font-smoothing:antialiased;font-weight:400;font-family:Roboto,sans-serif}.main[data-v-06bd1f32]{height:600px;display:flex;flex-direction:column;justify-content:center;align-items:center}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mozaic-ds/chart",
|
|
3
|
-
"version": "0.1.0-beta.
|
|
3
|
+
"version": "0.1.0-beta.6",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"build": "vue-tsc && vite build",
|
|
@@ -45,14 +45,18 @@
|
|
|
45
45
|
},
|
|
46
46
|
"devDependencies": {
|
|
47
47
|
"@babel/core": "^7.22.10",
|
|
48
|
+
"@code-hike/mdx": "^0.9.0",
|
|
49
|
+
"@geometricpanda/storybook-addon-badges": "^2.0.0",
|
|
48
50
|
"@release-it/conventional-changelog": "^7.0.0",
|
|
49
|
-
"@storybook/addon-
|
|
50
|
-
"@storybook/addon-
|
|
51
|
-
"@storybook/addon-
|
|
52
|
-
"@storybook/
|
|
51
|
+
"@storybook/addon-docs": "^7.3.2",
|
|
52
|
+
"@storybook/addon-essentials": "^7.3.2",
|
|
53
|
+
"@storybook/addon-interactions": "^7.3.2",
|
|
54
|
+
"@storybook/addon-links": "^7.3.2",
|
|
55
|
+
"@storybook/blocks": "^7.3.2",
|
|
56
|
+
"@storybook/design-system": "^7.15.15",
|
|
53
57
|
"@storybook/testing-library": "^0.2.0",
|
|
54
|
-
"@storybook/vue3": "^7.3.
|
|
55
|
-
"@storybook/vue3-vite": "^7.3.
|
|
58
|
+
"@storybook/vue3": "^7.3.2",
|
|
59
|
+
"@storybook/vue3-vite": "^7.3.2",
|
|
56
60
|
"@vitejs/plugin-vue": "^4.2.3",
|
|
57
61
|
"@vitest/coverage-v8": "^0.34.1",
|
|
58
62
|
"@vue/test-utils": "^2.4.1",
|
|
@@ -60,10 +64,13 @@
|
|
|
60
64
|
"chromatic": "^6.22.0",
|
|
61
65
|
"dotenv-cli": "^7.2.1",
|
|
62
66
|
"jsdom": "^22.1.0",
|
|
67
|
+
"mdx-mermaid": "^2.0.0",
|
|
68
|
+
"mermaid": "^10.3.1",
|
|
63
69
|
"react": "^18.2.0",
|
|
64
70
|
"react-dom": "^18.2.0",
|
|
65
71
|
"release-it": "^16.1.3",
|
|
66
|
-
"
|
|
72
|
+
"remark-gfm": "^3.0.1",
|
|
73
|
+
"storybook": "^7.3.2",
|
|
67
74
|
"typescript": "^5.1.6",
|
|
68
75
|
"vite": "^4.4.9",
|
|
69
76
|
"vitest": "^0.34.1",
|
|
@@ -15,11 +15,10 @@ export const Default = {
|
|
|
15
15
|
args: {
|
|
16
16
|
width: "500px",
|
|
17
17
|
height: "400px",
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
secondTooltip: "content2",
|
|
18
|
+
tooltipFirstLineLabel: "content",
|
|
19
|
+
tooltipSecondLineLabel: "content2",
|
|
21
20
|
disableAccessibility: false,
|
|
22
|
-
newPatternsOrder: [0,4,1,2,3,5],
|
|
21
|
+
newPatternsOrder: [0, 4, 1, 2, 3, 5],
|
|
23
22
|
labels: ["Data One", "Data Two", "Data Three"],
|
|
24
23
|
colourSet: 0,
|
|
25
24
|
datasets: [
|
|
@@ -72,9 +71,8 @@ export const MultipleData = {
|
|
|
72
71
|
args: {
|
|
73
72
|
width: "700px",
|
|
74
73
|
height: "400px",
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
secondTooltip: "content2",
|
|
74
|
+
tooltipFirstLineLabel: "content",
|
|
75
|
+
tooltipSecondLineLabel: "content2",
|
|
78
76
|
disableAccessibility: false,
|
|
79
77
|
labels: [
|
|
80
78
|
"Data One",
|
|
@@ -231,10 +229,9 @@ export const StackedBarChart = {
|
|
|
231
229
|
args: {
|
|
232
230
|
width: "700px",
|
|
233
231
|
height: "400px",
|
|
234
|
-
|
|
235
|
-
|
|
232
|
+
tooltipFirstLineLabel: "content",
|
|
233
|
+
tooltipSecondLineLabel: "content2",
|
|
236
234
|
disableAccessibility: false,
|
|
237
|
-
rawTitle: "Stacked Bar Chart Title",
|
|
238
235
|
stacked: true,
|
|
239
236
|
labels: ["Category One", "Category Two", "Category Three"],
|
|
240
237
|
colourSet: 3,
|
|
@@ -4,13 +4,12 @@
|
|
|
4
4
|
<Bar
|
|
5
5
|
v-if="chartData"
|
|
6
6
|
ref="barChartRef"
|
|
7
|
+
:id="chartId"
|
|
7
8
|
:data="chartData"
|
|
8
9
|
:options="options"
|
|
9
10
|
:plugins="htmlLegendPlugin"
|
|
10
|
-
:
|
|
11
|
-
:
|
|
12
|
-
:cssClasses:="cssClasses"
|
|
13
|
-
:styles="styles"
|
|
11
|
+
:class="cssClasses"
|
|
12
|
+
:style="[{ width, height }, styles]"
|
|
14
13
|
/>
|
|
15
14
|
</div>
|
|
16
15
|
<div ref="legendContainer" />
|
|
@@ -19,16 +18,28 @@
|
|
|
19
18
|
|
|
20
19
|
<script setup lang="ts">
|
|
21
20
|
import { computed, ref, watch, PropType } from 'vue';
|
|
22
|
-
import type { Ref } from 'vue';
|
|
23
21
|
import { Bar, Chart } from 'vue-chartjs';
|
|
22
|
+
import type { Ref } from 'vue';
|
|
24
23
|
import barChartFunctions from '../../services/BarChartFunctions';
|
|
25
24
|
import type { Context } from '../../services/GenericTooltipService';
|
|
26
25
|
import { GenericTooltipService } from '../../services/GenericTooltipService';
|
|
27
26
|
import { TooltipChartType } from '../../types/TooltipChartType';
|
|
28
|
-
import {
|
|
29
|
-
|
|
27
|
+
import {
|
|
28
|
+
formatTicks,
|
|
29
|
+
formatWithThousandsSeprators,
|
|
30
|
+
} from '../../services/FormatUtilities';
|
|
31
|
+
import {
|
|
32
|
+
BarElement,
|
|
33
|
+
CategoryScale,
|
|
34
|
+
Chart as ChartJS,
|
|
35
|
+
Legend,
|
|
36
|
+
LinearScale,
|
|
37
|
+
Title,
|
|
38
|
+
Tooltip,
|
|
39
|
+
Plugin,
|
|
40
|
+
} from 'chart.js';
|
|
30
41
|
import { ButtonName } from '../../types/ButtonName';
|
|
31
|
-
import { BarData } from
|
|
42
|
+
import { BarData } from '../../types/BarData';
|
|
32
43
|
import ChartDesign from '../../services/patterns/ChartDesign';
|
|
33
44
|
|
|
34
45
|
ChartJS.register(
|
|
@@ -40,104 +51,145 @@ ChartJS.register(
|
|
|
40
51
|
LinearScale
|
|
41
52
|
);
|
|
42
53
|
|
|
43
|
-
const {
|
|
44
|
-
colourSets,
|
|
45
|
-
patternsStandardList
|
|
46
|
-
} = ChartDesign();
|
|
54
|
+
const { colourSets, patternsStandardList } = ChartDesign();
|
|
47
55
|
|
|
48
56
|
const legendContainer = ref(null);
|
|
49
57
|
const selectMode = ref(false);
|
|
50
58
|
const barDataProps = defineProps({
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
59
|
+
/**
|
|
60
|
+
* Value of the id attribute present on the <canvas> tag element the chart
|
|
61
|
+
*/
|
|
62
|
+
chartId: {
|
|
63
|
+
type: String,
|
|
64
|
+
default: 'radar-chart',
|
|
65
|
+
},
|
|
66
|
+
/**
|
|
67
|
+
* Unit of values on canvas Y axis
|
|
68
|
+
*/
|
|
69
|
+
unit: {
|
|
70
|
+
type: String,
|
|
71
|
+
default: '%',
|
|
72
|
+
},
|
|
73
|
+
/**
|
|
74
|
+
* Labels used to label the index axis (default x axes). See [Data structures documentation](https://www.chartjs.org/docs/latest/general/data-structures.html)
|
|
75
|
+
*/
|
|
76
|
+
labels: {
|
|
77
|
+
type: Array as PropType<string[]>,
|
|
78
|
+
default: () => [],
|
|
79
|
+
},
|
|
80
|
+
/**
|
|
81
|
+
* Used to choose the colour set of the charts as defined in the Figma prototypes.
|
|
82
|
+
* 7 colour sets are currently defined:
|
|
83
|
+
* - Default 0 corresponds to the current one
|
|
84
|
+
* - 1 to 6 corresponds to the "new" [colour sets](https://www.figma.com/file/Hn6PyvnR385Ta0XN3KqOI9/04.-Dataviz---Documentation-(read-only)?type=design&node-id=1-69316&mode=design&t=sDytQ5BipsryWkuA-0)
|
|
85
|
+
* Note: All the sets are defined in /src/services/patterns/ChartDesign.ts
|
|
86
|
+
*/
|
|
87
|
+
colourSet: {
|
|
88
|
+
type: Number,
|
|
89
|
+
default: 0,
|
|
90
|
+
},
|
|
91
|
+
/**
|
|
92
|
+
* 6 patterns exist and are not randomly given but follow the order defined in [patternsStandardList](/src/services/patterns/ChartDesign.ts)
|
|
93
|
+
* Additionally, a pattern has only one possible colour per colour set as defined in the Figma prototype.
|
|
94
|
+
* In some use cases, the chart may need to show a different orders of these patterns, this can be changed using the props newPatternsOrder
|
|
95
|
+
*/
|
|
96
|
+
newPatternsOrder: {
|
|
97
|
+
type: Array as PropType<number[]>,
|
|
98
|
+
default: () => [0, 1, 2, 3, 4, 5],
|
|
99
|
+
},
|
|
100
|
+
/**
|
|
101
|
+
* Value of the `datasets` key present in the `data` object passed to the Chart config
|
|
102
|
+
*/
|
|
103
|
+
datasets: {
|
|
104
|
+
type: Array as PropType<BarData[]>,
|
|
105
|
+
default: () => [],
|
|
106
|
+
},
|
|
107
|
+
/**
|
|
108
|
+
* Value of the `width` css property used to define the width of the <canvas> element
|
|
109
|
+
*/
|
|
110
|
+
width: {
|
|
111
|
+
type: String,
|
|
112
|
+
default: '400px',
|
|
113
|
+
},
|
|
114
|
+
/**
|
|
115
|
+
* Value of the `height` css property used to define the height of the <canvas> element
|
|
116
|
+
*/
|
|
117
|
+
height: {
|
|
118
|
+
type: String,
|
|
119
|
+
default: '300px',
|
|
120
|
+
},
|
|
121
|
+
/**
|
|
122
|
+
* Add custom CSS classes to the <canvas> element
|
|
123
|
+
*/
|
|
124
|
+
cssClasses: {
|
|
125
|
+
type: String,
|
|
126
|
+
default: undefined,
|
|
127
|
+
},
|
|
128
|
+
/**
|
|
129
|
+
* Add custom CSS styles to the <canvas> element
|
|
130
|
+
*/
|
|
131
|
+
styles: {
|
|
132
|
+
type: Object as PropType<Partial<CSSStyleDeclaration>>,
|
|
133
|
+
default: () => {},
|
|
134
|
+
},
|
|
135
|
+
/**
|
|
136
|
+
* Value of the `plugins` key passed to the Chart config
|
|
137
|
+
*/
|
|
138
|
+
plugins: {
|
|
139
|
+
type: Array as PropType<Plugin<'bar'>[]>,
|
|
140
|
+
default: () => [],
|
|
141
|
+
},
|
|
142
|
+
/**
|
|
143
|
+
* Activates "stacked" mode
|
|
144
|
+
*/
|
|
145
|
+
stacked: {
|
|
146
|
+
type: Boolean,
|
|
147
|
+
default: false,
|
|
148
|
+
},
|
|
149
|
+
/**
|
|
150
|
+
* Disable accessibility patterns
|
|
151
|
+
*/
|
|
152
|
+
disableAccessibility: {
|
|
153
|
+
type: Boolean,
|
|
154
|
+
default: false,
|
|
155
|
+
},
|
|
156
|
+
/**
|
|
157
|
+
* Label of the first line in the Tooltip
|
|
158
|
+
*/
|
|
159
|
+
tooltipFirstLineLabel: {
|
|
160
|
+
type: String,
|
|
161
|
+
default: 'content',
|
|
162
|
+
},
|
|
163
|
+
/**
|
|
164
|
+
* Label of the second line in the Tooltip
|
|
165
|
+
*/
|
|
166
|
+
tooltipSecondLineLabel: {
|
|
167
|
+
type: String,
|
|
168
|
+
default: 'content2',
|
|
169
|
+
},
|
|
170
|
+
});
|
|
125
171
|
|
|
126
172
|
// computed to make the colors list reactive to the props
|
|
127
173
|
const patternsColors = computed(() => {
|
|
128
174
|
return barDataProps.newPatternsOrder.length !== patternsStandardList.length
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
return colourSets[barDataProps.colourSet][id]
|
|
175
|
+
? colourSets[barDataProps.colourSet]
|
|
176
|
+
: barDataProps.newPatternsOrder.map((id) => {
|
|
177
|
+
return colourSets[barDataProps.colourSet][id];
|
|
132
178
|
});
|
|
133
179
|
});
|
|
134
180
|
|
|
135
181
|
// computed to make the patterns list reactive to the props
|
|
136
|
-
const patternsOrderedList = computed(() => {
|
|
137
|
-
|
|
138
|
-
|
|
182
|
+
const patternsOrderedList = computed(() => {
|
|
183
|
+
return barDataProps.newPatternsOrder.length !== patternsStandardList.length
|
|
184
|
+
? patternsStandardList
|
|
185
|
+
: barDataProps.newPatternsOrder.map((id) => {
|
|
186
|
+
return patternsStandardList[id];
|
|
187
|
+
});
|
|
188
|
+
});
|
|
139
189
|
|
|
140
|
-
const disablePattern = computed(() => {
|
|
190
|
+
const disablePattern = computed(() => {
|
|
191
|
+
return barDataProps.disableAccessibility;
|
|
192
|
+
});
|
|
141
193
|
|
|
142
194
|
const {
|
|
143
195
|
onHoverIndex,
|
|
@@ -156,15 +208,14 @@ const chartData = computed(() => {
|
|
|
156
208
|
datasets: getStackedDatasets(
|
|
157
209
|
barDataProps.datasets.map((dataset, index) => ({
|
|
158
210
|
data: getChartData(index, indexOfOthersLabelIfNull.value),
|
|
159
|
-
label: barDataProps.datasets[index].label
|
|
160
|
-
|
|
161
|
-
),
|
|
211
|
+
label: barDataProps.datasets[index].label,
|
|
212
|
+
})),
|
|
162
213
|
barDataProps.stacked,
|
|
163
214
|
barDataProps.disableAccessibility,
|
|
164
215
|
patternsColors.value,
|
|
165
216
|
patternsOrderedList.value,
|
|
166
217
|
0
|
|
167
|
-
)
|
|
218
|
+
),
|
|
168
219
|
};
|
|
169
220
|
});
|
|
170
221
|
|
|
@@ -172,23 +223,29 @@ let xValue: string;
|
|
|
172
223
|
let yValue: string;
|
|
173
224
|
|
|
174
225
|
const gettooltipContent = (): void => {
|
|
175
|
-
|
|
176
|
-
|
|
226
|
+
xValue = barDataProps.tooltipFirstLineLabel;
|
|
227
|
+
yValue = barDataProps.tooltipSecondLineLabel;
|
|
177
228
|
};
|
|
178
229
|
|
|
179
230
|
const indexOfOthersLabelIfNull: Ref<number | null> = computed(() => {
|
|
180
231
|
const labels = barDataProps.labels;
|
|
181
232
|
if (labels.includes('other')) {
|
|
182
233
|
const index = labels.indexOf('other');
|
|
183
|
-
if (
|
|
184
|
-
barDataProps.datasets[
|
|
234
|
+
if (
|
|
235
|
+
barDataProps.datasets[0].data[index].rate + '' === '0' &&
|
|
236
|
+
barDataProps.datasets[1].data[index].rate + '' === '0'
|
|
237
|
+
) {
|
|
185
238
|
return index;
|
|
186
239
|
}
|
|
187
240
|
}
|
|
188
241
|
return null;
|
|
189
242
|
});
|
|
190
243
|
|
|
191
|
-
const getChartData = (
|
|
244
|
+
const getChartData = (
|
|
245
|
+
index: number,
|
|
246
|
+
indexOfValueToHide: number | null,
|
|
247
|
+
isStacked: boolean = false
|
|
248
|
+
) => {
|
|
192
249
|
const data = Object.assign([], barDataProps.datasets[index].data);
|
|
193
250
|
if (indexOfValueToHide && indexOfOthersLabelIfNull.value) {
|
|
194
251
|
data.splice(indexOfOthersLabelIfNull.value, 1);
|
|
@@ -198,15 +255,13 @@ const getChartData = (index: number, indexOfValueToHide: number | null, isStacke
|
|
|
198
255
|
};
|
|
199
256
|
|
|
200
257
|
const getTooltipData = (context: Context) => {
|
|
201
|
-
const datasetIndex = context.tooltip.dataPoints[0].datasetIndex;
|
|
202
|
-
const dataIndex = context.tooltip.dataPoints[0].dataIndex;
|
|
203
|
-
const percent =
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
const rawdata =
|
|
209
|
-
barDataProps.datasets[datasetIndex].data[dataIndex];
|
|
258
|
+
const datasetIndex = context.tooltip.dataPoints[0].datasetIndex as number;
|
|
259
|
+
const dataIndex = context.tooltip.dataPoints[0].dataIndex as number;
|
|
260
|
+
const percent =
|
|
261
|
+
parseFloat(
|
|
262
|
+
context.tooltip.body[0].lines[0].split(':')[1].replace(',', '.')
|
|
263
|
+
).toFixed(2) + '% ';
|
|
264
|
+
const rawdata = barDataProps.datasets[datasetIndex].data[dataIndex];
|
|
210
265
|
const data = formatWithThousandsSeprators(rawdata.amount);
|
|
211
266
|
return percent + data + rawdata.amountUnit;
|
|
212
267
|
};
|
|
@@ -225,8 +280,8 @@ const options = computed(() => ({
|
|
|
225
280
|
onHover: getOnHoverOptions(),
|
|
226
281
|
elements: {
|
|
227
282
|
bar: {
|
|
228
|
-
borderSkipped: false
|
|
229
|
-
}
|
|
283
|
+
borderSkipped: false,
|
|
284
|
+
},
|
|
230
285
|
},
|
|
231
286
|
plugins: {
|
|
232
287
|
responsive: true,
|
|
@@ -235,7 +290,7 @@ const options = computed(() => ({
|
|
|
235
290
|
display: false,
|
|
236
291
|
},
|
|
237
292
|
title: {
|
|
238
|
-
display: false
|
|
293
|
+
display: false,
|
|
239
294
|
},
|
|
240
295
|
tooltip: {
|
|
241
296
|
enabled: false,
|
|
@@ -247,14 +302,14 @@ const options = computed(() => ({
|
|
|
247
302
|
{
|
|
248
303
|
chartType: TooltipChartType.BAR_CHART,
|
|
249
304
|
firstLineLabel: xValue,
|
|
250
|
-
secondLineLabel: yValue
|
|
305
|
+
secondLineLabel: yValue,
|
|
251
306
|
},
|
|
252
307
|
patternsColors.value,
|
|
253
308
|
patternsOrderedList.value,
|
|
254
309
|
barDataProps.disableAccessibility
|
|
255
310
|
);
|
|
256
|
-
}
|
|
257
|
-
}
|
|
311
|
+
},
|
|
312
|
+
},
|
|
258
313
|
},
|
|
259
314
|
scales: {
|
|
260
315
|
x: {
|
|
@@ -267,24 +322,33 @@ const options = computed(() => ({
|
|
|
267
322
|
return formatTicks(val as number, barDataProps.unit);
|
|
268
323
|
},
|
|
269
324
|
maxTicksLimit: 8,
|
|
270
|
-
}
|
|
271
|
-
}
|
|
272
|
-
}
|
|
325
|
+
},
|
|
326
|
+
},
|
|
327
|
+
},
|
|
273
328
|
}));
|
|
274
329
|
|
|
275
|
-
const htmlLegendPlugin = ref(
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
330
|
+
const htmlLegendPlugin = ref(
|
|
331
|
+
privateGetHtmlLegendPlugin(
|
|
332
|
+
legendContainer,
|
|
333
|
+
selectMode,
|
|
334
|
+
disablePattern,
|
|
335
|
+
patternsColors,
|
|
336
|
+
patternsOrderedList
|
|
337
|
+
)
|
|
338
|
+
);
|
|
282
339
|
|
|
340
|
+
watch(
|
|
341
|
+
onHoverIndex,
|
|
342
|
+
() => {
|
|
343
|
+
reloadChart();
|
|
344
|
+
},
|
|
345
|
+
{ deep: true }
|
|
346
|
+
);
|
|
283
347
|
</script>
|
|
284
348
|
|
|
285
349
|
<style lang="scss">
|
|
286
|
-
@import
|
|
287
|
-
@import
|
|
350
|
+
@import 'settings-tools/all-settings';
|
|
351
|
+
@import 'components/c.checkbox';
|
|
288
352
|
</style>
|
|
289
353
|
|
|
290
354
|
<style scoped>
|
|
@@ -301,4 +365,4 @@ watch(onHoverIndex, () => {
|
|
|
301
365
|
align-items: center;
|
|
302
366
|
margin-bottom: 20px;
|
|
303
367
|
}
|
|
304
|
-
</style>
|
|
368
|
+
</style>
|