Skip to content

Commit 3cee0da

Browse files
authored
Merge pull request #76 from WJSoftware:JP/drilldown_demo
feat(demo): Add sales drilldown demo page
2 parents 30f7c05 + ff14cee commit 3cee0da

26 files changed

+939
-74
lines changed

src/data-models.d.ts

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,47 @@ export type Person = {
99
country_code: string;
1010
credit_score: number;
1111
net_worth: number;
12-
};
12+
};
13+
14+
export type GeoSale = {
15+
id: number;
16+
country_code: string;
17+
country_name: string;
18+
city: string;
19+
month: number;
20+
year: number;
21+
sales_amount: number;
22+
product_category: string;
23+
quantity_sold: number;
24+
total_sales: number;
25+
total_costs: number;
26+
top_client: string;
27+
top_client_fraction: number;
28+
};
29+
30+
export type GeoSaleQuantities = {
31+
sales_amount: number;
32+
quantity_sold: number;
33+
total_sales: number;
34+
total_costs: number;
35+
};
36+
37+
export type GeoSaleByCountry = GeoSaleQuantities & {
38+
country_code: string;
39+
country_name: string;
40+
}
41+
42+
export type GeoSaleByCity = GeoSaleByCountry & {
43+
city: string;
44+
};
45+
46+
export type GeoSalesResult = {
47+
detail: GeoSale[];
48+
byCountry: GeoSaleByCountry[];
49+
byCity: GeoSaleByCity[];
50+
};
51+
52+
export type GeoSaleColumn = {
53+
dataType?: 'string' | 'currency' | 'real-amount' | 'int-amount';
54+
numberFormatter?: Intl.NumberFormat;
55+
};

src/demolib/EditInGitHub.svelte

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<script lang="ts">
2+
type Props = {
3+
editUrl: string;
4+
};
5+
6+
let {
7+
editUrl,
8+
}: Props = $props();
9+
</script>
10+
<a
11+
class="position-absolute bottom-0 end-0 rounded-circle btn btn-sm btn-secondary mb-3 me-3 semi-transparent"
12+
title="See an error? Want to improve the demo? Curious about the source code? View/edit this page in GitHub."
13+
href={editUrl}
14+
target="_blank"
15+
>
16+
<i class="bi bi-pencil"></i>
17+
</a>
18+
19+
<style lang="scss">
20+
.semi-transparent {
21+
opacity: 0.4;
22+
&:hover {
23+
opacity: 1;
24+
}
25+
}
26+
</style>
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
export class GlobalOptions {
2+
noViewportInChildren = $state(true);
3+
}
4+
5+
export const globalOptions = new GlobalOptions();

src/demolib/Numeric.svelte

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<script lang="ts">
2+
import { browser } from "$app/environment";
3+
4+
type Props = {
5+
formatter?: Intl.NumberFormat;
6+
value: number;
7+
};
8+
9+
let {
10+
formatter = new Intl.NumberFormat(browser ? navigator?.language : undefined, { maximumFractionDigits: 4 }),
11+
value,
12+
}: Props = $props();
13+
</script>
14+
15+
<span class="numeric">{formatter.format(value)}</span>
16+
17+
<style>
18+
span.numeric {
19+
font-family: monospace;
20+
}
21+
</style>
File renamed without changes.

src/demolib/nextControlId.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
let nextId = 0;
2+
3+
export function nextControlId(prefix?: string) {
4+
return `${prefix ?? 'control'}${++nextId}`;
5+
};

src/demolib/numberFormatters.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { browser } from "$app/environment";
2+
3+
export const currencyFormatter = new Intl.NumberFormat(browser ? navigator?.language : undefined, {
4+
style: 'currency',
5+
currency: 'USD',
6+
currencyDisplay: 'narrowSymbol'
7+
});
8+
9+
export function amountFormatterFactory(decimalPlaces: number) {
10+
return new Intl.NumberFormat(browser ? navigator?.language : undefined, {
11+
style: 'decimal',
12+
minimumFractionDigits: decimalPlaces,
13+
maximumFractionDigits: decimalPlaces,
14+
});
15+
}
16+
17+
export const fractionFormatter = new Intl.NumberFormat(browser ? navigator?.language : undefined, {
18+
style: 'percent',
19+
minimumFractionDigits: 0,
20+
maximumFractionDigits: 2,
21+
});
File renamed without changes.

src/index.html

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,15 @@
77
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" class="" integrity="sha384-QWTKZyjpPEjISv5WaRU9OFeRpok6YctnYmDr5pNlyT2bRjXh0JMhjY6hW+ALEwIH" crossorigin="anonymous">
88
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/font/bootstrap-icons.min.css">
99
<title>wjfe@dataview - Svelte v5 Data View Component</title>
10+
<script type="text/javascript">
11+
(function () {
12+
var redirect = sessionStorage.redirect;
13+
delete sessionStorage.redirect;
14+
if (redirect && redirect != location.href) {
15+
history.replaceState(null, null, redirect);
16+
}
17+
})();
18+
</script>
1019
%sveltekit.head%
1120
</head>
1221
<body data-sveltekit-preload-data="hover">

src/routes/+layout.svelte

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,27 @@
11
<script lang="ts">
2+
import { base } from "$app/paths";
23
import type { Snippet } from "svelte";
3-
import ThemeSwitch from "./ThemeSwitch.svelte";
44
import "../app.scss";
5+
import ThemeSwitch from "./ThemeSwitch.svelte";
56
67
let { children }: {
78
children: Snippet
89
} = $props();
910
</script>
1011

1112
<div class="d-flex flex-column doc-container">
12-
<nav class="navbar bg-primary-subtle px-3">
13+
<nav class="navbar navbar-expand-md bg-primary-subtle px-3">
1314
<span class="navbar-brand">WjDataView Demo</span>
15+
<div class="navbar-collapse">
16+
<ul class="navbar-nav">
17+
<li class="nav-item">
18+
<a href={base} class="nav-link">Overview (Home)</a>
19+
</li>
20+
<li class="nav-item">
21+
<a href="{base}/sales" class="nav-link">Data Drilldown Demo</a>
22+
</li>
23+
</ul>
24+
</div>
1425
<a
1526
href="https://github.com/WJSoftware/wjfe-dataview"
1627
title="Repository"
@@ -22,7 +33,7 @@
2233
<ThemeSwitch />
2334
</nav>
2435
<div class="flex-fill overflow-auto">
25-
<div class="container-fluid overflow-auto h-100">
36+
<div class="container-fluid overflow-auto h-100 theme-def d-flex flex-column">
2637
{@render children()}
2738
</div>
2839
</div>
@@ -72,4 +83,16 @@
7283
.footer-logo {
7384
height: 1em;
7485
}
86+
87+
.theme-def {
88+
--wjdv-sky-bg-rgb: 200, 240, 250;
89+
--wjdv-sky-color: var(--bs-black);
90+
--bs-row-selection-bg-color-rgb: 221, 235, 255;
91+
92+
:global([data-bs-theme="dark"]) & {
93+
--wjdv-sky-bg-rgb: 30, 90, 120;
94+
--wjdv-sky-color: var(--bs-white);
95+
--bs-row-selection-bg-color-rgb: 21, 35, 55;
96+
}
97+
}
7598
</style>

0 commit comments

Comments
 (0)