From d791f902e9cce7a0fa53b0cdd59a42d7fb9e3641 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torkel=20=C3=96degaard?= Date: Wed, 10 May 2017 13:05:26 +0200 Subject: [PATCH] heatmap: more refactoring --- .../panel/heatmap/heatmap_data_converter.ts | 28 ++++++++----------- .../plugins/panel/heatmap/heatmap_tooltip.ts | 25 +++++------------ 2 files changed, 19 insertions(+), 34 deletions(-) diff --git a/public/app/plugins/panel/heatmap/heatmap_data_converter.ts b/public/app/plugins/panel/heatmap/heatmap_data_converter.ts index f627173d233..0136a1bb511 100644 --- a/public/app/plugins/panel/heatmap/heatmap_data_converter.ts +++ b/public/app/plugins/panel/heatmap/heatmap_data_converter.ts @@ -92,7 +92,8 @@ function mergeZeroBuckets(buckets, minValue) { let emptyBucket = { bounds: {bottom: 0, top: 0}, values: [], - points: [] + points: [], + count: 0, }; let nullBucket = yBuckets[0] || emptyBucket; @@ -102,25 +103,20 @@ function mergeZeroBuckets(buckets, minValue) { y: 0, bounds: {bottom: minValue, top: minBucket.bounds.top || minValue}, 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; diff --git a/public/app/plugins/panel/heatmap/heatmap_tooltip.ts b/public/app/plugins/panel/heatmap/heatmap_tooltip.ts index 28824d7c7e2..d2152c68aa7 100644 --- a/public/app/plugins/panel/heatmap/heatmap_tooltip.ts +++ b/public/app/plugins/panel/heatmap/heatmap_tooltip.ts @@ -33,7 +33,7 @@ export class HeatmapTooltip { } 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) { this.add(); @@ -67,6 +67,10 @@ export class HeatmapTooltip { show(pos, data) { if (!this.panel.tooltip.show || !data) { return; } + // shared tooltip mode + if (pos.panelRelY) { + return; + } let {xBucketIndex, yBucketIndex} = this.getBucketIndexes(pos, data); @@ -120,23 +124,8 @@ export class HeatmapTooltip { } 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}; }