forked from MrBlenny/react-flow-chart
-
Notifications
You must be signed in to change notification settings - Fork 0
/
StressTest.tsx
108 lines (99 loc) · 2.5 KB
/
StressTest.tsx
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
import { compact, flatMap, flatten, keyBy, range } from 'lodash'
import * as React from 'react'
import styled from 'styled-components'
import { FlowChartWithState } from '../src'
import { Page } from './components'
const getChart = (rows: number, cols: number) => {
const xyGrid = flatten(range(0, cols * 300, 300).map((x) => range(0, rows * 150, 150).map((y) => ({ x, y }))))
return {
offset: {
x: 0,
y: 0,
},
scale: 1,
nodes: keyBy(xyGrid.map(({ x, y }) => ({
id: `node-${x}-${y}`,
type: 'default',
position: { x: x + 100, y: y + 100 },
ports: {
port1: {
id: 'port1',
type: 'top',
},
port2: {
id: 'port2',
type: 'bottom',
},
port3: {
id: 'port3',
type: 'right',
},
port4: {
id: 'port4',
type: 'left',
},
},
})), 'id'),
links: keyBy(compact(flatMap(xyGrid, ({ x, y }, idx) => {
const next = xyGrid[idx + 1]
if (next) {
return [{
id: `link-${x}-${y}-a`,
from: {
nodeId: `node-${x}-${y}`,
portId: 'port2',
},
to: {
nodeId: `node-${next.x}-${next.y}`,
portId: 'port3',
},
}, {
id: `link-${x}-${y}-b`,
from: {
nodeId: `node-${x}-${y}`,
portId: 'port2',
},
to: {
nodeId: `node-${next.x}-${next.y}`,
portId: 'port4',
},
}]
}
return undefined
})), 'id') as any,
selected: {},
hovered: {},
}
}
const StressTestWithState = () => {
const [rows, setRows] = React.useState(100)
const [cols, setCols] = React.useState(100)
const chart = React.useMemo(() => getChart(rows, cols), [rows, cols])
return (
<>
<Controls>
<Label>Columns:</Label>
<Input type="number" value={cols} onChange={(e) => setCols(parseInt(e.target.value, 10))} />
<Label>Rows:</Label>
<Input type="number" value={rows} onChange={(e) => setRows(parseInt(e.target.value, 10))} />
</Controls>
<Page>
<FlowChartWithState key={`${cols}:${rows}`} initialValue={chart} />
</Page>
</>
)
}
export const StressTestDemo = () => {
return <StressTestWithState />
}
const Input = styled.input`
padding: 5px 5px 5px 10px;
width: 50px;
`
const Label = styled.label`
padding: 0 10px;
font-size: 14px;
`
const Controls = styled.div`
padding: 10px;
`