-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #98 from FMS-Cat/feat-gui-
feature (gui): add stats inspector
- Loading branch information
Showing
6 changed files
with
183 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
161 changes: 161 additions & 0 deletions
161
packages/automaton-with-gui/src/view/components/InspectorStats.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,161 @@ | ||
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; | ||
`; | ||
|
||
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 }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters