Просмотр исходного кода

feat(panels): graph panel starting to work

Torkel Ödegaard 10 лет назад
Родитель
Сommit
aac190eaa9

+ 37 - 37
public/app/plugins/panel/graph/axisEditor.html

@@ -10,22 +10,22 @@
 					Unit
 				</li>
 				<li class="dropdown" style="width: 140px;"
-					ng-model="panel.y_formats[0]"
-					dropdown-typeahead="unitFormats"
-					dropdown-typeahead-on-select="setUnitFormat(0, $subItem)">
+					ng-model="ctrl.panel.y_formats[0]"
+					dropdown-typeahead="ctrl.unitFormats"
+					dropdown-typeahead-on-select="ctrl.setUnitFormat(0, $subItem)">
 				</li>
 				<li class="tight-form-item">
 					Scale type
 				</li>
 				<li>
-					<select class="input-small tight-form-input" style="width: 113px" ng-model="panel.grid.leftLogBase" ng-options="v as k for (k, v) in logScales" ng-change="render()"></select>
+					<select class="input-small tight-form-input" style="width: 113px" ng-model="ctrl.panel.grid.leftLogBase" ng-options="v as k for (k, v) in ctrl.logScales" ng-change="ctrl.render()"></select>
 				</li>
 				<li class="tight-form-item">
 					Label
 				</li>
 				<li>
 					<input type="text" class="input-small tight-form-input last"
-					ng-model="panel.leftYAxisLabel" ng-change="render()" ng-model-onblur>
+					ng-model="ctrl.panel.leftYAxisLabel" ng-change="ctrl.render()" ng-model-onblur>
 				</li>
 			</ul>
 			<div class="clearfix"></div>
@@ -40,16 +40,16 @@
 				</li>
 				<li>
 					<input type="number" class="input-small tight-form-input" placeholder="auto"
-					empty-to-null ng-model="panel.grid.leftMax"
-					ng-change="render()" ng-model-onblur>
+					empty-to-null ng-model="ctrl.panel.grid.leftMax"
+					ng-change="ctrl.render()" ng-model-onblur>
 				</li>
 				<li class="tight-form-item" style="width: 115px; text-align: right;">
 					Y-Min
 				</li>
 				<li>
 					<input type="number" class="input-small tight-form-input" placeholder="auto" style="width: 113px;"
-					empty-to-null ng-model="panel.grid.leftMin"
-					ng-change="render()" ng-model-onblur>
+					empty-to-null ng-model="ctrl.panel.grid.leftMin"
+					ng-change="ctrl.render()" ng-model-onblur>
 				</li>
 				</ul>
 			<div class="clearfix"></div>
@@ -63,22 +63,22 @@
 					Unit
 				</li>
 				<li class="dropdown" style="width: 140px"
-					ng-model="panel.y_formats[1]"
-					dropdown-typeahead="unitFormats"
-					dropdown-typeahead-on-select="setUnitFormat(1, $subItem)">
+					ng-model="ctrl.panel.y_formats[1]"
+					dropdown-typeahead="ctrl.unitFormats"
+					dropdown-typeahead-on-select="ctrl.setUnitFormat(1, $subItem)">
 				</li>
 				<li class="tight-form-item">
 					Scale type
 				</li>
 				<li>
-					<select class="input-small tight-form-input" style="width: 113px" ng-model="panel.grid.rightLogBase" ng-options="v as k for (k, v) in logScales" ng-change="render()"></select>
+					<select class="input-small tight-form-input" style="width: 113px" ng-model="ctrl.panel.grid.rightLogBase" ng-options="v as k for (k, v) in ctrl.logScales" ng-change="ctrl.render()"></select>
 				</li>
 				<li class="tight-form-item">
 					Label
 				</li>
 				<li>
 					<input type="text" class="input-small tight-form-input last"
-					ng-model="panel.rightYAxisLabel" ng-change="render()" ng-model-onblur>
+					ng-model="ctrl.panel.rightYAxisLabel" ng-change="ctrl.render()" ng-model-onblur>
 				</li>
 			</ul>
 			<div class="clearfix"></div>
@@ -93,16 +93,16 @@
 				</li>
 				<li>
 					<input type="number" class="input-small tight-form-input" placeholder="auto"
