UNPKG

@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

67 lines (64 loc) 1.96 kB
import { jsx } from 'react/jsx-runtime'; import { 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__ */ jsx(CircularProgress, {}); } 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__ */ jsx(Pie, { options, data: dataAll }); } export { GroupDivisionPieChart }; //# sourceMappingURL=GroupDivisionPieChartComponent.esm.js.map