-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- implemented frappe chart for placemarks by category - implemented leaflet map - implemented both in the create (soon to be renamed dashboard) +page - additional map layers and charts to come known issue: svelte will occasionally throw a "window not defined" error resulting from the leaflet src. Investigating
- Loading branch information
Showing
14 changed files
with
293 additions
and
18 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
<script lang="ts"> | ||
import "leaflet/dist/leaflet.css"; | ||
import { onMount } from "svelte"; | ||
import type { Control, Map as LeafletMap } from "leaflet"; | ||
import L from "leaflet"; | ||
export let id = "home-map-id"; | ||
export let height = 80; | ||
export let location = { lat: 53.2734, lng: -7.7783203 }; | ||
export let zoom = 8; | ||
export let minZoom = 5; | ||
export let activeLayer = "Terrain"; | ||
let imap: LeafletMap; | ||
let control: Control.Layers; | ||
let overlays: Control.LayersObject = {}; | ||
let baseLayers: any; | ||
onMount(async () => { | ||
const leaflet = await import("leaflet"); | ||
baseLayers = { | ||
Terrain: leaflet.tileLayer("https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png", { | ||
maxZoom: 17, | ||
attribution: | ||
'Map data: © <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors, <a href="http://viewfinderpanoramas.org">SRTM</a> | Map style: © <a href="https://opentopomap.org">OpenTopoMap</a> (<a href="https://creativecommons.org/licenses/by-sa/3.0/">CC-BY-SA</a>)' | ||
}), | ||
Satellite: leaflet.tileLayer("https://server.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer/tile/{z}/{y}/{x}", { | ||
attribution: "Tiles © Esri — Source: Esri, i-cubed, USDA, USGS, AEX, GeoEye, Getmapping, Aerogrid, IGN, IGP, UPR-EGP, and the GIS User Community" | ||
}) | ||
}; | ||
let defaultLayer = baseLayers[activeLayer]; | ||
imap = leaflet.map(id, { | ||
center: [location.lat, location.lng], | ||
zoom: zoom, | ||
minZoom: minZoom, | ||
layers: [defaultLayer] | ||
}); | ||
control = leaflet.control.layers(baseLayers, overlays).addTo(imap); | ||
}); | ||
export function moveTo(lat: number, lng: number) { | ||
imap.flyTo({ lat: lat, lng: lng }); | ||
} | ||
export function addMarker(lat: number, lng: number, popupText: string) { | ||
const marker = L.marker([lat, lng]).addTo(imap); | ||
const popup = L.popup({ autoClose: false, closeOnClick: false }); | ||
popup.setContent(popupText); | ||
marker.bindPopup(popup); | ||
} | ||
</script> | ||
|
||
<div {id} class="box" style="height: {height}vh" /> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import type { Placemark, DataSet } from "$lib/types/placemark-types"; | ||
|
||
export function calculateCategoryData(placemarks: Placemark[]): DataSet { | ||
const categoriesTotal: DataSet = { | ||
labels: [], | ||
datasets: [{ values: [] }], | ||
}; | ||
|
||
// Calculate category counts | ||
const categoryCounts = placemarks.reduce((counts, placemark) => { | ||
const category = placemark.category; | ||
counts[category] = (counts[category] || 0) + 1; | ||
return counts; | ||
}, {} as Record<string, number>); | ||
|
||
// Update chart data | ||
categoriesTotal.labels = Object.keys(categoryCounts); | ||
categoriesTotal.datasets[0].values = Object.values(categoryCounts); | ||
|
||
return categoriesTotal; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<script lang="ts"> | ||
// @ts-ignore | ||
import Chart from "svelte-frappe-charts"; | ||
import Charts from "./Charts.svelte"; | ||
import Card from "$lib/ui/Card.svelte"; | ||
import { subTitle } from "$lib/stores"; | ||
import type { DataSet } from "$lib/types/placemark-types"; | ||
import { placemarkService } from "$lib/services/placemark-service"; | ||
import { currentSession, placemarkStore } from "$lib/stores"; | ||
import { get } from "svelte/store"; | ||
import { calculateCategoryData } from "$lib/utils/placemark-calculations"; | ||
import { onMount } from "svelte"; | ||
subTitle.set("Charts"); | ||
let placemarks = []; | ||
placemarkStore.subscribe((value) => { | ||
placemarks = value; | ||
}); | ||
let categoriesTotal: DataSet = { | ||
labels: [], | ||
datasets: [{ values: [] }] | ||
}; | ||
onMount(async () => { | ||
const fetchedPlacemarks = await placemarkService.getPlacemarks(get(currentSession)); | ||
categoriesTotal = calculateCategoryData(fetchedPlacemarks); | ||
}); | ||
</script> | ||
|
||
<!-- Gallery of placemark images --> | ||
<div> | ||
<Card title="Charts"> | ||
<div class="columns"> | ||
<div class="column has-text-centered"> | ||
<h1 class="title is-4">Categories by number of Placemarks</h1> | ||
<Chart data={categoriesTotal} type="bar" /> | ||
</div> | ||
</div> | ||
</Card> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<script lang="ts"> | ||
// @ts-ignore | ||
import Chart from "svelte-frappe-charts"; | ||
let categoriesTotal = { | ||
labels: [""], | ||
datasets: [ | ||
{ | ||
values: [0, 0], | ||
}, | ||
], | ||
}; | ||
</script> | ||
|
||
<div class="columns"> | ||
<div class="column has-text-centered"> | ||
<h1 class="title is-4">Categories by number of Placemarks</h1> | ||
<Chart data={categoriesTotal} type="bar" /> | ||
</div> | ||
</div> |
Oops, something went wrong.