nercone.devaboutlinkscontactsitemap
aboutlinkssitemap82ffc6419

Data Display

Components that show values and their changes, such as on a dashboard.

The CSP of this site forbids style attributes, so every value is written in an attribute, and a script turns it into a custom property: aria-valuenow for progress indicators and gauges, data-value for heatmap cells and stack bar segments, and data-chart-values for charts. Change the attribute, and the component follows.

Stat

stat shows one value with a label above (stat-label) and a description below (stat-description). Combine it with layer or block. A second child of the label is placed at its end, in regular weight. Inside a link, the stat is highlighted under the pointer.

Requests OK12,480

In the last hour

Memory 32.0 GiB14.2 GiB

44% in use

Link→

The whole stat is a link

<div class="layer stat">
    <span class="stat-label">Requests <span class="badge badge-success">OK</span></span>
    <span class="stat-value">12,480</span>
    <p class="stat-description">In the last hour</p>
</div>

Change the size of the value with --stat-value-size (default 1.75rem) and the space between the parts with --stat-gap (default 8px).

Gauge

gauge places a value inside a circular progress indicator. A <small> in gauge-value is a caption under the value.

38%CPU
93%Disk
<div class="gauge">
    <svg class="progress-circular" viewBox="0 0 48 48" role="progressbar" aria-label="CPU" aria-valuenow="38">
        <circle class="progress-track"     cx="24" cy="24" r="20" pathLength="1"/>
        <circle class="progress-indicator" cx="24" cy="24" r="20" pathLength="1"/>
    </svg>
    <span class="gauge-value">38%<small>CPU</small></span>
</div>

Change the size with --gauge-size (default 144px), the line with --gauge-thickness (default 3px), and the value with --gauge-font-size (default 1.5rem). The second gauge is colored by its level.

Chart

chart draws lines with the area below them. Write the values in data-chart-values: numbers separated by spaces, series separated by ;, and - for a missing value, which leaves a gap. The last values are at the right edge.

<div class="chart" role="img" aria-label="CPU usage, from 12% to 43%"
     data-chart-values="12 18 15 22 30 26 41 …" data-chart-max="100"></div>
AttributeValue
data-chart-valuesThe values. Without it, chart.js leaves the chart to Chart.draw()
data-chart-maxThe top of the scale. By default, it follows the highest value, with 15% room above it
data-chart-lengthThe number of values across the chart. By default, the length of the longest series. Set it to keep the scale of time while the values are still few

Series, legend, and scale

The nth series is drawn in --color-chart-n (up to 4). chart-legend is a list of the series; give each item the class chart-series-n. A chart-scale inside the chart is a label at its top, such as the maximum; it is hidden while empty.

<div class="chart" data-chart-values="3 4 3 6 …; 1 2 1 2 …"><span class="chart-scale">Max 15 Mbps</span></div>
<ul class="chart-legend">
    <li class="chart-series-1">Received <b>10 Mbps</b></li>
    <li class="chart-series-2">Sent <b>3 Mbps</b></li>
</ul>

Drawing from a script

For values that change often, such as a history of measurements, call window.nercone.Chart.draw(element, series, options) instead of writing the attribute: it does not turn the numbers into text and back. series is an array of arrays of numbers, where null leaves a gap, and options takes max and length, like the attributes. It returns the top of the scale, or 0 when the scale follows the values and none is above 0, so that a chart-scale can show it.

const top = window.nercone.Chart.draw(element, [received, sent], { length: 150 });
scale.textContent = top > 0 ? `Max ${format(top)}` : '';

Change the height with --chart-height (default 120px), the line with --chart-line-width (default 1.5px), the area with --chart-area-opacity (default 15%), and the colors with --color-chart-1 to --color-chart-4 and --color-chart-grid. A chart is a picture: give it role="img" and a label, or show the values in text next to it.

Heatmap

heatmap is a grid of cells (heatmap-cell) filled by their value in data-value, from data-min (default 0) to data-max (default 1). A cell without a value is not filled. The first of two children is a small label. Cells are colored by their level too.

<ul class="heatmap">
    <li class="heatmap-cell" data-value="0.12"><span>#0</span><span>12%</span></li>
    <li class="heatmap-cell" data-value="0.35"><span>#1</span><span>35%</span></li>
