Skip to content

Commit e4c4e34

Browse files
(removed) the following imports: visx legend, snapshots, useForceUpdate
1 parent b2e298f commit e4c4e34

File tree

1 file changed

+21
-13
lines changed

1 file changed

+21
-13
lines changed

src/app/components/PerformanceVisx.tsx

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,8 @@ import { Grid } from "@visx/grid";
66
import { AxisBottom, AxisLeft } from "@visx/axis";
77
import { scaleBand, scaleLinear, scaleOrdinal } from "@visx/scale";
88
import { useTooltip, useTooltipInPortal, defaultStyles } from "@visx/tooltip";
9-
// import { LegendOrdinal } from "@visx/legend";
109
import { Text } from '@visx/text';
1110
import { schemeSet1,schemeSet3 } from "d3-scale-chromatic";
12-
// import snapshots from "./snapshots";
13-
import useForceUpdate from './useForceUpdate';
1411

1512

1613
/* TYPESCRIPT */
@@ -46,16 +43,18 @@ const tooltipStyles = {
4643
color: "white"
4744
};
4845

49-
/* DATA PREP FUNCTIONS */
46+
/* DATA HANDLING FUNCTIONS */
5047
const getPerfMetrics = (snapshots, snapshotsIds) => {
51-
return snapshots.reduce((perfSnapshots, curSnapshot,idx)=> {
48+
return snapshots.reduce((perfSnapshots, curSnapshot, idx)=> {
5249
return perfSnapshots.concat(traverse(curSnapshot, {snapshotId:snapshotsIds[idx]}))
5350
}, [])
5451
}
5552

53+
// traverse the snapshot for all components and their rendering time
5654
const traverse = (snapshot, perfSnapshot) => {
5755
if (!snapshot.children[0]) return
5856
for (let i = 0; i < snapshot.children.length; i++){
57+
// perfSnapshot.state = snapshot.children[i].state
5958
if (snapshot.children[i].componentData.actualDuration){
6059
const renderTime = Number(Number.parseFloat(snapshot.children[i].componentData.actualDuration).toPrecision(5))
6160
perfSnapshot[snapshot.children[i].name+-[i+1]] = renderTime
@@ -75,6 +74,8 @@ if (obj.children) {
7574
return snapshotIds
7675
};
7776

77+
78+
7879
/* EXPORT COMPONENT */
7980
export default function PerformanceVisx({
8081
width,
@@ -100,7 +101,8 @@ let tooltipTimeout: number;
100101
// filter and structure incoming data for VISX
101102
const data = getPerfMetrics(snapshots, getSnapshotIds(hierarchy))
102103
const keys = Object.keys(data[0]).filter((d) => d !== "snapshotId") as CityName[];
103-
console.log(data)
104+
console.log('data', data)
105+
console.log('snapshots', snapshots)
104106

105107
// create array of total render times for each snapshot
106108
const totalRenderArr = data.reduce((totalRender, curSnapshot) => {
@@ -117,7 +119,7 @@ const getSnapshotId = (d: snapshot) => d.snapshotId;
117119
const formatSnapshotId = id => 'Snapshot ID: ' + id;
118120
const formatRenderTime = time => time + ' ms ';
119121

120-
// create visualization scales with filtered data
122+
// create visualization SCALES with filtered data
121123
const snapshotIdScale = scaleBand<string>({
122124
domain: data.map(getSnapshotId),
123125
padding: 0.2
@@ -142,6 +144,12 @@ const yMax = height - margin.top - 150;
142144
snapshotIdScale.rangeRound([0, xMax]);
143145
renderingScale.range([yMax, 0]);
144146

147+
// console.log('totalRenderArr', totalRenderArr)
148+
// console.log('renderingScale domain', renderingScale.domain)
149+
// console.log('renderingscale range', renderingScale)
150+
console.log('height', height)
151+
// console.log(yMax)
152+
145153
return width < 10 ? null : (
146154
// relative position is needed for correct tooltip positioning
147155

@@ -175,23 +183,23 @@ renderingScale.range([yMax, 0]);
175183
yScale={renderingScale}
176184
color={colorScale}
177185
>
178-
{(barStacks) => barStacks.map(barStack => barStack.bars.map((bar => (
186+
{(barStacks) => barStacks.map(barStack => barStack.bars.map(((bar,idx) => (
179187
<rect
180188
key={`bar-stack-${barStack.index}-${bar.index}`}
181189
x={bar.x}
182190
y={bar.y}
183-
height={bar.height}
191+
height={bar.height === 0 ? idx + 1 : bar.height}
184192
width={bar.width}
185193
fill={bar.color}
186194
/* TIP TOOL EVENT HANDLERS */
187-
onClick={() => {
188-
if (events) alert(`clicked: ${JSON.stringify(bar)}`);
189-
}}
195+
196+
// Hides tool tip once cursor moves off the current rect
190197
onMouseLeave={() => {
191198
tooltipTimeout = window.setTimeout(() => {
192199
hideTooltip();
193200
}, 300);
194201
}}
202+
// Cursor position in window updates position of the tool tip
195203
onMouseMove={event => {
196204
if (tooltipTimeout) clearTimeout(tooltipTimeout);
197205
const top = event.clientY - margin.top - bar.height;
@@ -208,7 +216,7 @@ renderingScale.range([yMax, 0]);
208216
}
209217
</BarStack>
210218
</Group>
211-
<AxisLeft
219+
<AxisLeft
212220
top={margin.top}
213221
left={margin.left}
214222
scale={renderingScale}

0 commit comments

Comments
 (0)