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

feat: ✨ Add danger and safe zone to charts #111

Merged
merged 3 commits into from
Jun 2, 2023
Merged
Show file tree
Hide file tree
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
32 changes: 32 additions & 0 deletions packages/web-reporter-ui/src/components/Chart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,34 @@ import { ApexOptions } from "apexcharts";
import { getColorPalette } from "../theme/colors";
import { POLLING_INTERVAL } from "@perf-profiler/types";

type AnnotationInterval = {
y: number;
y2: number;
label: string;
color: string;
};

const getAnnotationInterval = (
annotationIntervalList: AnnotationInterval[] | undefined
) => {
const layout = annotationIntervalList?.map(({ y, y2, label, color }) => ({
y,
y2,
borderColor: color,
fillColor: color,
opacity: 0.2,
label: {
borderColor: color,
style: {
color: "#fff",
background: color,
},
text: label,
},
}));
return layout;
};

const getVideoCurrentTimeAnnotation = () => {
const palette = getColorPalette();
const lastColor = palette[palette.length - 1];
Expand Down Expand Up @@ -72,6 +100,7 @@ export const Chart = ({
maxValue,
showLegendForSingleSeries,
colors = getColorPalette(),
annotationIntervalList = undefined,
}: {
title: string;
series: { name: string; data: { x: number; y: number }[] }[];
Expand All @@ -81,6 +110,7 @@ export const Chart = ({
maxValue?: number;
showLegendForSingleSeries?: boolean;
colors?: string[];
annotationIntervalList?: AnnotationInterval[];
}) => {
const setVideoCurrentTimeOnMouseHover = useSetVideoTimeOnMouseHover({
series,
Expand All @@ -107,6 +137,7 @@ export const Chart = ({
},
annotations: {
xaxis: videoEnabled ? [getVideoCurrentTimeAnnotation()] : [],
yaxis: getAnnotationInterval(annotationIntervalList),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

eslint is saying you need to add the annotationIntervalList to the array of deps

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The eslint config and prettier is a little weird isn't it ? It does the prettier only after the push...

},
title: {
text: title,
Expand Down Expand Up @@ -154,6 +185,7 @@ export const Chart = ({
interval,
videoEnabled,
setVideoCurrentTimeOnMouseHover,
annotationIntervalList,
timeLimit,
maxValue,
colors,
Expand Down
10 changes: 10 additions & 0 deletions packages/web-reporter-ui/src/sections/CPUReport.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,14 @@ const buildAverageCpuSeriesData = (measures: Measure[]) =>
const buildCpuPerThreadSeriesData = (measures: Measure[], threadName: string) =>
buildSeriesData(measures, (measure) => measure.cpu.perName[threadName]);

const totalCpuAnnotationInterval = [
{ y: 300, y2: 1000, color: "#E62E2E", label: "Danger Zone" },
];

const perThreadCpuAnnotationInterval = [
{ y: 90, y2: 100, color: "#E62E2E", label: "Danger Zone" },
];

export const CPUReport = ({
results,
}: {
Expand Down Expand Up @@ -61,6 +69,7 @@ export const CPUReport = ({
height={500}
interval={POLLING_INTERVAL}
series={totalCPUUsage}
annotationIntervalList={totalCpuAnnotationInterval}
/>
<Chart
title="CPU Usage per thread (%)"
Expand All @@ -74,6 +83,7 @@ export const CPUReport = ({
}
maxValue={100}
showLegendForSingleSeries
annotationIntervalList={perThreadCpuAnnotationInterval}
/>
<Collapsible
unmountOnExit
Expand Down
5 changes: 5 additions & 0 deletions packages/web-reporter-ui/src/sections/FPSReport.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ import { AveragedTestCaseResult, POLLING_INTERVAL } from "@perf-profiler/types";
import { Chart } from "../components/Chart";
import { roundToDecimal } from "../../utils/roundToDecimal";

const fpsAnnotationInterval = [
{ y: 57, y2: 60, color: "#158000", label: "Safe Zone" },
];

export const FPSReport = ({
results,
}: {
Expand All @@ -24,6 +28,7 @@ export const FPSReport = ({
height={500}
interval={POLLING_INTERVAL}
series={ram}
annotationIntervalList={fpsAnnotationInterval}
/>
);
};