Browse Source

Use new chart js version

master
Kai Kretschmann 1 year 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 @@
class Config extends AbstractConfig {
function __construct() {
$this->setDbUser('lggr');
$this->setDbPwd('lggr');
$this->setDbName('lggr');
$this->setDbUser('logviewer');
$this->setDbPwd('rl');
$this->setDbName('logger');

// Set your preferred language en_US, de_DE, or pt_BR
$this->setLocale('en_US');
@@ -16,7 +17,7 @@ class Config extends AbstractConfig {
$this->setUrlJqueryui('//code.jquery.com/ui/1.11.4/');
$this->setUrlJAtimepicker(
'//cdnjs.cloudflare.com/ajax/libs/jquery-ui-timepicker-addon/1.4.5/');
$this->setUrlChartjs('//cdnjs.cloudflare.com/ajax/libs/Chart.js/1.0.2/');
$this->setUrlChartjs('//cdnjs.cloudflare.com/ajax/libs/Chart.js/2.7.2/');
$this->setUrlJQCloud('//cdnjs.cloudflare.com/ajax/libs/jqcloud/1.0.4/');
/* local storage */

+ 110
- 106
js/lggr_stat_data.php View File

@@ -1,61 +1,61 @@
<?php
header('Content-Type: text/javascript');
spl_autoload_register(
function ($class) {
include '../inc/' . strtolower($class) . '_class.php';
});
$searchvalue = '';
session_start();
define('COLORALERT', 'd9534f');
if (isset($_SESSION[LggrState::SESSIONNAME])) {
$state = $_SESSION[LggrState::SESSIONNAME];
} else {
$state = new LggrState();
} // if
$aColors = array(
'emerg' => COLORALERT,
'crit' => COLORALERT,
'err' => COLORALERT,
'warning' => '#f0ad4e',
'notice' => '#337ab7',
'info' => '#5cb85c'
);
$l = null;
try {
$config = new Config();
$l = new Lggr($state, $config);
$aLevels = $l->getLevels();
$aServers = $l->getServers();
$aStatistic = $l->getStatistic();
$aStatistic = $aStatistic[0];
$aMsgPerHour = $l->getMessagesPerHour();
$aCloud = $l->getCloud();
}
catch (LggrException $e) {
exit();
}
?>
<!-- dynamic data -->
<?php
$aTmp = array();
foreach ($aMsgPerHour as $hour) {
$aTmp[$hour->h] = $hour->c;
} // foreach
<?php
header('Content-Type: text/javascript');
spl_autoload_register(
function ($class) {
include '../inc/' . strtolower($class) . '_class.php';
});
$searchvalue = '';
session_start();
define('COLORALERT', 'd9534f');
if (isset($_SESSION[LggrState::SESSIONNAME])) {
$state = $_SESSION[LggrState::SESSIONNAME];
} else {
$state = new LggrState();
} // if
$aColors = array(
'emerg' => COLORALERT,
'crit' => COLORALERT,
'err' => COLORALERT,
'warning' => '#f0ad4e',
'notice' => '#337ab7',
'info' => '#5cb85c'
);
$l = null;
try {
$config = new Config();
$l = new Lggr($state, $config);
$aLevels = $l->getLevels();
$aServers = $l->getServers();
$aStatistic = $l->getStatistic();
$aStatistic = $aStatistic[0];
$aMsgPerHour = $l->getMessagesPerHour();
$aCloud = $l->getCloud();
}
catch (LggrException $e) {
exit();
}
?>
<!-- dynamic data -->
<?php
$aTmp = array();
foreach ($aMsgPerHour as $hour) {
$aTmp[$hour->h] = $hour->c;
} // foreach
?>
var dataMsgsPerHour = {
labels: ["<?= implode('","', array_keys($aTmp)) ?>"],
@@ -66,11 +66,11 @@ var dataMsgsPerHour = {
} ]
};

<?php
$aTmp = array();
foreach ($aServers as $server) {
$aTmp[$server->host] = $server->c;
} // foreach
<?php
$aTmp = array();
foreach ($aServers as $server) {
$aTmp[$server->host] = $server->c;
} // foreach
?>
var dataServers = {
labels: ["<?= implode('","', array_keys($aTmp)) ?>"],
@@ -81,59 +81,63 @@ var dataServers = {
} ]
};

var dataLevels = [
<?php
foreach ($aLevels as $level) {
$newVal = round(log($level->c));
$newCol = $aColors[$level->level];
echo <<<EOL
{
value: $newVal,
color: "$newCol",
label: "{$level->level}",
},

EOL;
} // foreach
var dataLevels = {
datasets: [{
data: [
<?php
foreach ($aLevels as $level) {
$newVal = round(log($level->c));
// $newCol = $aColors[$level->level];
echo "{$newVal}, ";
} // foreach
?>
];
]
}],
labels: [
<?php
foreach ($aLevels as $level) {
echo "'{$level->level}', ";
} // foreach
?>
]
};

var dataServersPie = [
<?php
foreach ($aServers as $server) {
$sHash = md5($server->host);
$cHash = $sHash[0] . '0' . $sHash[1] . '0' . $sHash[2] . '0';
$cHashHigh = $sHash[0] . 'f' . $sHash[1] . 'f' . $sHash[2] . 'f';
echo <<<EOL
{
value: {$server->c},
color: "#$cHash",
highlight: "#$cHashHigh",
label: "{$server->host}"
},

EOL;
} // foreach
var dataServersPie = {
datasets: [{
data: [
<?php
foreach ($aServers as $server) {
echo $server->c . ",";
} // foreach
?>
];
]
}],
labels: [
<?php
foreach ($aServers as $server) {
echo "'{$server->host}',";
}
?>
]
};


var dataCloudWords = [
<?php
foreach ($aCloud as $entry) {
$prog = $entry->program;
if (false !== strpos($prog, '&')) {
continue;
}
$prog = htmlspecialchars($prog, ENT_QUOTES | ENT_HTML5, 'UTF-8', false);
<?php
foreach ($aCloud as $entry) {
$prog = $entry->program;
if (false !== strpos($prog, '&')) {
continue;
}
$prog = htmlspecialchars($prog, ENT_QUOTES | ENT_HTML5, 'UTF-8', false);
echo <<<EOL
{
text: "{$prog}",
weight: {$entry->c}
weight: {$entry->c}
},

EOL;
} // foreach
EOL;
} // foreach
?>
];

+ 20
- 4
js/lggr_stats.js View File

@@ -9,16 +9,32 @@ var options = {


var ctx = $("#chartMsgsPerHour").get(0).getContext("2d");
new Chart(ctx).Bar(dataMsgsPerHour, options);
new Chart(ctx, {
type: 'bar',
data: dataMsgsPerHour,
options: options
});

ctx = $("#chartServers").get(0).getContext("2d");
new Chart(ctx).Bar(dataServers, options);
new Chart(ctx, {
type: 'bar',
data: dataServers,
options: options
});

ctx = $("#chartLevels").get(0).getContext("2d");
new Chart(ctx).PolarArea(dataLevels, {animateRotate: true, showScale: false});
new Chart(ctx, {
type: 'polarArea',
data: dataLevels
});

ctx = $("#chartServersPie").get(0).getContext("2d");
new Chart(ctx).Doughnut(dataServersPie, options);
new Chart(ctx, {
type: 'doughnut',
data: dataServersPie,
options: options
});


$('#cloudcontainer').jQCloud(dataCloudWords, {
autoResize: true

Loading…
Cancel
Save
Social stuff:
Mastodon