-
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
663 additions
and
65 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,30 @@ | ||
<script lang="ts"> | ||
import Typography from '~/elements/typography.svelte' | ||
import ChartLine from '~/elements/chart-line.svelte' | ||
import Container from '~/elements/container.svelte' | ||
import { data } from '~/stores/data' | ||
$: history = | ||
$data.history?.sort( | ||
(a, b) => new Date(a.date).getTime() - new Date(b.date).getTime(), | ||
) ?? [] | ||
$: labels = history?.map(({ date }) => date) | ||
$: values = history?.map(({ count }) => count) | ||
</script> | ||
|
||
<div class="graph-wrapper"> | ||
<Container> | ||
<Typography size="l" tag="h2" mbe="l">Todos Graph</Typography> | ||
<div> | ||
{#if values.length && labels.length} | ||
<ChartLine {values} {labels} /> | ||
{/if} | ||
</div> | ||
</Container> | ||
</div> | ||
|
||
<style> | ||
.graph-wrapper { | ||
margin-block: var(--space-xl) var(--space-2xl); | ||
} | ||
</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
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
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,140 @@ | ||
<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[] | ||
export let labels: string[] | ||
let max = Math.max(...values) | ||
let min = Math.min(...values) | ||
$: computedStyles = getComputedStyle(document.body) | ||
$: data = { | ||
datasets: [ | ||
{ | ||
pointBackgroundColor: computedStyles.getPropertyValue( | ||
'--color-additional-primary', | ||
), | ||
backgroundColor: computedStyles.getPropertyValue( | ||
'--color-additional-secondary', | ||
), | ||
pointBorderColor: computedStyles.getPropertyValue( | ||
'--color-additional-primary', | ||
), | ||
borderColor: computedStyles.getPropertyValue( | ||
'--color-additional-primary', | ||
), | ||
borderJoinStyle: 'miter', | ||
pointBorderWidth: 3, | ||
borderWidth: 4, | ||
tension: 0.3, | ||
data: values, | ||
fill: false, | ||
}, | ||
], | ||
labels, | ||
} as ChartData<'line'> | ||
theme.subscribe(() => { | ||
computedStyles = getComputedStyle(document.body) | ||
}) | ||
$: options = { | ||
scales: { | ||
x: { | ||
ticks: { | ||
callback: (_value, index) => { | ||
let date = new Date(labels[index]) | ||
let monthNames = [ | ||
'Jan', | ||
'Feb', | ||
'Mar', | ||
'Apr', | ||
'May', | ||
'Jun', | ||
'Jul', | ||
'Aug', | ||
'Sep', | ||
'Oct', | ||
'Nov', | ||
'Dec', | ||
] | ||
if (date.getDate() === 1) { | ||
return monthNames[date.getMonth()] | ||
} | ||
return null | ||
}, | ||
font: { | ||
family: computedStyles.getPropertyValue('--font-family-base'), | ||
size: 16, | ||
}, | ||
color: computedStyles.getPropertyValue('--color-content-primary'), | ||
autoSkip: false, | ||
maxRotation: 0, | ||
}, | ||
grid: { | ||
color: computedStyles.getPropertyValue('--color-border-primary'), | ||
}, | ||
}, | ||
y: { | ||
ticks: { | ||
font: { | ||
family: computedStyles.getPropertyValue('--font-family-base'), | ||
size: 16, | ||
}, | ||
color: computedStyles.getPropertyValue('--color-content-primary'), | ||
}, | ||
grid: { | ||
color: computedStyles.getPropertyValue('--color-border-primary'), | ||
}, | ||
min: min === 0 ? 0 : min / 2, | ||
max: max + min / 2, | ||
}, | ||
}, | ||
plugins: { | ||
tooltip: { | ||
callbacks: { | ||
labelColor: () => ({ | ||
backgroundColor: computedStyles.getPropertyValue( | ||
'--color-additional-primary', | ||
), | ||
borderColor: computedStyles.getPropertyValue( | ||
'--color-border-primary', | ||
), | ||
borderRadius: 2, | ||
borderWidth: 0, | ||
}), | ||
}, | ||
titleFont: { | ||
family: computedStyles.getPropertyValue('--font-family-base'), | ||
size: 16, | ||
}, | ||
bodyFont: { | ||
family: computedStyles.getPropertyValue('--font-family-base'), | ||
size: 16, | ||
}, | ||
backgroundColor: computedStyles.getPropertyValue( | ||
'--color-background-secondary', | ||
), | ||
footerFont: { | ||
family: computedStyles.getPropertyValue('--font-family-base'), | ||
}, | ||
borderColor: computedStyles.getPropertyValue('--color-border-primary'), | ||
titleColor: computedStyles.getPropertyValue('--color-content-primary'), | ||
bodyColor: computedStyles.getPropertyValue('--color-content-primary'), | ||
borderWidth: 1, | ||
}, | ||
legend: { | ||
display: false, | ||
}, | ||
}, | ||
maintainAspectRatio: false, | ||
responsive: true, | ||
} as ChartOptions<'line'> | ||
</script> | ||
|
||
<Chart type="line" height={600} {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
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
Oops, something went wrong.