Skip to content

Commit e3da008

Browse files
committed
simple bar chart
1 parent 317b177 commit e3da008

File tree

1 file changed

+33
-3
lines changed

1 file changed

+33
-3
lines changed

usr-web/src/routes/(apps)/manifest/+page.svelte

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@
2828
link: string;
2929
}
3030
let orders: Order[] = $state([]);
31+
let expenditures: Record<string, number> = $state({});
32+
let maxExpenditure = $state(0);
3133
3234
interface OrderStatus {
3335
order_id: number;
@@ -58,6 +60,18 @@
5860
setTimeout(() => {
5961
fetching = false;
6062
}, 500);
63+
64+
expenditures = orders.reduce<Record<string, number>>((acc, order) => {
65+
const team = order.team;
66+
const subtotal = order.count * (order.unit_cost as number);
67+
if (acc[team] === undefined) {
68+
acc[team] = 0;
69+
}
70+
acc[team] += subtotal;
71+
return acc;
72+
}, {});
73+
74+
maxExpenditure = Math.max(...Object.values(expenditures));
6175
}
6276
6377
if (browser) {
@@ -502,13 +516,29 @@
502516
{/if}
503517
{:else if tabIndex === 4}
504518
{#snippet cost(team: string)}
505-
<p>{team} Total: {orders
506-
.filter(o => o.team === team)
507-
.reduce((acc, cur) => acc + cur.count * (cur.unit_cost as number), 0).toLocaleString('en-US', { style: 'currency', currency: 'USD' })}</p>
519+
<p>{team} Total: {(expenditures[team] ?? 0).toLocaleString(
520+
'en-US',
521+
{ style: 'currency', currency: 'USD' }
522+
)}</p>
508523
{/snippet}
509524
{@render cost("Software")}
510525
{@render cost("Mechanical")}
511526
{@render cost("Electrical")}
527+
528+
<section class="flex flex-row gap-4 w-min p-4" style:min-height="20rem" style:background-color="darkgray">
529+
{#snippet bar(team: string)}
530+
<div class="flex flex-col">
531+
<div class="flex flex-col justify-end flex-grow">
532+
<div style:background-color="darkred" style:height={`calc(100% * ${expenditures[team] / maxExpenditure})`}>
533+
</div>
534+
</div>
535+
<p>{team}</p>
536+
</div>
537+
{/snippet}
538+
{@render bar("Software")}
539+
{@render bar("Mechanical")}
540+
{@render bar("Electrical")}
541+
</section>
512542
{/if}
513543
</section>
514544
</section>

0 commit comments

Comments
 (0)