Skip to content

@vibe-labs/design-components-graphs

Graph and chart component tokens, styles, and TypeScript types for the Vibe Design System. Provides a framework-agnostic design language for chart libraries (D3, Chart.js, etc.) to consume.

Installation

bash
npm install @vibe-labs/design-components-graphs
css
@import "@vibe-labs/design-components-graphs";
ts
import { GRAPH_SERIES_COUNT, GraphRatios, GraphStatusSeries, RadarGridStyles } from "@vibe-labs/design-components-graphs/types";
import type {
  GraphRatio,
  GraphStyleProps,
  GraphSeriesStyleProps,
  RadarGridStyle,
  GraphRadarStyleProps,
} from "@vibe-labs/design-components-graphs/types";

Contents

Tokens

Comprehensive charting tokens defined in @layer vibe.tokens (file: graph.css).

Series Palette

8 default series colors chosen for dark/light distinguishability. Tenants can override or extend with --graph-series-9, etc.

TokenDefault
--graph-series-1#7c5cff (accent purple)
--graph-series-2#38bdf8 (sky blue)
--graph-series-3#34d399 (emerald)
--graph-series-4#fb923c (orange)
--graph-series-5#f472b6 (pink)
--graph-series-6#facc15 (yellow)
--graph-series-7#a78bfa (violet)
--graph-series-8#22d3ee (cyan)
--graph-series-opacity0.15 (area fills)

Status Series

--graph-positive (success) · --graph-negative (danger) · --graph-warning (warning) · --graph-neutral (muted)

Other Token Groups

  • Axes & Grid — axis lines, labels, titles, major/minor ticks, major/minor grid lines (with dash patterns)
  • Tooltip — background, border, shadow, padding, label color, value weight
  • Legend — font size, color, gap, swatch size/radius, inactive opacity
  • Data Elements — points (size, hover size, stroke), lines (width, hover, caps), bars (radius, gap, hover brightness)
  • Annotations — reference lines with dash pattern, label background, positive/negative/warning variants
  • Highlight & Selection — region fill/border, selection region fill (accent-tinted)
  • Empty State — centered muted text for no-data scenarios

Radar / Spider Chart

TokenDefaultDescription
--graph-radar-grid-colorborder-subtleConcentric ring stroke
--graph-radar-grid-width1pxRing stroke width
--graph-radar-grid-opacity0.6Ring opacity
--graph-radar-spoke-colorborder-subtleAxis line stroke
--graph-radar-spoke-width1pxAxis line width
--graph-radar-label-colortext-secondaryPerimeter label color
--graph-radar-label-font-sizetext-xsPerimeter label size
--graph-radar-label-font-weightfont-semiboldPerimeter label weight
--graph-radar-label-gap12pxGap between perimeter and labels
--graph-radar-fill-opacity0.2Polygon area fill opacity
--graph-radar-fill-hover-opacity0.35Polygon hover fill opacity
--graph-radar-stroke-width2pxPolygon outline width
--graph-radar-stroke-hover-width3pxPolygon hover outline width
--graph-radar-point-size4pxVertex dot radius
--graph-radar-point-size-hover6pxVertex dot hover radius
--graph-radar-point-stroke-width2pxVertex dot stroke width
--graph-radar-point-stroke-colorsurface-baseVertex dot stroke color

Generated Styles

Component classes generated into @layer vibe.components (file: graph.g.css).

Container

ClassDescription
.graphRelative positioned, full width, padding
.graph-canvasFull width/height SVG container

Ratios (data-ratio): 16x9 · 4x3 · 1x1 · 21x9

Series

Set data-color attribute on the series element:

  • Numbered: data-color="1"data-color="8" — sets stroke and fill from series palette
  • Status: data-color="positive|negative|warning|neutral" — semantic series colors
  • Areas: area-flagged series get reduced fill opacity (--graph-series-opacity)

Data Elements

ClassDescription
.graph-pointCircle markers with hover size transition
.graph-lineStroked paths with hover width transition
.graph-barRounded rects with hover brightness filter

Other Elements

ClassDescription
.graph-tooltipPositioned overlay with label rows and auto-layout
.graph-legendFlex-wrapped items with swatches, inactive toggle
.graph-crosshairDashed pointer-events-none tracking line
.graph-radarRadar container
.graph-radar-gridConcentric ring paths (polygon or circle)
.graph-radar-spokeAxis lines from centre to perimeter
.graph-radar-labelPerimeter axis labels
.graph-radar-polygonData area with fill opacity + stroke, hover
.graph-radar-pointVertex dots with hover size transition

Radar grid style (data-grid-style on .graph-radar): polygon · circle

TypeScript Types

