Skip to content

Commit cd0c1ff

Browse files
Built new component map with all supporting files
1 parent 5e157f1 commit cd0c1ff

File tree

2 files changed

+44
-32
lines changed

2 files changed

+44
-32
lines changed

src/app/components/ComponentMap.tsx

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -145,20 +145,18 @@ const ComponentMap = (props: componentMapProps) => {
145145

146146
//TODO -> Alter incoming snapshots so there is useful data to show on hover.
147147
nodeEnter.on('mouseover', function (d: any, i: number): any {
148-
149-
d3.select(this)
150-
.append('text')
151-
.text(() => {
152-
return JSON.stringify(d.data.state);
153-
})
154-
.attr('x', -25)
155-
.attr('y', 20)
156-
.style('font-size', `.6rem`)
157-
.style('fill', 'white')
158-
.attr('stroke', 'white')
159-
.attr('stroke-width', .5)
160-
.attr('id', `popup${i}`);
161-
148+
d3.select(this)
149+
.append('text')
150+
.text(() => {
151+
return JSON.stringify(d.data.state);
152+
})
153+
.attr('x', -25)
154+
.attr('y', 20)
155+
.style('font-size', `.6rem`)
156+
.style('fill', 'white')
157+
.attr('stroke', 'white')
158+
.attr('stroke-width', 0.5)
159+
.attr('id', `popup${i}`);
162160
});
163161
nodeEnter.on('mouseout', function (d: any, i: number): any {
164162
d3.select(`#popup${i}`).remove();
@@ -221,22 +219,22 @@ const ComponentMap = (props: componentMapProps) => {
221219
svgContainer.call(
222220
zoom.transform,
223221
// Changes the initial view, (left, top)
224-
d3.zoomIdentity.translate(x, y).scale(k)
222+
d3.zoomIdentity.translate(x, y).scale(k),
225223
);
226224

227225
// allows the canvas to be zoom-able
228226
svgContainer.call(
229227
d3
230228
.zoom()
231229
.scaleExtent([0.15, 1.5]) // [zoomOut, zoomIn]
232-
.on('zoom', zoomed)
230+
.on('zoom', zoomed),
233231
);
234232
function zoomed(d: any) {
235233
svg
236234
.attr('transform', d3.event.transform)
237235
.on(
238236
'mouseup',
239-
setZoomState(d3.zoomTransform(d3.select('#canvas').node()))
237+
setZoomState(d3.zoomTransform(d3.select('#canvas').node())),
240238
);
241239
}
242240

@@ -246,12 +244,12 @@ const ComponentMap = (props: componentMapProps) => {
246244
// call update on node click
247245
update(root);
248246
},
249-
[data]
247+
[data],
250248
);
251249

252250
return (
253-
<div data-testid="canvas" id="componentMapContainer">
254-
<svg id="canvas"></svg>
251+
<div data-testid='canvas' id='componentMapContainer'>
252+
<svg id='canvas'></svg>
255253
</div>
256254
);
257255
};

src/app/components/Example.tsx

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { pointRadial } from 'd3-shape';
66
import useForceUpdate from './useForceUpdate';
77
import LinkControls from './LinkControls';
88
import getLinkComponent from './getLinkComponent';
9+
import { node } from 'prop-types';
910

1011
interface TreeNode {
1112
name: string;
@@ -69,7 +70,18 @@ export default function Example({
6970
margin = defaultMargin,
7071
snapshots: snapshots,
7172
}: LinkTypesProps) {
72-
console.log('snapshots passed in', snapshots);
73+
//-------------------------------------------------------------------
74+
let obj = { name: 'root', children: snapshots };
75+
console.log('obj', obj);
76+
77+
const nodeCreator = (node) => {
78+
const lastNode = node.length - 1;
79+
return node[lastNode];
80+
};
81+
const finalObj = nodeCreator(snapshots);
82+
//-------------------------------------------------------------------
83+
84+
// console.log('snapshots children', snapshots.children);
7385
const [layout, setLayout] = useState<string>('cartesian');
7486
const [orientation, setOrientation] = useState<string>('horizontal');
7587
const [linkType, setLinkType] = useState<string>('diagonal');
@@ -102,7 +114,7 @@ export default function Example({
102114
}
103115

104116
const LinkComponent = getLinkComponent({ layout, linkType, orientation });
105-
117+
console.log(data);
106118
return totalWidth < 10 ? null : (
107119
<div>
108120
<LinkControls
@@ -116,11 +128,13 @@ export default function Example({
116128
setStepPercent={setStepPercent}
117129
/>
118130
<svg width={totalWidth} height={totalHeight}>
119-
<LinearGradient id="links-gradient" from="#fd9b93" to="#fe6e9e" />
120-
<rect width={totalWidth} height={totalHeight} rx={14} fill="#242529" />
131+
<LinearGradient id='links-gradient' from='#fd9b93' to='#fe6e9e' />
132+
<rect width={totalWidth} height={totalHeight} rx={14} fill='#242529' />
121133
<Group top={margin.top} left={margin.left}>
122134
<Tree
123-
root={hierarchy(data, (d) => (d.isExpanded ? null : d.children))}
135+
root={hierarchy(finalObj, (d) =>
136+
d.isExpanded ? null : d.children,
137+
)}
124138
size={[sizeWidth, sizeHeight]}
125139
separation={(a, b) => (a.parent === b.parent ? 1 : 0.5) / a.depth}
126140
>
@@ -131,9 +145,9 @@ export default function Example({
131145
key={i}
132146
data={link}
133147
percent={stepPercent}
134-
stroke="rgb(254,110,158,0.6)"
135-
strokeWidth="1"
136-
fill="none"
148+
stroke='rgb(254,110,158,0.6)'
149+
strokeWidth='1'
150+
fill='none'
137151
/>
138152
))}
139153

@@ -174,7 +188,7 @@ export default function Example({
174188
width={width}
175189
y={-height / 2}
176190
x={-width / 2}
177-
fill="#272b4d"
191+
fill='#272b4d'
178192
stroke={node.data.children ? '#03c0dc' : '#26deb0'}
179193
strokeWidth={1}
180194
strokeDasharray={node.data.children ? '0' : '2,2'}
@@ -188,10 +202,10 @@ export default function Example({
188202
/>
189203
)}
190204
<text
191-
dy=".33em"
205+
dy='.33em'
192206
fontSize={9}
193-
fontFamily="Arial"
194-
textAnchor="middle"
207+
fontFamily='Arial'
208+
textAnchor='middle'
195209
style={{ pointerEvents: 'none' }}
196210
fill={
197211
node.depth === 0

0 commit comments

Comments
 (0)