-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Start a radar chart for expressing route preferences, but don't use it
yet
- Loading branch information
1 parent
098394e
commit 203440c
Showing
4 changed files
with
152 additions
and
0 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,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> |