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]: Added Y-axis unit support for uplots graphs. #3813

Closed
Closed
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
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,12 @@ function FullView({
const containerDimensions = useDimensions(fullViewRef);
const isDarkMode = useIsDarkMode();

const chartOptions = getUPlotChartOptions(
response.data?.payload.data.newResult.data,
containerDimensions,
const chartOptions = getUPlotChartOptions({
yAxisUnit: yAxisUnit || '',
apiResponse: response.data?.payload.data.newResult.data,
dimensions: containerDimensions,
isDarkMode,
);
});

useEffect(() => {
if (!response.isFetching && lineChartRef.current) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,12 +174,14 @@ function WidgetGraphComponent({

const options = useMemo(
() =>
getUPlotChartOptions(
queryResponse?.data?.payload?.data?.newResult?.data,
containerDimensions,
getUPlotChartOptions({
yAxisUnit: widget.yAxisUnit || '',
apiResponse: queryResponse?.data?.payload?.data?.newResult?.data,
dimensions: containerDimensions,
isDarkMode,
),
}),
[
widget.yAxisUnit,
queryResponse?.data?.payload?.data?.newResult?.data,
containerDimensions,
isDarkMode,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,17 @@ function WidgetGraph({

const options = useMemo(
() =>
getUPlotChartOptions(
getWidgetQueryRange?.data?.payload?.data?.newResult?.data,
containerDimensions,
getUPlotChartOptions({
yAxisUnit,
apiResponse: getWidgetQueryRange?.data?.payload?.data?.newResult?.data,
dimensions: containerDimensions,
isDarkMode,
),
}),
[
getWidgetQueryRange?.data?.payload?.data?.newResult?.data,
containerDimensions,
isDarkMode,
yAxisUnit,
],
);

Expand Down
24 changes: 15 additions & 9 deletions frontend/src/lib/getUplotChartData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,20 @@ const getGridColor = (isDarkMode: boolean): string => {
return 'rgba(231,233,237,0.8)';
};

export const getUPlotChartOptions = (
apiResponse?: MetricRangePayloadV3['data'],
dimensions: Dimensions = { height: 0, width: 0 },
type GetUPlotChartOptions = {
yAxisUnit: string;
apiResponse?: MetricRangePayloadV3['data'];
dimensions?: Dimensions;
isDarkMode?: boolean;
};

export const getUPlotChartOptions = ({
yAxisUnit,
apiResponse,
dimensions = { height: 0, width: 0 },
isDarkMode = false,
// eslint-disable-next-line arrow-body-style
): uPlot.Options => {
}: GetUPlotChartOptions): // eslint-disable-next-line arrow-body-style
uPlot.Options => {
// console.log('getUPlotChartOptions');

return {
Expand All @@ -91,7 +99,6 @@ export const getUPlotChartOptions = (
show: true,
},
ticks: {
stroke: 'white', // Color of the tick lines
width: 0.3, // Width of the tick lines,
show: true,
},
Expand All @@ -105,10 +112,9 @@ export const getUPlotChartOptions = (
dash: [10, 10], // Dash pattern for grid lines,
width: 0.3, // Width of the grid lines
},
ticks: {
stroke: 'white', // Color of the tick lines
},
ticks: {},
gap: 5,
values: (_, t): string[] => t.map((v) => `${v}${yAxisUnit}`),
},
],
};
Expand Down
Loading