Fix stacked graph bug

pull/1957/head
Andrew Watkins 2017-09-01 10:09:52 -07:00
parent eff225e9c2
commit 5a843836c9
2 changed files with 22 additions and 4 deletions

View File

@ -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(),

View File

@ -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