Commit c629a58b by Torkel Ödegaard

refactor: removed graph height from legend decimal calc

parent a7897b94
......@@ -21,14 +21,13 @@ function translateFillOption(fill) {
* Calculate decimals for legend and update values for each series.
* @param data series data
* @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++) {
let series = data[i];
let yaxes = panel.yaxes;
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];
// decimal override
......
......@@ -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.
* Implementation from Flot.
*/
export function getFlotTickDecimals(data, axis, height) {
export function getFlotTickDecimals(data, axis) {
let {datamin, datamax} = getDataMinMax(data);
let {min, max} = getFlotRange(axis.min, axis.max, datamin, datamax);
let noTicks = getFlotNumberOfTicks(height);
let noTicks = 3;
let tickDecimals, maxDec;
let delta = (max - min) / noTicks;
let dec = -Math.floor(Math.log(delta) / Math.LN10);
......
......@@ -19,6 +19,10 @@ module.directive('graphLegend', function(popoverSrv, $timeout) {
var i;
var legendScrollbar;
scope.$on("$destroy", function() {
legendScrollbar.destroy();
});
ctrl.events.on('render-legend', () => {
data = ctrl.seriesList;
if (data) {
......@@ -27,8 +31,8 @@ module.directive('graphLegend', function(popoverSrv, $timeout) {
ctrl.events.emit('legend-rendering-complete');
});
function updateLegendDecimals(graphHeight) {
updateLegendValues(data, panel, graphHeight);
function updateLegendDecimals() {
updateLegendValues(data, panel);
}
function getSeriesIndexForElement(el) {
......@@ -157,11 +161,10 @@ module.directive('graphLegend', function(popoverSrv, $timeout) {
// render first time for getting proper legend height
if (!panel.legend.rightSide) {
renderLegendElement(tableHeaderElem);
let graphHeight = ctrl.height - $container.height() - 23;
updateLegendDecimals(graphHeight);
updateLegendDecimals();
$container.empty();
} else {
updateLegendDecimals(ctrl.height);
updateLegendDecimals();
}
renderLegendElement(tableHeaderElem);
......@@ -227,6 +230,7 @@ module.directive('graphLegend', function(popoverSrv, $timeout) {
var maxLegendHeight = ctrl.height / 2;
$container.css("max-height", maxLegendHeight - 6);
$container.append(seriesElements);
if (!legendScrollbar) {
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