Skip to content

Commit b84fe56

Browse files
Merge pull request #1428 from liberu-genealogy/copilot/improve-tree-rendering-features
Fix chart rendering: Livewire v3 compatibility and FanChart component inheritance
2 parents 72dfc70 + 5db662a commit b84fe56

File tree

6 files changed

+45
-17
lines changed

6 files changed

+45
-17
lines changed

app/Filament/App/Widgets/PedigreeChartWidget.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,22 +26,22 @@ public function render(): View
2626

2727
public function initializeChart(): void
2828
{
29-
$this->dispatchBrowserEvent('initializeChart', ['people' => $this->getData()['people']->toJson()]);
29+
$this->dispatch('initializeChart', people: $this->getData()['people']->toJson());
3030
}
3131

3232
public function zoomIn(): void
3333
{
34-
$this->dispatchBrowserEvent('zoomIn');
34+
$this->dispatch('zoomIn');
3535
}
3636

3737
public function zoomOut(): void
3838
{
39-
$this->dispatchBrowserEvent('zoomOut');
39+
$this->dispatch('zoomOut');
4040
}
4141

4242
public function pan($direction): void
4343
{
44-
$this->dispatchBrowserEvent('pan', ['direction' => $direction]);
44+
$this->dispatch('pan', direction: $direction);
4545
}
4646

4747
protected function getListeners()

app/Livewire/DescendantChartComponent.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ public function setRootPerson(int $personId): void
8888
$rootPerson = Person::find($this->rootPersonId);
8989
$this->descendantsData = $this->buildDescendantTree($rootPerson, $this->generations);
9090
}
91-
$this->emit('descendant-chart-updated');
91+
$this->dispatch('refreshDescendantChart');
9292
}
9393

9494
public function setGenerations(int $generations): void
@@ -100,11 +100,16 @@ public function setGenerations(int $generations): void
100100
$rootPerson = Person::find($this->rootPersonId);
101101
$this->descendantsData = $this->buildDescendantTree($rootPerson, $this->generations);
102102
}
103-
$this->emit('descendant-chart-updated');
103+
$this->dispatch('refreshDescendantChart');
104104
}
105105

106106
public function render()
107107
{
108108
return view('livewire.descendant-chart-component');
109109
}
110+
111+
public function getPeopleListProperty(): array
112+
{
113+
return Person::getListOptimized();
114+
}
110115
}

app/Livewire/FanChart.php

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@
44

55
use Illuminate\Contracts\View\View;
66
use App\Models\Person;
7-
use Filament\Widgets\Widget;
7+
use Livewire\Component;
88

9-
class FanChart extends Widget
9+
class FanChart extends Component
1010
{
11-
protected string $view = 'filament.widgets.fan-chart-widget';
11+
protected string $view = 'livewire.fan-chart';
1212

1313
public ?int $rootPersonId = null;
1414
public int $generations = 5;
@@ -82,35 +82,40 @@ private function buildFanData($person, $maxGenerations, $generation = 0): array
8282
public function setRootPerson($personId): void
8383
{
8484
$this->rootPersonId = $personId;
85-
$this->emit('refreshFanChart');
85+
$this->dispatch('refreshFanChart');
8686
}
8787

8888
public function setGenerations($generations): void
8989
{
9090
$this->generations = max(2, min(8, $generations));
91-
$this->emit('refreshFanChart');
91+
$this->dispatch('refreshFanChart');
9292
}
9393

9494
public function toggleNames(): void
9595
{
9696
$this->showNames = !$this->showNames;
97-
$this->emit('refreshFanChart');
97+
$this->dispatch('refreshFanChart');
9898
}
9999

100100
public function toggleDates(): void
101101
{
102102
$this->showDates = !$this->showDates;
103-
$this->emit('refreshFanChart');
103+
$this->dispatch('refreshFanChart');
104104
}
105105

106106
public function setColorScheme($scheme): void
107107
{
108108
$this->colorScheme = $scheme;
109-
$this->emit('refreshFanChart');
109+
$this->dispatch('refreshFanChart');
110110
}
111111

112112
public function render(): View
113113
{
114114
return view($this->view, $this->getData());
115115
}
116+
117+
public function getPeopleListProperty(): array
118+
{
119+
return Person::getListOptimized();
120+
}
116121
}

app/Livewire/PedigreeChart.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,20 +39,20 @@ public function setRootPerson(int $personId): void
3939
{
4040
$this->rootPersonId = $personId;
4141
$this->hydrateTree();
42-
$this->emit('refreshChart');
42+
$this->dispatch('refreshChart');
4343
}
4444

4545
public function setGenerations(int $generations): void
4646
{
4747
$this->generations = max(3, min(8, $generations));
4848
$this->hydrateTree();
49-
$this->emit('refreshChart');
49+
$this->dispatch('refreshChart');
5050
}
5151

5252
public function toggleDates(): void
5353
{
5454
$this->showDates = ! $this->showDates;
55-
$this->emit('refreshChart');
55+
$this->dispatch('refreshChart');
5656
}
5757

5858
public function expandPerson(int $personId): void

resources/views/livewire/descendant-chart-component.blade.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,13 @@
11
<div class="descendant-chart-container">
2+
<div class="flex items-center gap-3 mb-4">
3+
<label class="text-sm text-gray-700">Root person:</label>
4+
<select class="fi-input block rounded-md border-gray-300 text-sm"
5+
wire:change="setRootPerson($event.target.value)">
6+
@foreach($this->peopleList as $id => $label)
7+
<option value="{{ $id }}" @selected($rootPersonId === (int) $id)>{{ $label }}</option>
8+
@endforeach
9+
</select>
10+
</div>
211
<div class="chart-header mb-4">
312
<h3 class="text-xl font-semibold text-gray-800">Descendant Chart</h3>
413
<div class="chart-controls flex gap-2 mt-2">

resources/views/livewire/fan-chart.blade.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,13 @@
11
<div class="fan-chart-container">
2+
<div class="flex items-center gap-3 mb-4">
3+
<label class="text-sm text-gray-700">Root person:</label>
4+
<select class="fi-input block rounded-md border-gray-300 text-sm"
5+
wire:change="setRootPerson($event.target.value)">
6+
@foreach($this->peopleList as $id => $label)
7+
<option value="{{ $id }}" @selected($rootPersonId === (int) $id)>{{ $label }}</option>
8+
@endforeach
9+
</select>
10+
</div>
211
<div class="chart-header mb-4">
312
<h3 class="text-xl font-semibold text-gray-800">Fan Chart</h3>
413
<div class="chart-controls flex gap-2 mt-2">

0 commit comments

Comments
 (0)