@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
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
// DoughnutChart.stories.ts;
|
|
2
|
+
|
|
3
|
+
import type { Meta, StoryObj } from "@storybook/vue3";
|
|
4
|
+
import DoughnutChart from "./DoughnutChart.vue";
|
|
5
|
+
|
|
6
|
+
const meta = {
|
|
7
|
+
title: "Charts/Doughnut",
|
|
8
|
+
component: DoughnutChart,
|
|
9
|
+
} satisfies Meta<typeof DoughnutChart>;
|
|
10
|
+
|
|
11
|
+
export default meta;
|
|
12
|
+
type Story = StoryObj<typeof meta>;
|
|
13
|
+
|
|
14
|
+
export const Default = {
|
|
15
|
+
args: {
|
|
16
|
+
height: "400px",
|
|
17
|
+
width: "400px",
|
|
18
|
+
labels: ["Data One", "Data Two"],
|
|
19
|
+
data: [
|
|
20
|
+
{
|
|
21
|
+
value: 2771824.19,
|
|
22
|
+
unit: "€",
|
|
23
|
+
rate: 30.186240355262925,
|
|
24
|
+
},
|
|
25
|
+
{
|
|
26
|
+
value: 1715453.65,
|
|
27
|
+
unit: "€",
|
|
28
|
+
rate: 18.68195550931139,
|
|
29
|
+
},
|
|
30
|
+
],
|
|
31
|
+
},
|
|
32
|
+
} satisfies Story;
|
|
33
|
+
|
|
34
|
+
export const MultipleData = {
|
|
35
|
+
args: {
|
|
36
|
+
height: "400px",
|
|
37
|
+
width: "400px",
|
|
38
|
+
labels: [
|
|
39
|
+
"Data One",
|
|
40
|
+
"Data Two",
|
|
41
|
+
"Data Three",
|
|
42
|
+
"Data Four",
|
|
43
|
+
"Data Five",
|
|
44
|
+
"Data Six",
|
|
45
|
+
],
|
|
46
|
+
maxValues: 3,
|
|
47
|
+
data: [
|
|
48
|
+
{
|
|
49
|
+
value: 2771824.19,
|
|
50
|
+
unit: "€",
|
|
51
|
+
rate: 30.186240355262925,
|
|
52
|
+
},
|
|
53
|
+
{
|
|
54
|
+
value: 1715453.65,
|
|
55
|
+
unit: "€",
|
|
56
|
+
rate: 18.68195550931139,
|
|
57
|
+
},
|
|
58
|
+
{
|
|
59
|
+
value: 1651575.28,
|
|
60
|
+
unit: "€",
|
|
61
|
+
rate: 17.986295287685856,
|
|
62
|
+
},
|
|
63
|
+
{
|
|
64
|
+
value: 1168958.3,
|
|
65
|
+
unit: "€",
|
|
66
|
+
rate: 12.730409214402426,
|
|
67
|
+
},
|
|
68
|
+
{
|
|
69
|
+
value: 949837.87,
|
|
70
|
+
unit: "€",
|
|
71
|
+
rate: 10.34410275579238,
|
|
72
|
+
},
|
|
73
|
+
{
|
|
74
|
+
value: 924760.17,
|
|
75
|
+
unit: "€",
|
|
76
|
+
rate: 10.070996877545035,
|
|
77
|
+
},
|
|
78
|
+
],
|
|
79
|
+
},
|
|
80
|
+
} satisfies Story;
|
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<div class="container">
|
|
3
|
+
<div class="main">
|
|
4
|
+
<Doughnut
|
|
5
|
+
v-if="doughnutChartData"
|
|
6
|
+
ref='doughnutRef'
|
|
7
|
+
:data='doughnutChartData as ChartData<"doughnut", number[], unknown>'
|
|
8
|
+
:options='options'
|
|
9
|
+
:plugins='htmlLegendPlugin'
|
|
10
|
+
:cssClasses:="cssClasses"
|
|
11
|
+
:max-values="maxValues"
|
|
12
|
+
:style='{width, height, cursor:"pointer"}'
|
|
13
|
+
/>
|
|
14
|
+
</div>
|
|
15
|
+
<div ref="legendContainer" />
|
|
16
|
+
</div>
|
|
17
|
+
</template>
|
|
18
|
+
|
|
19
|
+
<script setup lang="ts">
|
|
20
|
+
import { onMounted, watch } from 'vue';
|
|
21
|
+
import { Doughnut } from 'vue-chartjs';
|
|
22
|
+
import type { ChartData } from 'chart.js';
|
|
23
|
+
import { computed, ref, PropType } from 'vue';
|
|
24
|
+
import type { DoughnutData } from '../../types/DoughnutData';
|
|
25
|
+
import { TooltipChartType } from '../../types/TooltipChartType';
|
|
26
|
+
import type { Context } from '../../services/GenericTooltipService';
|
|
27
|
+
import doughnutChartFunction from '../../services/DoughnutChartFunctions';
|
|
28
|
+
import { GenericTooltipService } from '../../services/GenericTooltipService';
|
|
29
|
+
import { formatWithThousandsSeprators } from '../../services/FormatUtilities';
|
|
30
|
+
import type { GenericData } from '../../types/GenericData';
|
|
31
|
+
import ChartDesign from '../../services/patterns/ChartDesign';
|
|
32
|
+
import {
|
|
33
|
+
Chart as ChartJS,
|
|
34
|
+
Title,
|
|
35
|
+
Tooltip,
|
|
36
|
+
Legend,
|
|
37
|
+
ArcElement,
|
|
38
|
+
Plugin
|
|
39
|
+
} from 'chart.js';
|
|
40
|
+
ChartJS.register(
|
|
41
|
+
Title,
|
|
42
|
+
Tooltip,
|
|
43
|
+
Legend,
|
|
44
|
+
ArcElement
|
|
45
|
+
);
|
|
46
|
+
|
|
47
|
+
const {
|
|
48
|
+
patternsColors,
|
|
49
|
+
patternsColorsLowerOpacity
|
|
50
|
+
} = ChartDesign();
|
|
51
|
+
|
|
52
|
+
const {
|
|
53
|
+
onHoverIndex,
|
|
54
|
+
doughnutRef,
|
|
55
|
+
backgroundColor,
|
|
56
|
+
privateGetHtmlLegendPlugin,
|
|
57
|
+
getOnHoverOptions,
|
|
58
|
+
groupDataAfterNthValue,
|
|
59
|
+
getDoughnutLabels,
|
|
60
|
+
getBackgroundColor,
|
|
61
|
+
} = doughnutChartFunction();
|
|
62
|
+
const selectMode = ref(false);
|
|
63
|
+
const legendContainer = ref<HTMLElement | null>(null);
|
|
64
|
+
|
|
65
|
+
const doughnutDataProps = defineProps({
|
|
66
|
+
chartId: {
|
|
67
|
+
type: String,
|
|
68
|
+
default: 'doughnut-chart',
|
|
69
|
+
},
|
|
70
|
+
data: {
|
|
71
|
+
type: Array as PropType<DoughnutData[]>,
|
|
72
|
+
default: () => []
|
|
73
|
+
},
|
|
74
|
+
labels: {
|
|
75
|
+
type: Array as PropType<string[]>,
|
|
76
|
+
default: () => []
|
|
77
|
+
},
|
|
78
|
+
cssClasses: {
|
|
79
|
+
default: '',
|
|
80
|
+
type: String,
|
|
81
|
+
},
|
|
82
|
+
width: {
|
|
83
|
+
type: String,
|
|
84
|
+
default: '400px',
|
|
85
|
+
},
|
|
86
|
+
height: {
|
|
87
|
+
type: String,
|
|
88
|
+
default: '400px',
|
|
89
|
+
},
|
|
90
|
+
maxValues: {
|
|
91
|
+
type: Number,
|
|
92
|
+
default: 5,
|
|
93
|
+
},
|
|
94
|
+
styles: {
|
|
95
|
+
type: Object as PropType<Partial<CSSStyleDeclaration>>,
|
|
96
|
+
default: () => {
|
|
97
|
+
},
|
|
98
|
+
},
|
|
99
|
+
plugins: {
|
|
100
|
+
type: Array as PropType<Plugin<'doughnut'>[]>,
|
|
101
|
+
default: () => [],
|
|
102
|
+
},
|
|
103
|
+
})
|
|
104
|
+
|
|
105
|
+
const doughnutChartData = computed(() => {
|
|
106
|
+
return {
|
|
107
|
+
labels: getDoughnutLabels(doughnutDataProps.labels,
|
|
108
|
+
doughnutDataProps.data, doughnutDataProps.maxValues),
|
|
109
|
+
datasets: [
|
|
110
|
+
{
|
|
111
|
+
data: groupDataAfterNthValue(doughnutDataProps.data, doughnutDataProps.maxValues).map((x: GenericData) => x.rate),
|
|
112
|
+
backgroundColor: backgroundColor.value,
|
|
113
|
+
}
|
|
114
|
+
]
|
|
115
|
+
}
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
const getTooltipData = (context: Context) => {
|
|
119
|
+
const dataIndex = context.tooltip.dataPoints[0].dataIndex;
|
|
120
|
+
if (!dataIndex) {
|
|
121
|
+
return '';
|
|
122
|
+
}
|
|
123
|
+
const tooltipData =
|
|
124
|
+
groupDataAfterNthValue(doughnutDataProps.data, doughnutDataProps.maxValues)[dataIndex];
|
|
125
|
+
const rate = formatWithThousandsSeprators(tooltipData.rate);
|
|
126
|
+
const value = formatWithThousandsSeprators(tooltipData.value);
|
|
127
|
+
const unit = tooltipData.unit || '';
|
|
128
|
+
return `${value}${unit} (${rate})%`;
|
|
129
|
+
};
|
|
130
|
+
|
|
131
|
+
function getSpacing () {
|
|
132
|
+
return doughnutDataProps.labels.length <= 1 ? 0 : 12;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
// @ts-ignore
|
|
136
|
+
const options = computed(() => ({
|
|
137
|
+
onHover: getOnHoverOptions(),
|
|
138
|
+
plugins: {
|
|
139
|
+
legend: {
|
|
140
|
+
display: false,
|
|
141
|
+
// @ts-ignore
|
|
142
|
+
position: 'bottom' as const,
|
|
143
|
+
align: 'start' as const,
|
|
144
|
+
labels: {
|
|
145
|
+
pointStyle: 'rectRounded',
|
|
146
|
+
usePointStyle: true
|
|
147
|
+
}
|
|
148
|
+
},
|
|
149
|
+
title: {
|
|
150
|
+
display: false
|
|
151
|
+
},
|
|
152
|
+
tooltip: {
|
|
153
|
+
enabled: false,
|
|
154
|
+
external: function (context: Context) {
|
|
155
|
+
new GenericTooltipService().createTooltip(
|
|
156
|
+
context,
|
|
157
|
+
getTooltipData,
|
|
158
|
+
{
|
|
159
|
+
chartType: TooltipChartType.DOUGHNUT
|
|
160
|
+
}
|
|
161
|
+
);
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
},
|
|
165
|
+
radius: '90%',
|
|
166
|
+
cutout: '70%',
|
|
167
|
+
borderWidth: 3,
|
|
168
|
+
borderColor: function (context: any) {
|
|
169
|
+
return (onHoverIndex.value !== null && context.dataIndex !== (onHoverIndex.value))
|
|
170
|
+
? patternsColorsLowerOpacity[context.dataIndex]
|
|
171
|
+
: patternsColors[context.dataIndex];
|
|
172
|
+
},
|
|
173
|
+
spacing: getSpacing(),
|
|
174
|
+
hoverOffset: 4
|
|
175
|
+
}));
|
|
176
|
+
|
|
177
|
+
const doughnutDataAndLabels = {
|
|
178
|
+
data: doughnutDataProps.data,
|
|
179
|
+
labels: doughnutDataProps.labels
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
const htmlLegendPlugin = computed(() => privateGetHtmlLegendPlugin(legendContainer, selectMode, doughnutDataProps.maxValues, doughnutDataAndLabels));
|
|
183
|
+
|
|
184
|
+
onMounted(() =>{
|
|
185
|
+
getBackgroundColor();
|
|
186
|
+
});
|
|
187
|
+
watch(onHoverIndex, (newValue, oldValue) => {
|
|
188
|
+
if (newValue !== oldValue) {
|
|
189
|
+
getBackgroundColor();
|
|
190
|
+
}
|
|
191
|
+
});
|
|
192
|
+
</script>
|
|
193
|
+
|
|
194
|
+
<style scoped>
|
|
195
|
+
.container {
|
|
196
|
+
-moz-osx-font-smoothing: grayscale;
|
|
197
|
+
-webkit-font-smoothing: antialiased;
|
|
198
|
+
font-weight: 400;
|
|
199
|
+
font-family: 'Roboto', sans-serif;
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
.main {
|
|
203
|
+
display: flex;
|
|
204
|
+
flex-direction: column;
|
|
205
|
+
justify-content: center;
|
|
206
|
+
align-items: center;
|
|
207
|
+
}
|
|
208
|
+
</style>
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
// LineChart.stories.ts;
|
|
2
|
+
|
|
3
|
+
import type { Meta, StoryObj } from "@storybook/vue3";
|
|
4
|
+
import LineChart from "./LineChart.vue";
|
|
5
|
+
|
|
6
|
+
const meta = {
|
|
7
|
+
title: "Charts/Line",
|
|
8
|
+
component: LineChart,
|
|
9
|
+
} satisfies Meta<typeof LineChart>;
|
|
10
|
+
|
|
11
|
+
export default meta;
|
|
12
|
+
type Story = StoryObj<typeof meta>;
|
|
13
|
+
|
|
14
|
+
export const Default = {
|
|
15
|
+
args: {
|
|
16
|
+
rawTitle: "Line title",
|
|
17
|
+
width: "600px",
|
|
18
|
+
height: "400px",
|
|
19
|
+
labels: ["Data One", "Data Two", "Data Three"],
|
|
20
|
+
lines: [
|
|
21
|
+
{
|
|
22
|
+
label: "Data One",
|
|
23
|
+
data: [-22, 34, 11],
|
|
24
|
+
unit: "%",
|
|
25
|
+
},
|
|
26
|
+
{
|
|
27
|
+
label: "Data Two",
|
|
28
|
+
data: [-3, 28, 35],
|
|
29
|
+
unit: "%",
|
|
30
|
+
},
|
|
31
|
+
],
|
|
32
|
+
},
|
|
33
|
+
} satisfies Story;
|
|
34
|
+
|
|
35
|
+
export const MultipleData = {
|
|
36
|
+
args: {
|
|
37
|
+
width: "600px",
|
|
38
|
+
height: "400px",
|
|
39
|
+
labels: [
|
|
40
|
+
"Data One",
|
|
41
|
+
"Data Two",
|
|
42
|
+
"Data Three",
|
|
43
|
+
"Data Four",
|
|
44
|
+
"Data Five",
|
|
45
|
+
"Data Six",
|
|
46
|
+
],
|
|
47
|
+
lines: [
|
|
48
|
+
{
|
|
49
|
+
label: "Data One",
|
|
50
|
+
data: [-22, 34, 11, 1, 22, 21],
|
|
51
|
+
unit: "%",
|
|
52
|
+
},
|
|
53
|
+
{
|
|
54
|
+
label: "Data Two",
|
|
55
|
+
data: [-3, 28, 35, 10, 3, 18],
|
|
56
|
+
unit: "%",
|
|
57
|
+
},
|
|
58
|
+
],
|
|
59
|
+
},
|
|
60
|
+
} satisfies Story;
|
|
@@ -0,0 +1,245 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<div class="container">
|
|
3
|
+
<div class="main">
|
|
4
|
+
<Line
|
|
5
|
+
v-if="chartData"
|
|
6
|
+
ref="cockpitLineChartRef"
|
|
7
|
+
:data="chartData"
|
|
8
|
+
:options="options"
|
|
9
|
+
:plugins='htmlLegendPlugin'
|
|
10
|
+
:chart-id='chartId'
|
|
11
|
+
:cssClasses:='cssClasses'
|
|
12
|
+
:styles='styles'
|
|
13
|
+
:style='{ width, height, cursor:"pointer"}'
|
|
14
|
+
/>
|
|
15
|
+
</div>
|
|
16
|
+
<div ref="legendContainer" />
|
|
17
|
+
</div>
|
|
18
|
+
</template>
|
|
19
|
+
|
|
20
|
+
<script setup lang="ts">
|
|
21
|
+
|
|
22
|
+
import type { Ref } from 'vue';
|
|
23
|
+
import { computed, ref, PropType } from 'vue';
|
|
24
|
+
import { Line } from 'vue-chartjs';
|
|
25
|
+
import { LineData } from '../../types/LineChart';
|
|
26
|
+
import { GenericTooltipService } from '../../services/GenericTooltipService';
|
|
27
|
+
import type { Context } from '../../services/GenericTooltipService';
|
|
28
|
+
import { TooltipChartType } from '../../types/TooltipChartType';
|
|
29
|
+
import { formatTicks } from '../../services/FormatUtilities';
|
|
30
|
+
import type { ChartItem } from '../../services/ChartsCommonLegend';
|
|
31
|
+
|
|
32
|
+
import {
|
|
33
|
+
createHtmlLegendItemText,
|
|
34
|
+
createHtmlLegendListElement,
|
|
35
|
+
createLegendElementWithSquareArea,
|
|
36
|
+
getOrCreateLegendList,
|
|
37
|
+
createLegendCheckbox,
|
|
38
|
+
switchItemVisibility
|
|
39
|
+
} from '../../services/ChartsCommonLegend';
|
|
40
|
+
|
|
41
|
+
import {
|
|
42
|
+
CategoryScale,
|
|
43
|
+
Chart as ChartJS,
|
|
44
|
+
Legend,
|
|
45
|
+
LinearScale,
|
|
46
|
+
LineElement,
|
|
47
|
+
PointElement,
|
|
48
|
+
Title,
|
|
49
|
+
Tooltip,
|
|
50
|
+
Plugin
|
|
51
|
+
} from 'chart.js';
|
|
52
|
+
|
|
53
|
+
ChartJS.register(
|
|
54
|
+
Title,
|
|
55
|
+
Tooltip,
|
|
56
|
+
Legend,
|
|
57
|
+
PointElement,
|
|
58
|
+
LineElement,
|
|
59
|
+
CategoryScale,
|
|
60
|
+
LinearScale
|
|
61
|
+
);
|
|
62
|
+
|
|
63
|
+
const legendContainer = ref(null);
|
|
64
|
+
const selectMode = ref(false);
|
|
65
|
+
const lineDataProps = defineProps({
|
|
66
|
+
chartId: {
|
|
67
|
+
type: String,
|
|
68
|
+
default: 'radar-chart',
|
|
69
|
+
},
|
|
70
|
+
rawTitle: {
|
|
71
|
+
type: String,
|
|
72
|
+
default: 'sales',
|
|
73
|
+
},
|
|
74
|
+
width: {
|
|
75
|
+
type: String,
|
|
76
|
+
default: '200px',
|
|
77
|
+
},
|
|
78
|
+
height: {
|
|
79
|
+
type: String,
|
|
80
|
+
default: '400px',
|
|
81
|
+
},
|
|
82
|
+
lines: {
|
|
83
|
+
type: Array as PropType<LineData[]>,
|
|
84
|
+
default: () => {},
|
|
85
|
+
},
|
|
86
|
+
labels: {
|
|
87
|
+
type: Array as PropType<string[]>,
|
|
88
|
+
default: () => []
|
|
89
|
+
},
|
|
90
|
+
cssClasses: {
|
|
91
|
+
default: '',
|
|
92
|
+
type: String,
|
|
93
|
+
},
|
|
94
|
+
styles: {
|
|
95
|
+
type: Object as PropType<Partial<CSSStyleDeclaration>>,
|
|
96
|
+
default: () => {},
|
|
97
|
+
},
|
|
98
|
+
plugins: {
|
|
99
|
+
type: Array as PropType<Plugin<'line'>[]>,
|
|
100
|
+
default: () => [],
|
|
101
|
+
},
|
|
102
|
+
})
|
|
103
|
+
|
|
104
|
+
const getTooltipData = (context: Context) => {
|
|
105
|
+
const datasetIndex = context.tooltip.dataPoints[0].datasetIndex;
|
|
106
|
+
const dataIndex = context.tooltip.dataPoints[0].dataIndex;
|
|
107
|
+
if (!dataIndex || !datasetIndex) {
|
|
108
|
+
return '';
|
|
109
|
+
}
|
|
110
|
+
const formattedValue = lineDataProps.lines[datasetIndex].data[dataIndex].toFixed(2);
|
|
111
|
+
return lineDataProps.lines[datasetIndex].unit ? formattedValue +
|
|
112
|
+
' ' + lineDataProps.lines[datasetIndex].unit
|
|
113
|
+
: formattedValue;
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
const tooltipFirstLine = 'months';
|
|
117
|
+
const tooltipValueAttribute = computed(() => {
|
|
118
|
+
return lineDataProps.rawTitle;
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
const chartData = computed(() => {
|
|
122
|
+
return {
|
|
123
|
+
labels: lineDataProps.labels.map((label: string) => label),
|
|
124
|
+
datasets: [
|
|
125
|
+
{
|
|
126
|
+
type: 'line' as const,
|
|
127
|
+
borderColor: '#605F9D',
|
|
128
|
+
pointStyle: 'rectRot',
|
|
129
|
+
pointBackgroundColor: '#FFFFFF',
|
|
130
|
+
pointRadius: 5,
|
|
131
|
+
label: lineDataProps.lines[0].label,
|
|
132
|
+
data: lineDataProps.lines[0].data,
|
|
133
|
+
borderWidth: 2
|
|
134
|
+
},
|
|
135
|
+
{
|
|
136
|
+
type: 'line' as const,
|
|
137
|
+
borderColor: '#00919F',
|
|
138
|
+
pointStyle: 'circle',
|
|
139
|
+
pointBackgroundColor: '#FFFFFF',
|
|
140
|
+
pointRadius: 5,
|
|
141
|
+
label: lineDataProps.lines[1].label,
|
|
142
|
+
data: lineDataProps.lines[1].data,
|
|
143
|
+
borderWidth: 2
|
|
144
|
+
}
|
|
145
|
+
]
|
|
146
|
+
};
|
|
147
|
+
});
|
|
148
|
+
|
|
149
|
+
function getHtmlLegendPlugin(legendContainer: Ref, selectMode: Ref) {
|
|
150
|
+
return [{
|
|
151
|
+
id: 'htmlLegend',
|
|
152
|
+
afterUpdate (chart: any) {
|
|
153
|
+
const ul = getOrCreateLegendList(legendContainer, 'column');
|
|
154
|
+
ul.style.display = 'flex';
|
|
155
|
+
ul.style.flexDirection = 'row';
|
|
156
|
+
while (ul.firstChild) {
|
|
157
|
+
ul.firstChild.remove();
|
|
158
|
+
}
|
|
159
|
+
const items = chart.options.plugins.legend.labels.generateLabels(chart);
|
|
160
|
+
items.forEach((item: ChartItem) => {
|
|
161
|
+
const li = createHtmlLegendListElement(chart, selectMode, item.datasetIndex);
|
|
162
|
+
let liContent: HTMLElement;
|
|
163
|
+
if (!selectMode.value) {
|
|
164
|
+
liContent = createLegendElementWithSquareArea(item);
|
|
165
|
+
} else {
|
|
166
|
+
liContent = createLegendElementWithCheckbox(chart, item);
|
|
167
|
+
}
|
|
168
|
+
li.style.marginRight = '10px';
|
|
169
|
+
li.appendChild(liContent);
|
|
170
|
+
li.appendChild(createHtmlLegendItemText(item));
|
|
171
|
+
ul.appendChild(li);
|
|
172
|
+
});
|
|
173
|
+
}
|
|
174
|
+
}];
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
function createLegendElementWithCheckbox (chart: any, item: ChartItem) {
|
|
178
|
+
const liContent = createLegendCheckbox(chart, item);
|
|
179
|
+
liContent.onclick = (e: Event) => {
|
|
180
|
+
switchItemVisibility(chart, item.datasetIndex, selectMode);
|
|
181
|
+
e.stopPropagation();
|
|
182
|
+
};
|
|
183
|
+
return liContent;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
const htmlLegendPlugin = getHtmlLegendPlugin(legendContainer, selectMode);
|
|
187
|
+
|
|
188
|
+
const options = computed(() => ({
|
|
189
|
+
responsive: true,
|
|
190
|
+
maintainAspectRatio: true,
|
|
191
|
+
plugins: {
|
|
192
|
+
legend: {
|
|
193
|
+
display: false
|
|
194
|
+
},
|
|
195
|
+
tooltip: {
|
|
196
|
+
enabled: false,
|
|
197
|
+
external: function (context: Context) {
|
|
198
|
+
new GenericTooltipService().createTooltip(
|
|
199
|
+
context,
|
|
200
|
+
getTooltipData,
|
|
201
|
+
{
|
|
202
|
+
chartType: TooltipChartType.LINE_CHART,
|
|
203
|
+
firstLineLabel: tooltipFirstLine,
|
|
204
|
+
secondLineLabel: tooltipValueAttribute.value
|
|
205
|
+
}
|
|
206
|
+
);
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
},
|
|
210
|
+
scales: {
|
|
211
|
+
y: {
|
|
212
|
+
type: 'linear' as const,
|
|
213
|
+
display: true,
|
|
214
|
+
position: 'left' as const,
|
|
215
|
+
grid: {
|
|
216
|
+
drawOnChartArea: true
|
|
217
|
+
},
|
|
218
|
+
ticks: {
|
|
219
|
+
callback: function (val: number | string) {
|
|
220
|
+
const unit = lineDataProps.lines[0].unit;
|
|
221
|
+
return formatTicks(val as number, unit ? unit : null);
|
|
222
|
+
},
|
|
223
|
+
maxTicksLimit: 8,
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
}));
|
|
228
|
+
</script>
|
|
229
|
+
|
|
230
|
+
<style scoped>
|
|
231
|
+
.container {
|
|
232
|
+
-moz-osx-font-smoothing: grayscale;
|
|
233
|
+
-webkit-font-smoothing: antialiased;
|
|
234
|
+
font-weight: 400;
|
|
235
|
+
font-family: 'Roboto', sans-serif;
|
|
236
|
+
}
|
|
237
|
+
.main {
|
|
238
|
+
display: flex;
|
|
239
|
+
flex-direction: column;
|
|
240
|
+
justify-content: center;
|
|
241
|
+
align-items: center;
|
|
242
|
+
margin-bottom: 20px;
|
|
243
|
+
}
|
|
244
|
+
</style>
|
|
245
|
+
|