Skip to content

Commit

Permalink
feat: map totals (#93)
Browse files Browse the repository at this point in the history
* feat: map totals

* embed
  • Loading branch information
andreiio authored Nov 24, 2024
1 parent 5b0cf0c commit 2f80dd2
Show file tree
Hide file tree
Showing 7 changed files with 64 additions and 8 deletions.
16 changes: 16 additions & 0 deletions app/Livewire/Map.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ class Map extends Component

public bool $embed = false;

public int|float|null $totalValue = null;

public ?string $totalValueFormatted = null;

public ?string $totalLabel = null;

#[Computed]
public function file(): string
{
Expand All @@ -32,6 +38,16 @@ public function file(): string
};
}

#[Computed]
public function showOverlay(): bool
{
if ($this->level->isNot(DataLevel::TOTAL)) {
return false;
}

return filled($this->totalValue) || filled($this->totalValueFormatted) || filled($this->totalLabel);
}

public function render()
{
return view('livewire.map');
Expand Down
12 changes: 11 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"devDependencies": {
"@iframe-resizer/child": "^5.3.2",
"@ryangjchandler/alpine-clipboard": "^2.3.0",
"@tailwindcss/container-queries": "^0.1.1",
"@tailwindcss/forms": "^0.5.9",
"@tailwindcss/typography": "^0.5.15",
"autoprefixer": "^10.4.20",
Expand Down
4 changes: 4 additions & 0 deletions resources/views/livewire/embeds/election-turnouts.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@
:country="$country"
:county="$county"
:level="$level"
:total-value="percent($this->aggregate?->value, $this->aggregate?->max)"
:total-value-formatted="percent($this->aggregate?->value, $this->aggregate?->max, formatted: true)"
:total-label="__('app.navigation.turnout')"
:data="$this->data->toArray()"
:legend="$this->getLegend()"
embed />
</div>
30 changes: 24 additions & 6 deletions resources/views/livewire/map.blade.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,24 @@
<div
class="block h-[600px] outline-none z-[1]"
data-url="{{ Vite::asset("resources/geojson/{$this->file}.geojson") }}"
x-data="map"
x-resize="resize"
x-cloak></div>
<div class="relative">
<div
class="block h-[600px] outline-none z-[1]"
data-url="{{ Vite::asset("resources/geojson/{$this->file}.geojson") }}"
x-data="map"
x-resize="resize"
x-cloak></div>

@if ($this->showOverlay)
<div @class([
'absolute inset-0 z-10 flex flex-col items-center justify-center leading-0',
'@container',
'text-purple-950' => filled($legend) && $this->totalValue < 50,
'text-purple-50' => filled($legend) && $this->totalValue >= 50,
])>
<div class="text-3xl font-bold @md:text-5xl @xl:text-6xl">
{{ $this->totalValueFormatted ?? $this->totalValue }}
</div>
<div class="text-sm @sm:text-base @md:text-lg @lg:text-xl">
{{ $this->totalLabel }}
</div>
</div>
@endif
</div>
3 changes: 3 additions & 0 deletions resources/views/livewire/pages/election-turnouts.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@
:country="$country"
:county="$county"
:level="$level"
:total-value="percent($this->aggregate?->value, $this->aggregate?->max)"
:total-value-formatted="percent($this->aggregate?->value, $this->aggregate?->max, formatted: true)"
:total-label="__('app.navigation.turnout')"
:data="$this->data->toArray()"
:legend="$this->getLegend()" />

Expand Down
6 changes: 5 additions & 1 deletion tailwind.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,9 @@ export default {
},
},
},
plugins: [require('@tailwindcss/forms'), require('@tailwindcss/typography')],
plugins: [
require('@tailwindcss/forms'),
require('@tailwindcss/typography'),
require('@tailwindcss/container-queries'),
],
};

0 comments on commit 2f80dd2

Please sign in to comment.