Components/MonoChart

MonoChart

Thirty rounded monochrome chart variants plus a data-driven GitHub activity calendar.

Since 0.7.0BETA

Overview

TxMonoChart renders native SVG using the existing chart scales, d3 curves, Sankey layout and --tx-chart-* theme. It has no React, Recharts or ECharts runtime. All values come from data; omitting it shows an empty state, not invented business values. Activity palettes retain emerald, blue and violet emphasis; other charts follow the host's monochrome ink.

Hover a mark to read its actual values. Press and drag to sweep across marks: the reading snaps to the mark under the pointer, or the nearest one, with no easing, and holds the edge datum past the plot; ending a drag does not emit select. On touch a sideways drag reads and a vertical swipe still scrolls the page. Focus the SVG and use arrow keys, Home or End to inspect marks, Enter or Space to emit select, and Escape to clear the readout or cancel a drag. Donut/radial legends are also keyboard-operable. Repository disclosure uses a native button, aria-expanded and an inert collapsed list. Center values reflect the hovered segment, otherwise the caller's metric or the data total.

Usage

Catalog and data contracts

The demo renders every original catalog ID and switches the supplied dataset; filtering changes which examples are shown, never aliasing different chart types.

Full mono chart catalog

30 original variants, repository disclosure, live-source loading, palette controls and date filtering.

Loading demo...
Original variant IDInput fieldsIndependent rendering / interaction
mono-activity-greencontributionsEmerald 7-day columns, month labels, intensity scale and day readout.
mono-activity-bluecontributionsBlue activity palette with the same real calendar contract.
mono-activity-purplecontributionsViolet activity palette with the same real calendar contract.
mono-rounded-lineseries, categories?Monotone spline, rounded caps, dots, dashed secondary series; Single/Dual switch.
mono-rounded-barseries, categories?Grouped pill columns or horizontal rows; Col/Row switch.
mono-rounded-areaseries, categories?Gradient area, rounded boundary; Monotone/Natural curve switch.
mono-rounded-donutitemsValue-proportional ring segments, cap gaps, legend and hover center metric.
mono-rounded-composedseries, categories?First series as pill bars, subsequent series as spline overlays; Spline on/off.
mono-rounded-scatterpointsNumeric X/Y coordinates, Z-weighted solid dots and dashed hover crosshair.
mono-rounded-candlestickcandlesActual OHLC domain, rounded high/low wicks, solid rising and hollow falling bodies.
mono-rounded-kpiseries, metric?, metricLabel?, change?Caller-owned metric/change with an embedded gradient sparkline.
mono-rounded-pyramiditemsCentered rounded tiers, value-proportional widths and opacity tones.
mono-rounded-radial-groupitemsMultiple concentric 180-degree progress arcs with rounded caps.
mono-rounded-gauge-arcitems[0]240-degree dial, remaining track and center value.
mono-rounded-bulletitemsActual-value pill, maximum track and independent target marker.
mono-rounded-sankeynodes, linksd3-computed routing, flow-weighted rounded channels and node readouts.
mono-rounded-stepseries, categories?Step-after staircase, round joins and level dots.
mono-rounded-stacked-barseries, categories?Positive/negative stacks with toned layers and rounded outside ends.
mono-rounded-radaritemsNumeric polygon web, per-axis values, rounded joins and node readouts.
mono-rounded-radial-gaugeitemsFull concentric utilization rings starting from the left.
mono-rounded-funnelitemsInput-order horizontal stage pills with proportional lengths.
mono-rounded-heatmapmatrix, categories?Rounded matrix cells with actual density shading and cell readouts.
mono-rounded-sparklineseriesIndependent telemetry rows, mini splines and per-series metric text.
mono-rounded-bubblepointsNumeric distribution, Z-proportional circle area and hollow/translucent bubbles.
mono-rounded-treemaptree or itemsWeighted binary allocation tiles, nested children, rounded gaps and tile readouts.
mono-rounded-streamseries, categories?Independent overlapping natural-curve gradient waves; not a bar/line alias.
mono-rounded-meteritems[0]180-degree meter with separate track and center value.
mono-rounded-waterfallwaterfallSequential positive/negative deltas, optional explicit bases/totals and connecting levels.
mono-rounded-polaritems360-degree rounded radial bands starting from the top.
mono-rounded-rangerangesActual min/max floating band with curved upper and lower boundaries.

Source capabilities

