All files / libs/lti/components/src/lib/enrollment/kpi-structure-widget KpiProportionsProgressBar.tsx

0% Statements 0/87
0% Branches 0/1
0% Functions 0/1
0% Lines 0/87

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88                                                                                                                                                                               
import { css } from '@emotion/react';
import { memo, useMemo } from 'react';
import { Bar, BarChart, ResponsiveContainer, XAxis, YAxis } from 'recharts';

import { Stack } from '@allshares/studio-design-system';
import { type LtiPlan as LtiPlanBase } from '@amalia/lti/types';
import { ChartSvgDefinitions, useChartColor } from '@amalia/reporting/dashboards-v2/components';

interface KpiProportionsProgressBarProps {
  readonly kpis: LtiPlanBase['kpis'];
}

export const KpiProportionsProgressBar = memo(function KpiProportionsProgressBar({
  kpis,
}: KpiProportionsProgressBarProps) {
  const chartColors = useChartColor();

  const data = useMemo(
    () => [
      {
        index: 0,
        ...kpis.reduce(
          (acc, curr) => {
            acc[curr.id] = curr.weight;
            return acc;
          },
          {} as Record<string, number>,
        ),
      },
    ],
    [kpis],
  );

  return (
    <Stack
      css={css`
        height: 100%;
      `}
    >
      <ResponsiveContainer height={16}>
        <BarChart
          barGap={0}
          data={data}
          layout="vertical"
          margin={{ top: 0, right: 0, bottom: 0, left: 0 }}
        >
          <ChartSvgDefinitions />

          <XAxis
            allowDataOverflow
            hide
            axisLine={false}
            dataKey="progress"
            domain={[0, 1]}
            height={0}
            interval={0}
            orientation="bottom"
            shapeRendering="crispEdges"
            type="number"
            width={0}
            xAxisId="value"
          />

          <YAxis
            hide
            axisLine={false}
            dataKey="index"
            height={0}
            type="category"
            width={0}
          />

          {kpis.map((kpi) => (
            <Bar
              key={kpi.id}
              barSize={40}
              dataKey={kpi.id}
              fill={chartColors[kpi.color]}
              stackId="stack"
              xAxisId="value"
            />
          ))}
        </BarChart>
      </ResponsiveContainer>
    </Stack>
  );
});