From 825406690c5d5896189ea3caf3e2abca65c94b40 Mon Sep 17 00:00:00 2001 From: Chantsova Ekaterina Date: Mon, 23 Dec 2019 15:45:27 +0200 Subject: [PATCH] Flot widget pull requests: resolve conflicts for #2053, #2061 (#2289) * Add some datakey settings to edit legend appearance for flot widget * Fix timestamp and index search in 'line' flot charts tooltip Co-authored-by: Mirco Pizzichini <52463156+mircopz@users.noreply.github.com> --- ui/src/app/api/subscription.js | 3 +- ui/src/app/components/legend.directive.js | 4 +- ui/src/app/components/legend.tpl.html | 25 ++++++++--- ui/src/app/widget/lib/flot-widget.js | 55 ++++++++++++++++++++--- 4 files changed, 72 insertions(+), 15 deletions(-) diff --git a/ui/src/app/api/subscription.js b/ui/src/app/api/subscription.js index 89f8aae309..4ad374bfe4 100644 --- a/ui/src/app/api/subscription.js +++ b/ui/src/app/api/subscription.js @@ -332,7 +332,8 @@ export default class Subscription { for (var a = 0; a < datasource.dataKeys.length; a++) { var dataKey = datasource.dataKeys[a]; - dataKey.hidden = false; + dataKey.hidden = dataKey.settings.hideDataByDefault ? true : false; + dataKey.inLegend = dataKey.settings.removeFromLegend ? false : true; dataKey.pattern = angular.copy(dataKey.label); if (this.comparisonEnabled && dataKey.settings.comparisonSettings && dataKey.settings.comparisonSettings.showValuesForComparison) { diff --git a/ui/src/app/components/legend.directive.js b/ui/src/app/components/legend.directive.js index 76ffdb4e78..bed10e3f52 100644 --- a/ui/src/app/components/legend.directive.js +++ b/ui/src/app/components/legend.directive.js @@ -46,7 +46,9 @@ function Legend($compile, $templateCache, types) { scope.isRowDirection = scope.legendConfig.direction === types.direction.row.value; scope.toggleHideData = function(index) { - scope.legendData.keys[index].dataKey.hidden = !scope.legendData.keys[index].dataKey.hidden; + if (!scope.legendData.keys[index].dataKey.settings.disableDataHiding) { + scope.legendData.keys[index].dataKey.hidden = !scope.legendData.keys[index].dataKey.hidden; + } } $compile(element.contents())(scope); diff --git a/ui/src/app/components/legend.tpl.html b/ui/src/app/components/legend.tpl.html index 157835729b..d77bb1193c 100644 --- a/ui/src/app/components/legend.tpl.html +++ b/ui/src/app/components/legend.tpl.html @@ -27,7 +27,8 @@ - + - + {{ 'legend.min' | translate }} - {{ legendData.data[legendKey.dataIndex].min }} + + {{ legendData.data[legendKey.dataIndex].min }} + {{ 'legend.max' | translate }} - {{ legendData.data[legendKey.dataIndex].max }} + + {{ legendData.data[legendKey.dataIndex].max }} + {{ 'legend.avg' | translate }} - {{ legendData.data[legendKey.dataIndex].avg }} + + {{ legendData.data[legendKey.dataIndex].avg }} + {{ 'legend.total' | translate }} - {{ legendData.data[legendKey.dataIndex].total }} + + {{ legendData.data[legendKey.dataIndex].total }} + diff --git a/ui/src/app/widget/lib/flot-widget.js b/ui/src/app/widget/lib/flot-widget.js index 08496d574b..063c68a4da 100644 --- a/ui/src/app/widget/lib/flot-widget.js +++ b/ui/src/app/widget/lib/flot-widget.js @@ -139,12 +139,7 @@ export default class TbFlot { return seriesHover.index === seriesIndex; }); if (found && found.length) { - let timestamp; - if (!angular.isNumber(hoverInfo[0].time) || (found[0].time < hoverInfo[0].time)) { - timestamp = parseInt(hoverInfo[1].time); - } else { - timestamp = parseInt(hoverInfo[0].time); - } + let timestamp = parseInt(found[0].time); let date = moment(timestamp).format('YYYY-MM-DD HH:mm:ss'); let dateDiv = $('
' + date + '
'); dateDiv.css({ @@ -1213,7 +1208,35 @@ export default class TbFlot { } static get pieDatakeySettingsSchema() { - return {} + return { + "schema": { + "type": "object", + "title": "DataKeySettings", + "properties": { + "hideDataByDefault": { + "title": "Data is hidden by default", + "type": "boolean", + "default": false + }, + "disableDataHiding": { + "title": "Disable data hiding", + "type": "boolean", + "default": false + }, + "removeFromLegend": { + "title": "Remove datakey from legend", + "type": "boolean", + "default": false + } + }, + "required": [] + }, + "form": [ + "hideDataByDefault", + "disableDataHiding", + "removeFromLegend" + ] + }; } static datakeySettingsSchema(defaultShowLines, chartType) { @@ -1228,6 +1251,21 @@ export default class TbFlot { "type": "boolean", "default": false }, + "hideDataByDefault": { + "title": "Data is hidden by default", + "type": "boolean", + "default": false + }, + "disableDataHiding": { + "title": "Disable data hiding", + "type": "boolean", + "default": false + }, + "removeFromLegend": { + "title": "Remove datakey from legend", + "type": "boolean", + "default": false + }, "showLines": { "title": "Show lines", "type": "boolean", @@ -1316,6 +1354,9 @@ export default class TbFlot { "required": ["showLines", "fillLines", "showPoints"] }, "form": [ + "hideDataByDefault", + "disableDataHiding", + "removeFromLegend", "excludeFromStacking", "showLines", "fillLines",