Skip to content

Commit cf32b91

Browse files
author
Kevin Ngo
committed
Fix issue with barstacks snapshots stacking on top of each other in Comparison view by correcting the key of each rect
1 parent a689e3f commit cf32b91

File tree

2 files changed

+63
-43
lines changed

2 files changed

+63
-43
lines changed

src/app/components/BarGraphComparison.tsx

Lines changed: 26 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ import { scaleBand, scaleLinear, scaleOrdinal } from '@visx/scale';
99
import { useTooltip, useTooltipInPortal, defaultStyles } from '@visx/tooltip';
1010
import { Text } from '@visx/text';
1111
import { schemeSet3 } from 'd3-scale-chromatic';
12+
import Select from '@material-ui/core/Select';
13+
import InputLabel from '@material-ui/core/InputLabel';
14+
import MenuItem from '@material-ui/core/MenuItem';
15+
import FormControl from '@material-ui/core/FormControl';
1216
import snapshots from './snapshots';
1317
import { onHover, onHoverExit } from '../actions/actions';
1418
import { useStoreContext } from '../store';
@@ -65,9 +69,12 @@ const tooltipStyles = {
6569
const BarGraphComparison = (props) => {
6670
const [{ tabs, currentTab }, dispatch] = useStoreContext();
6771
const { width, height, data, comparison } = props;
68-
console.log('props in BGComparison.tsx', props);
69-
console.log('comparison in BGComparison.tsx', comparison);
7072

73+
console.log('comparison >>>', comparison);
74+
75+
// console.log('tabs in BGComp >>>', tabs);
76+
const currentIndex = tabs[currentTab].sliderIndex;
77+
console.log('sliderIndx outside of bargraph >>>', currentIndex);
7178
const {
7279
tooltipOpen,
7380
tooltipLeft,
@@ -87,15 +94,10 @@ const BarGraphComparison = (props) => {
8794
const getSeriesId = (d: series) => d.currentTab;
8895
const formatSnapshotId = (id) => `Snapshot ID: ${id}`;
8996
const formatRenderTime = (time) => `${time} ms `;
90-
const tabsComparison = [
91-
!comparison ? null : `Series: ${comparison[0]['currentTab']}`,
92-
`Series: ${currentTab}`,
93-
];
97+
9498
// create visualization SCALES with cleaned data
9599
const snapshotIdScale = scaleBand<string>({
96-
// domain: comparison.map(getSeriesId),
97-
// domain: .map(getSnapshotId),
98-
domain: getSnapshotId(data.barStack[0]),
100+
domain: getSnapshotId(data.barStack[currentIndex]),
99101
padding: 0.2,
100102
});
101103

@@ -114,10 +116,15 @@ const BarGraphComparison = (props) => {
114116
const yMax = height - margin.top - 150;
115117
snapshotIdScale.rangeRound([0, xMax]);
116118
renderingScale.range([yMax, 0]);
117-
119+
const filterSeries = (comparisonArray) => {
120+
return comparisonArray.map((sessionName, idx) => {
121+
return <MenuItem>{sessionName}</MenuItem>;
122+
});
123+
};
118124
// console.log('getSeriesID', getSeriesId());
119125
return (
120126
<div>
127+
<h1>{`Current Snapshot: ${currentIndex + 1}`}</h1>
121128
<svg ref={containerRef} width={width} height={height}>
122129
{}
123130
<rect
@@ -152,12 +159,13 @@ const BarGraphComparison = (props) => {
152159
color={colorScale}
153160
>
154161
{(barStacks) =>
155-
barStacks.map((barStack) => {
156-
const bar = barStack.bars[0];
162+
barStacks.map((barStack, idx) => {
163+
const bar = barStack.bars[currentIndex];
164+
console.log('data.barStack >>>', data.barStack);
157165

158166
return (
159167
<rect
160-
key={`bar-stack-${bar.index}-NewView`}
168+
key={`bar-stack-${idx}-NewView`}
161169
x={300}
162170
y={bar.y}
163171
height={bar.height === 0 ? null : bar.height}
@@ -192,7 +200,7 @@ const BarGraphComparison = (props) => {
192200
</BarStack>
193201
<BarStack
194202
// Comparison Barstack
195-
data={!comparison ? ['1', '2'] : comparison[0].data.barStack}
203+
data={!comparison ? [] : comparison[0].data.barStack}
196204
// data={data.barStack}
197205
keys={keys}
198206
// x={getSnapshotId}
@@ -202,12 +210,12 @@ const BarGraphComparison = (props) => {
202210
color={colorScale}
203211
>
204212
{(barStacks) =>
205-
barStacks.map((barStack) => {
206-
const bar = barStack.bars[0];
207-
213+
barStacks.map((barStack, idx) => {
214+
if (barStacks.length === 0) return <h1>No Comparison</h1>;
215+
const bar = barStack.bars[currentIndex];
208216
return (
209217
<rect
210-
key={`bar-stack-${bar.index}-${bar.index}`}
218+
key={`bar-stack-${idx}-${bar.index}`}
211219
x={bar.x + 50}
212220
y={bar.y}
213221
height={bar.height === 0 ? null : bar.height}

src/app/components/ComponentMap.tsx

Lines changed: 37 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,17 @@ import getLinkComponent from './getLinkComponent';
1010
import { onHover, onHoverExit } from '../actions/actions';
1111
import { useStoreContext } from '../store';
1212

13-
1413
const root = hierarchy({
1514
name: 'root',
1615
children: [
1716
{ name: 'child #1' },
1817
{
1918
name: 'child #2',
20-
children: [{ name: 'grandchild #1' }, { name: 'grandchild #2' }, { name: 'grandchild #3' }],
19+
children: [
20+
{ name: 'grandchild #1' },
21+
{ name: 'grandchild #2' },
22+
{ name: 'grandchild #3' },
23+
],
2124
},
2225
],
2326
});
@@ -45,7 +48,6 @@ export default function ComponentMap({
4548
margin = defaultMargin,
4649
snapshots: snapshots,
4750
}: LinkTypesProps) {
48-
4951
const [{ tabs, currentTab }, dispatch] = useStoreContext();
5052
// This is where we select the last object in the snapshots array from props to allow hierarchy to parse the data for render on the component map per hierarchy layout specifications.
5153
const lastNode = snapshots.length - 1;
@@ -103,8 +105,8 @@ export default function ComponentMap({
103105
/>
104106

105107
<svg width={totalWidth} height={totalHeight}>
106-
<LinearGradient id='links-gradient' from='#fd9b93' to='#fe6e9e' />
107-
<rect width={totalWidth} height={totalHeight} rx={14} fill='#242529'/>
108+
<LinearGradient id="links-gradient" from="#fd9b93" to="#fe6e9e" />
109+
<rect width={totalWidth} height={totalHeight} rx={14} fill="#242529" />
108110
<Group top={margin.top} left={margin.left}>
109111
<Tree
110112
root={hierarchy(data, (d) => (d.isExpanded ? null : d.children))}
@@ -118,9 +120,9 @@ export default function ComponentMap({
118120
key={i}
119121
data={link}
120122
percent={stepPercent}
121-
stroke='#ff6569'
122-
strokeWidth='1'
123-
fill='none'
123+
stroke="#ff6569"
124+
strokeWidth="1"
125+
fill="none"
124126
/>
125127
))}
126128

@@ -130,7 +132,7 @@ export default function ComponentMap({
130132
if (nodeLength < 5) return nodeLength + 40;
131133
if (nodeLength < 10) return nodeLength + 60;
132134
return nodeLength + 70;
133-
}
135+
};
134136
const width = widthFunc(node.data.name);
135137
const height = 25;
136138

@@ -168,39 +170,49 @@ export default function ComponentMap({
168170
width={width}
169171
y={-height / 2}
170172
x={-width / 2}
171-
fill= {node.children ? '#161521' : '#62d6fb'}
173+
fill={node.children ? '#161521' : '#62d6fb'}
172174
stroke={node.children ? '#62d6fb' : '#161521'}
173175
strokeWidth={1}
174176
strokeDasharray={node.children ? '0' : '2,2'}
175-
strokeOpacity='1'
176-
rx={node.children ? 4 : 10}
177+
strokeOpacity="1"
178+
rx={node.children ? 4 : 10}
177179
onClick={() => {
178180
node.data.isExpanded = !node.data.isExpanded;
179181
forceUpdate();
180182
}}
181-
//check with recoil
182-
onMouseLeave={()=> {
183-
if(Object.keys(node.data.recoilDomNode).length > 0){
184-
dispatch(onHoverExit(node.data.recoilDomNode[node.data.name]))
183+
//check with recoil
184+
onMouseLeave={() => {
185+
if (
186+
Object.keys(node.data.recoilDomNode).length > 0
187+
) {
188+
dispatch(
189+
onHoverExit(
190+
node.data.recoilDomNode[node.data.name]
191+
)
192+
);
185193
} else {
186-
dispatch(onHoverExit(node.data.rtid))
194+
dispatch(onHoverExit(node.data.rtid));
187195
}
188196
}}
189-
onMouseEnter={()=> {
190-
if(Object.keys(node.data.recoilDomNode).length > 0){
191-
dispatch(onHover(node.data.recoilDomNode[node.data.name]))
197+
onMouseEnter={() => {
198+
if (
199+
Object.keys(node.data.recoilDomNode).length > 0
200+
) {
201+
dispatch(
202+
onHover(node.data.recoilDomNode[node.data.name])
203+
);
192204
} else {
193-
dispatch(onHover(node.data.rtid))
194-
}
205+
dispatch(onHover(node.data.rtid));
206+
}
195207
}}
196208
/>
197209
)}
198210
{/* Display text inside of each component node */}
199211
<text
200-
dy='.33em'
212+
dy=".33em"
201213
fontSize={10}
202-
fontFamily='Roboto'
203-
textAnchor='middle'
214+
fontFamily="Roboto"
215+
textAnchor="middle"
204216
style={{ pointerEvents: 'none' }}
205217
fill={
206218
node.depth === 0

0 commit comments

Comments
 (0)