1.36.1 • Published 1 month ago

@melfore/konva-timeline v1.36.1

Weekly downloads
-
License
MIT
Repository
github
Last release
1 month ago

@melfore/konva-timeline

Konva Timeline - Release Commitizen friendly

@melfore/konva-timeline is a TypeScript ReactJS library that uses konva and react-konva to render a timeline component using canvas.

Changelog | Storybook

sample

Features

This library is meant to represent data on a time range. It has been developed in a way to be the most generic it could. It can be used to display gantt charts, schedulers and planners.

The library follows the concept of organizing data (tasks) belonging to specific groups (resources) over a predefined time window.

Interaction

There can be from none to many tasks per each resource and tasks can be moved across resources. Tasks can also be resized and hovered.

For each user interaction with tasks there is a dedicated hook function exposed by the component's props. This enables various use cases like displaying the details of a task inside a modal or calling an API each time the task is moved.

Gantt

In order to create and display connection between tasks is neccesary setting dedicated props:

  • relatedTasks is a string array prop of TaskData that contains Ids of related Tasks.
  • enableLines is a global prop for the visualization of the connections.

In this case OnTasksChange return also array of all tasks id that are inpacted by changed end of a the task at hand, and value of time in milliseconds of this variation.

⚠️ By relatedTasks is mean these tasks that their start can depends of the end of the task in question.

gantt

Custom display

Size of columns and rows can be adjusted using dedicated props:

column width

row height

Resolution of the timeline can be changed as well, choosing the right one for your scenario.

Below a comparison of the same data set using 5 mins resolution:

5mins resolution

Now with 2 hours resolution:

2hrs resolution

Tasks

In many of the above mentioned use cases it's important to track the progress of tasks. That's why we offer a built-in visualization for percentage of completion:

completed percentage

Tasks can also have their label displayed:

label display

Handling timezones and DST

The library uses luxon to handle dates and date-times. This allows localization (see next paragraph) and handling of timezones and DST.

