Skip to content

Commit 031fa05

Browse files
committed
docs: add rule examples
1 parent a952693 commit 031fa05

File tree

10 files changed

+100
-0
lines changed

10 files changed

+100
-0
lines changed
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<script module>
2+
export const title = 'Rule';
3+
</script>
4+
5+
<h1>Rule examples</h1>
6+
7+
<p>
8+
Here are examples related to the <a href="/marks/rule"
9+
>rule</a> mark.
10+
</p>
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<script module>
2+
export const title = 'Data rules';
3+
export const description =
4+
'Note that you probably want to use TickY instead of a faceted RuleY.';
5+
</script>
6+
7+
<script lang="ts">
8+
import { Plot, RuleY } from 'svelteplot';
9+
import { page } from '$app/state';
10+
import type { ExamplesData } from '../types';
11+
let { aapl } = $derived(page.data.data) as ExamplesData;
12+
13+
const monthNames = [
14+
'Jan',
15+
'Feb',
16+
'Mar',
17+
'Apr',
18+
'May',
19+
'Jun',
20+
'Jul',
21+
'Aug',
22+
'Sep',
23+
'Oct',
24+
'Nov',
25+
'Dec'
26+
];
27+
</script>
28+
29+
<Plot inset={10}>
30+
<RuleY
31+
data={aapl.slice(0, 150)}
32+
y="Close"
33+
fx={(d) => monthNames[d.Date.getMonth()]} />
34+
</Plot>
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<script module>
2+
export const title = 'Min/max rules';
3+
</script>
4+
5+
<script lang="ts">
6+
import { Plot, Line, RuleY, binX } from 'svelteplot';
7+
import { page } from '$app/state';
8+
import type { ExamplesData } from '../types';
9+
import { max, min } from 'd3-array';
10+
let { aapl } = $derived(page.data.data) as ExamplesData;
11+
</script>
12+
13+
<Plot>
14+
<Line
15+
data={aapl}
16+
x="Date"
17+
y="Close"
18+
strokeOpacity={0.5} />
19+
<RuleY
20+
stroke="var(--svp-blue)"
21+
{...binX(
22+
{
23+
data: aapl,
24+
x: 'Date',
25+
y: 'Close'
26+
},
27+
{ y: 'max', interval: 'year' }
28+
)} />
29+
<RuleY
30+
stroke="var(--svp-red)"
31+
{...binX(
32+
{
33+
data: aapl,
34+
x: 'Date',
35+
y: 'Close'
36+
},
37+
{ y: 'min', interval: 'year' }
38+
)} />
39+
</Plot>
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<script module>
2+
export const title = 'Y Baseline';
3+
export const description =
4+
'A simple horizontal rule at y=0.';
5+
</script>
6+
7+
<script lang="ts">
8+
import { Plot, Line, RuleY } from 'svelteplot';
9+
import { page } from '$app/state';
10+
import type { ExamplesData } from '../types';
11+
let { aapl } = $derived(page.data.data) as ExamplesData;
12+
</script>
13+
14+
<Plot>
15+
<RuleY y={0} />
16+
<Line data={aapl} x="Date" y="Close" />
17+
</Plot>
24.2 KB
Loading

static/examples/rule/data-rules.png

24.1 KB
Loading

static/examples/rule/min-max.dark.png

34.1 KB
Loading

static/examples/rule/min-max.png

33.7 KB
Loading
36 KB
Loading

static/examples/rule/y-baseline.png

34.8 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