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 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 | import { css, useTheme } from '@emotion/react'; import { memo, useMemo } from 'react'; import { Bar, BarChart, ReferenceLine, ResponsiveContainer, XAxis, YAxis } from 'recharts'; import { Stack, useColorSchemeContext } from '@allshares/studio-design-system'; import { ChartSvgDefinitions, useChartColor } from '@amalia/reporting/dashboards-v2/components'; import { type ChartColor } from '@amalia/reporting/dashboards-v2/types'; interface LtiPlanProgressBarProps { readonly done: number; readonly granted: number; readonly color: ChartColor; } export const LtiPlanProgressBar = memo(function LtiPlanProgressBar({ done, granted, color }: LtiPlanProgressBarProps) { const chartColors = useChartColor(); const theme = useTheme(); const { colorScheme } = useColorSchemeContext(); const domainMax = 1; const data = useMemo(() => { const progress = done / granted; const progressTo100 = 1 - progress; return [ { progress, progressTo100, __background: 0, index: 0, }, ]; }, [done, granted]); return ( <Stack gap={16} css={css` height: 100%; `} > <ResponsiveContainer height={45}> <BarChart data={data} layout="vertical" > <ChartSvgDefinitions /> <XAxis allowDataOverflow hide axisLine={false} dataKey="progress" domain={[0, domainMax]} height={0} interval={0} orientation="bottom" shapeRendering="crispEdges" type="number" xAxisId="value" /> <YAxis hide dataKey="index" type="category" /> {/* Progress. */} <Bar barSize={45} dataKey="progress" fill={chartColors[color]} stackId="stack" xAxisId="value" /> {/* Definition for the stripes background pattern for remaining to 100%. */} <defs> <pattern height="16" id={`bar-stripes-${color}`} patternUnits="userSpaceOnUse" width="13" > <rect fill={chartColors[color]} fillOpacity="0.15" height="16" width="8" x="0" y="0" /> <rect fill="transparent" height="16" width="5" x="8" y="0" /> </pattern> </defs> {/* Remaining to 100% */} <Bar barSize={45} dataKey="progressTo100" fill={`url(#bar-stripes-${color})`} stackId="stack" xAxisId="value" /> {/* Background. */} <Bar barSize={45} dataKey="__background" fill={colorScheme === 'dark' ? theme.ds.colors.dark[700] : theme.ds.colors.gray[50]} stackId="stack" xAxisId="value" /> <ReferenceLine shapeRendering="crispEdges" stroke={colorScheme === 'dark' ? theme.ds.colors.gray[200] : theme.ds.colors.gray[800]} strokeWidth={2} x={1} xAxisId="value" /> </BarChart> </ResponsiveContainer> </Stack> ); }); |