1.0.3 â€Ē Published 11 months ago

@aniruddha1806/gantt-chart v1.0.3

Weekly downloads
-
License
MIT
Repository
-
Last release
11 months ago

React Gantt Chart

A powerful, customizable Gantt chart component for React applications with TypeScript support. Perfect for project management, scheduling, and timeline visualization with interactive features and extensive customization options.

Installation

npm install @aniruddha1806/gantt-chart

Features

  • 📅 Interactive Gantt charts with task bars and timelines
  • ðŸŽŊ Milestone support with different types (normal, critical, completed)
  • 🔗 Task dependencies with visual connection lines
  • 📊 Progress tracking with visual indicators
  • ðŸ–ąïļ Interactive tooltips and click handlers
  • ðŸ“ą Responsive design with horizontal/vertical scrolling
  • ðŸŽĻ Extensive customization (colors, dimensions, styling)
  • 📍 Today marker and weekend highlighting
  • 🔄 Virtualization support for large datasets
  • 📏 Flexible date ranges and custom date formatting
  • 📝 TypeScript support with full type definitions
  • â™ŋ Accessibility-friendly structure
  • ðŸŠķ Zero dependencies for chart rendering

Quick Start

Basic Gantt Chart

import { GanttChart } from '@aniruddha1806/gantt-chart';

function App() {
  const tasks = [
    {
      id: 1,
      label: 'Project Planning',
      startDate: new Date('2024-01-01'),
      endDate: new Date('2024-01-15'),
      color: '#3b82f6',
      progress: 100
    },
    {
      id: 2,
      label: 'Development Phase',
      startDate: new Date('2024-01-10'),
      endDate: new Date('2024-02-28'),
      color: '#10b981',
      progress: 60,
      dependencies: [1]
    },
    {
      id: 3,
      label: 'Testing & QA',
      startDate: new Date('2024-02-15'),
      endDate: new Date('2024-03-15'),
      color: '#f59e0b',
      progress: 30,
      dependencies: [2]
    }
  ];

  const milestones = [
    {
      id: 'milestone-1',
      label: 'Project Kickoff',
      date: new Date('2024-01-01'),
      type: 'normal'
    },
    {
      id: 'milestone-2',
      label: 'Beta Release',
      date: new Date('2024-02-28'),
      type: 'critical'
    }
  ];

  return (
    <GanttChart
      tasks={tasks}
      milestones={milestones}
      width="100%"
      height={400}
      showToday={true}
      showDependencies={true}
    />
  );
}

Advanced Configuration

import { GanttChart } from '@aniruddha1806/gantt-chart';

function AdvancedExample() {
  const tasks = [
    // ... your tasks
  ];

  const milestones = [
    // ... your milestones
  ];

  return (
    <GanttChart
      tasks={tasks}
      milestones={milestones}
      width="100%"
      height={600}
      rowHeight={50}
      columnWidth={80}
      showToday={true}
      showGrid={true}
      showDependencies={true}
      highlightWeekends={true}
      separateMilestoneRow={true}
      showMilestoneLabels={true}
      virtualized={true}
      onTaskClick={(task) => console.log('Task clicked:', task)}
      onMilestoneClick={(milestone) => console.log('Milestone clicked:', milestone)}
    />
  );
}

Props

Core Props

PropTypeDefaultDescription
tasksGanttTask[]requiredArray of tasks to display
milestonesGanttMilestone[][]Array of milestones
widthstring \| number"100%"Chart width
heightstring \| number500Chart height

Layout Props

PropTypeDefaultDescription
headerHeightnumber40Height of date header
rowHeightnumber40Height of each task row
columnWidthnumber60Width of date columns
barCornerRadiusnumber0Border radius of task bars

Display Props

PropTypeDefaultDescription
showTodaybooleantrueShow today marker line
showGridbooleantrueShow grid lines
showDependenciesbooleanfalseShow dependency connections
highlightWeekendsbooleanfalseHighlight weekend columns
showMilestoneLabelsbooleanfalseShow milestone labels
separateMilestoneRowbooleantrueSeparate row for milestones

