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
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 = [];
......
......@@ -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()}
......
......@@ -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];
}
......
......@@ -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,
});
}
......
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