-					empty-to-null ng-model="panel.grid.rightMax"
-					ng-change="render()" ng-model-onblur>
+					empty-to-null ng-model="ctrl.panel.grid.rightMax"
+					ng-change="ctrl.render()" ng-model-onblur>
 				</li>
 				<li class="tight-form-item" style="width: 115px; text-align: right;">
 					Y-Min
 				</li>
 				<li>
 					<input type="number" class="input-small tight-form-input" placeholder="auto" style="width: 113px;"
-					empty-to-null ng-model="panel.grid.rightMin"
-					ng-change="render()" ng-model-onblur>
+					empty-to-null ng-model="ctrl.panel.grid.rightMin"
+					ng-change="ctrl.render()" ng-model-onblur>
 				</li>
 			</ul>
 			<div class="clearfix"></div>
@@ -119,13 +119,13 @@
 				<li class="tight-form-item">
 					X-Axis&nbsp;
 					<input class="cr1" id="hideXAxis" type="checkbox"
-					ng-model="panel['x-axis']" ng-checked="panel['x-axis']" ng-change="render()">
+					ng-model="ctrl.panel['x-axis']" ng-checked="ctrl.panel['x-axis']" ng-change="ctrl.render()">
 					<label for="hideXAxis" class="cr1"></label>
 				</li>
 				<li class="tight-form-item last">
 					Y-Axis&nbsp;
 					<input class="cr1" id="hideYAxis" type="checkbox"
-					ng-model="panel['y-axis']" ng-checked="panel['y-axis']" ng-change="render()">
+					ng-model="ctrl.panel['y-axis']" ng-checked="ctrl.panel['y-axis']" ng-change="ctrl.render()">
 					<label for="hideYAxis" class="cr1"></label>
 				</li>
 			</ul>
@@ -141,23 +141,23 @@
 				</li>
 				<li>
 					<input type="number" class="input-small tight-form-input"
-					ng-model="panel.grid.threshold1" ng-change="render()" ng-model-onblur>
+					ng-model="ctrl.panel.grid.threshold1" ng-change="ctrl.render()" ng-model-onblur>
 				</li>
 				<li class="tight-form-item">
-					<spectrum-picker ng-model="panel.grid.threshold1Color" ng-change="render()" ></spectrum-picker>
+					<spectrum-picker ng-model="ctrl.panel.grid.threshold1Color" ng-change="ctrl.render()" ></spectrum-picker>
 				</li>
 				<li class="tight-form-item">
 					Level 2
 				</li>
 				<li>
 					<input type="number" class="input-small tight-form-input"
-					ng-model="panel.grid.threshold2" ng-change="render()" ng-model-onblur>
+					ng-model="ctrl.panel.grid.threshold2" ng-change="ctrl.render()" ng-model-onblur>
 				</li>
 				<li class="tight-form-item">
-					<spectrum-picker ng-model="panel.grid.threshold2Color" ng-change="render()" ></spectrum-picker>
+					<spectrum-picker ng-model="ctrl.panel.grid.threshold2Color" ng-change="ctrl.render()" ></spectrum-picker>
 				</li>
 				<li class="tight-form-item last">
-					<editor-checkbox text="Line mode" model="panel.grid.thresholdLine" change="render()"></editor-checkbox>
+					<editor-checkbox text="Line mode" model="ctrl.panel.grid.thresholdLine" change="ctrl.render()"></editor-checkbox>
 				</li>
 			</ul>
 			<div class="clearfix"></div>
@@ -173,20 +173,20 @@
 					Legend
 				</li>
 				<li class="tight-form-item">
-					<editor-checkbox text="Show" model="panel.legend.show" change="get_data()"></editor-checkbox>
+					<editor-checkbox text="Show" model="ctrl.panel.legend.show" change="ctrl.refresh()"></editor-checkbox>
 				</li>
 				<li class="tight-form-item">
-					<editor-checkbox text="Table" model="panel.legend.alignAsTable" change="render()"></editor-checkbox>
+					<editor-checkbox text="Table" model="ctrl.panel.legend.alignAsTable" change="ctrl.render()"></editor-checkbox>
 				</li>
 				<li class="tight-form-item">
