mirror of
https://github.com/grafana/grafana.git
synced 2025-02-16 18:34:52 -06:00
heatmap: minor refactor, don't repeat cards stats calculation
This commit is contained in:
parent
f7ea08dba7
commit
c7e8b98d14
@ -191,20 +191,14 @@ export class HeatmapCtrl extends MetricsPanelCtrl {
|
||||
yBucketSize = 1;
|
||||
}
|
||||
|
||||
let cardsData = convertToCards(bucketsData);
|
||||
let maxCardsValue = _.max(_.map(cardsData, 'count'));
|
||||
let minCardsValue = _.min(_.map(cardsData, 'count'));
|
||||
let cardStats = {
|
||||
max: maxCardsValue,
|
||||
min: minCardsValue
|
||||
};
|
||||
let {cards, cardStats} = convertToCards(bucketsData);
|
||||
|
||||
this.data = {
|
||||
buckets: bucketsData,
|
||||
heatmapStats: heatmapStats,
|
||||
xBucketSize: xBucketSize,
|
||||
yBucketSize: yBucketSize,
|
||||
cards: cardsData,
|
||||
cards: cards,
|
||||
cardStats: cardStats
|
||||
};
|
||||
}
|
||||
|
@ -51,6 +51,7 @@ function elasticHistogramToHeatmap(seriesList) {
|
||||
* @return {Array} Array of "card" objects
|
||||
*/
|
||||
function convertToCards(buckets) {
|
||||
let min = 0, max = 0;
|
||||
let cards = [];
|
||||
_.forEach(buckets, xBucket => {
|
||||
_.forEach(xBucket.buckets, yBucket=> {
|
||||
@ -62,10 +63,19 @@ function convertToCards(buckets) {
|
||||
count: yBucket.count,
|
||||
};
|
||||
cards.push(card);
|
||||
|
||||
if (cards.length === 1) {
|
||||
min = yBucket.count;
|
||||
max = yBucket.count;
|
||||
}
|
||||
|
||||
min = yBucket.count < min ? yBucket.count : min;
|
||||
max = yBucket.count > max ? yBucket.count : max;
|
||||
});
|
||||
});
|
||||
|
||||
return cards;
|
||||
let cardStats = {min, max};
|
||||
return {cards, cardStats};
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -114,14 +114,8 @@ describe('grafanaHeatmap', function () {
|
||||
let bucketsData = convertToHeatMap(ctx.series, ctx.data.yBucketSize, ctx.data.xBucketSize, logBase);
|
||||
ctx.data.buckets = bucketsData;
|
||||
|
||||
let cardsData = convertToCards(bucketsData);
|
||||
let maxCardsValue = _.max(_.map(cardsData, 'count'));
|
||||
let minCardsValue = _.min(_.map(cardsData, 'count'));
|
||||
let cardStats = {
|
||||
max: maxCardsValue,
|
||||
min: minCardsValue
|
||||
};
|
||||
ctx.data.cards = cardsData;
|
||||
let {cards, cardStats} = convertToCards(bucketsData);
|
||||
ctx.data.cards = cards;
|
||||
ctx.data.cardStats = cardStats;
|
||||
|
||||
let elemHtml = `
|
||||
|
Loading…
Reference in New Issue
Block a user