heatmap: more refactoring

pull/8336/head
Torkel Ödegaard 8 years ago
parent acff78d421
commit d791f902e9
  1. 28
      public/app/plugins/panel/heatmap/heatmap_data_converter.ts
  2. 25
      public/app/plugins/panel/heatmap/heatmap_tooltip.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;

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

Loading…
Cancel
Save