Performance Props

PropTypeDefaultDescription
virtualizedbooleanfalseEnable virtualization for large datasets

Color Props

PropTypeDefaultDescription
todayColorstring"#4338CA"Today marker color
gridColorstring"#E5E7EB"Grid line color
barFillColorstring"#4F46E5"Default task bar color
barStrokeColorstring"#4338CA"Task bar border color
weekendColorstring"#F3F4F6"Weekend highlight color
milestoneColorstring"#EF4444"Default milestone color

Styling Props

PropTypeDefaultDescription
classNamestringundefinedCSS class for container
headerClassNamestringundefinedCSS class for header
rowClassNamestringundefinedCSS class for rows
barClassNamestringundefinedCSS class for task bars
tooltipClassNamestringundefinedCSS class for tooltips

Event Props

PropTypeDefaultDescription
onTaskClick(task: GanttTask) => voidundefinedTask click handler
onMilestoneClick(milestone: GanttMilestone) => voidundefinedMilestone click handler

Data Types

type GanttTask = {
  id: string | number;
  label: string;
  startDate: Date;
  endDate: Date;
  color?: string;
  progress?: number;
  dependencies?: (string | number)[];
};

type GanttMilestone = {
  id: string | number;
  label: string;
  date: Date;
  color?: string;
  description?: string;
  type?: "normal" | "critical" | "completed";
};

Examples

Project Management Dashboard

Complete project timeline with dependencies:

import { GanttChart } from '@aniruddha1806/gantt-chart';

function ProjectDashboard() {
  const tasks = [
    {
      id: 'planning',
      label: 'Project Planning',
      startDate: new Date('2024-01-01'),
      endDate: new Date('2024-01-15'),
      color: '#3b82f6',
      progress: 100
    },
    {
      id: 'design',
      label: 'UI/UX Design',
      startDate: new Date('2024-01-10'),
      endDate: new Date('2024-02-05'),
      color: '#8b5cf6',
      progress: 85,
      dependencies: ['planning']
    },
    {
      id: 'frontend',
      label: 'Frontend Development',
      startDate: new Date('2024-01-25'),
      endDate: new Date('2024-03-15'),
      color: '#10b981',
      progress: 60,
      dependencies: ['design']
    },
    {
      id: 'backend',
      label: 'Backend Development',
      startDate: new Date('2024-02-01'),
      endDate: new Date('2024-03-20'),
      color: '#f59e0b',
      progress: 45,
      dependencies: ['planning']
    },
    {
      id: 'testing',
      label: 'Testing & QA',
      startDate: new Date('2024-03-10'),
      endDate: new Date('2024-04-05'),
      color: '#ef4444',
      progress: 20,
      dependencies: ['frontend', 'backend']
    },
    {
      id: 'deployment',
      label: 'Deployment',
      startDate: new Date('2024-04-01'),
      endDate: new Date('2024-04-10'),
      color: '#06b6d4',
      progress: 0,
      dependencies: ['testing']
    }
  ];

  const milestones = [
    {
      id: 'kickoff',
      label: 'Project Kickoff',
      date: new Date('2024-01-01'),
      type: 'normal',
      description: 'Official project start'
    },
    {
      id: 'design-complete',
      label: 'Design Complete',
      date: new Date('2024-02-05'),
      type: 'normal',
      description: 'All designs approved'
    },
    {
      id: 'beta-release',
      label: 'Beta Release',
      date: new Date('2024-03-20'),
      type: 'critical',
      description: 'Beta version ready for testing'
    },
    {
      id: 'launch',
      label: 'Product Launch',
      date: new Date('2024-04-10'),
      type: 'critical',
      description: 'Official product launch'
    }
  ];

  const handleTaskClick = (task) => {
    console.log('Task clicked:', task.label);
    // Open task details modal, etc.
  };

  const handleMilestoneClick = (milestone) => {
    console.log('Milestone clicked:', milestone.label);
    // Show milestone details, etc.
  };

  return (
    <div style={{ padding: '20px' }}>
      <h2>Project Timeline</h2>
      <p>Web Application Development - Q1 2024</p>
      
      <GanttChart
        tasks={tasks}
        milestones={milestones}
        width="100%"
        height={500}
        showToday={true}
        showGrid={true}
        showDependencies={true}
        highlightWeekends={true}
        separateMilestoneRow={true}
        showMilestoneLabels={true}
        onTaskClick={handleTaskClick}
        onMilestoneClick={handleMilestoneClick}
      />
      
      <div style={{ 
        marginTop: '20px',
        display: 'grid',
        gridTemplateColumns: 'repeat(auto-fit, minmax(250px, 1fr))',
        gap: '16px'
      }}>
        <div style={{ 
          padding: '16px', 
          backgroundColor: '#f8fafc', 
          borderRadius: '8px',
          border: '1px solid #e2e8f0'
        }}>
          <h4>Project Progress</h4>
          <p>Overall: {Math.round(tasks.reduce((sum, task) => sum + (task.progress || 0), 0) / tasks.length)}%</p>
        </div>
        
        <div style={{ 
          padding: '16px', 
          backgroundColor: '#f8fafc', 
          borderRadius: '8px',
          border: '1px solid #e2e8f0'
        }}>
          <h4>Upcoming Milestones</h4>
          <p>{milestones.filter(m => m.date > new Date()).length} remaining</p>
        </div>
      </div>
    </div>
  );
}

TypeScript Usage

The component provides full TypeScript support:

import { GanttChart, GanttTask, GanttMilestone, GanttChartProps } from '@aniruddha1806/gantt-chart';
import { useState, useCallback } from 'react';

interface ProjectData {
  tasks: GanttTask[];
  milestones: GanttMilestone[];
  settings: {
    showDependencies: boolean;
    highlightWeekends: boolean;
  };
}

interface TaskUpdateData {
  taskId: string | number;
  progress: number;
  endDate?: Date;
}

const ProjectManager: React.FC = () => {
  const [projectData, setProjectData] = useState<ProjectData>({
    tasks: [
      {
        id: 'task-1',
        label: 'Development',
        startDate: new Date('2024-01-01'),
        endDate: new Date('2024-02-01'),
        color: '#3b82f6',
        progress: 60,
        dependencies: []
      }
    ],
    milestones: [
      {
        id: 'milestone-1',
        label: 'Release',
        date: new Date('2024-02-01'),
        type: 'critical',
        description: 'Product release milestone'
      }
    ],
    settings: {
      showDependencies: true,
      highlightWeekends: true
    }
  });

  const handleTaskClick = useCallback((task: GanttTask): void => {
    console.log('Task clicked:', task);
    // Handle task click logic
  }, []);

  const handleMilestoneClick = useCallback((milestone: GanttMilestone): void => {
    console.log('Milestone clicked:', milestone);
    // Handle milestone click logic
  }, []);

  const updateTaskProgress = useCallback((updateData: TaskUpdateData): void => {
    setProjectData(prev => ({
      ...prev,
      tasks: prev.tasks.map(task => 
        task.id === updateData.taskId 
          ? { 
              ...task, 
              progress: updateData.progress,
              ...(updateData.endDate && { endDate: updateData.endDate })
            }
          : task
      )
    }));
  }, []);

  const ganttProps: GanttChartProps = {
    tasks: projectData.tasks,
    milestones: projectData.milestones,
    width: '100%',
    height: 500,
    showToday: true,
    showDependencies: projectData.settings.showDependencies,
    highlightWeekends: projectData.settings.highlightWeekends,
    onTaskClick: handleTaskClick,
    onMilestoneClick: handleMilestoneClick
  };

  return (
    <div>
      <h2>Project Timeline</h2>
      <GanttChart {...ganttProps} />
      
      <div>
        <h3>Project Statistics:</h3>
        <p>Total Tasks: {projectData.tasks.length}</p>
        <p>Completed Tasks: {projectData.tasks.filter(t => t.progress === 100).length}</p>
        <p>Milestones: {projectData.milestones.length}</p>
      </div>
    </div>
  );
};
1.0.3

11 months ago

1.0.2

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago