-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
40 changed files
with
3,835 additions
and
566 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
<!-- | ||
Copyright (C) 2024 Nethesis S.r.l. | ||
SPDX-License-Identifier: GPL-3.0-or-later | ||
--> | ||
|
||
<script setup lang="ts"> | ||
import { | ||
Chart as ChartJS, | ||
Title, | ||
Tooltip, | ||
Legend, | ||
BarElement, | ||
CategoryScale, | ||
LinearScale | ||
} from 'chart.js' | ||
import { Bar } from 'vue-chartjs' | ||
import { computed } from 'vue' | ||
import { useThemeStore } from '@/stores/theme' | ||
import { GRAY_200, GRAY_700, GRAY_800 } from '@/lib/color' | ||
|
||
const themeStore = useThemeStore() | ||
|
||
const props = withDefaults( | ||
defineProps<{ | ||
labels: string[] | ||
datasets: any[] | ||
height?: string | ||
isHorizontal?: boolean | ||
showLegend?: boolean | ||
showValuesOnBars?: boolean | ||
}>(), | ||
{ isHorizontal: false, showLegend: false, showValuesOnBars: true } | ||
) | ||
|
||
const options: any = { | ||
indexAxis: props.isHorizontal ? 'y' : 'x', | ||
scales: { | ||
x: { | ||
ticks: { | ||
color: themeStore.isLight ? GRAY_700 : GRAY_200 | ||
}, | ||
grid: { | ||
color: themeStore.isLight ? GRAY_200 : GRAY_800 | ||
} | ||
}, | ||
y: { | ||
ticks: { | ||
color: themeStore.isLight ? GRAY_700 : GRAY_200 | ||
}, | ||
grid: { | ||
color: themeStore.isLight ? GRAY_200 : GRAY_800 | ||
} | ||
} | ||
}, | ||
plugins: { | ||
legend: { | ||
display: props.showLegend | ||
} | ||
}, | ||
animation: | ||
props.showValuesOnBars && props.isHorizontal | ||
? { | ||
duration: 1, | ||
onComplete: function ({ chart }: any) { | ||
const ctx = chart.ctx | ||
|
||
chart.config.data.datasets.forEach(function (dataset: any, i: number) { | ||
const meta = chart.getDatasetMeta(i) | ||
|
||
meta.data.forEach(function (bar: any, index: number) { | ||
const data = dataset.data[index] | ||
|
||
if (data) { | ||
ctx.fillStyle = themeStore.isLight ? GRAY_700 : GRAY_200 | ||
ctx.fillText(Number(data).toLocaleString(), bar.x + 5, bar.y + 5) | ||
} | ||
}) | ||
}) | ||
} | ||
} | ||
: {} | ||
} | ||
|
||
const chartData: any = computed(() => { | ||
return { labels: props.labels, datasets: props.datasets } | ||
}) | ||
|
||
const chartStyle = computed(() => { | ||
return { | ||
height: props.height || '', | ||
width: '100%', | ||
position: 'relative' | ||
} | ||
}) | ||
|
||
ChartJS.register(CategoryScale, LinearScale, BarElement, Title, Tooltip, Legend) | ||
</script> | ||
|
||
<template> | ||
<div> | ||
<Bar :data="chartData" :options="options" :style="chartStyle" /> | ||
</div> | ||
</template> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
<!-- | ||
Copyright (C) 2024 Nethesis S.r.l. | ||
SPDX-License-Identifier: GPL-3.0-or-later | ||
--> | ||
|
||
<script setup lang="ts"> | ||
import 'chartjs-adapter-date-fns' | ||
import { computed } from 'vue' | ||
import { useThemeStore } from '@/stores/theme' | ||
import { GRAY_200, GRAY_700 } from '@/lib/color' | ||
import { Pie } from 'vue-chartjs' | ||
import { Chart as ChartJS, registerables } from 'chart.js' | ||
|
||
const themeStore = useThemeStore() | ||
|
||
const props = defineProps<{ | ||
labels: string[] | ||
datasets: any[] | ||
height?: string | ||
}>() | ||
|
||
const options: any = { | ||
responsive: true, | ||
maintainAspectRatio: false, | ||
plugins: { | ||
legend: { | ||
position: 'right', | ||
labels: { | ||
// show dataset value and sort by pie slice | ||
generateLabels: function (chart: any) { | ||
const data = chart.data | ||
if (data.labels.length && data.datasets.length) { | ||
// Create an array of label-value pairs | ||
const labelValuePairs = data.labels.map((label: string, i: number) => { | ||
const value = data.datasets[0].data[i] | ||
return { label, value, index: i } | ||
}) | ||
|
||
// Sort the array by value in descending order | ||
labelValuePairs.sort((a: any, b: any) => b.value - a.value) | ||
|
||
// Return the sorted labels | ||
return labelValuePairs.map( | ||
({ label, value, index }: { label: string; value: number; index: number }) => { | ||
const meta = chart.getDatasetMeta(0) | ||
const ds = data.datasets[0] | ||
const arc = meta.data[index] | ||
const custom = (arc && arc.custom) || {} | ||
return { | ||
text: `${label}: ${value?.toLocaleString()}`, | ||
fontColor: themeStore.isLight ? GRAY_700 : GRAY_200, | ||
fillStyle: custom.backgroundColor || ds.backgroundColor[index], | ||
hidden: isNaN(ds.data[index]) || meta.data[index].hidden, | ||
index: index | ||
} | ||
} | ||
) | ||
} | ||
return [] | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
const chartData: any = computed(() => { | ||
return { labels: props.labels, datasets: props.datasets } | ||
}) | ||
|
||
const chartStyle = computed(() => { | ||
return { | ||
height: props.height || '', | ||
width: '100%', | ||
position: 'relative' | ||
} | ||
}) | ||
|
||
ChartJS.register(...registerables) | ||
</script> | ||
|
||
<template> | ||
<div> | ||
<Pie :data="chartData" :options="options" :style="chartStyle" /> | ||
</div> | ||
</template> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<!-- | ||
Copyright (C) 2024 Nethesis S.r.l. | ||
SPDX-License-Identifier: GPL-3.0-or-later | ||
--> | ||
|
||
<template> | ||
<div | ||
class="inline-block w-full text-center text-2xl font-medium text-indigo-700 dark:text-indigo-500 2xl:text-3xl" | ||
> | ||
<slot /> | ||
</div> | ||
</template> |
Oops, something went wrong.