mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Added validation of input parameters.
This commit is contained in:
@@ -6,6 +6,10 @@ import _ from 'lodash';
|
|||||||
* @param align Y level
|
* @param align Y level
|
||||||
*/
|
*/
|
||||||
export function alignYLevel(yaxis, alignLevel) {
|
export function alignYLevel(yaxis, alignLevel) {
|
||||||
|
if (isNaN(alignLevel) || !checkCorrectAxis(yaxis)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
var [yLeft, yRight] = yaxis;
|
var [yLeft, yRight] = yaxis;
|
||||||
moveLevelToZero(yLeft, yRight, alignLevel);
|
moveLevelToZero(yLeft, yRight, alignLevel);
|
||||||
|
|
||||||
@@ -92,6 +96,14 @@ function restoreLevelFromZero(yLeft, yRight, alignLevel) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function checkCorrectAxis(axis) {
|
||||||
|
return axis.length === 2 && checkCorrectAxes(axis[0]) && checkCorrectAxes(axis[1]);
|
||||||
|
}
|
||||||
|
|
||||||
|
function checkCorrectAxes(axes) {
|
||||||
|
return 'min' in axes && 'max' in axes;
|
||||||
|
}
|
||||||
|
|
||||||
function checkOneSide(yLeft, yRight) {
|
function checkOneSide(yLeft, yRight) {
|
||||||
// on the one hand with respect to zero
|
// on the one hand with respect to zero
|
||||||
return (yLeft.min >= 0 && yRight.min >= 0) || (yLeft.max <= 0 && yRight.max <= 0);
|
return (yLeft.min >= 0 && yRight.min >= 0) || (yLeft.max <= 0 && yRight.max <= 0);
|
||||||
|
|||||||
@@ -197,4 +197,15 @@ describe('Graph Y axes aligner', function() {
|
|||||||
expect(yaxes).toMatchObject(expected);
|
expect(yaxes).toMatchObject(expected);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('on level not number value', () => {
|
||||||
|
it('Should ignore without errors', () => {
|
||||||
|
alignY = 'q';
|
||||||
|
yaxes = [{ min: 5, max: 10 }, { min: 2, max: 4 }];
|
||||||
|
expected = [{ min: 5, max: 10 }, { min: 2, max: 4 }];
|
||||||
|
|
||||||
|
alignYLevel(yaxes, alignY);
|
||||||
|
expect(yaxes).toMatchObject(expected);
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user