Visualize synthetic data and safe exports
Aggregate the same filtered data used by the dashboard
A chart communicates a comparison or trend; a table provides precise values. Start with a defined measure, units, time range and population. In this synthetic dataset the measure is total inspection duration in minutes, grouped by equipment category. Real time-based dashboards should define timestamp semantics, time zone and bucket boundaries. Missing values are not automatically zero. A valid zero is meaningful; malformed or missing measurements should be surfaced rather than silently coerced.
export function summarize(rows){ const groups=new Map(); for(const row of rows){ if(typeof row.group!=='string'||!row.group.trim()||!Number.isSafeInteger(row.minutes)||row.minutes<0) throw new TypeError('Invalid measurement'); const value=(groups.get(row.group)||0)+row.minutes; if(!Number.isSafeInteger(value)) throw new RangeError('Total too large'); groups.set(row.group,value); } return Array.from(groups,([group,minutes])=>({group,minutes}));}Power totals 32 minutes and Hand totals 12 minutes. The model accepts nonnegative safe integers only, rejects malformed groups or measurements and prevents unsafe totals. An empty dataset produces no groups; an all-zero dataset is valid. The fixture is small enough to aggregate in the browser; real server aggregation must be labeled with the scope and snapshot time. Avoid mixing counts, minutes and percentages on a single unlabeled scale.
Give every chart an equivalent text and table view
import React from 'react';import {records} from './rows.mjs';import {summarize} from './aggregate.mjs';export default function DurationChart(){ const groups=summarize(records), max=Math.max(1,...groups.map(g=>g.minutes)); return <figure><figcaption>Total inspection minutes by equipment group (synthetic sample)</figcaption> {groups.length===0?<p>No measurements.</p>:<><p>{groups.map(g=>`${g.group}: ${g.minutes} minutes`).join('; ')}.</p> <svg aria-hidden="true" viewBox={`0 0 300 ${groups.length*40}`} style={{width:'100%',maxWidth:420}}>{groups.map((g,i)=><g key={g.group}><text x="0" y={i*40+12}>{g.group}</text><rect x="80" y={i*40} width={g.minutes/max*210} height="20" fill="currentColor"/></g>)}</svg> <table><caption>Exact values</caption><thead><tr><th scope="col">Group</th><th scope="col">Minutes</th></tr></thead><tbody>{groups.map(g=><tr key={g.group}><th scope="row">{g.group}</th><td>{g.minutes}</td></tr>)}</tbody></table></>} </figure>;}The horizontal bars start from a common zero baseline and are scaled relative to the maximum; using at least one as denominator handles zero safely. The chart is decorative because the adjacent visible text and exact table communicate all its data. It does not depend on color or hover to explain the values. Recharts 3.x offers declarative charts and an accessibility layer; its default accessibility layer is documented for 3.0, but keyboard behavior must be checked with the installed version. Canvas chart libraries have different accessibility trade-offs. Choose a tool by data size, interaction, rendering needs and tested accessibility, not by screenshot appearance. This example uses native SVG to avoid an extra dependency.
Export only approved data and validate spreadsheet-bound text
// Strict synthetic spreadsheet export policy; rejects rather than rewrites risky text.export function csvText(value){ if(typeof value!=='string'||/[\u0000-\u001f\u007f]/u.test(value)||/^[=+\-@=+-@]/u.test(value.trimStart())) throw new TypeError('Text not permitted in spreadsheet export'); return '"'+value.replaceAll('"','""')+'"';}export function exportCsv(rows){ const lines=rows.map(r=>{ if(!Number.isSafeInteger(r.minutes)||r.minutes<0) throw new TypeError('Invalid minutes'); return [csvText(r.id),csvText(r.name),csvText(r.group),String(r.minutes)].join(','); }); return ['id,name,group,minutes',...lines].join('\r\n')+'\r\n';}CSV quoting escapes delimiters and quotes but does not stop spreadsheets interpreting text as formulas. This deliberately strict teaching policy rejects controls and common formula-leading characters (including listed fullwidth forms) after leading whitespace inspection. It rejects rather than silently changes the original data. It is not a universal spreadsheet sanitizer: application parsing, normalization, save/reopen behavior and locale can differ. For arbitrary text prefer a structured format or a tested workbook writer with explicit text cell types. Validate headers and each field, use server authorization for export scope, enforce size bounds, and do not export confidential data just because it is present in UI memory. The sample returns text only; no file or network side effect. For a real download use a reviewed Blob/object URL lifecycle and revoke it when no longer needed. Practice: export the four records, test empty data, embedded quotes and rejected values, and explain the scope of the policy.