data = $data; return $this; } /** * Get field data. * * @param \Laravel\Nova\Http\Requests\NovaRequest $request * @return array|mixed */ public function getData(NovaRequest $request) { if ($this->data instanceof Trend) { $ranges = $this->data->ranges(); $defaultRange = array_key_first($ranges); return array_values( $this->data->calculate( $request->merge([ 'range' => $defaultRange, 'resourceId' => $this->data->component, ]) )->trend ?? [] ); } elseif ($this->data instanceof Closure) { return call_user_func($this->data, $request); } return $this->data; } /** * Format the sparkline as a bar. * * @return $this */ public function asBarChart() { $this->chartStyle = 'Bar'; return $this; } /** * Set the component height. * * @param int $height * @return $this */ public function height($height) { return $this->withMeta([ __FUNCTION__ => $height, ]); } /** * Set the component width. * * @param int $width * @return $this */ public function width($width) { return $this->withMeta([ __FUNCTION__ => $width, ]); } /** * Prepare the element for JSON serialization. * * @return array */ public function jsonSerialize(): array { return array_merge(parent::jsonSerialize(), [ 'chartStyle' => $this->chartStyle, 'data' => $this->getData(app(NovaRequest::class)), ]); } }