-
Notifications
You must be signed in to change notification settings - Fork 146
Expand file tree
/
Copy pathtimeline-graph.svelte
More file actions
134 lines (123 loc) · 4.41 KB
/
timeline-graph.svelte
File metadata and controls
134 lines (123 loc) · 4.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
<script lang="ts">
import { timestamp } from '$lib/components/timestamp.svelte';
import type { EventGroups } from '$lib/models/event-groups/event-groups';
import { activeGroupHeight, activeGroups } from '$lib/stores/active-events';
import { fullEventHistory } from '$lib/stores/events';
import { eventStatusFilter } from '$lib/stores/filters';
import type { WorkflowExecution } from '$lib/types/workflows';
import { isWorkflowDelayed } from '$lib/utilities/delayed-workflows';
import { getFailedOrPendingGroups } from '$lib/utilities/get-failed-or-pending';
import { TimelineConfig } from '../constants';
import EndTimeInterval from '../end-time-interval.svelte';
import GroupDetailsRow from './group-details-row.svelte';
import Line from './line.svelte';
import TimelineAxis from './timeline-axis.svelte';
import TimelineGraphRow from './timeline-graph-row.svelte';
import WorkflowRow from './workflow-row.svelte';
export let x = 0;
export let y = 0;
export let workflow: WorkflowExecution;
export let groups: EventGroups;
export let viewportHeight: number | undefined;
export let readOnly = false;
export let error: boolean = false;
const { height, gutter, radius } = TimelineConfig;
let canvasWidth = 0;
let scrollY = 0;
$: expandedGroupHeight = readOnly ? 0 : $activeGroupHeight;
$: filteredGroups = getFailedOrPendingGroups(groups, $eventStatusFilter);
$: firstStartTime =
$fullEventHistory[0]?.eventTime < workflow.executionTime
? $fullEventHistory[0]?.eventTime
: workflow.executionTime;
$: startTime =
(!isWorkflowDelayed(workflow) && firstStartTime) || workflow.startTime;
$: timelineHeight =
Math.max(height * (filteredGroups.length + 2), 120) + expandedGroupHeight;
$: canvasHeight = timelineHeight + 120;
const handleScroll = (e) => {
scrollY = e?.target?.scrollTop;
};
$: groupIndexMap = new Map(filteredGroups.map((g, i) => [g.id, i]));
$: activeGroupsHeightAboveGroup = (groupIndex: number) => {
const hasActiveAbove = $activeGroups?.some((id) => {
const activeIndex = groupIndexMap.get(id);
return activeIndex !== undefined && activeIndex < groupIndex;
});
return hasActiveAbove ? expandedGroupHeight : 0;
};
</script>
<div
id="event-history-timeline-graph"
class="relative h-auto overflow-auto border border-t-0 border-subtle bg-primary [scrollbar-gutter:stable]"
bind:clientWidth={canvasWidth}
style={viewportHeight ? `max-height: ${viewportHeight}px;` : ''}
on:scroll={handleScroll}
>
<EndTimeInterval {workflow} {startTime} let:endTime let:duration>
<div
class="pointer-events-none sticky top-[120px]"
class:invisible={!!$activeGroups.length}
>
<div class="flex w-full justify-between text-xs">
<p class="w-60 -translate-x-24 rotate-90">
{$timestamp(startTime, { format: 'short' })}
</p>
<p class="w-60 translate-x-24 rotate-90">
{$timestamp(endTime, { format: 'short' })}
</p>
</div>
</div>
<svg
{x}
{y}
viewBox="0 0 {canvasWidth} {canvasHeight}"
height={canvasHeight}
width={canvasWidth}
class="-mt-4"
class:error
>
<Line
startPoint={[gutter, 0]}
endPoint={[gutter, timelineHeight]}
strokeWidth={radius / 2}
/>
<Line
startPoint={[canvasWidth - gutter, 0]}
endPoint={[canvasWidth - gutter, timelineHeight]}
strokeWidth={radius / 2}
/>
<TimelineAxis
x1={gutter - radius / 4}
x2={canvasWidth - gutter + radius / 4}
{timelineHeight}
{startTime}
{duration}
/>
<WorkflowRow {workflow} y={height} length={canvasWidth} />
{#each filteredGroups as group, index (group.id)}
{@const y = (index + 2) * height + activeGroupsHeightAboveGroup(index)}
{#if !viewportHeight || (y > scrollY - 2 * height && y < scrollY + viewportHeight * height)}
{#key group.eventList.length}
<TimelineGraphRow
{y}
{group}
{canvasWidth}
{startTime}
{endTime}
{readOnly}
/>
{/key}
{/if}
{#if !readOnly && $activeGroups.includes(group.id)}
<GroupDetailsRow y={y + 1.33 * radius} {group} {canvasWidth} />
{/if}
{/each}
</svg>
</EndTimeInterval>
</div>
<style lang="postcss">
.error {
@apply bg-danger;
}
</style>