@tduniec/backstage-plugin-time-saver
Version:
This plugin provides an implementation of charts and statistics related to your time savings that are coming from usage of your templates. Plugins is built from frontend and backend part. This part of plugin `frontend` is responsible of providing views wi
66 lines (63 loc) • 1.98 kB
JavaScript
import React__default, { useState, useEffect } from 'react';
import { Chart, Title, Tooltip, ArcElement } from 'chart.js';
import { Pie } from 'react-chartjs-2';
import { useApi, configApiRef, fetchApiRef } from '@backstage/core-plugin-api';
import { createUrlWithDates, getRandomColor } from '../utils.esm.js';
import CircularProgress from '@material-ui/core/CircularProgress';
import { useTheme } from '@material-ui/core';
Chart.register(Title, Tooltip, ArcElement);
function GroupDivisionPieChart({
dates
}) {
const configApi = useApi(configApiRef);
const fetchApi = useApi(fetchApiRef);
const [data, setData] = useState(null);
const theme = useTheme();
useEffect(() => {
fetchApi.fetch(
createUrlWithDates(
`${configApi.getString(
"backend.baseUrl"
)}/api/time-saver/getStats/group`,
dates
)
).then((response) => response.json()).then((dt) => setData(dt)).catch();
}, [configApi, fetchApi, dates]);
if (!data) {
return /* @__PURE__ */ React__default.createElement(CircularProgress, null);
}
const options = {
plugins: {
legend: {
labels: {
color: theme.palette.text.primary
}
},
title: {
display: true,
text: "Team Percentage Distribution",
color: theme.palette.text.primary
}
},
responsive: true
};
const labels = data.stats.map((stat) => stat.team);
const percentages = data.stats.map((stat) => parseFloat(stat.percentage));
const backgroundColors = Array.from(
{ length: labels.length },
() => getRandomColor()
);
const dataAll = {
labels,
datasets: [
{
data: percentages,
backgroundColor: backgroundColors,
hoverBackgroundColor: backgroundColors
}
]
};
return /* @__PURE__ */ React__default.createElement(Pie, { options, data: dataAll });
}
export { GroupDivisionPieChart };
//# sourceMappingURL=GroupDivisionPieChartComponent.esm.js.map