From c672e44d35c5976df7f00b7acd9b06d829049928 Mon Sep 17 00:00:00 2001 From: Marcus Efraimsson Date: Thu, 22 Mar 2018 18:30:23 +0100 Subject: [PATCH] graph: minor fixes to y-axes alignment feature --- public/app/plugins/panel/graph/align_yaxes.ts | 38 +++++++++---------- .../app/plugins/panel/graph/axes_editor.html | 10 +++-- public/app/plugins/panel/graph/graph.ts | 10 +++-- public/app/plugins/panel/graph/module.ts | 4 +- 4 files changed, 33 insertions(+), 29 deletions(-) diff --git a/public/app/plugins/panel/graph/align_yaxes.ts b/public/app/plugins/panel/graph/align_yaxes.ts index 71bfcd8423d..e0d8794c250 100644 --- a/public/app/plugins/panel/graph/align_yaxes.ts +++ b/public/app/plugins/panel/graph/align_yaxes.ts @@ -2,16 +2,16 @@ import _ from 'lodash'; /** * To align two Y axes by Y level - * @param yaxis data [{min: min_y1, min: max_y1}, {min: min_y2, max: max_y2}] - * @param align Y level + * @param yAxes data [{min: min_y1, min: max_y1}, {min: min_y2, max: max_y2}] + * @param level Y level */ -export function alignYLevel(yaxis, alignLevel) { - if (isNaN(alignLevel) || !checkCorrectAxis(yaxis)) { +export function alignYLevel(yAxes, level) { + if (isNaN(level) || !checkCorrectAxis(yAxes)) { return; } - var [yLeft, yRight] = yaxis; - moveLevelToZero(yLeft, yRight, alignLevel); + var [yLeft, yRight] = yAxes; + moveLevelToZero(yLeft, yRight, level); expandStuckValues(yLeft, yRight); @@ -62,7 +62,7 @@ export function alignYLevel(yaxis, alignLevel) { } } - restoreLevelFromZero(yLeft, yRight, alignLevel); + restoreLevelFromZero(yLeft, yRight, level); } function expandStuckValues(yLeft, yRight) { @@ -78,21 +78,21 @@ function expandStuckValues(yLeft, yRight) { } } -function moveLevelToZero(yLeft, yRight, alignLevel) { - if (alignLevel !== 0) { - yLeft.min -= alignLevel; - yLeft.max -= alignLevel; - yRight.min -= alignLevel; - yRight.max -= alignLevel; +function moveLevelToZero(yLeft, yRight, level) { + if (level !== 0) { + yLeft.min -= level; + yLeft.max -= level; + yRight.min -= level; + yRight.max -= level; } } -function restoreLevelFromZero(yLeft, yRight, alignLevel) { - if (alignLevel !== 0) { - yLeft.min += alignLevel; - yLeft.max += alignLevel; - yRight.min += alignLevel; - yRight.max += alignLevel; +function restoreLevelFromZero(yLeft, yRight, level) { + if (level !== 0) { + yLeft.min += level; + yLeft.max += level; + yRight.min += level; + yRight.max += level; } } diff --git a/public/app/plugins/panel/graph/axes_editor.html b/public/app/plugins/panel/graph/axes_editor.html index 9020bbe4446..6ec64015746 100644 --- a/public/app/plugins/panel/graph/axes_editor.html +++ b/public/app/plugins/panel/graph/axes_editor.html @@ -70,10 +70,12 @@

Y-Axes
- -
- - + +
+ +
diff --git a/public/app/plugins/panel/graph/graph.ts b/public/app/plugins/panel/graph/graph.ts index dc801a1b33f..8a2aea8c4c2 100755 --- a/public/app/plugins/panel/graph/graph.ts +++ b/public/app/plugins/panel/graph/graph.ts @@ -157,10 +157,12 @@ function graphDirective(timeSrv, popoverSrv, contextSrv) { } function processRangeHook(plot) { - var yaxis = plot.getYAxes(); - if (yaxis.length > 1 && panel.yaxis.alignment) { - var align = panel.yaxis.align || 0; - alignYLevel(yaxis, parseFloat(align)); + var yAxes = plot.getYAxes(); + const align = panel.yaxis.align || false; + + if (yAxes.length > 1 && align === true) { + const level = panel.yaxis.alignLevel || 0; + alignYLevel(yAxes, parseFloat(level)); } } diff --git a/public/app/plugins/panel/graph/module.ts b/public/app/plugins/panel/graph/module.ts index 2fe1ecc8684..6cebbe65ab8 100644 --- a/public/app/plugins/panel/graph/module.ts +++ b/public/app/plugins/panel/graph/module.ts @@ -56,8 +56,8 @@ class GraphCtrl extends MetricsPanelCtrl { buckets: null, }, yaxis: { - alignment: false, - align: 0, + align: false, + alignLevel: null, }, // show/hide lines lines: true,