Skip to content

Commit 882823f

Browse files
committed
removed scrolling for map and perforamnce and added scrolling for tree and history
1 parent fb681ba commit 882823f

File tree

5 files changed

+71
-41
lines changed

5 files changed

+71
-41
lines changed

src/app/components/StateRoute/History.tsx

Lines changed: 35 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ function History(props: Record<string, unknown>): JSX.Element {
114114
if (!delta) return 'No state changes';
115115

116116
const changedState = findStateChangeObj(delta);
117+
console.log('changed state', formatters.html.format(changedState[0]));
117118
return changedState.length > 0 ? formatters.html.format(changedState[0]) : 'No state changes';
118119
} catch (error) {
119120
console.error('Error in findDiff:', error);
@@ -129,9 +130,20 @@ function History(props: Record<string, unknown>): JSX.Element {
129130
const svg = d3.select(svgRef.current);
130131
svg.selectAll('*').remove();
131132

132-
const treeLayout = d3.tree().nodeSize([FIXED_NODE_WIDTH, FIXED_NODE_HEIGHT]);
133-
const d3root = treeLayout(d3.hierarchy(root));
133+
// Create tree layout with fixed node size
134+
const treeLayout = d3
135+
.tree()
136+
.nodeSize([FIXED_NODE_WIDTH, FIXED_NODE_HEIGHT])
137+
.separation((a, b) => {
138+
// Increase separation between unrelated subtrees
139+
return a.parent === b.parent ? 1.2 : 2;
140+
});
141+
142+
// Create hierarchy and compute initial layout
143+
const d3root = d3.hierarchy(root);
144+
treeLayout(d3root);
134145

146+
// Calculate the bounds of the tree
135147
let minX = Infinity;
136148
let maxX = -Infinity;
137149
let minY = Infinity;
@@ -144,15 +156,24 @@ function History(props: Record<string, unknown>): JSX.Element {
144156
maxY = Math.max(maxY, d.y);
145157
});
146158

159+
// Calculate the actual dimensions needed
147160
const actualWidth = maxX - minX + FIXED_NODE_WIDTH;
148161
const actualHeight = maxY - minY + FIXED_NODE_HEIGHT;
149162

163+
// Set SVG dimensions to accommodate the tree
164+
const svgWidth = Math.max(actualWidth + margin.left + margin.right, totalWidth);
150165
svg
151-
.attr('width', Math.max(actualWidth + margin.left + margin.right, totalWidth))
166+
.attr('width', svgWidth)
152167
.attr('height', Math.max(actualHeight + margin.top + margin.bottom, totalHeight));
153168

154-
const centerOffset = totalWidth / 2 - (maxX - minX) / 2;
155-
const g = svg.append('g').attr('transform', `translate(${centerOffset},${margin.top})`);
169+
// Calculate center offset to keep root centered
170+
const rootOffset = -d3root.x;
171+
const horizontalCenter = svgWidth / 2;
172+
173+
// Create container group and apply transforms
174+
const g = svg
175+
.append('g')
176+
.attr('transform', `translate(${horizontalCenter + rootOffset},${margin.top})`);
156177

157178
// Draw links
158179
const link = g
@@ -163,13 +184,12 @@ function History(props: Record<string, unknown>): JSX.Element {
163184
.attr('class', (d) => {
164185
return d.data.index === currLocation.index ? 'link current-link' : 'link';
165186
})
166-
.attr(
167-
'd',
168-
(d) =>
169-
`M${d.x},${d.y}C${d.x},${(d.y + d.parent.y) / 2} ${d.parent.x},${
170-
(d.y + d.parent.y) / 2
171-
} ${d.parent.x},${d.parent.y}`,
172-
);
187+
.attr('d', (d) => {
188+
return `M${d.x},${d.y}
189+
C${d.x},${(d.y + d.parent.y) / 2}
190+
${d.parent.x},${(d.y + d.parent.y) / 2}
191+
${d.parent.x},${d.parent.y}`;
192+
});
173193

174194
// Create node groups
175195
const node = g
@@ -189,7 +209,7 @@ function History(props: Record<string, unknown>): JSX.Element {
189209
dispatch(changeSlider(d.data.index));
190210
});
191211

192-
// Add rectangles for nodes
212+
// Add rectangles for nodes with consistent size
193213
node
194214
.append('rect')
195215
.attr('width', 180)
@@ -199,7 +219,7 @@ function History(props: Record<string, unknown>): JSX.Element {
199219
.attr('rx', 8)
200220
.attr('ry', 8);
201221

202-
// Add snapshot title
222+
// Add snapshot titles
203223
node
204224
.append('text')
205225
.attr('dy', '-25')
@@ -216,7 +236,7 @@ function History(props: Record<string, unknown>): JSX.Element {
216236
.attr('height', 65)
217237
.append('xhtml:div')
218238
.style('font-size', '12px')
219-
.style('overflow', 'hidden')
239+
.style('overflow-y', 'auto')
220240
.style('text-align', 'center')
221241
.html((d) => findDiff(d.data.index));
222242

src/app/components/StateRoute/Tree.tsx

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -55,20 +55,22 @@ const Tree = (props: TreeProps) => {
5555

5656
return (
5757
<>
58-
{snapshot && (
59-
// @ts-ignore
60-
<JSONTree
58+
<div className='tree-component'>
59+
{snapshot && (
6160
// @ts-ignore
62-
data={snapshots[currLocation.index] || snapshot} // data to be rendered, a snapshot object
63-
theme={{ extend: colors, tree: () => ({ className: 'json-tree' }) }} // theme set to a base16 theme that has been extended to include "className: 'json-tree'"
64-
shouldExpandNodeInitially={() => true} // determines if node should be expanded when it first renders (root is expanded by default)
65-
getItemString={getItemString} // allows the customization of how arrays, objects, and iterable nodes are displayed.
66-
labelRenderer={(raw: any[]) => {
67-
// renders a label if the first element of raw is a number.
68-
return typeof raw[0] !== 'number' ? <span>{raw[0]}</span> : null;
69-
}}
70-
/>
71-
)}
61+
<JSONTree
62+
// @ts-ignore
63+
data={snapshots[currLocation.index] || snapshot} // data to be rendered, a snapshot object
64+
theme={{ extend: colors, tree: () => ({ className: 'json-tree' }) }} // theme set to a base16 theme that has been extended to include "className: 'json-tree'"
65+
shouldExpandNodeInitially={() => true} // determines if node should be expanded when it first renders (root is expanded by default)
66+
getItemString={getItemString} // allows the customization of how arrays, objects, and iterable nodes are displayed.
67+
labelRenderer={(raw: any[]) => {
68+
// renders a label if the first element of raw is a number.
69+
return typeof raw[0] !== 'number' ? <span>{raw[0]}</span> : null;
70+
}}
71+
/>
72+
)}
73+
</div>
7274
</>
7375
);
7476
};

src/app/styles/components/d3graph.css

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,7 @@
1515
}
1616

1717
.node:hover rect {
18-
fill: #14b8a6;
19-
stroke: #0d9488;
18+
stroke: #14b8a6;
2019
filter: drop-shadow(0 4px 6px rgba(0, 0, 0, 0.1));
2120
}
2221

@@ -35,8 +34,7 @@
3534
}
3635

3736
.node--internal:hover rect {
38-
fill: #14b8a6;
39-
stroke: #0d9488;
37+
stroke: #14b8a6;
4038
}
4139
.node--internal text {
4240
font-family: 'Outfit', sans-serif;
@@ -46,9 +44,8 @@
4644
}
4745

4846
/* Current/active node styling */
49-
.node.active circle {
50-
fill: #14b8a6;
51-
stroke: #0d9488;
47+
.node.active rect {
48+
stroke: #14b8a6;
5249
}
5350

5451
/* Link styling */
@@ -90,4 +87,8 @@ div.tooltip {
9087
/* Container styling */
9188
.display {
9289
background-color: #f9fafb;
90+
height: 100%;
91+
width: 100%;
92+
overflow: auto; /* Enable scrolling */
93+
position: relative; /* Create new stacking context */
9394
}

src/app/styles/components/diff.css

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
@import url('https://fonts.googleapis.com/css2?family=Outfit:wght@100;200;300;400;500;600;700;800;900&display=swap');
22
.jsondiffpatch-delta {
33
font-family: 'Outfit', sans-serif;
4-
font-size: 16px;
4+
font-size: 12px;
55
margin: 0;
6-
padding: 0 0 0 12px;
76
display: inline-block;
87
}
98
.jsondiffpatch-delta pre {

src/app/styles/layout/_stateContainer.scss

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
.state-container {
22
overflow: auto;
3-
}
4-
5-
.app-body {
63
height: 100%;
4+
display: flex;
5+
flex-direction: column;
76
}
87

9-
.app-content {
8+
.app-content,
9+
.app-body {
1010
height: 100%;
11+
overflow: hidden; /* Prevent double scrollbars */
1112
}
1213

1314
.main-navbar-container--structural {
@@ -152,4 +153,11 @@
152153
.json-tree {
153154
overflow: auto;
154155
list-style: none;
156+
padding: 16px;
157+
margin: 0 0 50px;
158+
}
159+
160+
.tree-component {
161+
height: 100%;
162+
overflow: auto;
155163
}

0 commit comments

Comments
 (0)