Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix chart width and height #3

Merged
merged 1 commit into from
Feb 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions docs/getting-started/installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,9 @@ Model::where('child_id',$this->record->id)

```php
\LaraZeus\InlineChart\Tables\Columns\InlineChart::make('last activities')
->chart(MiniChart::class)
->maxWidth('!w-[150px]')
->description('description')
->toggleable(),
->chart(MiniChart::class)
->maxWidth(350)// int, default 200
->maxHeight(90)// int, default 50
->description('description')
->toggleable(),
```
11 changes: 9 additions & 2 deletions resources/views/tables/columns/inline-chart.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
@php
$getState = $getState();
$getMaxWidth = $getMaxWidth();
$getMaxHeight = $getMaxHeight();
$getIcon = $getIcon($getState);
$descriptionAbove = $getDescriptionAbove();
$descriptionBelow = $getDescriptionBelow();
Expand All @@ -21,8 +22,14 @@
</p>
@endif

<div wire:ignore>
@livewire($getChart, ['maxWidth' => $getMaxWidth, 'lazy' => true, 'record' => $getRecord], key("chart-{$getRecord->id}"))
<div
wire:ignore
style="
width: {{ $getMaxWidth }}px !important;
height: {{ $getMaxHeight }}px !important;
"
>
@livewire($getChart, ['maxWidth' => $getMaxWidth, 'maxHeight' => $getMaxHeight, 'lazy' => true, 'record' => $getRecord], key("chart-{$getRecord->id}"))
</div>

@if (filled($descriptionBelow))
Expand Down
13 changes: 5 additions & 8 deletions resources/views/widgets/inline-chart.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,10 @@ class="px-2"
>
<canvas
x-ref="canvas"
@if ($maxHeight = $this->getMaxHeight())
style="width: {{ $maxWidth }}!important; height: {{ $maxHeight }}!important;"
@endif
style="
width: {{ (int) $maxWidth }}px !important;
height: {{ (int) $this->getMaxHeight() }}px !important;
"
></canvas>

<span
Expand Down Expand Up @@ -82,11 +83,7 @@ class="text-gray-200 dark:text-gray-800"
class="text-gray-500 dark:text-gray-400"
></span>

<p
@if ($maxHeight = $this->getMaxHeight())
style="width: {{ $maxWidth }}!important;"
@endif
class="my-1 text-center tooltipElement text-sm text-gray-500 dark:text-gray-400"><br></p>
<p class="my-1 text-center tooltipElement text-sm text-gray-500 dark:text-gray-400"><br></p>
</div>
</div>
</div>
Expand Down
6 changes: 3 additions & 3 deletions src/InlineChartWidget.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ abstract class InlineChartWidget extends ChartWidget
{
protected static string $view = 'zeus-inline-chart::widgets.inline-chart';

protected static ?string $maxHeight = '70px';

protected int | string | array $columnSpan = 'full';

protected static ?string $heading = 'Chart';

public ?string $maxWidth = null;
public int $maxWidth = 200;

protected static ?string $maxHeight = '50';

public Model $record;

Expand Down
20 changes: 17 additions & 3 deletions src/Tables/Columns/InlineChart.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ class InlineChart extends Column

protected ?string $chart = null;

protected string $maxWidth = 'w-full';
protected int $maxWidth = 200;

protected int $maxHeight = 50;

public function chart(string $chart): static
{
Expand All @@ -35,15 +37,27 @@ public function getChart(): string
return $this->chart;
}

public function maxWidth(string $maxWidth): static
public function maxWidth(int $maxWidth): static
{
$this->maxWidth = $maxWidth;

return $this;
}

public function getMaxWidth(): string
public function getMaxWidth(): int
{
return $this->maxWidth;
}

public function maxHeight(int $maxHeight): static
{
$this->maxHeight = $maxHeight;

return $this;
}

public function getMaxHeight(): int
{
return $this->maxHeight;
}
}
Loading