Commit a2d10937 authored by Jose Ivan Vargas's avatar Jose Ivan Vargas

refactored the pickColors method

parent 290217d5
...@@ -10,25 +10,27 @@ const defaultColorPalette = { ...@@ -10,25 +10,27 @@ const defaultColorPalette = {
}; };
const defaultColorOrder = ['blue', 'orange', 'red', 'green', 'purple']; const defaultColorOrder = ['blue', 'orange', 'red', 'green', 'purple'];
let usedColors = [];
function pickColor(name) { export default function createTimeSeries(queryData, graphWidth, graphHeight, graphHeightOffset) {
let pick; let usedColors = [];
if (name && defaultColorPalette[name]) {
pick = name; function pickColor(name) {
} else { let pick;
const unusedColors = _.difference(defaultColorOrder, usedColors); if (name && defaultColorPalette[name]) {
if (unusedColors.length > 0) { pick = name;
pick = unusedColors[0];
} else { } else {
usedColors = []; const unusedColors = _.difference(defaultColorOrder, usedColors);
pick = defaultColorOrder[0]; if (unusedColors.length > 0) {
pick = unusedColors[0];
} else {
usedColors = [];
pick = defaultColorOrder[0];
}
} }
usedColors.push(pick);
return defaultColorPalette[pick];
} }
usedColors.push(pick);
return defaultColorPalette[pick];
}
export default function createTimeSeries(queryData, graphWidth, graphHeight, graphHeightOffset) {
const maxValues = queryData.result.map((timeSeries, index) => { const maxValues = queryData.result.map((timeSeries, index) => {
const maxValue = d3.max(timeSeries.values.map(d => d.value)); const maxValue = d3.max(timeSeries.values.map(d => d.value));
return { return {
...@@ -45,6 +47,7 @@ export default function createTimeSeries(queryData, graphWidth, graphHeight, gra ...@@ -45,6 +47,7 @@ export default function createTimeSeries(queryData, graphWidth, graphHeight, gra
let metricTag = ''; let metricTag = '';
let lineColor = '#1f78d1'; let lineColor = '#1f78d1';
let areaColor = '#8fbce8'; let areaColor = '#8fbce8';
const timeSeriesScaleX = d3.time.scale() const timeSeriesScaleX = d3.time.scale()
.range([0, graphWidth - 70]); .range([0, graphWidth - 70]);
......
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