The default timezone configuration is system (meaning the system's local zone). This can be overridden using the dedicated prop.

Along with timezones, the library handles DST changes (if any). In the example below the switch of DST for spring 2020, happening between March 28th and March 29th.

timezones dst

Localization

Date formats and static texts can be localized:

localized

Area Select

Select area to get its timeRange and resourceId:

area selected

Personalized ToolTip

It's possible to personalize the toolTip passing createToolTip callback that return jsx element

personalized toolTip

Getting started

To install the library run:

npm i @melfore/konva-timeline

This library has the following required peerDependencies:

"konva": ">= 9.2.0 < 10",
"luxon": ">= 3.3.0 < 4",
"react": ">= 18.2.0 < 19",
"react-dom": ">= 18.2.0 < 19",
"react-konva": ">= 18.2.9 < 19",
"react-konva-utils": ">= 1.0.5 < 2"

⚠️ Installing with npm < 7

If installing with versions of npm < 7, you have to manually install them.

npm i konva luxon react react-dom react-konva

Beware to check the versions installed, they must match peerDependencies ranges.

Usage

Import the KonvaTimeline component from @melfore/konva-timeline library:

import { KonvaTimeline } from "@melfore/konva-timeline";

Provide the minimum set of required props.

  <KonvaTimeline
    range={{
      end: 1577919600000,
      start: 1577833200000
    }}
    resources={[
      {
        color: '#f00bda',
        id: '1',
        label: 'Resource #1'
      },
      {
        color: '#b66f77',
        id: '2',
        label: 'Resource #2'
      },
      {
        color: '#273e3e',
        id: '3',
        label: 'Resource #3'
      }
    ]}
  />

This will print an empty timeline with three resources:

usage empty

Add an array of tasks:

  <KonvaTimeline
    range={{
      end: 1577919600000,
      start: 1577833200000
    }}
    resources={[
      {
        color: '#74ff93',
        id: '1',
        label: 'Resource #1'
      },
      {
        color: '#7de7dd',
        id: '2',
        label: 'Resource #2'
      },
      {
        color: '#a6bbec',
        id: '3',
        label: 'Resource #3'
      }
    ]}
+   tasks={[
+     {
+       id: '4',
+       label: 'Task #4',
+       resourceId: '2',
+       time: {
+         end: 1577833740000,
+         start: 1577833200000
+       }
+     },
+     {
+       id: '2',
+       label: 'Task #2',
+       resourceId: '1',
+       time: {
+         end: 1577848200000,
+         start: 1577833200000
+       }
+     },
+     {
+       id: '1',
+       label: 'Task #1',
+       resourceId: '3',
+       time: {
+         end: 1577849520000,
+         start: 1577833200000
+       }
+     },
+     {
+       id: '3',
+       label: 'Task #3',
+       resourceId: '1',
+       time: {
+         end: 1577885040100,
+         start: 1577871660100
+       }
+     },
+     {
+       id: '5',
+       label: 'Task #5',
+       resourceId: '2',
+       time: {
+         end: 1577865540100,
+         start: 1577842440100
+       }
+     }
+   ]}
  />

The resourceId property of each task assigns the task to the respective resource.

usage final

Documentation and examples

Browse official StoryBook

1.36.1

1 month ago

1.36.0

2 months ago

1.35.0

2 months ago

1.34.0

2 months ago

1.33.1

2 months ago

1.33.2

2 months ago

1.33.0

2 months ago

1.32.3

2 months ago

1.32.2

3 months ago

1.32.1

3 months ago

1.32.0

3 months ago

1.30.2

3 months ago

1.31.0

3 months ago

1.30.0

3 months ago

1.30.1

3 months ago

1.29.1

3 months ago

1.29.2

3 months ago

1.29.0

3 months ago

1.28.0

3 months ago

1.27.1

4 months ago

1.27.0

4 months ago

1.26.1

4 months ago

1.26.0

4 months ago

1.25.2

4 months ago

1.25.1

4 months ago

1.25.0

5 months ago

1.24.0

5 months ago

1.23.0

5 months ago

1.22.2

5 months ago

1.22.1

6 months ago

1.22.0

6 months ago

1.21.2

6 months ago

1.21.1

6 months ago

1.21.0

6 months ago

1.20.1

6 months ago

1.20.0

6 months ago

1.19.0

6 months ago

1.18.1

6 months ago

1.18.0

6 months ago

1.17.0

6 months ago

1.16.2

6 months ago

1.16.1

6 months ago

1.16.0

7 months ago

1.15.4

7 months ago

1.15.3

7 months ago

1.15.2

7 months ago

1.15.1

7 months ago

1.15.0

7 months ago

1.14.3

7 months ago

1.14.2

7 months ago

1.14.1

7 months ago

1.14.0

7 months ago

1.13.1

7 months ago

1.13.0

7 months ago

1.12.0

7 months ago

1.11.0

7 months ago

1.10.0

7 months ago

1.9.0

7 months ago

1.8.0

7 months ago

1.7.7

8 months ago

1.7.6

8 months ago

1.7.5

8 months ago

1.7.4

8 months ago

1.7.3

8 months ago

1.7.2

8 months ago

1.7.1

8 months ago

1.7.0

8 months ago

1.6.0

8 months ago

1.5.2

8 months ago

1.5.1

8 months ago

1.5.0

8 months ago

1.4.6

8 months ago

1.4.5

8 months ago

1.4.4

8 months ago

1.4.3

8 months ago

1.4.2

8 months ago

1.4.1

8 months ago

1.4.0

8 months ago

1.3.2

8 months ago

1.3.1

8 months ago

1.3.0

8 months ago

1.2.0

8 months ago

1.1.0

8 months ago

1.0.3

8 months ago

1.0.2

9 months ago

1.0.1

9 months ago

1.0.0

9 months ago

0.0.1

9 months ago