Skip to content
This repository has been archived by the owner on Aug 9, 2021. It is now read-only.

Commit

Permalink
fix(graph): do not display graph without data
Browse files Browse the repository at this point in the history
fix #203
  • Loading branch information
btry authored and ajsb85 committed Nov 22, 2017
1 parent fddb81b commit bee0099
Showing 1 changed file with 27 additions and 33 deletions.
60 changes: 27 additions & 33 deletions inc/graph.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,14 @@ public function showInvitationsGraph() {
$dbUtils = new DbUtils();

$pendingCount = $dbUtils->countElementsInTableForMyEntities(
PluginFlyvemdmInvitation::getTable(),
"`status` = 'pending'"
PluginFlyvemdmInvitation::getTable(),
"`status` = 'pending'"
);

$doneCount = $dbUtils->countElementsInTableForMyEntities(
PluginFlyvemdmInvitation::getTable(),
"`status` = 'done'"
);
PluginFlyvemdmInvitation::getTable(),
"`status` = 'done'"
);

if (($pendingCount + $doneCount) == 0) {
return '';
Expand All @@ -63,18 +63,18 @@ public function showInvitationsGraph() {
$out = $stat->displayPieGraph(
__('Invitations', 'flyvemdm'),
[
__('Done', 'flyvemdm'),
__('Pending', 'flyvemdm')
__('Done', 'flyvemdm'),
__('Pending', 'flyvemdm')
],
[
[
'name' => __('Done', 'flyvemdm'),
'data' => $doneCount,
],
[
'name' => __('Pending', 'flyvemdm'),
'data' => $pendingCount,
],
[
'name' => __('Done', 'flyvemdm'),
'data' => $doneCount,
],
[
'name' => __('Pending', 'flyvemdm'),
'data' => $pendingCount,
],
],
false
);
Expand Down Expand Up @@ -112,15 +112,13 @@ public function showDevicesPerOSVersion() {
WHERE `$computerTable`.`computertypes_id` = '$computerTypeId' $entityRestrict
GROUP BY `operatingsystem`, `version`";
$result = $DB->query($query);
if ($result) {
$labels = [];
if ($result && $DB->numrows($result) > 0) {
$osNames = [];
$versionNames = [];
$versionPerOS = [];
while ($row = $DB->fetch_assoc($result)) {
$osNames[$row['operatingsystem']] = $row['operatingsystem'];
$versionNames[$row['version']] = $row['version'];
$labels[] = $row['operatingsystem']; /*. ' ' . $row['version']*/
$versionPerOS[$row['version']][$row['operatingsystem']] = $row['cpt'];
}
foreach ($osNames as $osName) {
Expand All @@ -135,21 +133,19 @@ public function showDevicesPerOSVersion() {
foreach ($versionPerOS as $osName => $serie) {
ksort($serie);
$series[] = [
'name' => $osName,
'data' => array_values($serie),
'name' => $osName,
'data' => array_values($serie),
];
}
$stat = new Stat();
$out = $this->displayStackedBarGraph(
__('Devices per operating system version', 'flyvemdm'),
array_values($osNames),
$series,
[
'width' => '100%',
],
false
__('Devices per operating system version', 'flyvemdm'),
array_values($osNames),
$series,
[
'width' => '100%',
],
false
);

}

return $out;
Expand Down Expand Up @@ -185,7 +181,6 @@ public function displayStackedBarGraph($title, $labels, $series, $options = null
}
}

$stat = new Stat();
$slug = str_replace('-', '_', Toolbox::slugify($title));
$this->checkEmptyLabels($labels);
$out = "<h2 class='center'>$title</h2>";
Expand Down Expand Up @@ -243,7 +238,7 @@ public function displayStackedBarGraph($title, $labels, $series, $options = null
$out .= "});";

if ($param['animate'] === true) {
$out .= "
$out .= "
chart_$slug.on('draw', function(data) {
if(data.type === 'bar') {
data.element.animate({
Expand All @@ -259,7 +254,7 @@ public function displayStackedBarGraph($title, $labels, $series, $options = null
});
});";
}
$out .="</script>";
$out .= "</script>";

if ($display) {
echo $out;
Expand All @@ -282,5 +277,4 @@ private function checkEmptyLabels(&$labels) {
}
}
}

}

0 comments on commit bee0099

Please sign in to comment.