-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(Chart): separate chart components for report and evolution (#190)
* feat(Chart): add formatter prop * refacto(LineSeriesType): extract subtypes * feat(Chart): add onPointClick prop * fix(Chart): express x axis type as category * feat(ChartRangeArea): add formatter * fix(ChartRangeArea): specify x axis type as category * refacto(Chart): remove unused interval prop * refacto(Chart): extract common options * refacto(Chart): remove redundant chart type * refacto(Chart): extract base chart component * refacto(Chart): simplify formatter * refacto(BaseChart): introduce type prop * refacto(ChartRangeArea): use BaseChart * refacto(ChartRangeArea): remove report logic * refacto(ChartRangeArea): remove unused prop * refacto(Chart): rename components * feat(index): export ApexOptions type * refacto(DeprecatedChart): remove evolution components * refacto(DeprecatedChart): rename to ReportChart * refacto(ReportChart): move to own file
- Loading branch information
Showing
8 changed files
with
135 additions
and
113 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
80 changes: 80 additions & 0 deletions
80
packages/core/web-reporter-ui/src/components/Charts/ReportChart.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
import React, { useMemo, useContext } from "react"; | ||
import { VideoEnabledContext } from "../../../videoCurrentTimeContext"; | ||
import { ApexOptions } from "apexcharts"; | ||
import { getColorPalette } from "../../theme/colors"; | ||
import { getLastX, useSetVideoTimeOnMouseHover } from "./useSetVideoTimeOnMouseHover"; | ||
import { AnnotationInterval, LineSeriesType } from "./types"; | ||
import { getAnnotations } from "./getAnnotations"; | ||
import { Chart } from "./Chart"; | ||
|
||
export const ReportChart = ({ | ||
title, | ||
series, | ||
height, | ||
timeLimit, | ||
maxValue, | ||
showLegendForSingleSeries, | ||
colors = getColorPalette(), | ||
annotationIntervalList = undefined, | ||
formatter, | ||
onPointClick, | ||
}: { | ||
title: string; | ||
series: LineSeriesType; | ||
height: number; | ||
timeLimit?: number | null; | ||
maxValue?: number; | ||
showLegendForSingleSeries?: boolean; | ||
colors?: string[]; | ||
annotationIntervalList?: AnnotationInterval[]; | ||
formatter?: (label: string) => string; | ||
onPointClick?: (seriesIndex: number, dataPointIndex: number) => void; | ||
}) => { | ||
const setVideoCurrentTimeOnMouseHover = useSetVideoTimeOnMouseHover({ | ||
lastX: getLastX(series), | ||
}); | ||
|
||
const videoEnabled = useContext(VideoEnabledContext); | ||
|
||
const options: ApexOptions = useMemo( | ||
() => ({ | ||
chart: { | ||
events: videoEnabled ? setVideoCurrentTimeOnMouseHover : {}, | ||
}, | ||
annotations: getAnnotations(annotationIntervalList) || {}, | ||
stroke: { | ||
width: 2, | ||
}, | ||
xaxis: { | ||
type: "numeric", | ||
max: timeLimit || undefined, | ||
}, | ||
yaxis: { | ||
min: 0, | ||
max: maxValue, | ||
}, | ||
legend: { | ||
showForSingleSeries: showLegendForSingleSeries, | ||
}, | ||
}), | ||
[ | ||
videoEnabled, | ||
setVideoCurrentTimeOnMouseHover, | ||
annotationIntervalList, | ||
timeLimit, | ||
maxValue, | ||
showLegendForSingleSeries, | ||
] | ||
); | ||
|
||
return ( | ||
<Chart | ||
type="line" | ||
title={title} | ||
series={series} | ||
colors={colors} | ||
height={height} | ||
options={options} | ||
/> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,13 @@ | ||
import React from "react"; | ||
import { AveragedTestCaseResult, POLLING_INTERVAL } from "@perf-profiler/types"; | ||
import { Chart } from "../components/Charts/Chart"; | ||
import { AveragedTestCaseResult } from "@perf-profiler/types"; | ||
import { buildValueGraph } from "./hideSectionForEmptyValue"; | ||
import { ReportChart } from "../components/Charts/ReportChart"; | ||
|
||
export const RAMReport = ({ results }: { results: AveragedTestCaseResult[] }) => { | ||
const ram = buildValueGraph({ | ||
results, | ||
stat: "ram", | ||
}); | ||
|
||
return ( | ||
<> | ||
<Chart title="RAM Usage (MB)" height={500} interval={POLLING_INTERVAL} series={ram} /> | ||
</> | ||
); | ||
return <ReportChart title="RAM Usage (MB)" height={500} series={ram} />; | ||
}; |