You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/examples/time-series/index.qmd
+43-17Lines changed: 43 additions & 17 deletions
Original file line number
Diff line number
Diff line change
@@ -16,22 +16,23 @@ sverto:
16
16
17
17
Let's do something more useful: a time series of temperature extremes.
18
18
19
-
In Quarto, we'll download the data for two cities (Melbourne and Brisbane), letting the user choose which to display. We'll also let them choose a month and the extreme to display.
19
+
In Quarto, we'll download the data for two cities (Melbourne and Brisbane), letting the user choose which to display. We'll also create controls using [Observable Inputs](https://observablehq.com/documentation/inputs/overview) to let them choose a month and the extreme to display.
20
20
21
-
:::{.callout-tip appearance="simple"}
21
+
:::{.callout-info appearance="simple" title="What is this data?" collapse="true"}
22
22
In climate parlance, the highest temperature of the day is called the "daily maximum temperature", or `tmax` for short. The coldest temperature of the day is called "daily minimum temperature", or `tmin` for short.
23
23
24
24
I'm just calling them "daytime temperature" and "nighttime temperature" here — although the lowest temperature can technically happen during the day, it's usually at night!
25
25
:::
26
26
27
27
Once the data has been appropriately filtered and calculated, we'll pass it to our Svelte chart.
28
28
29
-
The chart is fairly agnostic in the sense that it could be used with other time series datasets too, rather than being tailored specifically to this one. It expects a prop called `data`, which is an array of objects that each have a numerical `year` and a `value`.
29
+
The chart expects a prop called `data`, which is an array of objects that each have a numerical `year` and a `value`.
We could generalise this chart further if we wanted: we could have it expect columns called `x` and `y`, and perhaps allow full date objects as the x values.
33
-
:::
31
+
:::{.callout-tip appearance="simple" collapse="true" title="Can I use this chart with other data?"}
32
+
You can! This chart can plot any series of data, although it expects a numerical x value called `year` (it doesn't handle full dates) and a numerical y value called `value`.
34
33
34
+
The y-axis has a suffix that is set to `"°C"` by default, but you could change this to `°F`, `kph` or something else if you had some other kind of data!
This chart has a few differences from the [simpler barchart example](../barchart):
187
+
188
+
1. We make the chart responsive to changes in window size by wrapping the `<svg>` in a `<main`> and using `bind:clientHeight` and `bind:clientWidth` to track the space available to the chart
189
+
2. Since this is designed for more data, we use axes instead of labelling each datum. We use [`d3-axis`](https://d3js.org/d3-axis) for this. Instead of directly drawing the SVG elements of the axis, we create a placeholder and then use D3's functions to create the content, making them reactive to changes in data or window size with `$:`
190
+
3. Instead of passing in colour directly, we let the user in Quarto choose a colour scheme (`"warm"` or `"cool"`). In this example, the colour scheme is connected to the Daytime or Nighttime option.
191
+
192
+
And here's the processed data as a table, so we can see what we're sending to Svelte. Note the two columns, `year` and `value`:
193
+
194
+
:::{.callout-note title="Table of values" collapse="true" appearance="simple"}
0 commit comments