-					<editor-checkbox text="Right side" model="panel.legend.rightSide" change="render()"></editor-checkbox>
+					<editor-checkbox text="Right side" model="ctrl.panel.legend.rightSide" change="ctrl.render()"></editor-checkbox>
 				</li>
 				<li ng-if="panel.legend.rightSide" class="tight-form-item">
 					Side width
 				</li>
 				<li ng-if="panel.legend.rightSide" style="width: 105px">
 					<input type="number" class="input-small tight-form-input" placeholder="250" bs-tooltip="'Set a min-width for the legend side table/block'" data-placement="right"
-					ng-model="panel.legend.sideWidth" ng-change="render()" ng-model-onblur>
+					ng-model="ctrl.panel.legend.sideWidth" ng-change="ctrl.render()" ng-model-onblur>
 				</li>
 			</ul>
 			<div class="clearfix"></div>
@@ -197,10 +197,10 @@
 					Hide series
 				</li>
 				<li class="tight-form-item">
-					<editor-checkbox text="With only nulls" model="panel.legend.hideEmpty" change="render()"></editor-checkbox>
+					<editor-checkbox text="With only nulls" model="ctrl.panel.legend.hideEmpty" change="ctrl.render()"></editor-checkbox>
 				</li>
 				<li class="tight-form-item last">
-					<editor-checkbox text="With only zeroes" model="panel.legend.hideZero" change="render()"></editor-checkbox>
+					<editor-checkbox text="With only zeroes" model="ctrl.panel.legend.hideZero" change="ctrl.render()"></editor-checkbox>
 				</li>
 			</ul>
 			<div class="clearfix"></div>
@@ -212,26 +212,26 @@
 					Values
 				</li>
 				<li class="tight-form-item">
-					<editor-checkbox text="Min" model="panel.legend.min" change="legendValuesOptionChanged()"></editor-checkbox>
+					<editor-checkbox text="Min" model="ctrl.panel.legend.min" change="ctrl.legendValuesOptionChanged()"></editor-checkbox>
 				</li>
 				<li class="tight-form-item">
-					<editor-checkbox text="Max" model="panel.legend.max" change="legendValuesOptionChanged()"></editor-checkbox>
+					<editor-checkbox text="Max" model="ctrl.panel.legend.max" change="ctrl.legendValuesOptionChanged()"></editor-checkbox>
 				</li>
 				<li class="tight-form-item">
-					<editor-checkbox text="Avg" model="panel.legend.avg" change="legendValuesOptionChanged()"></editor-checkbox>
+					<editor-checkbox text="Avg" model="ctrl.panel.legend.avg" change="ctrl.legendValuesOptionChanged()"></editor-checkbox>
 				</li>
 				<li class="tight-form-item">
-					<editor-checkbox text="Current" model="panel.legend.current" change="legendValuesOptionChanged()"></editor-checkbox>
+					<editor-checkbox text="Current" model="ctrl.panel.legend.current" change="ctrl.legendValuesOptionChanged()"></editor-checkbox>
 				</li>
 				<li class="tight-form-item">
-					<editor-checkbox text="Total" model="panel.legend.total" change="legendValuesOptionChanged()"></editor-checkbox>
+					<editor-checkbox text="Total" model="ctrl.panel.legend.total" change="ctrl.legendValuesOptionChanged()"></editor-checkbox>
 				</li>
 				<li class="tight-form-item">
 					Decimals
 				</li>
 				<li style="width: 105px">
 					<input type="number" class="input-small tight-form-input" placeholder="auto" bs-tooltip="'Override automatic decimal precision for legend and tooltips'" data-placement="right"
-					ng-model="panel.decimals" ng-change="render()" ng-model-onblur>
+					ng-model="ctrl.panel.decimals" ng-change="ctrl.render()" ng-model-onblur>
 				</li>
 			</ul>
 			<div class="clearfix"></div>

+ 6 - 5
public/app/plugins/panel/graph/legend.js

