Skip to content

Commit

Permalink
optionsRaw() is a "json-like string" rather than a perfect json blob.…
Browse files Browse the repository at this point in the history
… So the decoding (if any) is better managed in the Builder rather than in the blade files.
  • Loading branch information
Peter Thomson committed Jul 31, 2024
1 parent f20bde9 commit e0776ad
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 6 deletions.
5 changes: 1 addition & 4 deletions src/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -168,10 +168,7 @@ public function render()
$inLivewire = $chart['inLivewire'] ?? (class_exists('Livewire\\Livewire') ? \Livewire\Livewire::isLivewireRequest() : false);
$view = ($inLivewire ? 'laravelchartjs::chart-template-livewire' : 'laravelchartjs::chart-template');

$optionsRaw = $chart['optionsRaw'] ?? null;
$optionsSimple = $chart['options'] ? $chart['options'] : null;
$options = $optionsRaw ? $optionsRaw : $optionsSimple;
$options = (is_string($options) ? json_decode($options) : $options);
$options = $chart['optionsRaw'] ?? json_encode($chart['options']);

return view($view)->with([
'datasets' => json_encode($chart['datasets']),
Expand Down
2 changes: 1 addition & 1 deletion src/resources/views/chart-template-livewire.blade.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<div>
<div
x-data="chart(@js($this->{$model}), @js($options))"
x-data="chart(@js($this->{$model}), {!! $options !!})"
wire:loading.class="opacity-50"
>
<canvas width="@js($size['width'])" height="@js($size['height'])" wire:ignore></canvas>
Expand Down
2 changes: 1 addition & 1 deletion src/resources/views/chart-template.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@
labels: {!! $labels !!},
datasets: {!! $datasets !!}
},
options: @js($options)
options: {!! $options !!}
});
})();
});
Expand Down

0 comments on commit e0776ad

Please sign in to comment.