Commit c629a58b by Torkel Ödegaard

refactor: removed graph height from legend decimal calc

parent a7897b94
...@@ -21,14 +21,13 @@ function translateFillOption(fill) { ...@@ -21,14 +21,13 @@ function translateFillOption(fill) {
* Calculate decimals for legend and update values for each series. * Calculate decimals for legend and update values for each series.
* @param data series data * @param data series data
* @param panel * @param panel
* @param height Graph height
*/ */
export function updateLegendValues(data: TimeSeries[], panel, height) { export function updateLegendValues(data: TimeSeries[], panel) {
for (let i = 0; i < data.length; i++) { for (let i = 0; i < data.length; i++) {
let series = data[i]; let series = data[i];
let yaxes = panel.yaxes; let yaxes = panel.yaxes;
let axis = yaxes[series.yaxis - 1]; let axis = yaxes[series.yaxis - 1];
let {tickDecimals, scaledDecimals} = getFlotTickDecimals(data, axis, height); let {tickDecimals, scaledDecimals} = getFlotTickDecimals(data, axis);
let formater = kbn.valueFormats[panel.yaxes[series.yaxis - 1].format]; let formater = kbn.valueFormats[panel.yaxes[series.yaxis - 1].format];
// decimal override // decimal override
......
...@@ -118,29 +118,13 @@ export function getFlotRange(panelMin, panelMax, datamin, datamax) { ...@@ -118,29 +118,13 @@ export function getFlotRange(panelMin, panelMax, datamin, datamax) {
} }
/** /**
* Estimate number of ticks for Y axis.
* Implementation from Flot.
*/
export function getFlotNumberOfTicks(height, ticks?) {
let noTicks;
if (typeof ticks === "number" && ticks > 0) {
noTicks = ticks;
} else {
// heuristic based on the model a*sqrt(x) fitted to
// some data points that seemed reasonable
noTicks = 0.3 * Math.sqrt(height);
}
return noTicks;
}
/**
* Calculate tick decimals. * Calculate tick decimals.
* Implementation from Flot. * Implementation from Flot.
*/ */
export function getFlotTickDecimals(data, axis, height) { export function getFlotTickDecimals(data, axis) {
let {datamin, datamax} = getDataMinMax(data); let {datamin, datamax} = getDataMinMax(data);
let {min, max} = getFlotRange(axis.min, axis.max, datamin, datamax); let {min, max} = getFlotRange(axis.min, axis.max, datamin, datamax);
let noTicks = getFlotNumberOfTicks(height); let noTicks = 3;
let tickDecimals, maxDec; let tickDecimals, maxDec;
let delta = (max - min) / noTicks; let delta = (max - min) / noTicks;
let dec = -Math.floor(Math.log(delta) / Math.LN10); let dec = -Math.floor(Math.log(delta) / Math.LN10);
......
...@@ -19,6 +19,10 @@ module.directive('graphLegend', function(popoverSrv, $timeout) { ...@@ -19,6 +19,10 @@ module.directive('graphLegend', function(popoverSrv, $timeout) {
var i; var i;
var legendScrollbar; var legendScrollbar;
scope.$on("$destroy", function() {
legendScrollbar.destroy();
});
ctrl.events.on('render-legend', () => { ctrl.events.on('render-legend', () => {
data = ctrl.seriesList; data = ctrl.seriesList;
if (data) { if (data) {
...@@ -27,8 +31,8 @@ module.directive('graphLegend', function(popoverSrv, $timeout) { ...@@ -27,8 +31,8 @@ module.directive('graphLegend', function(popoverSrv, $timeout) {
ctrl.events.emit('legend-rendering-complete'); ctrl.events.emit('legend-rendering-complete');
}); });
function updateLegendDecimals(graphHeight) { function updateLegendDecimals() {
updateLegendValues(data, panel, graphHeight); updateLegendValues(data, panel);
} }
function getSeriesIndexForElement(el) { function getSeriesIndexForElement(el) {
...@@ -157,11 +161,10 @@ module.directive('graphLegend', function(popoverSrv, $timeout) { ...@@ -157,11 +161,10 @@ module.directive('graphLegend', function(popoverSrv, $timeout) {
// render first time for getting proper legend height // render first time for getting proper legend height
if (!panel.legend.rightSide) { if (!panel.legend.rightSide) {
renderLegendElement(tableHeaderElem); renderLegendElement(tableHeaderElem);
let graphHeight = ctrl.height - $container.height() - 23; updateLegendDecimals();
updateLegendDecimals(graphHeight);
$container.empty(); $container.empty();
} else { } else {
updateLegendDecimals(ctrl.height); updateLegendDecimals();
} }
renderLegendElement(tableHeaderElem); renderLegendElement(tableHeaderElem);
...@@ -227,6 +230,7 @@ module.directive('graphLegend', function(popoverSrv, $timeout) { ...@@ -227,6 +230,7 @@ module.directive('graphLegend', function(popoverSrv, $timeout) {
var maxLegendHeight = ctrl.height / 2; var maxLegendHeight = ctrl.height / 2;
$container.css("max-height", maxLegendHeight - 6); $container.css("max-height", maxLegendHeight - 6);
$container.append(seriesElements); $container.append(seriesElements);
if (!legendScrollbar) { if (!legendScrollbar) {
legendScrollbar = new PerfectScrollbar($container[0]); legendScrollbar = new PerfectScrollbar($container[0]);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment