Обновлен компонент Bar для визуализации данных с нормализацией цветов на основе максимального значения. Добавлены новые стили для tooltip и сетки, улучшены параметры анимации. Обновлен файл mock данных с добавлением новых уроков и студентов, улучшена структура данных.

This commit is contained in:
Primakov Alexandr Alexandrovich 2025-03-23 23:33:23 +03:00
parent c92be3d7dd
commit 5f836ea6b4
2 changed files with 1648 additions and 601 deletions

View File

@ -1,9 +1,14 @@
import React from 'react'
import { type BarDatum, ResponsiveBar } from '@nivo/bar'
import { useTranslation } from 'react-i18next'
import { useColorMode } from '@chakra-ui/react'
export const Bar = ({ data }: { data: BarDatum[] }) => {
const { t } = useTranslation()
const { colorMode } = useColorMode()
// Находим максимальное значение для нормализации цветов
const maxValue = Math.max(...data.map(item => (item.count as number)))
return (
<ResponsiveBar
@ -11,18 +16,46 @@ export const Bar = ({ data }: { data: BarDatum[] }) => {
keys={['count']}
indexBy="lessonIndex"
margin={{ top: 50, right: 130, bottom: 50, left: 60 }}
padding={0.3}
padding={0.4}
valueScale={{ type: 'linear' }}
indexScale={{ type: 'band', round: true }}
colors={{ scheme: 'set3' }}
colors={(bar) => {
// Нормализованное значение от 0 до 1
const normalized = (bar.data.count as number) / maxValue
// Красный при низких значениях, зеленый при высоких
const r = Math.round(255 * (1 - normalized))
const g = Math.round(255 * normalized)
const b = 100 // Немного синего, чтобы цвета не были слишком резкими
return `rgb(${r}, ${g}, ${b})`
}}
theme={{
tooltip: {
container: {
background: colorMode === 'dark' ? '#2D3748' : '#ffffff',
color: colorMode === 'dark' ? '#ffffff' : '#333333',
fontSize: 14,
borderRadius: 8,
boxShadow: '0 4px 10px rgba(0, 0, 0, 0.1)',
},
},
grid: {
line: {
stroke: colorMode === 'dark' ? '#4A5568' : '#e0e0e0',
strokeWidth: 1,
},
},
}}
borderRadius={4}
borderWidth={1}
borderColor={{ from: 'color', modifiers: [['darker', 0.3]] }}
axisTop={null}
axisRight={null}
labelSkipWidth={12}
labelSkipHeight={12}
labelTextColor={{
from: 'color',
modifiers: [['brighter', 1.4]],
}}
labelTextColor={colorMode === 'dark' ? '#ffffff' : '#333333'}
animate={true}
motionConfig="gentle"
enableGridY={false}
role="application"
ariaLabel={t('journal.pl.lesson.attendanceChart')}
barAriaLabel={(e) =>

File diff suppressed because it is too large Load Diff