Skip to content

Commit 8fcd536

Browse files
committed
add streamgraph example
1 parent b263fe6 commit 8fcd536

File tree

7 files changed

+86
-2
lines changed

7 files changed

+86
-2
lines changed

screenshot-examples.js

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ const OUTPUT_DIR = path.join(__dirname, 'static', 'examples');
1212
const SCREENSHOT_WIDTH = 600;
1313
const DEVICE_PIXEL_RATIO = 2;
1414

15+
// Only take missing screenshots if ENV variable is set
16+
const ONLY_MISSING = process.env.ONLY_MISSING == 1;
17+
1518
// Start the development server and return server instance and local URL
1619
const startServer = () => {
1720
console.log('Starting development server...');
@@ -70,6 +73,26 @@ const getSvelteFiles = async (dir) => {
7073
return files.flat();
7174
};
7275

76+
const getExistingScreenshots = async (dir) => {
77+
const entries = await fs.readdir(dir, { withFileTypes: true });
78+
79+
const files = await Promise.all(
80+
entries.map(async (entry) => {
81+
const fullPath = path.join(dir, entry.name);
82+
83+
if (entry.isDirectory()) {
84+
return getExistingScreenshots(fullPath);
85+
} else if (entry.isFile() && entry.name.endsWith('.png')) {
86+
return [fullPath];
87+
}
88+
89+
return [];
90+
})
91+
);
92+
93+
return files.flat();
94+
};
95+
7396
// Convert file path to URL path
7497
const filePathToUrlPath = (filePath) => {
7598
const relativePath = path.relative(EXAMPLES_DIR, filePath);
@@ -161,9 +184,35 @@ const screenshotExamples = async () => {
161184
});
162185

163186
// Get all example Svelte files
164-
const svelteFiles = await getSvelteFiles(EXAMPLES_DIR);
187+
let svelteFiles = await getSvelteFiles(EXAMPLES_DIR);
165188
console.log(`Found ${svelteFiles.length} example files to screenshot`);
166189

190+
if (ONLY_MISSING) {
191+
// Filter to only include files that don't have screenshots ()
192+
const existingScreenshots = (await getExistingScreenshots(OUTPUT_DIR)).map((file) =>
193+
path.relative(OUTPUT_DIR, file)
194+
);
195+
196+
console.log(`Found ${existingScreenshots.length} existing screenshots`);
197+
198+
// Filter out files that already have screenshots
199+
svelteFiles = svelteFiles.filter((filePath) => {
200+
return (
201+
!existingScreenshots.find((screenshot) =>
202+
filePath.endsWith(screenshot.replace('.png', '.svelte'))
203+
) ||
204+
!existingScreenshots.find((screenshot) =>
205+
filePath.endsWith(screenshot.replace('.dark.png', '.svelte'))
206+
)
207+
);
208+
});
209+
210+
console.log(
211+
`Filtered down to ${svelteFiles.length} files needing screenshots`,
212+
svelteFiles
213+
);
214+
}
215+
167216
// Process each file
168217
for (const filePath of svelteFiles) {
169218
const urlPath = filePathToUrlPath(filePath);

src/routes/examples/area/area-x.svelte

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
import { Plot, AreaX } from 'svelteplot';
77
import { page } from '$app/state';
88
import type { ExamplesData } from '../types';
9-
import { setContext } from 'svelte';
109
let { aapl } = $derived(page.data.data) as ExamplesData;
1110
</script>
1211

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<script module>
2+
export const title = 'Streamgraph';
3+
</script>
4+
5+
<script lang="ts">
6+
import { Plot, AreaY } from '$lib/index.js';
7+
import { page } from '$app/state';
8+
import type { ExamplesData } from '../types';
9+
const { riaa } = $derived(
10+
page.data.data
11+
) as ExamplesData;
12+
</script>
13+
14+
<Plot
15+
marginLeft={0}
16+
x={{ grid: true }}
17+
y={{ axis: false }}
18+
color={{ legend: true }}>
19+
<AreaY
20+
data={riaa}
21+
x="year"
22+
y="revenue"
23+
z="format"
24+
curve="basis"
25+
fill="group"
26+
opacity={0.8}
27+
stack={{ offset: 'wiggle', order: 'inside-out' }} />
28+
</Plot>

src/routes/examples/types.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,13 @@ type BeagleRow = {
7474
lat: number;
7575
};
7676

77+
type RiaaRow = {
78+
year: Date;
79+
format: string;
80+
group: string;
81+
revenue: number;
82+
};
83+
7784
export type ExamplesData = {
7885
aapl: AaplRow[];
7986
simpsons: SimpsonsRow[];
@@ -85,4 +92,5 @@ export type ExamplesData = {
8592
};
8693
world: any;
8794
beagle: BeagleRow[];
95+
riaa: RiaaRow[];
8896
};

static/examples/area/area-x.dark.png

23 Bytes
Loading
48.6 KB
Loading

static/examples/area/streamgraph.png

48.2 KB
Loading

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy