5 Commits

6 changed files with 49 additions and 7 deletions

View File

@@ -3,6 +3,6 @@ import { cloudApiUrl } from '../../shared/config/env';
import type { HistoryRequest, HistoryResponse } from './types'; import type { HistoryRequest, HistoryResponse } from './types';
/** Запрашивает исторический ряд с avg-линией и min/max-диапазоном для графика. */ /** Запрашивает исторический ряд с avg-линией и min/max-диапазоном для графика. */
export function getHistory(params: HistoryRequest): Promise<HistoryResponse> { export function getHistory(params: HistoryRequest, signal?: AbortSignal): Promise<HistoryResponse> {
return getJson<HistoryResponse>(cloudApiUrl, '/history', params); return getJson<HistoryResponse>(cloudApiUrl, '/history', params, { signal });
} }

View File

@@ -202,7 +202,12 @@ export function ArchiveView({
) : null} ) : null}
</div> </div>
<div className="archive-chart"> <div
className="archive-chart"
onFocusCapture={() => setSelectorOpen(false)}
onPointerDown={() => setSelectorOpen(false)}
onPointerEnter={() => setSelectorOpen(false)}
>
<div className="toolbar"> <div className="toolbar">
<div className="segmented"> <div className="segmented">
{RANGE_PRESETS.map((preset) => ( {RANGE_PRESETS.map((preset) => (
@@ -249,7 +254,7 @@ export function ArchiveView({
{selectedTags.length ? ( {selectedTags.length ? (
<HistoryChart <HistoryChart
key={`${range.from}:${range.to}:${selectedTags.join(',')}`} key={`${range.from}:${range.to}:${historyAxis.granulate}`}
edge={edgeId} edge={edgeId}
from={fromIso} from={fromIso}
to={toIso} to={toIso}

View File

@@ -18,6 +18,10 @@ type HistoryChartProps = {
}; };
/** Контейнер истории: загружает выбранные теги и передает готовые серии в область ECharts. */ /** Контейнер истории: загружает выбранные теги и передает готовые серии в область ECharts. */
function isXAxisDataZoom(state: DataZoomState): boolean {
return state.dataZoomId?.startsWith('history-x-') || state.dataZoomIndex === 0 || state.dataZoomIndex === 1;
}
export function HistoryChart({ export function HistoryChart({
edge, edge,
from, from,
@@ -49,7 +53,12 @@ export function HistoryChart({
); );
const handleDataZoom = useCallback((event: DataZoomEventBatch) => { const handleDataZoom = useCallback((event: DataZoomEventBatch) => {
const state = event.batch?.[0] ?? event; const state = (event.batch ?? [event]).find(isXAxisDataZoom);
if (!state) {
return;
}
dataZoomRef.current = { dataZoomRef.current = {
start: state.start, start: state.start,
end: state.end, end: state.end,

View File

@@ -8,6 +8,8 @@ export type TooltipParam = {
}; };
export type DataZoomState = { export type DataZoomState = {
dataZoomId?: string;
dataZoomIndex?: number;
start?: number; start?: number;
end?: number; end?: number;
startValue?: number; startValue?: number;

View File

@@ -54,7 +54,7 @@ export function createHistoryChartOptions({
grid: { grid: {
top: 54, top: 54,
left: 48, left: 48,
right: 24, right: 56,
bottom: 72, bottom: 72,
}, },
xAxis: { xAxis: {
@@ -79,7 +79,9 @@ export function createHistoryChartOptions({
}, },
dataZoom: [ dataZoom: [
{ {
id: 'history-x-inside',
type: 'inside', type: 'inside',
xAxisIndex: 0,
throttle: 80, throttle: 80,
start: dataZoomState.start, start: dataZoomState.start,
end: dataZoomState.end, end: dataZoomState.end,
@@ -87,7 +89,9 @@ export function createHistoryChartOptions({
endValue: dataZoomState.endValue, endValue: dataZoomState.endValue,
}, },
{ {
id: 'history-x-slider',
type: 'slider', type: 'slider',
xAxisIndex: 0,
bottom: 18, bottom: 18,
height: 28, height: 28,
borderColor: 'rgba(148, 163, 184, 0.24)', borderColor: 'rgba(148, 163, 184, 0.24)',
@@ -102,6 +106,28 @@ export function createHistoryChartOptions({
startValue: dataZoomState.startValue, startValue: dataZoomState.startValue,
endValue: dataZoomState.endValue, endValue: dataZoomState.endValue,
}, },
{
id: 'history-y-inside',
type: 'inside',
yAxisIndex: 0,
filterMode: 'none',
throttle: 80,
},
{
id: 'history-y-slider',
type: 'slider',
yAxisIndex: 0,
filterMode: 'none',
right: 8,
width: 12,
borderColor: 'rgba(148, 163, 184, 0.24)',
fillerColor: 'rgba(91, 143, 249, 0.18)',
handleStyle: {
color: '#d4a574',
borderColor: '#e8c9a0',
},
textStyle: { color: '#94a3b8' },
},
], ],
series, series,
}; };

View File

@@ -33,7 +33,7 @@ export function useHistoryChartQueries({
const queries = useQueries({ const queries = useQueries({
queries: tags.map((tag) => ({ queries: tags.map((tag) => ({
queryKey: ['history', edge, tag, from, to, granulate], queryKey: ['history', edge, tag, from, to, granulate],
queryFn: () => getHistory({ edge, tag, from, to, granulate }), queryFn: ({ signal }: { signal: AbortSignal }) => getHistory({ edge, tag, from, to, granulate }, signal),
enabled, enabled,
})), })),
}); });