Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Metrics graph axis labels #3913

Merged
merged 5 commits into from
Oct 17, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 30 additions & 3 deletions ui/packages/shared/profile/src/MetricsGraph/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ export const RawMetricsGraph = ({
const xScale = d3
.scaleUtc()
.domain([from, to])
.range([0, width - 2 * margin]);
.range([0, width - 2.5 * margin]);

const yScale = d3
.scaleLinear()
Expand Down Expand Up @@ -381,6 +381,18 @@ export const RawMetricsGraph = ({
setIsContextMenuOpen(isVisible);
};

const isDeltaType = profile !== null ? profile?.query.profType.delta : false;

let yAxisLabel = sampleUnit;
if (isDeltaType) {
if (profile?.query.profType.periodType === 'cpu' && sampleUnit === 'count') {
yAxisLabel = 'CPU Cores';
}
if (sampleUnit === 'bytes') {
yAxisLabel = 'Bytes per Second';
}
}

return (
<>
<MetricsContextMenu
Expand All @@ -402,7 +414,7 @@ export const RawMetricsGraph = ({
highlighted={highlighted}
contextElement={graph.current}
sampleUnit={sampleUnit}
delta={profile !== null ? profile?.query.profType.delta : false}
delta={isDeltaType}
/>
)}
</div>
Expand Down Expand Up @@ -436,7 +448,7 @@ export const RawMetricsGraph = ({
</g>
)}
</g>
<g transform={`translate(${margin}, ${margin / 1.5})`}>
<g transform={`translate(${margin * 1.5}, ${margin / 1.5})`}>
<g className="y axis" textAnchor="end" fontSize="10" fill="none">
{yScale.ticks(5).map((d, i) => (
<Fragment key={`${i.toString()}-${d.toString()}`}>
Expand Down Expand Up @@ -476,6 +488,16 @@ export const RawMetricsGraph = ({
y1={0}
y2={height - margin}
/>
<g transform={`translate(${-margin}, ${(height - margin) / 2}) rotate(270)`}>
<text
fill="currentColor"
dy="-0.7em"
className="text-sm capitalize"
textAnchor="middle"
>
{yAxisLabel}
</text>
</g>
</g>
<g
className="x axis"
Expand Down Expand Up @@ -515,6 +537,11 @@ export const RawMetricsGraph = ({
y1={0}
y2={0}
/>
<g transform={`translate(${(width - 2.5 * margin) / 2}, ${margin / 2})`}>
<text fill="currentColor" dy=".71em" y={5} className="text-sm">
Time
</text>
</g>
</g>
<g className="lines fill-transparent">
{series.map((s, i) => (
Expand Down