Skip to content

Commit 7584d7f

Browse files
committed
improve docs
1 parent 8783c4e commit 7584d7f

File tree

3 files changed

+134
-1
lines changed

3 files changed

+134
-1
lines changed

src/routes/marks/line/+page.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,8 @@ BLS Demo:
278278
</Plot>
279279
```
280280

281+
[fork](https://svelte.dev/playground/31a8033153784f33848a7c388a67a82e?version=5)
282+
281283
## Line
282284

283285
The following channels are supported:

src/routes/marks/rect/+page.md

Lines changed: 81 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,85 @@
22
title: Rect mark
33
---
44

5-
The Rect mark can be used to add rectangles to the plot, defined by x1, y1, x2, and y2 coordinates:
5+
The Rect mark can be used to add rectangles to the plot, defined by x1, y1, x2, and y2 coordinates. It is useful in cases where both the x and y axis are using quantitative scales.
6+
7+
:::tip
8+
**Tip:** If one of your axes is a band scale, you may want to use the [Bar](/marks/bar) marks instead, and if both axes are band scales you probably need the [Cell](/marks/cell) mark.
9+
:::
10+
11+
In it's purest form, the `<Rect>` mark will just add rectangles at the given coordinates:
12+
13+
```svelte live
14+
<script>
15+
import { Plot, Rect, Text } from 'svelteplot';
16+
17+
const data = [
18+
{
19+
x1: 10,
20+
x2: 15,
21+
y1: 5,
22+
y2: 9
23+
},
24+
{
25+
x1: 7,
26+
x2: 12,
27+
y1: 7,
28+
y2: 13
29+
}
30+
];
31+
</script>
32+
33+
<Plot grid inset={10}>
34+
<Rect
35+
{data}
36+
x1="x1"
37+
x2="x2"
38+
y1="y1"
39+
y2="y2"
40+
stroke="currentColor"
41+
fill="currentColor"
42+
fillOpacity={0.5} />
43+
</Plot>
44+
```
45+
46+
```svelte
47+
<Plot grid inset={10}>
48+
<Rect {data} x1="x1" x2="x2" y1="y1" y2="y2" />
49+
</Plot>
50+
```
51+
52+
[fork](https://svelte.dev/playground/7a6b0ae12c624ffeb52448adac644b5b?version=5)
53+
54+
If your data does not come with x1/x2 and y1/y2 pairs but x/y coordinates, you can use the implicit interval transform:
55+
56+
```svelte live
57+
<script>
58+
import { Plot, Rect, Text } from 'svelteplot';
59+
60+
const data = [
61+
{ x: 1, y1: 5, y2: 8 },
62+
{ x: 3, y1: 7, y2: 11 }
63+
];
64+
</script>
65+
66+
<Plot grid inset={10}>
67+
<Rect
68+
{data}
69+
x="x"
70+
y1="y1"
71+
y2="y2"
72+
interval={1}
73+
stroke="currentColor"
74+
fill="currentColor"
75+
fillOpacity={0.5} />
76+
</Plot>
77+
```
78+
79+
```svelte
80+
<Plot grid inset={10}>
81+
<Rect {data} x="x" y="y" interval={1} />
82+
</Plot>
83+
```
684

785
The interval transform may be used to convert a single value in x or y (or both) into an extent. For example, the chart below shows the observed daily maximum temperature in Seattle for the year 2015. The day-in-month and month-in-year numbers are expanded to unit intervals by setting the [interval option](/transforms/interval) to 1.
886

@@ -55,6 +133,8 @@ The interval transform may be used to convert a single value in x or y (or both)
55133
</Plot>
56134
```
57135

136+
## Rect
137+
58138
## RectX
59139

60140
RectX can be used for range annotations:

src/routes/tests/rect/+page.md

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
```svelte live
2+
<script>
3+
import { Plot, BarY, RectY, RuleY } from 'svelteplot';
4+
5+
const timeseries = [
6+
{ year: 2014, population: 2295 },
7+
{ year: 2015, population: 3379 },
8+
{ year: 2016, population: 4464 },
9+
{ year: 2017, population: 5547 },
10+
{ year: 2019, population: 6713 },
11+
{ year: 2020, population: 7795 }
12+
];
13+
</script>
14+
15+
<Plot title="RectY" y={{ grid: true }} marginRight={20}>
16+
<RectY
17+
data={timeseries}
18+
x="year"
19+
y="population"
20+
interval={1}
21+
insetLeft={2}
22+
insetRight={2} />
23+
<RuleY y={0} />
24+
</Plot>
25+
```
26+
27+
```svelte live
28+
<script>
29+
import { Plot, RectX, RuleX } from 'svelteplot';
30+
31+
const timeseries = [
32+
{ year: 2014, population: 2295 },
33+
{ year: 2015, population: 3379 },
34+
{ year: 2016, population: 4464 },
35+
{ year: 2017, population: 5547 },
36+
{ year: 2019, population: 6713 },
37+
{ year: 2020, population: 7795 }
38+
];
39+
</script>
40+
41+
<Plot title="RectX" x={{ grid: true }} marginRight={20}>
42+
<RectX
43+
data={timeseries}
44+
y="year"
45+
x="population"
46+
interval={1}
47+
insetTop={2}
48+
insetBottom={2} />
49+
<RuleX x={0} />
50+
</Plot>
51+
```

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