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.
After the cyanotype plant family (tree) on ui-feed.dev.
Show the code the markup, the tree and the control
- The markup. A nested list.
data-openstarts a branch open. - Reading the list.
- The tree. Where each row is laid out, where it should be seen, and one clipped draw for each row while something moves.
- The control.
- A
<details>that closes over time. - 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.
After editor files (tree) on ui-feed.dev.
Show the code the markup and the control
- The markup.
- 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.
After the store floor guide (tree) on ui-feed.dev.
Show the code the markup, the row heights and the control
- The markup.
- The height of a heading. Worked out each frame, then given to the layout at rest.
- 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
- The markup. The value of an option is the day.
- The plant at any point.
- The range. A drag is followed between the steps.
- 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
- The markup. One option for each segment.
- The programme. When each segment starts, and the temperature at any time.
- 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
- A branch in the middle of one picture can be drawn part open. The canvas draws the whole tree once for each row, clipped to that row and moved up by what the closing branch has given back. 130 ms after a click a genus was 38% open, and "Malus" below it was laid out 139 units down and drawn at 87.9. At rest the tree went back to one draw.
- The hit regions stay where the rows are laid out. The tree is one element with one hit region, and a clipped draw of it moves the whole region, so the last draw of each frame puts it back at the layout position. While a branch closes, a row below it is drawn above its own box. I haven't measured what a tap answers during that time.
- A radio inside the tree's picture answers its own point. The point on the second file answered the radio for
globals.css, and a click gave
file=app/globals.css. After its folder closed, the same point answered the summary of the next folder and the form kept the value. - A layout change that the next picture needs can't be made in the paint handler. The floor guide shares out its height by setting a row height on the element. Set inside the paint handler, the picture and the offsets were a frame apart, and the rows jumped. It's now set in an animation frame, at rest only.
offsetHeightis a whole number. A heading 34.6 units high reads 35, so a test for "drawn where it is laid out" never passed and the guide painted for ever. The tolerance is now half a unit.- The range can be held between two steps. Held 0.4 of the way from the second stage to the third, the plant was at
1.39 and the figure read day 14, while the form still had
day=10. The input only has five values, so the position between them is the control's own. - The kiln's figures are worked out, and agree with the original's. The six steps start at 06:30, 12:14, 15:34, 17:42, 17:57 and 23:21, and 7:22:09 into the firing the temperature is 1541.6. The display paints 4 times a second.
- The plant and the blueprint are far from the originals. Theirs look like a photograph of an amaryllis and a cyanotype print. Mine are paths and gradients on a plain canvas.
- Not verified: everything on a phone, what a screen reader says about a branch that is open in the element and
drawn shut, the tree's arrow keys (a
<details>has none), and the fonts.