From a02b4b47b61d737bc323600788556746dfe8a65c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torkel=20=C3=96degaard?= Date: Sun, 23 Dec 2018 09:15:32 +0100 Subject: [PATCH] Moving a couple of types to @grafana/ui --- packages/grafana-ui/src/types/index.ts | 2 + packages/grafana-ui/src/types/panel.ts | 31 +++++++++ packages/grafana-ui/src/types/series.ts | 50 ++++++++++++-- packages/grafana-ui/src/types/time.ts | 17 +++++ public/app/core/utils/explore.ts | 3 +- public/app/core/utils/rangeutil.ts | 2 +- .../features/dashboard/dashgrid/DataPanel.tsx | 4 +- .../dashboard/dashgrid/PanelChrome.tsx | 3 +- .../dashgrid/PanelHeader/PanelHeaderMenu.tsx | 2 +- .../PanelHeader/PanelHeaderMenuItem.tsx | 2 +- .../dashgrid/PanelPluginNotFound.tsx | 6 +- public/app/features/dashboard/time_srv.ts | 4 +- .../features/dashboard/utils/getPanelMenu.ts | 2 +- public/app/features/dashboard/utils/panel.ts | 2 +- public/app/features/explore/Explore.tsx | 3 +- public/app/features/explore/Graph.tsx | 2 +- public/app/features/explore/Logs.tsx | 2 +- public/app/features/explore/QueryEditor.tsx | 2 +- public/app/features/explore/QueryRows.tsx | 2 +- public/app/features/explore/TimePicker.tsx | 2 +- .../plugins/panel/gauge/Threshold.test.tsx | 3 +- public/app/plugins/panel/gauge/module.tsx | 11 +--- .../app/plugins/panel/graph2/GraphOptions.tsx | 2 +- .../app/plugins/panel/graph2/GraphPanel.tsx | 2 +- public/app/plugins/panel/text2/module.tsx | 2 +- public/app/types/explore.ts | 3 +- public/app/types/index.ts | 24 +------ public/app/types/panel.ts | 32 --------- public/app/types/plugins.ts | 2 +- public/app/types/series.ts | 65 +------------------ public/app/viz/Gauge.tsx | 3 +- public/app/viz/Graph.tsx | 2 +- public/app/viz/state/timeSeries.ts | 2 +- 33 files changed, 137 insertions(+), 159 deletions(-) create mode 100644 packages/grafana-ui/src/types/panel.ts create mode 100644 packages/grafana-ui/src/types/time.ts diff --git a/packages/grafana-ui/src/types/index.ts b/packages/grafana-ui/src/types/index.ts index 0ca60a90923..f618ce6db34 100644 --- a/packages/grafana-ui/src/types/index.ts +++ b/packages/grafana-ui/src/types/index.ts @@ -1 +1,3 @@ export * from './series'; +export * from './time'; +export * from './panel'; diff --git a/packages/grafana-ui/src/types/panel.ts b/packages/grafana-ui/src/types/panel.ts new file mode 100644 index 00000000000..44336555a81 --- /dev/null +++ b/packages/grafana-ui/src/types/panel.ts @@ -0,0 +1,31 @@ +import { TimeSeries, LoadingState } from './series'; +import { TimeRange } from './time'; + +export interface PanelProps { + timeSeries: TimeSeries[]; + timeRange: TimeRange; + loading: LoadingState; + options: T; + renderCounter: number; + width: number; + height: number; +} + +export interface PanelOptionsProps { + options: T; + onChange: (options: T) => void; +} + +export interface PanelSize { + width: number; + height: number; +} + +export interface PanelMenuItem { + type?: 'submenu' | 'divider'; + text?: string; + iconClassName?: string; + onClick?: () => void; + shortcut?: string; + subMenu?: PanelMenuItem[]; +} diff --git a/packages/grafana-ui/src/types/series.ts b/packages/grafana-ui/src/types/series.ts index 9c79ebdc99f..6868ff567c9 100644 --- a/packages/grafana-ui/src/types/series.ts +++ b/packages/grafana-ui/src/types/series.ts @@ -1,5 +1,3 @@ -import { Moment } from 'moment'; - export enum LoadingState { NotStarted = 'NotStarted', Loading = 'Loading', @@ -7,7 +5,49 @@ export enum LoadingState { Error = 'Error', } -export interface RawTimeRange { - from: Moment | string; - to: Moment | string; +export type TimeSeriesValue = string | number | null; + +export type TimeSeriesPoints = TimeSeriesValue[][]; + +export interface TimeSeries { + target: string; + datapoints: TimeSeriesPoints; + unit?: string; +} + +/** View model projection of a time series */ +export interface TimeSeriesVM { + label: string; + color: string; + data: TimeSeriesValue[][]; + stats: TimeSeriesStats; +} + +export interface TimeSeriesStats { + total: number; + max: number; + min: number; + logmin: number; + avg: number | null; + current: number | null; + first: number | null; + delta: number; + diff: number | null; + range: number | null; + timeStep: number; + count: number; + allIsNull: boolean; + allIsZero: boolean; +} + +export enum NullValueMode { + Null = 'null', + Ignore = 'connected', + AsZero = 'null as zero', +} + +/** View model projection of many time series */ +export interface TimeSeriesVMs { + [index: number]: TimeSeriesVM; + length: number; } diff --git a/packages/grafana-ui/src/types/time.ts b/packages/grafana-ui/src/types/time.ts new file mode 100644 index 00000000000..b6acf7f07b6 --- /dev/null +++ b/packages/grafana-ui/src/types/time.ts @@ -0,0 +1,17 @@ +import { Moment } from 'moment'; + +export interface RawTimeRange { + from: Moment | string; + to: Moment | string; +} + +export interface TimeRange { + from: Moment; + to: Moment; + raw: RawTimeRange; +} + +export interface IntervalValues { + interval: string; // 10s,5m + intervalMs: number; +} diff --git a/public/app/core/utils/explore.ts b/public/app/core/utils/explore.ts index f978ec1ef8c..b7de48ac479 100644 --- a/public/app/core/utils/explore.ts +++ b/public/app/core/utils/explore.ts @@ -9,7 +9,8 @@ import { parse as parseDate } from 'app/core/utils/datemath'; import TimeSeries from 'app/core/time_series2'; import TableModel, { mergeTablesIntoModel } from 'app/core/table_model'; import { ExploreState, ExploreUrlState, HistoryItem, QueryTransaction } from 'app/types/explore'; -import { DataQuery, RawTimeRange, IntervalValues, DataSourceApi } from 'app/types/series'; +import { DataQuery, DataSourceApi } from 'app/types/series'; +import { RawTimeRange, IntervalValues } from '@grafana/ui'; export const DEFAULT_RANGE = { from: 'now-6h', diff --git a/public/app/core/utils/rangeutil.ts b/public/app/core/utils/rangeutil.ts index 0150e80f1ed..310c8ab8533 100644 --- a/public/app/core/utils/rangeutil.ts +++ b/public/app/core/utils/rangeutil.ts @@ -1,7 +1,7 @@ import _ from 'lodash'; import moment from 'moment'; -import { RawTimeRange } from 'app/types/series'; +import { RawTimeRange } from '@grafana/ui'; import * as dateMath from './datemath'; diff --git a/public/app/features/dashboard/dashgrid/DataPanel.tsx b/public/app/features/dashboard/dashgrid/DataPanel.tsx index 2a72b16d60f..30a939b50aa 100644 --- a/public/app/features/dashboard/dashgrid/DataPanel.tsx +++ b/public/app/features/dashboard/dashgrid/DataPanel.tsx @@ -8,8 +8,8 @@ import { getDatasourceSrv, DatasourceSrv } from 'app/features/plugins/datasource import kbn from 'app/core/utils/kbn'; // Types -import { TimeRange, DataQueryOptions, DataQueryResponse, TimeSeries } from 'app/types'; -import { LoadingState } from '@grafana/ui'; +import { DataQueryOptions, DataQueryResponse } from 'app/types'; +import { TimeRange, TimeSeries, LoadingState } from '@grafana/ui'; interface RenderProps { loading: LoadingState; diff --git a/public/app/features/dashboard/dashgrid/PanelChrome.tsx b/public/app/features/dashboard/dashgrid/PanelChrome.tsx index 5df6f20fc23..94719dfe6e0 100644 --- a/public/app/features/dashboard/dashgrid/PanelChrome.tsx +++ b/public/app/features/dashboard/dashgrid/PanelChrome.tsx @@ -16,7 +16,8 @@ import { PANEL_HEADER_HEIGHT } from 'app/core/constants'; // Types import { PanelModel } from '../panel_model'; import { DashboardModel } from '../dashboard_model'; -import { PanelPlugin, TimeRange } from 'app/types'; +import { PanelPlugin } from 'app/types'; +import { TimeRange } from '@grafana/ui'; export interface Props { panel: PanelModel; diff --git a/public/app/features/dashboard/dashgrid/PanelHeader/PanelHeaderMenu.tsx b/public/app/features/dashboard/dashgrid/PanelHeader/PanelHeaderMenu.tsx index cde540c0509..1d17ec6cefc 100644 --- a/public/app/features/dashboard/dashgrid/PanelHeader/PanelHeaderMenu.tsx +++ b/public/app/features/dashboard/dashgrid/PanelHeader/PanelHeaderMenu.tsx @@ -3,7 +3,7 @@ import { DashboardModel } from 'app/features/dashboard/dashboard_model'; import { PanelModel } from 'app/features/dashboard/panel_model'; import { PanelHeaderMenuItem } from './PanelHeaderMenuItem'; import { getPanelMenu } from 'app/features/dashboard/utils/getPanelMenu'; -import { PanelMenuItem } from 'app/types/panel'; +import { PanelMenuItem } from '@grafana/ui'; export interface Props { panel: PanelModel; diff --git a/public/app/features/dashboard/dashgrid/PanelHeader/PanelHeaderMenuItem.tsx b/public/app/features/dashboard/dashgrid/PanelHeader/PanelHeaderMenuItem.tsx index 92a64a2f24d..d42b48fe1d6 100644 --- a/public/app/features/dashboard/dashgrid/PanelHeader/PanelHeaderMenuItem.tsx +++ b/public/app/features/dashboard/dashgrid/PanelHeader/PanelHeaderMenuItem.tsx @@ -1,5 +1,5 @@ import React, { SFC } from 'react'; -import { PanelMenuItem } from 'app/types/panel'; +import { PanelMenuItem } from '@grafana/ui'; interface Props { children: any; diff --git a/public/app/features/dashboard/dashgrid/PanelPluginNotFound.tsx b/public/app/features/dashboard/dashgrid/PanelPluginNotFound.tsx index 82008b10d2f..18b307b5ea5 100644 --- a/public/app/features/dashboard/dashgrid/PanelPluginNotFound.tsx +++ b/public/app/features/dashboard/dashgrid/PanelPluginNotFound.tsx @@ -1,6 +1,10 @@ +// Libraries import _ from 'lodash'; import React, { PureComponent } from 'react'; -import { PanelPlugin, PanelProps } from 'app/types'; + +// Types +import { PanelProps } from '@grafana/ui'; +import { PanelPlugin } from 'app/types'; interface Props { pluginId: string; diff --git a/public/app/features/dashboard/time_srv.ts b/public/app/features/dashboard/time_srv.ts index ac717de15c9..b4d18e0279a 100644 --- a/public/app/features/dashboard/time_srv.ts +++ b/public/app/features/dashboard/time_srv.ts @@ -6,9 +6,9 @@ import _ from 'lodash'; import kbn from 'app/core/utils/kbn'; import coreModule from 'app/core/core_module'; import * as dateMath from 'app/core/utils/datemath'; -// Types -import { TimeRange } from 'app/types'; +// Types +import { TimeRange } from '@grafana/ui'; export class TimeSrv { time: any; diff --git a/public/app/features/dashboard/utils/getPanelMenu.ts b/public/app/features/dashboard/utils/getPanelMenu.ts index 07ce54108f3..190451671ad 100644 --- a/public/app/features/dashboard/utils/getPanelMenu.ts +++ b/public/app/features/dashboard/utils/getPanelMenu.ts @@ -4,7 +4,7 @@ import { store } from 'app/store/store'; import { removePanel, duplicatePanel, copyPanel, editPanelJson, sharePanel } from 'app/features/dashboard/utils/panel'; import { PanelModel } from 'app/features/dashboard/panel_model'; import { DashboardModel } from 'app/features/dashboard/dashboard_model'; -import { PanelMenuItem } from 'app/types/panel'; +import { PanelMenuItem } from '@grafana/ui'; export const getPanelMenu = (dashboard: DashboardModel, panel: PanelModel) => { const onViewPanel = () => { diff --git a/public/app/features/dashboard/utils/panel.ts b/public/app/features/dashboard/utils/panel.ts index 0b0f127e2aa..f7ed0efd910 100644 --- a/public/app/features/dashboard/utils/panel.ts +++ b/public/app/features/dashboard/utils/panel.ts @@ -4,7 +4,7 @@ import store from 'app/core/store'; // Models import { DashboardModel } from 'app/features/dashboard/dashboard_model'; import { PanelModel } from 'app/features/dashboard/panel_model'; -import { TimeRange } from 'app/types/series'; +import { TimeRange } from '@grafana/ui'; // Utils import { isString as _isString } from 'lodash'; diff --git a/public/app/features/explore/Explore.tsx b/public/app/features/explore/Explore.tsx index e8897c6926a..f56d9cabd16 100644 --- a/public/app/features/explore/Explore.tsx +++ b/public/app/features/explore/Explore.tsx @@ -11,7 +11,8 @@ import { QueryHintGetter, QueryHint, } from 'app/types/explore'; -import { TimeRange, DataQuery } from 'app/types/series'; +import { TimeRange } from '@grafana/ui'; +import { DataQuery } from 'app/types/series'; import store from 'app/core/store'; import { DEFAULT_RANGE, diff --git a/public/app/features/explore/Graph.tsx b/public/app/features/explore/Graph.tsx index 10f3faa1267..5d64dde28ce 100644 --- a/public/app/features/explore/Graph.tsx +++ b/public/app/features/explore/Graph.tsx @@ -8,7 +8,7 @@ import 'vendor/flot/jquery.flot.time'; import 'vendor/flot/jquery.flot.selection'; import 'vendor/flot/jquery.flot.stack'; -import { RawTimeRange } from 'app/types/series'; +import { RawTimeRange } from '@grafana/ui'; import * as dateMath from 'app/core/utils/datemath'; import TimeSeries from 'app/core/time_series2'; diff --git a/public/app/features/explore/Logs.tsx b/public/app/features/explore/Logs.tsx index 2119f5a96b7..1a384cf011d 100644 --- a/public/app/features/explore/Logs.tsx +++ b/public/app/features/explore/Logs.tsx @@ -4,7 +4,7 @@ import Highlighter from 'react-highlight-words'; import classnames from 'classnames'; import * as rangeUtil from 'app/core/utils/rangeutil'; -import { RawTimeRange } from 'app/types/series'; +import { RawTimeRange } from '@grafana/ui'; import { LogsDedupDescription, LogsDedupStrategy, diff --git a/public/app/features/explore/QueryEditor.tsx b/public/app/features/explore/QueryEditor.tsx index 7ad659ec784..ce0a8a6e03e 100644 --- a/public/app/features/explore/QueryEditor.tsx +++ b/public/app/features/explore/QueryEditor.tsx @@ -3,7 +3,7 @@ import { getAngularLoader, AngularComponent } from 'app/core/services/AngularLoa import { Emitter } from 'app/core/utils/emitter'; import { getIntervals } from 'app/core/utils/explore'; import { DataQuery } from 'app/types'; -import { RawTimeRange } from 'app/types/series'; +import { RawTimeRange } from '@grafana/ui'; import { getTimeSrv } from 'app/features/dashboard/time_srv'; import 'app/features/plugins/plugin_loader'; diff --git a/public/app/features/explore/QueryRows.tsx b/public/app/features/explore/QueryRows.tsx index 45a8c48ca22..4101475092b 100644 --- a/public/app/features/explore/QueryRows.tsx +++ b/public/app/features/explore/QueryRows.tsx @@ -7,7 +7,7 @@ import { Emitter } from 'app/core/utils/emitter'; import QueryEditor from './QueryEditor'; import QueryTransactionStatus from './QueryTransactionStatus'; import { DataSource, DataQuery } from 'app/types'; -import { RawTimeRange } from 'app/types/series'; +import { RawTimeRange } from '@grafana/ui'; function getFirstHintFromTransactions(transactions: QueryTransaction[]): QueryHint { const transaction = transactions.find(qt => qt.hints && qt.hints.length > 0); diff --git a/public/app/features/explore/TimePicker.tsx b/public/app/features/explore/TimePicker.tsx index b99618d257a..8476c6b2b27 100644 --- a/public/app/features/explore/TimePicker.tsx +++ b/public/app/features/explore/TimePicker.tsx @@ -3,7 +3,7 @@ import moment from 'moment'; import * as dateMath from 'app/core/utils/datemath'; import * as rangeUtil from 'app/core/utils/rangeutil'; -import { RawTimeRange, TimeRange } from 'app/types/series'; +import { RawTimeRange, TimeRange } from '@grafana/ui'; const DATE_FORMAT = 'YYYY-MM-DD HH:mm:ss'; export const DEFAULT_RANGE = { diff --git a/public/app/plugins/panel/gauge/Threshold.test.tsx b/public/app/plugins/panel/gauge/Threshold.test.tsx index 3b2becd9859..3fa508b98a9 100644 --- a/public/app/plugins/panel/gauge/Threshold.test.tsx +++ b/public/app/plugins/panel/gauge/Threshold.test.tsx @@ -2,7 +2,8 @@ import React from 'react'; import { shallow } from 'enzyme'; import Thresholds from './Thresholds'; import { defaultProps, OptionsProps } from './module'; -import { BasicGaugeColor, PanelOptionsProps } from 'app/types'; +import { BasicGaugeColor } from 'app/types'; +import { PanelOptionsProps } from '@grafana/ui'; const setup = (propOverrides?: object) => { const props: PanelOptionsProps = { diff --git a/public/app/plugins/panel/gauge/module.tsx b/public/app/plugins/panel/gauge/module.tsx index 152e7c20b5e..245a17abe52 100644 --- a/public/app/plugins/panel/gauge/module.tsx +++ b/public/app/plugins/panel/gauge/module.tsx @@ -5,15 +5,8 @@ import ValueOptions from './ValueOptions'; import GaugeOptions from './GaugeOptions'; import Thresholds from './Thresholds'; import ValueMappings from './ValueMappings'; -import { - BasicGaugeColor, - NullValueMode, - PanelOptionsProps, - PanelProps, - RangeMap, - Threshold, - ValueMap, -} from 'app/types'; +import { PanelOptionsProps, PanelProps, NullValueMode } from '@grafana/ui'; +import { BasicGaugeColor, RangeMap, Threshold, ValueMap } from 'app/types'; export interface OptionsProps { baseColor: string; diff --git a/public/app/plugins/panel/graph2/GraphOptions.tsx b/public/app/plugins/panel/graph2/GraphOptions.tsx index e87c03da634..6bb4b2c13d5 100644 --- a/public/app/plugins/panel/graph2/GraphOptions.tsx +++ b/public/app/plugins/panel/graph2/GraphOptions.tsx @@ -6,7 +6,7 @@ import React, { PureComponent } from 'react'; import { Switch } from 'app/core/components/Switch/Switch'; // Types -import { PanelOptionsProps } from 'app/types'; +import { PanelOptionsProps } from '@grafana/ui'; import { Options } from './types'; export class GraphOptions extends PureComponent> { diff --git a/public/app/plugins/panel/graph2/GraphPanel.tsx b/public/app/plugins/panel/graph2/GraphPanel.tsx index a7ef45e5428..95dc5a9e620 100644 --- a/public/app/plugins/panel/graph2/GraphPanel.tsx +++ b/public/app/plugins/panel/graph2/GraphPanel.tsx @@ -9,7 +9,7 @@ import Graph from 'app/viz/Graph'; import { getTimeSeriesVMs } from 'app/viz/state/timeSeries'; // Types -import { PanelProps, NullValueMode } from 'app/types'; +import { PanelProps, NullValueMode } from '@grafana/ui'; import { Options } from './types'; interface Props extends PanelProps {} diff --git a/public/app/plugins/panel/text2/module.tsx b/public/app/plugins/panel/text2/module.tsx index aaca23ccbf0..68523ff0880 100644 --- a/public/app/plugins/panel/text2/module.tsx +++ b/public/app/plugins/panel/text2/module.tsx @@ -1,5 +1,5 @@ import React, { PureComponent } from 'react'; -import { PanelProps } from 'app/types'; +import { PanelProps } from '@grafana/ui'; export class Text2 extends PureComponent { constructor(props) { diff --git a/public/app/types/explore.ts b/public/app/types/explore.ts index 80d55eedb60..647b3e99398 100644 --- a/public/app/types/explore.ts +++ b/public/app/types/explore.ts @@ -1,6 +1,7 @@ import { Value } from 'slate'; -import { DataQuery, RawTimeRange } from './series'; +import { DataQuery } from './series'; +import { RawTimeRange } from '@grafana/ui'; import TableModel from 'app/core/table_model'; import { LogsModel } from 'app/core/logs_model'; import { DataSourceSelectItem } from 'app/types/datasources'; diff --git a/public/app/types/index.ts b/public/app/types/index.ts index dd84f4acf7d..ab52b03ab17 100644 --- a/public/app/types/index.ts +++ b/public/app/types/index.ts @@ -8,19 +8,8 @@ import { DashboardAcl, OrgRole, PermissionLevel } from './acl'; import { ApiKey, ApiKeysState, NewApiKey } from './apiKeys'; import { Invitee, OrgUser, User, UsersState, UserState } from './user'; import { DataSource, DataSourceSelectItem, DataSourcesState } from './datasources'; -import { - TimeRange, - TimeSeries, - TimeSeriesVM, - TimeSeriesVMs, - TimeSeriesStats, - NullValueMode, - DataQuery, - DataQueryResponse, - DataQueryOptions, - IntervalValues, -} from './series'; -import { BasicGaugeColor, MappingType, PanelProps, PanelOptionsProps, RangeMap, Threshold, ValueMap } from './panel'; +import { DataQuery, DataQueryResponse, DataQueryOptions } from './series'; +import { BasicGaugeColor, MappingType, RangeMap, Threshold, ValueMap } from './panel'; import { PluginDashboard, PluginMeta, Plugin, PanelPlugin, PluginsState } from './plugins'; import { Organization, OrganizationState } from './organization'; import { @@ -67,15 +56,7 @@ export { OrgUser, User, UsersState, - TimeRange, PanelPlugin, - PanelProps, - PanelOptionsProps, - TimeSeries, - TimeSeriesVM, - TimeSeriesVMs, - NullValueMode, - TimeSeriesStats, DataQuery, DataQueryResponse, DataQueryOptions, @@ -93,7 +74,6 @@ export { ValidationRule, ValueMap, RangeMap, - IntervalValues, MappingType, BasicGaugeColor, }; diff --git a/public/app/types/panel.ts b/public/app/types/panel.ts index d5db8256670..31674d20304 100644 --- a/public/app/types/panel.ts +++ b/public/app/types/panel.ts @@ -1,35 +1,3 @@ -import { TimeSeries, TimeRange } from './series'; -import { LoadingState } from '@grafana/ui'; - -export interface PanelProps { - timeSeries: TimeSeries[]; - timeRange: TimeRange; - loading: LoadingState; - options: T; - renderCounter: number; - width: number; - height: number; -} - -export interface PanelOptionsProps { - options: T; - onChange: (options: T) => void; -} - -export interface PanelSize { - width: number; - height: number; -} - -export interface PanelMenuItem { - type?: 'submenu' | 'divider'; - text?: string; - iconClassName?: string; - onClick?: () => void; - shortcut?: string; - subMenu?: PanelMenuItem[]; -} - export interface Threshold { index: number; value: number; diff --git a/public/app/types/plugins.ts b/public/app/types/plugins.ts index a3519e5b5cc..a1403c7a71c 100644 --- a/public/app/types/plugins.ts +++ b/public/app/types/plugins.ts @@ -1,5 +1,5 @@ import { ComponentClass } from 'react'; -import { PanelProps, PanelOptionsProps } from './panel'; +import { PanelProps, PanelOptionsProps } from '@grafana/ui'; export interface PluginExports { Datasource?: any; diff --git a/public/app/types/series.ts b/public/app/types/series.ts index f7e196a03f5..9fe68955da5 100644 --- a/public/app/types/series.ts +++ b/public/app/types/series.ts @@ -1,68 +1,5 @@ -import { Moment } from 'moment'; import { PluginMeta } from './plugins'; - -export interface RawTimeRange { - from: Moment | string; - to: Moment | string; -} - -export interface TimeRange { - from: Moment; - to: Moment; - raw: RawTimeRange; -} - -export interface IntervalValues { - interval: string; // 10s,5m - intervalMs: number; -} - -export type TimeSeriesValue = string | number | null; - -export type TimeSeriesPoints = TimeSeriesValue[][]; - -export interface TimeSeries { - target: string; - datapoints: TimeSeriesPoints; - unit?: string; -} - -/** View model projection of a time series */ -export interface TimeSeriesVM { - label: string; - color: string; - data: TimeSeriesValue[][]; - stats: TimeSeriesStats; -} - -export interface TimeSeriesStats { - total: number; - max: number; - min: number; - logmin: number; - avg: number | null; - current: number | null; - first: number | null; - delta: number; - diff: number | null; - range: number | null; - timeStep: number; - count: number; - allIsNull: boolean; - allIsZero: boolean; -} - -export enum NullValueMode { - Null = 'null', - Ignore = 'connected', - AsZero = 'null as zero', -} - -/** View model projection of many time series */ -export interface TimeSeriesVMs { - [index: number]: TimeSeriesVM; - length: number; -} +import { TimeSeries, TimeRange, RawTimeRange } from '@grafana/ui'; export interface DataQueryResponse { data: TimeSeries[]; diff --git a/public/app/viz/Gauge.tsx b/public/app/viz/Gauge.tsx index 9907ddf575f..031d856f492 100644 --- a/public/app/viz/Gauge.tsx +++ b/public/app/viz/Gauge.tsx @@ -1,6 +1,7 @@ import React, { PureComponent } from 'react'; import $ from 'jquery'; -import { BasicGaugeColor, MappingType, RangeMap, Threshold, TimeSeriesVMs, ValueMap } from 'app/types'; +import { BasicGaugeColor, MappingType, RangeMap, Threshold, ValueMap } from 'app/types'; +import { TimeSeriesVMs } from '@grafana/ui'; import config from '../core/config'; import kbn from '../core/utils/kbn'; diff --git a/public/app/viz/Graph.tsx b/public/app/viz/Graph.tsx index bdababb3e50..c1330d6ce8a 100644 --- a/public/app/viz/Graph.tsx +++ b/public/app/viz/Graph.tsx @@ -5,7 +5,7 @@ import 'vendor/flot/jquery.flot'; import 'vendor/flot/jquery.flot.time'; // Types -import { TimeRange, TimeSeriesVMs } from 'app/types'; +import { TimeRange, TimeSeriesVMs } from '@grafana/ui'; interface GraphProps { timeSeries: TimeSeriesVMs; diff --git a/public/app/viz/state/timeSeries.ts b/public/app/viz/state/timeSeries.ts index e22cb4681b7..782383957bc 100644 --- a/public/app/viz/state/timeSeries.ts +++ b/public/app/viz/state/timeSeries.ts @@ -5,7 +5,7 @@ import _ from 'lodash'; import colors from 'app/core/utils/colors'; // Types -import { TimeSeries, TimeSeriesVMs, NullValueMode } from 'app/types'; +import { TimeSeries, TimeSeriesVMs, NullValueMode } from '@grafana/ui'; interface Options { timeSeries: TimeSeries[];