Skip to content

Commit 1b50ddc

Browse files
committed
Dev | Examples | Timeline: Add timeline arrows example
Introduce a new timeline arrows example in the xy-components library that demonstrates arrow configuration between timeline rows.
1 parent e469c69 commit 1b50ddc

File tree

2 files changed

+75
-0
lines changed

2 files changed

+75
-0
lines changed
Lines changed: 3 additions & 0 deletions
Loading
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
import React, { useMemo } from 'react'
2+
import { VisXYContainer, VisTimeline, VisAxis } from '@unovis/react'
3+
4+
import { ExampleViewerDurationProps } from '@src/components/ExampleViewer/index'
5+
import { Arrangement, TextAlign, TimelineArrow } from '@unovis/ts'
6+
7+
// Icons
8+
import icon from './icon.svg?raw'
9+
10+
export const title = 'Timeline Arrows'
11+
export const subTitle = 'Between the lines'
12+
13+
export const component = (props: ExampleViewerDurationProps): JSX.Element => {
14+
const lineIconSize = 25
15+
const data = Array(10).fill(0).map((_, i) => ({
16+
timestamp: Date.now() + i * 1000 * 60 * 60 * 24,
17+
length: 1000 * 60 * 60 * 24,
18+
id: i.toString(),
19+
type: `Row ${i}`,
20+
lineWidth: 5 + Math.random() * 15,
21+
}))
22+
23+
type Datum = typeof data[number]
24+
25+
const arrows = data.map((d, i) => {
26+
if (i === data.length - 1) return undefined
27+
28+
return {
29+
x: d.timestamp + d.length,
30+
lineSourceId: d.id,
31+
lineTargetId: data[i + 1].id,
32+
xOffsetPx: lineIconSize / 2,
33+
lineSourceMarginPx: (lineIconSize - d.lineWidth) / 2,
34+
lineTargetMarginPx: 4,
35+
}
36+
}).filter(Boolean) as TimelineArrow[]
37+
38+
const svgDefs = useMemo(() => `${icon}`, [])
39+
return (<>
40+
<VisXYContainer<Datum>
41+
data={data}
42+
height={300}
43+
svgDefs={svgDefs}
44+
>
45+
<VisTimeline
46+
id={(d) => d.id}
47+
lineRow={(d: Datum) => d.type as string}
48+
x={(d: Datum) => d.timestamp}
49+
rowHeight={40}
50+
lineWidth={(d) => d.lineWidth}
51+
lineCap
52+
showEmptySegments
53+
showRowLabels
54+
rowLabelTextAlign={TextAlign.Left}
55+
duration={props.duration}
56+
lineEndIcon={'#circle_check_filled'}
57+
lineEndIconSize={lineIconSize}
58+
lineStartIconColor={'#fff'}
59+
lineEndIconColor={'rgb(38, 86, 201)'}
60+
lineEndIconArrangement={Arrangement.Outside}
61+
arrows={arrows}
62+
/>
63+
<VisAxis
64+
type='x'
65+
numTicks={3}
66+
tickFormat={(x: number) => new Date(x).toDateString()}
67+
duration={props.duration}
68+
/>
69+
</VisXYContainer>
70+
</>
71+
)
72+
}

0 commit comments

Comments
 (0)