# @cloud-ru/ds-uikit-product-charts > Продуктовые графики — кольцо заполненности BagelChart, круговая диаграмма PieChart с легендами, тепловая карта HeatMapChart и интерактивный график InteractiveChart на uPlot. Docs: /snack-v2/components/uikit-product-charts/ ## Установка ```sh pnpm add @cloud-ru/ds-uikit-product-charts ``` ## API ### BagelChart | Prop | Type | Default | Required | Description | |------|------|---------|----------|-------------| | `className` | `string` | — | no | CSS-класс корня | | `data-test-id` | `string` | — | no | | | `title` | `ReactNode` | — | no | Заголовок над кольцом | | `total` | `number` | — | yes | Общий объём, от которого считается заполненность | | `value` | `number` | — | yes | Занятое значение. Определяет длину сегмента и его цвет: до 50% — зелёный, до 75% — жёлтый, выше — красный | ### HeatMapChart | Prop | Type | Default | Required | Description | |------|------|---------|----------|-------------| | `className` | `string` | — | no | CSS-класс корня | | `data` | `number[][]` | — | yes | Матрица значений: строки × столбцы | | `data-test-id` | `string` | — | no | | | `options` | `HeatMapChartOptions` | — | yes | Настройки отображения | ### InteractiveChart | Prop | Type | Default | Required | Description | |------|------|---------|----------|-------------| | `className` | `string` | — | no | CSS-класс корня | | `data` | `AlignedData` | — | yes | Данные в формате uPlot: первый массив — значения оси X, остальные — серии | | `data-test-id` | `string` | — | no | | | `options` | `Partial` | — | no | Опции uPlot, которые глубоко сливаются поверх базовой конфигурации `type` | | `type` | `boxPlot \| default` | `default` | no | Базовая конфигурация графика | ### Legend | Prop | Type | Default | Required | Description | |------|------|---------|----------|-------------| | `data` | `T[]` | — | yes | | | `data-test-id` | `string` | — | yes | | | `itemTestId` | `string` | — | yes | | | `onItemClick` | `((item: T) => void)` | — | no | | | `size` | `l \| m \| s` | — | yes | | | `title` | `string` | — | no | | ### Pie | Prop | Type | Default | Required | Description | |------|------|---------|----------|-------------| | `data` | `PieDataItem[]` | — | yes | | | `hoveredIndex` | `number` | — | no | | | `innerRadius` | `number` | — | yes | | | `label` | `LabelRenderFunction` | — | yes | | | `onSegmentHover` | `(index: number \| undefined) => void` | — | yes | | | `onSegmentMouseDown` | `(index: number) => void` | — | yes | | | `radius` | `number` | — | yes | | | `segmentsShift` | `number` | — | yes | | ### PieChart | Prop | Type | Default | Required | Description | |------|------|---------|----------|-------------| | `aggregatedLegend` | `PieChartAggregatedLegend` | — | no | Дополнительная легенда справа от диаграммы — например, сводка по группам | | `className` | `string` | — | no | CSS-класс корня | | `data` | `PieChartDataItem[]` | — | yes | Сегменты диаграммы | | `data-test-id` | `string` | — | no | | | `onLegendItemClick` | `((item: PieChartLegendItem) => void)` | — | no | Колбэк клика по пункту основной легенды | | `onPieSegmentClick` | `((item: PieChartDataItem) => void)` | — | no | Колбэк клика по сегменту | | `options` | `PieChartOptions` | — | yes | Настройки отображения | ## Примеры ### AggregatedLegend ```tsx import { PieChart } from '@cloud-ru/ds-uikit-product-charts'; import { useState } from 'react'; const DATA = [ { id: 'compute', label: 'Compute', value: 420 }, { id: 'storage', label: 'Object Storage', value: 310 }, { id: 'network', label: 'Network', value: 180 }, { id: 'kubernetes', label: 'Managed Kubernetes', value: 150 }, { id: 'databases', label: 'Databases', value: 95 }, { id: 'other', label: 'Other services', value: 45 }, ]; const GROUPS = [ { id: 'infrastructure', label: 'Infrastructure', value: 910 }, { id: 'platform', label: 'Platform', value: 245 }, { id: 'other', label: 'Other', value: 45 }, ]; type GroupItem = { label: string | number }; export function AggregatedLegend() { const [group, setGroup] = useState(); return (
Группа: {group ? group.label : 'не выбрана'}
); } ``` ### BoxPlot ```tsx import { InteractiveChart } from '@cloud-ru/ds-uikit-product-charts'; type ChartProps = Parameters[0]; // Формат данных box plot: [x, min, q1, median, q3, max]. const DATA: ChartProps['data'] = [ [1, 2, 3, 4, 5, 6], [10, 14, 8, 20, 12, 16], [22, 28, 18, 34, 25, 30], [30, 36, 26, 42, 33, 38], [40, 46, 35, 52, 44, 49], [55, 62, 50, 70, 58, 64], ]; const HEIGHT = 320; const OPTIONS: ChartProps['options'] = { width: 640, height: HEIGHT }; export function BoxPlot() { return ; } ``` ### ClickableSegments ```tsx import { PieChart } from '@cloud-ru/ds-uikit-product-charts'; import { useState } from 'react'; const DATA = [ { id: 'compute', label: 'Compute', value: 420 }, { id: 'storage', label: 'Object Storage', value: 310 }, { id: 'network', label: 'Network', value: 180 }, { id: 'kubernetes', label: 'Managed Kubernetes', value: 150 }, { id: 'databases', label: 'Databases', value: 95 }, ]; type SelectedItem = { label: string | number; value: string | number }; export function ClickableSegments() { const [selected, setSelected] = useState(); return (
Выбрано: {selected ? `${selected.label} — ${selected.value}` : 'ничего'}
); } ``` ### CustomCell ```tsx import { HeatMapChart } from '@cloud-ru/ds-uikit-product-charts'; const DAYS = ['Пн', 'Вт', 'Ср', 'Чт', 'Пт']; const HOURS = ['00:00', '04:00', '08:00', '12:00', '16:00', '20:00']; // Загрузка CPU в процентах: строки — дни, столбцы — часы. const DATA = DAYS.map((_, day) => HOURS.map((__, hour) => ((day * 11 + hour * 17) % 20) * 5)); function formatPercent(value: number) { return `${value}%`; } function renderCell(_x: number, _y: number, value: number) { return value >= 80 ? {formatPercent(value)} : formatPercent(value); } export function CustomCell() { return ( ); } ``` ### MultiSeries ```tsx import { InteractiveChart, useLayer } from '@cloud-ru/ds-uikit-product-charts'; import { useMemo } from 'react'; type ChartProps = Parameters[0]; const WIDTH = 640; const HEIGHT = 320; const POINTS = 40; const X_VALUES = Array.from({ length: POINTS }, (_, index) => index); const DATA: ChartProps['data'] = [ X_VALUES, X_VALUES.map(x => Math.round(50 + 30 * Math.sin(x / 5))), X_VALUES.map(x => Math.round(40 + 20 * Math.cos(x / 7))), X_VALUES.map(x => Math.round(20 + 10 * Math.sin(x / 3))), ]; export function MultiSeries() { const cpu = useLayer({ label: 'CPU', color: 'blue1', drawStyle: 'line', lineInterpolation: 'spline' }); const memory = useLayer({ label: 'RAM', color: 'green1', drawStyle: 'line', lineInterpolation: 'stepAfter' }); const disk = useLayer({ label: 'Disk', color: 'violet2', drawStyle: 'bars' }); // Первая серия — ось X, остальные совпадают по порядку с массивами данных. const options = useMemo( () => ({ width: WIDTH, height: HEIGHT, series: [{}, cpu, memory, disk] }), [cpu, memory, disk], ); return ; } ``` ### QuotaUsage ```tsx import { BagelChart } from '@cloud-ru/ds-uikit-product-charts'; const QUOTAS = [ { title: 'vCPU', value: 32, total: 128 }, { title: 'RAM, GB', value: 180, total: 256 }, { title: 'SSD, GB', value: 920, total: 1000 }, ]; export function QuotaUsage() { return ( // Кольцо заполняет ширину контейнера: колонки сетки задают его размер.
{QUOTAS.map(quota => ( ))}
); } ```