Files
librenms-librenms/app/View/Components/Graph.php
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

107 lines
2.9 KiB
PHP

<?php
namespace App\View\Components;
use App\Models\Device;
use App\Models\Port;
use Illuminate\View\Component;
class Graph extends Component
{
const DEFAULT_WIDE_WIDTH = 340;
const DEFAULT_WIDE_HEIGHT = 100;
const DEFAULT_NORMAL_WIDTH = 300;
const DEFAULT_NORMAL_HEIGHT = 150;
/**
* @var array
*/
public $vars;
/**
* @var int|null
*/
public $width;
/**
* @var int|null
*/
public $height;
/**
* @var string
*/
public $type;
/**
* @var int|string|null
*/
public $from;
/**
* @var int|string|null
*/
public $to;
/**
* @var string
*/
public $legend;
/**
* @var int
*/
public $absolute_size;
/**
* Create a new component instance.
*
* @param string $type
* @param array $vars
* @param int|string $from
* @param int|string $to
* @param string $legend
* @param string $aspect
* @param int|null $width
* @param int|null $height
* @param int $absolute_size
* @param \App\Models\Device|int|null $device
* @param \App\Models\Port|int|null $port
*/
public function __construct(string $type = '', array $vars = [], $from = '-1d', $to = null, string $legend = 'no', string $aspect = 'normal', ?int $width = null, ?int $height = null, int $absolute_size = 0, $device = null, $port = null)
{
$this->type = $type;
$this->vars = $vars;
$this->from = $from;
$this->to = $to;
$this->legend = $legend;
$this->absolute_size = $absolute_size;
$this->width = $width ?: ($aspect == 'wide' ? self::DEFAULT_WIDE_WIDTH : self::DEFAULT_NORMAL_WIDTH);
$this->height = $height ?: ($aspect == 'wide' ? self::DEFAULT_WIDE_HEIGHT : self::DEFAULT_NORMAL_HEIGHT);
// handle device and port ids/models for convenience could be set in $vars
if ($device instanceof Device) {
$this->vars['device'] = $device->device_id;
} elseif (is_numeric($device)) {
$this->vars['device'] = $device;
} elseif ($port instanceof Port) {
$this->vars['id'] = $port->port_id;
} elseif (is_numeric($port)) {
$this->vars['id'] = $port;
}
}
/**
* Get the view / contents that represent the component.
*
* @return \Illuminate\Contracts\View\View|\Closure|string
*/
public function render()
{
return view('components.graph', [
'link' => url('graph.php') . '?' . http_build_query($this->vars + [
'type' => $this->type,
'legend' => $this->legend,
'absolute_size' => $this->absolute_size,
'width' => $this->width,
'height' => $this->height,
'from' => $this->from,
'to' => $this->to,
]),
]);
}
}