| 1 |
<script lang="ts"> |
| 2 |
import { _ } from "../i18n"; |
| 3 |
import { hierarchyChartMode } from "../stores/chart"; |
| 4 |
import type { HierarchyChart } from "./hierarchy"; |
| 5 |
import Sunburst from "./Sunburst.svelte"; |
| 6 |
import Treemap from "./Treemap.svelte"; |
| 7 |
|
| 8 |
interface Props { |
| 9 |
chart: HierarchyChart; |
| 10 |
width: number; |
| 11 |
} |
| 12 |
|
| 13 |
let { chart, width }: Props = $props(); |
| 14 |
|
| 15 |
let data = $derived(chart.data); |
| 16 |
let currencies = $derived(chart.currencies); |
| 17 |
|
| 18 |
let treemap_currency = $derived(chart.treemap_currency); |
| 19 |
let mode = $derived($hierarchyChartMode); |
| 20 |
let treemap = $derived( |
| 21 |
mode === "treemap" ? data.get($treemap_currency ?? "") : undefined, |
| 22 |
); |
| 23 |
</script> |
| 24 |
|
| 25 |
{#if currencies.length === 0} |
| 26 |
<svg viewBox={`0 0 ${width.toString()} 160`}> |
| 27 |
<text x={width / 2} y={80} text-anchor="middle"> |
| 28 |
{_("Chart is empty.")} |
| 29 |
</text> |
| 30 |
</svg> |
| 31 |
{:else if treemap && $treemap_currency} |
| 32 |
<Treemap data={treemap} currency={$treemap_currency} {width} /> |
| 33 |
{:else if mode === "sunburst"} |
| 34 |
<svg viewBox={`0 0 ${width.toString()} 500`}> |
| 35 |
{#each [...data] as [chart_currency, d], i (chart_currency)} |
| 36 |
<g |
| 37 |
transform={`translate(${((width * i) / currencies.length).toString()},0)`} |
| 38 |
> |
| 39 |
<Sunburst |
| 40 |
data={d} |
| 41 |
currency={chart_currency} |
| 42 |
width={width / currencies.length} |
| 43 |
height={500} |
| 44 |
/> |
| 45 |
</g> |
| 46 |
{/each} |
| 47 |
</svg> |
| 48 |
{/if} |