Commit c7e8b98d by Alexander Zobnin

heatmap: minor refactor, don't repeat cards stats calculation

parent f7ea08db
......@@ -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 = `
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment