Skip to content

Commit 26e9597

Browse files
(added) units, labels for on-hover box
1 parent e8226f6 commit 26e9597

File tree

1 file changed

+28
-33
lines changed

1 file changed

+28
-33
lines changed

src/app/components/PerformanceVisx.tsx

Lines changed: 28 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,7 @@ export type BarStackProps = {
3535
};
3636

3737
/* DEFAULT STYLING */
38-
const purple1 = "#6c5efb";
39-
const purple2 = "#c998ff";
40-
const purple4 = "#00ffff ";
41-
const purple3 = "#a44afe";
42-
const tickColor = '#679DCA';
38+
const axisColor = '#679DCA';
4339
const background = "#242529";
4440
const defaultMargin = { top: 40, right: 0, bottom: 0, left: 0 };
4541
const tooltipStyles = {
@@ -88,8 +84,6 @@ export default function PerformanceVisx({
8884
hierarchy,
8985
}: BarStackProps)
9086

91-
let tooltipTimeout: number;
92-
9387
{
9488
const {
9589
tooltipOpen,
@@ -100,6 +94,8 @@ let tooltipTimeout: number;
10094
showTooltip
10195
} = useTooltip<TooltipData>();
10296

97+
let tooltipTimeout: number;
98+
10399
// filter and structure incoming data for VISX
104100
const data = getPerfMetrics(snapshots, getSnapshotIds(hierarchy))
105101
const keys = Object.keys(data[0]).filter((d) => d !== "snapshotId") as CityName[];
@@ -115,41 +111,39 @@ const totalRenderArr = data.reduce((totalRender, curSnapshot) => {
115111
return totalRender;
116112
}, [] as number[]);
117113

114+
// data accessor (used to generate scales) and formatter (add units for on hover box)
115+
const getSnapshotId = (d: snapshot) => d.snapshotId;
116+
const formatSnapshotId = id => 'Snapshot ID: ' + id;
117+
const formatRenderTime = time => time + ' ms';
118118

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>({
119+
// create visualization scales with filtered data
120+
const snapshotIdScale = scaleBand<string>({
125121
domain: data.map(getSnapshotId),
126122
padding: 0.2
127-
});
123+
});
128124

129-
const renderingScale = scaleLinear<number>({
125+
const renderingScale = scaleLinear<number>({
130126
domain: [0, Math.max(...totalRenderArr)],
131127
nice: true
132-
});
128+
});
133129

134-
const colorScale = scaleOrdinal<CityName, string>({
130+
const colorScale = scaleOrdinal<CityName, string>({
135131
domain: keys,
136132
range: schemeSet3
137-
});
138-
133+
});
139134

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

143-
// setting max dimensions and scale ranges
144-
if (width < 10) return null;
145-
const xMax = width;
146-
const yMax = height - margin.top - 100;
147-
148-
snapshotIdScale.rangeRound([0, xMax]);
149-
renderingScale.range([yMax, 0]);
137+
// setting max dimensions and scale ranges
138+
if (width < 10) return null;
139+
const xMax = width;
140+
const yMax = height - margin.top - 100;
141+
snapshotIdScale.rangeRound([0, xMax]);
142+
renderingScale.range([yMax, 0]);
150143

151144
return width < 10 ? null : (
152145
// relative position is needed for correct tooltip positioning
146+
153147
<div style={{ position: "relative" }}>
154148
<svg ref={containerRef} width={width} height={height}>
155149
<rect
@@ -215,17 +209,17 @@ const totalRenderArr = data.reduce((totalRender, curSnapshot) => {
215209
<AxisBottom
216210
top={yMax + margin.top}
217211
scale={snapshotIdScale}
218-
// tickFormat={formatDate}
219-
stroke={tickColor}
220-
tickStroke={tickColor}
212+
stroke={axisColor}
213+
tickStroke={axisColor}
221214
tickLabelProps={() => ({
222-
fill: tickColor,
215+
fill: axisColor,
223216
fontSize: 11,
224217
textAnchor: 'middle',
225218
})}
226219
/>
227220
</svg>
228221

222+
// OPTIONAL legend
229223
{/* <div
230224
style={{
231225
position: "absolute",
@@ -242,6 +236,7 @@ const totalRenderArr = data.reduce((totalRender, curSnapshot) => {
242236
labelMargin="0 15px 0 0"
243237
/>
244238
</div> */}
239+
245240
{/* FOR HOVER OVER DISPLAY */}
246241
{tooltipOpen && tooltipData && (
247242
<TooltipInPortal
@@ -254,10 +249,10 @@ const totalRenderArr = data.reduce((totalRender, curSnapshot) => {
254249
<strong>{tooltipData.key}</strong>
255250
</div>
256251
<div>
257-
{tooltipData.bar.data[tooltipData.key]}
252+
{formatRenderTime(tooltipData.bar.data[tooltipData.key])}
258253
</div>
259254
<div>
260-
<small>{getSnapshotId(tooltipData.bar.data)}</small>
255+
<small>{formatSnapshotId(getSnapshotId(tooltipData.bar.data))}</small>
261256
</div>
262257
</TooltipInPortal>
263258
)}

0 commit comments

Comments
 (0)