forked from jlfwong/speedscope
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsandwich-view.tsx
149 lines (137 loc) · 4.42 KB
/
sandwich-view.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
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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
import {Frame} from '../lib/profile'
import {StyleSheet, css} from 'aphrodite'
import {ProfileTableViewContainer} from './profile-table-view'
import {h} from 'preact'
import {commonStyle, Sizes, Colors, FontSize} from './style'
import {actions} from '../store/actions'
import {createContainer, Dispatch, StatelessComponent} from '../lib/typed-redux'
import {ApplicationState} from '../store'
import {InvertedCallerFlamegraphView} from './inverted-caller-flamegraph-view'
import {CalleeFlamegraphView} from './callee-flamegraph-view'
import {ActiveProfileState} from './application'
interface SandwichViewProps {
selectedFrame: Frame | null
profileIndex: number
activeProfileState: ActiveProfileState
setSelectedFrame: (selectedFrame: Frame | null) => void
glCanvas: HTMLCanvasElement
}
class SandwichView extends StatelessComponent<SandwichViewProps> {
private setSelectedFrame = (selectedFrame: Frame | null) => {
this.props.setSelectedFrame(selectedFrame)
}
onWindowKeyPress = (ev: KeyboardEvent) => {
if (ev.key === 'Escape') {
this.setSelectedFrame(null)
}
}
componentDidMount() {
window.addEventListener('keydown', this.onWindowKeyPress)
}
componentWillUnmount() {
window.removeEventListener('keydown', this.onWindowKeyPress)
}
render() {
const {selectedFrame} = this.props
let flamegraphViews: JSX.Element | null = null
if (selectedFrame) {
flamegraphViews = (
<div className={css(commonStyle.fillY, style.callersAndCallees, commonStyle.vbox)}>
<div className={css(commonStyle.hbox, style.panZoomViewWraper)}>
<div className={css(style.flamechartLabelParent)}>
<div className={css(style.flamechartLabel)}>Callers</div>
</div>
<InvertedCallerFlamegraphView
glCanvas={this.props.glCanvas}
activeProfileState={this.props.activeProfileState}
/>
</div>
<div className={css(style.divider)} />
<div className={css(commonStyle.hbox, style.panZoomViewWraper)}>
<div className={css(style.flamechartLabelParent, style.flamechartLabelParentBottom)}>
<div className={css(style.flamechartLabel, style.flamechartLabelBottom)}>Callees</div>
</div>
<CalleeFlamegraphView
glCanvas={this.props.glCanvas}
activeProfileState={this.props.activeProfileState}
/>
</div>
</div>
)
}
return (
<div className={css(commonStyle.hbox, commonStyle.fillY)}>
<div className={css(style.tableView)}>
<ProfileTableViewContainer activeProfileState={this.props.activeProfileState} />
</div>
{flamegraphViews}
</div>
)
}
}
const style = StyleSheet.create({
tableView: {
flex: 1,
},
panZoomViewWraper: {
flex: 1,
},
flamechartLabelParent: {
display: 'flex',
flexDirection: 'column',
justifyContent: 'flex-end',
alignItems: 'flex-start',
fontSize: FontSize.TITLE,
width: FontSize.TITLE * 1.2,
borderRight: `1px solid ${Colors.LIGHT_GRAY}`,
},
flamechartLabelParentBottom: {
justifyContent: 'flex-start',
},
flamechartLabel: {
transform: 'rotate(-90deg)',
transformOrigin: '50% 50% 0',
width: FontSize.TITLE * 1.2,
flexShrink: 1,
},
flamechartLabelBottom: {
transform: 'rotate(-90deg)',
display: 'flex',
justifyContent: 'flex-end',
},
callersAndCallees: {
flex: 1,
borderLeft: `${Sizes.SEPARATOR_HEIGHT}px solid ${Colors.LIGHT_GRAY}`,
},
divider: {
height: 2,
background: Colors.LIGHT_GRAY,
},
})
interface SandwichViewContainerProps {
activeProfileState: ActiveProfileState
glCanvas: HTMLCanvasElement
}
export const SandwichViewContainer = createContainer(
SandwichView,
(state: ApplicationState, dispatch: Dispatch, ownProps: SandwichViewContainerProps) => {
const {activeProfileState, glCanvas} = ownProps
const {sandwichViewState, index} = activeProfileState
const {callerCallee} = sandwichViewState
const setSelectedFrame = (selectedFrame: Frame | null) => {
dispatch(
actions.sandwichView.setSelectedFrame({
profileIndex: index,
args: selectedFrame,
}),
)
}
return {
activeProfileState: activeProfileState,
glCanvas,
setSelectedFrame,
selectedFrame: callerCallee ? callerCallee.selectedFrame : null,
profileIndex: index,
}
},
)