Merge pull request 'Сглаживающая линия' (#28) from dev into main
Reviewed-on: #28
This commit was merged in pull request #28.
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
branch=
|
BRANCH=
|
||||||
DEV_API_URL=http://localhost:3101
|
#DEV_API_URL=http://localhost:3101
|
||||||
|
DEV_API_URL=https://beta.drill.greact.ru
|
||||||
VITE_DIAGRAM_API_URL=http://localhost:3002
|
VITE_DIAGRAM_API_URL=http://localhost:3002
|
||||||
VITE_TOIR_LIGHT_ORIGIN=https://toir-light.greact.ru
|
VITE_TOIR_LIGHT_ORIGIN=https://toir-light.greact.ru
|
||||||
VITE_KEYCLOAK_URL=https://sso.greact.ru
|
VITE_KEYCLOAK_URL=https://sso.greact.ru
|
||||||
|
|||||||
@@ -4,6 +4,8 @@ import { useRef } from 'react';
|
|||||||
import { CalendarDays, CalendarClock, Check, ChevronDown, Clock3, DatabaseZap, Search } from 'lucide-react';
|
import { CalendarDays, CalendarClock, Check, ChevronDown, Clock3, DatabaseZap, Search } from 'lucide-react';
|
||||||
import type { CurrentItem } from '../../../entities/current/types';
|
import type { CurrentItem } from '../../../entities/current/types';
|
||||||
import { HistoryChart } from '../../../features/history-chart/HistoryChart';
|
import { HistoryChart } from '../../../features/history-chart/HistoryChart';
|
||||||
|
import { HistoryChartAvgLineModeControl } from '../../../features/history-chart/HistoryChartAvgLineModeControl';
|
||||||
|
import type { AvgLineMode } from '../../../features/history-chart/chartTypes';
|
||||||
import { RANGE_PRESETS, createRange, type DateRangeState } from '../../../features/history/dateRange';
|
import { RANGE_PRESETS, createRange, type DateRangeState } from '../../../features/history/dateRange';
|
||||||
import { formatNumber, toIsoFromInput } from '../../../utils/format';
|
import { formatNumber, toIsoFromInput } from '../../../utils/format';
|
||||||
import type { HistoryGranularity } from '../../../utils/historyGranularity';
|
import type { HistoryGranularity } from '../../../utils/historyGranularity';
|
||||||
@@ -93,6 +95,8 @@ export function ArchiveView({
|
|||||||
onSelectVisibleTags,
|
onSelectVisibleTags,
|
||||||
onToggleTag,
|
onToggleTag,
|
||||||
}: ArchiveViewProps) {
|
}: ArchiveViewProps) {
|
||||||
|
const [avgLineMode, setAvgLineMode] = useState<AvgLineMode>('auto');
|
||||||
|
const [selectedRangePresetId, setSelectedRangePresetId] = useState<string>('24h');
|
||||||
const [selectorOpen, setSelectorOpen] = useState(false);
|
const [selectorOpen, setSelectorOpen] = useState(false);
|
||||||
const selectedPreview = selectedTags.slice(0, 10);
|
const selectedPreview = selectedTags.slice(0, 10);
|
||||||
const hiddenSelectedCount = Math.max(0, selectedTags.length - selectedPreview.length);
|
const hiddenSelectedCount = Math.max(0, selectedTags.length - selectedPreview.length);
|
||||||
@@ -103,6 +107,7 @@ export function ArchiveView({
|
|||||||
const fromIso = toIsoFromInput(range.from) as string;
|
const fromIso = toIsoFromInput(range.from) as string;
|
||||||
const toIso = toIsoFromInput(range.to) as string;
|
const toIso = toIsoFromInput(range.to) as string;
|
||||||
const updateRangePart = (rangePart: RangePart, inputPart: RangeInputPart, value: string) => {
|
const updateRangePart = (rangePart: RangePart, inputPart: RangeInputPart, value: string) => {
|
||||||
|
setSelectedRangePresetId('');
|
||||||
onRangeChange({
|
onRangeChange({
|
||||||
...range,
|
...range,
|
||||||
[rangePart]: updateRangeInputPart(range[rangePart], inputPart, value),
|
[rangePart]: updateRangeInputPart(range[rangePart], inputPart, value),
|
||||||
@@ -149,14 +154,14 @@ export function ArchiveView({
|
|||||||
<input value={search} onChange={(event) => onSearchChange(event.target.value)} placeholder="Поиск" />
|
<input value={search} onChange={(event) => onSearchChange(event.target.value)} placeholder="Поиск" />
|
||||||
</label>
|
</label>
|
||||||
<div className="tag-selector__tools">
|
<div className="tag-selector__tools">
|
||||||
<button type="button" onClick={onSelectFirstTags}>
|
{/* <button type="button" onClick={onSelectFirstTags}>
|
||||||
Первый
|
Первый
|
||||||
</button>
|
</button> */}
|
||||||
<button type="button" onClick={onSelectVisibleTags}>
|
<button type="button" onClick={onSelectVisibleTags}>
|
||||||
Выбрать найденный
|
Выбрать все
|
||||||
</button>
|
</button>
|
||||||
<button type="button" onClick={onClearVisibleTags}>
|
<button type="button" onClick={onClearVisibleTags}>
|
||||||
Снять найденные
|
Снять все
|
||||||
</button>
|
</button>
|
||||||
<button type="button" onClick={onClearTags}>
|
<button type="button" onClick={onClearTags}>
|
||||||
Сбросить все
|
Сбросить все
|
||||||
@@ -209,13 +214,23 @@ export function ArchiveView({
|
|||||||
onPointerEnter={() => setSelectorOpen(false)}
|
onPointerEnter={() => setSelectorOpen(false)}
|
||||||
>
|
>
|
||||||
<div className="toolbar">
|
<div className="toolbar">
|
||||||
<div className="segmented">
|
<div className="archive-toolbar-segmented-control">
|
||||||
|
<div className="segmented segmented--range-preset">
|
||||||
{RANGE_PRESETS.map((preset) => (
|
{RANGE_PRESETS.map((preset) => (
|
||||||
<button key={preset.id} type="button" onClick={() => onRangeChange(createRange(preset.hours))}>
|
<button
|
||||||
|
key={preset.id}
|
||||||
|
type="button"
|
||||||
|
className={preset.id === selectedRangePresetId ? 'segmented__button--active' : undefined}
|
||||||
|
onClick={() => {
|
||||||
|
setSelectedRangePresetId(preset.id);
|
||||||
|
onRangeChange(createRange(preset.hours));
|
||||||
|
}}
|
||||||
|
>
|
||||||
{preset.label}
|
{preset.label}
|
||||||
</button>
|
</button>
|
||||||
))}
|
))}
|
||||||
</div>
|
</div>
|
||||||
|
</div>
|
||||||
<div className="archive-date-range">
|
<div className="archive-date-range">
|
||||||
<span>С</span>
|
<span>С</span>
|
||||||
<DateRangeField
|
<DateRangeField
|
||||||
@@ -250,11 +265,13 @@ export function ArchiveView({
|
|||||||
onChange={(value) => updateRangePart('to', 'time', value)}
|
onChange={(value) => updateRangePart('to', 'time', value)}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
<HistoryChartAvgLineModeControl value={avgLineMode} onChange={setAvgLineMode} />
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{selectedTags.length ? (
|
{selectedTags.length ? (
|
||||||
<HistoryChart
|
<HistoryChart
|
||||||
key={`${range.from}:${range.to}:${historyAxis.granulate}`}
|
key={`${range.from}:${range.to}:${historyAxis.granulate}:${historyAxis.tickIntervalMs ?? ''}`}
|
||||||
|
avgLineMode={avgLineMode}
|
||||||
edge={edgeId}
|
edge={edgeId}
|
||||||
from={fromIso}
|
from={fromIso}
|
||||||
to={toIso}
|
to={toIso}
|
||||||
|
|||||||
@@ -1,13 +1,22 @@
|
|||||||
import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
|
import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
|
||||||
import type { EChartsOption } from 'echarts';
|
import type { EChartsOption } from 'echarts';
|
||||||
import { getHistoryGranularity, type HistoryAxisLabelFormat } from '../../utils/historyGranularity';
|
import { parseGranulateMs, type HistoryAxisLabelFormat } from '../../utils/historyGranularity';
|
||||||
import type { DataZoomEventBatch, DataZoomState, HistoryZoomRange } from './chartTypes';
|
import type { AvgLineMode, DataZoomEventBatch, HistoryZoomRange } from './chartTypes';
|
||||||
import { HistoryChartArea } from './HistoryChartArea';
|
import { HistoryChartArea } from './HistoryChartArea';
|
||||||
import { createHistoryChartOptions } from './historyChartOptions';
|
import { createHistoryChartOptions } from './historyChartOptions';
|
||||||
|
import {
|
||||||
|
createDataZoomState,
|
||||||
|
createInitialZoomRange,
|
||||||
|
getZoomRangeFromEvent,
|
||||||
|
isSameZoomRange,
|
||||||
|
isXAxisDataZoom,
|
||||||
|
ZOOM_REQUEST_DELAY_MS,
|
||||||
|
} from './historyChartZoom';
|
||||||
import { useHistoryChartQueries } from './useHistoryChartQueries';
|
import { useHistoryChartQueries } from './useHistoryChartQueries';
|
||||||
import { useHistoryChartSeries } from './useHistoryChartSeries';
|
import { useHistoryChartSeries } from './useHistoryChartSeries';
|
||||||
|
|
||||||
type HistoryChartProps = {
|
type HistoryChartProps = {
|
||||||
|
avgLineMode: AvgLineMode;
|
||||||
edge: string;
|
edge: string;
|
||||||
from: string;
|
from: string;
|
||||||
granulate: string;
|
granulate: string;
|
||||||
@@ -18,109 +27,23 @@ type HistoryChartProps = {
|
|||||||
tagLabels?: Record<string, string>;
|
tagLabels?: Record<string, string>;
|
||||||
};
|
};
|
||||||
|
|
||||||
const ZOOM_REQUEST_DELAY_MS = 350;
|
const DAY_MS = 24 * 60 * 60 * 1000;
|
||||||
|
|
||||||
function isXAxisDataZoom(state: DataZoomState): boolean {
|
/** Определяет видимость соединительной avg-линии с учетом ручного режима и масштаба X-шкалы. */
|
||||||
return state.dataZoomId?.startsWith('history-x-') || state.dataZoomIndex === 0 || state.dataZoomIndex === 1;
|
function shouldShowAvgLine(mode: AvgLineMode, range: HistoryZoomRange): boolean {
|
||||||
}
|
if (mode === 'show') {
|
||||||
|
return true;
|
||||||
/** Собирает начальный zoom-диапазон из внешних props графика. */
|
|
||||||
function createInitialZoomRange({
|
|
||||||
from,
|
|
||||||
granulate,
|
|
||||||
labelFormat,
|
|
||||||
tickIntervalMs,
|
|
||||||
to,
|
|
||||||
}: Pick<HistoryChartProps, 'from' | 'granulate' | 'labelFormat' | 'tickIntervalMs' | 'to'>): HistoryZoomRange {
|
|
||||||
return { from, to, granulate, labelFormat, tickIntervalMs };
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Создает zoom-диапазон из миллисекунд и подбирает для него грануляцию. */
|
|
||||||
function createZoomRange(fromMs: number, toMs: number): HistoryZoomRange {
|
|
||||||
const from = new Date(fromMs).toISOString();
|
|
||||||
const to = new Date(toMs).toISOString();
|
|
||||||
|
|
||||||
return {
|
|
||||||
from,
|
|
||||||
to,
|
|
||||||
...getHistoryGranularity(from, to),
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Достает подинтервал X-зума из события ECharts. */
|
|
||||||
function getZoomRangeFromEvent(state: DataZoomState, baseRange: HistoryZoomRange): HistoryZoomRange | null {
|
|
||||||
const baseFromMs = new Date(baseRange.from).getTime();
|
|
||||||
const baseToMs = new Date(baseRange.to).getTime();
|
|
||||||
const baseSpanMs = baseToMs - baseFromMs;
|
|
||||||
|
|
||||||
if (!Number.isFinite(baseFromMs) || !Number.isFinite(baseToMs) || baseSpanMs <= 0) {
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const startValue = Number(state.startValue);
|
if (mode === 'hide') {
|
||||||
const endValue = Number(state.endValue);
|
return false;
|
||||||
let nextFromMs = Number.isFinite(startValue) ? startValue : undefined;
|
|
||||||
let nextToMs = Number.isFinite(endValue) ? endValue : undefined;
|
|
||||||
|
|
||||||
// ECharts иногда не передает startValue/endValue, поэтому используем start/end.
|
|
||||||
if (nextFromMs === undefined || nextToMs === undefined) {
|
|
||||||
const start = Number(state.start);
|
|
||||||
const end = Number(state.end);
|
|
||||||
|
|
||||||
if (!Number.isFinite(start) || !Number.isFinite(end)) {
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
nextFromMs = baseFromMs + (baseSpanMs * start) / 100;
|
return (range.tickIntervalMs ?? parseGranulateMs(range.granulate)) < DAY_MS;
|
||||||
nextToMs = baseFromMs + (baseSpanMs * end) / 100;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Проверка на выход из диапазона
|
|
||||||
const fromMs = Math.max(baseFromMs, Math.min(nextFromMs, nextToMs));
|
|
||||||
const toMs = Math.min(baseToMs, Math.max(nextFromMs, nextToMs));
|
|
||||||
|
|
||||||
return toMs > fromMs ? createZoomRange(fromMs, toMs) : null;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Проверяет, что lazy zoom не пытается повторно применить тот же диапазон. */
|
|
||||||
function isSameZoomRange(left: HistoryZoomRange, right: HistoryZoomRange): boolean {
|
|
||||||
return left.from === right.from && left.to === right.to && left.granulate === right.granulate;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Вычисляет, какую часть верхнеуровневого периода занимает текущий пользовательский zoom. */
|
|
||||||
function createDataZoomState(baseRange: HistoryZoomRange, zoomRange: HistoryZoomRange): DataZoomState {
|
|
||||||
// Верхнеуровневый период берём из инпутов "С/По" и считаем его полными 0..100%.
|
|
||||||
const baseFromMs = new Date(baseRange.from).getTime();
|
|
||||||
const baseToMs = new Date(baseRange.to).getTime();
|
|
||||||
|
|
||||||
// Пользовательский zoom живёт внутри верхнеуровневого периода и должен быть выделен на нижней шкале.
|
|
||||||
const zoomFromMs = new Date(zoomRange.from).getTime();
|
|
||||||
const zoomToMs = new Date(zoomRange.to).getTime();
|
|
||||||
const baseSpanMs = baseToMs - baseFromMs;
|
|
||||||
|
|
||||||
// Если даты некорректны, показываем весь период, чтобы не ломать управление графиком.
|
|
||||||
if (
|
|
||||||
!Number.isFinite(baseFromMs) ||
|
|
||||||
!Number.isFinite(baseToMs) ||
|
|
||||||
!Number.isFinite(zoomFromMs) ||
|
|
||||||
!Number.isFinite(zoomToMs) ||
|
|
||||||
baseSpanMs <= 0
|
|
||||||
) {
|
|
||||||
return { start: 0, end: 100 };
|
|
||||||
}
|
|
||||||
|
|
||||||
// Переводим абсолютные даты zoom-а в проценты относительно верхнеуровневого периода.
|
|
||||||
const start = ((zoomFromMs - baseFromMs) / baseSpanMs) * 100;
|
|
||||||
const end = ((zoomToMs - baseFromMs) / baseSpanMs) * 100;
|
|
||||||
|
|
||||||
// Ограничиваем значения диапазоном 0..100, чтобы ECharts не получил выход за шкалу.
|
|
||||||
return {
|
|
||||||
start: Math.max(0, Math.min(100, start)),
|
|
||||||
end: Math.max(0, Math.min(100, end)),
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export function HistoryChart({
|
export function HistoryChart({
|
||||||
|
avgLineMode,
|
||||||
edge,
|
edge,
|
||||||
from,
|
from,
|
||||||
granulate,
|
granulate,
|
||||||
@@ -149,7 +72,8 @@ export function HistoryChart({
|
|||||||
to: zoomRange.to,
|
to: zoomRange.to,
|
||||||
tagLabels,
|
tagLabels,
|
||||||
});
|
});
|
||||||
const series = useHistoryChartSeries(lines, zoomRange.granulate);
|
const showAvgLine = shouldShowAvgLine(avgLineMode, zoomRange);
|
||||||
|
const series = useHistoryChartSeries(lines, zoomRange.granulate, avgLineMode, showAvgLine);
|
||||||
const legendData = useMemo(() => lines.map((line) => line.label), [lines]);
|
const legendData = useMemo(() => lines.map((line) => line.label), [lines]);
|
||||||
const loading = lines.some((line) => line.loading);
|
const loading = lines.some((line) => line.loading);
|
||||||
const hasData = series.length > 0;
|
const hasData = series.length > 0;
|
||||||
@@ -226,6 +150,7 @@ export function HistoryChart({
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<HistoryChartArea
|
<HistoryChartArea
|
||||||
|
avgLineMode={avgLineMode}
|
||||||
hasData={displayHasData}
|
hasData={displayHasData}
|
||||||
hasSelection={tags.length > 0}
|
hasSelection={tags.length > 0}
|
||||||
loading={loading}
|
loading={loading}
|
||||||
|
|||||||
@@ -4,8 +4,10 @@ import { useCallback, useEffect, useMemo, useRef } from 'react';
|
|||||||
import type { WheelEvent } from 'react';
|
import type { WheelEvent } from 'react';
|
||||||
import type { DataZoomEventBatch } from './chartTypes';
|
import type { DataZoomEventBatch } from './chartTypes';
|
||||||
import { echarts } from './historyChartEcharts';
|
import { echarts } from './historyChartEcharts';
|
||||||
|
import type { AvgLineMode } from './chartTypes';
|
||||||
|
|
||||||
type HistoryChartAreaProps = {
|
type HistoryChartAreaProps = {
|
||||||
|
avgLineMode: AvgLineMode;
|
||||||
hasData: boolean;
|
hasData: boolean;
|
||||||
hasSelection: boolean;
|
hasSelection: boolean;
|
||||||
loading: boolean;
|
loading: boolean;
|
||||||
@@ -30,6 +32,7 @@ function setXAxisWheelZoom(chart: ReturnType<ReactEChartsCore['getEchartsInstanc
|
|||||||
|
|
||||||
/** Отвечает только за визуальную область графика: placeholder или ECharts canvas. */
|
/** Отвечает только за визуальную область графика: placeholder или ECharts canvas. */
|
||||||
export function HistoryChartArea({
|
export function HistoryChartArea({
|
||||||
|
avgLineMode,
|
||||||
hasData,
|
hasData,
|
||||||
hasSelection,
|
hasSelection,
|
||||||
loading,
|
loading,
|
||||||
@@ -101,6 +104,7 @@ export function HistoryChartArea({
|
|||||||
return (
|
return (
|
||||||
<div className="history-chart-shell" onWheelCapture={handleWheelCapture}>
|
<div className="history-chart-shell" onWheelCapture={handleWheelCapture}>
|
||||||
<ReactEChartsCore
|
<ReactEChartsCore
|
||||||
|
key={avgLineMode}
|
||||||
ref={chartRef}
|
ref={chartRef}
|
||||||
echarts={echarts}
|
echarts={echarts}
|
||||||
option={option}
|
option={option}
|
||||||
|
|||||||
@@ -0,0 +1,33 @@
|
|||||||
|
import type { AvgLineMode } from './chartTypes';
|
||||||
|
|
||||||
|
type HistoryChartAvgLineModeControlProps = {
|
||||||
|
value: AvgLineMode;
|
||||||
|
onChange: (mode: AvgLineMode) => void;
|
||||||
|
};
|
||||||
|
|
||||||
|
const AVG_LINE_MODES: Array<{ value: AvgLineMode; label: string }> = [
|
||||||
|
{ value: 'auto', label: 'Авто' },
|
||||||
|
{ value: 'show', label: 'Рисовать' },
|
||||||
|
{ value: 'hide', label: 'Скрывать' },
|
||||||
|
];
|
||||||
|
|
||||||
|
export function HistoryChartAvgLineModeControl({ value, onChange }: HistoryChartAvgLineModeControlProps) {
|
||||||
|
return (
|
||||||
|
<div className="archive-toolbar-segmented-control archive-avgline-mode-control" aria-label="Режим соединительной линии avg">
|
||||||
|
<span>Соединительная линия</span>
|
||||||
|
<div className="segmented history-chart-line-mode">
|
||||||
|
{AVG_LINE_MODES.map((mode) => (
|
||||||
|
<button
|
||||||
|
key={mode.value}
|
||||||
|
type="button"
|
||||||
|
className={mode.value === value ? 'segmented__button--active' : undefined}
|
||||||
|
onClick={() => onChange(mode.value)}
|
||||||
|
aria-pressed={mode.value === value}
|
||||||
|
>
|
||||||
|
{mode.label}
|
||||||
|
</button>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -2,7 +2,16 @@ import type { HistoryAxisLabelFormat } from '../../utils/historyGranularity';
|
|||||||
|
|
||||||
export type AvgPointValue = [time: number, avg: number, min: number, max: number, count: number, slotMs?: number];
|
export type AvgPointValue = [time: number, avg: number, min: number, max: number, count: number, slotMs?: number];
|
||||||
|
|
||||||
export type HistoryBucketValue = [time: number, avg: number, min: number, max: number, count: number, slotMs: number];
|
export type HistoryBucketValue = [
|
||||||
|
time: number,
|
||||||
|
avg: number,
|
||||||
|
min: number,
|
||||||
|
max: number,
|
||||||
|
count: number,
|
||||||
|
slotMs: number,
|
||||||
|
];
|
||||||
|
|
||||||
|
export type AvgLineMode = 'auto' | 'show' | 'hide';
|
||||||
|
|
||||||
export type HistoryZoomRange = {
|
export type HistoryZoomRange = {
|
||||||
from: string;
|
from: string;
|
||||||
|
|||||||
92
src/features/history-chart/historyChartAvgLineSeries.ts
Normal file
92
src/features/history-chart/historyChartAvgLineSeries.ts
Normal file
@@ -0,0 +1,92 @@
|
|||||||
|
import type { LineSeriesOption, SeriesOption } from 'echarts';
|
||||||
|
import type { HistoryPoint } from '../../entities/history/types';
|
||||||
|
import { parseGranulateMs } from '../../utils/historyGranularity';
|
||||||
|
import { SERIES_COLORS } from './historyChartSeries';
|
||||||
|
|
||||||
|
type AvgLineSeriesValue = [time: number, avg: number, min: number, max: number, count: number, slotMs: number];
|
||||||
|
type AvgLineSeriesPoint = AvgLineSeriesValue | null;
|
||||||
|
|
||||||
|
function isFinitePoint(point: HistoryPoint): boolean {
|
||||||
|
return [point.avg_value, point.min_value, point.max_value].every(Number.isFinite);
|
||||||
|
}
|
||||||
|
|
||||||
|
function createAvgLineData(points: HistoryPoint[], granulate: string, breakOnGaps: boolean): AvgLineSeriesPoint[] {
|
||||||
|
const slotMs = parseGranulateMs(granulate);
|
||||||
|
const finitePoints = points.filter(isFinitePoint);
|
||||||
|
|
||||||
|
if (!breakOnGaps) {
|
||||||
|
return finitePoints.map((point) => [
|
||||||
|
new Date(point.time).getTime(),
|
||||||
|
point.avg_value,
|
||||||
|
point.min_value,
|
||||||
|
point.max_value,
|
||||||
|
point.point_count,
|
||||||
|
slotMs,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
return finitePoints.flatMap((point, index) => {
|
||||||
|
const currentTime = new Date(point.time).getTime();
|
||||||
|
const currentPoint: AvgLineSeriesValue = [
|
||||||
|
currentTime,
|
||||||
|
point.avg_value,
|
||||||
|
point.min_value,
|
||||||
|
point.max_value,
|
||||||
|
point.point_count,
|
||||||
|
slotMs,
|
||||||
|
];
|
||||||
|
|
||||||
|
if (index === 0) {
|
||||||
|
return [currentPoint];
|
||||||
|
}
|
||||||
|
|
||||||
|
const previousTime = new Date(finitePoints[index - 1].time).getTime();
|
||||||
|
const hasAcceptableGap = currentTime - previousTime <= slotMs * 50;
|
||||||
|
|
||||||
|
return hasAcceptableGap ? [currentPoint] : [null, currentPoint];
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
export function createAvgLineSeries(
|
||||||
|
points: HistoryPoint[],
|
||||||
|
index: number,
|
||||||
|
label: string,
|
||||||
|
granulate: string,
|
||||||
|
showAvgLine: boolean,
|
||||||
|
breakOnGaps: boolean,
|
||||||
|
): SeriesOption[] {
|
||||||
|
if (!showAvgLine) {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
|
const color = SERIES_COLORS[index % SERIES_COLORS.length];
|
||||||
|
|
||||||
|
return [
|
||||||
|
{
|
||||||
|
name: `${label} avg-line`,
|
||||||
|
type: 'line',
|
||||||
|
data: createAvgLineData(points, granulate, breakOnGaps),
|
||||||
|
encode: {
|
||||||
|
x: 0,
|
||||||
|
y: 1,
|
||||||
|
},
|
||||||
|
smooth: true,
|
||||||
|
connectNulls: false,
|
||||||
|
showSymbol: false,
|
||||||
|
symbol: 'none',
|
||||||
|
silent: true,
|
||||||
|
tooltip: {
|
||||||
|
show: false,
|
||||||
|
},
|
||||||
|
lineStyle: {
|
||||||
|
color,
|
||||||
|
width: 1.5,
|
||||||
|
opacity: 0.78,
|
||||||
|
},
|
||||||
|
emphasis: {
|
||||||
|
disabled: true,
|
||||||
|
},
|
||||||
|
z: 4,
|
||||||
|
} as LineSeriesOption,
|
||||||
|
];
|
||||||
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
import { CustomChart } from 'echarts/charts';
|
import { CustomChart, LineChart } from 'echarts/charts';
|
||||||
import {
|
import {
|
||||||
DataZoomComponent,
|
DataZoomComponent,
|
||||||
GridComponent,
|
GridComponent,
|
||||||
@@ -10,6 +10,7 @@ import { CanvasRenderer } from 'echarts/renderers';
|
|||||||
|
|
||||||
echarts.use([
|
echarts.use([
|
||||||
CustomChart,
|
CustomChart,
|
||||||
|
LineChart,
|
||||||
GridComponent,
|
GridComponent,
|
||||||
LegendComponent,
|
LegendComponent,
|
||||||
TooltipComponent,
|
TooltipComponent,
|
||||||
|
|||||||
@@ -56,7 +56,12 @@ export function formatAxisDate(value: number, labelFormat: HistoryAxisLabelForma
|
|||||||
|
|
||||||
function formatChartValue(value: number): string {
|
function formatChartValue(value: number): string {
|
||||||
return new Intl.NumberFormat('ru-RU', {
|
return new Intl.NumberFormat('ru-RU', {
|
||||||
maximumFractionDigits: Math.abs(value) >= 100 ? 2 : 3,
|
maximumFractionDigits:
|
||||||
|
Math.abs(value) >= 1000 ? 0
|
||||||
|
: Math.abs(value) >= 100 ? 1
|
||||||
|
: Math.abs(value) >= 10 ? 2
|
||||||
|
: Math.abs(value) >= 1 ? 3
|
||||||
|
: 4,
|
||||||
}).format(value);
|
}).format(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -141,7 +146,8 @@ export function formatTooltip(params: unknown): string {
|
|||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
|
|
||||||
const header = formatTooltipInterval(firstValue);
|
const time = firstValue[0];
|
||||||
|
const header = formatTooltipDateTime(time);
|
||||||
|
|
||||||
const rows = avgItems.map((item) => {
|
const rows = avgItems.map((item) => {
|
||||||
const value = item.value as AvgPointValue;
|
const value = item.value as AvgPointValue;
|
||||||
@@ -149,8 +155,7 @@ export function formatTooltip(params: unknown): string {
|
|||||||
'<div class="chart-tooltip-row">',
|
'<div class="chart-tooltip-row">',
|
||||||
`<span class="chart-tooltip-label" style="--chart-tooltip-marker-color:${item.color ?? 'currentColor'};">${item.seriesName ?? ''}</span>`,
|
`<span class="chart-tooltip-label" style="--chart-tooltip-marker-color:${item.color ?? 'currentColor'};">${item.seriesName ?? ''}</span>`,
|
||||||
'<strong>',
|
'<strong>',
|
||||||
formatTooltipValue(value),
|
formatChartValue(value[1]),
|
||||||
value[4] > 1 ? ` · ${value[4]} точек` : '',
|
|
||||||
'</strong>',
|
'</strong>',
|
||||||
'</div>',
|
'</div>',
|
||||||
].join('');
|
].join('');
|
||||||
|
|||||||
@@ -20,6 +20,15 @@ export const SERIES_COLORS = [
|
|||||||
'#A7B3FF',
|
'#A7B3FF',
|
||||||
];
|
];
|
||||||
|
|
||||||
|
const BUCKET = {
|
||||||
|
time: 0,
|
||||||
|
avg: 1,
|
||||||
|
min: 2,
|
||||||
|
max: 3,
|
||||||
|
count: 4,
|
||||||
|
slotMs: 5,
|
||||||
|
} as const;
|
||||||
|
|
||||||
type CartesianCoordSys = {
|
type CartesianCoordSys = {
|
||||||
x: number;
|
x: number;
|
||||||
y: number;
|
y: number;
|
||||||
@@ -27,10 +36,22 @@ type CartesianCoordSys = {
|
|||||||
height: number;
|
height: number;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
type ChartArea = CartesianCoordSys;
|
||||||
|
|
||||||
|
type BucketValues = {
|
||||||
|
time: number;
|
||||||
|
avg: number;
|
||||||
|
min: number;
|
||||||
|
max: number;
|
||||||
|
slotMs: number;
|
||||||
|
};
|
||||||
|
|
||||||
|
/** Ограничивает число заданными границами, чтобы фигуры не выходили за canvas графика. */
|
||||||
function clamp(value: number, min: number, max: number): number {
|
function clamp(value: number, min: number, max: number): number {
|
||||||
return Math.min(max, Math.max(min, value));
|
return Math.min(max, Math.max(min, value));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Создает вертикальный градиент min..max с максимальной яркостью в позиции avg. */
|
||||||
function createAvgGradientStops(color: string, avgOffset: number) {
|
function createAvgGradientStops(color: string, avgOffset: number) {
|
||||||
const softZone = 0.18;
|
const softZone = 0.18;
|
||||||
|
|
||||||
@@ -43,13 +64,16 @@ function createAvgGradientStops(color: string, avgOffset: number) {
|
|||||||
].sort((first, second) => first.offset - second.offset);
|
].sort((first, second) => first.offset - second.offset);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Проверяет, что точку можно безопасно отрисовать на графике. */
|
||||||
function isFinitePoint(point: HistoryPoint): boolean {
|
function isFinitePoint(point: HistoryPoint): boolean {
|
||||||
return [point.avg_value, point.min_value, point.max_value].every(Number.isFinite);
|
return [point.avg_value, point.min_value, point.max_value].every(Number.isFinite);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Упаковывает один bucket API в компактный tuple для custom series ECharts. */
|
/** Упаковывает bucket в tuple для custom series ECharts. */
|
||||||
function createBucketData(points: HistoryPoint[], slotMs: number): HistoryBucketValue[] {
|
function createBucketData(points: HistoryPoint[], slotMs: number): HistoryBucketValue[] {
|
||||||
return points.filter(isFinitePoint).map((point) => [
|
const finitePoints = points.filter(isFinitePoint);
|
||||||
|
|
||||||
|
return finitePoints.map((point) => [
|
||||||
new Date(point.time).getTime(),
|
new Date(point.time).getTime(),
|
||||||
point.avg_value,
|
point.avg_value,
|
||||||
point.min_value,
|
point.min_value,
|
||||||
@@ -59,87 +83,108 @@ function createBucketData(points: HistoryPoint[], slotMs: number): HistoryBucket
|
|||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Рисует один bucket как временной слот: затухающий min..max и яркий маркер avg. */
|
/** Читает tuple bucket-а из ECharts API и возвращает значения с понятными именами. */
|
||||||
function renderBucket(color: string) {
|
function readBucketValues(api: CustomSeriesRenderItemAPI): BucketValues {
|
||||||
return (params: CustomSeriesRenderItemParams, api: CustomSeriesRenderItemAPI): CustomSeriesRenderItemReturn => {
|
return {
|
||||||
const time = Number(api.value(0));
|
time: Number(api.value(BUCKET.time)),
|
||||||
const avg = Number(api.value(1));
|
avg: Number(api.value(BUCKET.avg)),
|
||||||
const min = Number(api.value(2));
|
min: Number(api.value(BUCKET.min)),
|
||||||
const max = Number(api.value(3));
|
max: Number(api.value(BUCKET.max)),
|
||||||
const slotMs = Number(api.value(5));
|
slotMs: Number(api.value(BUCKET.slotMs)),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
// ECharts отдает размеры области графика в runtime, но в публичных типах
|
/** Считает пиксельные фигуры одного bucket-а и обрезает их по области графика. */
|
||||||
// они не описаны. Поэтому держим cast локально рядом с clipping-логикой.
|
function createBucketShapes(api: CustomSeriesRenderItemAPI, values: BucketValues, chartArea: ChartArea) {
|
||||||
const coordSys = params.coordSys as unknown as CartesianCoordSys;
|
const avgPoint = api.coord([values.time, values.avg]);
|
||||||
|
const minPoint = api.coord([values.time, values.min]);
|
||||||
|
const maxPoint = api.coord([values.time, values.max]);
|
||||||
|
const slotStart = api.coord([values.time - values.slotMs / 2, values.avg]);
|
||||||
|
const slotEnd = api.coord([values.time + values.slotMs / 2, values.avg]);
|
||||||
|
|
||||||
// Переводим координаты данных (time/value) в пиксели canvas.
|
|
||||||
const avgPoint = api.coord([time, avg]);
|
|
||||||
const minPoint = api.coord([time, min]);
|
|
||||||
const maxPoint = api.coord([time, max]);
|
|
||||||
const slotStart = api.coord([time - slotMs / 2, avg]);
|
|
||||||
const slotEnd = api.coord([time + slotMs / 2, avg]);
|
|
||||||
|
|
||||||
// Слот занимает один интервал грануляции по X и диапазон min..max по Y.
|
|
||||||
const x = Math.min(slotStart[0], slotEnd[0]);
|
const x = Math.min(slotStart[0], slotEnd[0]);
|
||||||
const rawHeight = Math.abs(maxPoint[1] - minPoint[1]);
|
const rawHeight = Math.abs(maxPoint[1] - minPoint[1]);
|
||||||
const width = Math.max(2, Math.abs(slotEnd[0] - slotStart[0]));
|
const width = Math.max(2, Math.abs(slotEnd[0] - slotStart[0]));
|
||||||
const height = Math.max(2, rawHeight);
|
const height = Math.max(2, rawHeight);
|
||||||
const y = Math.min(minPoint[1], maxPoint[1]) - (height - rawHeight) / 2;
|
const y = Math.min(minPoint[1], maxPoint[1]) - (height - rawHeight) / 2;
|
||||||
const avgY = avgPoint[1];
|
const avgY = avgPoint[1];
|
||||||
const chartArea = { x: coordSys.x, y: coordSys.y, width: coordSys.width, height: coordSys.height };
|
|
||||||
|
|
||||||
// Обрезаем фигуры, чтобы при Y-зуме они не выходили за область графика.
|
const rangeShape = graphic.clipRectByRect({ x, y, width, height }, chartArea);
|
||||||
const rangeShape = graphic.clipRectByRect(
|
const avgShape = graphic.clipRectByRect({ x, y: avgY - 1, width, height: 2 }, chartArea);
|
||||||
{ x, y, width, height },
|
|
||||||
chartArea,
|
|
||||||
);
|
|
||||||
const avgShape = graphic.clipRectByRect(
|
|
||||||
{ x, y: avgY - 1, width, height: 2 },
|
|
||||||
chartArea,
|
|
||||||
);
|
|
||||||
|
|
||||||
if (!rangeShape) {
|
if (!rangeShape) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
const avgOffset = clamp((avgY - rangeShape.y) / rangeShape.height, 0, 1);
|
return {
|
||||||
|
avgPoint,
|
||||||
|
avgShape,
|
||||||
|
avgY,
|
||||||
|
rangeShape,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Рисует один bucket: min..max слот и горизонтальный avg-маркер. */
|
||||||
|
function renderBucket(color: string) {
|
||||||
|
return (params: CustomSeriesRenderItemParams, api: CustomSeriesRenderItemAPI): CustomSeriesRenderItemReturn => {
|
||||||
|
const values = readBucketValues(api);
|
||||||
|
|
||||||
|
// ECharts отдает размеры области графика в runtime, но в публичных типах они не описаны.
|
||||||
|
const chartArea = params.coordSys as unknown as ChartArea;
|
||||||
|
const bucketShapes = createBucketShapes(api, values, chartArea);
|
||||||
|
|
||||||
|
if (!bucketShapes) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
const avgOffset = clamp(
|
||||||
|
(bucketShapes.avgY - bucketShapes.rangeShape.y) / bucketShapes.rangeShape.height,
|
||||||
|
0,
|
||||||
|
1,
|
||||||
|
);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
type: 'group',
|
type: 'group',
|
||||||
children: [
|
children: [
|
||||||
{
|
{
|
||||||
type: 'rect',
|
type: 'rect',
|
||||||
shape: rangeShape,
|
shape: bucketShapes.rangeShape,
|
||||||
style: {
|
style: {
|
||||||
fill: new graphic.LinearGradient(0, 0, 0, 1, createAvgGradientStops(color, avgOffset)),
|
fill: new graphic.LinearGradient(0, 0, 0, 1, createAvgGradientStops(color, avgOffset)),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
...(avgShape ? [{
|
...(bucketShapes.avgShape
|
||||||
|
? [{
|
||||||
type: 'rect' as const,
|
type: 'rect' as const,
|
||||||
shape: avgShape,
|
shape: bucketShapes.avgShape,
|
||||||
style: {
|
style: {
|
||||||
fill: color,
|
fill: color,
|
||||||
},
|
},
|
||||||
}] : []),
|
}]
|
||||||
|
: []),
|
||||||
],
|
],
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Создает отдельный временной слот min..max с акцентом на avg для каждой точки history. */
|
/** Создает bucket-серию на тег: min..max слот и горизонтальный avg-маркер. */
|
||||||
export function createSeriesOptions(points: HistoryPoint[], index: number, label: string, granulate: string): SeriesOption[] {
|
export function createSeriesOptions(
|
||||||
|
points: HistoryPoint[],
|
||||||
|
index: number,
|
||||||
|
label: string,
|
||||||
|
granulate: string,
|
||||||
|
): SeriesOption[] {
|
||||||
const color = SERIES_COLORS[index % SERIES_COLORS.length];
|
const color = SERIES_COLORS[index % SERIES_COLORS.length];
|
||||||
const data = createBucketData(points, parseGranulateMs(granulate));
|
|
||||||
|
|
||||||
return [
|
return [
|
||||||
{
|
{
|
||||||
name: label,
|
name: label,
|
||||||
type: 'custom',
|
type: 'custom',
|
||||||
data,
|
data: createBucketData(points, parseGranulateMs(granulate)),
|
||||||
renderItem: renderBucket(color),
|
renderItem: renderBucket(color),
|
||||||
encode: {
|
encode: {
|
||||||
x: 0,
|
x: BUCKET.time,
|
||||||
y: [1, 2, 3],
|
y: [BUCKET.avg, BUCKET.min, BUCKET.max],
|
||||||
},
|
},
|
||||||
itemStyle: {
|
itemStyle: {
|
||||||
color,
|
color,
|
||||||
|
|||||||
97
src/features/history-chart/historyChartZoom.ts
Normal file
97
src/features/history-chart/historyChartZoom.ts
Normal file
@@ -0,0 +1,97 @@
|
|||||||
|
import { getHistoryGranularity } from '../../utils/historyGranularity';
|
||||||
|
import type { DataZoomState, HistoryZoomRange } from './chartTypes';
|
||||||
|
|
||||||
|
export const ZOOM_REQUEST_DELAY_MS = 180;
|
||||||
|
|
||||||
|
export function isXAxisDataZoom(state: DataZoomState): boolean {
|
||||||
|
return state.dataZoomId?.startsWith('history-x-') || state.dataZoomIndex === 0 || state.dataZoomIndex === 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Собирает начальный zoom-диапазон из внешних props графика. */
|
||||||
|
export function createInitialZoomRange(range: HistoryZoomRange): HistoryZoomRange {
|
||||||
|
return range;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Создает zoom-диапазон из миллисекунд и подбирает для него грануляцию. */
|
||||||
|
function createZoomRange(fromMs: number, toMs: number): HistoryZoomRange {
|
||||||
|
const from = new Date(fromMs).toISOString();
|
||||||
|
const to = new Date(toMs).toISOString();
|
||||||
|
|
||||||
|
return {
|
||||||
|
from,
|
||||||
|
to,
|
||||||
|
...getHistoryGranularity(from, to),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Достает подинтервал X-зума из события ECharts. */
|
||||||
|
export function getZoomRangeFromEvent(state: DataZoomState, baseRange: HistoryZoomRange): HistoryZoomRange | null {
|
||||||
|
const baseFromMs = new Date(baseRange.from).getTime();
|
||||||
|
const baseToMs = new Date(baseRange.to).getTime();
|
||||||
|
const baseSpanMs = baseToMs - baseFromMs;
|
||||||
|
|
||||||
|
if (!Number.isFinite(baseFromMs) || !Number.isFinite(baseToMs) || baseSpanMs <= 0) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
const startValue = Number(state.startValue);
|
||||||
|
const endValue = Number(state.endValue);
|
||||||
|
let nextFromMs = Number.isFinite(startValue) ? startValue : undefined;
|
||||||
|
let nextToMs = Number.isFinite(endValue) ? endValue : undefined;
|
||||||
|
|
||||||
|
// ECharts иногда не передает startValue/endValue, поэтому используем проценты start/end.
|
||||||
|
if (nextFromMs === undefined || nextToMs === undefined) {
|
||||||
|
const start = Number(state.start);
|
||||||
|
const end = Number(state.end);
|
||||||
|
|
||||||
|
if (!Number.isFinite(start) || !Number.isFinite(end)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
nextFromMs = baseFromMs + (baseSpanMs * start) / 100;
|
||||||
|
nextToMs = baseFromMs + (baseSpanMs * end) / 100;
|
||||||
|
}
|
||||||
|
|
||||||
|
const fromMs = Math.max(baseFromMs, Math.min(nextFromMs, nextToMs));
|
||||||
|
const toMs = Math.min(baseToMs, Math.max(nextFromMs, nextToMs));
|
||||||
|
|
||||||
|
return toMs > fromMs ? createZoomRange(fromMs, toMs) : null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Проверяет, что lazy zoom не пытается повторно применить тот же диапазон. */
|
||||||
|
export function isSameZoomRange(left: HistoryZoomRange, right: HistoryZoomRange): boolean {
|
||||||
|
return left.from === right.from && left.to === right.to && left.granulate === right.granulate;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Вычисляет, какую часть верхнеуровневого периода занимает текущий пользовательский zoom. */
|
||||||
|
export function createDataZoomState(baseRange: HistoryZoomRange, zoomRange: HistoryZoomRange): DataZoomState {
|
||||||
|
// Верхнеуровневый период берем из инпутов "С/По" и считаем его полными 0..100%.
|
||||||
|
const baseFromMs = new Date(baseRange.from).getTime();
|
||||||
|
const baseToMs = new Date(baseRange.to).getTime();
|
||||||
|
|
||||||
|
// Пользовательский zoom живет внутри верхнеуровневого периода и выделяется на нижней шкале.
|
||||||
|
const zoomFromMs = new Date(zoomRange.from).getTime();
|
||||||
|
const zoomToMs = new Date(zoomRange.to).getTime();
|
||||||
|
const baseSpanMs = baseToMs - baseFromMs;
|
||||||
|
|
||||||
|
// Если даты некорректны, показываем весь период, чтобы не ломать управление графиком.
|
||||||
|
if (
|
||||||
|
!Number.isFinite(baseFromMs) ||
|
||||||
|
!Number.isFinite(baseToMs) ||
|
||||||
|
!Number.isFinite(zoomFromMs) ||
|
||||||
|
!Number.isFinite(zoomToMs) ||
|
||||||
|
baseSpanMs <= 0
|
||||||
|
) {
|
||||||
|
return { start: 0, end: 100 };
|
||||||
|
}
|
||||||
|
|
||||||
|
// Переводим абсолютные даты zoom-а в проценты относительно верхнеуровневого периода.
|
||||||
|
const start = ((zoomFromMs - baseFromMs) / baseSpanMs) * 100;
|
||||||
|
const end = ((zoomToMs - baseFromMs) / baseSpanMs) * 100;
|
||||||
|
|
||||||
|
// Ограничиваем значения диапазоном 0..100, чтобы ECharts не получил выход за шкалу.
|
||||||
|
return {
|
||||||
|
start: Math.max(0, Math.min(100, start)),
|
||||||
|
end: Math.max(0, Math.min(100, end)),
|
||||||
|
};
|
||||||
|
}
|
||||||
@@ -1,14 +1,26 @@
|
|||||||
import { useMemo } from 'react';
|
import { useMemo } from 'react';
|
||||||
import type { SeriesOption } from 'echarts';
|
import type { SeriesOption } from 'echarts';
|
||||||
|
import { createAvgLineSeries } from './historyChartAvgLineSeries';
|
||||||
import { createSeriesOptions } from './historyChartSeries';
|
import { createSeriesOptions } from './historyChartSeries';
|
||||||
import type { HistoryChartLineData } from './useHistoryChartQueries';
|
import type { HistoryChartLineData } from './useHistoryChartQueries';
|
||||||
|
import type { AvgLineMode } from './chartTypes';
|
||||||
|
|
||||||
export function useHistoryChartSeries(lines: HistoryChartLineData[], granulate: string): SeriesOption[] {
|
export function useHistoryChartSeries(
|
||||||
|
lines: HistoryChartLineData[],
|
||||||
|
granulate: string,
|
||||||
|
avgLineMode: AvgLineMode,
|
||||||
|
showAvgLine: boolean,
|
||||||
|
): SeriesOption[] {
|
||||||
return useMemo(
|
return useMemo(
|
||||||
() =>
|
() =>
|
||||||
lines.flatMap((line) =>
|
lines.flatMap((line) =>
|
||||||
line.rows.length ? createSeriesOptions(line.rows, line.index, line.label, granulate) : [],
|
line.rows.length
|
||||||
|
? [
|
||||||
|
...createSeriesOptions(line.rows, line.index, line.label, granulate),
|
||||||
|
...createAvgLineSeries(line.rows, line.index, line.label, granulate, showAvgLine, avgLineMode === 'auto'),
|
||||||
|
]
|
||||||
|
: [],
|
||||||
),
|
),
|
||||||
[granulate, lines],
|
[granulate, lines, showAvgLine, avgLineMode],
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,6 +8,58 @@
|
|||||||
height: 100%;
|
height: 100%;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.history-chart-shell {
|
||||||
|
position: relative;
|
||||||
|
}
|
||||||
|
|
||||||
|
.history-chart-controls {
|
||||||
|
position: absolute;
|
||||||
|
top: 8px;
|
||||||
|
right: 12px;
|
||||||
|
z-index: 2;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 8px;
|
||||||
|
color: var(--muted);
|
||||||
|
font-size: 12px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.history-chart-line-mode {
|
||||||
|
padding: 3px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.archive-avgline-mode-control .history-chart-line-mode button {
|
||||||
|
border-radius: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.archive-avgline-mode-control .history-chart-line-mode button:first-child {
|
||||||
|
border-top-left-radius: var(--radius);
|
||||||
|
border-bottom-left-radius: var(--radius);
|
||||||
|
}
|
||||||
|
|
||||||
|
.archive-avgline-mode-control .history-chart-line-mode button:last-child {
|
||||||
|
border-top-right-radius: var(--radius);
|
||||||
|
border-bottom-right-radius: var(--radius);
|
||||||
|
}
|
||||||
|
|
||||||
|
.segmented--range-preset button {
|
||||||
|
border-radius: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.segmented--range-preset button:first-child {
|
||||||
|
border-top-left-radius: var(--radius);
|
||||||
|
border-bottom-left-radius: var(--radius);
|
||||||
|
}
|
||||||
|
|
||||||
|
.segmented--range-preset button:last-child {
|
||||||
|
border-top-right-radius: var(--radius);
|
||||||
|
border-bottom-right-radius: var(--radius);
|
||||||
|
}
|
||||||
|
|
||||||
|
.history-chart-line-mode button {
|
||||||
|
font-size: inherit;
|
||||||
|
}
|
||||||
|
|
||||||
.chart-section--archive .history-chart-shell,
|
.chart-section--archive .history-chart-shell,
|
||||||
.chart-section--archive .history-chart {
|
.chart-section--archive .history-chart {
|
||||||
flex: 1;
|
flex: 1;
|
||||||
@@ -24,10 +76,6 @@
|
|||||||
border-radius: var(--radius);
|
border-radius: var(--radius);
|
||||||
}
|
}
|
||||||
|
|
||||||
.chart-tooltip {
|
|
||||||
min-width: 240px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.chart-tooltip-title {
|
.chart-tooltip-title {
|
||||||
margin-bottom: 8px;
|
margin-bottom: 8px;
|
||||||
color: #e5e7eb;
|
color: #e5e7eb;
|
||||||
@@ -36,7 +84,7 @@
|
|||||||
|
|
||||||
.chart-tooltip-row {
|
.chart-tooltip-row {
|
||||||
display: grid;
|
display: grid;
|
||||||
grid-template-columns: minmax(90px, 1fr) auto;
|
grid-template-columns: 1fr auto;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
gap: 14px;
|
gap: 14px;
|
||||||
margin-top: 5px;
|
margin-top: 5px;
|
||||||
|
|||||||
@@ -73,6 +73,12 @@
|
|||||||
background: rgba(201, 122, 61, 0.18);
|
background: rgba(201, 122, 61, 0.18);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.segmented__button--active {
|
||||||
|
border-color: rgba(212, 165, 116, 0.34);
|
||||||
|
background: rgba(201, 122, 61, 0.14);
|
||||||
|
color: #f8fafc;
|
||||||
|
}
|
||||||
|
|
||||||
.source-chip,
|
.source-chip,
|
||||||
.status-pill,
|
.status-pill,
|
||||||
.metric-card__state {
|
.metric-card__state {
|
||||||
|
|||||||
@@ -216,6 +216,14 @@
|
|||||||
font-size: 0.84rem;
|
font-size: 0.84rem;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.archive-toolbar-segmented-control {
|
||||||
|
display: inline-flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 8px;
|
||||||
|
color: var(--muted);
|
||||||
|
font-size: 0.84rem;
|
||||||
|
}
|
||||||
|
|
||||||
.archive-date-input {
|
.archive-date-input {
|
||||||
color-scheme: dark;
|
color-scheme: dark;
|
||||||
min-height: 36px;
|
min-height: 36px;
|
||||||
|
|||||||
@@ -15,7 +15,6 @@ export default defineConfig(({ mode }) => {
|
|||||||
'/api': {
|
'/api': {
|
||||||
target: DEV_API_URL,
|
target: DEV_API_URL,
|
||||||
changeOrigin: true,
|
changeOrigin: true,
|
||||||
rewrite: (path) => path.replace(/^\/api/, ''),
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user