Skip to content

Commit

Permalink
wip(mapa): Adiciona mapa de especies
Browse files Browse the repository at this point in the history
  • Loading branch information
Phenome committed Mar 14, 2024
1 parent f32ca2c commit 379c965
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 11 deletions.
10 changes: 3 additions & 7 deletions web/src/components/Map.astro
Original file line number Diff line number Diff line change
@@ -1,21 +1,17 @@
---
interface Props {
stateList: string[]
data: [string, any][]
}
const { stateList } = Astro.props
const data = [
['Estado', 'Ocorrência'],
...stateList.map((state) => [state, state])
]
const { data } = Astro.props
---

<script type="module">
import 'https://cdn.skypack.dev/@google-web-components/google-chart'
</script>

<google-chart
class="h-[200px] w-auto"
class="h-[500px] w-[800px]"
type="geo"
data={JSON.stringify(data)}
options='{"region":"BR", "resolution":"provinces","title":"Ocorrências"}'
Expand Down
26 changes: 26 additions & 0 deletions web/src/lib/mongo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,32 @@ export async function countTaxa(filter: Record<string, unknown> = {}) {
return await taxa.countDocuments(filter)
}

export async function countTaxaRegions() {
const taxa = await getCollection('dwc2json', 'taxa')
return await taxa
.aggregate([
{
$match: {
taxonomicStatus: 'NOME ACEITO'
}
},
{
$unwind: {
path: '$distribution.occurrence'
}
},
{
$group: {
_id: '$distribution.occurrence',
count: {
$count: {}
}
}
}
])
.toArray()
}

export async function getTaxon(
kingdom: 'Plantae' | 'Fungi' | 'Animalia',
id: string,
Expand Down
15 changes: 11 additions & 4 deletions web/src/pages/taxa.astro
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
---
import BaseLayout from '../layouts/base.astro'
import { listTaxaPaginated } from '../lib/mongo'
import { countTaxa, countTaxaRegions, listTaxaPaginated } from '../lib/mongo'
import { countTaxa } from '../lib/mongo'
import Map from '../components/Map.astro'
const taxaNum = await countTaxa()
const taxaRegions: { _id: string; count: number }[] = await countTaxaRegions()
const searchParams: Record<string, string> = Object.fromEntries(
Array.from(Astro.url.searchParams.entries())
Expand Down Expand Up @@ -43,8 +44,14 @@ const searchParamsWithPage = (page: number) => {
}
---

<img src="/logoReflora.svg" alt="Reflora Logo" />
<BaseLayout useTransition title="Procura de Taxa">
<BaseLayout title="Procura de Taxa">
<img src="/logoReflora.svg" alt="Reflora Logo" />
<Map
data={[
['Estado', 'Taxa'],
...taxaRegions.map(({ _id, count }) => [_id, count] as [string, number])
]}
/>
<section class="m-2 p-2 border rounded border-slate-400 inline-block">
<h2 class="text-xl font-bold">Filtro</h2>
<form class="inline-flex flex-col gap-1">
Expand Down

0 comments on commit 379c965

Please sign in to comment.