Browse Source

don't require x & y columns for timeSeries

ryan 7 years ago
parent
commit
8bf57359ab

+ 17 - 2
packages/grafana-ui/src/utils/processTimeSeries.ts

@@ -8,13 +8,28 @@ import { TimeSeriesVMs, NullValueMode, TimeSeriesValue, TableData } from '../typ
 
 interface Options {
   data: TableData[];
-  xColumn: number; // Time
-  yColumn: number; // Value
+  xColumn?: number; // Time
+  yColumn?: number; // Value
   nullValueMode: NullValueMode;
 }
 
 export function processTimeSeries({ data, xColumn, yColumn, nullValueMode }: Options): TimeSeriesVMs {
   const vmSeries = data.map((item, index) => {
+    if (!isNumber(xColumn)) {
+      xColumn = 1; // Default timeseries colum.  TODO, find first time field!
+    }
+    if (!isNumber(yColumn)) {
+      yColumn = 0; // TODO, find first non-time field
+    }
+
+    // TODO? either % or throw error?
+    if (xColumn >= item.columns.length) {
+      throw new Error('invalid colum: ' + xColumn);
+    }
+    if (yColumn >= item.columns.length) {
+      throw new Error('invalid colum: ' + yColumn);
+    }
+
     const colorIndex = index % colors.length;
     const label = item.columns[yColumn].text;
     const result = [];

+ 1 - 5
public/app/features/dashboard/dashgrid/DataPanel.tsx

@@ -145,12 +145,10 @@ export class DataPanel extends Component<Props, State> {
         onDataResponse(resp);
       }
 
-      const data = toTableData(resp.data);
-      console.log('Converted:', data);
       this.setState({
         loading: LoadingState.Done,
         response: resp,
-        data,
+        data: toTableData(resp.data),
         isFirstLoad: false,
       });
     } catch (err) {
@@ -190,8 +188,6 @@ export class DataPanel extends Component<Props, State> {
       );
     }
 
-    console.log('RENDER', data);
-
     return (
       <>
         {loading === LoadingState.Loading && this.renderLoadingState()}

+ 0 - 12
public/app/plugins/panel/gauge/GaugePanel.tsx

@@ -22,12 +22,9 @@ export class GaugePanel extends Component<Props, State> {
     this.state = {
       value: this.findValue(props),
     };
-    console.log('CONSTRUCTOR!', this.props.data);
   }
 
   componentDidUpdate(prevProps: Props) {
-    console.log('UPDATE', this.props.data);
-
     if (this.props.data !== prevProps.data) {
       this.setState({ value: this.findValue(this.props) });
     }
@@ -37,21 +34,12 @@ export class GaugePanel extends Component<Props, State> {
     const { data, options } = props;
     const { valueOptions } = options;
 
-    console.log('FIND VALUE', data);
-
     if (data) {
-      // For now, assume timeseries defaults
-      const xColumn = 1; // time
-      const yColumn = 0; // value
       const vmSeries = processTimeSeries({
         data,
-        xColumn,
-        yColumn,
         nullValueMode: NullValueMode.Null,
       });
 
-      console.log('GOT', vmSeries);
-
       if (vmSeries[0]) {
         return vmSeries[0].stats[valueOptions.stat];
       }

+ 0 - 5
public/app/plugins/panel/graph2/GraphPanel.tsx

@@ -21,13 +21,8 @@ export class GraphPanel extends PureComponent<Props> {
 
     let vmSeries: TimeSeriesVMs;
     if (data) {
-      // For now, assume timeseries defaults
-      const xColumn = 1; // time
-      const yColumn = 0; // value
       vmSeries = processTimeSeries({
         data,
-        xColumn,
-        yColumn,
         nullValueMode: NullValueMode.Ignore,
       });
     }