package file→ .shtukbase/packages/lenses/kit/patterns/map.md
kit/patterns/map.md
203 lines, 13.4 KB.
- # A map on a canvas: areas, pictures, frames and a tree
- A guide for an agent that has to build a map lens: one canvas where you can see why something is needed, what
- it consists of and what it is made with. This is how the Shtukbase standard map is built (`shtuks/projects/shtukbase-standard/map.html`).
- A working example that can be copied whole is `apps/standard/packages/lenses/kit/examples/base/` (an invented vegetable garden, the lens
- `examples/base/map.html`). General information about lenses is in the [README of the set](../README.md); pictures are in
- ["Card pictures"](pictures.md).
- The "Dependencies" view (tiers, area frames and a tree of strips) is accepted by the owner as the reference; it is
- described separately in ["A tiers map"](deps.md).
- ## When to use it
- - You need one picture of the whole subject, read by eye: left to right "why → what → with what", cards with
- pictures, arrows between them.
- - There are tens of records, not hundreds: the map shows every record as a card.
- - Records divide into groups by collections and fields, and groups into subgroups (a frame with areas inside).
- - There is an "is part of" relation that you want to see as a tree.
- If you need a table, a board by status or a graph with no layout — those are other templates (`board`, `lanes`, `nest`; see the README).
- ## What the records need
- | Field | Type in the collection | What it gives on the map |
- |---|---|---|
- | `title` | — | the card's title |
- | `description` | `text` | one sentence under the title (the "Short" view) |
- | `statement` | `text` | the full text (the "Full" view); it is worth repeating it in the record body |
- | `art` | `text` | the path to a picture from the base root: `/assets/icons/<name>.svg` |
- | `order` | `number` | the card's place in an area and in a tree |
- | a mark, for example `mark` | `select` with `options` | a chip on the card ("Not sown yet", "Not yet") |
- | "is part of", for example `parent` | `relation` to the same collection | a tree: to the right of a record stand those that are part of it |
- | links, for example `servedBy`, `bed` | `relation` | arrows between areas and the `where` filter for areas |
- | `size` (optional) | `text` | the card's own size: `xs`, `s`, `m`, `l` |
- An example record (`examples/base/plants/carrot.md`):
- ```yaml
- ---
- type: Plant
- title: "Carrot"
- icon: "🥕"
- art: /assets/icons/carrot.svg
- description: "Sown in April, harvested in September"
- order: 1
- bed: /beds/roots.md
- statement: "Carrots are sown early, in April, and thinned twice. They are harvested in September, before the first frosts."
- ---
- ```
- Links to records in fields are a path from the base root with `.md` (`/beds/roots.md`). The collection declares fields in `properties`
- (see `examples/base/plants.md`); without a declared `select` the chip shows the code instead of the label.
- ## Steps
- 1. **Records.** A collection for each column of meaning (in the example: `needs`, `beds`, `plants`, `plot`), records with the fields from
- the table above.
- 2. **Pictures.** One per record, in the set's style: `node apps/standard/packages/lenses/kit/bin/shtukbase-icons.js new <base>/assets/icons/<name>.svg`,
- then `check` (in detail — ["Card pictures"](pictures.md)).
- 3. **The lens.** An HTML file in the base root; the settings are YAML in the first HTML comment. Start with the header below.
- 4. **Build.** `node apps/standard/packages/lenses/kit/bin/shtukbase-lenses.js build --root <base>` — writes `<base>/lib/` (the data and a copy of the set).
- 5. **A look.** Open `<base>/map.html` in a browser (or through any static server in the base root). Go through the three views
- with the "Cards" switch in the side panel.
- 6. **Checks.** `node apps/standard/packages/lenses/kit/bin/shtukbase-lenses.js check --root <base>` or
- `shtuk run --dir <base> lenses check` (the data is fresh). Check the completeness of the lens header against the section below.
- ## A minimal header
- Two areas, a frame with one area, a tree and an arrow. Copy it and replace the collections and fields with your own.
- ```html
- <!--
- ---
- type: Lens
- title: Map
- icon: "🗺️"
- description: "One phrase: what is on the map"
- template: canvas
- lensType: map
- render: live
- sources: [needs.md, "needs/*.md", parts.md, "parts/*.md", plot.md, "plot/*.md"]
- generator: "node apps/standard/packages/lenses/kit/bin/shtukbase-lenses.js build --root <base>"
- look: atlas
- surface: paper
- areaMax: 1600
- fit: width
- mode: short
- modes:
- - {id: names, label: "Names", card: {sub: false, size: xs, chips: []}}
- - {id: short, label: "Short", card: {sub: description, size: s}}
- - {id: full, label: "Full", card: {sub: statement, size: auto}}
- layout:
- columns: "248px max-content max-content"
- areas:
- - "needs main tree"
- regions:
- - {id: needs, title: "Why", icon: "🎯", color: red, units: 2,
- from: /needs, sort: order, card: {sub: description, full: true, art: art, size: s, chips: []}}
- - id: main
- title: "What"
- color: blue
- layout: {columns: "248px"}
- regions:
- - {id: parts, title: "Parts", color: blue, units: 2,
- from: /parts, sort: order, card: {sub: description, full: true, art: art, size: s, chips: [mark]}}
- - {id: tree, title: "Structure", hint: "left to right: what consists of what", color: green, tree: parent,
- from: /plot, sort: order, card: {sub: description, full: true, art: art, size: s, chips: []}}
- edges:
- - {field: servedBy, from: needs, to: parts, label: serves, color: red}
- ---
- A paragraph for the reader: how to read the map. It is shown by the "About the lens" section of the side panel.
- -->
- <!doctype html>
- <html lang="en">
- <head>
- <meta charset="utf-8">
- <meta name="viewport" content="width=device-width, initial-scale=1">
- <title>Map</title>
- <link rel="stylesheet" href="lib/kit.css">
- <script src="lib/data.js"></script>
- <script src="lib/kit.js"></script>
- </head>
- <body><p class="lx-missing">There is no data yet: build it with the command <code>shtukbase-lenses build</code> in the base root.</p></body>
- </html>
- ```
- A lens does not get its own `<style>`: everything a map needs is in the options below. If an option is missing, it is added to the set
- (`kit/templates/canvas.js`, `kit/kit.css`), not to the lens.
- ## Lens options
- | Option | What it does | When to use it |
- |---|---|---|
- | `template: canvas` | the "canvas" template: areas on a CSS grid, cards, arrows | always for a map |
- | `look: atlas` | a colored blueprint: a color strip and a glyph on an area, right-angle arrows | always for a map; `surface: paper` works only with it |
- | `surface: paper` | three visible levels: a frame (a light color fill), an area (white), a card (a light tint of the area and a shadow); hovering does not dim the rest; arrows appear after half a second and smoothly | a map that is read, rather than a diagram of links |
- | `fit: width` | a canvas wider than the window is shrunk on opening to the window width (no smaller than 67%) | a wide map |
- | `areaMax` | the cap on an area's and a card's width, pixels (720 in the set) | an area wider than 720 pixels: a tree, a full-width frame; in the example `1600`, on the standard map `2400` |
- | `modes`, `mode` | card views with the "Cards" switch; `mode` is the default view, the reader's choice is remembered | always when a card has both a phrase and a full text |
- | `layout.columns`, `layout.areas` | the area grid: column widths and a map of area names | always; a name in `areas` is an area's `id` |
- | `layout.stacks` | columns of areas one under another without an `areas` grid | a simple layout by columns |
- | `show: hover` | there are no summary arrows between areas, only the arrows of the card under the cursor are visible | very many links: an ontology of hundreds of concepts |
- | `edges` | arrows along link fields: `{field, from, to, label, color, dash, reverse}`; `from` is an area or a list of areas | links between columns |
- **Card views** (`modes`). Each view appends its own `card` to the `card` of every area, at any depth of frames, and can
- replace `columns`, `areas` and the width of areas `units: {area id: cells}`. The map's three views:
- - `names` — `{sub: false, size: xs, chips: []}`: a strip with a 36-pixel picture and a title;
- - `short` — `{sub: description, size: s}`: a picture, a title and one sentence;
- - `full` — `{sub: statement, size: auto}`: the full text; the size by text length. A wide area gets more
- cells here (`units`) and a wider column (`columns`), as in the example.
- ## Area options
- | Option | What it does | When to use it |
- |---|---|---|
- | `id`, `title`, `hint`, `icon`, `color` | a name for `areas` and arrows; a title; an explanation of up to three lines; a glyph; a color (`red`, `orange`, `yellow`, `green`, `blue`, `purple`, `pink`, `brown`, `gray`, `teal`) | always |
- | `from`, `where`, `not`, `sort` | the records folder, a filter on fields, an exclusion, the order field | always; a record lands in the **first** matching area |
- | `units` | the area's width in cells of the card grid (a cell is 103 pixels; an `s` card is 2 cells) | with `size` on cards: `units: 2` — a column, `units: 6` — three cards in a row |
- | `columns: auto`, `units: auto` | the area's columns are computed by the rule "no long rows": a grid close to a square, a row no longer than four cards (`units: auto` — when cards have a `size`) | an area with more than four cards and no row set by meaning |
- | `hug: true` | an area as wide as its content and in the middle of its grid cell | a row of cards above wider frames (the standard map's formula, the beds in the example) |
- | `tree: <field>` | the area is drawn as a tree left to right by the "is part of" field. At the roots stand the area's records that have no parent at all; a record that has a parent comes together with it, in whatever area it stands. Roots that nothing is part of lie in an ordinary grid under the tree | a "what consists of what" hierarchy: a structure, an ontology |
- | `flow: down`, `spread: N` | a tree top to bottom: the root on top, its children in a row under it; deeper than level `spread` (1 by default) the children stand in a column with an indent. A record's `color` field colors its branch | one tree for the whole map: the main concepts on top, the rest unfolds downward |
- | `fold: N` | in a tree area branches deeper than N levels are collapsed (0 — only the roots are visible); a button with a number opens a branch, the number is how many records are inside | a big tree: hundreds of records |
- | `sort: title` | in a tree area the records go by title, not by a numeric field | a tree with no order field |
- | `regions` + `layout` | a **frame**: an area with its own grid and areas inside; a frame's `layout` understands `columns`, `areas`, `stacks` | the third level of grouping: a frame → areas → cards |
- | `plain: true` | a frame with no outline and no title, only a layout | grouping without a visible frame |
- | `card` | the area's card options (below) | always |
- ## Card options (`card`)
- | Option | What it does | When to use it |
- |---|---|---|
- | `sub` | the text field under the title (`description`, `statement`); `false` — no text | always; a view changes it |
- | `full: true` | the text is shown in full, with no truncation by lines | a paragraph card read on the canvas |
- | `art: art` | the name of the field with the path to a picture; the picture large on the left (48, 84 or 108 pixels by card size), on a load failure it tries up to three more times | a map with pictures |
- | `size` | `xs`, `s`, `m`, `l` or `auto` (by text length: up to 135 characters — `s`, up to 240 — `m`, beyond — `l`); a record's `size` field wins (except in the `xs` view) | always on a map: cards lie on a dense grid of cells, no taller than their text |
- | `chips` | chip fields (`[mark]`); `[]` — no chips | marks like "Not implemented" |
- | `ratio` | the card's aspect ratio, `"3/2"` | rarely: the standard map and the example do not use it, the `size` sizes replaced it |
- | `flag: <field>` | a card whose record has this field filled in is highlighted with an outline and a bold title | to mark key records among hundreds |
- ## What it looks like in the example
- `examples/base/map.html`: on the left the area "Why" (`units: 2`, a column); on top in the middle "Beds" (`units: 6`,
- `hug: true` — three cards in a row, the area as wide as they are); under them a frame "What grows" with the areas "Greens" and
- "Root vegetables" (the filter `where: {bed: /beds/greens.md}`); on the right the tree "Plot" (`tree: parent`). Arrows: from "Why" to
- the beds by `servedBy`, from plants to beds by `bed`. `areaMax: 1600` is needed for the tree: it is wider than 720 pixels.
- ## Pitfalls
- - A record lands in the first matching area in the order of `regions`; a shared folder for two areas is split by the filter
- `where`, otherwise the second area stays empty.
- - `units` less than the sum of the cards' widths — the cards go to a new row; more — empty space remains.
- - Without `areaMax` a wide area is cut at 720 pixels; a tree of three levels of `s` cards is already wider.
- - `surface: paper` is designed for `look: atlas`: without it the levels and white areas do not appear, only the arrows' behavior remains.
- - In a tree, a root record has no "is part of" field (or it leads outside the area).
- - After editing records or the lens — `build` again: the lens reads `lib/data.js`, not markdown.
- ## What is not on the map and what is not used
- - `layout.groups` (named stacks of areas inside `areas`) exists in the set, but no lens uses it,
- and it does not work inside frames (only at the canvas's top level). Until it is needed, use frames and `layout.stacks` instead.
- - `card.ratio` — see the card table.