Skip to content

Commit 51165e7

Browse files
committed
Merge branch 'shared_tooltip' of https://github.com/connection-reset/grafana into connection-reset-shared_tooltip
2 parents 9bb440b + e6c8e75 commit 51165e7

File tree

4 files changed

+56
-8
lines changed

4 files changed

+56
-8
lines changed

public/app/features/dashboard/model.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ export class DashboardModel {
1919
timezone: any;
2020
editable: any;
2121
sharedCrosshair: any;
22+
sharedTooltip: any;
2223
rows: DashboardRow[];
2324
time: any;
2425
timepicker: any;
@@ -52,6 +53,7 @@ export class DashboardModel {
5253
this.timezone = data.timezone || '';
5354
this.editable = data.editable !== false;
5455
this.sharedCrosshair = data.sharedCrosshair || false;
56+
this.sharedTooltip = data.sharedTooltip || false;
5557
this.hideControls = data.hideControls || false;
5658
this.time = data.time || { from: 'now-6h', to: 'now' };
5759
this.timepicker = data.timepicker || {};

public/app/features/dashboard/partials/settings.html

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,12 @@ <h5 class="section-heading">Toggles</h5>
6767
checked="dashboard.sharedCrosshair"
6868
label-class="width-11">
6969
</gf-form-switch>
70+
<gf-form-switch class="gf-form"
71+
label="Shared Tooltip"
72+
tooltip="Shared Tooltip on all graphs."
73+
checked="dashboard.sharedTooltip"
74+
label-class="width-11">
75+
</gf-form-switch>
7076
</div>
7177
</div>
7278

public/app/plugins/panel/graph/graph.ts

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ module.directive('grafanaGraph', function($rootScope, timeSrv) {
3434
var rootScope = scope.$root;
3535
var panelWidth = 0;
3636
var thresholdManager = new ThresholdManager(ctrl);
37+
var tooltip = new GraphTooltip(elem, dashboard, scope, function() {
38+
return sortedSeries;
39+
});
3740
var plot;
3841

3942
ctrl.events.on('panel-teardown', () => {
@@ -64,6 +67,19 @@ module.directive('grafanaGraph', function($rootScope, timeSrv) {
6467
}
6568
}, scope);
6669

70+
rootScope.onAppEvent('setTooltip', function(event, info) {
71+
// do not need to to this if event is from this panel
72+
// or another panel is in fullscreen mode
73+
if (info.scope === scope || ctrl.otherPanelInFullscreenMode()) {
74+
return;
75+
}
76+
tooltip.setTooltip(info.pos);
77+
}, scope);
78+
79+
rootScope.onAppEvent('clearTooltip', function() {
80+
tooltip.clearTooltip();
81+
}, scope);
82+
6783
// Receive render events
6884
ctrl.events.on('render', function(renderData) {
6985
data = renderData || data;
@@ -565,10 +581,6 @@ module.directive('grafanaGraph', function($rootScope, timeSrv) {
565581
return "%H:%M";
566582
}
567583

568-
var tooltip = new GraphTooltip(elem, dashboard, scope, function() {
569-
return sortedSeries;
570-
});
571-
572584
elem.bind("plotselected", function (event, ranges) {
573585
scope.$apply(function() {
574586
timeSrv.setTime({

public/app/plugins/panel/graph/graph_tooltip.js

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ function ($) {
1010
var ctrl = scope.ctrl;
1111
var panel = ctrl.panel;
1212

13-
var $tooltip = $('<div id="tooltip" class="graph-tooltip">');
13+
var $tooltip = $('<div class="graph-tooltip">');
1414

1515
this.destroy = function() {
1616
$tooltip.remove();
@@ -141,21 +141,49 @@ function ($) {
141141
}
142142
}
143143

144+
if (dashboard.sharedTooltip) {
145+
ctrl.publishAppEvent('clearTooltip');
146+
}
147+
144148
if (dashboard.sharedCrosshair) {
145149
ctrl.publishAppEvent('clearCrosshair');
146150
}
147151
});
148152

149153
elem.bind("plothover", function (event, pos, item) {
154+
if (dashboard.sharedCrosshair) {
155+
ctrl.publishAppEvent('setCrosshair', {pos: pos, scope: scope});
156+
}
157+
158+
if (dashboard.sharedTooltip) {
159+
pos.panelRelY = (pos.pageY - elem.offset().top) / elem.height();
160+
ctrl.publishAppEvent('setTooltip', {pos: pos, scope: scope});
161+
}
162+
self.setTooltip(pos, item);
163+
});
164+
165+
this.clearTooltip = function() {
166+
$tooltip.detach();
167+
};
168+
169+
this.setTooltip = function(pos, item) {
150170
var plot = elem.data().plot;
151171
var plotData = plot.getData();
152172
var xAxes = plot.getXAxes();
153173
var xMode = xAxes[0].options.mode;
154174
var seriesList = getSeriesFn();
155175
var group, value, absoluteTime, hoverInfo, i, series, seriesHtml, tooltipFormat;
156176

157-
if (dashboard.sharedCrosshair) {
158-
ctrl.publishAppEvent('setCrosshair', {pos: pos, scope: scope});
177+
// if panelRelY is defined another panel wants us to show a tooltip
178+
// get pageX from position on x axis and pageY from relative position in original panel
179+
if (pos.panelRelY !== undefined) {
180+
var pointOffset = plot.pointOffset({x: pos.x});
181+
if (Number.isNaN(pointOffset.left) || pointOffset.left < 0) {
182+
$tooltip.detach();
183+
return;
184+
}
185+
pos.pageX = elem.offset().left + pointOffset.left;
186+
pos.pageY = elem.offset().top + elem.height() * pos.panelRelY;
159187
}
160188

161189
if (seriesList.length === 0) {
@@ -238,7 +266,7 @@ function ($) {
238266
else {
239267
$tooltip.detach();
240268
}
241-
});
269+
};
242270
}
243271

244272
return GraphTooltip;

0 commit comments

Comments
 (0)