Skip to content

Commit

Permalink
Start a radar chart for expressing route preferences, but don't use it
Browse files Browse the repository at this point in the history
yet
  • Loading branch information
dabreegster committed Nov 7, 2023
1 parent 098394e commit 203440c
Show file tree
Hide file tree
Showing 4 changed files with 152 additions and 0 deletions.
61 changes: 61 additions & 0 deletions viewer/package-lock.json

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

2 changes: 2 additions & 0 deletions viewer/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
"vite-plugin-wasm-pack": "0.1.11"
},
"dependencies": {
"chart.js": "^4.4.0",
"chartjs-plugin-dragdata": "^2.2.5",
"pmtiles": "^2.10.0",
"svelte-maplibre": "^0.6.0"
}
Expand Down
2 changes: 2 additions & 0 deletions viewer/src/EdgeCostApp.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import Layout from "./Layout.svelte";
import Legend from "./Legend.svelte";
import Loading from "./Loading.svelte";
import PreferenceRadar from "./PreferenceRadar.svelte";
import PropertiesTable from "./PropertiesTable.svelte";
import SequentialLegend from "./SequentialLegend.svelte";
Expand Down Expand Up @@ -244,6 +245,7 @@
<hr />
<CostFunction bind:cost />
{/if}
<PreferenceRadar />
</div>
<div slot="main" style="position:relative; width: 100%; height: 100vh;">
<MapLibre
Expand Down
87 changes: 87 additions & 0 deletions viewer/src/PreferenceRadar.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
<script lang="ts">
import { Chart, registerables } from "chart.js";
import ChartJSdragDataPlugin from "chartjs-plugin-dragdata";
Chart.register(...registerables);
Chart.register(ChartJSdragDataPlugin);
let lts = 50;
let nearbyAmenities = 30;
let greenspace = 20;
let colors = ["red", "blue", "green"];
$: sum = lts + nearbyAmenities + greenspace;
function makeChart(node) {
let options = {
type: "radar",
data: {
labels: ["LTS", "Amenities", "Greenspace"],
datasets: [
{
label: "Routing preferences",
data: [lts, nearbyAmenities, greenspace],
pointHitRadius: 25,
},
],
},
options: {
responsive: false,
onHover: function (e) {
const point = e.chart.getElementsAtEventForMode(
e,
"nearest",
{ intersect: true },
false
);
e.native.target.style.cursor = point.length ? "grab" : "default";
},
plugins: {
dragData: {
round: 1,
showTooltip: true,
onDragStart: function (e) {
e.target.style.cursor = "grabbing";
},
onDragEnd: function (e, datasetIndex, index, value) {
e.target.style.cursor = "default";
if (index == 0) {
lts = value;
} else if (index == 1) {
nearbyAmenities = value;
} else if (index == 2) {
greenspace = value;
}
},
},
},
scales: {
r: {
min: 0,
max: 100,
stepSize: 1,
pointLabels: {
color: colors,
font: {
weight: "bold",
size: 15,
},
},
},
},
},
};
new Chart(node.getContext("2d"), options);
}
</script>

<canvas use:makeChart style="width: 100%; height: 400px;" />
<ul>
<li style:color={colors[0]}>LTS: {((100 * lts) / sum).toFixed(0)}%</li>
<li style:color={colors[1]}>
Nearby amenities: {((100 * nearbyAmenities) / sum).toFixed(0)}%
</li>
<li style:color={colors[2]}>
Greenspace proximity: {((100 * greenspace) / sum).toFixed(0)}%
</li>
</ul>

0 comments on commit 203440c

Please sign in to comment.