audiocn

Electric Bar Visualizer

Frequency-band bars drawn as crackling filaments, with arcs between loud neighbours and sparks on sudden rises.

Installation

$ pnpm dlx shadcn@latest add @audiocn/electric-bar-visualizer

Usage

import { ElectricBarVisualizer } from "@/components/ui/electric-bar-visualizer";
<ElectricBarVisualizer
  aria-label="Voice activity"
  className="text-primary h-24"
  source={analyser.visual}
/>

It takes the same data and props as the bar visualizer, so you can swap one for the other. The electric look comes from the shape and the motion, not from a fixed colour: the bars follow the text colour, so they turn with your theme. In dark mode the core runs white-hot.

The visualizer fills its container, so size it with classes. It paints on the animation frame without re-rendering React, redraws on resize and picks up theme changes on its own.

Examples

Colors

Set the text color, or --electric, to any theme color.

primary
meter-ok
channel-solo
destructive

Intensity, arcs and sparks

intensity sets how jagged and restless the filaments are. arcs jump between loud neighbouring bars and sparks fly off the tips when a level rises quickly.

calm
default
charged

Idle and loading

idle decides what bars do without a signal. loading runs an arc along the bars, for connecting or thinking states.

idle pulse
idle wave
loading

Mirrored

Microphone

Theming

Variable or attributeMeaning
--electricFilament color, default currentColor
--electric-coreCore and tip color, default --electric mixed toward white by --electric-heat
--electric-heatHow white-hot the core runs, default 0% in light mode and 70% in dark mode
--electric-glowGlow color, default --electric
--electric-glow-sizeGlow blur, default 0.5rem
data-activeThe signal is above the floor
data-loadingThe loading arc is running
data-alignWhere bars grow from

The variables can be set from a class, such as [--electric-heat:40%], or globally.

Accessibility

The root has role="img" and the label "Audio visualizer". Pass aria-label to describe what it shows, or aria-hidden when it is decorative next to a labelled meter.

The flicker changes brightness by at most 12%, only on thin strokes, and each jagged shape holds for at least 40 ms, so nothing flashes across a large area. With reduced motion the bars are straight and still, with no arcs, sparks or flicker, and redraw four times a second.

API reference

Prop

Type