-
Notifications
You must be signed in to change notification settings - Fork 0
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
14 changed files
with
295 additions
and
16 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
---|---|---|
|
@@ -42,7 +42,7 @@ | |
|
||
<style> | ||
.header { | ||
padding-block: var(--space-m); | ||
padding-block: var(--space-xl); | ||
} | ||
.wrapper { | ||
|
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,97 @@ | ||
<script lang="ts"> | ||
import ChartDoughnut from '~/elements/chart-doughnut.svelte' | ||
import Typography from '~/elements/typography.svelte' | ||
import Container from '~/elements/container.svelte' | ||
import { data } from '~/stores/data' | ||
$: todosByKind = | ||
$data.data?.reduce((accumulator: Record<string, number>, { kind }) => { | ||
if (kind in accumulator) { | ||
accumulator[kind] = accumulator[kind] + 1 | ||
} else { | ||
accumulator[kind] = 1 | ||
} | ||
return accumulator | ||
}, {}) || {} | ||
$: todosEntries = Object.entries(todosByKind).sort(([, a], [, b]) => b - a) | ||
$: finalTodosEntries = (() => { | ||
if (todosEntries.length > 5) { | ||
let topFive = todosEntries.slice(0, 4) | ||
let remainingSum = todosEntries | ||
.slice(4) | ||
.reduce((sum, [, value]) => sum + value, 0) | ||
topFive.push(['TOTAL', remainingSum]) | ||
return topFive | ||
} | ||
return todosEntries | ||
})() | ||
$: values = finalTodosEntries.map(([, value]) => value) | ||
let colors = [ | ||
'primary', | ||
'secondary', | ||
'tertiary', | ||
'quaternary', | ||
'quinary', | ||
'senary', | ||
] | ||
</script> | ||
|
||
<Container> | ||
<div class="wrapper"> | ||
<div></div> | ||
<div class="chart"> | ||
<Typography size="l" tag="h2" mbe="l" align="center" | ||
>Todos by kind</Typography | ||
> | ||
{#if values.length} | ||
<ChartDoughnut {values} /> | ||
{/if} | ||
</div> | ||
</div> | ||
<div class="legend"> | ||
{#each finalTodosEntries as [kind], index} | ||
<div class="legend-element"> | ||
<div | ||
style={`--color: var(--color-additional-${colors[index]});`} | ||
class="legend-color" | ||
></div> | ||
<Typography size="s" tag="span">{kind}</Typography> | ||
</div> | ||
{/each} | ||
</div> | ||
</Container> | ||
|
||
<style> | ||
.wrapper { | ||
display: grid; | ||
grid-template-columns: 1fr 420px; | ||
gap: var(--space-l); | ||
margin-block-end: var(--space-xl); | ||
} | ||
.legend { | ||
display: flex; | ||
gap: var(--space-xl); | ||
justify-content: center; | ||
max-inline-size: 800px; | ||
margin-block-start: var(--space-xl); | ||
margin-inline: auto; | ||
} | ||
.legend-element { | ||
display: flex; | ||
gap: var(--space-s); | ||
align-items: center; | ||
} | ||
.legend-color { | ||
inline-size: var(--space-l); | ||
block-size: var(--space-l); | ||
background: var(--color); | ||
border-radius: var(--border-radius); | ||
} | ||
</style> |
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,44 @@ | ||
<script lang="ts"> | ||
import type { ChartOptions, ChartData } from 'chart.js' | ||
import Chart from '~/elements/chart.svelte' | ||
import { theme } from '~/stores/theme' | ||
export let values: number[] | ||
$: computedStyles = getComputedStyle(document.body) | ||
$: data = { | ||
datasets: [ | ||
{ | ||
backgroundColor: [ | ||
computedStyles.getPropertyValue('--color-additional-primary'), | ||
computedStyles.getPropertyValue('--color-additional-secondary'), | ||
computedStyles.getPropertyValue('--color-additional-tertiary'), | ||
computedStyles.getPropertyValue('--color-additional-quaternary'), | ||
computedStyles.getPropertyValue('--color-additional-quinary'), | ||
computedStyles.getPropertyValue('--color-additional-senary'), | ||
], | ||
borderColor: computedStyles.getPropertyValue( | ||
'--color-border-secondary', | ||
), | ||
data: values, | ||
}, | ||
], | ||
} as ChartData<'doughnut'> | ||
theme.subscribe(() => { | ||
computedStyles = getComputedStyle(document.body) | ||
}) | ||
let options: ChartOptions<'doughnut'> = { | ||
plugins: { | ||
legend: { | ||
display: false, | ||
}, | ||
}, | ||
responsive: true, | ||
} | ||
</script> | ||
|
||
<Chart type="doughnut" {options} {data} /> |
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,52 @@ | ||
<script lang="ts" generics="T extends ChartType"> | ||
/* global T */ | ||
// eslint-disable-next-line no-unused-vars | ||
import type { ChartOptions, ChartData, ChartType } from 'chart.js' | ||
import { registerables, Chart } from 'chart.js' | ||
import { onDestroy, onMount } from 'svelte' | ||
Chart.register(...registerables) | ||
export let type: T | ||
export let data: ChartData<T> | ||
export let options: ChartOptions<T> | ||
let canvasRef: HTMLCanvasElement | ||
export let chart: Chart<T> | null = null | ||
onMount(() => { | ||
chart = new Chart(canvasRef, { | ||
options: { | ||
...options, | ||
animation: { | ||
duration: 1000, | ||
}, | ||
}, | ||
data, | ||
type, | ||
}) | ||
}) | ||
$: if (chart) { | ||
chart.data = data | ||
chart.options = { | ||
...options, | ||
animation: { | ||
duration: 0, | ||
}, | ||
} | ||
chart.update() | ||
} | ||
onDestroy(() => { | ||
if (chart) { | ||
chart.destroy() | ||
chart = null | ||
} | ||
}) | ||
</script> | ||
|
||
<canvas bind:this={canvasRef}></canvas> |
Oops, something went wrong.