• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

eswdd / aardvark / 4031096410

pending completion
4031096410

push

github

GitHub
Add rel="noopener noreferrer" to external link (#247)

1622 of 2218 branches covered (73.13%)

3379 of 4186 relevant lines covered (80.72%)

83.13 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

65.15
/static-content/GraphControlCtrl.js
1
/*
2
 * Graph management:
3
 * - adding/removing
4
 * - global graph options
5
 * - per-graph options (shared and type specific)
6
 */
7
aardvark.controller('GraphControlCtrl', [ '$scope', '$rootScope', 'idGenerator', 'tsdbClient', 'deepUtils', function GraphControlCtrl($scope, $rootScope, idGenerator, $tsdbClient, deepUtils) {
1✔
8
    $scope.lastHash = "";
14✔
9
    $scope.hashModel = function(global,graphs) {
14✔
10
        // todo: something better?
11
        return JSON.stringify(global) + JSON.stringify(graphs);
19✔
12
    }
13
    // accordion openings
14
    $scope.isOpen={};
14✔
15

16
    // misc logic
17
    $scope.graphs = [];
14✔
18

19
    // per graph settings
20
    $scope.showEdit={};
14✔
21
    
22
    // graph model
23
    $scope.graphs = [];
14✔
24

25
    // global model
26
    $scope.model = {};
14✔
27
    $scope.model.relativePeriod = "2h";
14✔
28
    $scope.model.absoluteTimeSpecification = false;
14✔
29
    $scope.model.autoReload = false;
14✔
30
    $scope.model.autoReloadPeriod = "15";
14✔
31
    $scope.model.fromDate = "";
14✔
32
    $scope.model.fromTime = "";
14✔
33
    $scope.model.toDate = "";
14✔
34
    $scope.model.toTime = "";
14✔
35

36
    $scope.model.autoGraphHeight = true;
14✔
37
    $scope.model.minGraphHeight = 0;
14✔
38
    $scope.model.graphHeight = 300;
14✔
39
    
40
    $scope.model.globalDownsampling = false;
14✔
41
    $scope.model.globalDownsampleTo = "5m";
14✔
42
    
43
    $scope.model.baselining = false;
14✔
44
    $scope.model.baselineDatumStyle = "relative";
14✔
45
    $scope.model.baselineRelativePeriod = "1d";
14✔
46
    $scope.model.baselineFromDate = "";
14✔
47
    $scope.model.baselineFromTime = "";
14✔
48
    $scope.model.baselineToDate = "";
14✔
49
    $scope.model.baselineToTime = "";
14✔
50

51
    $scope.fromDatePopupOpen = false;
14✔
52
    $scope.toDatePopupOpen = false;
14✔
53

54
    $scope.bindWatchExpressions = function() {
14✔
55
        $scope.$watch('model.globalDownsampling', function(newVal, oldVal, scope) {
14✔
56
            $rootScope.$emit('globalDownsamplingChanged', newVal);
×
57
        });
58

59
        $scope.$watch('model.absoluteTimeSpecification', function(newVal, oldVal, scope) {
14✔
60
            if (newVal != oldVal) {
×
61
                // want to block this if the change came from a graph modification..
62
                // so only save the model if changed
63
                $scope.saveAndRenderGraphsIfAutoUpdateWithChangeCheck();
×
64
            }
65
        });
66

67
        /*
68
        // $apply(fn()) is not working in GraphCtrl so we do it manually via a custom event
69
        $rootScope.$watch('model.global', function(newVal, oldVal, scope) {
70
            console.log("rootScope.model.global changed, updating GraphControlCtrl model")
71
            $scope.loadModel(null, false);
72
        });
73
        $rootScope.$watch('model.graphs', function(newVal, oldVal, scope) {
74
            console.log("rootScope.model.graphs changed, updating GraphControlCtrl model")
75
            $scope.loadModel(null, false);
76
        });
77
        */
78
        $rootScope.$on("modelUpdated", function(event,data) {
14✔
79
            //console.log("rootScope.modelUpdated received, updating GraphControlCtrl model")
80
            $scope.loadModel(null, false);
×
81
        });
82
        $scope.loadModel(null, true);
14✔
83
    }
84

85
    $scope.openFromDatePopup = function() {
14✔
86
        $scope.fromDatePopupOpen = !$scope.fromDatePopupOpen;
×
87
    };
88
    $scope.openToDatePopup = function() {
14✔
89
        $scope.toDatePopupOpen = !$scope.toDatePopupOpen;
×
90
    };
91
    
92
    $scope.toggleGraphOpen = function(index) {
14✔
93
        if (index >= $scope.graphs.length) {
×
94
            return;
×
95
        }
96
        var graphId = $scope.graphs[index].id; 
×
97
        if ($scope.isOpen[graphId]) {
×
98
            $scope.isOpen[graphId] = false;
×
99
        }
100
        else {
101
            for (var i=0; i<$scope.graphs.length; i++) {
×
102
                $scope.isOpen[$scope.graphs[i].id] = false;
×
103
            }
104
            $scope.isOpen[graphId] = true;
×
105
        }
106
    }
107
    
108
    $scope.showGnuplotStyles = function() {
14✔
109
        return $tsdbClient.versionNumber >= $tsdbClient.TSDB_2_2;
×
110
    }
111
    
112
    $scope.showGnuplotAnnotationOptions = function() {
14✔
113
        return $tsdbClient.versionNumber >= $tsdbClient.TSDB_2_3;
×
114
    }
115
    
116
    $scope.now = function() {
14✔
117
        if ($scope.autoReload) {
×
118
            $scope.saveAndRenderGraphsInternal(true);
×
119
        }
120
        else {
121
            $scope.toDate = moment.utc().format("YYYY/MM/DD");
×
122
            $scope.toTime = new Date();
×
123
            $scope.saveAndRenderGraphsIfAutoUpdate();
×
124
        }
125
        
126
    }
127
    
128
    $scope.setGraphType = function(graph, type) {
14✔
129
        graph.type = type;
×
130
        $scope.saveAndRenderGraphsIfAutoUpdate();
×
131
    }
132
    
133
    $scope.setGnuplotStyle = function(graph, style) {
14✔
134
        graph.gnuplot.style = style;
×
135
        $scope.saveAndRenderGraphsIfAutoUpdate();
×
136
    }
137
    
138
    $scope.heatmapStyleLabels = {
14✔
139
        auto: "Automatic",
140
        week_day: "Week columns, day cells",
141
        day_hour: "Day columns, hour cells"
142
    }
143
    
144
    $scope.setHeatmapStyle = function(graph, style) {
14✔
145
        graph.heatmap.style = style;
×
146
        $scope.saveAndRenderGraphsIfAutoUpdate();
×
147
    }
148

149
    $scope.getHeatmapStyleLabel = function(graph) {
14✔
150
        if (graph.heatmap == null || graph.heatmap.style == null || graph.heatmap.style == "") {
×
151
            return $scope.heatmapStyleLabels.auto;
×
152
        }
153
        return $scope.heatmapStyleLabels[graph.heatmap.style];
×
154
    }
155
    
156
    $scope.heatmapColourSchemeLabels = {
14✔
157
        RdYlGn: "Diverging - Red/Yellow/Green",
158
        Gn: "Sequential - Green",
159
        Bl: "Sequential - Blue",
160
        Rd: "Sequential - Red"
161
    }
162
    
163
    $scope.setHeatmapColourScheme = function(graph, scheme) {
14✔
164
        graph.heatmap.colourScheme = scheme;
×
165
        $scope.saveAndRenderGraphsIfAutoUpdate();
×
166
    }
167
    
168
    $scope.getHeatmapColourSchemeLabel = function(graph) {
14✔
169
        if (graph.heatmap == null || graph.heatmap.colourScheme == null || graph.heatmap.colourScheme == "") {
×
170
            return $scope.heatmapColourSchemeLabels.RdYlGn;
×
171
        }
172
        return $scope.heatmapColourSchemeLabels[graph.heatmap.colourScheme];
×
173
    }
174
    
175
    $scope.setCountFilterEnd = function(graph, end) {
14✔
176
        graph.dygraph.countFilter.end = end;
×
177
        $scope.saveAndRenderGraphsIfAutoUpdate();
×
178
    }
179
    
180
    $scope.setCountFilterMeasure = function(graph, measure) {
14✔
181
        graph.dygraph.countFilter.measure = measure;
×
182
        $scope.saveAndRenderGraphsIfAutoUpdate();
×
183
    }
184
    
185
    $scope.setValueFilterMeasure = function(graph, measure) {
14✔
186
        graph.dygraph.valueFilter.measure = measure;
×
187
        $scope.saveAndRenderGraphsIfAutoUpdate();
×
188
    }
189
    
190
    $scope.setHorizonSortMethod = function(graph, method) {
14✔
191
        graph.horizon.sortMethod = method;
×
192
        $scope.saveAndRenderGraphsIfAutoUpdate();
×
193
    }
194

195
    $scope.loadModel = function(datum, renderIfUpdatesExist) {
14✔
196
        
197
        // now load the model
198
        var model = $rootScope.model;
19✔
199
        var hash = $scope.hashModel(model.global, model.graphs);
19✔
200
        // prevent recursion
201
        if (hash == $scope.lastHash) {
19!
202
            //console.log("graph range 1: "+model.graphs[0].scatter.yRange);
203
            //console.log("Hash check fail - no change to apply");
204
            return;
×
205
        }
206
        $scope.lastHash = hash;
19✔
207

208
        // default state
209
        $scope.graphs = [];
19✔
210
        $scope.model.relativePeriod = "2h";
19✔
211
        $scope.model.absoluteTimeSpecification = false;
19✔
212
        $scope.model.autoReload = false;
19✔
213
        $scope.model.autoReloadPeriod = "15";
19✔
214
        $scope.model.fromDate = "";
19✔
215
        $scope.model.fromTime = "";
19✔
216
        $scope.model.toDate = "";
19✔
217
        $scope.model.toTime = "";
19✔
218
        $scope.model.autoGraphHeight = true;
19✔
219
        $scope.model.minGraphHeight = 0;
19✔
220
        $scope.model.graphHeight = 300;
19✔
221
        $scope.model.globalDownsampling = false;
19✔
222
        $scope.model.globalDownsampleTo = "5m";
19✔
223
        $scope.model.baselining = false;
19✔
224
        $scope.model.baselineDatumStyle = "relative";
19✔
225
        $scope.model.baselineRelativePeriod = "1d";
19✔
226
        $scope.model.baselineFromDate = "";
19✔
227
        $scope.model.baselineFromTime = "";
19✔
228
        $scope.model.baselineToDate = "";
19✔
229
        $scope.model.baselineToTime = "";
19✔
230
        
231
        if (model.graphs == null || model.graphs.length == 0) {
19✔
232
            model.graphs = [];
15✔
233
            $scope.addGraph();
15✔
234
        }
235
        else {
236
            $scope.graphs = deepUtils.deepClone(model.graphs);
4✔
237
    
238
            if (model.global != null) {
4!
239
                $scope.model = deepUtils.deepClone(model.global);
4✔
240
                var now = datum ? datum.clone() : moment.utc();
4✔
241
                var twoHoursAgo = now.subtract(2, "hours");
4✔
242
                if (model.global.absoluteTimeSpecification) {
4✔
243
                    if (model.global.fromDate == null || model.global.fromDate == "") {
1!
244
                        $scope.model.fromDate = twoHoursAgo.format("YYYY/MM/DD");
1✔
245
                    }
246
                    if (model.global.fromTime == null || model.global.fromTime == "") {
1!
247
                        $scope.model.fromTime = twoHoursAgo.format("HH:mm:ss");
1✔
248
                    }
249
                }
250
                else {
251
                    if (model.global.relativePeriod == null || model.global.relativePeriod == "") {
3!
252
                        $scope.model.relativePeriod = "2h";
×
253
                    }
254
                }
255
            }
256
        }
257
        $scope.saveAndRenderGraphsInternal(renderIfUpdatesExist);
19✔
258
    }
259

260
    $scope.addGraph = function() {
14✔
261
        var id = idGenerator.nextId();
26✔
262
        $scope.graphs.push({
26✔
263
            id: id,
264
            title: "Graph "+($scope.graphs.length+1),
265
            type: $rootScope.graphTypes.length == 1 ? $rootScope.graphTypes[0] : $rootScope.config ? $rootScope.config.defaultGraphType : null,
49!
266
            // gnuplot defaults
267
            gnuplot: {
268
                y1AxisRange: "[0:]",
269
                y2AxisRange: "[0:]",
270
                showKey: true,
271
                keyAlignment: "columnar",
272
                keyLocation: "top left",
273
                keyBox: true,
274
                style: "linespoint"
275
            },
276
            // horizon defaults
277
            horizon: {
278
                interpolateGaps: true,
279
                squashNegative: true
280
            },
281
            // dygraph defaults
282
            dygraph: {
283
                interpolateGaps: true,
284
                highlightLines: $rootScope.config ? $rootScope.config.ui.graphs.dygraph.highlightingDefault : true,
26!
285
                annotations: true,
286
                countFilter: {
287
                    end: "top",
288
                    count: "",
289
                    measure: "mean"
290
                },
291
                valueFilter: {
292
                    lowerBound: "",
293
                    measure: "any",
294
                    upperBound: ""
295
                }
296
            },
297
            // heatmap defaults
298
            heatmap: {
299
                style: 'auto',
300
                filterLowerBound: "",
301
                filterUpperBound: "",
302
                colourScheme: 'RdYlGn'
303
            },
304
            scatter: {
305
                xRange: "[:]",
306
                yRange: "[:]"
307
            }
308
        });
309
        $scope.showEdit[id] = true;
26✔
310
        for (var i=0; i<$scope.graphs.length; i++) {
26✔
311
            $scope.isOpen[$scope.graphs[i].id] = false;
41✔
312
        }
313
        $scope.isOpen[id] = true;
26✔
314
    };
315
    
316
    $scope.deleteGraph = function(id) {
14✔
317
        var index = -1;
5✔
318
        for (var i=0; i<$scope.graphs.length; i++) {
5✔
319
            if ($scope.graphs[i].id == id) {
9✔
320
                index = i;
4✔
321
                break;
4✔
322
            }
323
        }
324
        if (index == -1) {
5✔
325
            return;
1✔
326
        }
327
        $scope.graphs.splice(index, 1);
4✔
328
        $scope.isOpen[id] = false;
4✔
329
        if ($scope.graphs.length > 0) {
4✔
330
            var prevGraph = index == 0 ? 0 : index-1;
3✔
331
            $scope.isOpen[$scope.graphs[prevGraph].id] = true;
3✔
332
        }
333
    }
334
    $scope.saveAndRenderGraphsIfAutoUpdateWithChangeCheck = function() {
14✔
335
        if ($rootScope.autoUpdateEnabled()) {
×
336
            $scope.saveAndRenderGraphsInternal(true, true);
×
337
        }
338
    }
339
    $scope.saveAndRenderGraphsIfAutoUpdate = function() {
14✔
340
        if ($rootScope.autoUpdateEnabled()) {
×
341
            $scope.saveAndRenderGraphsInternal(true, false);
×
342
        }
343
    }
344
    // for button on ui
345
    $scope.saveAndRenderGraphs = function() {
14✔
346
        $scope.saveAndRenderGraphsInternal(true, false);
2✔
347
    }
348
    $scope.saveAndRenderGraphsInternal = function(forceRender, doChangeCheck) {
14✔
349
        // abort if no change
350
        if (doChangeCheck) {
21!
351
            var hash = $scope.hashModel($scope.model, $scope.graphs);
×
352
            if (hash == $scope.lastHash) {
×
353
                return;
×
354
            }
355
        }
356

357
        // now save for rendering
358
        $rootScope.model.graphs = deepUtils.deepClone($scope.graphs);
21✔
359
        $rootScope.model.global = deepUtils.deepClone($scope.model);
21✔
360
        $rootScope.saveModel(forceRender);
21✔
361
    }
362
    
363
    $scope.bindWatchExpressions();
14✔
364
}]);
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc