/* Timeline: lanes of phases over a shared axis, for . Light DOM, wrapped in @scope (pebble-timeline); :scope is the host. The @property registrations of --pebble-timeline-start and --pebble-timeline-size cannot be scoped: they are properties.css, page-wide. Theming, two levels, every value with a fallback: - --pebble-chart-*: what every library chart shares, so one set of page tokens themes them all: series-1 … series-8 (the categorical slots, in fixed order), muted, ink, ink-2, tick, grid, axis, surface, border, hatch, focus. - --pebble-timeline-*: this chart's own: bar (24px), gap (2px between touching segments), radius (4px at a track's ends), row-gap (0.75rem), font-size (0.875rem), label-on-fill (#fff), label-on-light (#0b0b0b). Defaults are the dataviz reference palette, light and dark steps chosen by prefers-color-scheme; a page with its own theme toggle sets the --pebble-chart-* tokens for both. Parts: timeline, legend, plot, track-label, lane, segment, total, axis, axis-title, tooltip, table-view. State is attributes, never generated CSS: [data-series], [data-texture], [data-first], [data-last], [data-active], [data-unlabelled] on segments, [data-open] on the tooltip, [data-enhanced] and [show-table] on the host; the element marks each segment row of the table with [data-fill] (its palette slot) and [data-track-start] (the first row of a run of one track). */ :scope { --_s1: var(--pebble-chart-series-1, #2a78d6); --_s2: var(--pebble-chart-series-2, #eb6834); --_s3: var(--pebble-chart-series-3, #1baf7a); --_s4: var(--pebble-chart-series-4, #eda100); --_s5: var(--pebble-chart-series-5, #e87ba4); --_s6: var(--pebble-chart-series-6, #008300); --_s7: var(--pebble-chart-series-7, #6250d6); --_s8: var(--pebble-chart-series-8, #e34948); --_muted: var(--pebble-chart-muted, #c3c2b7); --_ink: var(--pebble-chart-ink, #0b0b0b); --_ink-2: var(--pebble-chart-ink-2, #52514e); --_tick: var(--pebble-chart-tick, #898781); --_grid: var(--pebble-chart-grid, #e1e0d9); --_axis: var(--pebble-chart-axis, #c3c2b7); --_surface: var(--pebble-chart-surface, #fcfcfb); --_border: var(--pebble-chart-border, rgba(11, 11, 11, 0.1)); --_hatch: var(--pebble-chart-hatch, rgba(255, 255, 255, 0.55)); --_focus: var(--pebble-chart-focus, var(--accent, #2a78d6)); --_bar: var(--pebble-timeline-bar, 24px); --_gap: var(--pebble-timeline-gap, 2px); --_radius: var(--pebble-timeline-radius, 4px); --_row-gap: var(--pebble-timeline-row-gap, 0.75rem); display: block; container-type: inline-size; color: var(--_ink); font-size: var(--pebble-timeline-font-size, 0.875rem); line-height: 1.4; } @media (prefers-color-scheme: dark) { :scope { --_s1: var(--pebble-chart-series-1, #3987e5); --_s2: var(--pebble-chart-series-2, #d95926); --_s3: var(--pebble-chart-series-3, #199e70); --_s4: var(--pebble-chart-series-4, #c98500); --_s5: var(--pebble-chart-series-5, #d55181); --_s6: var(--pebble-chart-series-6, #008300); --_s7: var(--pebble-chart-series-7, #9085e9); --_s8: var(--pebble-chart-series-8, #e66767); --_muted: var(--pebble-chart-muted, #52514e); --_ink: var(--pebble-chart-ink, #f0efec); --_ink-2: var(--pebble-chart-ink-2, #c3c2b7); --_grid: var(--pebble-chart-grid, #2c2c2a); --_axis: var(--pebble-chart-axis, #383835); --_surface: var(--pebble-chart-surface, #1a1a19); --_border: var(--pebble-chart-border, rgba(255, 255, 255, 0.1)); --_hatch: var(--pebble-chart-hatch, rgba(26, 26, 25, 0.5)); } } /* The table stays for screen readers and no-script readers. While it is the host's own child (no [show-table]) it is visually hidden. A table ignores width: 1px and keeps its content's width, so the usual visually-hidden box would still stick out of the page and scroll it sideways: the scale shrinks the box itself, and the table stays in the accessibility tree. */ :scope[data-enhanced] > table { position: absolute; overflow: hidden; clip-path: inset(50%); white-space: nowrap; transform: scale(0.01); transform-origin: 0 0; } /* The table view ([show-table]): the element moves the page's table into .table-view, under the plot, and back where it was when the attribute goes or the element disconnects. The table takes its natural width: an auto layout, every column at least as wide as its longest word, and no word is ever broken (the page's own soft hyphens aside). Whatever the page's table holds (more columns than the sample's five, long notes, a DOI), when it is wider than the element the view scrolls sideways, never the page. The view is a focusable region (arrow keys scroll it), and a shadow at an edge says there is more that way: a scroll-driven animation, so nothing shows where the view does not scroll, or where the browser lacks scroll timelines. */ .table-view { --_edge: color-mix(in srgb, var(--_ink) 28%, transparent); overflow-x: auto; margin-top: 1.5rem; border-radius: 4px; outline: none; animation: pebble-timeline-edges linear both; animation-timeline: scroll(self inline); &:focus-visible { outline: 2px solid var(--_focus); outline-offset: 2px; } } /* Right edge, then left: both always, one transparent, so the lists interpolate. Inset shadows sit on the view's background, under the table's text, and stay put as it scrolls. */ @keyframes pebble-timeline-edges { from { box-shadow: inset -12px 0 10px -10px var(--_edge), inset 12px 0 10px -10px transparent; } 5%, 95% { box-shadow: inset -12px 0 10px -10px var(--_edge), inset 12px 0 10px -10px var(--_edge); } to { box-shadow: inset -12px 0 10px -10px transparent, inset 12px 0 10px -10px var(--_edge); } } .table-view > table { --_cell-x: 0.75rem; width: 100%; border-collapse: collapse; font-size: 0.8125rem; /* Whole words, whatever the page's own CSS sets around it. */ white-space: normal; overflow-wrap: normal; word-break: normal; hyphens: manual; & caption { caption-side: top; padding-bottom: 0.5rem; text-align: start; font-size: 0.75rem; color: var(--_ink-2); } & tr > * { padding: 0.375rem var(--_cell-x); text-align: start; vertical-align: baseline; } & tr > :first-child { padding-inline-start: 0; } & tr > :last-child { padding-inline-end: 0; } & thead th { vertical-align: bottom; border-bottom: 1px solid var(--_tick); font-size: 0.75rem; font-weight: 600; color: var(--_ink-2); } & tbody > tr > * { border-top: 1px solid var(--_grid); font-weight: 400; } /* Start and length: numbers, right-aligned on tabular figures. */ & tr > :nth-child(n + 3):nth-child(-n + 4) { text-align: end; font-variant-numeric: tabular-nums; } /* Tracks: a firmer rule where one starts, in the tick ink like the header's (the axis token is too close to the hairlines, in dark above all), and the track's name repeated in a muted ink. Under the header, the header's rule wins: with collapsed borders the upper cell's does. */ & tbody > tr[data-track-start] > * { border-top-color: var(--_tick); } & tbody > tr[data-track-start] > :first-child { font-weight: 600; } & tbody > tr[data-fill]:not([data-track-start]) > :first-child { color: var(--_ink-2); } /* Each segment row's swatch, in its segment's fill and texture, hung in the cell's margin so a wrapped label keeps to one column. */ & tr[data-fill] > :nth-child(2) { padding-inline-start: calc(var(--_cell-x) + 18px); text-indent: -18px; } & tr[data-fill] > :nth-child(2)::before { content: ""; display: inline-block; width: 10px; height: 10px; margin-inline-end: 8px; border-radius: 2px; vertical-align: -1px; background-color: var(--_fill); } } /* Fills: one slot per series, the muted one, and the 45° hatch over any of them. A table row carries its slot too (data-fill), for its swatch; the hatch is only ever on marks. */ [data-series="1"], [data-fill="1"] { --_fill: var(--_s1); } [data-series="2"], [data-fill="2"] { --_fill: var(--_s2); } [data-series="3"], [data-fill="3"] { --_fill: var(--_s3); } [data-series="4"], [data-fill="4"] { --_fill: var(--_s4); --_on-fill: var(--pebble-timeline-label-on-light, #0b0b0b); } [data-series="5"], [data-fill="5"] { --_fill: var(--_s5); } [data-series="6"], [data-fill="6"] { --_fill: var(--_s6); } [data-series="7"], [data-fill="7"] { --_fill: var(--_s7); } [data-series="8"], [data-fill="8"] { --_fill: var(--_s8); } [data-series="muted"], [data-fill="muted"] { --_fill: var(--_muted); --_on-fill: var(--_ink); } .segment[data-texture="hatch"], .swatch[data-texture="hatch"], tr[data-texture="hatch"] > :nth-child(2)::before { background-image: repeating-linear-gradient(45deg, var(--_hatch) 0 2px, transparent 2px 6px); } .legend { list-style: none; display: flex; flex-wrap: wrap; gap: 0.375rem 1rem; margin: 0 0 1rem; padding: 0; font-size: 0.8125rem; color: var(--_ink-2); & li { display: inline-flex; align-items: center; gap: 0.375rem; } } .swatch { flex: none; width: 12px; height: 12px; border-radius: 3px; background-color: var(--_fill, var(--_muted)); } /* The plot: one grid, a row per track; label, lane and total columns line up across tracks. */ .plot { position: relative; display: grid; grid-template-columns: [label] max-content [lane] minmax(0, 1fr) [total] max-content; column-gap: 0.75rem; row-gap: var(--_row-gap); align-items: center; outline: none; border-radius: 4px; &:focus-visible { outline: 2px solid var(--_focus); outline-offset: 6px; } } .grid { grid-column: lane; grid-row: 1 / span var(--tracks); align-self: stretch; position: relative; margin-block: calc(var(--_row-gap) * -0.5); } .gridline { position: absolute; top: 0; bottom: 0; left: calc(var(--at) * 100%); width: 1px; background: var(--_grid); &[data-baseline] { background: var(--_axis); } } .track-label { grid-column: label; grid-row: var(--row); font-weight: 600; white-space: nowrap; } /* A lane is a size container so that a label can know its segment's target width (cqw): see .segment-label. */ .lane { grid-column: lane; grid-row: var(--row); position: relative; height: var(--_bar); container-type: inline-size; } .total { grid-column: total; grid-row: var(--row); font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap; & .delta { font-weight: 400; color: var(--_ink-2); } } .segment { position: absolute; top: 0; bottom: 0; /* The label's cap (below): --pebble-timeline-start and -size are registered with inherits: false (properties.css), so the segment hands its target width down by a name of its own. */ --_target: calc(var(--pebble-timeline-size) * 100cqw - var(--_gap)); left: calc(var(--pebble-timeline-start) * 100%); width: max(1px, calc(var(--pebble-timeline-size) * 100% - var(--_gap))); display: flex; align-items: center; overflow: hidden; background-color: var(--_fill, var(--_muted)); &[data-first] { border-start-start-radius: var(--_radius); border-end-start-radius: var(--_radius); } &[data-last] { --_target: calc(var(--pebble-timeline-size) * 100cqw); width: max(1px, calc(var(--pebble-timeline-size) * 100%)); border-start-end-radius: var(--_radius); border-end-end-radius: var(--_radius); } &[data-active] { filter: brightness(1.12); } &[data-unlabelled] .segment-label { visibility: hidden; } } /* A label is never wider than its segment's TARGET width, the one the width transition is heading to: max-width uses the same formula as the segment's width (--_target, resolved in the lane's cqw: the lane is the nearest container), and does not transition. So the element's fit (does the label's text overflow the label?) hides a label as soon as a shrink starts, and shows it only once a grow has ended (it is fitted again at transitionend): a shown label is never clipped mid-glide. */ .segment-label { box-sizing: border-box; min-width: 0; max-width: max(1px, var(--_target)); padding: 0 6px; overflow: hidden; white-space: nowrap; font-size: 11px; font-weight: 600; color: var(--_on-fill, var(--pebble-timeline-label-on-fill, #fff)); } .axis { grid-column: lane; position: relative; height: 1rem; margin-top: calc(var(--_row-gap) * -0.5); } .tick { position: absolute; left: calc(var(--at) * 100%); transform: translateX(-50%); font-size: 11px; color: var(--_tick); font-variant-numeric: tabular-nums; white-space: nowrap; } .axis-title { grid-column: lane; margin: calc(var(--_row-gap) * -0.5) 0 0; text-align: center; font-size: 11px; color: var(--_tick); &:empty { display: none; } } /* The tooltip sits in the active track's lane area (an absolute grid item takes its area as containing block), over the active segment, kept inside the lane by moving its own anchor with --x. Nothing is measured. */ .tooltip { position: absolute; grid-column: lane; grid-row: var(--row); bottom: calc(100% + 0.375rem); left: calc(var(--x) * 100%); transform: translateX(calc(var(--x) * -100%)); z-index: 1; display: none; min-width: 10rem; max-width: 16rem; padding: 0.5rem 0.625rem; border: 1px solid var(--_border); border-radius: 0.5rem; background: var(--_surface); color: var(--_ink); box-shadow: 0 4px 16px rgba(0, 0, 0, 0.12); font-size: 0.8125rem; pointer-events: none; &[data-open] { display: block; } & .heading { display: block; font-size: 0.875rem; } & .track { display: block; color: var(--_ink-2); } & ul { list-style: none; margin: 0.25rem 0 0; padding: 0; } & .value { font-weight: 600; font-variant-numeric: tabular-nums; } & .name { color: var(--_ink-2); } } /* Narrow: each track's label and total take a row above its lane, so the lane gets the full width; the gridlines go, the ticks stay. */ @container (max-width: 30rem) { .plot { grid-template-columns: [lane] minmax(0, 1fr) [total] max-content; row-gap: 0.25rem; } .grid { display: none; } .track-label, .total { grid-row: var(--label-row); margin-top: 0.5rem; } .track-label { grid-column: lane; } .lane, .tooltip { grid-column: 1 / -1; grid-row: var(--lane-row); } .axis, .axis-title { grid-column: 1 / -1; margin-top: 0.25rem; } /* The table at a phone's width: smaller type, tighter cells. */ .table-view > table { --_cell-x: 0.375rem; font-size: 0.75rem; } } /* Motion: when the page rewrites a row, its segment glides to its new place and width (the element keeps segment elements across re-reads). left and width transition, not the registered --pebble-timeline-start and -size: the label's cap must jump to the target at once (see .segment-label), and left and width are computed from them, so a change of either changes them. A resize changes no computed value (they are percentages), so it never animates. */ @media (prefers-reduced-motion: no-preference) { .segment { transition: filter 120ms ease, left 350ms ease-out, width 350ms ease-out; } }