Skip to content

Commit 4ea61ac

Browse files
(added, verified) getSnapshotIds algo to clean incoming data
1 parent 1914cbf commit 4ea61ac

File tree

3 files changed

+25
-12
lines changed

3 files changed

+25
-12
lines changed

src/app/components/PerformanceVisx.tsx

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ export type BarStackProps = {
3030
margin?: { top: number; right: number; bottom: number; left: number };
3131
events?: boolean;
3232
snapshots?: any;
33+
hierarchy?: any;
3334
};
3435

3536
/* DEFAULT STYLING */
@@ -49,7 +50,7 @@ const tooltipStyles = {
4950
/* DATA PREP FUNCTIONS */
5051
const getPerfMetrics = snapshots => {
5152
return snapshots.reduce((perfSnapshots, curSnapshot,idx)=> {
52-
return perfSnapshots.concat(traverse(curSnapshot, {snapshot:idx+1}))
53+
return perfSnapshots.concat(traverse(curSnapshot, {snapshot:++idx}))
5354
}, [])
5455
}
5556

@@ -63,14 +64,24 @@ const traverse = (snapshot, perfSnapshot = {}) => {
6364
return perfSnapshot;
6465
}
6566

67+
const getSnapshotIds = (obj, snapshotIds = []) => {
68+
snapshotIds.push(`${obj.name}.${obj.branch}`);
69+
if (obj.children) {
70+
obj.children.forEach(child => {
71+
getSnapshotIds(child, snapshotIds);
72+
});
73+
}
74+
return snapshotIds
75+
};
6676

6777
/* EXPORT COMPONENT */
6878
export default function PerformanceVisx({
6979
width,
7080
height,
7181
events = false,
7282
margin = defaultMargin,
73-
snapshots
83+
snapshots,
84+
hierarchy,
7485
}: BarStackProps)
7586

7687
{
@@ -84,9 +95,9 @@ export default function PerformanceVisx({
8495
} = useTooltip<TooltipData>();
8596

8697
/* DATA PREP */
87-
const data = getPerfMetrics(snapshots);
88-
console.log(data)
89-
98+
// const data = getPerfMetrics(snapshots);
99+
const data = [...snapshots]
100+
console.log('cleaned data', getPerfMetrics(snapshots, getSnapshotIds(hierarchy)))
90101

91102
// array of all object keys
92103
const keys = Object.keys(data[0]).filter((d) => d !== "snapshot") as CityName[];

src/app/components/StateRoute.tsx

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ interface StateRouteProps {
4848
const StateRoute = (props: StateRouteProps) => {
4949
const { snapshot, hierarchy, snapshots, viewIndex } = props;
5050

51+
console.log(hierarchy)
52+
5153
const isRecoil = snapshot.atomsComponents ? true : false;
5254
const [noRenderData, setNoRenderData] = useState(false);
5355

@@ -113,11 +115,12 @@ const StateRoute = (props: StateRouteProps) => {
113115
if (hierarchy) {
114116
return (
115117
<ParentSize>{({ width, height }) =>
116-
<PerformanceVisx
117-
width={width}
118-
height={height}
119-
snapshots={snapshots}
120-
/>}
118+
<PerformanceVisx
119+
width={width}
120+
height={height}
121+
snapshots={snapshots}
122+
hierarchy={hierarchy}
123+
/>}
121124
</ParentSize>
122125

123126
// <PerfView

src/app/containers/ActionContainer.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@ import Action from '../components/Action';
1212
import { emptySnapshots, changeView, changeSlider } from '../actions/actions';
1313
import { useStoreContext } from '../store';
1414

15-
16-
1715
const resetSlider = () => {
1816
const slider = document.querySelector('.rc-slider-handle');
1917
if (slider) { slider.setAttribute('style', 'left: 0'); }
@@ -25,6 +23,7 @@ function ActionContainer() {
2523
let actionsArr = [];
2624
const hierarchyArr:any[] = [];
2725

26+
// function to traverse state from hiararchy and also getting information on display name and component name
2827
// function to traverse state from hiararchy and also getting information on display name and component name
2928
const displayArray = (obj:{stateSnapshot:{children:any[]}, name:number, branch:number, index:number, children?:[]}) => {
3029
if (obj.stateSnapshot.children.length > 0 && obj.stateSnapshot.children[0] && obj.stateSnapshot.children[0].state && obj.stateSnapshot.children[0].name) {

0 commit comments

Comments
 (0)