|
1 | 1 | import { config } from 'app/core/config';
|
2 | 2 | import React, { useCallback, useMemo, useState } from 'react';
|
3 |
| -import { |
4 |
| - CartesianCoords2D, |
5 |
| - DashboardCursorSync, |
6 |
| - DataFrame, |
7 |
| - DataFrameType, |
8 |
| - PanelProps, |
9 |
| - toDataFrame, |
10 |
| - VizOrientation, |
11 |
| -} from '@grafana/data'; |
| 3 | +import { DashboardCursorSync, DataFrame, DataFrameType, PanelProps, toDataFrame, VizOrientation } from '@grafana/data'; |
12 | 4 | import { getAppEvents, getBackendSrv, PanelDataErrorView } from '@grafana/runtime';
|
13 | 5 | import { TooltipDisplayMode } from '@grafana/schema';
|
14 |
| -import { |
15 |
| - EventBusPlugin, |
16 |
| - KeyboardPlugin, |
17 |
| - MenuItemProps, |
18 |
| - TooltipPlugin, |
19 |
| - TooltipPlugin2, |
20 |
| - usePanelContext, |
21 |
| - ZoomPlugin, |
22 |
| -} from '@grafana/ui'; |
| 6 | +import { Button, EventBusPlugin, KeyboardPlugin, TooltipPlugin2, usePanelContext } from '@grafana/ui'; |
23 | 7 | import { TimeSeries } from 'app/core/components/TimeSeries/TimeSeries';
|
24 | 8 | import { Options } from './panelcfg.gen';
|
25 |
| -import { AnnotationEditorPlugin } from './plugins/AnnotationEditorPlugin'; |
26 |
| -import { AnnotationsPlugin } from './plugins/AnnotationsPlugin'; |
27 |
| -import { ContextMenuPlugin } from './plugins/ContextMenuPlugin'; |
28 | 9 | import { ExemplarsPlugin, getVisibleLabels } from './plugins/ExemplarsPlugin';
|
29 | 10 | import { OutsideRangePlugin } from './plugins/OutsideRangePlugin';
|
30 | 11 | import { ThresholdControlsPlugin } from './plugins/ThresholdControlsPlugin';
|
31 | 12 | import { TimescaleEditor } from './plugins/timescales/TimescaleEditor';
|
32 | 13 | import { TimescaleItem } from './plugins/timescales/TimescaleEditorForm';
|
33 | 14 | import { getPrepareTimeseriesSuggestion } from './suggestions';
|
34 | 15 | import { useRuntimeVariables } from './hooks';
|
35 |
| -import { getTimezones, prepareGraphableFields, regenerateLinksSupplier } from './utils'; |
| 16 | +import { getTimezones, prepareGraphableFields } from './utils'; |
36 | 17 | import { TimeRange2, TooltipHoverMode } from '@grafana/ui/src/components/uPlot/plugins/TooltipPlugin2';
|
37 | 18 | import { TimeSeriesTooltip } from './TimeSeriesTooltip';
|
38 | 19 | import { AnnotationsPlugin2 } from './plugins/AnnotationsPlugin2';
|
@@ -63,10 +44,7 @@ export const TimeSeriesPanel = ({
|
63 | 44 | } = usePanelContext();
|
64 | 45 |
|
65 | 46 | const [isAddingTimescale, setAddingTimescale] = useState(false);
|
66 |
| - const [timescaleTriggerCoords, setTimescaleTriggerCoords] = useState<{ |
67 |
| - viewport: CartesianCoords2D; |
68 |
| - plotCanvas: CartesianCoords2D; |
69 |
| - } | null>(null); |
| 47 | + const [timescaleTriggerCoords, setTimescaleTriggerCoords] = useState<{ left: number; top: number } | null>(null); |
70 | 48 |
|
71 | 49 | const isVerticallyOriented = options.orientation === VizOrientation.Vertical;
|
72 | 50 | const frames = useMemo(() => prepareGraphableFields(data.series, config.theme2, timeRange), [data.series, timeRange]);
|
@@ -273,6 +251,27 @@ export const TimeSeriesPanel = ({
|
273 | 251 | isPinned={isPinned}
|
274 | 252 | annotate={enableAnnotationCreation ? annotate : undefined}
|
275 | 253 | maxHeight={options.tooltip.maxHeight}
|
| 254 | + footerContent={ |
| 255 | + <> |
| 256 | + <Button |
| 257 | + icon="channel-add" |
| 258 | + variant="secondary" |
| 259 | + size="sm" |
| 260 | + id="custom-scales" |
| 261 | + onClick={() => { |
| 262 | + setTimescaleTriggerCoords({ |
| 263 | + left: u.rect.left + (u.cursor.left ?? 0), |
| 264 | + top: u.rect.top + (u.cursor.top ?? 0), |
| 265 | + }); |
| 266 | + setAddingTimescale(true); |
| 267 | + getTimescales(); |
| 268 | + dismiss(); |
| 269 | + }} |
| 270 | + > |
| 271 | + Custom scales |
| 272 | + </Button> |
| 273 | + </> |
| 274 | + } |
276 | 275 | />
|
277 | 276 | );
|
278 | 277 | }}
|
@@ -306,6 +305,19 @@ export const TimeSeriesPanel = ({
|
306 | 305 | )}
|
307 | 306 | </>
|
308 | 307 | )}
|
| 308 | + {isAddingTimescale && ( |
| 309 | + <TimescaleEditor |
| 310 | + onSave={onUpsertTimescales} |
| 311 | + onDismiss={() => setAddingTimescale(false)} |
| 312 | + scales={scales} |
| 313 | + style={{ |
| 314 | + position: 'absolute', |
| 315 | + left: timescaleTriggerCoords?.left, |
| 316 | + top: timescaleTriggerCoords?.top, |
| 317 | + }} |
| 318 | + timescalesFrame={timescalesFrame} |
| 319 | + /> |
| 320 | + )} |
309 | 321 | </>
|
310 | 322 | );
|
311 | 323 | }}
|
|
0 commit comments