2023-06-16 13:38:39 +03:00
|
|
|
import Graph from 'components/Graph';
|
|
|
|
|
import Spinner from 'components/Spinner';
|
2023-07-06 14:22:44 +03:00
|
|
|
import getChartData, { GetChartDataProps } from 'lib/getChartData';
|
|
|
|
|
import { colors } from 'lib/getRandomColor';
|
2023-06-23 11:19:53 +03:00
|
|
|
import { memo, useMemo } from 'react';
|
2023-06-16 13:38:39 +03:00
|
|
|
|
2023-07-06 14:22:44 +03:00
|
|
|
import { LogsExplorerChartProps } from './LogsExplorerChart.interfaces';
|
2023-06-16 13:38:39 +03:00
|
|
|
import { CardStyled } from './LogsExplorerChart.styled';
|
|
|
|
|
|
2023-07-06 14:22:44 +03:00
|
|
|
function LogsExplorerChart({
|
|
|
|
|
data,
|
|
|
|
|
isLoading,
|
|
|
|
|
}: LogsExplorerChartProps): JSX.Element {
|
|
|
|
|
const handleCreateDatasets: Required<GetChartDataProps>['createDataset'] = (
|
|
|
|
|
element,
|
|
|
|
|
index,
|
|
|
|
|
allLabels,
|
|
|
|
|
) => ({
|
|
|
|
|
label: allLabels[index],
|
|
|
|
|
data: element,
|
|
|
|
|
backgroundColor: colors[index % colors.length] || 'red',
|
|
|
|
|
borderColor: colors[index % colors.length] || 'red',
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
const graphData = useMemo(
|
|
|
|
|
() =>
|
|
|
|
|
getChartData({
|
|
|
|
|
queryData: [
|
|
|
|
|
{
|
|
|
|
|
queryData: data,
|
|
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
createDataset: handleCreateDatasets,
|
|
|
|
|
}),
|
|
|
|
|
[data],
|
2023-06-16 13:38:39 +03:00
|
|
|
);
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<CardStyled>
|
2023-07-06 14:22:44 +03:00
|
|
|
{isLoading ? (
|
2023-06-16 13:38:39 +03:00
|
|
|
<Spinner size="default" height="100%" />
|
|
|
|
|
) : (
|
|
|
|
|
<Graph
|
|
|
|
|
name="logsExplorerChart"
|
|
|
|
|
data={graphData}
|
|
|
|
|
type="bar"
|
|
|
|
|
containerHeight="100%"
|
|
|
|
|
animate
|
|
|
|
|
/>
|
|
|
|
|
)}
|
|
|
|
|
</CardStyled>
|
|
|
|
|
);
|
|
|
|
|
}
|
2023-06-23 11:19:53 +03:00
|
|
|
|
|
|
|
|
export default memo(LogsExplorerChart);
|