LuxelEspañol

Luxel v0.2 · Guide

Charts

A chart in Luxel is three things: a section (a fixed template in the view), a scale and values (both from the server). The template is an SVG or a bar whose size is expressed in the scale's units; the browser's own SVG and CSS engines draw the proportion. Nothing is computed in the browser: not the maximum, not a percentage, not a format.

There are two components: Chart (a fixed set of columns) and Bar (one bar per item of a collection).

Chart: a fixed set of columns

‹Chart scale="cobranza.max" columns="cobranza.months" label="Monthly collections" className="chart" columnClassName="chart__column" />

// contract cobranza: { // 12 values, one per column, and their maximum: both from one query. months: numbers({ min: 0, max: 1_000_000_000_00, length: 12 }), max: number({ min: 1, max: 1_000_000_000_00 }), total: money(), },

// load return ctx.snapshot(version, { 'cobranza.months': data.months, // 12 integers (cents) 'cobranza.max': data.max, // at least 1 'cobranza.total': data.total, });

PropMeaning
columnsA numbers({ min, max, length }) path: exactly length raw numbers, one per column
scaleA number({ min, max }) path: the largest value, computed by the server
labelThe chart's accessible name
className, columnClassNameClasses of the chart and of each column

The compiled template is an SVG whose viewBox height is the scale and whose columns' heights are the values. When the server sends new values or a new scale, only those numbers change.

The server checks every number against the leaf's min and max, and the count against length. Give the scale a minimum of 1 so an all-zero series still has a valid drawing.

Labels under the columns are static text, written at build time:

const MONTHS = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']; ‹Row className="chart__labels"> {MONTHS.map((m, i) => ‹Text id={`m${i + 1}`} as="span">{m}‹/Text>)} ‹/Row>

Columns grow from the top: flip the chart in CSS

The compiled ‹svg> draws each column from the top of its viewBox (y = 0) down to its height. To make columns grow from the bottom, flip the chart in your stylesheet, as the lab does:

.chart { display: block; width: 100%; height: 160px; transform: scaleY(-1); }

No number is computed for this: the browser's SVG engine scales the drawing.

Show the values as text too

A chart is an image for assistive technology (role="img" with your label). Show the same values as text next to it, for example a collection of single-text items the server fills with { id: 'm01', label: 'Jan · S/ 1,250.00' } (one item per column), or a table. The server formats the text; the browser shows it as it comes.

Bar: one bar per item

When the number of bars varies (the top agencies, spending by category), use a Collection and put a Bar in the item template. The item carries its value and the scale:

‹Collection bind="cobranza.agencies" itemKey="id" maxItems={10} as="ul" label="Agencies with the highest collections" className="bars"> {(a) => ( ‹Stack as="li" className="bars__item"> ‹Text as="span" className="bars__label">{a.name}‹/Text> ‹Bar value={a.amount} scale={a.scale} className="bars__track" barClassName="bars__bar" /> ‹Text as="span" className="bars__value">{a.shown}‹/Text> ‹/Stack> )} ‹/Collection>

// contract agencies: collection({ key: 'id', fields: { name: text(), amount: number({ min: 0, max: 1_000_000_000_00 }), scale: number({ min: 1, max: 1_000_000_000_00 }), shown: money(), }, }),

// load: every bar gets the same scale, the top amount 'cobranza.agencies': top.map((a) => ({ id: a.id, name: a.name, amount: a.total, scale: topMax, shown: a.total })),

PropMeaning
valueAn item field of type number(...): the bar's length
scaleAn item field of type number(...): the length of a full bar
verticalA column instead of a horizontal bar (the scale is the drawing's height)
className, barClassNameClasses of the track and of the bar

Bar is allowed only in an item template. A vertical example, spending by category:

‹Collection bind="dashboard.sections" itemKey="id" maxItems={7} as="ul" label="Spending by category" className="ledger-bars"> {(c) => ( ‹Stack as="li" className="ledger-bar"> ‹Text as="span" className="ledger-bar__value">{c.shown}‹/Text> ‹Bar value={c.amount} scale={c.scale} vertical className="ledger-bar__plot" barClassName="ledger-bar__fill" /> ‹Text as="span" className="ledger-bar__label">{c.name}‹/Text> ‹/Stack> )} ‹/Collection>

The server computes the scale and the values

In React you might write height: ${(value / max) * 100}% in the component. In Luxel the server sends value and max and the template expresses the ratio in SVG units. Compute the scale in the same read as the values (the lab does both in one PostgreSQL statement), so they always belong together.

When a refresh changes the largest value, the scale moves for every bar: send every item again (ctx.item for each, or ctx.set for the list). When only one bar's value changed and the scale did not, send that item alone.

Accessibility

  • Give every chart a label (the Chart prop; label on the Collection of bars).
  • Show the values as text too. A drawing is not readable by everyone. Put the formatted amount next to each bar (shown, a money() field), or show the series in a table. The examples above do.
  • Colors and sizes come from your stylesheet; keep enough contrast.

None of this makes a page conformant with any standard by itself; test with people and assistive technology.

Policies

If policies.allowedComponents is set in luxel.config.ts, a view with a Chart needs 'Chart' in the list, or luxel check refuses it (LUXEL-E035); the create-luxel template lists it. A Bar lives in a collection's item template, which luxel check counts as the Collection.

What is not there

Chart and Bar are the only chart components. You do not write SVG in a view, and there are no line, pie or scatter charts yet. A need that does not fit is recorded as a gap; it is never solved by computing in the browser.

Edit this page on GitHub

This page: 7.9 KB of JavaScript (Luxel's shared runtime), 0 KB from your app.

Measured when the site is built: the runtime files this page loads, compressed as they are sent.

Made by IntiOps. The Luxel 0.1.0 betas are on npm (0.1.0-beta.1, 0.1.0-beta.2), with an alpha of 0.2 (0.2.0-alpha.1): no external security review yet.