Merge pull request #379 from mikegoatly/timespan-options
Allow for more timespan options
This commit is contained in:
Коммит
0c8961c0b7
|
@ -97,7 +97,7 @@ export function timeline(
|
||||||
|
|
||||||
let result = {};
|
let result = {};
|
||||||
result[prefix + 'graphData'] = timelineValues;
|
result[prefix + 'graphData'] = timelineValues;
|
||||||
result[prefix + 'timeFormat'] = (timespan === '24 hours' ? 'hour' : 'date');
|
result[prefix + 'timeFormat'] = ((timespan || "").indexOf("hour") > 0 ? 'hour' : 'date');
|
||||||
result[prefix + 'lines'] = lines;
|
result[prefix + 'lines'] = lines;
|
||||||
result[prefix + 'pieData'] = usage;
|
result[prefix + 'pieData'] = usage;
|
||||||
|
|
||||||
|
|
|
@ -3,6 +3,40 @@ import utils from '../../index';
|
||||||
import { DataFormatTypes, IDataFormat, formatWarn, getPrefix } from '../common';
|
import { DataFormatTypes, IDataFormat, formatWarn, getPrefix } from '../common';
|
||||||
import { IDataSourcePlugin } from '../../../data-sources/plugins/DataSourcePlugin';
|
import { IDataSourcePlugin } from '../../../data-sources/plugins/DataSourcePlugin';
|
||||||
|
|
||||||
|
enum Interval {
|
||||||
|
Hours = 0,
|
||||||
|
Days = 1,
|
||||||
|
Weeks= 2,
|
||||||
|
Months = 3
|
||||||
|
}
|
||||||
|
|
||||||
|
interface IQueryTimespan {
|
||||||
|
queryTimespan: string;
|
||||||
|
granularity: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
const timespanRegex = /^(\d+) (hour|day|week|month)s?$/;
|
||||||
|
function parseTimespan(timespanText: string) : IQueryTimespan {
|
||||||
|
var match = timespanRegex.exec(timespanText);
|
||||||
|
if (!match) {
|
||||||
|
// Backwards compatibility with existing functionality
|
||||||
|
return { queryTimespan: "P90D", granularity: "1d" };
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (match[2]) {
|
||||||
|
case "hour":
|
||||||
|
return { queryTimespan: `PT${match[1]}H`, granularity: "5m" };
|
||||||
|
case "day":
|
||||||
|
return { queryTimespan: `P${match[1]}D`, granularity: "30m" };
|
||||||
|
case "week":
|
||||||
|
return { queryTimespan: `P${parseInt(match[1]) * 7}D`, granularity: "1d" };
|
||||||
|
case "month":
|
||||||
|
return { queryTimespan: `P${parseInt(match[1]) * 30}D`, granularity: "1d" };
|
||||||
|
default:
|
||||||
|
return { queryTimespan: "P90D", granularity: "1d" };
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Receives a timespan data source and formats is accordingly
|
* Receives a timespan data source and formats is accordingly
|
||||||
*
|
*
|
||||||
|
@ -45,20 +79,8 @@ export function timespan(
|
||||||
|
|
||||||
const params = plugin.getParams();
|
const params = plugin.getParams();
|
||||||
const prefix = getPrefix(format);
|
const prefix = getPrefix(format);
|
||||||
let queryTimespan =
|
|
||||||
state.selectedValue === '24 hours' ? 'PT24H' :
|
|
||||||
state.selectedValue === '1 week' ? 'P7D' :
|
|
||||||
state.selectedValue === '1 month' ? 'P30D' :
|
|
||||||
'P90D';
|
|
||||||
|
|
||||||
let granularity =
|
let result = parseTimespan(state.selectedValue);
|
||||||
state.selectedValue === '24 hours' ? '5m' :
|
|
||||||
state.selectedValue === '1 week' ? '1d' : '1d';
|
|
||||||
|
|
||||||
let result = {
|
|
||||||
queryTimespan,
|
|
||||||
granularity
|
|
||||||
};
|
|
||||||
|
|
||||||
const args = typeof format !== 'string' && format.args || {};
|
const args = typeof format !== 'string' && format.args || {};
|
||||||
let values = params[args.data || 'values'];
|
let values = params[args.data || 'values'];
|
||||||
|
|
Загрузка…
Ссылка в новой задаче