From b250d10320763c62c4e762e7c56658a7e214c84a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torkel=20=C3=96degaard?= Date: Tue, 30 Sep 2014 17:55:07 +0200 Subject: [PATCH 1/9] Trying to fox unit tests for sharePanelCtrl --- src/test/specs/sharePanelCtrl-specs.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/test/specs/sharePanelCtrl-specs.js b/src/test/specs/sharePanelCtrl-specs.js index 4c36e8fe156..5b712bbba7a 100644 --- a/src/test/specs/sharePanelCtrl-specs.js +++ b/src/test/specs/sharePanelCtrl-specs.js @@ -1,7 +1,8 @@ define([ './helpers', + 'moment', 'controllers/sharePanelCtrl' -], function(helpers) { +], function(helpers, moment) { 'use strict'; describe('SharePanelCtrl', function() { @@ -12,6 +13,10 @@ define([ beforeEach(ctx.providePhase()); beforeEach(ctx.createControllerPhase('SharePanelCtrl')); + function getDate(year, month, day) { + return moment.utc(new Date(year, month, day)).toDate(); + } + describe('shareUrl with current time range and panel', function() { it('should generate share url relative time', function() { @@ -26,7 +31,7 @@ define([ it('should generate share url absolute time', function() { ctx.$location.path('/test'); ctx.scope.panel = { id: 22 }; - ctx.timeSrv.time = { from: new Date(2012,1,1), to: new Date(2014,3,5) }; + ctx.timeSrv.time = { from: getDate(2012,1,1), to: new Date(2014,3,5) }; ctx.scope.buildUrl(); expect(ctx.scope.shareUrl).to.be('http://server/#/test?from=1328050800000&to=1396648800000&panelId=22&fullscreen'); From ce972d4f194cecdb000d608d6e762a9ba998604c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torkel=20=C3=96degaard?= Date: Tue, 30 Sep 2014 17:56:43 +0200 Subject: [PATCH 2/9] Graph: css & scroll fix for dropdown menus in graph edit mode, Closes #855 --- CHANGELOG.md | 1 + src/app/panels/graph/styleEditor.html | 2 +- src/css/less/grafana.less | 4 ++++ 3 files changed, 6 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 82390a8e88c..52ee0066cf5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ # 1.8.1 (unreleased) **Fixes** +- [Issue #855](https://github.com/grafana/grafana/issues/855). Graph: Fix for scroll issue in graph edit mode when dropdown goes below screen - [Issue #847](https://github.com/grafana/grafana/issues/847). Graph: Fix for series draw order not being the same after hiding/unhiding series - [Issue #851](https://github.com/grafana/grafana/issues/851). Annotations: Fix for annotations not reloaded when switching between 2 dashboards with annotations - [Issue #846](https://github.com/grafana/grafana/issues/846). Edit panes: Issue when open row or json editor when scrolled down the page, unable to scroll and you did not see editor diff --git a/src/app/panels/graph/styleEditor.html b/src/app/panels/graph/styleEditor.html index cd83f23f197..13644e95578 100644 --- a/src/app/panels/graph/styleEditor.html +++ b/src/app/panels/graph/styleEditor.html @@ -90,7 +90,7 @@ {{option.name}}: {{option.value}} diff --git a/src/css/less/grafana.less b/src/css/less/grafana.less index 9f55faf3ba7..6c2c5e4ea61 100644 --- a/src/css/less/grafana.less +++ b/src/css/less/grafana.less @@ -114,6 +114,10 @@ .panel-content { padding-bottom: 130px; } + + .dropdown-menu { + margin-bottom: 70px; + } } .dashboard-fullscreen { From 282c834d9f435340ace6fdd2b0aaf2272150ff8e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torkel=20=C3=96degaard?= Date: Tue, 30 Sep 2014 17:58:02 +0200 Subject: [PATCH 3/9] updated package.json --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 8369d640c62..90983011688 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,7 @@ "company": "Coding Instinct AB" }, "name": "grafana", - "version": "1.8.1", + "version": "1.9.0", "repository": { "type": "git", "url": "http://github.com/torkelo/grafana.git" From 44f2a375f60678796a8713698bc4ece36e5e6089 Mon Sep 17 00:00:00 2001 From: toni-moreno Date: Tue, 30 Sep 2014 06:24:56 +0200 Subject: [PATCH 4/9] Added shared crosshair to dashboards to track better all graphs, and little Fix for #884 --- src/app/directives/grafanaGraph.js | 18 +++++++++++++-- src/app/directives/grafanaGraph.tooltip.js | 22 ++++++++++++++----- src/app/partials/dasheditor.html | 1 + .../dashboard/dashboardKeyBindings.js | 6 +++++ src/app/services/dashboard/dashboardSrv.js | 1 + 5 files changed, 40 insertions(+), 8 deletions(-) diff --git a/src/app/directives/grafanaGraph.js b/src/app/directives/grafanaGraph.js index 42ef1b91cb5..8efcee45fd6 100755 --- a/src/app/directives/grafanaGraph.js +++ b/src/app/directives/grafanaGraph.js @@ -19,6 +19,20 @@ function (angular, $, kbn, moment, _, graphTooltip) { var dashboard = scope.dashboard; var data, annotations; var legendSideLastValue = null; + scope.crosshairEmiter = false; + + scope.$on('setCrosshair',function(event,pos) { + console.log('setCrosshair'+ pos); + if(dashboard.sharedCrosshair && !scope.crosshairEmiter) { + var plot = elem.data().plot; + plot.setCrosshair({ x: pos.x, y: pos.y }); + } + }); + + scope.$on('clearCrosshair',function() { + var plot = elem.data().plot; + plot.clearCrosshair(); + }); scope.$on('refresh',function() { scope.get_data(); @@ -147,7 +161,7 @@ function (angular, $, kbn, moment, _, graphTooltip) { color: '#666' }, crosshair: { - mode: panel.tooltip.shared ? "x" : null + mode: panel.tooltip.shared || dashboard.sharedCrosshair ? "x" : null } }; @@ -394,7 +408,7 @@ function (angular, $, kbn, moment, _, graphTooltip) { elem.html(''); } - graphTooltip.register(elem, dashboard, scope); + graphTooltip.register(elem, dashboard, scope, $rootScope); elem.bind("plotselected", function (event, ranges) { scope.$apply(function() { diff --git a/src/app/directives/grafanaGraph.tooltip.js b/src/app/directives/grafanaGraph.tooltip.js index 513d7126985..380d948ef5e 100644 --- a/src/app/directives/grafanaGraph.tooltip.js +++ b/src/app/directives/grafanaGraph.tooltip.js @@ -5,7 +5,7 @@ define([ function ($, kbn) { 'use strict'; - function registerTooltipFeatures(elem, dashboard, scope) { + function registerTooltipFeatures(elem, dashboard, scope, $rootScope) { var $tooltip = $('
'); @@ -13,7 +13,8 @@ function ($, kbn) { if(scope.panel.tooltip.shared) { var plot = elem.data().plot; $tooltip.detach(); - plot.clearCrosshair(); + $rootScope.$broadcast('clearCrosshair'); + //plot.clearCrosshair(); plot.unhighlight(); } }); @@ -32,6 +33,11 @@ function ($, kbn) { var data = plot.getData(); var group, value, timestamp, seriesInfo, format, i, series, hoverIndex, seriesHtml; + scope.crosshairEmiter = true; + if(dashboard.sharedCrosshair){ + $rootScope.$broadcast('setCrosshair',pos); + } + scope.crosshairEmiter = false; if (scope.panel.tooltip.shared) { plot.unhighlight(); @@ -60,11 +66,15 @@ function ($, kbn) { seriesInfo = series.info; format = scope.panel.y_formats[seriesInfo.yaxis - 1]; - if (scope.panel.stack && scope.panel.tooltip.value_type === 'individual') { - value = series.data[hoverIndex][1]; + if (scope.panel.stack) { + if (scope.panel.stack && scope.panel.tooltip.value_type === 'individual') { + value = series.data[hoverIndex][1]; + } else { + last_value += series.data[hoverIndex][1]; + value = last_value; + } } else { - last_value += series.data[hoverIndex][1]; - value = last_value; + value = series.data[hoverIndex][1]; } value = kbn.valueFormats[format](value, series.yaxis.tickDecimals); diff --git a/src/app/partials/dasheditor.html b/src/app/partials/dasheditor.html index ae8608b97d1..07e846127fe 100644 --- a/src/app/partials/dasheditor.html +++ b/src/app/partials/dasheditor.html @@ -29,6 +29,7 @@
+
diff --git a/src/app/services/dashboard/dashboardKeyBindings.js b/src/app/services/dashboard/dashboardKeyBindings.js index 11d5e2d4787..b6b4d606c6d 100644 --- a/src/app/services/dashboard/dashboardKeyBindings.js +++ b/src/app/services/dashboard/dashboardKeyBindings.js @@ -18,6 +18,7 @@ function(angular, $) { keyboardManager.unbind('ctrl+s'); keyboardManager.unbind('ctrl+r'); keyboardManager.unbind('ctrl+z'); + keyboardManager.unbind('ctrl+o'); keyboardManager.unbind('esc'); }); @@ -25,6 +26,11 @@ function(angular, $) { scope.appEvent('show-dash-editor', { src: 'app/partials/search.html' }); }, { inputDisabled: true }); + keyboardManager.bind('ctrl+o', function() { + var current = scope.dashboard.sharedCrosshair; + scope.dashboard.sharedCrosshair = !current; + }, { inputDisabled: true }); + keyboardManager.bind('ctrl+h', function() { var current = scope.dashboard.hideControls; scope.dashboard.hideControls = !current; diff --git a/src/app/services/dashboard/dashboardSrv.js b/src/app/services/dashboard/dashboardSrv.js index 17313a207d5..d071b286535 100644 --- a/src/app/services/dashboard/dashboardSrv.js +++ b/src/app/services/dashboard/dashboardSrv.js @@ -27,6 +27,7 @@ function (angular, $, kbn, _, moment) { this.timezone = data.timezone || 'browser'; this.editable = data.editable === false ? false : true; this.hideControls = data.hideControls || false; + this.sharedCrosshair = data.sharedCrosshair || true; this.rows = data.rows || []; this.nav = data.nav || []; this.time = data.time || { from: 'now-6h', to: 'now' }; From ffd370176d654fda2e0fb9a5544b8ef8fec1f61d Mon Sep 17 00:00:00 2001 From: toni-moreno Date: Wed, 1 Oct 2014 07:15:20 +0200 Subject: [PATCH 5/9] fix tooltip test expecting for stacked data --- src/test/specs/graph-tooltip-specs.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/test/specs/graph-tooltip-specs.js b/src/test/specs/graph-tooltip-specs.js index 2ca3ec85cac..17dc551bdc4 100644 --- a/src/test/specs/graph-tooltip-specs.js +++ b/src/test/specs/graph-tooltip-specs.js @@ -15,6 +15,7 @@ define([ shared: true }, y_formats: ['ms', 'none'], + stack: true } }; From 2e9cc2a74e32d817290a4f83ec0b9d193c387f9a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torkel=20=C3=96degaard?= Date: Wed, 1 Oct 2014 07:58:31 +0200 Subject: [PATCH 6/9] Fix for SharePanelCtrl-specs and travis-ci timezone issue --- src/test/specs/sharePanelCtrl-specs.js | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/src/test/specs/sharePanelCtrl-specs.js b/src/test/specs/sharePanelCtrl-specs.js index 5b712bbba7a..8c4eb2a2443 100644 --- a/src/test/specs/sharePanelCtrl-specs.js +++ b/src/test/specs/sharePanelCtrl-specs.js @@ -1,8 +1,7 @@ define([ './helpers', - 'moment', 'controllers/sharePanelCtrl' -], function(helpers, moment) { +], function(helpers) { 'use strict'; describe('SharePanelCtrl', function() { @@ -13,10 +12,6 @@ define([ beforeEach(ctx.providePhase()); beforeEach(ctx.createControllerPhase('SharePanelCtrl')); - function getDate(year, month, day) { - return moment.utc(new Date(year, month, day)).toDate(); - } - describe('shareUrl with current time range and panel', function() { it('should generate share url relative time', function() { @@ -31,16 +26,16 @@ define([ it('should generate share url absolute time', function() { ctx.$location.path('/test'); ctx.scope.panel = { id: 22 }; - ctx.timeSrv.time = { from: getDate(2012,1,1), to: new Date(2014,3,5) }; + ctx.timeSrv.time = { from: new Date(1362178800000), to: new Date(1396648800000) }; ctx.scope.buildUrl(); - expect(ctx.scope.shareUrl).to.be('http://server/#/test?from=1328050800000&to=1396648800000&panelId=22&fullscreen'); + expect(ctx.scope.shareUrl).to.be('http://server/#/test?from=1362178800000&to=1396648800000&panelId=22&fullscreen'); }); it('should generate share url with time as JSON strings', function() { ctx.$location.path('/test'); ctx.scope.panel = { id: 22 }; - ctx.timeSrv.time = { from: new Date(2012,1,1).toJSON(), to: new Date(2014,3,5).toJSON() }; + ctx.timeSrv.time = { from: "2012-01-31T23:00:00.000Z", to: "2014-04-04T22:00:00.000Z" }; ctx.scope.buildUrl(); expect(ctx.scope.shareUrl).to.be('http://server/#/test?from=1328050800000&to=1396648800000&panelId=22&fullscreen'); From 8fc5a2785f9443209c7952537881fb551955d0f3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torkel=20=C3=96degaard?= Date: Wed, 1 Oct 2014 09:08:11 +0200 Subject: [PATCH 7/9] Refactoring and fixes for PR #880 --- src/app/directives/grafanaGraph.js | 19 +++++++++++++------ src/app/directives/grafanaGraph.tooltip.js | 18 +++++++++--------- src/app/panels/graph/styleEditor.html | 13 +++++++------ src/app/partials/dasheditor.html | 2 +- .../dashboard/dashboardKeyBindings.js | 1 + src/app/services/dashboard/dashboardSrv.js | 2 +- 6 files changed, 32 insertions(+), 23 deletions(-) diff --git a/src/app/directives/grafanaGraph.js b/src/app/directives/grafanaGraph.js index 8efcee45fd6..8d8e288d3f9 100755 --- a/src/app/directives/grafanaGraph.js +++ b/src/app/directives/grafanaGraph.js @@ -21,20 +21,27 @@ function (angular, $, kbn, moment, _, graphTooltip) { var legendSideLastValue = null; scope.crosshairEmiter = false; - scope.$on('setCrosshair',function(event,pos) { - console.log('setCrosshair'+ pos); - if(dashboard.sharedCrosshair && !scope.crosshairEmiter) { + scope.onAppEvent('setCrosshair', function(event, info) { + // do not need to to this if event is from this panel + if (info.scope === scope) { + return; + } + + if(dashboard.sharedCrosshair) { + console.log("setCrosshair"); var plot = elem.data().plot; - plot.setCrosshair({ x: pos.x, y: pos.y }); + if (plot) { + plot.setCrosshair({ x: info.pos.x, y: info.pos.y }); + } } }); - scope.$on('clearCrosshair',function() { + scope.onAppEvent('clearCrosshair', function() { var plot = elem.data().plot; plot.clearCrosshair(); }); - scope.$on('refresh',function() { + scope.$on('refresh', function() { scope.get_data(); }); diff --git a/src/app/directives/grafanaGraph.tooltip.js b/src/app/directives/grafanaGraph.tooltip.js index 380d948ef5e..0d8fafe498a 100644 --- a/src/app/directives/grafanaGraph.tooltip.js +++ b/src/app/directives/grafanaGraph.tooltip.js @@ -5,17 +5,18 @@ define([ function ($, kbn) { 'use strict'; - function registerTooltipFeatures(elem, dashboard, scope, $rootScope) { + function registerTooltipFeatures(elem, dashboard, scope) { var $tooltip = $('
'); elem.mouseleave(function () { - if(scope.panel.tooltip.shared) { + if (scope.panel.tooltip.shared || dashboard.sharedCrosshair) { var plot = elem.data().plot; - $tooltip.detach(); - $rootScope.$broadcast('clearCrosshair'); - //plot.clearCrosshair(); - plot.unhighlight(); + if (plot) { + $tooltip.detach(); + plot.unhighlight(); + scope.appEvent('clearCrosshair'); + } } }); @@ -33,11 +34,10 @@ function ($, kbn) { var data = plot.getData(); var group, value, timestamp, seriesInfo, format, i, series, hoverIndex, seriesHtml; - scope.crosshairEmiter = true; if(dashboard.sharedCrosshair){ - $rootScope.$broadcast('setCrosshair',pos); + scope.appEvent('setCrosshair', { pos: pos, scope: scope }); } - scope.crosshairEmiter = false; + if (scope.panel.tooltip.shared) { plot.unhighlight(); diff --git a/src/app/panels/graph/styleEditor.html b/src/app/panels/graph/styleEditor.html index 9f4c5c3a1fb..07e72c93f15 100644 --- a/src/app/panels/graph/styleEditor.html +++ b/src/app/panels/graph/styleEditor.html @@ -33,11 +33,7 @@ -
- - -
-
+
@@ -55,7 +51,12 @@
Tooltip
- + + +
+
+ +
diff --git a/src/app/partials/dasheditor.html b/src/app/partials/dasheditor.html index 07e846127fe..9802ab75004 100644 --- a/src/app/partials/dasheditor.html +++ b/src/app/partials/dasheditor.html @@ -29,7 +29,6 @@ -
@@ -75,6 +74,7 @@
+ diff --git a/src/app/services/dashboard/dashboardKeyBindings.js b/src/app/services/dashboard/dashboardKeyBindings.js index b6b4d606c6d..987bb5a71ad 100644 --- a/src/app/services/dashboard/dashboardKeyBindings.js +++ b/src/app/services/dashboard/dashboardKeyBindings.js @@ -29,6 +29,7 @@ function(angular, $) { keyboardManager.bind('ctrl+o', function() { var current = scope.dashboard.sharedCrosshair; scope.dashboard.sharedCrosshair = !current; + scope.dashboard.emit_refresh('refresh'); }, { inputDisabled: true }); keyboardManager.bind('ctrl+h', function() { diff --git a/src/app/services/dashboard/dashboardSrv.js b/src/app/services/dashboard/dashboardSrv.js index d071b286535..40d9b5df55f 100644 --- a/src/app/services/dashboard/dashboardSrv.js +++ b/src/app/services/dashboard/dashboardSrv.js @@ -27,7 +27,7 @@ function (angular, $, kbn, _, moment) { this.timezone = data.timezone || 'browser'; this.editable = data.editable === false ? false : true; this.hideControls = data.hideControls || false; - this.sharedCrosshair = data.sharedCrosshair || true; + this.sharedCrosshair = data.sharedCrosshair || false; this.rows = data.rows || []; this.nav = data.nav || []; this.time = data.time || { from: 'now-6h', to: 'now' }; From d77448d84e4a765363c3756fb99ea55d285a207b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torkel=20=C3=96degaard?= Date: Wed, 1 Oct 2014 09:10:49 +0200 Subject: [PATCH 8/9] Fixed unit tests for grafanaGraph component --- src/test/specs/grafanaGraph-specs.js | 8 +++++++- src/test/specs/graph-tooltip-specs.js | 4 +++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/test/specs/grafanaGraph-specs.js b/src/test/specs/grafanaGraph-specs.js index 159a923cc7c..c5659ba8825 100644 --- a/src/test/specs/grafanaGraph-specs.js +++ b/src/test/specs/grafanaGraph-specs.js @@ -14,10 +14,13 @@ define([ function graphScenario(desc, func) { describe(desc, function() { var ctx = {}; + ctx.setup = function (setupFunc) { + beforeEach(module(function($provide) { $provide.value("timeSrv", new helpers.TimeSrvStub()); })); + beforeEach(inject(function($rootScope, $compile) { var scope = $rootScope.$new(); var element = angular.element("
"); @@ -28,10 +31,13 @@ define([ grid: {}, y_formats: [], seriesOverrides: [], - tooltip: { + tooltip: { shared: true } }; + + scope.appEvent = sinon.spy(); + scope.onAppEvent = sinon.spy(); scope.hiddenSeries = {}; scope.dashboard = { timezone: 'browser' }; scope.range = { diff --git a/src/test/specs/graph-tooltip-specs.js b/src/test/specs/graph-tooltip-specs.js index 17dc551bdc4..7f20ad8dbc9 100644 --- a/src/test/specs/graph-tooltip-specs.js +++ b/src/test/specs/graph-tooltip-specs.js @@ -10,12 +10,14 @@ define([ formatDate: sinon.stub().returns('date'), }; var scope = { + appEvent: sinon.spy(), + onAppEvent: sinon.spy(), panel: { tooltip: { shared: true }, y_formats: ['ms', 'none'], - stack: true + stack: true } }; From c79ab84fdf3e7b9a23211c2f8cafe9ec7a389689 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torkel=20=C3=96degaard?= Date: Wed, 1 Oct 2014 09:42:42 +0200 Subject: [PATCH 9/9] More fixes related to shared crosshair #880 --- src/app/directives/grafanaGraph.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/app/directives/grafanaGraph.js b/src/app/directives/grafanaGraph.js index 8d8e288d3f9..685ac7e0b83 100755 --- a/src/app/directives/grafanaGraph.js +++ b/src/app/directives/grafanaGraph.js @@ -28,7 +28,6 @@ function (angular, $, kbn, moment, _, graphTooltip) { } if(dashboard.sharedCrosshair) { - console.log("setCrosshair"); var plot = elem.data().plot; if (plot) { plot.setCrosshair({ x: info.pos.x, y: info.pos.y }); @@ -38,7 +37,9 @@ function (angular, $, kbn, moment, _, graphTooltip) { scope.onAppEvent('clearCrosshair', function() { var plot = elem.data().plot; - plot.clearCrosshair(); + if (plot) { + plot.clearCrosshair(); + } }); scope.$on('refresh', function() {