ソースを参照

histogram: improved ticks rendering

Alexander Zobnin 8 年 前
コミット
934c0fea6f
1 ファイル変更18 行追加4 行削除
  1. 18 4
      public/app/plugins/panel/graph/graph.ts

+ 18 - 4
public/app/plugins/panel/graph/graph.ts

@@ -422,21 +422,32 @@ coreModule.directive('grafanaGraph', function($rootScope, timeSrv, popoverSrv) {
 
 
       function addXHistogramAxis(options, bucketSize) {
       function addXHistogramAxis(options, bucketSize) {
         let ticks, min, max;
         let ticks, min, max;
+        let defaultTicks = panelWidth / 50;
 
 
         if (data.length && bucketSize) {
         if (data.length && bucketSize) {
           ticks = _.map(data[0].data, point => point[0]);
           ticks = _.map(data[0].data, point => point[0]);
+          min = _.min(ticks);
+          max = _.max(ticks);
+
+          // Adjust tick step
+          let tickStep = bucketSize;
+          let ticks_num = Math.floor((max - min) / tickStep);
+          while (ticks_num > defaultTicks) {
+            tickStep = tickStep * 2;
+            ticks_num = Math.ceil((max - min) / tickStep);
+          }
 
 
           // Expand ticks for pretty view
           // Expand ticks for pretty view
-          min = _.min(ticks) - bucketSize;
-          max = _.max(ticks) + bucketSize;
+          min = Math.floor(min / tickStep) * tickStep;
+          max = Math.ceil(max / tickStep) * tickStep;
 
 
           ticks = [];
           ticks = [];
-          for (let i = min; i <= max; i += bucketSize) {
+          for (let i = min; i <= max; i += tickStep) {
             ticks.push(i);
             ticks.push(i);
           }
           }
         } else {
         } else {
           // Set defaults if no data
           // Set defaults if no data
-          ticks = panelWidth / 100;
+          ticks = defaultTicks / 2;
           min = 0;
           min = 0;
           max = 1;
           max = 1;
         }
         }
@@ -450,6 +461,9 @@ coreModule.directive('grafanaGraph', function($rootScope, timeSrv, popoverSrv) {
           label: "Histogram",
           label: "Histogram",
           ticks: ticks
           ticks: ticks
         };
         };
+
+        // Use 'short' format for histogram values
+        configureAxisMode(options.xaxis, 'short');
       }
       }
 
 
       function addXTableAxis(options) {
       function addXTableAxis(options) {