github-activity is the extra GitHubActivity calendar; its capabilities and data sources are listed below.

TopicNotes
CalendarFits the most recent columns to the width, with adjustable cell size and month window, month headers, one-color or four/five-color intensity scales, year metadata, stacked repository avatars and repository expansion. Pass data.contributions and data.repos to use your own source; explicit empty arrays stay empty.
Public dataWith username, missing activity and repository fields load through the shared network client from the upstream public calendar endpoint and the GitHub public events API, with no credentials embedded; activityLoader(username, signal) swaps in a proxy or authenticated source.
Failure and cancellationA failure emits error and shows the configurable retry state, with no generated-data fallback; source changes, offscreen suspension, deactivation and unmount abort requests, and a stale response cannot replace a newer source.
Periodsperiods can select periodData datasets (shallowly merged with data) or inclusive numeric/ISO-date ranges, filtering series points, categories, candles, range bands and contribution dates. A period without matching data or a range only emits the selection and cannot invent a time window.

Best Practices

  • Use the matching data field from the catalog table; series is not a fallback for candles, flow nodes, matrix cells or tree allocations.
  • Match each categorical point's x to categories, or omit categories to derive their order. Provide input-order stages and tiers deliberately. points.z controls circle area, not radius.
  • Set each radial item's max for non-percent units; the default is 100. Donut values are normalized against their actual positive sum, not a hardcoded 100.
  • Supply repository URLs and labels from your source. Use a custom loader rather than exposing private credentials to the browser. Network access occurs only after the calendar becomes visible on the client.
  • Give SSR an explicit width and a consistent locale. SVG gradients and repository panel IDs use Vue useId, so multiple instances do not collide during hydration.
  • Localize title, ariaLabel, data labels and the labels object. Adapt theme tokens instead of overriding SVG geometry. Reduced motion keeps the finished chart visible.

API Reference

Props

PropTypeDefaultDescription
variantMonoChartVariant'mono-rounded-line'One of the 30 IDs above or 'github-activity'. MONO_CHART_VARIANTS exports the original 30 IDs.
dataMonoChartData{}Caller-owned series, items, matrix, calendar, financial or flow data.
widthnumber560Deterministic SVG coordinate width; CSS scales it to the container, minimum 180.
heightnumber210 / compact 150SVG coordinate height, minimum 100.
titlestring—Optional heading.
ariaLabelstring'Mono chart'Accessible SVG name.
compactbooleanfalseSmaller insets, corner radius and default chart height.
seriesMode'single' | 'dual'local 'dual'v-model:series-mode; single uses the first series, dual includes the supplied series.
layout'col' | 'row'local 'col'v-model:layout; grouped/stacked bar orientation.
curve'monotone' | 'natural'local 'monotone'v-model:curve; line/area/range/sparkline curve. Stream always uses natural; step uses step-after.
showLinebooleanlocal truev-model:show-line; composed spline visibility.
controlsbooleantrueShow the source's line, bar, area or composed controls.
periodsMonoChartPeriod[]—{value,label,range?} period buttons.
periodstringfirst periodv-model:period; selected dataset/range.
periodDataRecord<string, MonoChartData>—Actual datasets indexed by period value.
centerMetricstring | numberdata-derivedCenter fallback when no segment is hovered.
centerLabelstringdata.metricLabelCenter fallback label.
showTooltipbooleantrueRender the readout; hover still emits when false.
showLegendbooleantrueDonut/radial item legends.
showMonthsbooleantrueActivity calendar month headers.
monthsnumber12Maximum recent activity month window, also fitted to width.
cellSizenumber11Activity cell coordinate size; adaptive gap, minimum 3.
accentstring | string[]variant paletteActivity color or four/five intensity colors. Four colors prepend transparent level zero.
accentColor'green' | 'blue' | 'purple' | 'mono'variant-derivedActivity palette override when no explicit accent is supplied.
openbooleanlocal statev-model:open; GitHub repository disclosure.
defaultOpenbooleanfalseInitial uncontrolled disclosure state.
yearnumberlatest contribution yearOptional GitHub year metadata override in the header; does not fabricate/filter data.
usernamestring—Public GitHub source for missing calendar/repository fields.
activityLoaderMonoChartActivityLoaderloadGitHubActivity(username, AbortSignal) => Promise<{contributions?,repos?}>.
labelsMonoChartLabelsEnglish defaultsSource controls, statuses, disclosure and tooltip field names.
localestring'en-US'Month-header locale; use the same locale server/client.
formatValue(number) => stringString(value)Numeric metric, legend and tooltip formatting.
formatX(string | number) => stringString(x)Writes an x value on the axis and as the tooltip title, e.g. a timestamp as a date.

