ActiveActionsChart.jsx 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. // components
  2. import Spring from '@components/Spring';
  3. import ClubInfo from '@components/ClubInfo';
  4. import TabButton from '@ui/TabButton';
  5. import {ResponsiveContainer, BarChart, Bar, XAxis, CartesianGrid, Tooltip} from 'recharts';
  6. import ChartTooltip from '@ui/ChartTooltip';
  7. // hooks
  8. import {useState, useEffect} from 'react';
  9. import {useThemeProvider} from '@contexts/themeContext';
  10. import {useWindowSize} from 'react-use';
  11. // utils
  12. import {generateGridPoints} from '@utils/helpers';
  13. const data = {
  14. first: [
  15. {label: 'GK', a: 12, b: 23},
  16. {label: 'LB', a: 17, b: 34},
  17. {label: 'CB', a: 28, b: 18},
  18. {label: 'CB', a: 15, b: 27},
  19. {label: 'RB', a: 19, b: 31},
  20. {label: 'CM', a: 20, b: 25},
  21. {label: 'CM', a: 22, b: 16},
  22. {label: 'CAM', a: 30, b: 35},
  23. {label: 'LW', a: 14, b: 26},
  24. {label: 'RW', a: 24, b: 11},
  25. {label: 'ST', a: 33, b: 29}
  26. ],
  27. second: [
  28. {label: 'GK', a: 21, b: 32},
  29. {label: 'LB', a: 16, b: 36},
  30. {label: 'CB', a: 13, b: 45},
  31. {label: 'CB', a: 37, b: 42},
  32. {label: 'RB', a: 44, b: 41},
  33. {label: 'CM', a: 40, b: 46},
  34. {label: 'CM', a: 47, b: 38},
  35. {label: 'CAM', a: 43, b: 48},
  36. {label: 'LW', a: 39, b: 20},
  37. {label: 'RW', a: 26, b: 15},
  38. {label: 'ST', a: 28, b: 30}
  39. ]
  40. }
  41. const ActiveActionsChart = () => {
  42. const [selectedHalf, setSelectedHalf] = useState('first');
  43. const {direction} = useThemeProvider();
  44. const {width} = useWindowSize();
  45. const [points, setPoints] = useState([]);
  46. const isRTL = direction === 'rtl';
  47. useEffect(() => {
  48. setPoints(generateGridPoints('activeActionsChart', 20, 'x'));
  49. }, [width]);
  50. return (
  51. <Spring className="card h-2 d-flex flex-column g-30 card-padded">
  52. <div className="d-flex flex-column g-20">
  53. <ClubInfo id="tottenham" title="Active actions" subtitle="Tottenham, London"/>
  54. <div className="tab-nav col-2">
  55. <TabButton
  56. title="First half"
  57. active={selectedHalf === 'first'}
  58. onClick={() => setSelectedHalf('first')}
  59. />
  60. <TabButton
  61. title="Second half"
  62. active={selectedHalf === 'second'}
  63. onClick={() => setSelectedHalf('second')}
  64. />
  65. </div>
  66. </div>
  67. <ResponsiveContainer className="flex-1" width="100%" height="100%" id="activeActionsChart">
  68. <BarChart data={data[selectedHalf]} margin={false}>
  69. <defs>
  70. <linearGradient id="grid" x1="769.75" y1="-0.442191" x2="-0.783631" y2="-0.442191" gradientUnits="userSpaceOnUse">
  71. <stop stopColor="var(--border)" stopOpacity="0.2"/>
  72. <stop offset="0.504355" stopColor="var(--border)"/>
  73. <stop offset="0.99905" stopColor="var(--border)" stopOpacity="0.257922"/>
  74. </linearGradient>
  75. </defs>
  76. <CartesianGrid vertical={false} horizontalPoints={points} strokeDasharray="3 3" stroke="url(#grid)"/>
  77. <XAxis dataKey="label"
  78. tickLine={false}
  79. axisLine={false}
  80. reversed={isRTL}
  81. style={{
  82. fontFamily: 'var(--heading-font)',
  83. fontSize: '0.5rem',
  84. fontWeight: 600,
  85. }}/>
  86. <Tooltip cursor={false} content={<ChartTooltip multi/>}/>
  87. <Bar dataKey="a" stackId="a" fill="var(--orange)" barSize={8} />
  88. <Bar dataKey="b" stackId="a" fill="var(--grass)" barSize={8}/>
  89. </BarChart>
  90. </ResponsiveContainer>
  91. </Spring>
  92. )
  93. }
  94. export default ActiveActionsChart