forked from librenms/librenms
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
1,105 additions
and
76 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
<?php | ||
|
||
namespace LibreNMS\Data; | ||
|
||
class ChartData | ||
{ | ||
|
||
protected function __construct( | ||
protected string $format, | ||
protected array $data, | ||
protected array $map = [], | ||
) {} | ||
|
||
public static function createFromRrd(array $legend, array $data): static | ||
{ | ||
$map = ['_timestamp' => 0]; | ||
// RRD legend is shifted by one when timestamp is included | ||
foreach ($legend as $index => $name) { | ||
$map[$name] = $index + 1; | ||
} | ||
|
||
return new static('grouped_by_point', $data, $map); | ||
} | ||
|
||
/** | ||
* @param ChartDataset[] $chartDatasets | ||
* @return array | ||
*/ | ||
public function forChartJs(array $chartDatasets): array | ||
{ | ||
$data = []; | ||
|
||
if ($this->format == 'grouped_by_point') { | ||
$timestamp_index = $this->map['_timestamp']; | ||
$ds = array_diff_key($this->map, ['_timestamp' => null]); | ||
|
||
foreach($this->data as $point) { | ||
foreach($ds as $name => $index) { | ||
$data[$name][] = ['x' => (int) $point[$timestamp_index], 'y' => $point[$index]]; | ||
} | ||
} | ||
} | ||
|
||
$datasets = []; | ||
foreach($chartDatasets as $ds) { | ||
$datasets[] = [ | ||
'label' => $ds->label, | ||
'data' => $data[$ds->name], | ||
'fill' => true, | ||
'borderColor' => $ds->color, | ||
'backgroundColor' => $ds->fill, | ||
]; | ||
} | ||
|
||
return [ | ||
'datasets' => $datasets, | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<?php | ||
|
||
namespace LibreNMS\Data; | ||
|
||
class ChartDataset | ||
{ | ||
public function __construct( | ||
public string $name, | ||
public string $label, | ||
public ?string $color = null, | ||
public ?string $fill = null, | ||
){} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<?php | ||
|
||
namespace LibreNMS\Enum; | ||
|
||
enum RrdCF | ||
{ | ||
case AVERAGE; | ||
case MIN; | ||
case MAX; | ||
case LAST; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
<?php | ||
|
||
namespace App\Filament\Widgets; | ||
|
||
use Leandrocfe\FilamentApexCharts\Widgets\ApexChartWidget; | ||
|
||
class NetworkChart extends ApexChartWidget | ||
{ | ||
/** | ||
* Chart Id | ||
* | ||
* @var string | ||
*/ | ||
protected static ?string $chartId = 'networkChart'; | ||
|
||
/** | ||
* Widget Title | ||
* | ||
* @var string|null | ||
*/ | ||
protected static ?string $heading = 'NetworkChart'; | ||
|
||
|
||
|
||
/** | ||
* Chart options (series, labels, types, size, animations...) | ||
* https://apexcharts.com/docs/options | ||
* | ||
* @return array | ||
*/ | ||
protected function getOptions(): array | ||
{ | ||
return [ | ||
'chart' => [ | ||
'type' => 'area', | ||
'height' => 300, | ||
], | ||
'series' => [ | ||
[ | ||
'name' => 'NetworkChart', | ||
'data' => [7, 4, 6, 10, 14, 7, 5, 9, 10, 15, 13, 18], | ||
], | ||
], | ||
'xaxis' => [ | ||
'categories' => ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'], | ||
'labels' => [ | ||
'style' => [ | ||
'fontFamily' => 'inherit', | ||
], | ||
], | ||
], | ||
'yaxis' => [ | ||
'labels' => [ | ||
'style' => [ | ||
'fontFamily' => 'inherit', | ||
], | ||
], | ||
], | ||
'colors' => ['#f59e0b'], | ||
'stroke' => [ | ||
'curve' => 'smooth', | ||
], | ||
'dataLabels' => [ | ||
'enabled' => false, | ||
], | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.