浏览代码

heatmap: more refactoring

Torkel Ödegaard 8 年之前
父节点
当前提交
d791f902e9

+ 12 - 16
public/app/plugins/panel/heatmap/heatmap_data_converter.ts

@@ -92,7 +92,8 @@ function mergeZeroBuckets(buckets, minValue) {
     let emptyBucket = {
     let emptyBucket = {
       bounds: {bottom: 0, top: 0},
       bounds: {bottom: 0, top: 0},
       values: [],
       values: [],
-      points: []
+      points: [],
+      count: 0,
     };
     };
 
 
     let nullBucket = yBuckets[0] || emptyBucket;
     let nullBucket = yBuckets[0] || emptyBucket;
@@ -102,25 +103,20 @@ function mergeZeroBuckets(buckets, minValue) {
       y: 0,
       y: 0,
       bounds: {bottom: minValue, top: minBucket.bounds.top || minValue},
       bounds: {bottom: minValue, top: minBucket.bounds.top || minValue},
       values: [],
       values: [],
-      points: []
+      points: [],
+      count: 0,
     };
     };
 
 
-    if (nullBucket.values) {
-      newBucket.values = nullBucket.values.concat(minBucket.values);
-    }
-    if (nullBucket.points) {
-      newBucket.points = nullBucket.points.concat(minBucket.points);
+    newBucket.points = nullBucket.points.concat(minBucket.points);
+    newBucket.values = nullBucket.values.concat(minBucket.values);
+    newBucket.count = newBucket.values.length;
+
+    if (newBucket.count === 0) {
+      return;
     }
     }
 
 
-    let newYBuckets = {};
-    _.forEach(yBuckets, (bucket, bound) => {
-      bound = Number(bound);
-      if (bound !== 0 && bound !== minValue) {
-        newYBuckets[bound] = bucket;
-      }
-    });
-    newYBuckets[0] = newBucket;
-    xBucket.buckets = newYBuckets;
+    delete yBuckets[minValue];
+    yBuckets[0] = newBucket;
   });
   });
 
 
   return buckets;
   return buckets;

+ 7 - 18
public/app/plugins/panel/heatmap/heatmap_tooltip.ts

@@ -33,7 +33,7 @@ export class HeatmapTooltip {
   }
   }
 
 
   onMouseOver(e) {
   onMouseOver(e) {
-    if (!this.panel.tooltip.show || _.isEmpty(this.scope.ctrl.data.buckets)) { return; }
+    if (!this.panel.tooltip.show || !this.scope.ctrl.data || _.isEmpty(this.scope.ctrl.data.buckets)) { return; }
 
 
     if (!this.tooltip) {
     if (!this.tooltip) {
       this.add();
       this.add();
@@ -67,6 +67,10 @@ export class HeatmapTooltip {
 
 
   show(pos, data) {
   show(pos, data) {
     if (!this.panel.tooltip.show || !data) { return; }
     if (!this.panel.tooltip.show || !data) { return; }
+    // shared tooltip mode
+    if (pos.panelRelY) {
+      return;
+    }
 
 
     let {xBucketIndex, yBucketIndex} = this.getBucketIndexes(pos, data);
     let {xBucketIndex, yBucketIndex} = this.getBucketIndexes(pos, data);
 
 
@@ -120,23 +124,8 @@ export class HeatmapTooltip {
   }
   }
 
 
   getBucketIndexes(pos, data) {
   getBucketIndexes(pos, data) {
-    let xBucketIndex, yBucketIndex;
-
-    // if panelRelY is defined another panel wants us to show a tooltip
-    if (pos.panelRelY) {
-      xBucketIndex = getValueBucketBound(pos.x, data.xBucketSize, 1);
-      let y = this.scope.yScale.invert(pos.panelRelY * this.scope.chartHeight);
-      yBucketIndex = getValueBucketBound(y, data.yBucketSize, this.panel.yAxis.logBase);
-      pos = this.getSharedTooltipPos(pos);
-
-      if (!this.tooltip) {
-        // Add shared tooltip for panel
-        this.add();
-      }
-    } else {
-      xBucketIndex = this.getXBucketIndex(pos.offsetX, data);
-      yBucketIndex = this.getYBucketIndex(pos.offsetY, data);
-    }
+    const xBucketIndex = this.getXBucketIndex(pos.offsetX, data);
+    const yBucketIndex = this.getYBucketIndex(pos.offsetY, data);
 
 
     return {xBucketIndex, yBucketIndex};
     return {xBucketIndex, yBucketIndex};
   }
   }