From 5a843836c9d70a825702f351dd7d3243b5e576e7 Mon Sep 17 00:00:00 2001 From: Andrew Watkins Date: Fri, 1 Sep 2017 10:09:52 -0700 Subject: [PATCH] Fix stacked graph bug --- ui/src/shared/components/Dygraph.js | 12 ++++++++---- ui/src/shared/parsing/getRangeForDygraph.js | 14 ++++++++++++++ 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/ui/src/shared/components/Dygraph.js b/ui/src/shared/components/Dygraph.js index b37c9a1b3..3dc1dfb5c 100644 --- a/ui/src/shared/components/Dygraph.js +++ b/ui/src/shared/components/Dygraph.js @@ -6,7 +6,7 @@ import _ from 'lodash' import moment from 'moment' import Dygraphs from 'src/external/dygraph' -import getRange from 'shared/parsing/getRangeForDygraph' +import getRange, {getStackedRange} from 'shared/parsing/getRangeForDygraph' import DygraphLegend from 'src/shared/components/DygraphLegend' import {DISPLAY_OPTIONS} from 'src/dashboards/constants' import {buildDefaultYLabel} from 'shared/presenters' @@ -63,7 +63,9 @@ export default class Dygraph extends Component { plugins: [new Dygraphs.Plugins.Crosshair({direction: 'vertical'})], axes: { y: { - valueRange: getRange(timeSeries, y.bounds, ruleValues), + valueRange: options.stackedGraph + ? getStackedRange(y.bounds) + : getRange(timeSeries, y.bounds, ruleValues), axisLabelFormatter: (yval, __, opts) => numberValueFormatter(yval, opts, y.prefix, y.suffix), axisLabelWidth: this.getLabelWidth(), @@ -142,12 +144,14 @@ export default class Dygraph extends Component { const updateOptions = { ...options, labels, - ylabel: this.getLabel('y'), file: timeSeries, logscale: y.scale === LOG, + ylabel: this.getLabel('y'), axes: { y: { - valueRange: getRange(timeSeries, y.bounds, ruleValues), + valueRange: options.stackedGraph + ? getStackedRange(y.bounds) + : getRange(timeSeries, y.bounds, ruleValues), axisLabelFormatter: (yval, __, opts) => numberValueFormatter(yval, opts, y.prefix, y.suffix), axisLabelWidth: this.getLabelWidth(), diff --git a/ui/src/shared/parsing/getRangeForDygraph.js b/ui/src/shared/parsing/getRangeForDygraph.js index 06364a926..40bbe44ec 100644 --- a/ui/src/shared/parsing/getRangeForDygraph.js +++ b/ui/src/shared/parsing/getRangeForDygraph.js @@ -79,4 +79,18 @@ const getRange = ( return [min, max] } +const parseNumber = bound => { + if (bound) { + return +bound + } + + return null +} + +export const getStackedRange = (bounds = [null, null]) => { + const min = bounds[0] + const max = bounds[1] + + return [parseNumber(min), parseNumber(max)] +} export default getRange