heatmap: Docs and heatmap fixes

This commit is contained in:
Torkel Ödegaard
2017-05-11 10:19:47 +02:00
parent 30b6c3b54a
commit ab6740c685
5 changed files with 57 additions and 58 deletions

View File

@@ -423,7 +423,7 @@ coreModule.directive('grafanaGraph', function($rootScope, timeSrv, popoverSrv) {
function addXHistogramAxis(options, bucketSize) {
let ticks, min, max;
if (data.length) {
if (data.length && bucketSize) {
ticks = _.map(data[0].data, point => point[0]);
// Expand ticks for pretty view

View File

@@ -38,7 +38,6 @@ let panelDefaults = {
splitFactor: null,
min: null,
max: null,
removeZeroValues: false
},
xBucketSize: null,
xBucketNumber: null,

View File

@@ -122,24 +122,6 @@ function mergeZeroBuckets(buckets, minValue) {
return buckets;
}
/**
* Remove 0 values from heatmap buckets.
*/
function removeZeroBuckets(buckets) {
_.forEach(buckets, xBucket => {
let yBuckets = xBucket.buckets;
let newYBuckets = {};
_.forEach(yBuckets, (bucket, bound) => {
if (bucket.y !== 0) {
newYBuckets[bound] = bucket;
}
});
xBucket.buckets = newYBuckets;
});
return buckets;
}
/**
* Convert set of time series into heatmap buckets
* @return {Object} Heatmap object:
@@ -429,7 +411,6 @@ export {
convertToHeatMap,
elasticHistogramToHeatmap,
convertToCards,
removeZeroBuckets,
mergeZeroBuckets,
getMinLog,
getValueBucketBound,

View File

@@ -8,7 +8,7 @@ import {appEvents, contextSrv} from 'app/core/core';
import {tickStep} from 'app/core/utils/ticks';
import d3 from 'd3';
import {HeatmapTooltip} from './heatmap_tooltip';
import {convertToCards, mergeZeroBuckets, removeZeroBuckets} from './heatmap_data_converter';
import {convertToCards, mergeZeroBuckets} from './heatmap_data_converter';
let MIN_CARD_SIZE = 1,
CARD_PADDING = 1,
@@ -357,14 +357,10 @@ export default function link(scope, elem, attrs, ctrl) {
addAxes();
if (panel.yAxis.logBase !== 1) {
if (panel.yAxis.removeZeroValues) {
data.buckets = removeZeroBuckets(data.buckets);
} else {
let log_base = panel.yAxis.logBase;
let domain = yScale.domain();
let tick_values = logScaleTickValues(domain, log_base);
data.buckets = mergeZeroBuckets(data.buckets, _.min(tick_values));
}
let log_base = panel.yAxis.logBase;
let domain = yScale.domain();
let tick_values = logScaleTickValues(domain, log_base);
data.buckets = mergeZeroBuckets(data.buckets, _.min(tick_values));
}
let cardsData = convertToCards(data.buckets);
@@ -377,17 +373,17 @@ export default function link(scope, elem, attrs, ctrl) {
let cards = heatmap.selectAll(".heatmap-card").data(cardsData);
cards.append("title");
cards = cards.enter().append("rect")
.attr("x", getCardX)
.attr("width", getCardWidth)
.attr("y", getCardY)
.attr("height", getCardHeight)
.attr("rx", cardRound)
.attr("ry", cardRound)
.attr("class", "bordered heatmap-card")
.style("fill", getCardColor)
.style("stroke", getCardColor)
.style("stroke-width", 0)
.style("opacity", getCardOpacity);
.attr("x", getCardX)
.attr("width", getCardWidth)
.attr("y", getCardY)
.attr("height", getCardHeight)
.attr("rx", cardRound)
.attr("ry", cardRound)
.attr("class", "bordered heatmap-card")
.style("fill", getCardColor)
.style("stroke", getCardColor)
.style("stroke-width", 0)
.style("opacity", getCardOpacity);
let $cards = $heatmap.find(".heatmap-card");
$cards.on("mouseenter", (event) => {
@@ -750,6 +746,15 @@ export default function link(scope, elem, attrs, ctrl) {
panel = ctrl.panel;
timeRange = ctrl.range;
// Draw only if color editor is opened
if (!d3.select("#heatmap-color-legend").empty()) {
drawColorLegend();
}
if (!d3.select("#heatmap-opacity-legend").empty()) {
drawOpacityLegend();
}
if (!setElementHeight() || !data) {
return;
}
@@ -767,14 +772,6 @@ export default function link(scope, elem, attrs, ctrl) {
scope.chartHeight = chartHeight;
scope.chartWidth = chartWidth;
scope.chartTop = chartTop;
// Draw only if color editor is opened
if (!d3.select("#heatmap-color-legend").empty()) {
drawColorLegend();
}
if (!d3.select("#heatmap-opacity-legend").empty()) {
drawOpacityLegend();
}
}
// Register selection listeners