Bläddra i källkod

refactor: removed graph height from legend decimal calc

Torkel Ödegaard 8 år sedan
förälder
incheckning
c629a58b6d

+ 2 - 3
public/app/core/time_series2.ts

@@ -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

+ 2 - 18
public/app/core/utils/ticks.ts

@@ -117,30 +117,14 @@ export function getFlotRange(panelMin, panelMax, datamin, datamax) {
   return {min, max};
 }
 
-/**
- * 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);

+ 9 - 5
public/app/plugins/panel/graph/legend.ts

@@ -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]);
           }