Skip to content

Commit 35b46f3

Browse files
authored
Merge pull request #9 from 360-info/fix-publish
Add notes to README and docs
2 parents cbc1677 + 805276a commit 35b46f3

File tree

4 files changed

+88
-51
lines changed

4 files changed

+88
-51
lines changed

.github/workflows/_publish.yml

-33
This file was deleted.

README.md

+19-3
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,14 @@
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+
715
## 📋 Prerequisites
816

917
You'll need to install two things to run Sverto:
@@ -16,7 +24,7 @@ You'll need to install two things to run Sverto:
1624
Install the project extension using:
1725

1826
```
19-
quarto use template 360-info/sverto@firstrelease-docs
27+
quarto use template 360-info/sverto
2028
```
2129

2230
Then run:
@@ -41,23 +49,31 @@ Here's the short way to add Svelte component you've written to a Quarto doc:
4149
:::
4250
```
4351
44-
2. Import your Svelte component with `Component = import_svelte("Component.svelte")`
52+
2. Import your Svelte component in OJS with `Component = import_svelte("Component.svelte")`
4553
3. Add a target block for your visual using `:::` and give it an `#id`
4654
4. Instantiate the Svelte component with `myVisual = Component.default()` using some default props and your target block
4755
5. Update the instantiated component with `myVisual.propName`
4856
6. Render your Quarto website as usual with `quarto render` or `quarto preview`.
4957
5058
**To see this all in practice, check out [`example.qmd`](./example.qmd).**
5159
60+
> **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.
61+
>
62+
> 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.
63+
5264
## 📦 What's in the box?
5365
66+
When you use the Sverto template in a project, it creates some files for you:
67+
5468
* [`example.qmd`](./example.qmd): an example Quarto doc that uses a Svelte component
5569
* [`Circles.svelte`](./Circles.svelte): an example Svelte visualisation
5670
* [`package.json`](./package.json): this is used to keep track of the dependencies of your Svelte components. You should add this to version control.
57-
* Once you've run `npm install`, there'll also be a `package-lock.json` and a `.luarc.json`. You should version control these too (although you oughtn't need to edit them manually).
71+
* Once you've run `npm install`, there'll also be a `package-lock.json` and a `.luarc.json`. You should version control these too (although you oughtn't need to edit them manually). You don't need to touch the `node_modules` folder, either.
5872
5973
See [`example.qmd`](./example.qmd) to learn how to add Svelte components to your documents and the [Svelte tutorial](https://svelte.dev/tutorial/basics) to learn how to create them.
6074
75+
As well as the project format, Sverto ships with document formats (the default is `sverto-html`). If you need to change document options that would normally go under `format: html`, use `format: sverto-html` or `format-sverto-revealjs` instead.
76+
6177
## 🛍 Use other libraries in your Svelte component
6278
6379
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:

docs/examples/barchart/index.qmd

+48-12
Original file line numberDiff line numberDiff line change
@@ -62,27 +62,63 @@ This Svelte component accepts a few props:
6262

6363
We can hook any of those values up to OJS code using `myBarChart.propName`.
6464

65-
For example, let's make the data user-configurable:
65+
Let's give the user the choice between a randomly changing bar chart and user-configurable data and colours:
6666

6767
```{ojs}
6868
//| code-fold: true
69+
viewof changeType = Inputs.radio(["Random", "Custom"], {value: "Random"})
70+
```
71+
72+
Here's how we generate data and colours that change every two seconds
73+
74+
```{ojs}
75+
//| code-fold: true
76+
randomData = {
77+
while(true) {
78+
yield Promises.delay(2000, [
79+
Math.floor(Math.random() * 100).toString(),
80+
Math.floor(Math.random() * 100).toString(),
81+
Math.floor(Math.random() * 100).toString(),
82+
Math.floor(Math.random() * 100).toString(),
83+
Math.floor(Math.random() * 100).toString()
84+
]);
85+
}
86+
}
6987
70-
viewof userData = Inputs.form([
71-
Inputs.text({type: "number", value: 25, width: 20}),
72-
Inputs.text({type: "number", value: 35, width: 20}),
73-
Inputs.text({type: "number", value: 65, width: 20}),
74-
Inputs.text({type: "number", value: 5, width: 20}),
75-
Inputs.text({type: "number", value: 50, width: 20})
76-
]);
77-
myBarChart.data = [...userData];
88+
randomColor = {
89+
while(true) {
90+
yield Promises.delay(2000,
91+
`#${Math.floor(Math.random() * 256).toString(16)}${Math.floor(Math.random() * 256).toString(16)}${Math.floor(Math.random() * 256).toString(16)}`);
92+
}
93+
}
94+
```
95+
96+
And here are inputs that allow the user to change the data and colour:
97+
98+
```{ojs}
99+
//| code-fold: true
100+
viewof userData = Inputs.form(
101+
[
102+
Inputs.text({type: "number", value: 25, width: 20}),
103+
Inputs.text({type: "number", value: 35, width: 20}),
104+
Inputs.text({type: "number", value: 65, width: 20}),
105+
Inputs.text({type: "number", value: 5, width: 20}),
106+
Inputs.text({type: "number", value: 50, width: 20})
107+
], {
108+
disabled: changeType == "Random"
109+
});
110+
111+
viewof userColor = Inputs.color({
112+
value: "#36a7e9",
113+
disabled: changeType == "Random"});
78114
```
79115

80-
Or the colour:
116+
Finally, we update the visual whenever either the choice type changes or the random data does:
81117

82118
```{ojs}
83119
//| code-fold: true
84-
viewof userColor = Inputs.color({value: "#36a7e9"});
85-
myBarChart.barColor = userColor;
120+
myBarChart.data = changeType == "Random" ? randomData : [...userData];
121+
myBarChart.barColor = changeType == "Random" ? randomColor : userColor;
86122
```
87123
::::
88124

docs/index.qmd

+21-3
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@ 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."
44
author: James Goldie, 360info
55
date: last-modified
6+
format:
7+
sverto-html:
8+
toc: true
9+
toc-location: left
610
---
711

812
:::{}
@@ -11,7 +15,13 @@ date: last-modified
1115

1216
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.
1317

14-
<!-- examples here! -->
18+
## 💭 Why Sverto?
19+
20+
[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).
21+
22+
[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.
23+
24+
_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._
1525

1626
## 📋 Prerequisites
1727

@@ -25,7 +35,7 @@ You'll need to install two things to run Sverto:
2535
Install the project extension using:
2636

2737
```sh
28-
quarto use template 360-info/sverto@firstrelease-docs
38+
quarto use template 360-info/sverto
2939
```
3040

3141
Then run:
@@ -52,14 +62,22 @@ Here's the short way to add Svelte component you've written to a Quarto doc:
5262
:::
5363
```
5464
55-
2. Import your Svelte component with `Component = import_svelte("Component.svelte")`
65+
2. Import your Svelte component in OJS with `Component = import_svelte("Component.svelte")`
5666
3. Add a target block for your visual using `:::` and give it an `#id`
5767
4. Instantiate the Svelte component with `myVisual = Component.default()` using some default props and your target block
5868
5. Update the instantiated component with `myVisual.propName`
5969
6. Render your Quarto project as usual with `quarto render` or `quarto preview`.
6070
6171
**To see this all in practice, check out [`example.qmd`](https://github.com/360-info/sverto/blob/firstrelease/example.qmd).**
6272
73+
:::{.callout-note}
74+
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.
75+
76+
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.
77+
:::
78+
79+
As well as the project format, Sverto ships with document formats (the default is `sverto-html`). If you need to change document options that would normally go under `format: html`, use `format: sverto-html` or `format-sverto-revealjs` instead.
80+
6381
## 🛍 Use other libraries in your Svelte component
6482
6583
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:

0 commit comments

Comments
 (0)