Trees and timelines drawn from nested details and lists

Five more controls from ui-feed.dev, rebuilt with HTML-in-canvas: three trees and two timelines. A tree here is nested <details> inside one drawable <div>, written by the page author as a nested <ul>. I wanted to know if a branch in the middle of one picture could be drawn opening and closing, when the canvas only has the picture of the whole tree to work with.

Credit: every control on this page is a rebuild of a demo on ui-feed.dev, and each section links to the original it came from. The originals are far higher fidelity than these, so go and look at them. These are examples of what HTML-in-canvas makes possible with a native element underneath, not replacements. I worked from the published demos rather than their source: I looked at what each one does, worked out the mechanism and built it again. The designs and the ideas are theirs.

Plant family

A family, its genera and their species as nested <details>. The whole tree is one element and one picture. While a genus opens or closes, the canvas draws that picture once for each row, moved and clipped so the rows below slide and the rows inside are cut off and fade. The bar of bare paper under the branch you last used, the triangles and the print behind are drawn by the canvas. The branch of leaves and blossom is drawn once on a plain canvas.

  • Rosaceae
    • Prunus
      • Sweet cherry P. avium
      • Plum P. domestica
      • Almond P. amygdalus
      • Apricot P. armeniaca
      • Peach P. persica
    • Malus
      • Apple M. domestica
    • Pyrus
      • Pear P. communis

After the cyanotype plant family (tree) on ui-feed.dev.

Show the code the markup, the tree and the control
  1. The markup. A nested list. data-open starts a branch open.
  2. Reading the list.
  3. The tree. Where each row is laid out, where it should be seen, and one clipped draw for each row while something moves.
  4. The control.
  5. A <details> that closes over time.
  6. The base class. The shadow root, the canvas, the paint loop and the plain HTML fallback.

Editor files

Folders are <details> and files are radios in one group, so one file is chosen and the arrow keys move between files. The row you last used is black. The badge comes from the file's extension, and data-status and data-changed add the marks at the right. The chevrons and the rule beside an open folder are drawn by the canvas, and the rule is as long as the files that show.

  • app
    • globals.css
    • layout.tsx
    • page.tsx
  • components
    • button.tsx
    • dialog.tsx
    • nav.tsx
  • lib
    • dates.ts
    • fetch.ts
  • public
    • favicon.svg
    • robots.txt
  • package.json
  • README.md

After editor files (tree) on ui-feed.dev.

Show the code the markup and the control
  1. The markup.
  2. The control. Labels with radios for files, and the draw.

Store floor guide

Six floors, one open at a time, and some departments open too. The guide keeps its height: the rows of the open floor come out of the height of all six headings, so each heading is drawn shorter than it is laid out while things move. When they stop, the control gives the layout the same height, so the picture and the hit regions agree again. The numeral of each floor is in its summary for a screen reader and is drawn by the canvas so that it can grow.

  • Restaurant until 10 pm
    • The Orangery
      • Afternoon tea
      • Sunday lunch
    • Champagne bar
    • Customer services
      • Returns
      • Gift wrapping
  • Home
    • Kitchen
    • Bedding
    • Lighting
  • Menswear
    • Tailoring
      • Made to measure
      • Alterations
    • Casualwear
    • Shoes
    • Grooming
      • Barber
      • Shaving
  • Womenswear
    • Dresses
    • Knitwear
    • Shoes
    • Lingerie
  • Beauty & fragrance
    • Skincare
    • Fragrance
    • Make-up
  • Food hall from 8 am
    • Bakery
    • Cheese
    • Wine

After the store floor guide (tree) on ui-feed.dev.

Show the code the markup, the row heights and the control
  1. The markup.
  2. The height of a heading. Worked out each frame, then given to the layout at rest.
  3. The control.

Amaryllis in bloom

One range with a step for each stage, and an <ol> of dates. Tap a date, or drag along the line and hold the plant part way between two stages: the stalk, the bud and the four flowers are each drawn from lengths that are read between the stages. The plant follows on a slow spring and the day counts with it. The stages are <option> children. The original uses photographs, and mine is drawn with paths.

After amaryllis in bloom (timeline) on ui-feed.dev.

Show the code the markup, the plant and the range
  1. The markup. The value of an option is the day.
  2. The plant at any point.
  3. The range. A drag is followed between the steps.
  4. The spring and the day.

Kiln firing

A firing programme as an <ol> with a <button> in each step. The display runs in real time from 7 hours 22 minutes in: the temperature is worked out from the rates of the segments, so it rises by 0.075 degrees a second during the second ramp. The step that is running shows its rate and the temperature it's heading for, and pressing another step shows that one's too. The start time of each step is worked out from the rates. The canvas draws four times a second.

After the kiln firing programme (timeline) on ui-feed.dev.

Show the code the markup, the programme and the display
  1. The markup. One option for each segment.
  2. The programme. When each segment starts, and the temperature at any time.
  3. The display.

How it works

Each control is a custom element on the same base class as the accordions and tabs. Its shadow root holds a canvas with content="drawable", and the native elements are children of that canvas.

Only a direct child of the canvas can be drawn, so a tree is one <div> with every branch inside it. The browser lays the tree out and the canvas gets one picture of it. That's enough when nothing moves. To draw a branch part open, the control walks the tree and works out two numbers for each row: where the browser laid it out, and where it should be seen now. Then it draws the whole picture once for each row, shifted by the difference and clipped to the part of the row that shows. A tree of 14 rows is 14 draws a frame for a third of a second. A last draw with no alpha puts the hit region back where the rows are laid out.

Closing uses the same trick as the accordions: the click on the <summary> is cancelled, and the open attribute is removed when the branch has been drawn shut. A branch inside a closing branch keeps its own open attribute.

The range under the amaryllis has five steps, and the pointer is captured on it so that a drag can be followed between them. The kiln's buttons are drawn with no alpha under the rows of the display. Its temperature is in an <output> that changes once a degree.

Live checks

Findings