Charts, paging, and progress
This page describes the components that help users read changing data and understand loading work. Charts and sparklines show trends, pagination controls the size of a result view, progress indicators show known completion, number tickers highlight changing totals, and skeletons preserve the shape of content while it loads.
Data communication
The data presentation set uses different visual signals for different questions. A chart explains a relation across many values, a sparkline gives a small trend at a glance, and a number ticker draws attention to one changing value. Pagination limits the visible result set without hiding the user's place in it.
Chart views
PetalComponents.Chart provides a declarative chart view for data that needs axes, series, tooltips, or grouped interaction. The server supplies an Apache ECharts option map, so a LiveView can change the data without writing chart-specific client code; the chart can also accept partial updates for fast streams. Its theme follows the page's design tokens and supports automatic accessible chart descriptions. The ECharts engine is an app dependency rather than a bundled part of the component.
The chart supports common dashboard forms such as lines, bars, and circular breakdowns. Explicit chart settings take priority over the shared theme. Named number formatters bridge server data with readable axis and tooltip values.
This diagram shows how server data becomes a themed chart and how later data changes reach the existing view.
flowchart LR
A[LiveView data] --> B[Chart option]
B --> C[Chart view]
D[Design tokens] --> C
E[New data] --> B
E2[Stream update] --> C
References: lib/…/chart.ex• L1-139 assets/…/petal_components.js• L450-571 lib/…/chart.ex• L1-127
Sparkline views
PetalComponents.Sparkline provides a small inline trend view for places where a full chart would add too much weight. It renders from a list of numbers as an SVG line, can shade the area below the line, and can use either a smooth curve or straight segments. The line uses the surrounding text color, so the same component fits stat cards, table cells, and other compact data surfaces without a client runtime.
Sparklines are decorative summaries rather than a replacement for a readable data table or a full chart. Pair them with nearby text when the trend itself carries meaning for the user.
References: lib/…/sparkline.ex• L1-61 lib/…/sparkline.ex• L1
Number ticker views
PetalComponents.NumberTicker emphasizes a single changing number, such as a count or a total. It shows the final value on the server, then animates from an initial or previous value when the number enters view or changes in a LiveView. Locale-aware formatting, decimal places, prefixes, and suffixes keep the display aligned with the meaning of the value.
The server-rendered value remains available when JavaScript is not active. Reduced-motion users receive the value without the counting animation.
References: lib/…/number_ticker.ex• L1-64 assets/…/petal_components.js• L447-449 assets/…/petal_components.js• L929-1011
Result navigation
Pagination gives a user a stable way to move through a large result set. It can represent page numbers with a compact window and ellipses, or use a simpler Previous/Next form when a full page count is not useful.
Pagination controls
PetalComponents.Pagination connects the current page to the next result request. Link mode places the page in a URL, which supports normal navigation and sharing. Event mode sends the requested page to a LiveView instead, which lets the view replace its data without changing the URL. The control also supports LiveView link types and a target for component-scoped events.
The numbered form keeps boundary pages and nearby pages visible while collapsing distant ranges. The simple form shows only Previous and Next and disables a control at the start or end. Invalid or missing page values resolve to a safe one-page state rather than producing links outside the available range. Event-mode clicks can also carry extra values for the handler, and those attributes render in a stable order across builds.
This diagram shows the two ways a page choice can move from the control to new data.
flowchart LR
A[User selects page] --> B{Navigation mode}
B -->|Link| C[URL page]
B -->|Event| D[LiveView page event]
C --> E[Load result page]
D --> E
E --> F[Updated result view]
For a table that needs sorting, filtering, and page changes as one data view, see Data tables. For nested records and collection changes, see Hierarchical data and manipulation. The parent overview is Data presentation.
References: lib/…/pagination.ex• L1-262 lib/…/pagination_internal.ex• L1-131 lib/…/pagination.ex• L1-34
Loading communication
Loading components separate known completion from unknown wait time. A progress bar or ring makes a measured amount visible, while a skeleton reserves the shape of the content that will arrive.
Progress indicators
PetalComponents.Progress presents a known amount of work as either a horizontal bar or a circular ring. Both shapes use the same value, maximum, size, and semantic color model, so a page can change shape without changing the meaning of its progress. The bar suits strips, uploads, and quota meters; the ring suits compact rows and summary cards.
Labels can sit above the bar or inside its largest form. A status line gives users a stage such as “Downloading assets...” without forcing assistive technology to announce every percentage change. Both shapes expose progress semantics, while a missing value represents an indeterminate state with no claimed percentage. For work with no known measure, use a loading indicator rather than presenting a false percentage.
References: lib/…/progress.ex• L1-26 lib/…/progress.ex• L41-128 lib/…/progress.ex• L130-269 lib/…/progress.ex• L1-130
Skeleton loading states
PetalComponents.Skeleton gives a loading region a visual shape before its real content is ready. The basic brick can be sized and composed into the expected layout, while text helpers provide stable line shapes and older prebuilt layouts remain available for compatibility.
Use skeleton_group around a group of bricks when the region needs one loading announcement. The group exposes the loading state to assistive technology while individual bricks remain decorative. Pulse, shimmer, and no-motion choices support different loading styles, and motion stops for users who request reduced motion.
References: lib/…/skeleton.ex• L1-23 lib/…/skeleton.ex• L26-64 lib/…/skeleton.ex• L335-415
Change checklist
When these files or sections are changed, remember to consider these:
- Keep chart data updates compatible with both full option replacement and partial stream updates. Changes to chart token names must also preserve the light and dark theme paths.
- Keep pagination event names and page value payloads aligned with the LiveView or data-table handler that consumes them. Link mode must keep the page placeholder valid in normal and encoded URLs.
- Keep progress value, maximum, and accessibility values consistent when changing the visual scale or adding status text. Do not turn an unknown value into a displayed percentage.
- Keep number ticker fallback text aligned with its formatted animated value. Changes to motion behavior must preserve the reduced-motion path.
- Keep skeleton composition and its single loading announcement in step when changing placeholder layouts.
Important failure modes
| Trigger | Consequence | Guard |
|---|---|---|
| The chart engine is not loaded in an app that renders a chart | The chart hook cannot create a chart and the chart area stays empty | Add the app's ECharts dependency before using the chart component |
| A page event handler expects a different event name or page payload | A pagination click does not load the requested page | Keep the pagination event contract and its consumer aligned |
| A progress value is shown without a known maximum or completion measure | Users see a percentage that does not describe real progress | Use the indeterminate state or another loading indicator |
| A skeleton is used without a loading-region announcement | Screen-reader users may not know why the content is absent | Wrap related decorative bricks in skeleton_group |
| A ticker relies only on its animation for the value | Users without JavaScript or with reduced motion may miss the emphasis | Keep the final value in the server-rendered content |
Key files
| File | Why to read it |
|---|---|
lib/petal_components/chart.ex | Defines the server-facing chart contract and the chart's role in LiveView data updates |
| assets/…/petal_components.js | Shows the client boundary for chart updates, theme changes, loading, and number animation |
lib/petal_components/sparkline.ex | Shows the compact server-rendered trend surface |
lib/petal_components/pagination.ex | Defines URL and event navigation modes and the visible page controls |
lib/petal_components/pagination_internal.ex | Defines safe page-window and ellipsis behavior |
lib/petal_components/progress.ex | Defines bar and ring progress semantics and status communication |
lib/petal_components/number_ticker.ex | Defines the server-safe animated number surface |
lib/petal_components/skeleton.ex | Defines composable loading shapes and the loading-region accessibility boundary |
lib/petal_components/showcase/chart.ex | Demonstrates the main chart forms and server-side chart options |
lib/petal_components/showcase/pagination.ex | Demonstrates link, simple, and event paging flows |
lib/petal_components/showcase/progress.ex | Demonstrates progress shapes, labels, status, and compact row use |