Commit a28c25a2 by Torkel Ödegaard

progress on react time series infra

parent 9adad76f
...@@ -74,7 +74,7 @@ export class PanelChrome extends PureComponent<Props, State> { ...@@ -74,7 +74,7 @@ export class PanelChrome extends PureComponent<Props, State> {
refreshCounter={refreshCounter} refreshCounter={refreshCounter}
> >
{({ loading, timeSeries }) => { {({ loading, timeSeries }) => {
return <PanelComponent loading={loading} timeSeries={timeSeries} />; return <PanelComponent loading={loading} timeSeries={timeSeries} timeRange={timeRange} />;
}} }}
</DataPanel> </DataPanel>
</div> </div>
......
...@@ -3,7 +3,10 @@ import _ from 'lodash'; ...@@ -3,7 +3,10 @@ import _ from 'lodash';
import React, { PureComponent } from 'react'; import React, { PureComponent } from 'react';
// Components // Components
import { Graph } from 'app/viz/Graph'; import Graph from 'app/viz/Graph';
// Utils
import { getTimeSeriesVMs } from 'app/viz/state/timeSeries';
// Types // Types
import { PanelProps } from 'app/types'; import { PanelProps } from 'app/types';
...@@ -22,10 +25,11 @@ export class Graph2 extends PureComponent<Props> { ...@@ -22,10 +25,11 @@ export class Graph2 extends PureComponent<Props> {
} }
render() { render() {
const { timeSeries } = this.props; const { timeSeries, timeRange } = this.props;
let index = 0; const viewModels = getTimeSeriesVMs({ timeSeries });
console.log(viewModels);
return <Graph timeSeries={timeSeries} />; return <Graph timeSeries={viewModels} timeRange={timeRange} />;
} }
} }
......
...@@ -13,10 +13,11 @@ import { ...@@ -13,10 +13,11 @@ import {
TimeRange, TimeRange,
LoadingState, LoadingState,
TimeSeries, TimeSeries,
TimeSeriesVM,
TimeSeriesVMs,
DataQuery, DataQuery,
DataQueryResponse, DataQueryResponse,
DataQueryOptions, DataQueryOptions,
TimeSeriesViewModel,
} from './series'; } from './series';
import { PanelProps } from './panel'; import { PanelProps } from './panel';
...@@ -59,7 +60,8 @@ export { ...@@ -59,7 +60,8 @@ export {
LoadingState, LoadingState,
PanelProps, PanelProps,
TimeSeries, TimeSeries,
TimeSeriesViewModel, TimeSeriesVM,
TimeSeriesVMs,
DataQuery, DataQuery,
DataQueryResponse, DataQueryResponse,
DataQueryOptions, DataQueryOptions,
......
...@@ -28,10 +28,16 @@ export interface TimeSeries { ...@@ -28,10 +28,16 @@ export interface TimeSeries {
unit?: string; unit?: string;
} }
export interface TimeSeriesViewModel { /** View model projection of a time series */
export interface TimeSeriesVM {
label: string; label: string;
color: string; color: string;
data: number[][]; data: TimeSeriesValue[][];
}
/** View model projection of many time series */
export interface TimeSeriesVMs {
[index: number]: TimeSeriesVM;
} }
export interface DataQueryResponse { export interface DataQueryResponse {
......
...@@ -6,8 +6,7 @@ import 'vendor/flot/jquery.flot'; ...@@ -6,8 +6,7 @@ import 'vendor/flot/jquery.flot';
import 'vendor/flot/jquery.flot.time'; import 'vendor/flot/jquery.flot.time';
// Types // Types
import TimeSeries from 'app/core/time_series2'; import { TimeRange, TimeSeriesVMs } from 'app/types';
import { TimeRange } from 'app/types';
// Copied from graph.ts // Copied from graph.ts
function time_format(ticks, min, max) { function time_format(ticks, min, max) {
...@@ -60,7 +59,7 @@ const FLOT_OPTIONS = { ...@@ -60,7 +59,7 @@ const FLOT_OPTIONS = {
}; };
interface GraphProps { interface GraphProps {
timeSeries: TimeSeries[]; timeSeries: TimeSeriesVMs;
timeRange: TimeRange; timeRange: TimeRange;
size?: { width: number; height: number }; size?: { width: number; height: number };
} }
...@@ -85,11 +84,9 @@ export class Graph extends PureComponent<GraphProps> { ...@@ -85,11 +84,9 @@ export class Graph extends PureComponent<GraphProps> {
draw() { draw() {
const { size, timeSeries, timeRange } = this.props; const { size, timeSeries, timeRange } = this.props;
const data = timeSeries.map((ts: TimeSeries) => ({ if (!size) {
color: ts.color, return;
label: ts.label, }
data: ts.getFlotPairs('null'),
}));
const ticks = (size.width || 0) / 100; const ticks = (size.width || 0) / 100;
const min = timeRange.from.valueOf(); const min = timeRange.from.valueOf();
...@@ -111,7 +108,7 @@ export class Graph extends PureComponent<GraphProps> { ...@@ -111,7 +108,7 @@ export class Graph extends PureComponent<GraphProps> {
...dynamicOptions, ...dynamicOptions,
}; };
$.plot(this.element, data, options); $.plot(this.element, timeSeries, options);
} }
render() { render() {
......
import colors from 'app/core/utils/colors';
import { TimeSeries, TimeSeriesViewModel } from 'app/types';
interface Options {
ts: TimeSeries;
seriesIndex: number;
}
export function getTimeSeriesViewModel(ts: TimeSeries): TimeSeriesViewModel {}
import colors from 'app/core/utils/colors';
import { TimeSeries, TimeSeriesVMs } from 'app/types';
interface Options {
timeSeries: TimeSeries[];
}
export function getTimeSeriesVMs({ timeSeries }: Options): TimeSeriesVMs {
const vmSeries = timeSeries.map((item, index) => {
const colorIndex = index % colors.length;
const label = item.target;
return {
data: item.datapoints,
label: label,
color: colors[colorIndex],
};
});
return vmSeries;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment