Update charts to include titles and legends
This commit is contained in:
@@ -1217,19 +1217,20 @@ func chartsSection() func() *VNode {
|
||||
prose("webui.Chart draws its own SVG — nice-scale axes, rounded columns, arc slices, a "+
|
||||
"pointer crosshair — with no charting library. The geometry is pure Go, so the same shapes "+
|
||||
"the Solid kit draws on /js run here in the WebAssembly, against the same theme tokens. Change "+
|
||||
"the data and only the marks that moved re-render."),
|
||||
"the data and only the marks that moved re-render. A Title captions the plot, and the legend a "+
|
||||
"multi-series or pie/donut chart draws is interactive — clicking a key toggles that series or slice."),
|
||||
|
||||
demo("Bar, donut, smooth area, two lines — one data set, and a 3D toggle",
|
||||
row("grid gap-6 lg:grid-cols-12",
|
||||
Div(Attr("class", "lg:col-span-7"), barC.Render(ui.ChartProps{Kind: ui.ChartBar, Labels: chartDaysWasm, Series: []ui.ChartSeries{requests, errs}, Height: 260, ThreeD: threeD.Get()})),
|
||||
Div(Attr("class", "lg:col-span-5"), donutC.Render(ui.ChartProps{Kind: ui.ChartDonut, Labels: pieLabelsWasm, Series: []ui.ChartSeries{pie}, Height: 260, ThreeD: threeD.Get()})),
|
||||
Div(Attr("class", "lg:col-span-7"), areaC.Render(ui.ChartProps{Kind: ui.ChartArea, Smooth: true, Labels: chartDaysWasm, Series: []ui.ChartSeries{requests}, Height: 220})),
|
||||
Div(Attr("class", "lg:col-span-5"), lineC.Render(ui.ChartProps{Kind: ui.ChartLine, Labels: chartDaysWasm, Series: []ui.ChartSeries{requests, errs}, Height: 220})),
|
||||
Div(Attr("class", "lg:col-span-7"), barC.Render(ui.ChartProps{Kind: ui.ChartBar, Title: "Requests & errors this week", Labels: chartDaysWasm, Series: []ui.ChartSeries{requests, errs}, Height: 260, ThreeD: threeD.Get()})),
|
||||
Div(Attr("class", "lg:col-span-5"), donutC.Render(ui.ChartProps{Kind: ui.ChartDonut, Title: "Traffic by source", Labels: pieLabelsWasm, Series: []ui.ChartSeries{pie}, Height: 260, ThreeD: threeD.Get()})),
|
||||
Div(Attr("class", "lg:col-span-7"), areaC.Render(ui.ChartProps{Kind: ui.ChartArea, Title: "Requests, smoothed", Smooth: true, Labels: chartDaysWasm, Series: []ui.ChartSeries{requests}, Height: 220})),
|
||||
Div(Attr("class", "lg:col-span-5"), lineC.Render(ui.ChartProps{Kind: ui.ChartLine, Title: "Requests & errors", Labels: chartDaysWasm, Series: []ui.ChartSeries{requests, errs}, Height: 220})),
|
||||
),
|
||||
row("mt-4 flex items-center gap-3",
|
||||
ui.Button(ui.ButtonProps{Color: ui.ButtonPrimary, Small: true, Text: "New data", OnClick: func() { seed.Set(seed.Get() + 1) }}),
|
||||
ui.Button(ui.ButtonProps{Color: ui.ButtonNeutral, Small: true, Text: threeDLabel, OnClick: func() { threeD.Set(!threeD.Get()) }}),
|
||||
Span(Attr("class", "text-xs text-ink-muted"), Text("Hover any chart. 3D extrudes the bars and tilts the donut.")),
|
||||
Span(Attr("class", "text-xs text-ink-muted"), Text("Each chart takes a Title; a multi-series chart also draws a legend. Click a legend key (Errors, or a donut slice) to hide it — the scale and marks recompute. 3D extrudes the bars and tilts the donut.")),
|
||||
),
|
||||
),
|
||||
|
||||
|
||||
@@ -1419,16 +1419,16 @@ function Charts() {
|
||||
<Panel title="Grouped bars, a smooth area, a two-line series, and a donut — from one data set">
|
||||
<div class="grid gap-6 lg:grid-cols-12">
|
||||
<div class="lg:col-span-7">
|
||||
<Chart kind="bar" labels={CHART_DAYS} series={[requests(), errors()]} height={260} threeD={threeD()} />
|
||||
<Chart kind="bar" title="Requests & errors this week" labels={CHART_DAYS} series={[requests(), errors()]} height={260} threeD={threeD()} />
|
||||
</div>
|
||||
<div class="lg:col-span-5">
|
||||
<Chart kind="donut" labels={pieLabels} series={[pieData()]} height={260} threeD={threeD()} />
|
||||
<Chart kind="donut" title="Traffic by source" labels={pieLabels} series={[pieData()]} height={260} threeD={threeD()} />
|
||||
</div>
|
||||
<div class="lg:col-span-7">
|
||||
<Chart kind="area" curve="smooth" labels={CHART_DAYS} series={[requests()]} height={220} />
|
||||
<Chart kind="area" curve="smooth" title="Requests, smoothed" labels={CHART_DAYS} series={[requests()]} height={220} />
|
||||
</div>
|
||||
<div class="lg:col-span-5">
|
||||
<Chart kind="line" labels={CHART_DAYS} series={[requests(), errors()]} height={220} />
|
||||
<Chart kind="line" title="Requests & errors" labels={CHART_DAYS} series={[requests(), errors()]} height={220} />
|
||||
</div>
|
||||
</div>
|
||||
<div class="mt-4 flex items-center gap-3">
|
||||
@@ -1439,8 +1439,10 @@ function Charts() {
|
||||
{threeD() ? "Flat" : "3D"}
|
||||
</ButtonUI>
|
||||
<span class="text-xs text-ink-muted">
|
||||
The one <code class="font-mono">threeD</code> prop extrudes the bars and tilts the donut
|
||||
(line and area stay flat — depth just reads as noise on a curve).
|
||||
Each chart carries a <code class="font-mono">title</code>; a multi-series chart also draws a
|
||||
legend. Click a legend key — say <em>Errors</em> or a donut slice — to hide it, and the scale
|
||||
and marks recompute from what's left. The <code class="font-mono">threeD</code> prop extrudes
|
||||
the bars and tilts the donut (line and area stay flat — depth reads as noise on a curve).
|
||||
</span>
|
||||
</div>
|
||||
</Panel>
|
||||
@@ -1450,8 +1452,10 @@ function Charts() {
|
||||
<code class="font-mono">"line" | "area" | "bar" | "pie" | "donut"</code> — and{" "}
|
||||
<code class="font-mono">stacked</code>, <code class="font-mono">horizontal</code>,{" "}
|
||||
<code class="font-mono">curve</code>, <code class="font-mono">threeD</code>,{" "}
|
||||
<code class="font-mono">palette</code> and <code class="font-mono">valueFormat</code> refine it.
|
||||
The width is measured from the container, so a chart fills whatever column you give it.
|
||||
<code class="font-mono">title</code>, <code class="font-mono">palette</code> and{" "}
|
||||
<code class="font-mono">valueFormat</code> refine it. The legend it draws for a multi-series or
|
||||
pie/donut chart is interactive — clicking a key toggles that series or slice. The width is measured
|
||||
from the container, so a chart fills whatever column you give it.
|
||||
</Prose>
|
||||
|
||||
<Panel title="Horizontal bars, and stacked — the same kind, transposed and layered">
|
||||
|
||||
Reference in New Issue
Block a user