@@ -8,7 +8,7 @@ define([
 function (angular, _, $) {
   'use strict';
 
-  var module = angular.module('grafana.panels.graph');
+  var module = angular.module('grafana.directives');
 
   module.directive('graphLegend', function(popoverSrv) {
 
@@ -16,13 +16,14 @@ function (angular, _, $) {
       link: function(scope, elem) {
         var $container = $('<section class="graph-legend"></section>');
         var firstRender = true;
-        var panel = scope.panel;
+        var ctrl = scope.ctrl;
+        var panel = ctrl.panel;
         var data;
         var seriesList;
         var i;
 
         scope.$on('render', function() {
-          data = scope.seriesList;
+          data = ctrl.seriesList;
           if (data) {
             render();
           }
@@ -54,7 +55,7 @@ function (angular, _, $) {
           var el = $(e.currentTarget);
           var index = getSeriesIndexForElement(el);
           var seriesInfo = seriesList[index];
-          scope.toggleSeries(seriesInfo, e);
+          ctrl.toggleSeries(seriesInfo, e);
         }
 
         function sortLegend(e) {
@@ -148,7 +149,7 @@ function (angular, _, $) {
 
             var html = '<div class="graph-legend-series';
             if (series.yaxis === 2) { html += ' pull-right'; }
-            if (scope.hiddenSeries[series.alias]) { html += ' graph-legend-series-hidden'; }
+            if (ctrl.hiddenSeries[series.alias]) { html += ' graph-legend-series-hidden'; }
             html += '" data-series-index="' + i + '">';
             html += '<div class="graph-legend-icon">';
             html += '<i class="fa fa-minus pointer" style="color:' + series.color + '"></i>';

+ 4 - 4
public/app/plugins/panel/graph/legend.popover.html

@@ -3,12 +3,12 @@
 
 	<div class="editor-row small" style="padding-bottom: 0;">
 		<label>Axis:</label>
-		<button ng-click="toggleYAxis(series);dismiss();"
+		<button ng-click="ctrl.toggleYAxis(series);dismiss();"
 			class="btn btn-mini"
 			ng-class="{'btn-success': series.yaxis === 1 }">
 			Left
 		</button>
-		<button ng-click="toggleYAxis(series);dismiss();"
+		<button ng-click="ctrl.toggleYAxis(series);dismiss();"
 			class="btn btn-mini"
 			ng-class="{'btn-success': series.yaxis === 2 }">
 			Right
@@ -16,10 +16,10 @@
 	</div>
 
 	<div class="editor-row">
-		<i ng-repeat="color in colors" class="pointer"
+		<i ng-repeat="color in ctrl.colors" class="pointer"
 			ng-class="{'fa fa-circle-o': color === series.color,'fa fa-circle': color !== series.color}"
 			ng-style="{color:color}"
-			ng-click="changeSeriesColor(series, color);dismiss();">&nbsp;</i>
+			ng-click="ctrl.changeSeriesColor(series, color);dismiss();">&nbsp;</i>
 	</div>
 </div>
 

+ 3 - 3
public/app/plugins/panel/graph/module.html

@@ -1,4 +1,4 @@
-<div class="graph-wrapper" ng-class="{'graph-legend-rightside': panel.legend.rightSide}">
+<div class="graph-wrapper" ng-class="{'graph-legend-rightside': ctrl.panel.legend.rightSide}">
 	<div class="graph-canvas-wrapper">
 
 		<div ng-if="datapointsWarning" class="datapoints-warning">
@@ -8,12 +8,12 @@
 			<span class="small" ng-show="datapointsOutside">Datapoints outside time range <tip>Can be caused by timezone mismatch between browser and graphite server</tip></span>
 		</div>
 
-		<div grafana-graph class="histogram-chart" ng-dblclick="zoomOut()">
+		<div grafana-graph class="histogram-chart" ng-dblclick="ctrl.zoomOut()">
 		</div>
 
 	</div>
 
-	<div class="graph-legend-wrapper" ng-if="panel.legend.show" graph-legend></div>
+	<div class="graph-legend-wrapper" ng-if="ctrl.panel.legend.show" graph-legend></div>
 </div>
 
 <div class="clearfix"></div>

+ 1 - 0
public/app/plugins/panel/graph/module.ts

@@ -3,6 +3,7 @@ import {PanelDirective} from '../../../features/panel/panel';
 import {GraphCtrl} from './graph_ctrl';
 
 import './graph';
+import './legend';
 
 class GraphPanel extends PanelDirective {
   controller = GraphCtrl;