Skip to content

About

React and TypeScript component for rendering customizable sleep stage timelines with SVG.

Topics

Resources

Contributing

Stars

2 stars

Watchers

0 watching

Forks

Repository files navigation

react-hypnogram

Customizable, lightweight SVG sleep-stage charts (Hypnograms) for React and TypeScript.

CI License: MIT npm version npm downloads

Live Demo

react-hypnogram preview

  • SVG rendering with configurable stages, spacing, rounded corners, and vertical gradient fills.
  • Custom tooltip content, positioning, highlights, and callbacks.
  • React and TypeScript; no runtime dependency beyond React.

Installation

npm install react-hypnogram

Quick Start

import { Hypnogram } from 'react-hypnogram';
import type { HypnogramSegment } from 'react-hypnogram';

const data: HypnogramSegment[] = [
  { id: '1', stage: 'awake', start: '2026-09-09T22:14:00+08:00', end: '2026-09-09T22:32:00+08:00' },
  { id: '2', stage: 'light', start: '2026-09-09T22:32:00+08:00', end: '2026-09-09T23:10:00+08:00' },
  { id: '3', stage: 'deep',  start: '2026-09-09T23:10:00+08:00', end: '2026-09-10T00:28:00+08:00' },
  { id: '4', stage: 'rem',   start: '2026-09-10T00:28:00+08:00', end: '2026-09-10T01:10:00+08:00' },
];

export function App() {
  return (
    <Hypnogram
      data={data}
      time={{ timeZone: 'Asia/Shanghai' }}
      radius={12}
      stageHeight={40}
      barThickness={24}
      onSegmentClick={segment => console.log('Clicked segment:', segment.id)}
    />
  );
}

No external CSS required. The component adopts container width automatically.

Development

# Install dependencies
npm install

# Start playground development server
npm run dev

# Run tests and typecheck
npm test
npm run typecheck

# Full verification (types, tests, package, size, playground)
npm run check

Documentation

License

MIT

About

React and TypeScript component for rendering customizable sleep stage timelines with SVG.

Topics

Resources

Contributing

Stars

2 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages