Browse Source

Use new chart js version

Kai Kretschmann 5 months ago
parent
commit
70926eeb34
3 changed files with 135 additions and 114 deletions
  1. 5
    4
      inc/config_class.php
  2. 110
    106
      js/lggr_stat_data.php
  3. 20
    4
      js/lggr_stats.js

+ 5
- 4
inc/config_class.php View File

@@ -3,9 +3,10 @@
3 3
 class Config extends AbstractConfig {
4 4
 
5 5
     function __construct() {
6
-        $this->setDbUser('lggr');
7
-        $this->setDbPwd('lggr');
8
-        $this->setDbName('lggr');
6
+                $this->setDbUser('logviewer');
7
+                $this->setDbPwd('rl');
8
+                $this->setDbName('logger');
9
+
9 10
         
10 11
         // Set your preferred language en_US, de_DE, or pt_BR
11 12
         $this->setLocale('en_US');
@@ -16,7 +17,7 @@ class Config extends AbstractConfig {
16 17
         $this->setUrlJqueryui('//code.jquery.com/ui/1.11.4/');
17 18
         $this->setUrlJAtimepicker(
18 19
             '//cdnjs.cloudflare.com/ajax/libs/jquery-ui-timepicker-addon/1.4.5/');
19
-        $this->setUrlChartjs('//cdnjs.cloudflare.com/ajax/libs/Chart.js/1.0.2/');
20
+        $this->setUrlChartjs('//cdnjs.cloudflare.com/ajax/libs/Chart.js/2.7.2/');
20 21
         $this->setUrlJQCloud('//cdnjs.cloudflare.com/ajax/libs/jqcloud/1.0.4/');
21 22
         
22 23
         /* local storage */

+ 110
- 106
js/lggr_stat_data.php View File

@@ -1,61 +1,61 @@
1
-<?php
2
-header('Content-Type: text/javascript');
3
-
4
-spl_autoload_register(
5
-    function ($class) {
6
-        include '../inc/' . strtolower($class) . '_class.php';
7
-    });
8
-
9
-$searchvalue = '';
10
-
11
-session_start();
12
-
13
-define('COLORALERT', 'd9534f');
14
-
15
-if (isset($_SESSION[LggrState::SESSIONNAME])) {
16
-    $state = $_SESSION[LggrState::SESSIONNAME];
17
-} else {
18
-    $state = new LggrState();
19
-} // if
20
-
21
-$aColors = array(
22
-    'emerg' => COLORALERT,
23
-    'crit' => COLORALERT,
24
-    'err' => COLORALERT,
25
-    'warning' => '#f0ad4e',
26
-    'notice' => '#337ab7',
27
-    'info' => '#5cb85c'
28
-);
29
-
30
-$l = null;
31
-try {
32
-    $config = new Config();
33
-    $l = new Lggr($state, $config);
34
-    
35
-    $aLevels = $l->getLevels();
36
-    $aServers = $l->getServers();
37
-    
38
-    $aStatistic = $l->getStatistic();
39
-    $aStatistic = $aStatistic[0];
40
-    
41
-    $aMsgPerHour = $l->getMessagesPerHour();
42
-    
43
-    $aCloud = $l->getCloud();
44
-}
45
-catch (LggrException $e) {
46
-    
47
-    exit();
48
-}
49
-
50
-?>
51
-
52
-<!-- dynamic data -->
53
-
54
-<?php
55
-$aTmp = array();
56
-foreach ($aMsgPerHour as $hour) {
57
-    $aTmp[$hour->h] = $hour->c;
58
-} // foreach
1
+<?php
2
+header('Content-Type: text/javascript');
3
+
4
+spl_autoload_register(
5
+    function ($class) {
6
+        include '../inc/' . strtolower($class) . '_class.php';
7
+    });
8
+
9
+$searchvalue = '';
10
+
11
+session_start();
12
+
13
+define('COLORALERT', 'd9534f');
14
+
15
+if (isset($_SESSION[LggrState::SESSIONNAME])) {
16
+    $state = $_SESSION[LggrState::SESSIONNAME];
17
+} else {
18
+    $state = new LggrState();
19
+} // if
20
+
21
+$aColors = array(
22
+    'emerg' => COLORALERT,
23
+    'crit' => COLORALERT,
24
+    'err' => COLORALERT,
25
+    'warning' => '#f0ad4e',
26
+    'notice' => '#337ab7',
27
+    'info' => '#5cb85c'
28
+);
29
+
30
+$l = null;
31
+try {
32
+    $config = new Config();
33
+    $l = new Lggr($state, $config);
34
+    
35
+    $aLevels = $l->getLevels();
36
+    $aServers = $l->getServers();
37
+    
38
+    $aStatistic = $l->getStatistic();
39
+    $aStatistic = $aStatistic[0];
40
+    
41
+    $aMsgPerHour = $l->getMessagesPerHour();
42
+    
43
+    $aCloud = $l->getCloud();
44
+}
45
+catch (LggrException $e) {
46
+    
47
+    exit();
48
+}
49
+
50
+?>
51
+
52
+<!-- dynamic data -->
53
+
54
+<?php
55
+$aTmp = array();
56
+foreach ($aMsgPerHour as $hour) {
57
+    $aTmp[$hour->h] = $hour->c;
58
+} // foreach
59 59
 ?>
60 60
 var dataMsgsPerHour = {
61 61
 	labels: ["<?= implode('","', array_keys($aTmp)) ?>"],
@@ -66,11 +66,11 @@ var dataMsgsPerHour = {
66 66
 	} ]
67 67
 };
68 68
 
69
-<?php
70
-$aTmp = array();
71
-foreach ($aServers as $server) {
72
-    $aTmp[$server->host] = $server->c;
73
-} // foreach
69
+<?php
70
+$aTmp = array();
71
+foreach ($aServers as $server) {
72
+    $aTmp[$server->host] = $server->c;
73
+} // foreach
74 74
 ?>
75 75
 var dataServers = {
76 76
 	labels: ["<?= implode('","', array_keys($aTmp)) ?>"],
@@ -81,59 +81,63 @@ var dataServers = {
81 81
 	} ]
82 82
 };
83 83
 
84
-var dataLevels = [
85
-<?php
86
-foreach ($aLevels as $level) {
87
-    $newVal = round(log($level->c));
88
-    $newCol = $aColors[$level->level];
89
-    echo <<<EOL
90
-    {
91
-        value: $newVal,
92
-        color: "$newCol",
93
-        label: "{$level->level}",
94
-    },
95
-
96
-EOL;
97
-} // foreach
84
+var dataLevels = {
85
+    datasets: [{
86
+        data: [
87
+<?php
88
+foreach ($aLevels as $level) {
89
+    $newVal = round(log($level->c));
90
+    // $newCol = $aColors[$level->level];
91
+    echo "{$newVal}, ";
92
+} // foreach
98 93
 ?>
99
-];
94
+        ]
95
+    }],
96
+    labels: [
97
+<?php
98
+foreach ($aLevels as $level) {
99
+    echo "'{$level->level}', ";
100
+} // foreach
101
+?>
102
+    ]
103
+};
100 104
 
101
-var dataServersPie = [
102
-<?php
103
-foreach ($aServers as $server) {
104
-    $sHash = md5($server->host);
105
-    $cHash = $sHash[0] . '0' . $sHash[1] . '0' . $sHash[2] . '0';
106
-    $cHashHigh = $sHash[0] . 'f' . $sHash[1] . 'f' . $sHash[2] . 'f';
107
-    echo <<<EOL
108
-    {
109
-        value: {$server->c},
110
-        color: "#$cHash",
111
-        highlight: "#$cHashHigh",
112
-        label: "{$server->host}"
113
-    },
114
-
115
-EOL;
116
-} // foreach
105
+var dataServersPie = {
106
+    datasets: [{
107
+        data: [
108
+<?php
109
+foreach ($aServers as $server) {
110
+    echo $server->c . ",";
111
+} // foreach
117 112
 ?>
118
-];
113
+        ]
114
+    }],
115
+    labels: [
116
+<?php
117
+foreach ($aServers as $server) {
118
+    echo "'{$server->host}',";
119
+}
120
+?>
121
+    ]
122
+};
119 123
 
120 124
 
121 125
 var dataCloudWords = [
122
-<?php
123
-foreach ($aCloud as $entry) {
124
-    $prog = $entry->program;
125
-    if (false !== strpos($prog, '&')) {
126
-        continue;
127
-    }
128
-    $prog = htmlspecialchars($prog, ENT_QUOTES | ENT_HTML5, 'UTF-8', false);
126
+<?php
127
+foreach ($aCloud as $entry) {
128
+    $prog = $entry->program;
129
+    if (false !== strpos($prog, '&')) {
130
+        continue;
131
+    }
132
+    $prog = htmlspecialchars($prog, ENT_QUOTES | ENT_HTML5, 'UTF-8', false);
129 133
     echo <<<EOL
130 134
         {
131 135
             text: "{$prog}",
132
-            weight: {$entry->c}
136
+            weight: {$entry->c}
133 137
         },
134 138
 
135
-EOL;
136
-} // foreach
137
-
139
+EOL;
140
+} // foreach
141
+
138 142
 ?>
139 143
 ];

+ 20
- 4
js/lggr_stats.js View File

@@ -9,16 +9,32 @@ var options = {
9 9
 
10 10
 
11 11
 var ctx = $("#chartMsgsPerHour").get(0).getContext("2d");
12
-new Chart(ctx).Bar(dataMsgsPerHour, options);
12
+new Chart(ctx, {
13
+	type: 'bar',
14
+	data: dataMsgsPerHour,
15
+	options: options
16
+});
13 17
 
14 18
 ctx = $("#chartServers").get(0).getContext("2d");
15
-new Chart(ctx).Bar(dataServers, options);
19
+new Chart(ctx, {
20
+	type: 'bar',
21
+	data: dataServers,
22
+	options: options
23
+});
16 24
 
17 25
 ctx = $("#chartLevels").get(0).getContext("2d");
18
-new Chart(ctx).PolarArea(dataLevels, {animateRotate: true, showScale: false});
26
+new Chart(ctx, {
27
+	type: 'polarArea',
28
+	data: dataLevels
29
+});
19 30
 
20 31
 ctx = $("#chartServersPie").get(0).getContext("2d");
21
-new Chart(ctx).Doughnut(dataServersPie, options);
32
+new Chart(ctx, {
33
+	type: 'doughnut',
34
+	data: dataServersPie,
35
+	options: options
36
+});
37
+
22 38
 
23 39
 $('#cloudcontainer').jQCloud(dataCloudWords, {
24 40
 	autoResize: true

Loading…
Cancel
Save
Social stuff:
Mastodon