@granite-elements/granite-timeline 2.0.0 → 3.0.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/CHANGELOG.md +58 -0
- package/README.md +150 -53
- package/granite-timeline.js +252 -706
- package/package.json +36 -19
- package/src/timeline-renderer.js +391 -0
- package/.eslintrc.json +0 -28
- package/demo/index.html +0 -50
- package/example.html +0 -367
- package/index.html +0 -16
- package/polymer.json +0 -7
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to this project will be documented in this file.
|
|
4
|
+
|
|
5
|
+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
|
|
6
|
+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
|
+
|
|
8
|
+
## [3.0.0] - 2026-06-06
|
|
9
|
+
|
|
10
|
+
Full rewrite. See the [migration guide](README.md#migration-from-v2) in the README.
|
|
11
|
+
|
|
12
|
+
### Changed
|
|
13
|
+
|
|
14
|
+
- **Lit 3** replaces Polymer 3.
|
|
15
|
+
- **Native d3 v7 rendering** (`src/timeline-renderer.js`, a pure module usable
|
|
16
|
+
without the element) replaces the abandoned `d3-timelines` plugin.
|
|
17
|
+
- d3 is now a regular ES-module dependency: no more runtime script loading via
|
|
18
|
+
`granite-js-dependencies-grabber`, no more webcomponentsjs polyfills.
|
|
19
|
+
- Responsive redraw via `ResizeObserver` (v2 read the width once at startup).
|
|
20
|
+
- `tickFormat` is a single value — a d3 time-format specifier string (usable as
|
|
21
|
+
an HTML attribute) or a `(date) => string` function — instead of the v2 object.
|
|
22
|
+
- `tickTime` takes a modern d3-time interval (`import { timeHour } from 'd3-time'`)
|
|
23
|
+
instead of the old `d3.time.*`.
|
|
24
|
+
- Default color palette changed from `d3.scale.category20()` (removed in d3 v7)
|
|
25
|
+
to `scaleOrdinal(schemeCategory10)`.
|
|
26
|
+
- Wheel zooming (with `axisZoom`) now requires Ctrl/⌘ so the chart doesn't
|
|
27
|
+
hijack page scrolling; trackpad pinch works without modifier.
|
|
28
|
+
- The chart renders in shadow DOM: page CSS no longer styles the internals.
|
|
29
|
+
Use the CSS custom properties (`--granite-timeline-label-color`,
|
|
30
|
+
`--granite-timeline-axis-color`) or `::part(timeline)`.
|
|
31
|
+
|
|
32
|
+
### Added
|
|
33
|
+
|
|
34
|
+
- `zoom` event reporting the visible domain: `detail: {start, end, transform}`.
|
|
35
|
+
- `resetZoom()` method restoring the full-domain view.
|
|
36
|
+
- Zoom/pan transform persists across redraws (resize, data updates).
|
|
37
|
+
- Bars, bar labels and the today line are clipped to the plot area when zooming.
|
|
38
|
+
|
|
39
|
+
### Removed
|
|
40
|
+
|
|
41
|
+
- `displayCircles`, `relativeTime`, `showBorderLine` (+ `borderLine*` format
|
|
42
|
+
properties), `showTimeAxisTick` (+ `timeAxisTick*`), `xAxisClass`.
|
|
43
|
+
- `scroll` event, and the redundant `i` field of event details (use `index`).
|
|
44
|
+
- Bower support and the Polymer toolchain (`polymer.json`).
|
|
45
|
+
|
|
46
|
+
## [2.0.0] - 2018-06-04
|
|
47
|
+
|
|
48
|
+
### Changed
|
|
49
|
+
|
|
50
|
+
- Migrated to npm-based Polymer 3 (ES modules instead of HTML imports).
|
|
51
|
+
|
|
52
|
+
## 1.0.x - 2017-2018
|
|
53
|
+
|
|
54
|
+
- Initial Polymer 1.x/2.x element wrapping the d3-timelines plugin,
|
|
55
|
+
distributed via Bower.
|
|
56
|
+
|
|
57
|
+
[3.0.0]: https://github.com/LostInBrittany/granite-timeline/compare/2.0.0...3.0.0
|
|
58
|
+
[2.0.0]: https://github.com/LostInBrittany/granite-timeline/compare/1.0.9...2.0.0
|
package/README.md
CHANGED
|
@@ -2,74 +2,171 @@
|
|
|
2
2
|
|
|
3
3
|
# granite-timeline
|
|
4
4
|
|
|
5
|
-
A timeline rendering
|
|
5
|
+
A timeline rendering web component built with [Lit](https://lit.dev) and [d3](https://d3js.org) v7.
|
|
6
6
|
|
|
7
|
-
>
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
## Doc & demo
|
|
12
|
-
|
|
13
|
-
[https://lostinbrittany.github.io/granite-timeline](https://lostinbrittany.github.io/granite-timeline)
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
## Usage
|
|
17
|
-
|
|
18
|
-
<!---
|
|
19
|
-
```
|
|
20
|
-
<custom-element-demo>
|
|
21
|
-
<template>
|
|
22
|
-
<script src="../webcomponentsjs/webcomponents-lite.js"></script>
|
|
23
|
-
<link rel="import" href="granite-timeline.html">
|
|
24
|
-
<next-code-block></next-code-block>
|
|
25
|
-
</template>
|
|
26
|
-
</custom-element-demo>
|
|
27
|
-
```
|
|
28
|
-
-->
|
|
29
|
-
```html
|
|
30
|
-
<granite-timeline
|
|
31
|
-
data='[{"times":[{"starting_time":1355752800000,"ending_time":1355759900000}, {"starting_time":1355767900000,"ending_time":1355774400000}]},{"times":[{"starting_time":1355759910000,"ending_time":1355761900000}]},{"times":[{"starting_time":1355761910000,"ending_time":1355763910000}]}]'
|
|
32
|
-
debug></granite-timeline>
|
|
33
|
-
```
|
|
7
|
+
> **v3.0.0** is a full rewrite: Lit instead of Polymer, native d3 v7 rendering instead of the
|
|
8
|
+
> abandoned `d3-timelines` plugin, plain ES modules, no polyfills, no runtime script loading.
|
|
9
|
+
> See [Migration from v2](#migration-from-v2).
|
|
34
10
|
|
|
35
11
|
## Install
|
|
36
12
|
|
|
37
|
-
Install the component using [Bower](http://bower.io/):
|
|
38
|
-
|
|
39
13
|
```sh
|
|
40
|
-
|
|
14
|
+
npm install @granite-elements/granite-timeline
|
|
41
15
|
```
|
|
42
16
|
|
|
43
|
-
Or [download as ZIP](https://github.com/LostInBrittany/granite-timeline/archive/gh-pages.zip).
|
|
44
|
-
|
|
45
17
|
## Usage
|
|
46
18
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
<script src="bower_components/webcomponentsjs/webcomponents.min.js"></script>
|
|
51
|
-
```
|
|
19
|
+
```js
|
|
20
|
+
import '@granite-elements/granite-timeline';
|
|
21
|
+
```
|
|
52
22
|
|
|
53
|
-
|
|
23
|
+
```html
|
|
24
|
+
<granite-timeline
|
|
25
|
+
data='[{"times":[{"starting_time":1355752800000,"ending_time":1355759900000}, {"starting_time":1355767900000,"ending_time":1355774400000}]},{"times":[{"starting_time":1355759910000,"ending_time":1355761900000}]}]'
|
|
26
|
+
show-time-axis></granite-timeline>
|
|
27
|
+
```
|
|
54
28
|
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
29
|
+
Function- and object-valued options are set as properties:
|
|
30
|
+
|
|
31
|
+
```js
|
|
32
|
+
import { scaleOrdinal } from 'd3-scale';
|
|
33
|
+
import { timeHour } from 'd3-time';
|
|
34
|
+
|
|
35
|
+
const el = document.querySelector('granite-timeline');
|
|
36
|
+
el.data = [
|
|
37
|
+
{ label: 'fruit 1', fruit: 'orange', times: [
|
|
38
|
+
{ starting_time: 1355759910000, ending_time: 1355761900000 }] },
|
|
39
|
+
{ label: 'fruit 2', fruit: 'apple', times: [
|
|
40
|
+
{ starting_time: 1355752800000, ending_time: 1355759900000 }] },
|
|
41
|
+
];
|
|
42
|
+
el.colors = scaleOrdinal().domain(['apple', 'orange']).range(['#6b0000', '#ef9b0f']);
|
|
43
|
+
el.colorsProperty = 'fruit';
|
|
44
|
+
el.tickTime = timeHour;
|
|
45
|
+
```
|
|
58
46
|
|
|
59
|
-
|
|
47
|
+
## Data format
|
|
48
|
+
|
|
49
|
+
```js
|
|
50
|
+
[
|
|
51
|
+
{
|
|
52
|
+
label: 'series label', // optional, shown on the left when `stack` is set
|
|
53
|
+
times: [
|
|
54
|
+
{
|
|
55
|
+
starting_time: 1355752800000, // ms epoch
|
|
56
|
+
ending_time: 1355759900000, // ms epoch
|
|
57
|
+
label: 'bar label', // optional
|
|
58
|
+
color: '#6b0000', // optional, overrides the color scale
|
|
59
|
+
},
|
|
60
|
+
],
|
|
61
|
+
},
|
|
62
|
+
]
|
|
63
|
+
```
|
|
60
64
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
65
|
+
## Properties
|
|
66
|
+
|
|
67
|
+
| Property | Attribute | Type | Default | Description |
|
|
68
|
+
|---|---|---|---|---|
|
|
69
|
+
| `data` | `data` | Array | `[]` | The timeline data (see above) |
|
|
70
|
+
| `width` | `width` | Number | element width | Width of the timeline in pixels |
|
|
71
|
+
| `height` | `height` | Number | computed | Height of the timeline in pixels |
|
|
72
|
+
| `itemHeight` | `item-height` | Number | `20` | Height of a data series row |
|
|
73
|
+
| `itemMargin` | `item-margin` | Number | `5` | Margin between data series rows |
|
|
74
|
+
| `marginTop` | `margin-top` | Number | `30` | Top margin |
|
|
75
|
+
| `marginBottom` | `margin-bottom` | Number | `30` | Bottom margin |
|
|
76
|
+
| `marginLeft` | `margin-left` | Number | `30` | Left margin |
|
|
77
|
+
| `marginRight` | `margin-right` | Number | `30` | Right margin |
|
|
78
|
+
| `tickFormat` | `tick-format` | String\|Function | `'%I %p'` | d3 time-format specifier, or a `(date) => string` function (property only) |
|
|
79
|
+
| `tickTime` | — | d3-time interval | — | Tick time unit, e.g. `timeHour` from `d3-time` |
|
|
80
|
+
| `tickInterval` | `tick-interval` | Number | `1` | Tick interval, used with `tickTime` |
|
|
81
|
+
| `numTicks` | `num-ticks` | Number | — | Number of ticks, used when `tickTime` is unset |
|
|
82
|
+
| `tickSize` | `tick-size` | Number | `6` | Tick size in pixels |
|
|
83
|
+
| `tickValues` | — | Array | — | Explicit tick values (Date or ms epoch) |
|
|
84
|
+
| `rotateTicks` | `rotate-ticks` | Number | `0` | Rotation of the tick labels in degrees |
|
|
85
|
+
| `axisTop` | `axis-top` | Boolean | `false` | Places the time axis on top |
|
|
86
|
+
| `axisZoom` | `axis-zoom` | Boolean | `false` | Enables zooming (Ctrl/⌘ + wheel, pinch, double-click) and panning (drag) of the time axis |
|
|
87
|
+
| `colors` | — | d3 ordinal scale | `scaleOrdinal(schemeCategory10)` | Color scale for the series |
|
|
88
|
+
| `colorsProperty` | `colors-property` | String | — | Data property mapped to the `colors` scale |
|
|
89
|
+
| `beginning` | `beginning` | Date\|Number\|String | computed | Start of the timeline |
|
|
90
|
+
| `ending` | `ending` | Date\|Number\|String | computed | End of the timeline |
|
|
91
|
+
| `stack` | `stack` | Boolean | `false` | Stacks each data series on its own row |
|
|
92
|
+
| `showToday` | `show-today` | Boolean | `false` | Shows a vertical line at the current time |
|
|
93
|
+
| `todayMarginTop` | `today-margin-top` | Number | `25` | Top margin of the today line |
|
|
94
|
+
| `todayMarginBottom` | `today-margin-bottom` | Number | `0` | Bottom margin of the today line |
|
|
95
|
+
| `todayWidth` | `today-width` | Number | `2` | Stroke width of the today line |
|
|
96
|
+
| `todayColor` | `today-color` | String | `rgb(245, 157, 0)` | Color of the today line |
|
|
97
|
+
| `showTimeAxis` | `show-time-axis` | Boolean | `false` | Shows the time axis |
|
|
98
|
+
| `background` | `background` | String | — | Background color of the rows |
|
|
99
|
+
| `rowSeparators` | `row-separators` | String | — | Color of the separator lines between rows |
|
|
100
|
+
| `labelFormat` | — | Function | — | Maps a raw `label` value to its display text |
|
|
101
|
+
| `debug` | `debug` | Boolean | `false` | Logs debug information to the console |
|
|
102
|
+
|
|
103
|
+
Color resolution order for each bar: `time.color` → `colors(time[colorsProperty])` →
|
|
104
|
+
`colors(series[colorsProperty])` → `colors(seriesIndex)`.
|
|
105
|
+
|
|
106
|
+
## Events
|
|
107
|
+
|
|
108
|
+
All events are `CustomEvent`s dispatched from the element, with
|
|
109
|
+
`detail: { d, index, datum, mouse, evt }` where `d` is the time entry, `index` its index
|
|
110
|
+
in the series, `datum` the series object, `mouse` the `[x, y]` pointer position in the
|
|
111
|
+
SVG, and `evt` the originating DOM event.
|
|
112
|
+
|
|
113
|
+
| Event | Fired on |
|
|
114
|
+
|---|---|
|
|
115
|
+
| `click` | Click on a timeline bar |
|
|
116
|
+
| `mouseover` | Pointer enters a bar |
|
|
117
|
+
| `mouseout` | Pointer leaves a bar |
|
|
118
|
+
| `hover` | Pointer moves over a bar |
|
|
119
|
+
|
|
120
|
+
Note: a `click` listener also receives native click events from the element; check
|
|
121
|
+
`event.detail?.d` to distinguish bar clicks.
|
|
122
|
+
|
|
123
|
+
When `axisZoom` is enabled, a `zoom` event is fired on every zoom/pan, with
|
|
124
|
+
`detail: { start, end, transform }` where `start`/`end` are the `Date` bounds of the
|
|
125
|
+
visible domain and `transform` the d3 zoom transform.
|
|
126
|
+
|
|
127
|
+
## Methods
|
|
128
|
+
|
|
129
|
+
| Method | Description |
|
|
130
|
+
|---|---|
|
|
131
|
+
| `resetZoom()` | Resets the axis zoom/pan to the initial full-domain view |
|
|
132
|
+
|
|
133
|
+
## Styling
|
|
134
|
+
|
|
135
|
+
The chart renders in shadow DOM. Customization hooks:
|
|
136
|
+
|
|
137
|
+
| Hook | Description |
|
|
138
|
+
|---|---|
|
|
139
|
+
| `--granite-timeline-label-color` | Color of the series and bar labels |
|
|
140
|
+
| `--granite-timeline-axis-color` | Color of the time axis |
|
|
141
|
+
| `::part(timeline)` | The chart container |
|
|
142
|
+
|
|
143
|
+
## Demo
|
|
64
144
|
|
|
65
|
-
|
|
145
|
+
```sh
|
|
146
|
+
npm install
|
|
147
|
+
npm run dev # open http://localhost:5173/demo/
|
|
148
|
+
```
|
|
66
149
|
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
150
|
+
## Migration from v2
|
|
151
|
+
|
|
152
|
+
- **No more script loading**: d3 is now a regular ES-module dependency. Remove any
|
|
153
|
+
`granite-js-dependencies-grabber` setup; `bower` and the webcomponentsjs polyfills are gone.
|
|
154
|
+
- **Dropped properties**: `displayCircles`, `relativeTime`, `showBorderLine` (+ its
|
|
155
|
+
`borderLine*` format properties), `showTimeAxisTick` (+ `timeAxisTick*`),
|
|
156
|
+
`xAxisClass`. Open an issue if you need one of them back.
|
|
157
|
+
- **`axisZoom`** is kept, but zooming with the mouse wheel now requires
|
|
158
|
+
<kbd>Ctrl</kbd>/<kbd>⌘</kbd> so the chart doesn't hijack page scrolling; drag pans,
|
|
159
|
+
and a `zoom` event reports the visible domain.
|
|
160
|
+
- **Dropped events**: `scroll`. The `i` field of event details is gone — use `index`.
|
|
161
|
+
- **Tick intervals**: `tickTime` now takes a modern d3-time interval
|
|
162
|
+
(`import { timeHour } from 'd3-time'`) instead of the old `d3.time.hours`.
|
|
163
|
+
- **`tickFormat`** is now a single value (string specifier or function) instead of the
|
|
164
|
+
v2 object — the other tick options moved to top-level properties (unchanged names).
|
|
165
|
+
- **Default palette** changed from `d3.scale.category20()` (removed in d3 v7) to
|
|
166
|
+
`scaleOrdinal(schemeCategory10)`.
|
|
167
|
+
- **Shadow DOM styling**: page CSS no longer reaches the chart internals. Use the CSS
|
|
168
|
+
custom properties / `part` listed above.
|
|
72
169
|
|
|
73
170
|
## License
|
|
74
171
|
|
|
75
|
-
[MIT License](http://opensource.org/licenses/MIT)
|
|
172
|
+
[MIT License](http://opensource.org/licenses/MIT)
|