ts
GRAPH_SERIES_COUNT  // 8
GraphRatios         // ["16x9", "4x3", "1x1", "21x9"]
GraphStatusSeries   // ["positive", "negative", "warning", "neutral"]
GraphAnnotationVariants // ["positive", "negative", "warning"]
RadarGridStyles     // ["polygon", "circle"]

type GraphRatio
type GraphStatusSeriesName
type GraphAnnotationVariant
type RadarGridStyle

interface GraphStyleProps { ratio?: GraphRatio }
interface GraphSeriesStyleProps { color?: string }
interface GraphLegendItemStyleProps { inactive?: boolean }
interface GraphLegendSwatchStyleProps { line?: boolean }
interface GraphAnnotationStyleProps { variant?: GraphAnnotationVariant }
interface GraphRadarStyleProps { gridStyle?: RadarGridStyle }
// + tooltip, point, line, bar, canvas, empty, radar-grid, radar-spoke,
//   radar-label, radar-polygon, radar-point interfaces

Dist Structure

FileDescription
index.cssBarrel — imports tokens + generated styles
graph.cssToken definitions
graph.g.cssGenerated component styles
index.js / index.d.tsTypeScript types + runtime constants

Dependencies

Requires tokens from @vibe-labs/design (colors, surfaces, borders, spacing, typography, elevation, transitions).

Build

bash
npm run build

Usage Guide

Import

css
@import "@vibe-labs/design-components-graphs";
ts
import type { GraphStyleProps, GraphRadarStyleProps } from "@vibe-labs/design-components-graphs/types";

Variants

Aspect ratio

Set data-ratio on .graph: 16x9 · 4x3 · 1x1 · 21x9

Series color

Set data-color on series elements: 18 for palette colors · positive · negative · warning · neutral for semantic colors

Radar grid style

Set data-grid-style on .graph-radar: polygon · circle

Legend item inactive

Set data-inactive on .graph-legend-item for toggle-off state.

Annotation variant

Set data-variant on .graph-annotation: positive · negative · warning

Examples

Graph container shell

html
<!-- Base container — chart library renders into .graph-canvas -->
<div class="graph" data-ratio="16x9">
  <svg class="graph-canvas" viewBox="0 0 800 450">
    <!-- Chart library renders paths, rects, etc. here -->
  </svg>
</div>

Styled data series (SVG)

html
<!-- Apply Vibe series tokens to SVG paths/circles rendered by your chart lib -->
<g data-color="1">
  <!-- Series 1 — accent purple; stroke and fill from --graph-series-1 -->
  <path class="graph-line" d="M0,100 L200,50 L400,80" />
</g>
<g data-color="2">
  <!-- Series 2 — sky blue -->
  <path class="graph-line" d="M0,120 L200,70 L400,60" />
</g>

Bar chart elements

html
<svg class="graph-canvas">
  <!-- Bars use border-radius and hover brightness from tokens -->
  <rect class="graph-bar" data-color="1" x="10" y="50" width="30" height="100" />
  <rect class="graph-bar" data-color="2" x="50" y="30" width="30" height="120" />
</svg>

Tooltip

html
<!-- Tooltip — positioned absolutely over the chart -->
<div class="graph-tooltip" style="left: 200px; top: 50px">
  <div class="graph-tooltip-label">March 2024</div>
  <div class="graph-tooltip-row">
    <span class="graph-legend-swatch" style="background: var(--graph-series-1)"></span>
    <span>Revenue</span>
    <span>$42,000</span>
  </div>
</div>

Legend

html
<!-- Horizontal flex legend with swatches -->
<div class="graph-legend">
  <div class="graph-legend-item">
    <span class="graph-legend-swatch" style="background: var(--graph-series-1)"></span>
    Revenue
  </div>
  <div class="graph-legend-item" data-inactive>
    <!-- Inactive = toggled off series -->
    <span class="graph-legend-swatch" style="background: var(--graph-series-2)"></span>
    Expenses
  </div>
</div>

Radar chart (spider chart)

html
<!-- Radar chart container with polygon grid style -->
<div class="graph-radar" data-grid-style="polygon">
  <svg class="graph-canvas" viewBox="-150 -150 300 300">
    <!-- Concentric polygon rings -->
    <polygon class="graph-radar-grid" points="…" />
    <!-- Axis spokes -->
    <line class="graph-radar-spoke" x1="0" y1="0" x2="0" y2="-120" />
    <!-- Axis labels -->
    <text class="graph-radar-label" x="0" y="-135">Speed</text>
    <!-- Data polygon for series 1 -->
    <polygon class="graph-radar-polygon" data-color="1" points="…" />
    <!-- Vertex dots -->
    <circle class="graph-radar-point" data-color="1" cx="0" cy="-90" r="4" />
  </svg>
</div>

With Vue

Use @vibe-labs/design-vue-graphs for <SbGraph> and related components that expose the series color system and token CSS variables as props, making chart library integration straightforward.

Vibe