diff options
author | Jose Ivan Vargas <jvargas@gitlab.com> | 2017-09-07 22:46:16 +0300 |
---|---|---|
committer | Jose Ivan Vargas <jvargas@gitlab.com> | 2017-09-07 22:46:16 +0300 |
commit | a2d10937d861b1d288786ba92de2306f4f2ab22b (patch) | |
tree | 898f7e75ba7c80fd808dd779763c9c8222696263 /app/assets/javascripts/monitoring | |
parent | 290217d51bd2489ad23e346a65fbc21b52e57724 (diff) |
refactored the pickColors method
Diffstat (limited to 'app/assets/javascripts/monitoring')
-rw-r--r-- | app/assets/javascripts/monitoring/utils/multiple_time_series.js | 33 |
1 files changed, 18 insertions, 15 deletions
diff --git a/app/assets/javascripts/monitoring/utils/multiple_time_series.js b/app/assets/javascripts/monitoring/utils/multiple_time_series.js index 9845fd53222..17e5eb79816 100644 --- a/app/assets/javascripts/monitoring/utils/multiple_time_series.js +++ b/app/assets/javascripts/monitoring/utils/multiple_time_series.js @@ -10,25 +10,27 @@ const defaultColorPalette = { }; const defaultColorOrder = ['blue', 'orange', 'red', 'green', 'purple']; -let usedColors = []; -function pickColor(name) { - let pick; - if (name && defaultColorPalette[name]) { - pick = name; - } else { - const unusedColors = _.difference(defaultColorOrder, usedColors); - if (unusedColors.length > 0) { - pick = unusedColors[0]; + +export default function createTimeSeries(queryData, graphWidth, graphHeight, graphHeightOffset) { + let usedColors = []; + + function pickColor(name) { + let pick; + if (name && defaultColorPalette[name]) { + pick = name; } else { - usedColors = []; - pick = defaultColorOrder[0]; + const unusedColors = _.difference(defaultColorOrder, usedColors); + 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 maxValue = d3.max(timeSeries.values.map(d => d.value)); return { @@ -45,6 +47,7 @@ export default function createTimeSeries(queryData, graphWidth, graphHeight, gra let metricTag = ''; let lineColor = '#1f78d1'; let areaColor = '#8fbce8'; + const timeSeriesScaleX = d3.time.scale() .range([0, graphWidth - 70]); |