1 | <?php |
||
2 | |||
3 | use Amenadiel\JpGraph\Graph\Graph; |
||
4 | use Amenadiel\JpGraph\Plot\BarPlot; |
||
5 | use Amenadiel\JpGraph\Plot\GroupBarPlot; |
||
6 | use Amenadiel\JpGraph\Plot\LinePlot; |
||
7 | use LibreNMS\Util\Number; |
||
8 | |||
9 | $graph_data = getHistoricTransferGraphData($vars['id']); |
||
10 | |||
11 | // Reformat date labels |
||
12 | for ($i = 0; $i < count($graph_data['ticklabels']); $i++) { |
||
13 | if ($graph_data['ticklabels'][$i]) { |
||
14 | $parts = explode(' - ', $graph_data['ticklabels'][$i]); |
||
15 | $start = strtotime($parts[0]); |
||
16 | $end = strtotime($parts[1]); |
||
17 | |||
18 | if (date('m', $start) == date('m', $end) && date('d', $start == 1)) { |
||
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||
19 | // Calendar months, omit the date and the end! |
||
20 | $graph_data['ticklabels'][$i] = strftime('%b %Y', $start); |
||
21 | } else { |
||
22 | $graph_data['ticklabels'][$i] = strftime('%e %b %Y', $start) . "\n" . strftime('%e %b %Y', $end); |
||
23 | } |
||
24 | } |
||
25 | } |
||
26 | |||
27 | // Create the graph. These two calls are always required |
||
28 | $graph = new Graph($vars['width'], $vars['height'], $graph_data['graph_name']); |
||
29 | $graph->img->SetImgFormat('png'); |
||
30 | |||
31 | // work around bug in jpgraph error handling |
||
32 | $graph->title->Set(' '); |
||
33 | $graph->subtitle->Set(' '); |
||
34 | $graph->subsubtitle->Set(' '); |
||
35 | $graph->footer->left->Set(' '); |
||
36 | $graph->footer->center->Set(' '); |
||
37 | $graph->footer->right->Set(' '); |
||
38 | |||
39 | $graph->SetScale('textlin'); |
||
40 | // $graph->title->Set("$graph_name"); |
||
41 | $graph->title->SetFont(FF_FONT2, FS_BOLD, 10); |
||
42 | $graph->SetMarginColor('white'); |
||
43 | $graph->SetFrame(false); |
||
44 | $graph->SetMargin('75', '30', '30', '65'); |
||
45 | $graph->legend->SetFont(FF_FONT1, FS_NORMAL); |
||
46 | $graph->legend->SetLayout(LEGEND_HOR); |
||
47 | $graph->legend->Pos('0.52', '0.91', 'center'); |
||
48 | |||
49 | $graph->xaxis->SetFont(FF_FONT1, FS_BOLD); |
||
50 | $graph->xaxis->SetPos('min'); |
||
51 | $graph->xaxis->SetTitleMargin(30); |
||
52 | $graph->xaxis->title->Set(' '); |
||
53 | $graph->xaxis->SetTickLabels($graph_data['ticklabels']); |
||
54 | |||
55 | $graph->xgrid->Show(true, true); |
||
56 | $graph->xgrid->SetColor('#e0e0e0', '#efefef'); |
||
57 | |||
58 | function YCallback($value) |
||
59 | { |
||
60 | return Number::formatBase($value, \LibreNMS\Config::get('billing.base'), 2, 1); |
||
61 | } |
||
62 | |||
63 | $graph->yaxis->SetFont(FF_FONT1); |
||
64 | $graph->yaxis->SetTitleMargin(50); |
||
65 | $graph->yaxis->title->SetFont(FF_FONT1, FS_NORMAL, 10); |
||
66 | $graph->yaxis->title->Set('Bytes Transferred'); |
||
67 | $graph->yaxis->SetLabelFormatCallback('YCallback'); |
||
68 | |||
69 | $graph->ygrid->SetFill(true, '#[email protected]', '#[email protected]'); |
||
70 | |||
71 | // Create the bar plots |
||
72 | $barplot_tot = new BarPlot($graph_data['tot_data']); |
||
73 | $barplot_tot->SetLegend('Traffic total'); |
||
74 | $barplot_tot->SetColor('darkgray'); |
||
75 | $barplot_tot->SetFillColor('[email protected]'); |
||
76 | $barplot_tot->value->Show(); |
||
77 | $barplot_tot->value->SetFormatCallback('format_bytes_billing_short'); |
||
78 | |||
79 | $barplot_in = new BarPlot($graph_data['in_data']); |
||
80 | $barplot_in->SetLegend('Traffic In'); |
||
81 | $barplot_in->SetColor('darkgreen'); |
||
82 | $barplot_in->SetFillColor('[email protected]'); |
||
83 | $barplot_in->SetWeight(1); |
||
84 | |||
85 | $barplot_out = new BarPlot($graph_data['out_data']); |
||
86 | $barplot_out->SetLegend('Traffic Out'); |
||
87 | $barplot_out->SetColor('darkblue'); |
||
88 | $barplot_out->SetFillColor('[email protected]'); |
||
89 | $barplot_out->SetWeight(1); |
||
90 | |||
91 | $barplot_over = new BarPlot($graph_data['overuse_data']); |
||
92 | $barplot_over->SetLegend('Traffic Overusage'); |
||
93 | $barplot_over->SetColor('darkred'); |
||
94 | $barplot_over->SetFillColor('[email protected]'); |
||
95 | $barplot_over->SetWeight(1); |
||
96 | |||
97 | $lineplot_allow = new LinePlot($graph_data['allow_data']); |
||
98 | $lineplot_allow->SetLegend('Traffic Allowed'); |
||
99 | $lineplot_allow->SetColor('black'); |
||
100 | $lineplot_allow->SetWeight(1); |
||
101 | |||
102 | $gbplot = new GroupBarPlot([$barplot_in, $barplot_tot, $barplot_out, $barplot_over]); |
||
103 | |||
104 | $graph->Add($gbplot); |
||
105 | $graph->Add($lineplot_allow); |
||
106 | |||
107 | // Display the graph |
||
108 | $graph->Stroke(); |
||
109 |