Skip to content

Commit e8226f6

Browse files
(updated) variable names and comments for visualization scales
1 parent a6aa6fd commit e8226f6

File tree

1 file changed

+32
-31
lines changed

1 file changed

+32
-31
lines changed

src/app/components/PerformanceVisx.tsx

Lines changed: 32 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,8 @@ export default function PerformanceVisx({
8888
hierarchy,
8989
}: BarStackProps)
9090

91+
let tooltipTimeout: number;
92+
9193
{
9294
const {
9395
tooltipOpen,
@@ -98,12 +100,12 @@ export default function PerformanceVisx({
98100
showTooltip
99101
} = useTooltip<TooltipData>();
100102

101-
// data prep
103+
// filter and structure incoming data for VISX
102104
const data = getPerfMetrics(snapshots, getSnapshotIds(hierarchy))
103105
const keys = Object.keys(data[0]).filter((d) => d !== "snapshotId") as CityName[];
104106
console.log(data)
105107

106-
// ARRAY OF TOTAL VALUES PER SNAPSHOT
108+
// create array of total render times for each snapshot
107109
const totalRenderArr = data.reduce((totalRender, curSnapshot) => {
108110
const curRenderTotal = keys.reduce((acc, cur) => {
109111
acc += Number(curSnapshot[cur]);
@@ -113,42 +115,41 @@ const totalRenderArr = data.reduce((totalRender, curSnapshot) => {
113115
return totalRender;
114116
}, [] as number[]);
115117

116-
const temperatureScale = scaleLinear<number>({
118+
119+
120+
// data accessor - used for generating scales
121+
const getSnapshotId = (d: snapshot) => d.snapshotId;
122+
123+
// create visualization scales with filtered data
124+
const snapshotIdScale = scaleBand<string>({
125+
domain: data.map(getSnapshotId),
126+
padding: 0.2
127+
});
128+
129+
const renderingScale = scaleLinear<number>({
117130
domain: [0, Math.max(...totalRenderArr)],
118131
nice: true
119-
});
120-
const colorScale = scaleOrdinal<CityName, string>({
132+
});
133+
134+
const colorScale = scaleOrdinal<CityName, string>({
121135
domain: keys,
122136
range: schemeSet3
123-
});
124-
125-
let tooltipTimeout: number;
126-
127-
128-
/* ACCESSORS */
129-
const getSnapshot = (d: snapshot) => d.snapshotId;
137+
});
130138

131-
/* SCALE */
132-
const dateScale = scaleBand<string>({
133-
domain: data.map(getSnapshot),
134-
padding: 0.2
135-
});
136139

140+
// initial set-up for Tool Tip (aka the on hover bar)
137141
const { containerRef, TooltipInPortal } = useTooltipInPortal();
138142

143+
// setting max dimensions and scale ranges
139144
if (width < 10) return null;
140-
// bounds
141-
142-
// width, height
143145
const xMax = width;
144146
const yMax = height - margin.top - 100;
145147

146-
dateScale.rangeRound([0, xMax]);
147-
temperatureScale.range([yMax, 0]);
148+
snapshotIdScale.rangeRound([0, xMax]);
149+
renderingScale.range([yMax, 0]);
148150

149151
return width < 10 ? null : (
150152
// relative position is needed for correct tooltip positioning
151-
152153
<div style={{ position: "relative" }}>
153154
<svg ref={containerRef} width={width} height={height}>
154155
<rect
@@ -162,21 +163,21 @@ const dateScale = scaleBand<string>({
162163
<Grid
163164
top={margin.top}
164165
left={margin.left}
165-
xScale={dateScale}
166-
yScale={temperatureScale}
166+
xScale={snapshotIdScale}
167+
yScale={renderingScale}
167168
width={xMax}
168169
height={yMax}
169170
stroke="black"
170171
strokeOpacity={0.1}
171-
xOffset={dateScale.bandwidth() / 2}
172+
xOffset={snapshotIdScale.bandwidth() / 2}
172173
/>
173174
<Group top={margin.top}>
174175
<BarStack <snapshot, CityName>
175176
data={data}
176177
keys={keys}
177-
x={getSnapshot}
178-
xScale={dateScale}
179-
yScale={temperatureScale}
178+
x={getSnapshotId}
179+
xScale={snapshotIdScale}
180+
yScale={renderingScale}
180181
color={colorScale}
181182
>
182183
{(barStacks) => barStacks.map(barStack => barStack.bars.map((bar => (
@@ -213,7 +214,7 @@ const dateScale = scaleBand<string>({
213214
</Group>
214215
<AxisBottom
215216
top={yMax + margin.top}
216-
scale={dateScale}
217+
scale={snapshotIdScale}
217218
// tickFormat={formatDate}
218219
stroke={tickColor}
219220
tickStroke={tickColor}
@@ -256,7 +257,7 @@ const dateScale = scaleBand<string>({
256257
{tooltipData.bar.data[tooltipData.key]}
257258
</div>
258259
<div>
259-
<small>{getSnapshot(tooltipData.bar.data)}</small>
260+
<small>{getSnapshotId(tooltipData.bar.data)}</small>
260261
</div>
261262
</TooltipInPortal>
262263
)}

0 commit comments

Comments
 (0)