Data types

All types are exported from @talex-touch/tuffex/charts.

MonoChartData fieldShape
categories(string | number)[]; categorical order.
series{id?,name,data:{x:string|number,value:number}[],metric?:string|number,opacity?:number}[].
items{label,value,max?,target?,opacity?}[]; segment/tier/axis/ring inputs.
points{label,x:number,y:number,z?:number}[]; independent numeric axes and area weighting.
candles{x,open,high,low,close}[]; OHLC values.
ranges{x,min,max}[]; range boundaries.
waterfall{label,delta,base?,total?}[]; absent base accumulates, total resets its base to zero.
matrix{label,values:number[]}[]; rows can have different column counts.
contributions{date:'YYYY-MM-DD',count:number,level:0|1|2|3|4}[].
repos{name,count,href?,logo?}[]; logo is an image URL.
nodes / linksExisting SankeyNodeData[] / SankeyLinkData[]; links use numeric source/target indices.
tree{label,value?,children?:MonoChartTreeNode[]}[]; child sums own internal node area.
metric / metricLabel / changeOptional caller-supplied header metric, unit/label and change text.

Labels

labels is partial; omitted keys retain English defaults: single='Single', dual='Dual', col='Col', row='Row', monotone='Monotone', natural='Natural', showLine='Spline on', hideLine='Spline off', repositories='Top contributions in', expand='Show repositories', collapse='Hide repositories', empty='No data', loading='Loading activity', error='Activity could not be loaded', retry='Retry', less='Less', more='More', target='Target', open='Open', high='High', low='Low', close='Close', x='X', y='Y', z='Z', min='Min', max='Max', delta='Delta', balance='Balance'.

Events

EventPayloadMeaning
update:seriesMode'single' | 'dual'Controlled switch; without a matching model, local state is used.
update:layout'col' | 'row'Controlled switch; without a matching model, local state is used.
update:curve'monotone' | 'natural'Controlled switch; without a matching model, local state is used.
update:showLinebooleanControlled switch; without a matching model, local state is used.
update:periodstringControlled switch; without a matching model, local state is used.
update:openbooleanControlled disclosure change; without a matching model, local state is used.
hoverMonoChartHit | null{key,label,rows:[{name,value}],value?,x,y}; coordinates use the SVG viewBox. Null clears inspection.
selectMonoChartHitPointer click, legend activation, Enter or Space; ending a drag does not select. No business action is simulated.
load{contributions?,repos?}Real source data accepted by the current request.
errorErrorCurrent loader/response failure; aborted or superseded requests do not emit success/errors.

Slots

SlotScopeReplacement
header{metric,data}Metric/heading summary; controls remain separate.
tooltip{hit}Tooltip content.
center{value,label,hit}Ring/gauge center content.
repository{repo}Each expanded repository row.
avatar{repo,collapsed}Repository avatar in both the collapsed stack and expanded rows; supports arbitrary VNodes.
footer{data}Content below the chart.

CSS variables

VariablePurpose
--tx-mono-inkMonochrome strokes and fills; defaults to --tx-text-color-primary.
--tx-mono-trackGauge/bullet tracks; defaults to --tx-fill-color.
--tx-mono-accentRoot activity hue, resolved from palette or explicit input.
--tx-chart-grid-line, --tx-chart-text-primaryExisting chart grid and axis tokens.
--tx-chart-semantic-success, --tx-chart-categorical-1, --tx-chart-categorical-4Emerald/blue/violet activity palettes and benchmark marker.
--tx-bg-color, --tx-fill-color*, --tx-border-color*, --tx-text-color*Host surfaces, outlines and UI labels.

Technologies

  • Component source: packages/tuffex/packages/components/src/charts/src/mono-chart/src/.
  • Geometry is pure and driven by data, reusing the scale, curve, Sankey and tooltip-placement helpers; a drag captures the pointer on the SVG and reads values back from coordinates (elementFromPoint), while the slop, capture and Escape come from the shared utils/press-scrub.ts.
  • Ported from Amicro src/components/mono-charts; github-activity is an additional variant, not a renamed activity palette.
查看源码
packages/tuffex/packages/components/src/charts/src/mono-chart/index.ts