From fd5e838f0e21c839137159df52d3aab33e121205 Mon Sep 17 00:00:00 2001 From: Alexander Zobnin Date: Tue, 6 Feb 2018 13:38:17 +0300 Subject: [PATCH] heatmap tooltip: minor refactor --- .../app/plugins/panel/heatmap/heatmap_tooltip.ts | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/public/app/plugins/panel/heatmap/heatmap_tooltip.ts b/public/app/plugins/panel/heatmap/heatmap_tooltip.ts index 81bac685d3a..823c56425a5 100644 --- a/public/app/plugins/panel/heatmap/heatmap_tooltip.ts +++ b/public/app/plugins/panel/heatmap/heatmap_tooltip.ts @@ -153,16 +153,12 @@ export class HeatmapTooltip { getXBucketIndex(offsetX, data) { let x = this.scope.xScale.invert(offsetX - this.scope.yAxisWidth).valueOf(); - let xBucket = _.find(data.buckets, (bucket, bucketIndex) => { - return x-bucket.x <= data.xBucketSize && x-bucket.x >0; + // First try to find X bucket by checking x pos is in the + // [bucket.x, bucket.x + xBucketSize] interval + let xBucket = _.find(data.buckets, bucket => { + return x > bucket.x && x - bucket.x <= data.xBucketSize; }); - let xBucketIndex; - if (!xBucket) { - xBucketIndex = getValueBucketBound(x, data.xBucketSize, 1); - } else { - xBucketIndex = xBucket.x; - } - return xBucketIndex; + return xBucket ? xBucket.x : getValueBucketBound(x, data.xBucketSize, 1); } getYBucketIndex(offsetY, data) {