-
Notifications
You must be signed in to change notification settings - Fork 11
/
InspectorStats.tsx
162 lines (141 loc) · 4.21 KB
/
InspectorStats.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
150
151
152
153
154
155
156
157
158
159
160
161
162
import { Colors } from '../constants/Colors';
import { InspectorHeader } from './InspectorHeader';
import { InspectorHr } from './InspectorHr';
import { InspectorItem } from './InspectorItem';
import { minimizeData } from '../../minimizeData';
import { useSelector } from '../states/store';
import React, { useCallback, useState } from 'react';
import styled from 'styled-components';
// == styles =======================================================================================
const Value = styled.div`
margin: 0.15rem;
font-size: 0.7rem;
line-height: 1em;
white-space: nowrap;
`;
const CalculateButton = styled.div`
margin: 4px auto 0;
font-size: 0.8rem;
line-height: 1.2rem;
width: 128px;
text-align: center;
background: ${ Colors.back3 };
cursor: pointer;
&:hover {
background: ${ Colors.back4 };
}
&:active {
background: ${ Colors.back1 };
}
`;
// == element ======================================================================================
export interface InspectorStatsProps {
className?: string;
}
const InspectorStats = (): JSX.Element | null => {
const [ filesize, setFilesize ] = useState<number | null>( null );
const [ filesizeMin, setFilesizeMin ] = useState<number | null>( null );
const {
automaton,
channelsCount,
channelItemsCount,
curvesCount,
curvesLength,
fxDefsCount,
} = useSelector( ( state ) => ( {
automaton: state.automaton.instance,
channelsCount: Object.keys( state.automaton.channels ).length,
channelItemsCount: Object.values( state.automaton.channels ).reduce(
( prev, channel ) => prev + Object.keys( channel.items ).length,
0,
),
curvesCount: Object.keys( state.automaton.curves ).length,
curvesLength: Object.values( state.automaton.curves ).reduce(
( prev, curve ) => prev + curve.length,
0,
),
fxDefsCount: Object.keys( state.automaton.fxDefinitions ).length,
} ) );
const handleCalculateFilesize = useCallback(
() => {
if ( !automaton ) { return; }
const serialized = automaton.serialize();
setFilesize( JSON.stringify( serialized ).length );
const minimizeOptions = {
precisionTime: automaton.guiSettings.minimizedPrecisionTime,
precisionValue: automaton.guiSettings.minimizedPrecisionValue
};
const minimized = minimizeData( serialized, minimizeOptions );
setFilesizeMin( JSON.stringify( minimized ).length );
},
[ automaton ]
);
return ( automaton && <>
<InspectorHeader text="Project Stats" />
<InspectorHr />
<InspectorItem
name="Channels"
description="Channels exists in this project."
>
<Value>
{ channelsCount.toLocaleString() }
</Value>
</InspectorItem>
<InspectorItem
name="Channel Items"
description="Items of channels exists in this project."
>
<Value>
{ channelItemsCount.toLocaleString() }
</Value>
</InspectorItem>
<InspectorItem
name="Curves"
description="Curves exists in this project."
>
<Value>
{ curvesCount.toLocaleString() }
</Value>
</InspectorItem>
<InspectorItem
name="Curves Length"
description="Total length of curves."
>
<Value>
{ `${ curvesLength.toLocaleString() } sec` }
</Value>
</InspectorItem>
<InspectorItem
name="Fx Definitions"
description="Fx definitions loaded in this project."
>
<Value>
{ fxDefsCount.toLocaleString() }
</Value>
</InspectorItem>
<InspectorHr />
<InspectorItem
name="Filesize"
description="The size of its serialized data."
>
<Value>
{ filesize ? `${ filesize.toLocaleString() } bytes` : '----' }
</Value>
</InspectorItem>
<InspectorItem
name="Filesize (min)"
description="The size of its minimized serialized data."
>
<Value>
{ filesizeMin ? `${ filesizeMin.toLocaleString() } bytes` : '----' }
</Value>
</InspectorItem>
<CalculateButton
data-stalker="Calculate the size of its serialized data."
onClick={ handleCalculateFilesize }
>
Calculate Filesize
</CalculateButton>
</> ) ?? null;
};
export { InspectorStats };