@mozaic-ds/chart 0.1.0-beta.1 → 0.1.0-beta.10
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 +2796 -2127
- package/dist/mozaic-chart.umd.cjs +11 -11
- package/dist/style.css +1 -1
- package/package.json +25 -11
- package/src/components/bar/BarChart.stories.ts +7 -10
- package/src/components/bar/BarChart.vue +212 -136
- package/src/components/bar/index.ts +8 -0
- package/src/components/doughnut/DoughnutChart.stories.ts +1 -0
- package/src/components/doughnut/DoughnutChart.vue +163 -100
- package/src/components/doughnut/index.ts +8 -0
- package/src/components/index.ts +4 -0
- package/src/components/line/LineChart.stories.ts +0 -1
- package/src/components/line/LineChart.vue +305 -257
- package/src/components/line/index.ts +8 -0
- package/src/components/mixed/MixedBarLineChart.stories.ts +87 -0
- package/src/components/mixed/MixedBarLineChart.vue +404 -0
- package/src/components/mixed/index.ts +8 -0
- package/src/components/radar/RadarChart.stories.ts +2 -2
- package/src/components/radar/RadarChart.vue +210 -149
- package/src/components/radar/index.ts +8 -0
- package/src/main.ts +2 -1
- package/src/plugin.ts +19 -0
- package/src/services/ChartsCommonLegend.ts +35 -23
- package/src/services/DoughnutChartFunctions.ts +101 -56
- package/src/services/FormatUtilities.ts +1 -1
- package/src/services/GenericTooltipService.ts +21 -7
- package/src/services/MixedBarLineFunctions.ts +280 -0
- 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/src/types/MixedBarLineData.ts +7 -0
- package/src/types/TooltipChartType.ts +1 -0
package/dist/style.css
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
.container[data-v-
|
|
1
|
+
.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: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: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")}.container[data-v-fae6dcc9]{-moz-osx-font-smoothing:grayscale;-webkit-font-smoothing:antialiased;font-weight:400;font-family:Roboto,sans-serif}.main[data-v-fae6dcc9]{display:flex;flex-direction:column;justify-content:center;align-items:center;margin-bottom:20px}.container[data-v-9f73f105]{-moz-osx-font-smoothing:grayscale;-webkit-font-smoothing:antialiased;font-weight:400;font-family:Roboto,sans-serif}.main[data-v-9f73f105]{display:flex;flex-direction:column;justify-content:center;align-items:center}.container[data-v-9a586c1a]{-moz-osx-font-smoothing:grayscale;-webkit-font-smoothing:antialiased;font-weight:400;font-family:Roboto,sans-serif}.main[data-v-9a586c1a]{display:flex;flex-direction:column;justify-content:center;align-items:center;margin-bottom:20px}.container[data-v-26475601]{-moz-osx-font-smoothing:grayscale;-webkit-font-smoothing:antialiased;font-weight:400;font-family:Roboto,sans-serif}.main[data-v-26475601]{height:600px;display:flex;flex-direction:column;justify-content:center;align-items:center}.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-0dd46b73]{-moz-osx-font-smoothing:grayscale;-webkit-font-smoothing:antialiased;font-weight:400;font-family:Roboto,sans-serif}.main[data-v-0dd46b73]{display:flex;flex-direction:column;justify-content:center;align-items:center;margin-bottom:20px}
|
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.10",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"build": "vue-tsc && vite build",
|
|
@@ -17,7 +17,8 @@
|
|
|
17
17
|
"release": "release-it",
|
|
18
18
|
"release:beta": "release-it --preRelease=beta",
|
|
19
19
|
"storybook": "storybook dev -p 6006",
|
|
20
|
-
"test": "vitest --run"
|
|
20
|
+
"test": "vitest --run",
|
|
21
|
+
"vitest": "vitest ChartsCommonLegend.test.ts"
|
|
21
22
|
},
|
|
22
23
|
"bugs": {
|
|
23
24
|
"url": "https://github.com/adeo/mozaic-chart/issues"
|
|
@@ -25,7 +26,9 @@
|
|
|
25
26
|
"homepage": "https://github.com/adeo/mozaic-chart#readme",
|
|
26
27
|
"files": [
|
|
27
28
|
"dist/*",
|
|
28
|
-
"src/*"
|
|
29
|
+
"src/*",
|
|
30
|
+
"types/*",
|
|
31
|
+
"*.d.ts"
|
|
29
32
|
],
|
|
30
33
|
"main": "./dist/mozaic-chart.umd.cjs",
|
|
31
34
|
"module": "./dist/mozaic-chart.js",
|
|
@@ -33,24 +36,32 @@
|
|
|
33
36
|
".": {
|
|
34
37
|
"import": "./dist/mozaic-chart.js",
|
|
35
38
|
"require": "./dist/mozaic-chart.umd.cjs"
|
|
39
|
+
},
|
|
40
|
+
"./dist/style.css": {
|
|
41
|
+
"import": "./dist/style.css",
|
|
42
|
+
"require": "./dist/style.css"
|
|
36
43
|
}
|
|
37
44
|
},
|
|
38
45
|
"dependencies": {
|
|
39
|
-
"@mozaic-ds/vue-3": "0.
|
|
46
|
+
"@mozaic-ds/vue-3": "0.50.0",
|
|
40
47
|
"chart.js": "^4.3.3",
|
|
41
48
|
"vue": "^3.2.41",
|
|
42
49
|
"vue-chartjs": "5.2.0"
|
|
43
50
|
},
|
|
44
51
|
"devDependencies": {
|
|
45
52
|
"@babel/core": "^7.22.10",
|
|
53
|
+
"@code-hike/mdx": "^0.9.0",
|
|
54
|
+
"@geometricpanda/storybook-addon-badges": "^2.0.0",
|
|
46
55
|
"@release-it/conventional-changelog": "^7.0.0",
|
|
47
|
-
"@storybook/addon-
|
|
48
|
-
"@storybook/addon-
|
|
49
|
-
"@storybook/addon-
|
|
50
|
-
"@storybook/
|
|
56
|
+
"@storybook/addon-docs": "^7.3.2",
|
|
57
|
+
"@storybook/addon-essentials": "^7.3.2",
|
|
58
|
+
"@storybook/addon-interactions": "^7.3.2",
|
|
59
|
+
"@storybook/addon-links": "^7.3.2",
|
|
60
|
+
"@storybook/blocks": "^7.3.2",
|
|
61
|
+
"@storybook/design-system": "^7.15.15",
|
|
51
62
|
"@storybook/testing-library": "^0.2.0",
|
|
52
|
-
"@storybook/vue3": "^7.3.
|
|
53
|
-
"@storybook/vue3-vite": "^7.3.
|
|
63
|
+
"@storybook/vue3": "^7.3.2",
|
|
64
|
+
"@storybook/vue3-vite": "^7.3.2",
|
|
54
65
|
"@vitejs/plugin-vue": "^4.2.3",
|
|
55
66
|
"@vitest/coverage-v8": "^0.34.1",
|
|
56
67
|
"@vue/test-utils": "^2.4.1",
|
|
@@ -58,10 +69,13 @@
|
|
|
58
69
|
"chromatic": "^6.22.0",
|
|
59
70
|
"dotenv-cli": "^7.2.1",
|
|
60
71
|
"jsdom": "^22.1.0",
|
|
72
|
+
"mdx-mermaid": "^2.0.0",
|
|
73
|
+
"mermaid": "^10.3.1",
|
|
61
74
|
"react": "^18.2.0",
|
|
62
75
|
"react-dom": "^18.2.0",
|
|
63
76
|
"release-it": "^16.1.3",
|
|
64
|
-
"
|
|
77
|
+
"remark-gfm": "^3.0.1",
|
|
78
|
+
"storybook": "^7.3.2",
|
|
65
79
|
"typescript": "^5.1.6",
|
|
66
80
|
"vite": "^4.4.9",
|
|
67
81
|
"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, cursor: 'pointer' }, styles]"
|
|
14
13
|
/>
|
|
15
14
|
</div>
|
|
16
15
|
<div ref="legendContainer" />
|
|
@@ -19,16 +18,27 @@
|
|
|
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
|
-
|
|
30
|
-
|
|
31
|
-
|
|
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';
|
|
41
|
+
import { BarData } from '../../types/BarData';
|
|
32
42
|
import ChartDesign from '../../services/patterns/ChartDesign';
|
|
33
43
|
|
|
34
44
|
ChartJS.register(
|
|
@@ -40,104 +50,145 @@ ChartJS.register(
|
|
|
40
50
|
LinearScale
|
|
41
51
|
);
|
|
42
52
|
|
|
43
|
-
const {
|
|
44
|
-
colourSets,
|
|
45
|
-
patternsStandardList
|
|
46
|
-
} = ChartDesign();
|
|
53
|
+
const { colourSets, patternsStandardList } = ChartDesign();
|
|
47
54
|
|
|
48
55
|
const legendContainer = ref(null);
|
|
49
56
|
const selectMode = ref(false);
|
|
50
57
|
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
|
-
|
|
58
|
+
/**
|
|
59
|
+
* Value of the id attribute present on the <canvas> tag element the chart
|
|
60
|
+
*/
|
|
61
|
+
chartId: {
|
|
62
|
+
type: String,
|
|
63
|
+
default: 'radar-chart',
|
|
64
|
+
},
|
|
65
|
+
/**
|
|
66
|
+
* Unit of values on canvas Y axis
|
|
67
|
+
*/
|
|
68
|
+
unit: {
|
|
69
|
+
type: String,
|
|
70
|
+
default: '%',
|
|
71
|
+
},
|
|
72
|
+
/**
|
|
73
|
+
* Labels used to label the index axis (default x axes). See [Data structures documentation](https://www.chartjs.org/docs/latest/general/data-structures.html)
|
|
74
|
+
*/
|
|
75
|
+
labels: {
|
|
76
|
+
type: Array as PropType<string[]>,
|
|
77
|
+
default: () => [],
|
|
78
|
+
},
|
|
79
|
+
/**
|
|
80
|
+
* Used to choose the colour set of the charts as defined in the Figma prototypes.
|
|
81
|
+
* 7 colour sets are currently defined:
|
|
82
|
+
* - Default 0 corresponds to the current one
|
|
83
|
+
* - 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)
|
|
84
|
+
* Note: All the sets are defined in /src/services/patterns/ChartDesign.ts
|
|
85
|
+
*/
|
|
86
|
+
colourSet: {
|
|
87
|
+
type: Number,
|
|
88
|
+
default: 0,
|
|
89
|
+
},
|
|
90
|
+
/**
|
|
91
|
+
* 6 patterns exist and are not randomly given but follow the order defined in [patternsStandardList](/src/services/patterns/ChartDesign.ts)
|
|
92
|
+
* Additionally, a pattern has only one possible colour per colour set as defined in the Figma prototype.
|
|
93
|
+
* In some use cases, the chart may need to show a different orders of these patterns, this can be changed using the props newPatternsOrder
|
|
94
|
+
*/
|
|
95
|
+
newPatternsOrder: {
|
|
96
|
+
type: Array as PropType<number[]>,
|
|
97
|
+
default: () => [0, 1, 2, 3, 4, 5],
|
|
98
|
+
},
|
|
99
|
+
/**
|
|
100
|
+
* Value of the `datasets` key present in the `data` object passed to the Chart config
|
|
101
|
+
*/
|
|
102
|
+
datasets: {
|
|
103
|
+
type: Array as PropType<BarData[]>,
|
|
104
|
+
default: () => [],
|
|
105
|
+
},
|
|
106
|
+
/**
|
|
107
|
+
* Value of the `width` css property used to define the width of the <canvas> element
|
|
108
|
+
*/
|
|
109
|
+
width: {
|
|
110
|
+
type: String,
|
|
111
|
+
default: '400px',
|
|
112
|
+
},
|
|
113
|
+
/**
|
|
114
|
+
* Value of the `height` css property used to define the height of the <canvas> element
|
|
115
|
+
*/
|
|
116
|
+
height: {
|
|
117
|
+
type: String,
|
|
118
|
+
default: '300px',
|
|
119
|
+
},
|
|
120
|
+
/**
|
|
121
|
+
* Add custom CSS classes to the <canvas> element
|
|
122
|
+
*/
|
|
123
|
+
cssClasses: {
|
|
124
|
+
type: String,
|
|
125
|
+
default: undefined,
|
|
126
|
+
},
|
|
127
|
+
/**
|
|
128
|
+
* Add custom CSS styles to the <canvas> element
|
|
129
|
+
*/
|
|
130
|
+
styles: {
|
|
131
|
+
type: Object as PropType<Partial<CSSStyleDeclaration>>,
|
|
132
|
+
default: () => {},
|
|
133
|
+
},
|
|
134
|
+
/**
|
|
135
|
+
* Value of the `plugins` key passed to the Chart config
|
|
136
|
+
*/
|
|
137
|
+
plugins: {
|
|
138
|
+
type: Array as PropType<Plugin<'bar'>[]>,
|
|
139
|
+
default: () => [],
|
|
140
|
+
},
|
|
141
|
+
/**
|
|
142
|
+
* Activates "stacked" mode
|
|
143
|
+
*/
|
|
144
|
+
stacked: {
|
|
145
|
+
type: Boolean,
|
|
146
|
+
default: false,
|
|
147
|
+
},
|
|
148
|
+
/**
|
|
149
|
+
* Disable accessibility patterns
|
|
150
|
+
*/
|
|
151
|
+
disableAccessibility: {
|
|
152
|
+
type: Boolean,
|
|
153
|
+
default: false,
|
|
154
|
+
},
|
|
155
|
+
/**
|
|
156
|
+
* Label of the first line in the Tooltip
|
|
157
|
+
*/
|
|
158
|
+
tooltipFirstLineLabel: {
|
|
159
|
+
type: String,
|
|
160
|
+
default: 'content',
|
|
161
|
+
},
|
|
162
|
+
/**
|
|
163
|
+
* Label of the second line in the Tooltip
|
|
164
|
+
*/
|
|
165
|
+
tooltipSecondLineLabel: {
|
|
166
|
+
type: String,
|
|
167
|
+
default: 'content2',
|
|
168
|
+
},
|
|
169
|
+
});
|
|
125
170
|
|
|
126
171
|
// computed to make the colors list reactive to the props
|
|
127
172
|
const patternsColors = computed(() => {
|
|
128
173
|
return barDataProps.newPatternsOrder.length !== patternsStandardList.length
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
return colourSets[barDataProps.colourSet][id]
|
|
174
|
+
? colourSets[barDataProps.colourSet]
|
|
175
|
+
: barDataProps.newPatternsOrder.map((id) => {
|
|
176
|
+
return colourSets[barDataProps.colourSet][id];
|
|
132
177
|
});
|
|
133
178
|
});
|
|
134
179
|
|
|
135
180
|
// computed to make the patterns list reactive to the props
|
|
136
|
-
const patternsOrderedList = computed(() => {
|
|
137
|
-
|
|
138
|
-
|
|
181
|
+
const patternsOrderedList = computed(() => {
|
|
182
|
+
return barDataProps.newPatternsOrder.length !== patternsStandardList.length
|
|
183
|
+
? patternsStandardList
|
|
184
|
+
: barDataProps.newPatternsOrder.map((id) => {
|
|
185
|
+
return patternsStandardList[id];
|
|
186
|
+
});
|
|
187
|
+
});
|
|
139
188
|
|
|
140
|
-
const disablePattern = computed(() => {
|
|
189
|
+
const disablePattern = computed(() => {
|
|
190
|
+
return barDataProps.disableAccessibility;
|
|
191
|
+
});
|
|
141
192
|
|
|
142
193
|
const {
|
|
143
194
|
onHoverIndex,
|
|
@@ -156,15 +207,14 @@ const chartData = computed(() => {
|
|
|
156
207
|
datasets: getStackedDatasets(
|
|
157
208
|
barDataProps.datasets.map((dataset, index) => ({
|
|
158
209
|
data: getChartData(index, indexOfOthersLabelIfNull.value),
|
|
159
|
-
label: barDataProps.datasets[index].label
|
|
160
|
-
|
|
161
|
-
),
|
|
210
|
+
label: barDataProps.datasets[index].label,
|
|
211
|
+
})),
|
|
162
212
|
barDataProps.stacked,
|
|
163
213
|
barDataProps.disableAccessibility,
|
|
164
214
|
patternsColors.value,
|
|
165
215
|
patternsOrderedList.value,
|
|
166
216
|
0
|
|
167
|
-
)
|
|
217
|
+
),
|
|
168
218
|
};
|
|
169
219
|
});
|
|
170
220
|
|
|
@@ -172,43 +222,52 @@ let xValue: string;
|
|
|
172
222
|
let yValue: string;
|
|
173
223
|
|
|
174
224
|
const gettooltipContent = (): void => {
|
|
175
|
-
|
|
176
|
-
|
|
225
|
+
xValue = barDataProps.tooltipFirstLineLabel;
|
|
226
|
+
yValue = barDataProps.tooltipSecondLineLabel;
|
|
177
227
|
};
|
|
178
228
|
|
|
179
229
|
const indexOfOthersLabelIfNull: Ref<number | null> = computed(() => {
|
|
180
230
|
const labels = barDataProps.labels;
|
|
181
231
|
if (labels.includes('other')) {
|
|
182
232
|
const index = labels.indexOf('other');
|
|
183
|
-
if (
|
|
184
|
-
barDataProps.datasets[
|
|
233
|
+
if (
|
|
234
|
+
barDataProps.datasets[0].data[index].rate + '' === '0' &&
|
|
235
|
+
barDataProps.datasets[1].data[index].rate + '' === '0'
|
|
236
|
+
) {
|
|
185
237
|
return index;
|
|
186
238
|
}
|
|
187
239
|
}
|
|
188
240
|
return null;
|
|
189
241
|
});
|
|
190
242
|
|
|
191
|
-
const getChartData = (
|
|
243
|
+
const getChartData = (
|
|
244
|
+
index: number,
|
|
245
|
+
indexOfValueToHide: number | null,
|
|
246
|
+
isStacked: boolean = false
|
|
247
|
+
) => {
|
|
192
248
|
const data = Object.assign([], barDataProps.datasets[index].data);
|
|
193
249
|
if (indexOfValueToHide && indexOfOthersLabelIfNull.value) {
|
|
194
250
|
data.splice(indexOfOthersLabelIfNull.value, 1);
|
|
195
251
|
}
|
|
196
252
|
|
|
197
|
-
return data.map((data: { rate
|
|
253
|
+
return data.map((data: { rate?: number, amount?: number}) =>
|
|
254
|
+
barDataProps.unit === '%' ? data.rate : data.amount
|
|
255
|
+
);
|
|
198
256
|
};
|
|
199
257
|
|
|
200
258
|
const getTooltipData = (context: Context) => {
|
|
201
|
-
const datasetIndex = context.tooltip.dataPoints[0].datasetIndex;
|
|
202
|
-
const dataIndex = context.tooltip.dataPoints[0].dataIndex;
|
|
203
|
-
const
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
const rawdata
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
259
|
+
const datasetIndex = context.tooltip.dataPoints[0].datasetIndex as number;
|
|
260
|
+
const dataIndex = context.tooltip.dataPoints[0].dataIndex as number;
|
|
261
|
+
const rate: string = context.tooltip.body[0].lines[0].split(':')[1];
|
|
262
|
+
const rawdata = barDataProps.datasets[datasetIndex].data[dataIndex];
|
|
263
|
+
const percent = rawdata.rate
|
|
264
|
+
? parseFloat(rate.replace(',', '.')).toFixed(2) + '% '
|
|
265
|
+
: '';
|
|
266
|
+
const amountUnit = rawdata.amountUnit ? rawdata.amountUnit : '';
|
|
267
|
+
const data = rawdata.amount
|
|
268
|
+
? formatWithThousandsSeprators(rawdata.amount)
|
|
269
|
+
: '';
|
|
270
|
+
return percent + (percent && data ? '/ ' : '') + data + amountUnit;
|
|
212
271
|
};
|
|
213
272
|
|
|
214
273
|
const getChartLabels = (indexOfValueToHide: number | null) => {
|
|
@@ -225,8 +284,8 @@ const options = computed(() => ({
|
|
|
225
284
|
onHover: getOnHoverOptions(),
|
|
226
285
|
elements: {
|
|
227
286
|
bar: {
|
|
228
|
-
borderSkipped: false
|
|
229
|
-
}
|
|
287
|
+
borderSkipped: false,
|
|
288
|
+
},
|
|
230
289
|
},
|
|
231
290
|
plugins: {
|
|
232
291
|
responsive: true,
|
|
@@ -235,7 +294,7 @@ const options = computed(() => ({
|
|
|
235
294
|
display: false,
|
|
236
295
|
},
|
|
237
296
|
title: {
|
|
238
|
-
display: false
|
|
297
|
+
display: false,
|
|
239
298
|
},
|
|
240
299
|
tooltip: {
|
|
241
300
|
enabled: false,
|
|
@@ -247,41 +306,58 @@ const options = computed(() => ({
|
|
|
247
306
|
{
|
|
248
307
|
chartType: TooltipChartType.BAR_CHART,
|
|
249
308
|
firstLineLabel: xValue,
|
|
250
|
-
secondLineLabel: yValue
|
|
309
|
+
secondLineLabel: yValue,
|
|
251
310
|
},
|
|
252
311
|
patternsColors.value,
|
|
253
312
|
patternsOrderedList.value,
|
|
254
313
|
barDataProps.disableAccessibility
|
|
255
314
|
);
|
|
256
|
-
}
|
|
257
|
-
}
|
|
315
|
+
},
|
|
316
|
+
},
|
|
258
317
|
},
|
|
259
318
|
scales: {
|
|
260
319
|
x: {
|
|
261
|
-
stacked:
|
|
320
|
+
stacked: barDataProps.stacked,
|
|
262
321
|
},
|
|
263
322
|
y: {
|
|
264
|
-
stacked:
|
|
323
|
+
stacked: barDataProps.stacked,
|
|
265
324
|
ticks: {
|
|
266
325
|
callback: function (val: string | number) {
|
|
267
|
-
return
|
|
326
|
+
return barDataProps.unit === '%'
|
|
327
|
+
? formatTicks(val as number, barDataProps.unit)
|
|
328
|
+
: formatWithThousandsSeprators(val as number) +
|
|
329
|
+
' ' +
|
|
330
|
+
barDataProps.unit;
|
|
268
331
|
},
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
}
|
|
332
|
+
},
|
|
333
|
+
},
|
|
334
|
+
},
|
|
273
335
|
}));
|
|
274
336
|
|
|
275
|
-
const htmlLegendPlugin = ref(
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
337
|
+
const htmlLegendPlugin = ref(
|
|
338
|
+
privateGetHtmlLegendPlugin(
|
|
339
|
+
legendContainer,
|
|
340
|
+
selectMode,
|
|
341
|
+
disablePattern,
|
|
342
|
+
patternsColors,
|
|
343
|
+
patternsOrderedList
|
|
344
|
+
)
|
|
345
|
+
);
|
|
282
346
|
|
|
347
|
+
watch(
|
|
348
|
+
onHoverIndex,
|
|
349
|
+
() => {
|
|
350
|
+
reloadChart();
|
|
351
|
+
},
|
|
352
|
+
{ deep: true }
|
|
353
|
+
);
|
|
283
354
|
</script>
|
|
284
355
|
|
|
356
|
+
<style lang="scss">
|
|
357
|
+
@import 'settings-tools/all-settings';
|
|
358
|
+
@import 'components/c.checkbox';
|
|
359
|
+
</style>
|
|
360
|
+
|
|
285
361
|
<style scoped>
|
|
286
362
|
.container {
|
|
287
363
|
-moz-osx-font-smoothing: grayscale;
|
|
@@ -296,4 +372,4 @@ watch(onHoverIndex, () => {
|
|
|
296
372
|
align-items: center;
|
|
297
373
|
margin-bottom: 20px;
|
|
298
374
|
}
|
|
299
|
-
</style>
|
|
375
|
+
</style>
|