From 91a921e12d51f1d75275a1ea556102cedabeb37b Mon Sep 17 00:00:00 2001 From: Alexander Zobnin Date: Tue, 1 Aug 2017 14:07:52 +0300 Subject: [PATCH] heatmap: add show legend option --- public/app/plugins/panel/heatmap/color_legend.ts | 14 ++++++++++++-- public/app/plugins/panel/heatmap/heatmap_ctrl.ts | 3 +++ public/app/plugins/panel/heatmap/module.html | 2 +- .../panel/heatmap/partials/display_editor.html | 8 ++++++++ 4 files changed, 24 insertions(+), 3 deletions(-) diff --git a/public/app/plugins/panel/heatmap/color_legend.ts b/public/app/plugins/panel/heatmap/color_legend.ts index 0b23a10e000..2d52acb8ddb 100644 --- a/public/app/plugins/panel/heatmap/color_legend.ts +++ b/public/app/plugins/panel/heatmap/color_legend.ts @@ -46,7 +46,12 @@ module.directive('heatmapLegend', function() { let ctrl = scope.ctrl; let panel = scope.ctrl.panel; + render(); ctrl.events.on('render', function() { + render(); + }); + + function render() { if (!_.isEmpty(ctrl.data)) { let legendElem = $(elem).find('svg'); let legendWidth = Math.floor(legendElem.outerWidth()); @@ -66,7 +71,7 @@ module.directive('heatmapLegend', function() { drawOpacityLegend(elem, colorOptions, rangeFrom, rangeTo, maxValue, minValue); } } - }); + } } }; }); @@ -241,7 +246,12 @@ function getOpacityScale(options, maxValue, minValue = 0) { } function getSvgElemX(elem) { - return elem.get(0).x.baseVal.value; + let svgElem = elem.get(0); + if (svgElem && svgElem.x && svgElem.x.baseVal) { + return elem.get(0).x.baseVal.value; + } else { + return 0; + } } function buildLegendTicks(rangeFrom, rangeTo, maxValue, minValue) { diff --git a/public/app/plugins/panel/heatmap/heatmap_ctrl.ts b/public/app/plugins/panel/heatmap/heatmap_ctrl.ts index 03bb46a104f..3b8d1fa9d41 100644 --- a/public/app/plugins/panel/heatmap/heatmap_ctrl.ts +++ b/public/app/plugins/panel/heatmap/heatmap_ctrl.ts @@ -26,6 +26,9 @@ let panelDefaults = { exponent: 0.5, colorScheme: 'interpolateOranges', }, + legend: { + show: false + }, dataFormat: 'timeseries', xAxis: { show: true, diff --git a/public/app/plugins/panel/heatmap/module.html b/public/app/plugins/panel/heatmap/module.html index ac9652a5afc..272aac99772 100644 --- a/public/app/plugins/panel/heatmap/module.html +++ b/public/app/plugins/panel/heatmap/module.html @@ -8,7 +8,7 @@
- +
diff --git a/public/app/plugins/panel/heatmap/partials/display_editor.html b/public/app/plugins/panel/heatmap/partials/display_editor.html index 4f215f3fcce..f161bf6cab4 100644 --- a/public/app/plugins/panel/heatmap/partials/display_editor.html +++ b/public/app/plugins/panel/heatmap/partials/display_editor.html @@ -53,6 +53,14 @@ +
+
Legend
+ + +
+
Buckets