Skip to content

Commit 7d59e49

Browse files
author
James Goldie
committed
Update documentation
1 parent c5962e2 commit 7d59e49

File tree

6 files changed

+94
-74
lines changed

6 files changed

+94
-74
lines changed

README.md

+22-15
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,6 @@
44

55
Your Svelte components can seamlessly react to your ObservableJS code, making it quick and easy to build visuals that animate in response to [user inputs](https://observablehq.com/@observablehq/inputs?collection=@observablehq/inputs) or other changing data in your document.
66

7-
## 💭 Why Sverto?
8-
9-
[Quarto](https://quarto.org) helps users build beautiful documents regardless of their language of choice, and it encourages data analysts and scientists to explore web visualisation by making JavaScript accessible and easy to use. It makes interactive visualisations intuitive to write, but animated visuals are still a challenge that require either dipping into a high-level JavaScript library or learning a lower-level one like [d3](https://d3js.org).
10-
11-
[Svelte](https://svelte.dev) is a framework for building web visualisations and apps in JavaScript. Svelte goes out of its way to make writing self-contained components, like charts, comfortable and intuitive. It has a great [playground environment](https://svelte.dev/repl/hello-world?version=3.55.1) for developing and testing components, but like many web frameworks, the experience is much more complex when you start developing locally.
12-
13-
_Sverto aims to make it as easy to use Svelte components in Quarto documents as it is to work on them in the Svelte REPL: just write a `.svelte` file, add it to a Quarto document, and Sverto should take care of the rest._
14-
157
## 📋 Prerequisites
168

179
You'll need to install two things to run Sverto:
@@ -35,7 +27,15 @@ npm install
3527

3628
This will add the extension itself (which includes some project scripts) to the `_extension` folder, as well as a few other files.
3729

38-
> **Note:** Sverto depends on running [project pre-render scripts](https://quarto.org/docs/projects/scripts.html#pre-and-post-render), so you can't currently use it with single documents.
30+
### 📦 What's in the box?
31+
32+
When you use the Sverto template in a project, it creates some files for you:
33+
34+
* [`example.qmd`](./example.qmd): an example Quarto doc that uses a Svelte component
35+
* [`Circles.svelte`](./Circles.svelte): an example Svelte visualisation
36+
* [`package.json`](./package.json): this is used to keep track of the dependencies of your Svelte components. **You should add this to version control.**
37+
* `package-lock.json` is created once you run `npm install`. You should add this to version control.
38+
* `node_modules/`: This folder is created once you rum `npm install`. Don't add it to version control.
3939

4040
## 🎉 Use
4141

@@ -83,9 +83,10 @@ myChart.chartData = myData.filter(d => d.year == selectedYear)
8383
```
8484
````
8585

86-
> **Note:** `quarto preview` won't "live reload" when you modify your Svelte component—but if you modify and save the Quarto doc that imports it, that will trigger a re-render. You may need to hard reload the page in your browser to see the updated Svelte component.
86+
> ![NOTE]
87+
> `quarto preview` won't "live reload" when you modify your Svelte component—but if you modify and save the Quarto doc that imports it, that will trigger a re-render. You may need to hard reload the page in your browser to see the updated Svelte component.
8788
>
88-
> If you want to quickly iterate on the Svelte component and you aren't too concerned about the rest of your Quarto doc, you might find the [Svelte Preview](https://marketplace.visualstudio.com/items?itemName=RafaelMartinez.svelte-preview) extension for VSCode handy.
89+
> If you want to quickly iterate on the Svelte component, you might find the [Svelte Preview](https://marketplace.visualstudio.com/items?itemName=RafaelMartinez.svelte-preview) extension for VSCode handy.
8990
9091
## 📦 What's in the box?
9192

@@ -105,14 +106,20 @@ As well as the project format, Sverto ships with document formats (the default i
105106
If you want to refer to other JavaScript libraries in your Svelte component (like d3, for example), add them to the project using `npm install package1 [package2 ...]`. For example:
106107

107108
```
108-
npm install d3-scale
109+
npm install d3
109110
```
110111

111-
## Use pre-compiled Svelte components
112+
# 💭 Why Sverto?
113+
114+
[Quarto](https://quarto.org) helps data scientists and analysts build beautiful documents regardless of their language of choice, and it encourages data analysts and scientists to explore web visualisation by making JavaScript accessible and easy to use.
115+
116+
Quarto makes interactive charts intuitive to write, but animated ones are still a challenge that require either dipping into a high-level JavaScript library or learning a lower-level one like [d3](https://d3js.org).
117+
118+
[Svelte](https://svelte.dev) is a framework for building charts, web visualisations and even apps in HTML, CSS and JavaScript. Svelte goes out of its way to make writing self-contained components, like charts, comfortable and intuitive.
112119

113-
If you'd prefer to compile your own Svelte components instead of letting this extension do it, you can skip steps 1 and 2 and simply refer to the compiled bundle with, for example, `Component = import("Component.js")` in an OJS block.
120+
Svelte has a great [playground environment](https://svelte.dev/repl/hello-world?version=3.55.1) for developing and testing components, but like many web frameworks, the experience is much more complex when you start developing locally.
114121

115-
> **Note:** you must compile the Svelte component to an ES6 bundle, and you must enable accessors when compiling if you want to be able to update them from OJS. Refer to `_extensions/sverto/rollup.config.js` for guidance on configuring Rollup to do this.
122+
_Sverto aims to make it as easy to build and use animated Svelte charts in Quarto documents as it is to work on them in the Svelte playground: just write a `.svelte` file, add it to a Quarto document, and Sverto takes care of the rest._
116123

117124
## ❓ Issues
118125

docs/_quarto.yml

+4-3
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ website:
1515
menu:
1616
- text: "Simple bar chart"
1717
file: examples/barchart/index.qmd
18-
- text: "Time series"
18+
- text: "Time series chart"
1919
file: examples/time-series/index.qmd
2020
- text: Changelog
2121
file: news.qmd
@@ -26,7 +26,8 @@ website:
2626

2727
format:
2828
html:
29-
title-block-banner: "#e1e4e6"
30-
theme: default
29+
# title-block-banner: "#e1e4e6"
30+
title-block-banner: true
31+
theme: [default, style.scss]
3132
linkcolor: "#36a7e9"
3233

docs/examples/barchart/index.qmd

+9-4
Original file line numberDiff line numberDiff line change
@@ -152,11 +152,10 @@ How did we get this chart going again?
152152
1. Add `filters: ["sverto"]` to our frontmatter, plus the name of our Svelte file to `sverto.use`
153153
2. Created the chart with `myBarChart = new BarChart.default()`, giving it a `target` to place the chart in
154154
3. We created the `target` with a Pandoc div: `:::{#mybarchart}`
155-
4. We customised the bar chart with `myBarChart.propName`
155+
4. We customised the bar chart by assigning to `myBarChart.propName`
156156

157157
# Challenges
158158

159-
160159
Here's the code in the Svelte file:
161160

162161
:::{.callout-note appearance="simple" collapse="true" title="BarChart.svelte"}
@@ -165,7 +164,7 @@ Here's the code in the Svelte file:
165164
```
166165
:::
167166

168-
if you'd like to start practising your Svelte, start with [the official tutorial](https://learn.svelte.dev/tutorial/welcome-to-svelte). Sverto is designed to make using Svelte components in Quarto as easy as working in the tutorial.
167+
If you'd like to start practising your Svelte, start with [the official tutorial](https://learn.svelte.dev/tutorial/welcome-to-svelte). Sverto is designed to make using Svelte components in Quarto as easy as working in the tutorial.
169168

170169
This Svelte component's pretty basic, though. What else is it missing?
171170

@@ -188,4 +187,10 @@ The bars are all the same colour. We could write a function that converts each b
188187
`d3` is included with OJS, but if you want to use `d3-scale-chromatic` (or any other part of d3) in your Svelte components, you'll have to add it yourself by:
189188

190189
- running `npm install d3-scale-chromatic` in the terminal, then
191-
- adding `import XXXX from "d3-scale-chromatic"`, where `XXXX` is the name of the thing you want to import (or `*`).
190+
- adding `import XXXX from "d3-scale-chromatic"`, where `XXXX` is the name of the thing you want to import (or `*`).
191+
192+
### A more complex example
193+
194+
If you'd like to see an example that addresses some of these shortcomings, check out the [time series chart example](../time-series), which automatically resizes and adds axes that transition!
195+
196+
[See the time series chart →]((../time-series)){.btn .btn-success}

docs/index.qmd

+43-41
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,22 @@
11
---
22
title: Sverto
33
description: "**Sverto** is an extension for [Quarto](https://quarto.org) that lets you seamlessly write and include [Svelte](https://svelte.dev) components, like charts and other visuals, in your Quarto website."
4-
author: James Goldie
5-
date: last-modified
64
format:
75
html:
86
toc: true
97
toc-location: left
108
---
119

12-
Your Svelte components can seamlessly react to your ObservableJS code, making it quick and easy to build bespoke visuals that animate in response to [user inputs](https://observablehq.com/@observablehq/inputs?collection=@observablehq/inputs) or other changing data in your document.
10+
Your Svelte components can seamlessly react to your [Observable JavaScript](https://quarto.org/docs/interactive/ojs/) code, making it quick and easy to build bespoke visuals that animate in response to [user inputs](https://observablehq.com/@observablehq/inputs?collection=@observablehq/inputs) or other changing data in your document.
1311

14-
## 💭 Why Sverto?
15-
16-
[Quarto](https://quarto.org) helps users build beautiful documents regardless of their language of choice, and it encourages data analysts and scientists to explore web visualisation by making JavaScript accessible and easy to use. It makes interactive visualisations intuitive to write, but animated visuals are still a challenge that require either dipping into a high-level JavaScript library or learning a lower-level one like [d3](https://d3js.org).
17-
18-
[Svelte](https://svelte.dev) is a framework for building web visualisations and apps in JavaScript. Svelte goes out of its way to make writing self-contained components, like charts, comfortable and intuitive. It has a great [playground environment](https://svelte.dev/repl/hello-world?version=3.55.1) for developing and testing components, but like many web frameworks, the experience is much more complex when you start developing locally.
19-
20-
_Sverto aims to make it as easy to use animated Svelte charts in Quarto documents as it is to work on them in the Svelte REPL: just write a `.svelte` file, add it to a Quarto document, and Sverto should take care of the rest._
21-
22-
## 📋 Prerequisites
12+
# 📋 Prerequisites
2313

2414
You'll need to install two things to run Sverto:
2515

2616
- [Quarto](https://quarto.org)
2717
- [Node and the Node Package Manager (npm)](https://nodejs.org)
2818

29-
## ⚙️ Installation
19+
# ⚙️ Installation
3020

3121
Install the project extension using:
3222

@@ -42,15 +32,21 @@ npm install
4232

4333
This will add the extension itself (which includes some project scripts) to the `_extension` folder, as well as a few other files.
4434

45-
:::{.callout-note}
46-
Sverto depends on running [project pre-render scripts](https://quarto.org/docs/projects/scripts.html#pre-and-post-render), so you can't currently use it with single documents.
47-
:::
35+
## 📦 What's in the box?
36+
37+
When you use the Sverto template in a project, it creates some files for you:
4838

49-
## 🎉 Use
39+
* [`example.qmd`](./example.qmd): an example Quarto doc that uses a Svelte component. If you're adding Sverto to an existing document, you can delete this.
40+
* [`Circles.svelte`](./Circles.svelte): an example Svelte visualisation. If you have a Svelte component that you want to use instead, you can delete this.
41+
* [`package.json`](./package.json): this is used to keep track of the dependencies of your Svelte components. **You should add this to version control.**
42+
* `package-lock.json` is created once you run `npm install`. You should add this to version control.
43+
* `node_modules/`: This folder is created once you rum `npm install`. Don't add it to version control.
5044

51-
Here's the quick guide to add Svelte component you've written to a Quarto doc:
45+
# 🎉 Use
5246

53-
### Step 1: add Svelte to your document
47+
Here's the quick guide to add a Svelte component you've written to a Quarto doc:
48+
49+
## Step 1: add Svelte to your document
5450

5551
In the document frontmatter, add `sverto` to `filters`, and add one or more `.svelte` files to `sverto.use`:
5652

@@ -60,21 +56,18 @@ title: "My document"
6056
filters: ["sverto"]
6157
sverto:
6258
use:
63-
example.svelte
59+
- example.svelte
6460
---
6561
```
6662

67-
### Step 2: bring your Svelte component to life
63+
## Step 2: bring your Svelte component to life
6864

6965
Use an [Observable JS](https://quarto.org/docs/interactive/ojs/) chunk to _instantiate_ your Svelte component.
7066

7167
````js
7268
```{ojs}
7369
myChart = new example.default({
7470
target: document.querySelector("#chart")
75-
props: {
76-
chartData: {}
77-
}
7871
})
7972
```
8073

@@ -83,10 +76,10 @@ myChart = new example.default({
8376
````
8477

8578
- the `target` is where it will appear. This needs to be an existing part of the document — you can put a [Pandoc div](https://quarto.org/docs/authoring/markdown-basics.html#divs-and-spans) right after this code, or put one anywhere else on the page
86-
- `example` is the file name of your Svelte component, without the file extension
87-
- if your Svelte component has any `props`, add default values here too. Don't put reactive OJS code in here; we'll update the props separately!
79+
- `example` is the file name of your Svelte component, without the file extension (so if your file is called `example.svelte` call `example.default()`)
80+
- if your Svelte component has any `props` that don't have defaults built in, supply default values here for them too. Don't put reactive OJS code in here; we'll update the props separately!
8881

89-
### Step 3: make your visual reactive
82+
## Step 3: make your visual reactive
9083

9184
If your visual has `props` that allow it to change or transition in response to other OJS code, you can update it by assigning the prop directly.
9285

@@ -96,36 +89,45 @@ For example, if we have a dataset called `myData` in OJS, and a year slider call
9689
myChart.chartData = myData.filter(d => d.year == selectedYear)
9790
````
9891

99-
**To see this all in practice, check out [`example.qmd`](https://github.com/jimjam-slam/sverto/blob/main/example.qmd).**
92+
If you're writing a single document, you're done! Run `quarto render` and see your hard work.
10093

101-
:::{.callout-tip}
102-
If you're using a [Quarto project](https://quarto.org/docs/projects/quarto-projects.html) and you have documents that share Quarto components, add project `project.type: sverto`. All of the Svelte components in your project will be built together, avoiding duplication.
103-
:::
94+
**To see this all in practice, check out the [simple bar chart example](examples/barchart).**
10495

105-
:::{.callout-note}
96+
## Step 4 (for websites): set the project type
97+
98+
If you're using a [Quarto website](https://quarto.org/docs/projects/quarto-projects.html), change the `project.type` in `_quarto.yml` from `website` to `sverto`.
99+
100+
This way, your website pages can share Sverto components when you're rendering the whole website.
101+
102+
:::{.callout-tip appearance="simple" title="Hot reloads"}
106103
The `quarto preview` command won't "live reload" when you modify your Svelte component—but if you modify and save the Quarto doc that imports it, that will trigger a re-render. You may need to hard reload the page in your browser to see the updated Svelte component.
107104

108-
If you want to quickly iterate on the Svelte component and you aren't too concerned about the rest of your Quarto doc, you might find the [Svelte Preview](https://marketplace.visualstudio.com/items?itemName=RafaelMartinez.svelte-preview) extension for VSCode handy.
105+
If you want to quickly iterate on a Svelte component you're building, you might find the [Svelte Preview](https://marketplace.visualstudio.com/items?itemName=RafaelMartinez.svelte-preview) extension for VSCode handy.
109106
:::
110107

108+
# Advanced use
109+
111110
## 🛍 Use other libraries in your Svelte component
112111

113112
If you want to refer to other JavaScript libraries in your Svelte component (like d3, for example), add them to the project using `npm install package1 [package2 ...]`. For example:
114113

115114
```sh
116-
npm install d3-scale
115+
npm install d3
117116
```
117+
# 💭 Why Sverto?
118118

119-
## 🔨 Use pre-compiled Svelte components
119+
[Quarto](https://quarto.org) helps data scientists and analysts build beautiful documents regardless of their language of choice, and it encourages data analysts and scientists to explore web visualisation by making JavaScript accessible and easy to use.
120120

121-
If you'd prefer to compile your own Svelte components instead of letting this extension do it, you can skip steps 1 and 2 and simply refer to the compiled bundle with, for example, `Component = import("Component.js")` in an OJS block.
121+
Quarto makes interactive charts intuitive to write, but animated ones are still a challenge that require either dipping into a high-level JavaScript library or learning a lower-level one like [d3](https://d3js.org).
122122

123-
:::{.callout-note}
124-
You must compile the Svelte component to an ES6 bundle, and you must enable accessors when compiling if you want to be able to update them from OJS. Refer to [`_extensions/sverto/rollup.config.js`](https://github.com/jimjam-slam/sverto/blob/firstrelease/_extensions/sverto/rollup.config.js) for guidance on configuring Rollup to do this.
125-
:::
123+
[Svelte](https://svelte.dev) is a framework for building charts, web visualisations and even apps in HTML, CSS and JavaScript. Svelte goes out of its way to make writing self-contained components, like charts, comfortable and intuitive.
124+
125+
Svelte has a great [playground environment](https://svelte.dev/repl/hello-world?version=3.55.1) for developing and testing components, but like many web frameworks, the experience is much more complex when you start developing locally.
126+
127+
_Sverto aims to make it as easy to build and use animated Svelte charts in Quarto documents as it is to work on them in the Svelte playground: just write a `.svelte` file, add it to a Quarto document, and Sverto takes care of the rest._
126128

127-
## ❓ Issues
129+
# ❓ Issues
128130

129-
If you have any problems with the extension, please feel free to [create an issue](https://github.com/jimjam-slam/sverto)!
131+
If you have any problems with Sverto, please feel free to [create an issue](https://github.com/jimjam-slam/sverto)!
130132

131133
Special thanks to [Carlos Scheidegger](https://github.com/cscheid) from [Posit](https://posit.co) for his time and advice!

docs/news.qmd

+7-11
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,17 @@
22
title: News
33
author: James Goldie
44
date: last-modified
5-
format:
6-
html:
7-
title-block-banner: "#e1e4e6"
8-
linkcolor: "#36a7e9"
95
---
106

11-
## (Unreleased) Sverto 1.0.0
7+
## Sverto 1.0.0
128

13-
- Significant refactor of Sverto makes it easier to use and more compatible with Quarto's other features
14-
- Use Sverto in a Quarto document by adding `sverto` to `filters` in the document frontmatter
15-
- Add Svelte files to a document using the frontmatter key `sverto.use`
16-
- No need for magic blocks anymore!
17-
- When working in a website project, optionally use the `sverto` project type to cut down on duplicate Svelte compilation Quarto documents
9+
- Big refactor of Sverto makes it easier to use and more compatible with Quarto's other features!
10+
- Use Sverto in a Quarto document by adding `sverto` to `filters` in the document frontmatter
11+
- Add Svelte files to a document using the frontmatter key `sverto.use`
12+
- No need for magic blocks anymore!
13+
- When working in a website project, optionally use the `sverto` project type to cut down on duplicate Svelte compilation Quarto documents
1814
- Works properly with Quarto includes
19-
- Requires Quarto pre-release 1.5.25 or higher on Windows, but should work fine on Quarto 1.4 on macOS and Linux.
15+
- **Requires Quarto pre-release 1.5.25 or higher on Windows,** but should work fine on Quarto 1.4 on macOS and Linux.
2016

2117
## Sverto 0.0.3
2218

docs/style.scss

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
/*-- scss:defaults --*/
2+
3+
/*-- scss:rules --*/
4+
5+
.btn {
6+
box-shadow:
7+
0 .2em .8em .2em rgba(0,0,0,.05),
8+
0 .2em .6em .1em rgba(0,0,0,.025);
9+
}

0 commit comments

Comments
 (0)