Add status code text to webui bar chart tooltip

This commit is contained in:
Mattias Wadman 2018-01-25 16:54:03 +01:00 committed by Traefiker
parent b50aebd2ed
commit fa1f4f761d
3 changed files with 22 additions and 2 deletions

View file

@ -21,6 +21,7 @@
"angular-ui-router": "^0.3.1", "angular-ui-router": "^0.3.1",
"animate.css": "^3.4.0", "animate.css": "^3.4.0",
"bootstrap": "^3.3.6", "bootstrap": "^3.3.6",
"http-status-codes": "^1.3.0",
"moment": "^2.14.1", "moment": "^2.14.1",
"nvd3": "^1.8.4" "nvd3": "^1.8.4"
}, },

View file

@ -1,6 +1,7 @@
'use strict'; 'use strict';
var d3 = require('d3'), var d3 = require('d3'),
moment = require('moment'); moment = require('moment'),
HttpStatus = require('http-status-codes');
/** @ngInject */ /** @ngInject */
function HealthController($scope, $interval, $log, Health) { function HealthController($scope, $interval, $log, Health) {
@ -15,6 +16,12 @@ function HealthController($scope, $interval, $log, Health) {
vm.graph.totalStatusCodeCount.options = { vm.graph.totalStatusCodeCount.options = {
"chart": { "chart": {
type: 'discreteBarChart', type: 'discreteBarChart',
tooltip: {
contentGenerator: function (e) {
var d = e.data;
return d.label + " " + d.text;
}
},
height: 200, height: 200,
margin: { margin: {
top: 20, top: 20,
@ -69,9 +76,17 @@ function HealthController($scope, $interval, $log, Health) {
vm.graph.totalStatusCodeCount.data[0].values = []; vm.graph.totalStatusCodeCount.data[0].values = [];
for (var code in totalStatusCodeCount) { for (var code in totalStatusCodeCount) {
if (totalStatusCodeCount.hasOwnProperty(code)) { if (totalStatusCodeCount.hasOwnProperty(code)) {
var statusCodeText = "";
try {
statusCodeText = HttpStatus.getStatusText(code);
} catch (e) {
// HttpStatus.getStatusText throws error on unknown codes
statusCodeText = "Unknown status code";
}
vm.graph.totalStatusCodeCount.data[0].values.push({ vm.graph.totalStatusCodeCount.data[0].values.push({
label: code, label: code,
value: totalStatusCodeCount[code] value: totalStatusCodeCount[code],
text: statusCodeText
}); });
} }
} }

View file

@ -3073,6 +3073,10 @@ http-signature@~1.1.0:
jsprim "^1.2.2" jsprim "^1.2.2"
sshpk "^1.7.0" sshpk "^1.7.0"
http-status-codes@^1.3.0:
version "1.3.0"
resolved "https://registry.yarnpkg.com/http-status-codes/-/http-status-codes-1.3.0.tgz#9cd0e71391773d0671b489d41cbc5094aa4163b6"
https-browserify@0.0.1: https-browserify@0.0.1:
version "0.0.1" version "0.0.1"
resolved "https://registry.yarnpkg.com/https-browserify/-/https-browserify-0.0.1.tgz#3f91365cabe60b77ed0ebba24b454e3e09d95a82" resolved "https://registry.yarnpkg.com/https-browserify/-/https-browserify-0.0.1.tgz#3f91365cabe60b77ed0ebba24b454e3e09d95a82"