Commit 1f7ecf9a authored by Mike Greiling's avatar Mike Greiling

process all queries within a graph

parent 309c1e6b
...@@ -11,8 +11,9 @@ const defaultColorPalette = { ...@@ -11,8 +11,9 @@ const defaultColorPalette = {
const defaultColorOrder = ['blue', 'orange', 'red', 'green', 'purple']; const defaultColorOrder = ['blue', 'orange', 'red', 'green', 'purple'];
export default function createTimeSeries(queries, graphWidth, graphHeight, graphHeightOffset) { const defaultStyleOrder = ['solid', 'dashed', 'dotted'];
const queryData = queries[0];
function queryTimeSeries(query, graphWidth, graphHeight, graphHeightOffset, maxValue, lineStyle) {
let usedColors = []; let usedColors = [];
function pickColor(name) { function pickColor(name) {
...@@ -32,17 +33,7 @@ export default function createTimeSeries(queries, graphWidth, graphHeight, graph ...@@ -32,17 +33,7 @@ export default function createTimeSeries(queries, graphWidth, graphHeight, graph
return defaultColorPalette[pick]; return defaultColorPalette[pick];
} }
const maxValues = queryData.result.map((timeSeries, index) => { return query.result.map((timeSeries, timeSeriesNumber) => {
const maxValue = d3.max(timeSeries.values.map(d => d.value));
return {
maxValue,
index,
};
});
const maxValueFromSeries = _.max(maxValues, val => val.maxValue);
return queryData.result.map((timeSeries, timeSeriesNumber) => {
let metricTag = ''; let metricTag = '';
let lineColor = ''; let lineColor = '';
let areaColor = ''; let areaColor = '';
...@@ -55,7 +46,7 @@ export default function createTimeSeries(queries, graphWidth, graphHeight, graph ...@@ -55,7 +46,7 @@ export default function createTimeSeries(queries, graphWidth, graphHeight, graph
timeSeriesScaleX.domain(d3.extent(timeSeries.values, d => d.time)); timeSeriesScaleX.domain(d3.extent(timeSeries.values, d => d.time));
timeSeriesScaleX.ticks(d3.time.minute, 60); timeSeriesScaleX.ticks(d3.time.minute, 60);
timeSeriesScaleY.domain([0, maxValueFromSeries.maxValue]); timeSeriesScaleY.domain([0, maxValue]);
const defined = d => !isNaN(d.value) && d.value != null; const defined = d => !isNaN(d.value) && d.value != null;
...@@ -73,8 +64,8 @@ export default function createTimeSeries(queries, graphWidth, graphHeight, graph ...@@ -73,8 +64,8 @@ export default function createTimeSeries(queries, graphWidth, graphHeight, graph
.y1(d => timeSeriesScaleY(d.value)); .y1(d => timeSeriesScaleY(d.value));
const timeSeriesMetricLabel = timeSeries.metric[Object.keys(timeSeries.metric)[0]]; const timeSeriesMetricLabel = timeSeries.metric[Object.keys(timeSeries.metric)[0]];
const seriesCustomizationData = queryData.series != null && const seriesCustomizationData = query.series != null &&
_.findWhere(queryData.series[0].when, _.findWhere(query.series[0].when,
{ value: timeSeriesMetricLabel }); { value: timeSeriesMetricLabel });
if (seriesCustomizationData != null) { if (seriesCustomizationData != null) {
metricTag = seriesCustomizationData.value || timeSeriesMetricLabel; metricTag = seriesCustomizationData.value || timeSeriesMetricLabel;
...@@ -89,9 +80,26 @@ export default function createTimeSeries(queries, graphWidth, graphHeight, graph ...@@ -89,9 +80,26 @@ export default function createTimeSeries(queries, graphWidth, graphHeight, graph
areaPath: areaFunction(timeSeries.values), areaPath: areaFunction(timeSeries.values),
timeSeriesScaleX, timeSeriesScaleX,
values: timeSeries.values, values: timeSeries.values,
lineStyle,
lineColor, lineColor,
areaColor, areaColor,
metricTag, metricTag,
}; };
}); });
} }
export default function createTimeSeries(queries, graphWidth, graphHeight, graphHeightOffset) {
const maxValue =
d3.max(queries.map(query => (
d3.max(query.result.map(resultSet => (
d3.max(resultSet.values.map(d => d.value))
)))
)));
return queries.reduce((series, query, index) => {
const lineStyle = defaultStyleOrder[index % defaultStyleOrder.length];
return series.concat(
queryTimeSeries(query, graphWidth, graphHeight, graphHeightOffset, maxValue, lineStyle),
);
}, []);
}
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