mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
heatmap: more refactoring
This commit is contained in:
@@ -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.points = nullBucket.points.concat(minBucket.points);
|
||||||
newBucket.values = nullBucket.values.concat(minBucket.values);
|
newBucket.values = nullBucket.values.concat(minBucket.values);
|
||||||
}
|
newBucket.count = newBucket.values.length;
|
||||||
if (nullBucket.points) {
|
|
||||||
newBucket.points = nullBucket.points.concat(minBucket.points);
|
if (newBucket.count === 0) {
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
let newYBuckets = {};
|
delete yBuckets[minValue];
|
||||||
_.forEach(yBuckets, (bucket, bound) => {
|
yBuckets[0] = newBucket;
|
||||||
bound = Number(bound);
|
|
||||||
if (bound !== 0 && bound !== minValue) {
|
|
||||||
newYBuckets[bound] = bucket;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
newYBuckets[0] = newBucket;
|
|
||||||
xBucket.buckets = newYBuckets;
|
|
||||||
});
|
});
|
||||||
|
|
||||||
return buckets;
|
return buckets;
|
||||||
|
|||||||
@@ -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;
|
const xBucketIndex = this.getXBucketIndex(pos.offsetX, data);
|
||||||
|
const yBucketIndex = this.getYBucketIndex(pos.offsetY, data);
|
||||||
// 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);
|
|
||||||
}
|
|
||||||
|
|
||||||
return {xBucketIndex, yBucketIndex};
|
return {xBucketIndex, yBucketIndex};
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user