-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathexample-flourish.qmd
More file actions
176 lines (144 loc) · 3.64 KB
/
example-flourish.qmd
File metadata and controls
176 lines (144 loc) · 3.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
---
title: "RoughNotation + Flourish"
subtitle: "Animated code annotations"
format:
revealjs:
footer: <https://github.com/emilhvitfeldt/quarto-roughnotation>
filters:
- flourish
- roughnotation
---
## Setup
Install both extensions:
```bash
quarto add EmilHvitfeldt/quarto-roughnotation
quarto add kbodwin/flourish
```
Then add both as filters (order matters - flourish first):
```yaml
filters:
- flourish
- roughnotation
```
## Basic Usage
Use flourish's `style` option to pass roughnotation config via CSS custom properties:
```yaml
#| flourish:
#| - target: "mean"
#| style: "--rn-type: circle; --rn-color: red;"
```
## Circle annotation
```{r}
#| echo: true
#| flourish:
#| - target: "mean"
#| style: "--rn-type: circle; --rn-color: red;"
x <- c(1, 2, 3, 4, 5)
mean(x)
```
## Underline annotation
```{r}
#| echo: true
#| flourish:
#| - target: "quantile"
#| style: "--rn-type: underline; --rn-color: blue; --rn-strokeWidth: 3;"
x <- c(1, 2, 3, 4, 5)
quantile(x)
```
## Box annotation
```{r}
#| echo: true
#| flourish:
#| - target: "lm"
#| style: "--rn-type: box; --rn-color: purple;"
model <- lm(mpg ~ wt, data = mtcars)
summary(model)
```
## Highlight annotation
```{r}
#| echo: true
#| flourish:
#| - target: "filter"
#| style: "--rn-type: highlight; --rn-color: #ffeb3b80;"
library(dplyr)
mtcars |> filter(mpg > 20)
```
## Multiple targets
````md
```{{r}}
#| echo: true
#| flourish:
#| - target: "mean"
#| style: "--rn-type: circle; --rn-color: red; --rn-index: 1;"
#| - target: "quantile"
#| style: "--rn-type: underline; --rn-color: blue; --rn-index: 2;"
#| - target: "median"
#| style: "--rn-type: box; --rn-color: green; --rn-index: 3;"
x <- c(1, 2, 3, 4, 5)
mean(x)
quantile(x)
median(x)
```
````
## Multiple targets
```{r}
#| echo: true
#| flourish:
#| - target: "mean"
#| style: "--rn-type: circle; --rn-color: red; --rn-index: 1;"
#| - target: "quantile"
#| style: "--rn-type: underline; --rn-color: blue; --rn-index: 2;"
#| - target: "median"
#| style: "--rn-type: box; --rn-color: green; --rn-index: 3;"
x <- c(1, 2, 3, 4, 5)
mean(x)
quantile(x)
median(x)
```
## Regex targeting
Use flourish's `target-rx` for pattern matching:
````md
```{{r}}
#| echo: true
#| flourish:
#| - target-rx: "mpg|wt|hp"
#| style: "--rn-type: highlight; --rn-color: #e91e6380;"
head(mtcars[, c("mpg", "wt", "hp")])
```
````
## Regex targeting
Use flourish's `target-rx` for pattern matching:
```{r}
#| echo: true
#| flourish:
#| - target-rx: "mpg|wt|hp"
#| style: "--rn-type: highlight; --rn-color: #e91e6380;"
head(mtcars[, c("mpg", "wt", "hp")])
```
## Available options
All roughnotation options work via CSS custom properties:
::: {style="font-size: 0.55em;"}
| Property | Example | Description |
|----------|---------|-------------|
| `--rn-type` | `circle` | underline, box, circle, highlight, strike-through, crossed-off, bracket |
| `--rn-color` | `red` | Any CSS color |
| `--rn-animate` | `true` | Enable/disable animation |
| `--rn-animationDuration` | `800` | Duration in ms |
| `--rn-strokeWidth` | `2` | Line thickness |
| `--rn-padding` | `5` | Space around element |
| `--rn-multiline` | `true` | Annotate across lines |
| `--rn-iterations` | `2` | Drawing passes |
| `--rn-brackets` | `left,right` | Bracket sides |
| `--rn-index` | `1` | Fragment order |
:::
## Combining with regular text
You can mix code annotations with regular text annotations:
This text has a [highlighted word]{.rn-fragment rn-color=orange}.
```{r}
#| echo: true
#| flourish:
#| - target: "ggplot"
#| style: "--rn-type: box; --rn-color: steelblue;"
library(ggplot2)
ggplot(mtcars, aes(wt, mpg)) + geom_point()
```