Skip to content

Commit

Permalink
Merge pull request #882 from influxdata/kapacitor-padding
Browse files Browse the repository at this point in the history
Fix y-axis graph padding
  • Loading branch information
jaredscheib authored Feb 17, 2017
2 parents 65ea9e2 + 2627703 commit 01aa17e
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 9 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
## v1.2.0 [unreleased]

### Bug Fixes
1. [#882](https://github.com/influxdata/chronograf/pull/882): Fix y-axis graph padding

### Features
1. [#873](https://github.com/influxdata/chronograf/pull/873): Add [TLS](https://github.com/influxdata/chronograf/blob/master/docs/tls.md) support
Expand Down
44 changes: 44 additions & 0 deletions ui/spec/shared/parsing/getRangeForDygraphSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,48 @@ describe('getRangeForDygraphSpec', () => {

expect(actual).to.deep.equal(expected);
});

describe('when user provides a rule value', () => {
const defaultMax = 20;
const defaultMin = -10;
const timeSeries = [[new Date(1000), defaultMax], [new Date(2000), 1], [new Date(3000), defaultMin]];

it('can pad positive values', () => {
const value = 20;
const [min, max] = getRange(timeSeries, undefined, value);

expect(min).to.equal(defaultMin);
expect(max).to.be.above(defaultMax);
});

it('can pad negative values', () => {
const value = -10;
const [min, max] = getRange(timeSeries, undefined, value);

expect(min).to.be.below(defaultMin);
expect(max).to.equal(defaultMax);
});
});

describe('when user provides a rule range value', () => {
const defaultMax = 20;
const defaultMin = -10;
const timeSeries = [[new Date(1000), defaultMax], [new Date(2000), 1], [new Date(3000), defaultMin]];

it('can pad positive values', () => {
const rangeValue = 20;
const [min, max] = getRange(timeSeries, undefined, 0, rangeValue);

expect(min).to.equal(defaultMin);
expect(max).to.be.above(defaultMax);
});

it('can pad negative values', () => {
const rangeValue = -10;
const [min, max] = getRange(timeSeries, undefined, 0, rangeValue);

expect(min).to.be.below(defaultMin);
expect(max).to.equal(defaultMax);
});
});
});
14 changes: 5 additions & 9 deletions ui/src/shared/parsing/getRangeForDygraph.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,21 @@ export default function getRange(timeSeries, override, value = null, rangeValue
return override;
}

const subtractPadding = (val) => +val - val * PADDING_FACTOR;
const addPadding = (val) => +val + val * PADDING_FACTOR;
const subtractPadding = (val) => +val - Math.abs(val * PADDING_FACTOR);
const addPadding = (val) => +val + Math.abs(val * PADDING_FACTOR);

const pad = (val, side) => {
const pad = (val) => {
if (val === null || val === '') {
return null;
}

if (val < 0) {
return side === "top" ? subtractPadding(val) : addPadding(val);
}

return side === "top" ? addPadding(val) : subtractPadding(val);
return val < 0 ? subtractPadding(val) : addPadding(val);
};

const points = [
...timeSeries,
[null, pad(value)],
[null, pad(rangeValue, "top")],
[null, pad(rangeValue)],
];

const range = points.reduce(([min, max] = [], series) => {
Expand Down

0 comments on commit 01aa17e

Please sign in to comment.