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); $this->link = $link; // 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() { if ($this->link === false) { return view('components.graph', [ 'src' => $this->getSrc(), ]); } return view('components.linked-graph', [ 'link' => $this->getLink(), 'src' => $this->getSrc(), ]); } private function getSrc(): string { return 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, ]); } private function getLink(): string { if ($this->link === true) { $url = url('graphs') . '/' . http_build_query($this->vars + [ 'type' => $this->type, 'from' => $this->from, 'to' => $this->to, ], '', '/'); return $url; } if ($this->link === false) { return ''; } return $this->link; } }