Compare commits
9 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 782d3d4430 | |||
| e7d489bcee | |||
| 5d0408c533 | |||
| 1127b14946 | |||
| 9a542ce33e | |||
| 5ffe9192c1 | |||
| 88d628b696 | |||
| 1632bfb3d8 | |||
| 074d45d695 |
@@ -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,12 +214,22 @@ export function ArchiveView({
|
|||||||
onPointerEnter={() => setSelectorOpen(false)}
|
onPointerEnter={() => setSelectorOpen(false)}
|
||||||
>
|
>
|
||||||
<div className="toolbar">
|
<div className="toolbar">
|
||||||
<div className="segmented">
|
<div className="archive-toolbar-segmented-control">
|
||||||
{RANGE_PRESETS.map((preset) => (
|
<div className="segmented segmented--range-preset">
|
||||||
<button key={preset.id} type="button" onClick={() => onRangeChange(createRange(preset.hours))}>
|
{RANGE_PRESETS.map((preset) => (
|
||||||
{preset.label}
|
<button
|
||||||
</button>
|
key={preset.id}
|
||||||
))}
|
type="button"
|
||||||
|
className={preset.id === selectedRangePresetId ? 'segmented__button--active' : undefined}
|
||||||
|
onClick={() => {
|
||||||
|
setSelectedRangePresetId(preset.id);
|
||||||
|
onRangeChange(createRange(preset.hours));
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{preset.label}
|
||||||
|
</button>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div className="archive-date-range">
|
<div className="archive-date-range">
|
||||||
<span>С</span>
|
<span>С</span>
|
||||||
@@ -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}
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ 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;
|
||||||
@@ -42,6 +43,7 @@ function shouldShowAvgLine(mode: AvgLineMode, range: HistoryZoomRange): boolean
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function HistoryChart({
|
export function HistoryChart({
|
||||||
|
avgLineMode,
|
||||||
edge,
|
edge,
|
||||||
from,
|
from,
|
||||||
granulate,
|
granulate,
|
||||||
@@ -62,7 +64,6 @@ export function HistoryChart({
|
|||||||
const zoomRangeRef = useRef(zoomRange);
|
const zoomRangeRef = useRef(zoomRange);
|
||||||
const zoomTimerRef = useRef<ReturnType<typeof setTimeout> | null>(null);
|
const zoomTimerRef = useRef<ReturnType<typeof setTimeout> | null>(null);
|
||||||
const lastReadyOptionRef = useRef<EChartsOption | null>(null);
|
const lastReadyOptionRef = useRef<EChartsOption | null>(null);
|
||||||
const [avgLineMode, setAvgLineMode] = useState<AvgLineMode>('auto');
|
|
||||||
const lines = useHistoryChartQueries({
|
const lines = useHistoryChartQueries({
|
||||||
edge,
|
edge,
|
||||||
from: zoomRange.from,
|
from: zoomRange.from,
|
||||||
@@ -72,7 +73,7 @@ export function HistoryChart({
|
|||||||
tagLabels,
|
tagLabels,
|
||||||
});
|
});
|
||||||
const showAvgLine = shouldShowAvgLine(avgLineMode, zoomRange);
|
const showAvgLine = shouldShowAvgLine(avgLineMode, zoomRange);
|
||||||
const series = useHistoryChartSeries(lines, zoomRange.granulate, showAvgLine);
|
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;
|
||||||
@@ -149,13 +150,12 @@ 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}
|
||||||
avgLineMode={avgLineMode}
|
|
||||||
option={displayOption}
|
option={displayOption}
|
||||||
onDataZoom={handleDataZoom}
|
onDataZoom={handleDataZoom}
|
||||||
onAvgLineModeChange={setAvgLineMode}
|
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,8 +2,9 @@ import type { EChartsOption } from 'echarts';
|
|||||||
import ReactEChartsCore from 'echarts-for-react/esm/core.js';
|
import ReactEChartsCore from 'echarts-for-react/esm/core.js';
|
||||||
import { useCallback, useEffect, useMemo, useRef } from 'react';
|
import { useCallback, useEffect, useMemo, useRef } from 'react';
|
||||||
import type { WheelEvent } from 'react';
|
import type { WheelEvent } from 'react';
|
||||||
import type { AvgLineMode, 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;
|
avgLineMode: AvgLineMode;
|
||||||
@@ -11,17 +12,9 @@ type HistoryChartAreaProps = {
|
|||||||
hasSelection: boolean;
|
hasSelection: boolean;
|
||||||
loading: boolean;
|
loading: boolean;
|
||||||
option: EChartsOption;
|
option: EChartsOption;
|
||||||
onAvgLineModeChange: (mode: AvgLineMode) => void;
|
|
||||||
onDataZoom: (event: DataZoomEventBatch) => void;
|
onDataZoom: (event: DataZoomEventBatch) => void;
|
||||||
};
|
};
|
||||||
|
|
||||||
// Порядок режимов соответствует требованию: авто, принудительно рисовать, принудительно скрыть.
|
|
||||||
const AVG_LINE_MODES: Array<{ value: AvgLineMode; label: string }> = [
|
|
||||||
{ value: 'auto', label: 'Авто' },
|
|
||||||
{ value: 'show', label: 'Рисовать' },
|
|
||||||
{ value: 'hide', label: 'Не рисовать' },
|
|
||||||
];
|
|
||||||
|
|
||||||
/** Включает или выключает нативный X-зум колесом, чтобы Shift + колесо работал только по Y. */
|
/** Включает или выключает нативный X-зум колесом, чтобы Shift + колесо работал только по Y. */
|
||||||
function setXAxisWheelZoom(chart: ReturnType<ReactEChartsCore['getEchartsInstance']>, enabled: boolean): void {
|
function setXAxisWheelZoom(chart: ReturnType<ReactEChartsCore['getEchartsInstance']>, enabled: boolean): void {
|
||||||
chart.setOption(
|
chart.setOption(
|
||||||
@@ -44,7 +37,6 @@ export function HistoryChartArea({
|
|||||||
hasSelection,
|
hasSelection,
|
||||||
loading,
|
loading,
|
||||||
option,
|
option,
|
||||||
onAvgLineModeChange,
|
|
||||||
onDataZoom,
|
onDataZoom,
|
||||||
}: HistoryChartAreaProps) {
|
}: HistoryChartAreaProps) {
|
||||||
const chartRef = useRef<InstanceType<typeof ReactEChartsCore> | null>(null);
|
const chartRef = useRef<InstanceType<typeof ReactEChartsCore> | null>(null);
|
||||||
@@ -111,23 +103,8 @@ export function HistoryChartArea({
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="history-chart-shell" onWheelCapture={handleWheelCapture}>
|
<div className="history-chart-shell" onWheelCapture={handleWheelCapture}>
|
||||||
<div className="history-chart-controls" aria-label="Режим соединительной линии avg">
|
|
||||||
<span>Линия avg</span>
|
|
||||||
<div className="segmented history-chart-line-mode">
|
|
||||||
{AVG_LINE_MODES.map((mode) => (
|
|
||||||
<button
|
|
||||||
key={mode.value}
|
|
||||||
type="button"
|
|
||||||
className={mode.value === avgLineMode ? 'history-chart-line-mode__button--active' : undefined}
|
|
||||||
onClick={() => onAvgLineModeChange(mode.value)}
|
|
||||||
aria-pressed={mode.value === avgLineMode}
|
|
||||||
>
|
|
||||||
{mode.label}
|
|
||||||
</button>
|
|
||||||
))}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<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>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -9,8 +9,6 @@ export type HistoryBucketValue = [
|
|||||||
max: number,
|
max: number,
|
||||||
count: number,
|
count: number,
|
||||||
slotMs: number,
|
slotMs: number,
|
||||||
previousTime: number | null,
|
|
||||||
previousAvg: number | null,
|
|
||||||
];
|
];
|
||||||
|
|
||||||
export type AvgLineMode = 'auto' | 'show' | 'hide';
|
export type AvgLineMode = 'auto' | 'show' | 'hide';
|
||||||
|
|||||||
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('');
|
||||||
|
|||||||
@@ -27,8 +27,6 @@ const BUCKET = {
|
|||||||
max: 3,
|
max: 3,
|
||||||
count: 4,
|
count: 4,
|
||||||
slotMs: 5,
|
slotMs: 5,
|
||||||
previousTime: 6,
|
|
||||||
previousAvg: 7,
|
|
||||||
} as const;
|
} as const;
|
||||||
|
|
||||||
type CartesianCoordSys = {
|
type CartesianCoordSys = {
|
||||||
@@ -46,10 +44,6 @@ type BucketValues = {
|
|||||||
min: number;
|
min: number;
|
||||||
max: number;
|
max: number;
|
||||||
slotMs: number;
|
slotMs: number;
|
||||||
previousTime: number;
|
|
||||||
previousAvg: number;
|
|
||||||
previousTimeValue: unknown;
|
|
||||||
previousAvgValue: unknown;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/** Ограничивает число заданными границами, чтобы фигуры не выходили за canvas графика. */
|
/** Ограничивает число заданными границами, чтобы фигуры не выходили за canvas графика. */
|
||||||
@@ -75,56 +69,31 @@ 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 и предыдущую avg-точку в tuple для custom series ECharts. */
|
/** Упаковывает bucket в tuple для custom series ECharts. */
|
||||||
function createBucketData(points: HistoryPoint[], slotMs: number): HistoryBucketValue[] {
|
function createBucketData(points: HistoryPoint[], slotMs: number): HistoryBucketValue[] {
|
||||||
const finitePoints = points.filter(isFinitePoint);
|
const finitePoints = points.filter(isFinitePoint);
|
||||||
|
|
||||||
return finitePoints.map((point, index) => {
|
return finitePoints.map((point) => [
|
||||||
const previousPoint = finitePoints[index - 1];
|
|
||||||
|
|
||||||
return [
|
|
||||||
new Date(point.time).getTime(),
|
new Date(point.time).getTime(),
|
||||||
point.avg_value,
|
point.avg_value,
|
||||||
point.min_value,
|
point.min_value,
|
||||||
point.max_value,
|
point.max_value,
|
||||||
point.point_count,
|
point.point_count,
|
||||||
slotMs,
|
slotMs,
|
||||||
previousPoint ? new Date(previousPoint.time).getTime() : null,
|
]);
|
||||||
previousPoint?.avg_value ?? null,
|
|
||||||
];
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Читает tuple bucket-а из ECharts API и возвращает значения с понятными именами. */
|
/** Читает tuple bucket-а из ECharts API и возвращает значения с понятными именами. */
|
||||||
function readBucketValues(api: CustomSeriesRenderItemAPI): BucketValues {
|
function readBucketValues(api: CustomSeriesRenderItemAPI): BucketValues {
|
||||||
const previousTimeValue = api.value(BUCKET.previousTime);
|
|
||||||
const previousAvgValue = api.value(BUCKET.previousAvg);
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
time: Number(api.value(BUCKET.time)),
|
time: Number(api.value(BUCKET.time)),
|
||||||
avg: Number(api.value(BUCKET.avg)),
|
avg: Number(api.value(BUCKET.avg)),
|
||||||
min: Number(api.value(BUCKET.min)),
|
min: Number(api.value(BUCKET.min)),
|
||||||
max: Number(api.value(BUCKET.max)),
|
max: Number(api.value(BUCKET.max)),
|
||||||
slotMs: Number(api.value(BUCKET.slotMs)),
|
slotMs: Number(api.value(BUCKET.slotMs)),
|
||||||
previousTime: Number(previousTimeValue),
|
|
||||||
previousAvg: Number(previousAvgValue),
|
|
||||||
previousTimeValue,
|
|
||||||
previousAvgValue,
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Проверяет, можно ли рисовать соединительный отрезок к предыдущей avg-точке. */
|
|
||||||
function hasPreviousAvg(values: BucketValues): boolean {
|
|
||||||
return (
|
|
||||||
values.previousTimeValue !== null &&
|
|
||||||
values.previousTimeValue !== undefined &&
|
|
||||||
values.previousAvgValue !== null &&
|
|
||||||
values.previousAvgValue !== undefined &&
|
|
||||||
Number.isFinite(values.previousTime) &&
|
|
||||||
Number.isFinite(values.previousAvg)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Считает пиксельные фигуры одного bucket-а и обрезает их по области графика. */
|
/** Считает пиксельные фигуры одного bucket-а и обрезает их по области графика. */
|
||||||
function createBucketShapes(api: CustomSeriesRenderItemAPI, values: BucketValues, chartArea: ChartArea) {
|
function createBucketShapes(api: CustomSeriesRenderItemAPI, values: BucketValues, chartArea: ChartArea) {
|
||||||
const avgPoint = api.coord([values.time, values.avg]);
|
const avgPoint = api.coord([values.time, values.avg]);
|
||||||
@@ -155,30 +124,8 @@ function createBucketShapes(api: CustomSeriesRenderItemAPI, values: BucketValues
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Создает отрезок к предыдущей avg-точке, если режим соединительной линии включен. */
|
/** Рисует один bucket: min..max слот и горизонтальный avg-маркер. */
|
||||||
function createAvgLineShape(
|
function renderBucket(color: string) {
|
||||||
api: CustomSeriesRenderItemAPI,
|
|
||||||
values: BucketValues,
|
|
||||||
avgPoint: number[],
|
|
||||||
avgY: number,
|
|
||||||
chartArea: ChartArea,
|
|
||||||
) {
|
|
||||||
if (!hasPreviousAvg(values)) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
const previousPoint = api.coord([values.previousTime, values.previousAvg]);
|
|
||||||
|
|
||||||
return {
|
|
||||||
x1: clamp(previousPoint[0], chartArea.x, chartArea.x + chartArea.width),
|
|
||||||
y1: clamp(previousPoint[1], chartArea.y, chartArea.y + chartArea.height),
|
|
||||||
x2: clamp(avgPoint[0], chartArea.x, chartArea.x + chartArea.width),
|
|
||||||
y2: clamp(avgY, chartArea.y, chartArea.y + chartArea.height),
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Рисует один bucket: min..max слот, avg-маркер и опциональный отрезок к предыдущей avg-точке. */
|
|
||||||
function renderBucket(color: string, showAvgLine: boolean) {
|
|
||||||
return (params: CustomSeriesRenderItemParams, api: CustomSeriesRenderItemAPI): CustomSeriesRenderItemReturn => {
|
return (params: CustomSeriesRenderItemParams, api: CustomSeriesRenderItemAPI): CustomSeriesRenderItemReturn => {
|
||||||
const values = readBucketValues(api);
|
const values = readBucketValues(api);
|
||||||
|
|
||||||
@@ -190,10 +137,6 @@ function renderBucket(color: string, showAvgLine: boolean) {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Avg-линия рисуется внутри той же custom-серии, чтобы не удваивать число ECharts-серий при зуме.
|
|
||||||
const lineShape = showAvgLine
|
|
||||||
? createAvgLineShape(api, values, bucketShapes.avgPoint, bucketShapes.avgY, chartArea)
|
|
||||||
: null;
|
|
||||||
const avgOffset = clamp(
|
const avgOffset = clamp(
|
||||||
(bucketShapes.avgY - bucketShapes.rangeShape.y) / bucketShapes.rangeShape.height,
|
(bucketShapes.avgY - bucketShapes.rangeShape.y) / bucketShapes.rangeShape.height,
|
||||||
0,
|
0,
|
||||||
@@ -210,17 +153,6 @@ function renderBucket(color: string, showAvgLine: boolean) {
|
|||||||
fill: new graphic.LinearGradient(0, 0, 0, 1, createAvgGradientStops(color, avgOffset)),
|
fill: new graphic.LinearGradient(0, 0, 0, 1, createAvgGradientStops(color, avgOffset)),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
...(lineShape
|
|
||||||
? [{
|
|
||||||
type: 'line' as const,
|
|
||||||
shape: lineShape,
|
|
||||||
style: {
|
|
||||||
stroke: color,
|
|
||||||
lineWidth: 1,
|
|
||||||
opacity: 0.72,
|
|
||||||
},
|
|
||||||
}]
|
|
||||||
: []),
|
|
||||||
...(bucketShapes.avgShape
|
...(bucketShapes.avgShape
|
||||||
? [{
|
? [{
|
||||||
type: 'rect' as const,
|
type: 'rect' as const,
|
||||||
@@ -235,13 +167,12 @@ function renderBucket(color: string, showAvgLine: boolean) {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Создает одну custom-серию на тег: bucket-слоты и avg-линия живут в одном renderItem. */
|
/** Создает bucket-серию на тег: min..max слот и горизонтальный avg-маркер. */
|
||||||
export function createSeriesOptions(
|
export function createSeriesOptions(
|
||||||
points: HistoryPoint[],
|
points: HistoryPoint[],
|
||||||
index: number,
|
index: number,
|
||||||
label: string,
|
label: string,
|
||||||
granulate: string,
|
granulate: string,
|
||||||
showAvgLine: boolean,
|
|
||||||
): SeriesOption[] {
|
): SeriesOption[] {
|
||||||
const color = SERIES_COLORS[index % SERIES_COLORS.length];
|
const color = SERIES_COLORS[index % SERIES_COLORS.length];
|
||||||
|
|
||||||
@@ -250,7 +181,7 @@ export function createSeriesOptions(
|
|||||||
name: label,
|
name: label,
|
||||||
type: 'custom',
|
type: 'custom',
|
||||||
data: createBucketData(points, parseGranulateMs(granulate)),
|
data: createBucketData(points, parseGranulateMs(granulate)),
|
||||||
renderItem: renderBucket(color, showAvgLine),
|
renderItem: renderBucket(color),
|
||||||
encode: {
|
encode: {
|
||||||
x: BUCKET.time,
|
x: BUCKET.time,
|
||||||
y: [BUCKET.avg, BUCKET.min, BUCKET.max],
|
y: [BUCKET.avg, BUCKET.min, BUCKET.max],
|
||||||
|
|||||||
@@ -1,18 +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(
|
export function useHistoryChartSeries(
|
||||||
lines: HistoryChartLineData[],
|
lines: HistoryChartLineData[],
|
||||||
granulate: string,
|
granulate: string,
|
||||||
|
avgLineMode: AvgLineMode,
|
||||||
showAvgLine: boolean,
|
showAvgLine: boolean,
|
||||||
): SeriesOption[] {
|
): SeriesOption[] {
|
||||||
return useMemo(
|
return useMemo(
|
||||||
() =>
|
() =>
|
||||||
lines.flatMap((line) =>
|
lines.flatMap((line) =>
|
||||||
line.rows.length ? createSeriesOptions(line.rows, line.index, line.label, granulate, showAvgLine) : [],
|
line.rows.length
|
||||||
|
? [
|
||||||
|
...createSeriesOptions(line.rows, line.index, line.label, granulate),
|
||||||
|
...createAvgLineSeries(line.rows, line.index, line.label, granulate, showAvgLine, avgLineMode === 'auto'),
|
||||||
|
]
|
||||||
|
: [],
|
||||||
),
|
),
|
||||||
[granulate, lines, showAvgLine],
|
[granulate, lines, showAvgLine, avgLineMode],
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -28,16 +28,36 @@
|
|||||||
padding: 3px;
|
padding: 3px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.history-chart-line-mode button {
|
.archive-avgline-mode-control .history-chart-line-mode button {
|
||||||
min-height: 24px;
|
border-radius: 0;
|
||||||
padding: 0 8px;
|
|
||||||
font-size: 12px;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.history-chart-line-mode__button--active {
|
.archive-avgline-mode-control .history-chart-line-mode button:first-child {
|
||||||
color: #f8fafc;
|
border-top-left-radius: var(--radius);
|
||||||
background: rgba(212, 165, 116, 0.16);
|
border-bottom-left-radius: var(--radius);
|
||||||
border-color: rgba(212, 165, 116, 0.38);
|
}
|
||||||
|
|
||||||
|
.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,
|
||||||
@@ -56,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;
|
||||||
@@ -68,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