</ul>

Change the width of the cells with --heatmap-cell-min-width (default 72px) and the space between them with --heatmap-gap (default 4px). The color is --color-progress. Write the value in the cell as text as well; the color alone does not tell it.

Stack bar

stack-bar shows parts of one whole side by side. Each stack-bar-segment is as wide as its value in data-value, from data-min (default 0) to data-max (default 1), and the rest is the track. Color the segments with chart-series-n, and use the same classes in a chart-legend.

<div class="stack-bar" role="img" aria-label="Memory: 45% used, 20% cache">
    <span class="stack-bar-segment chart-series-1" data-value="0.45"></span>
    <span class="stack-bar-segment chart-series-3" data-value="0.2"></span>
</div>

Change the height with --stack-bar-thickness (default 16px). The values should add up to at most the maximum; the bar does not grow past it.

Badge

badge is a short label, such as a state. badge-information, badge-success, badge-warning, and badge-error color it; any other color can be set with --badge-color.

DefaultInformationSuccessWarningError
<span class="badge badge-success">Success</span>

Description list

description-list places the terms (<dt>) and their values (<dd>) of a <dl> in two columns. On small screens, each value goes under its term.

Host name
example
Kernel
linux 6.8.0
Processes
312
<dl class="description-list">
    <dt>Host name</dt><dd>example</dd>
    <dt>Kernel</dt><dd>linux 6.8.0</dd>
</dl>

Change the space with --description-list-gap (default 6px 24px).

Binding

binding.js fills elements with values from data, such as a response of an API, by their attributes. Each path is a dot-separated path into the data, such as system.cpu.0.name; an empty path is the data itself. Inside a list item, paths are relative to the item.

AttributeDoes
data-bind="path"Sets the text to the value, formatted by the formatter in data-format (default text). A missing value is written as —
data-bind-attr="name: path; …"Sets each attribute to the value as text, and removes it while the value is missing. While any of them is missing, the element has data-bind-missing
data-bind-show="path"Shows the element only while the value is present
data-bind-hide="path"Hides the element while the value is present
data-bind-list="path"Repeats the first element of its <template> for each item of an array. The copies get data-bind-item, and are kept and filled again on the next render

A value is missing when it is null, undefined, or a number that is not finite. It is present when it is not missing, not false, and not an empty array.

<div class="layer stat">
    <span class="stat-label">CPU <span data-bind="cpu.name"></span></span>
    <span class="stat-value" data-bind="cpu.usage" data-format="percent">—</span>
    <div class="progress-linear" role="progressbar" aria-label="CPU" aria-valuemax="1"
         data-bind-attr="aria-valuenow: cpu.usage"></div>
</div>
<ul class="heatmap" data-bind-list="cpu.cores">
    <template>
        <li class="heatmap-cell" data-bind-attr="data-value: usage">
            <span data-bind="name"></span><span data-bind="usage" data-format="percent"></span>
        </li>
    </template>
</ul>
<p data-bind-hide="cpu.cores">No cores.</p>
const binding = new window.nercone.Binding();
binding.render(document.querySelector('main'), await response.json());

render(root, data) fills root and its descendants, and changes an element only where its value changed, so it can be called again with each new response. Binding is a class, not a feature: it does nothing until a script calls it.

Formatters

NameValueExample
textAnything. Arrays are joined with , a, b
numberA number, rounded and grouped by the locale12,480
percentA ratio, from 0 to 138.5%
bytesA number of bytes, in binary units1.5 GiB
jsonAnything, as indented JSON{ … }
time, dateMilliseconds since the epoch, or a date string12:34:56

Options: missing ('—') is the text of a missing value, locale (that of the browser) is for numbers and dates, and formatters adds formatters or replaces the ones above. Binding.scaled(value, base, units, digits) helps to write one with units.

const binding = new window.nercone.Binding({
    locale: 'ja-JP',
    formatters: {
        bitrate: (bits) => window.nercone.Binding.scaled(bits, 1000, ['bps', 'kbps', 'Mbps', 'Gbps'])
    }
});

A progress indicator without aria-valuenow is indeterminate and animates. When a value can be missing, style [data-bind-missing], for example to draw only the track. Elements hidden by data-bind-show and data-bind-hide stay hidden, even when a class such as layer sets their display.