Files
librenms-librenms/app/View/Components/GraphRow.php
T
Tony Murray c5b63bde86 New Blade Components: x-device-link, x-port-link, x-graph-row, x-popup (#13197)
* working popover

* popup component

* cleanup

* finalize device-link component

* attributes WIP

* working graph component

* widgets WIP

* More dynamic configs

* Graph row component

* Build CSS so we can use a dark theme

* graph row set columns

* only one popup visible at a time.

* Just set graph row width statically

* responsive WIP

* rsponsive option for graph-row "working"

* remove @deviceLink and @portLink

* fix non-responsive graph row

* update js/css

* fix style

* bad type?

* types

* types

* types #3

* remove testing code

* full rebel, no closing tags for meta and link

* match previous formatting

* fix vlans display

* restore newline

* remove silly comment

* remove unused line

* style I guess
2021-09-10 08:07:08 -05:00

97 lines
2.2 KiB
PHP

<?php
namespace App\View\Components;
use Illuminate\View\Component;
class GraphRow extends Component
{
/**
* @var string
*/
public $type;
/**
* @var string
*/
public $loading;
/**
* @var null
*/
public $device;
/**
* @var null
*/
public $port;
/**
* @var array|string[][]
*/
public $graphs;
/**
* @var string|null
*/
public $title;
/**
* @var float|int
*/
public $rowWidth;
/**
* @var bool
*/
public $responsive;
/**
* @var string
*/
public $aspect;
/**
* Create a new component instance.
*
* @param string $type
* @param string|null $title
* @param string $loading
* @param string $aspect
* @param int $columns
* @param array $graphs
* @param \App\Models\Device|int|null $device
* @param \App\Models\Port|int|null $port
*/
public function __construct(string $type = '', string $title = null, string $loading = 'eager', string $aspect = 'normal', int $columns = 2, array $graphs = [['from' => '-1d'], ['from' => '-7d'], ['from' => '-30d'], ['from' => '-1y']], $device = null, $port = null)
{
$this->type = $type;
$this->aspect = $aspect;
$this->loading = $loading;
$this->device = $device;
$this->port = $port;
$this->graphs = $graphs;
$this->title = $title;
$this->responsive = $columns == 'responsive';
$this->rowWidth = $this->calculateRowWidth($columns);
}
/**
* Get the view / contents that represent the component.
*
* @return \Illuminate\Contracts\View\View|\Closure|string
*/
public function render()
{
return view('components.graph-row');
}
private function calculateRowWidth(int $columns): ?int
{
if ($this->responsive) {
return null;
}
$max = max(array_column($this->graphs, 'width') + [0]);
if (! $max) {
$max = $this->aspect == 'wide' ? Graph::DEFAULT_WIDE_WIDTH : Graph::DEFAULT_NORMAL_WIDTH;
}
// width * columns, unless there is less graphs than columns
return $max * min($columns, count($this->graphs));
}
}