CompMD gets charts, calendars, weather forecasts and data tables
A week ago, the first packs gave CompMD cards, galleries, notes and timelines. This time there are more of them, the ones a page of data needs: a chart, a calendar, a table the reader sorts, a weather forecast and a word cloud. Three more are now part of every document, with nothing to import: tabs, sections that fold away and numbered steps.
Tabs, foldable sections and steps, built in
Some components are so common that a document shouldn't have to import them. tabs, foldable and steps come with
every CompMD sandbox, so you just write them.
tabs holds a tab for each panel, which is what an install guide wants: one command for each package manager, and
the reader picks theirs.
::: tabs
::: tab {label=npm}
```sh
npm install @harbour/kit
```
::: /tab
::: tab {label=pnpm}
```sh
pnpm add @harbour/kit
```
::: /tab
::: tab {label=Yarn}
```sh
yarn add @harbour/kit
```
::: /tab
::: tab {label=Bun}
```sh
bun add @harbour/kit
```
::: /tab
::: tab {label=Deno}
```sh
deno add npm:@harbour/kit
```
::: /tab
::: /tabsnpm install @harbour/kitpnpm add @harbour/kityarn add @harbour/kitbun add @harbour/kitdeno add npm:@harbour/kitfoldable keeps the details of a page out of the way until a reader wants them: the summary first, the rest a click
away. The browser's find in page still finds what is folded, and on paper every section prints open. steps draws an
ordered list as steps; without it, it is the same numbered list.
**TL;DR:** we are ready to move on with the garden fence. The posts are bought, the line along the back of the garden
is agreed with next door, and the forecast is dry for the weekend. Two of us can put up the twelve metres in a day,
with a third pair of hands for the gate. Everything we need is below.
::: foldable {summary="Parts required"}
- 7 fence posts, 75 mm square, 2.4 m long
- 6 fence panels, 1.8 m wide
- 1 gate, with its hinges and latch
- 7 bags of post mix
- 2 boxes of 50 mm screws
::: /foldable
::: foldable {summary="Detailed steps"}
::: steps
1. **Mark the line** with string between two pegs, and a mark every 1.8 m for the posts.
2. **Dig the holes**, 60 cm deep, one at each mark.
3. **Set the posts** in post mix, level and in line, and leave them an hour.
4. **Fix the panels** between the posts, two screws at each end.
5. **Hang the gate**, then fit its latch.
::: /steps
::: /foldableTL;DR: we are ready to move on with the garden fence. The posts are bought, the line along the back of the garden is agreed with next door, and the forecast is dry for the weekend. Two of us can put up the twelve metres in a day, with a third pair of hands for the gate. Everything we need is below.
7 fence posts, 75 mm square, 2.4 m long
6 fence panels, 1.8 m wide
1 gate, with its hinges and latch
7 bags of post mix
2 boxes of 50 mm screws
Mark the line with string between two pegs, and a mark every 1.8 m for the posts.
Dig the holes, 60 cm deep, one at each mark.
Set the posts in post mix, level and in line, and leave them an hour.
Fix the panels between the posts, two screws at each end.
Hang the gate, then fit its latch.
Charts, from your data
chart draws a document's data rows as a bar, line, area, scatter, histogram, heatmap, box, pie or donut chart. The
rows come from a CSV, JSON or YAML file beside the post, so a chart changes when its file does. Here are four, from
three files, in a grid that puts as many side by side as the column holds:
---
md:
import:
- from: "@comp-markdown/chart@0"
names: [chart]
data:
- from: ./more-components/sales.csv
as: sales
schema: {month: string, region: string, amount: number}
- from: ./more-components/crossings.csv
as: crossings
schema: {day: string, time: string, passengers: number}
- from: ./more-components/visitors.csv
as: visitors
schema: {reason: string, visitors: number}
---
::: grid {min=18rem}
:: chart[Tickets sold by month, the harbour ahead of the old town] {type=bar rows=(md.data.sales) x=month y=amount series=region stack=grouped height=18rem}
:: chart[Tickets sold over the half year, stacked by region] {type=area rows=(md.data.sales) x=month y=amount series=region height=18rem}
:: chart[Ferry passengers by day and time: commuters in the week, day trips at the weekend] {type=heatmap rows=(md.data.crossings) x=day y=time value=passengers height=18rem}
:: chart[Why visitors came: the beach first, then the harbour] {type=donut rows=(md.data.visitors) series=reason value=visitors height=18rem}
::: /gridThe text in […] is the chart's title for a screen reader, and what a reader without the component sees.
A calendar of events
calendar shows a month, or several side by side, with its event days marked and the events listed under them, in
the document's language. It takes its box's type, like any component: here a handwritten font the post brings with
it, Caveat, for a noticeboard by the harbour.
---
md:
import:
- from: "@comp-markdown/calendar@0"
names: [calendar]
fonts:
caveat:
fallback: body
files:
- { from: ./more-components/caveat.woff2 }
data:
- from: ./more-components/season.csv
as: season
---
::: calendar {rows=(md.data.season) date=day title=topic end=last months=2 font-family=caveat font-size=0.75em}
- 5 December: Lamps lit on the quay
- 12 to 13 December: Winter market
- 19 December: Carols at the lifeboat station
- 31 December: Fireworks over the harbour
- 1 January: New Year's swim
- 16 January: Seal count on the sandbank
- 24 to 25 January: Boat show in the old sail loft
::: /calendar5 December: Lamps lit on the quay
12 to 13 December: Winter market
19 December: Carols at the lifeboat station
31 December: Fireworks over the harbour
1 January: New Year's swim
16 January: Seal count on the sandbank
24 to 25 January: Boat show in the old sail loft
The list in the body is what a plain Markdown reader shows, and GitHub too.
A table the reader sorts and searches
data-table turns rows into a table the reader sorts by clicking a column's header, and searches. Its body is the
same table as Markdown, for a reader without the component.
---
md:
import:
- from: "@comp-markdown/data-table@0"
names: [data-table]
data:
- from: ./more-components/books.csv
as: books
schema: {title: string, author: string, year: number, pages: number}
---
::: data-table {rows=(md.data.books) columns=["title", "author", "year"]}
| title | author | year |
| --- | --- | --- |
| Klara and the Sun | Kazuo Ishiguro | 2021 |
| Piranesi | Susanna Clarke | 2020 |
::: /data-table| title | author | year |
|---|---|---|
| Klara and the Sun | Kazuo Ishiguro | 2021 |
| Piranesi | Susanna Clarke | 2020 |
A weather forecast
weather shows a weather forecast in one of four views, with animated icons. Its rows can come from a file, as here, or from
a weather service a document imports, Open-Meteo among them, with no key; the component itself reaches nothing.
---
md:
import:
- from: "@comp-markdown/weather@0"
names: [weather]
data:
- from: ./more-components/forecast.csv
as: forecast
---
:: weather[The harbour: cloudy, then rain, clearing by the weekend] {rows=(md.data.forecast) date=day condition=weather high=max low=min}A word cloud
word-cloud sizes words by their weight. Here, the thirty things readers of a harbour town's newsletter asked about
most:
---
md:
import:
- from: "@comp-markdown/word-cloud@0"
names: [word-cloud]
data:
- from: ./more-components/questions.csv
as: questions
---
:: word-cloud[What readers asked about most: tides, then parking and the ferry] {rows=(md.data.questions) text=topic size=count height=14rem}Make your own
The packs above are a start. The patterns your pages need are probably not all there yet, and that is where you come in.
One command gets you a pack with a test page:
npm create @compmd/packWrite your component in CompMD itself, like most of the first packs, or in JSX, Svelte or JavaScript when it needs
code. compmd-pack dev shows its demo as a host would, and compmd-pack build checks it before you publish it to npm.
The Developer's Guide walks through a first pack.
Conclusion
Copy any of the examples above into the playground, change the data and see what happens. If something you need is missing, tell me in the comments below, or in an issue on GitHub. Or better, make it a pack: someone else is probably looking for it too.
Until next time...
Hakan Serce