Commit 8fc5a278 by Torkel Ödegaard

Refactoring and fixes for PR #880

parent 27da2b02
...@@ -21,20 +21,27 @@ function (angular, $, kbn, moment, _, graphTooltip) { ...@@ -21,20 +21,27 @@ function (angular, $, kbn, moment, _, graphTooltip) {
var legendSideLastValue = null; var legendSideLastValue = null;
scope.crosshairEmiter = false; scope.crosshairEmiter = false;
scope.$on('setCrosshair',function(event,pos) { scope.onAppEvent('setCrosshair', function(event, info) {
console.log('setCrosshair'+ pos); // do not need to to this if event is from this panel
if(dashboard.sharedCrosshair && !scope.crosshairEmiter) { if (info.scope === scope) {
return;
}
if(dashboard.sharedCrosshair) {
console.log("setCrosshair");
var plot = elem.data().plot; 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; var plot = elem.data().plot;
plot.clearCrosshair(); plot.clearCrosshair();
}); });
scope.$on('refresh',function() { scope.$on('refresh', function() {
scope.get_data(); scope.get_data();
}); });
......
...@@ -5,17 +5,18 @@ define([ ...@@ -5,17 +5,18 @@ define([
function ($, kbn) { function ($, kbn) {
'use strict'; 'use strict';
function registerTooltipFeatures(elem, dashboard, scope, $rootScope) { function registerTooltipFeatures(elem, dashboard, scope) {
var $tooltip = $('<div id="tooltip">'); var $tooltip = $('<div id="tooltip">');
elem.mouseleave(function () { elem.mouseleave(function () {
if(scope.panel.tooltip.shared) { if (scope.panel.tooltip.shared || dashboard.sharedCrosshair) {
var plot = elem.data().plot; var plot = elem.data().plot;
$tooltip.detach(); if (plot) {
$rootScope.$broadcast('clearCrosshair'); $tooltip.detach();
//plot.clearCrosshair(); plot.unhighlight();
plot.unhighlight(); scope.appEvent('clearCrosshair');
}
} }
}); });
...@@ -33,11 +34,10 @@ function ($, kbn) { ...@@ -33,11 +34,10 @@ function ($, kbn) {
var data = plot.getData(); var data = plot.getData();
var group, value, timestamp, seriesInfo, format, i, series, hoverIndex, seriesHtml; var group, value, timestamp, seriesInfo, format, i, series, hoverIndex, seriesHtml;
scope.crosshairEmiter = true;
if(dashboard.sharedCrosshair){ if(dashboard.sharedCrosshair){
$rootScope.$broadcast('setCrosshair',pos); scope.appEvent('setCrosshair', { pos: pos, scope: scope });
} }
scope.crosshairEmiter = false;
if (scope.panel.tooltip.shared) { if (scope.panel.tooltip.shared) {
plot.unhighlight(); plot.unhighlight();
......
...@@ -33,11 +33,7 @@ ...@@ -33,11 +33,7 @@
<editor-opt-bool text="Stack" model="panel.stack" change="render()"></editor-opt-bool> <editor-opt-bool text="Stack" model="panel.stack" change="render()"></editor-opt-bool>
<editor-opt-bool text="Percent" model="panel.percentage" change="render()" tip="Stack as a percentage of total"></editor-opt-bool> <editor-opt-bool text="Percent" model="panel.percentage" change="render()" tip="Stack as a percentage of total"></editor-opt-bool>
<div class="editor-option" ng-show="panel.stack"> </div>
<label class="small">Stacked Values <tip>How should the values in stacked charts to be calculated?</tip></label>
<select class="input-small" ng-model="panel.tooltip.value_type" ng-options="f for f in ['cumulative','individual']" ng-change="render()"></select>
</div>
</div>
<div class="section"> <div class="section">
...@@ -55,7 +51,12 @@ ...@@ -55,7 +51,12 @@
<div class="section"> <div class="section">
<h5>Tooltip</h5> <h5>Tooltip</h5>
<div class="editor-option"> <div class="editor-option">
<label class="small">shared <tip> Show all series values on the same time in the same tooltip and a x croshair to help follow all series</tip> </label><input type="checkbox" ng-model="panel.tooltip.shared" ng-checked="panel.tooltip.shared" ng-change="render()"> <label class="small">shared <tip> Show all series values on the same time in the same tooltip and a x croshair to help follow all series</tip></label>
<input type="checkbox" ng-model="panel.tooltip.shared" ng-checked="panel.tooltip.shared" ng-change="render()">
</div>
<div class="editor-option" ng-show="panel.stack">
<label class="small">Stacked Values <tip>How should the values in stacked charts to be calculated?</tip></label>
<select class="input-small" ng-model="panel.tooltip.value_type" ng-options="f for f in ['cumulative','individual']" ng-change="render()"></select>
</div> </div>
</div> </div>
</div> </div>
......
...@@ -29,7 +29,6 @@ ...@@ -29,7 +29,6 @@
<select ng-model="dashboard.timezone" class='input-small' ng-options="f for f in ['browser','utc']"></select> <select ng-model="dashboard.timezone" class='input-small' ng-options="f for f in ['browser','utc']"></select>
</div> </div>
<editor-opt-bool text="Hide controls (CTRL+H)" model="dashboard.hideControls"></editor-opt-bool> <editor-opt-bool text="Hide controls (CTRL+H)" model="dashboard.hideControls"></editor-opt-bool>
<editor-opt-bool text="Shared Crosshair (CTRL+O)" model="dashboard.sharedCrosshair"></editor-opt-bool>
</div> </div>
</div> </div>
<div class="editor-row"> <div class="editor-row">
...@@ -75,6 +74,7 @@ ...@@ -75,6 +74,7 @@
<input class="cr1" id="pulldown{{pulldown.type}}" type="checkbox" ng-model="pulldown.enable" ng-checked="pulldown.enable"> <input class="cr1" id="pulldown{{pulldown.type}}" type="checkbox" ng-model="pulldown.enable" ng-checked="pulldown.enable">
<label for="pulldown{{pulldown.type}}" class="cr1"></label> <label for="pulldown{{pulldown.type}}" class="cr1"></label>
</div> </div>
<editor-opt-bool text="Shared Crosshair (CTRL+O)" model="dashboard.sharedCrosshair"></editor-opt-bool>
</div> </div>
</div> </div>
</div> </div>
......
...@@ -29,6 +29,7 @@ function(angular, $) { ...@@ -29,6 +29,7 @@ function(angular, $) {
keyboardManager.bind('ctrl+o', function() { keyboardManager.bind('ctrl+o', function() {
var current = scope.dashboard.sharedCrosshair; var current = scope.dashboard.sharedCrosshair;
scope.dashboard.sharedCrosshair = !current; scope.dashboard.sharedCrosshair = !current;
scope.dashboard.emit_refresh('refresh');
}, { inputDisabled: true }); }, { inputDisabled: true });
keyboardManager.bind('ctrl+h', function() { keyboardManager.bind('ctrl+h', function() {
......
...@@ -27,7 +27,7 @@ function (angular, $, kbn, _, moment) { ...@@ -27,7 +27,7 @@ function (angular, $, kbn, _, moment) {
this.timezone = data.timezone || 'browser'; this.timezone = data.timezone || 'browser';
this.editable = data.editable === false ? false : true; this.editable = data.editable === false ? false : true;
this.hideControls = data.hideControls || false; this.hideControls = data.hideControls || false;
this.sharedCrosshair = data.sharedCrosshair || true; this.sharedCrosshair = data.sharedCrosshair || false;
this.rows = data.rows || []; this.rows = data.rows || [];
this.nav = data.nav || []; this.nav = data.nav || [];
this.time = data.time || { from: 'now-6h', to: 'now' }; this.time = data.time || { from: 'now-6h', to: 'now' };
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment