npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

time-segment-timeline

v1.0.8

Published

A flexible React component for displaying time-based tariff/schedule panels

Readme

Time Segment Timeline

npm version TypeScript React

A flexible React component for displaying time-based tariff/schedule panels with dynamic grouping and legends.

Screenshots

Basic Timeline View

Basic Timeline

Grouped Timeline

Grouped Timeline

Custom Legend Support

Custom Legend

Features

  • 🕐 Flexible Time Display - Display time ranges with visual timeline
  • 🎨 Customizable Legends - Support custom color schemes with fallback to built-in defaults
  • 📊 Dynamic Grouping - Group data by any criteria using custom filter functions
  • 🔧 Dynamic Properties - Support for arbitrary additional properties in data items
  • Performance Optimized - Uses React.memo for efficient re-rendering
  • 🎯 TypeScript Support - Full TypeScript support with type safety

Installation

npm install time-segment-timeline

Basic Usage

import React, { useState } from 'react';
import TimelinePanel from 'time-segment-timeline';
import { Timeitem } from 'time-segment-timeline/dist/types';

const testData: Timeitem[] = [
  {
    start_time: '00:00',
    end_time: '09:00',
    name: 'summer',
    tou_desc: 'work(A)'
  },
  {
    start_time: '08:00',
    end_time: '18:00',
    name: 'rain',
    tou_desc: 'sleep(B)'
  }
];

function App() {
  const [errorMap, setErrorMap] = useState<Timeitem[]>([]);
  
  const customLegend = {
    'work(A)': '#ff0000',
    'sleep(B)': '#ffbf00',
  };

  const groupConfig = {
    summer: {
      title: 'summer',
      filterFn: (item: Timeitem) => item.name === 'summer'
    },
    rain: {
      title: 'rain',
      filterFn: (item: Timeitem) => item.name === 'rain'
    }
  };

  return (
    <TimelinePanel
      testData={testData}
      setErrorMap={setErrorMap}
      legendData={customLegend}
      groupConfig={groupConfig}
    />
  );
}

API Reference

TimelinePanel Props

| Property | Type | Default | Description | |----------|------|---------|-------------| | testData | Timeitem[] | Required - Array of time data items | | setErrorMap | React.Dispatch<React.SetStateAction<Timeitem[]>> | Required - State setter for error items | | width | string \| number | '100%' | Component width | | height | string \| number | 'auto' | Component height | | mt | string \| number | undefined | Margin top | | legendData | Record<string, string> | undefined | Custom legend colors | | groupConfig | Record<string, GroupConfig> | undefined | Grouping configuration |

Timeitem Interface

interface Timeitem {
  id?: number;
  start_mn?: string;        // "MM-DD"
  end_mn?: string;          // "MM-DD"
  start_week?: number;       // 1=Mon ... 7=Sun
  end_week?: number;         // 1=Mon ... 7=Sun
  start_time?: string;       // "HH:mm"
  end_time?: string;         // "HH:mm"
  tou_desc?: string;         // Time period description
  tou_type?: string;         // Short code
  [key: string]: any;       // Additional properties
}

GroupConfig Interface

interface GroupConfig {
  title: string;                                    // Display title
  filterFn: (item: Timeitem) => boolean;  // Filter function
}

Visual Examples

Timeline with Overlap Detection

Overlap Detection

Multiple Time Groups

Multiple Groups

Custom Styling

Custom Styling

Advanced Features

Custom Grouping

Group your data by any criteria:

const groupConfig = {
  workingHours: {
    title: 'Working Hours',
    filterFn: (item) => item.start_time >= '09:00' && item.end_time <= '17:00'
  },
  weekends: {
    title: 'Weekends',
    filterFn: (item) => item.start_week >= 6
  }
};

Dynamic Properties

Add any custom properties to your data:

const testData = [
  {
    start_time: '09:00',
    end_time: '17:00',
    tou_desc: 'Work',
    priority: 'high',        // Custom property
    department: 'IT',         // Custom property
    cost: 150.75              // Custom property
  }
];

Built-in Legend Support

The component includes built-in legend items for common scenarios:

  • '空缺(V)' - Empty slots (gray)
  • '重複(R)' - Overlapping slots (black)

These will automatically display even if not provided in legendData.

alt text