ShtukbaseStandard
package file→ .shtukbase/packages/lenses/kit/patterns/map.md

kit/patterns/map.md

203 lines, 13.4 KB.

  1. # A map on a canvas: areas, pictures, frames and a tree
  2. A guide for an agent that has to build a map lens: one canvas where you can see why something is needed, what
  3. it consists of and what it is made with. This is how the Shtukbase standard map is built (`shtuks/projects/shtukbase-standard/map.html`).
  4. A working example that can be copied whole is `apps/standard/packages/lenses/kit/examples/base/` (an invented vegetable garden, the lens
  5. `examples/base/map.html`). General information about lenses is in the [README of the set](../README.md); pictures are in
  6. ["Card pictures"](pictures.md).
  7. The "Dependencies" view (tiers, area frames and a tree of strips) is accepted by the owner as the reference; it is
  8. described separately in ["A tiers map"](deps.md).
  9. ## When to use it
  10. - You need one picture of the whole subject, read by eye: left to right "why → what → with what", cards with
  11. pictures, arrows between them.
  12. - There are tens of records, not hundreds: the map shows every record as a card.
  13. - Records divide into groups by collections and fields, and groups into subgroups (a frame with areas inside).
  14. - There is an "is part of" relation that you want to see as a tree.
  15. 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).
  16. ## What the records need
  17. | Field | Type in the collection | What it gives on the map |
  18. |---|---|---|
  19. | `title` | — | the card's title |
  20. | `description` | `text` | one sentence under the title (the "Short" view) |
  21. | `statement` | `text` | the full text (the "Full" view); it is worth repeating it in the record body |
  22. | `art` | `text` | the path to a picture from the base root: `/assets/icons/<name>.svg` |
  23. | `order` | `number` | the card's place in an area and in a tree |
  24. | a mark, for example `mark` | `select` with `options` | a chip on the card ("Not sown yet", "Not yet") |
  25. | "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 |
  26. | links, for example `servedBy`, `bed` | `relation` | arrows between areas and the `where` filter for areas |
  27. | `size` (optional) | `text` | the card's own size: `xs`, `s`, `m`, `l` |
  28. An example record (`examples/base/plants/carrot.md`):
  29. ```yaml
  30. ---
  31. type: Plant
  32. title: "Carrot"
  33. icon: "🥕"
  34. art: /assets/icons/carrot.svg
  35. description: "Sown in April, harvested in September"
  36. order: 1
  37. bed: /beds/roots.md
  38. statement: "Carrots are sown early, in April, and thinned twice. They are harvested in September, before the first frosts."
  39. ---
  40. ```
  41. Links to records in fields are a path from the base root with `.md` (`/beds/roots.md`). The collection declares fields in `properties`
  42. (see `examples/base/plants.md`); without a declared `select` the chip shows the code instead of the label.
  43. ## Steps
  44. 1. **Records.** A collection for each column of meaning (in the example: `needs`, `beds`, `plants`, `plot`), records with the fields from
  45. the table above.
  46. 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`,
  47. then `check` (in detail — ["Card pictures"](pictures.md)).
  48. 3. **The lens.** An HTML file in the base root; the settings are YAML in the first HTML comment. Start with the header below.
  49. 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).
  50. 5. **A look.** Open `<base>/map.html` in a browser (or through any static server in the base root). Go through the three views
  51. with the "Cards" switch in the side panel.
  52. 6. **Checks.** `node apps/standard/packages/lenses/kit/bin/shtukbase-lenses.js check --root <base>` or
  53. `shtuk run --dir <base> lenses check` (the data is fresh). Check the completeness of the lens header against the section below.
  54. ## A minimal header
  55. Two areas, a frame with one area, a tree and an arrow. Copy it and replace the collections and fields with your own.
  56. ```html
  57. <!--
  58. ---
  59. type: Lens
  60. title: Map
  61. icon: "🗺️"
  62. description: "One phrase: what is on the map"
  63. template: canvas
  64. lensType: map
  65. render: live
  66. sources: [needs.md, "needs/*.md", parts.md, "parts/*.md", plot.md, "plot/*.md"]
  67. generator: "node apps/standard/packages/lenses/kit/bin/shtukbase-lenses.js build --root <base>"
  68. look: atlas
  69. surface: paper
  70. areaMax: 1600
  71. fit: width
  72. mode: short
  73. modes:
  74. - {id: names, label: "Names", card: {sub: false, size: xs, chips: []}}
  75. - {id: short, label: "Short", card: {sub: description, size: s}}
  76. - {id: full, label: "Full", card: {sub: statement, size: auto}}
  77. layout:
  78. columns: "248px max-content max-content"
  79. areas:
  80. - "needs main tree"
  81. regions:
  82. - {id: needs, title: "Why", icon: "🎯", color: red, units: 2,
  83. from: /needs, sort: order, card: {sub: description, full: true, art: art, size: s, chips: []}}
  84. - id: main
  85. title: "What"
  86. color: blue
  87. layout: {columns: "248px"}
  88. regions:
  89. - {id: parts, title: "Parts", color: blue, units: 2,
  90. from: /parts, sort: order, card: {sub: description, full: true, art: art, size: s, chips: [mark]}}
  91. - {id: tree, title: "Structure", hint: "left to right: what consists of what", color: green, tree: parent,
  92. from: /plot, sort: order, card: {sub: description, full: true, art: art, size: s, chips: []}}
  93. edges:
  94. - {field: servedBy, from: needs, to: parts, label: serves, color: red}
  95. ---
  96. A paragraph for the reader: how to read the map. It is shown by the "About the lens" section of the side panel.
  97. -->
  98. <!doctype html>
  99. <html lang="en">
  100. <head>
  101. <meta charset="utf-8">
  102. <meta name="viewport" content="width=device-width, initial-scale=1">
  103. <title>Map</title>
  104. <link rel="stylesheet" href="lib/kit.css">
  105. <script src="lib/data.js"></script>
  106. <script src="lib/kit.js"></script>
  107. </head>
  108. <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>
  109. </html>
  110. ```
  111. 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
  112. (`kit/templates/canvas.js`, `kit/kit.css`), not to the lens.
  113. ## Lens options
  114. | Option | What it does | When to use it |
  115. |---|---|---|
  116. | `template: canvas` | the "canvas" template: areas on a CSS grid, cards, arrows | always for a map |
  117. | `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 |
  118. | `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 |
  119. | `fit: width` | a canvas wider than the window is shrunk on opening to the window width (no smaller than 67%) | a wide map |
  120. | `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` |
  121. | `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 |
  122. | `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` |
  123. | `layout.stacks` | columns of areas one under another without an `areas` grid | a simple layout by columns |
  124. | `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 |
  125. | `edges` | arrows along link fields: `{field, from, to, label, color, dash, reverse}`; `from` is an area or a list of areas | links between columns |
  126. **Card views** (`modes`). Each view appends its own `card` to the `card` of every area, at any depth of frames, and can
  127. replace `columns`, `areas` and the width of areas `units: {area id: cells}`. The map's three views:
  128. - `names` — `{sub: false, size: xs, chips: []}`: a strip with a 36-pixel picture and a title;
  129. - `short` — `{sub: description, size: s}`: a picture, a title and one sentence;
  130. - `full` — `{sub: statement, size: auto}`: the full text; the size by text length. A wide area gets more
  131. cells here (`units`) and a wider column (`columns`), as in the example.
  132. ## Area options
  133. | Option | What it does | When to use it |
  134. |---|---|---|
  135. | `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 |
  136. | `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 |
  137. | `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 |
  138. | `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 |
  139. | `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) |
  140. | `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 |
  141. | `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 |
  142. | `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 |
  143. | `sort: title` | in a tree area the records go by title, not by a numeric field | a tree with no order field |
  144. | `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 |
  145. | `plain: true` | a frame with no outline and no title, only a layout | grouping without a visible frame |
  146. | `card` | the area's card options (below) | always |
  147. ## Card options (`card`)
  148. | Option | What it does | When to use it |
  149. |---|---|---|
  150. | `sub` | the text field under the title (`description`, `statement`); `false` — no text | always; a view changes it |
  151. | `full: true` | the text is shown in full, with no truncation by lines | a paragraph card read on the canvas |
  152. | `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 |
  153. | `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 |
  154. | `chips` | chip fields (`[mark]`); `[]` — no chips | marks like "Not implemented" |
  155. | `ratio` | the card's aspect ratio, `"3/2"` | rarely: the standard map and the example do not use it, the `size` sizes replaced it |
  156. | `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 |
  157. ## What it looks like in the example
  158. `examples/base/map.html`: on the left the area "Why" (`units: 2`, a column); on top in the middle "Beds" (`units: 6`,
  159. `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
  160. "Root vegetables" (the filter `where: {bed: /beds/greens.md}`); on the right the tree "Plot" (`tree: parent`). Arrows: from "Why" to
  161. the beds by `servedBy`, from plants to beds by `bed`. `areaMax: 1600` is needed for the tree: it is wider than 720 pixels.
  162. ## Pitfalls
  163. - A record lands in the first matching area in the order of `regions`; a shared folder for two areas is split by the filter
  164. `where`, otherwise the second area stays empty.
  165. - `units` less than the sum of the cards' widths — the cards go to a new row; more — empty space remains.
  166. - Without `areaMax` a wide area is cut at 720 pixels; a tree of three levels of `s` cards is already wider.
  167. - `surface: paper` is designed for `look: atlas`: without it the levels and white areas do not appear, only the arrows' behavior remains.
  168. - In a tree, a root record has no "is part of" field (or it leads outside the area).
  169. - After editing records or the lens — `build` again: the lens reads `lib/data.js`, not markdown.
  170. ## What is not on the map and what is not used
  171. - `layout.groups` (named stacks of areas inside `areas`) exists in the set, but no lens uses it,
  172. and it does not work inside frames (only at the canvas's top level). Until it is needed, use frames and `layout.stacks` instead.
  173. - `card.ratio` — see the card table.