Add total and reformat main page to scale if charts are less or more than 4
This commit is contained in:
parent
a90d18cad6
commit
5716d1ebc4
|
@ -146,6 +146,7 @@ export interface StatsType {
|
||||||
export interface StatsTypeCurrencyChart {
|
export interface StatsTypeCurrencyChart {
|
||||||
label: string;
|
label: string;
|
||||||
elements: StatsType[];
|
elements: StatsType[];
|
||||||
|
total: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
// {{{ Settings section
|
// {{{ Settings section
|
||||||
|
|
|
@ -9,6 +9,7 @@
|
||||||
type ChartConfiguration,
|
type ChartConfiguration,
|
||||||
} from "chart.js";
|
} from "chart.js";
|
||||||
import type { StatsTypeCurrencyChart } from "$lib/entities";
|
import type { StatsTypeCurrencyChart } from "$lib/entities";
|
||||||
|
import { NumberToFPA } from "$lib/util/fpa";
|
||||||
|
|
||||||
Chart.register(DoughnutController, ArcElement, Tooltip, Legend);
|
Chart.register(DoughnutController, ArcElement, Tooltip, Legend);
|
||||||
|
|
||||||
|
@ -33,7 +34,7 @@
|
||||||
labels: chart.elements.map((type) => type.name),
|
labels: chart.elements.map((type) => type.name),
|
||||||
datasets: [
|
datasets: [
|
||||||
{
|
{
|
||||||
label: "Chart Dataset",
|
label: chart.label,
|
||||||
data: chart.elements.map((type) => type.value / 100),
|
data: chart.elements.map((type) => type.value / 100),
|
||||||
backgroundColor: chart.elements.map((type) => type.color),
|
backgroundColor: chart.elements.map((type) => type.color),
|
||||||
},
|
},
|
||||||
|
@ -66,16 +67,24 @@
|
||||||
{/if}
|
{/if}
|
||||||
|
|
||||||
<!-- Render canvas elements for charts -->
|
<!-- Render canvas elements for charts -->
|
||||||
<div class="w-1/2 grid grid-cols-2 gap-4">
|
<div class="flex items-center justify-center">
|
||||||
|
<div
|
||||||
|
class="{configs.length > 4
|
||||||
|
? 'grid-cols-4'
|
||||||
|
: 'grid-cols-2'} w-fit grid gap-4"
|
||||||
|
>
|
||||||
{#each configs as _, index}
|
{#each configs as _, index}
|
||||||
<div class="flex flex-col">
|
<div class="flex flex-col">
|
||||||
<div class="type-chart">
|
<div class="type-chart">
|
||||||
<canvas bind:this={canvases[index]}></canvas>
|
<canvas bind:this={canvases[index]}></canvas>
|
||||||
<span class="flex justify-center">{data[index].label}</span>
|
<span class="flex justify-center"
|
||||||
|
>{`Total: ${NumberToFPA(data[index].total)} ${data[index].label}`}</span
|
||||||
|
>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{/each}
|
{/each}
|
||||||
</div>
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
<style lang="postcss">
|
<style lang="postcss">
|
||||||
.type-chart {
|
.type-chart {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user