Commit 8bf57359 by ryan

don't require x & y columns for timeSeries

parent abf015ac
...@@ -8,13 +8,28 @@ import { TimeSeriesVMs, NullValueMode, TimeSeriesValue, TableData } from '../typ ...@@ -8,13 +8,28 @@ import { TimeSeriesVMs, NullValueMode, TimeSeriesValue, TableData } from '../typ
interface Options { interface Options {
data: TableData[]; data: TableData[];
xColumn: number; // Time xColumn?: number; // Time
yColumn: number; // Value yColumn?: number; // Value
nullValueMode: NullValueMode; nullValueMode: NullValueMode;
} }
export function processTimeSeries({ data, xColumn, yColumn, nullValueMode }: Options): TimeSeriesVMs { export function processTimeSeries({ data, xColumn, yColumn, nullValueMode }: Options): TimeSeriesVMs {
const vmSeries = data.map((item, index) => { 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 colorIndex = index % colors.length;
const label = item.columns[yColumn].text; const label = item.columns[yColumn].text;
const result = []; const result = [];
......
...@@ -145,12 +145,10 @@ export class DataPanel extends Component<Props, State> { ...@@ -145,12 +145,10 @@ export class DataPanel extends Component<Props, State> {
onDataResponse(resp); onDataResponse(resp);
} }
const data = toTableData(resp.data);
console.log('Converted:', data);
this.setState({ this.setState({
loading: LoadingState.Done, loading: LoadingState.Done,
response: resp, response: resp,
data, data: toTableData(resp.data),
isFirstLoad: false, isFirstLoad: false,
}); });
} catch (err) { } catch (err) {
...@@ -190,8 +188,6 @@ export class DataPanel extends Component<Props, State> { ...@@ -190,8 +188,6 @@ export class DataPanel extends Component<Props, State> {
); );
} }
console.log('RENDER', data);
return ( return (
<> <>
{loading === LoadingState.Loading && this.renderLoadingState()} {loading === LoadingState.Loading && this.renderLoadingState()}
......
...@@ -22,12 +22,9 @@ export class GaugePanel extends Component<Props, State> { ...@@ -22,12 +22,9 @@ export class GaugePanel extends Component<Props, State> {
this.state = { this.state = {
value: this.findValue(props), value: this.findValue(props),
}; };
console.log('CONSTRUCTOR!', this.props.data);
} }
componentDidUpdate(prevProps: Props) { componentDidUpdate(prevProps: Props) {
console.log('UPDATE', this.props.data);
if (this.props.data !== prevProps.data) { if (this.props.data !== prevProps.data) {
this.setState({ value: this.findValue(this.props) }); this.setState({ value: this.findValue(this.props) });
} }
...@@ -37,21 +34,12 @@ export class GaugePanel extends Component<Props, State> { ...@@ -37,21 +34,12 @@ export class GaugePanel extends Component<Props, State> {
const { data, options } = props; const { data, options } = props;
const { valueOptions } = options; const { valueOptions } = options;
console.log('FIND VALUE', data);
if (data) { if (data) {
// For now, assume timeseries defaults
const xColumn = 1; // time
const yColumn = 0; // value
const vmSeries = processTimeSeries({ const vmSeries = processTimeSeries({
data, data,
xColumn,
yColumn,
nullValueMode: NullValueMode.Null, nullValueMode: NullValueMode.Null,
}); });
console.log('GOT', vmSeries);
if (vmSeries[0]) { if (vmSeries[0]) {
return vmSeries[0].stats[valueOptions.stat]; return vmSeries[0].stats[valueOptions.stat];
} }
......
...@@ -21,13 +21,8 @@ export class GraphPanel extends PureComponent<Props> { ...@@ -21,13 +21,8 @@ export class GraphPanel extends PureComponent<Props> {
let vmSeries: TimeSeriesVMs; let vmSeries: TimeSeriesVMs;
if (data) { if (data) {
// For now, assume timeseries defaults
const xColumn = 1; // time
const yColumn = 0; // value
vmSeries = processTimeSeries({ vmSeries = processTimeSeries({
data, data,
xColumn,
yColumn,
nullValueMode: NullValueMode.Ignore, nullValueMode: NullValueMode.Ignore,
}); });
} }
......
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