awesome-timeline-react 0.1.15 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE CHANGED
@@ -1,21 +1,21 @@
1
- MIT License
2
-
3
- Copyright (c) 2024 Jakub Plata
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
1
+ MIT License
2
+
3
+ Copyright (c) 2024 Jakub Plata
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,96 +1,240 @@
1
- # Awesome Timeline React
2
-
3
- ## Introduction
4
-
5
- **Awesome Timeline React** is a component that developers can include in their projects. It provides a Gantt timeline for visualizing and managing events. With simple configuration, powerful performance, and customization options, it's an excellent choice for your project. Current releases are pre-releases. If you have any ideas for features or encounter any bugs, please email me at [jakub.plata@yahoo.pl](mailto:jakub.plata@yahoo.pl).
6
-
7
- ![](https://raw.githubusercontent.com/Plageros/awesome-timeline-react/master/public/gifs/demo-overview.gif)
8
-
9
- ## Instalation
10
-
11
- ```sh
12
- npm install awesome-react-timeline
13
- ```
14
-
15
- ## Ladle
16
-
17
- To run ladle stories, type:
18
-
19
- ```sh
20
- npm run ladle
21
- ```
22
-
23
- ## Configuration
24
-
25
- First, import the `Timeline` component and css into your project.
26
-
27
- ```sh
28
- import { Timeline } from "awesome-timeline-react";
29
- import "awesome-timeline-react/dist/index.css";
30
- ```
31
-
32
- The following properties for Timeline component are available:
33
-
34
- - `rows` – an array of objects that define rows. The order within the array will be preserved in the Timeline.
35
-
36
- - `events` – an array of objects that define events assigned to particular rows. Each object includes:
37
-
38
- - `id`: `string`
39
- - `rowId`: `string`
40
- - `startTime`: `number` (timestamp in seconds)
41
- - `endTime`: `number` (timestamp in seconds)
42
- - `props`:
43
- - `isLocked`: `boolean` (defines if event is locked, meaning it cannot be moved. Default is `false`)
44
- - `content`: `JSX.Element | string` (customizable content for each event)
45
- - `classNames`: `string[]` (array of additional class names for customizing the event)
46
- - `isResizable`: `boolean` (defines if event is resizable, overrides the default property `eventsResize`)
47
- - `showPrompt`: `boolean` (defines if prompt will be shown after hover. Works only if `showEventPrompt` is set as true)
48
- - `metadata`: `any` (some data that can be used by event prompt template)
49
-
50
- - `staticEvents` – an array of objects that define static events for particular rows, meaning the events are not interactable by the user.
51
-
52
- - `onDrop` – an external callback for the `onDrop` event that can be injected. The callback receives the following properties:
53
-
54
- - `eventId`: `string`
55
- - `oldRowId`: `string`
56
- - `newRowId`: `string`
57
- - `startTime`: `number` (timestamp in seconds)
58
- - `endTime`: `number` (timestamp in seconds)
59
-
60
- - `onResize` – an external callback after the resize event was done, that can be injected. The callback receives the following properties:
61
-
62
- - `eventId`: `string`
63
- - `startTime`: `number` (timestamp in seconds)
64
- - `endTime`: `number` (timestamp in seconds)
65
-
66
- - `additionalClassNames` – contains additional class names that will be included within elements:
67
-
68
- - `timeBar`: `string`
69
- - `dayRow`: `string`
70
- - `hourRow`: `string`
71
- - `line`: `string`
72
- - `rowsHeader`: `string`
73
-
74
- - `showRTIndicator` – property that controls wheter Real Time Indicator will be show (default as true)
75
-
76
- - `eventsResize` - property that define if events are resizeable (default as true)
77
-
78
- - `showEventPrompt` - property that define if prompt for events will be shown after hover (defualt as true)
79
-
80
- - `eventPromptTemplate` - function that can be passed for event prompt. Function receives currently hovered `event` object. It returns JSX Element so it can be customize in various ways. The example is in story.
81
-
82
- ## Awesome Features
83
-
84
- One of the awesome features (currently hidden from the interface) is adjusting the granulation of the grid. To achieve this, click the wheel on the mouse. This will hide the scroll bar, and you can adjust the grid granulation by scrolling the wheel. Each scroll iteration adjusts the grid by ±15 minutes, depending on the scroll direction.
85
-
86
- ![](https://raw.githubusercontent.com/Plageros/awesome-timeline-react/master/public/gifs/demo-grid-granulation.gif)
87
-
88
- ## Roadmap
89
-
90
- Here, we will store major features planned for future releases (from highest to lowest priority):
91
-
92
- 1. ~~Resize events~~ - published in 0.1.8 version
93
- 2. ~~Real time line~~ - published in 0.1.7 version
94
- 3. ~~Customizable prompts after hovering over an event~~ - published in 0.1.14 version
95
- 4. Customizable second row of the time bar
96
- 5. Intersection observer with `display: none` property to further improve performance
1
+ # Awesome Timeline React
2
+
3
+ ## Introduction
4
+
5
+ **Awesome Timeline React** is a Gantt timeline component for visualizing and managing events. Since version **0.2.0** it renders on **HTML canvas** with vertical virtualization and an imperative streaming API — designed to hold **10,000+ events at 60 fps**, including boards fed by live data (websockets). If you have any ideas for features or encounter any bugs, please email me at [jakub.plata@yahoo.pl](mailto:jakub.plata@yahoo.pl).
6
+
7
+ ![](https://raw.githubusercontent.com/Plageros/awesome-timeline-react/master/public/gifs/demo-overview.gif)
8
+
9
+ ## Instalation
10
+
11
+ ```sh
12
+ npm install awesome-timeline-react
13
+ ```
14
+
15
+ ## Ladle
16
+
17
+ To run ladle stories, type:
18
+
19
+ ```sh
20
+ npm run ladle
21
+ ```
22
+
23
+ The `TimelineStreaming10k` story demonstrates 10k events with 2,000 live updates per second.
24
+
25
+ ## Configuration
26
+
27
+ Import the `Timeline` component and css into your project.
28
+
29
+ ```tsx
30
+ import { Timeline } from "awesome-timeline-react";
31
+ import "awesome-timeline-react/dist/index.css";
32
+ ```
33
+
34
+ > **Important:** the timeline virtualizes vertically — render it inside a container with a bounded height (e.g. `height: 90vh`), otherwise the board cannot scroll.
35
+
36
+ The following properties for Timeline component are available:
37
+
38
+ - `rows` – an array of objects that define rows. The order within the array will be preserved in the Timeline.
39
+
40
+ - `events` – an array of objects that define events assigned to particular rows. Each object includes:
41
+
42
+ - `id`: `string`
43
+ - `rowId`: `string`
44
+ - `startTime`: `number` (timestamp in seconds)
45
+ - `endTime`: `number` (timestamp in seconds)
46
+ - `props`:
47
+ - `isLocked`: `boolean` (defines if event is locked, meaning it cannot be moved. Default is `false`)
48
+ - `label`: `string` (plain-text label drawn inside the event bar)
49
+ - `style`: `EventStyle` (per-event appearance: `fill`, `stroke`, `strokeWidth`, `textColor`, `font`, `borderRadius`, `opacity`)
50
+ - `drawEvent`: `DrawEventFn` (per-event custom canvas renderer, see below)
51
+ - `isResizable`: `boolean` (defines if event is resizable, overrides the default property `eventsResize`)
52
+ - `showPrompt`: `boolean` (defines if prompt will be shown after hover. Works only if `showEventPrompt` is set as true)
53
+ - `metadata`: `unknown` (some data that can be used by event prompt template)
54
+
55
+ - `staticEvents` – an array of objects that define static events for particular rows, meaning the events are not interactable by the user.
56
+
57
+ - `onDrop` – an external callback for the drop after dragging an event. The callback receives the following properties:
58
+
59
+ - `eventId`: `string`
60
+ - `oldRowId`: `string`
61
+ - `newRowId`: `string`
62
+ - `startTime`: `number` (timestamp in seconds)
63
+ - `endTime`: `number` (timestamp in seconds)
64
+
65
+ - `onResize` – an external callback after the resize event was done. The callback receives the following properties:
66
+
67
+ - `eventId`: `string`
68
+ - `startTime`: `number` (timestamp in seconds)
69
+ - `endTime`: `number` (timestamp in seconds)
70
+
71
+ - `onEventClick` – callback for a click on an event (`eventId`, `rowId`, `nativeEvent`, `modifiers`).
72
+
73
+ - `onEventHover` – callback when the hovered event changes (`eventId`/`rowId`, `null` on hover-out).
74
+
75
+ - `theme` – color/font tokens for everything drawn to canvas (see Theming).
76
+
77
+ - `drawEvent` – custom canvas renderer for all events (see Custom event rendering).
78
+
79
+ - `additionalClassNames` – only `rowsHeader` still applies; everything else is canvas-drawn, use `theme` instead.
80
+
81
+ - `showRTIndicator` – property that controls wheter Real Time Indicator will be show (default as true)
82
+
83
+ - `eventsResize` - property that define if events are resizeable (default as true)
84
+
85
+ - `showEventPrompt` - property that define if prompt for events will be shown after hover (defualt as true)
86
+
87
+ - `eventPromptTemplate` - function that can be passed for event prompt. Function receives currently hovered `event` object. It returns JSX Element so it can be customize in various ways. The example is in story. (The prompt is regular DOM — JSX still works here.)
88
+
89
+ - `panZoom` – interaction configuration:
90
+ - `panOnDragBackground` (default true) – drag the background to pan.
91
+ - `ctrlWheelZoom` (default true) – **Ctrl/Cmd + wheel** (and Mac trackpad pinch) zooms the visible time frame around the cursor.
92
+ - `pinchZoom` (default true) – two-finger pinch zooms the time frame on touch devices.
93
+ - `dragZoom` (default true) – **Ctrl/Cmd + drag** the background to zoom (right = in, left = out).
94
+ - `minWindowSeconds` / `maxWindowSeconds` – zoom limits (defaults 900s / 30 days).
95
+ - `zoomWheelFactor` (default 1.15) – span multiplier per wheel notch.
96
+ - `middleClickGranularity` (default true) – middle-click toggles **wheel = grid granularity** mode.
97
+ - `zoomStepSeconds` (default 900) – grid-granularity step.
98
+
99
+ > Time-frame zoom changes how much time is visible; grid granularity (`cellWidth`) changes how wide a grid cell is drawn. Since 0.2.x, Ctrl+wheel does time-frame zoom and grid granularity lives on middle-click+wheel.
100
+
101
+ - `timeBar` – configure the two-row time bar (see Time bar rows). Defaults to a day row over an hour row.
102
+
103
+ - `animations` – layout animations when events re-stack (rows growing, events changing lanes). `true` (default), `false` to disable, or `{ layoutMs?: number, fadeMs?: number }` to tune (defaults 200/120; `layoutMs` is the stacking tween, `fadeMs` the resize-handle fade). A dropped event always lands instantly — only the events re-stacking around it animate.
104
+
105
+ ## Theming
106
+
107
+ CSS classes cannot style canvas pixels, so canvas-drawn elements are themed with the `theme` prop. Defaults mirror the pre-0.2.0 stylesheet:
108
+
109
+ ```tsx
110
+ <Timeline
111
+ theme={{
112
+ eventFill: "#ffffff",
113
+ eventStroke: "#000000",
114
+ eventTextColor: "#000000",
115
+ staticEventFill: "#e0e0e0",
116
+ gridColor: "#e4dcdc",
117
+ timeBarBorder: "yellow",
118
+ timeBarTextColor: "white",
119
+ font: "12px Inter", // defaults to the canvas element's computed font
120
+ // bar geometry — themeable since 0.2.x (defaults shown)
121
+ barHeight: 20, // event bar height
122
+ laneGap: 2, // gap between stacked lanes (laneHeight = barHeight + laneGap)
123
+ rowPaddingY: 10, // vertical padding above/below bars in a row
124
+ barRadius: 5, // event bar corner radius
125
+ }}
126
+ ...
127
+ />
128
+ ```
129
+
130
+ Bar geometry tokens drive row heights, lane stacking, hit-testing, and the drag
131
+ ghost together — changing `barHeight`/`laneGap` restacks and re-measures rows
132
+ automatically. (Per-event `style.borderRadius` still overrides `barRadius`.)
133
+
134
+ ## Time bar rows
135
+
136
+ The time bar has two rows. By default the top row shows calendar days and the
137
+ bottom row shows hours, but each row's unit and label are configurable via
138
+ `timeBar`:
139
+
140
+ ```tsx
141
+ <Timeline
142
+ timeBar={{
143
+ topRow: { unit: "day" }, // "hour" | "day" | "week" | "month"
144
+ bottomRow: {
145
+ unit: { stepSeconds: 8 * 3600 }, // or a fixed step in seconds
146
+ format: (start, end) => `Shift ${Math.floor(start.getHours() / 8) + 1}`,
147
+ },
148
+ }}
149
+ ...
150
+ />
151
+ ```
152
+
153
+ - `unit` – `"hour" | "day" | "week" | "month"`, or `{ stepSeconds }` for fixed
154
+ steps (weeks start on Monday; custom steps anchor to local midnight).
155
+ - `format(blockStart, blockEnd)` – optional label override; defaults mirror the
156
+ built-in `Mon 1 Jan` (day) and `HH:00` (hour) labels.
157
+
158
+ The time bar is purely presentational: it never changes the visible time range
159
+ or the grid. Vertical grid lines and drop snapping stay on the grid cell
160
+ (`cellWidth`), independent of the time-bar rows — so e.g. an 8-hour bottom row
161
+ can sit over an hourly grid.
162
+
163
+ ## Custom event rendering (`drawEvent`)
164
+
165
+ For visuals beyond `label` + `style`, draw the event yourself. Resolution order: per-event `props.drawEvent` → Timeline-level `drawEvent` → built-in default. Return `false` to fall through to the default.
166
+
167
+ ```tsx
168
+ const drawEvent: DrawEventFn = (ctx, event, rect, state, theme) => {
169
+ if (!event.props?.metadata) return false; // default drawing
170
+ ctx.fillStyle = state.hovered ? "#ffe8a3" : "#a3d5ff";
171
+ ctx.fillRect(rect.x, rect.y, rect.width, rect.height);
172
+ ctx.fillStyle = theme.eventTextColor;
173
+ ctx.fillText(event.props.label ?? "", rect.x + 4, rect.y + rect.height / 2);
174
+ };
175
+ ```
176
+
177
+ `state` carries `{ hovered, dragging, resizing, selected }`.
178
+
179
+ ## Streaming / imperative updates
180
+
181
+ For live boards, diffing a 10k-element `events` prop per tick is wasteful. Use the imperative handle — patches go straight to the internal store and coalesce into a single redraw per animation frame, with zero React re-renders on the hot path:
182
+
183
+ ```tsx
184
+ const ref = useRef<TimelineHandle>(null);
185
+
186
+ <Timeline ref={ref} rows={rows} events={initialEvents} ... />;
187
+
188
+ // e.g. from a websocket:
189
+ ref.current?.updateEvents([
190
+ { op: "update", id: "42", changes: { startTime, endTime } },
191
+ { op: "upsert", event: newEvent },
192
+ { op: "remove", id: "17" },
193
+ ]);
194
+ ```
195
+
196
+ The full handle: `setEvents`, `updateEvents`, `getEvent`, `scrollToRow`, `scrollToTime`, `setWindow`, `getVisibleRange`, `redraw`.
197
+
198
+ **Reconciliation rule:** the `events` prop is authoritative whenever its reference changes — a new array fully resets the store and discards imperative state. Pick one mode: declarative (swap the prop) or imperative (stable prop + handle calls).
199
+
200
+ ## Awesome Features
201
+
202
+ Adjusting the granulation of the grid: click the wheel on the mouse. This will hide the scroll bar, and you can adjust the grid granulation by scrolling the wheel. Each scroll iteration adjusts the grid by ±15 minutes, depending on the scroll direction. Since 0.2.0, `ctrl`/`cmd` + wheel does the same without the mode toggle.
203
+
204
+ ![](https://raw.githubusercontent.com/Plageros/awesome-timeline-react/master/public/gifs/demo-grid-granulation.gif)
205
+
206
+ Panning is smooth since 0.2.0: drag the background to move the time window with sub-hour precision (no more snapping to full hours).
207
+
208
+ ## Migration 0.1.x → 0.2.0
209
+
210
+ 0.2.0 replaces DOM rendering with a canvas engine. Breaking changes:
211
+
212
+ | 0.1.x | 0.2.0 |
213
+ | --- | --- |
214
+ | `props.content: JSX.Element \| string` | `props.label: string` for text, or `drawEvent` for rich visuals |
215
+ | `props.classNames: string[]` | `props.style: EventStyle` |
216
+ | `additionalClassNames.timeBar/dayRow/hourRow/gridLine` | `theme.timeBar*/gridColor` |
217
+ | CSS overrides via imported stylesheet | `theme` object (only rows header + prompt remain CSS-styleable) |
218
+ | `TimelineType` | renamed `TimelineProps` (deprecated alias kept) |
219
+ | unbounded height grew the page | bounded-height container required (virtualized scrolling) |
220
+ | `onDrop` / `onResize` / `metadata` / `eventPromptTemplate` | unchanged |
221
+
222
+ New in 0.2.0: `ref` (`TimelineHandle`), `theme`, `drawEvent`, `onEventClick`, `onEventHover`, `panZoom`.
223
+
224
+ New in 0.3.0:
225
+ - Themeable bar geometry — `theme.barHeight` / `laneGap` / `rowPaddingY` / `barRadius`.
226
+ - Configurable time-bar rows — `timeBar.topRow` / `bottomRow` (`unit` + `format`), units `hour`/`day`/`week`/`month` or `{ stepSeconds }`.
227
+ - Time-frame zoom — Ctrl/Cmd + wheel (and trackpad/touch pinch) and Ctrl + drag; grid granularity moved to middle-click + wheel. New `panZoom` keys: `pinchZoom`, `dragZoom`, `minWindowSeconds`, `maxWindowSeconds`, `zoomWheelFactor`.
228
+ - Fixes: time-bar hour labels follow panning on sub-day windows; grid lines stay aligned to the time-bar blocks while panning and zooming; the drag ghost inherits the dragged event's style; corrected weekday names.
229
+
230
+ ## Roadmap
231
+
232
+ Here, we will store major features planned for future releases (from highest to lowest priority):
233
+
234
+ 1. ~~Resize events~~ - published in 0.1.8 version
235
+ 2. ~~Real time line~~ - published in 0.1.7 version
236
+ 3. ~~Customizable prompts after hovering over an event~~ - published in 0.1.14 version
237
+ 4. ~~Canvas rendering engine, virtualization, streaming API~~ - published in 0.2.0 version
238
+ 5. ~~Customizable second row of the time bar~~ - `timeBar.topRow/bottomRow` (unit + format)
239
+ 6. ~~Themeable bar geometry (heights, lane spacing, radius)~~ - `theme.barHeight/laneGap/rowPaddingY/barRadius`
240
+ 7. Multi-select and rubber-band selection