Skip to content

Add visualization of graph that's used for calculating directions #155

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,18 @@
"tests": "yarn test"
},
"dependencies": {
"@egjs/hammerjs": "^2.0.17",
"component-emitter": "^1.3.0",
"core-js": "^3.4.3",
"keycharm": "^0.3.1",
"moment": "^2.24.0",
"register-service-worker": "^1.6.2",
"room-finder": "0.3.0-beta.2",
"timsort": "^0.3.0",
"uuid": "^8.3.2",
"vis-data": "^7.1.2",
"vis-network": "^9.0.4",
"vis-util": "^5.0.2",
"vue": "^2.6.10",
"vue-meta": "^2.3.1",
"vue-router": "^3.1.3",
Expand Down
5 changes: 5 additions & 0 deletions src/router/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ const routes = [
path: "/settings",
component: Settings,
},
{
path: "/graph",
component: () =>
import(/* webpackChunkName: 'graphpage' */ "@/views/GraphPage.vue"),
},
// fallback (client-side 404)
{
path: "*",
Expand Down
8 changes: 7 additions & 1 deletion src/service-worker.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
/* eslint-disable no-undef */
// eslint-disable-next-line no-restricted-globals, no-underscore-dangle
workbox.precaching.precacheAndRoute(self.__precacheManifest || []);
const precacheManifest = self.__precacheManifest || [];

workbox.precaching.precacheAndRoute(
precacheManifest.filter(
(p) => !p.url.includes("graphpage") && !p.url.includes("legacy")
Copy link
Member Author

@AjaiKN AjaiKN May 25, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is so that the service worker doesn't ask the browser to precache the resources for the graph page, since most people will never go to that page.

)
);

// https://developers.google.com/web/tools/workbox/guides/common-recipes#cache_css_and_javascript_files
workbox.routing.registerRoute(
Expand Down
86 changes: 86 additions & 0 deletions src/views/GraphPage.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
<template>
<div>
<p style="font-size: 0.5em">
This is the graph/network used to calculate directions in Walnut.Direct
using Dijkstra's algorithm. It'll take a minute to load. Scroll to zoom if
you're on a computer.
<b v-if="loading"><br />Loading...</b>
</p>
<div id="mynetwork" ref="mynetwork"></div>
</div>
</template>

<script lang="ts">
/* eslint-disable */
import Vue from "vue";
import { Network } from "vis-network/standalone";
import { walnutNonAccessible as walnut } from "@/walnut";

function nodeName(node: string) {
const [kind, name, thing] = node.split("-$-");
switch (kind) {
case "BasicRoomNode":
return name;
case "StairNode":
return `${name}, floor ${thing}`;
case "ForkNode":
return thing === "true" ? `${name}, reversed` : name;
default:
return `${name}, ${thing}`;
}
}

export default Vue.extend({
data: () => ({ loading: true }),
mounted() {
const { graph } = walnut;

const n = [];
const e: any[] = [];
for (const node in graph) {
console.log(node);
n.push({ id: n.length, label: nodeName(node) });
}
for (const node in graph) {
for (const node2 in graph[node]) {
const isDoubled = graph[node2] && graph[node2][node];
if (
e.filter(
({ from, to }) =>
from === Object.keys(graph).indexOf(node2) &&
to === Object.keys(graph).indexOf(node)
).length === 0
)
e.push({
from: Object.keys(graph).indexOf(node),
to: Object.keys(graph).indexOf(node2),
arrows: isDoubled ? "from, to" : "to",
color: { color: isDoubled ? "green" : "red" },
});
}
}
console.log({ n, e });

// create a network
const container = this.$refs.mynetwork as any;
const data = {
nodes: n,
edges: e,
};
const options = {
layout: { improvedLayout: false },
};
const network = new Network(container, data, options);

network.once("afterDrawing", () => (this.loading = false));
},
});
</script>

<style scoped>
#mynetwork {
/* width: 100%; */
height: 80vh;
border: 1px solid lightgray;
}
</style>
68 changes: 60 additions & 8 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -892,6 +892,13 @@
debug "^3.1.0"
lodash.once "^4.1.1"

"@egjs/hammerjs@^2.0.17":
version "2.0.17"
resolved "https://registry.yarnpkg.com/@egjs/hammerjs/-/hammerjs-2.0.17.tgz#5dc02af75a6a06e4c2db0202cae38c9263895124"
integrity sha512-XQsZgjm2EcVUiZQf11UBJQfmZeEmOW8DpI1gsFeln6w0ae0ii4dMQEQ0kjl6DspdWX1aGY1/loyXnP0JS06e/A==
dependencies:
"@types/hammerjs" "^2.0.36"

"@eslint/eslintrc@^0.4.0":
version "0.4.0"
resolved "https://registry.yarnpkg.com/@eslint/eslintrc/-/eslintrc-0.4.0.tgz#99cc0a0584d72f1df38b900fb062ba995f395547"
Expand Down Expand Up @@ -1244,6 +1251,11 @@
"@types/minimatch" "*"
"@types/node" "*"

"@types/hammerjs@^2.0.36":
version "2.0.39"
resolved "https://registry.yarnpkg.com/@types/hammerjs/-/hammerjs-2.0.39.tgz#4be64bbacf3813c79c0dab895c6b0fdc7d5e513f"
integrity sha512-lYR2Y/tV2ujpk/WyUc7S0VLI0a9hrtVIN9EwnrNo5oSEJI2cK2/XrgwOQmXLL3eTulOESvh9qP6si9+DWM9cOA==

"@types/http-proxy@^1.17.4":
version "1.17.5"
resolved "https://registry.yarnpkg.com/@types/http-proxy/-/http-proxy-1.17.5.tgz#c203c5e6e9dc6820d27a40eb1e511c70a220423d"
Expand Down Expand Up @@ -3448,7 +3460,7 @@ commondir@^1.0.1:
resolved "https://registry.yarnpkg.com/commondir/-/commondir-1.0.1.tgz#ddd800da0c66127393cca5950ea968a3aaf1253b"
integrity sha1-3dgA2gxmEnOTzKWVDqloo6rxJTs=

component-emitter@^1.2.1:
component-emitter@^1.2.1, component-emitter@^1.3.0:
version "1.3.0"
resolved "https://registry.yarnpkg.com/component-emitter/-/component-emitter-1.3.0.tgz#16e4070fba8ae29b679f2215853ee181ab2eabc0"
integrity sha512-Rd3se6QB+sO1TwqZjscQrurpEPIfO0/yYnSin6Q/rD3mOutHvUrCAhJub3r90uNb+SESBuE0QYoB90YdfatsRg==
Expand Down Expand Up @@ -3609,7 +3621,7 @@ core-js-compat@^3.6.5, core-js-compat@^3.8.1, core-js-compat@^3.9.0:
browserslist "^4.16.3"
semver "7.0.0"

core-js@3, core-js@^3.4.3, core-js@^3.6.5:
core-js@3, core-js@^3.6.5:
version "3.9.1"
resolved "https://registry.yarnpkg.com/core-js/-/core-js-3.9.1.tgz#cec8de593db8eb2a85ffb0dbdeb312cb6e5460ae"
integrity sha512-gSjRvzkxQc1zjM/5paAmL4idJBFzuJoo+jDjF1tStYFMV2ERfD02HhahhCGXUyHxQRG4yFKVSdO6g62eoRMcDg==
Expand All @@ -3619,6 +3631,11 @@ core-js@^2.4.0:
resolved "https://registry.yarnpkg.com/core-js/-/core-js-2.6.12.tgz#d9333dfa7b065e347cc5682219d6f690859cc2ec"
integrity sha512-Kb2wC0fvsWfQrgk8HU5lW6U/Lcs8+9aaYcy4ZFc6DDlo4nZ7n70dEgE5rtR0oG6ufKDUnrwfWL1mXR5ljDatrQ==

core-js@^3.4.3:
version "3.11.0"
resolved "https://registry.yarnpkg.com/core-js/-/core-js-3.11.0.tgz#05dac6aa70c0a4ad842261f8957b961d36eb8926"
integrity sha512-bd79DPpx+1Ilh9+30aT5O1sgpQd4Ttg8oqkqi51ZzhedMM1omD2e6IOF48Z/DzDCZ2svp49tN/3vneTK6ZBkXw==

[email protected], core-util-is@~1.0.0:
version "1.0.2"
resolved "https://registry.yarnpkg.com/core-util-is/-/core-util-is-1.0.2.tgz#b5fd54220aa2bc5ab57aab7140c940754503c1a7"
Expand Down Expand Up @@ -5652,7 +5669,12 @@ has-flag@^4.0.0:
resolved "https://registry.yarnpkg.com/has-flag/-/has-flag-4.0.0.tgz#944771fd9c81c81265c4d6941860da06bb59479b"
integrity sha512-EykJT/Q1KjTWctppgIAgfSO0tKVuZUjhgMr17kqTumMl6Afv3EISleU7qZUzoXDFTAHTDC4NOoG/ZxU3EvlMPQ==

has-symbols@^1.0.0, has-symbols@^1.0.1, has-symbols@^1.0.2:
has-symbols@^1.0.0, has-symbols@^1.0.1:
version "1.0.1"
resolved "https://registry.yarnpkg.com/has-symbols/-/has-symbols-1.0.1.tgz#9f5214758a44196c406d9bd76cebf81ec2dd31e8"
integrity sha512-PLcsoqu++dmEIZB+6totNFKq/7Do+Z0u4oT0zKOJNl3lYK6vGwwu2hjHs+68OEZbTjiUE9bgOABXbP/GvrS0Kg==

has-symbols@^1.0.2:
version "1.0.2"
resolved "https://registry.yarnpkg.com/has-symbols/-/has-symbols-1.0.2.tgz#165d3070c00309752a1236a479331e3ac56f1423"
integrity sha512-chXa79rL/UC2KlX17jo3vRGz0azaWEx5tGqZg5pO3NUyEJVB17dMruQlzCCOfUvElghKcm5194+BCRvi2Rv/Gw==
Expand Down Expand Up @@ -7208,6 +7230,11 @@ jsprim@^1.2.2:
json-schema "0.2.3"
verror "1.10.0"

keycharm@^0.3.1:
version "0.3.1"
resolved "https://registry.yarnpkg.com/keycharm/-/keycharm-0.3.1.tgz#1de258425454752b95c4d8a6cab9ec83218670de"
integrity sha512-zn47Ti4FJT9zdF+YBBLWJsfKF/fYQHkrYlBeB5Ez5e2PjW7SoIxr43yehAne2HruulIoid4NKZZxO0dHBygCtQ==

killable@^1.0.1:
version "1.0.1"
resolved "https://registry.yarnpkg.com/killable/-/killable-1.0.1.tgz#4c8ce441187a061c7474fb87ca08e2a638194892"
Expand Down Expand Up @@ -7848,14 +7875,14 @@ mixin-deep@^1.2.0:
for-in "^1.0.2"
is-extendable "^1.0.1"

[email protected]:
[email protected], [email protected], mkdirp@^0.5.1, mkdirp@~0.5.1:
version "0.5.1"
resolved "https://registry.yarnpkg.com/mkdirp/-/mkdirp-0.5.1.tgz#30057438eac6cf7f8c4767f38648d6697d75c903"
integrity sha1-MAV0OOrGz3+MR2fzhkjWaX11yQM=
dependencies:
minimist "0.0.8"

mkdirp@0.x, mkdirp@^0.5.1, mkdirp@^0.5.3, mkdirp@^0.5.5, mkdirp@~0.5.1:
mkdirp@^0.5.3, mkdirp@^0.5.5:
version "0.5.5"
resolved "https://registry.yarnpkg.com/mkdirp/-/mkdirp-0.5.5.tgz#d91cefd62d1436ca0f41620e251288d420099def"
integrity sha512-NKmAlESf6jMGym1++R0Ra7wvhV+wFW63FaSOFPwRahvea0gMUcGUhVeAg/0BC0wiv9ih5NYPB1Wn1UEI1/L+xQ==
Expand All @@ -7872,6 +7899,11 @@ [email protected]:
resolved "https://registry.yarnpkg.com/moment/-/moment-2.24.0.tgz#0d055d53f5052aa653c9f6eb68bb5d12bf5c2b5b"
integrity sha512-bV7f+6l2QigeBBZSM/6yTNq4P2fNpSWj/0e7jQcy87A8e7o2nAfP/34/2ky5Vw4B9S446EtIhodAzkFCcR4dQg==

moment@^2.24.0:
version "2.29.1"
resolved "https://registry.yarnpkg.com/moment/-/moment-2.29.1.tgz#b2be769fa31940be9eeea6469c075e35006fa3d3"
integrity sha512-kHmoybcPV8Sqy59DwNDY3Jefr64lK/by/da0ViFcuA4DH0vQg5Q6Ze5VimxkfQNSC+Mls/Kx53s7TjP1RhFEDQ==

move-concurrently@^1.0.1:
version "1.0.1"
resolved "https://registry.yarnpkg.com/move-concurrently/-/move-concurrently-1.0.1.tgz#be2c005fda32e0b29af1f05d7c4b33214c701f92"
Expand Down Expand Up @@ -9356,9 +9388,9 @@ [email protected]:
unpipe "1.0.0"

react-is@^16.8.4:
version "16.13.1"
resolved "https://registry.yarnpkg.com/react-is/-/react-is-16.13.1.tgz#789729a4dc36de2999dc156dd6c1d9c18cea56a4"
integrity sha512-24e6ynE2H+OKt4kqsOvNd8kBpV65zoxbA4BVsEOB3ARVWQki/DHzaUoC5KuON/BiccDaCCTZBuOcfZs70kR8bQ==
version "16.12.0"
resolved "https://registry.yarnpkg.com/react-is/-/react-is-16.12.0.tgz#2cc0fe0fba742d97fd527c42a13bec4eeb06241c"
integrity sha512-rPCkf/mWBtKc97aLL9/txD8DZdemK0vkA3JMLShjlJB3Pj3s+lpf1KaBzMfQrAmhMQB0n1cU/SUGgKKBCe837Q==

react-is@^17.0.1:
version "17.0.1"
Expand Down Expand Up @@ -11227,6 +11259,11 @@ uuid@^3.3.2, uuid@^3.4.0:
resolved "https://registry.yarnpkg.com/uuid/-/uuid-3.4.0.tgz#b23e4358afa8a202fe7a100af1f5f883f02007ee"
integrity sha512-HjSDRw6gZE5JMggctHBcjVak08+KEVhSIiDzFnT9S9aegmp85S/bReBVTb4QTFaRNptJ9kuYaNhnbNEOkbKb/A==

uuid@^8.3.2:
version "8.3.2"
resolved "https://registry.yarnpkg.com/uuid/-/uuid-8.3.2.tgz#80d5b5ced271bb9af6c445f21a1a04c606cefbe2"
integrity sha512-+NYs2QeMWy+GWFOEm9xnn6HCDp0l7QBD7ml8zLUmJ+93Q5NF0NocErnwkTkXVFNiX3/fpC6afS8Dhb/gz7R7eg==

v8-compile-cache@^2.0.3:
version "2.3.0"
resolved "https://registry.yarnpkg.com/v8-compile-cache/-/v8-compile-cache-2.3.0.tgz#2de19618c66dc247dcfb6f99338035d8245a2cee"
Expand Down Expand Up @@ -11259,6 +11296,21 @@ [email protected]:
core-util-is "1.0.2"
extsprintf "^1.2.0"

vis-data@^7.1.2:
version "7.1.2"
resolved "https://registry.yarnpkg.com/vis-data/-/vis-data-7.1.2.tgz#b7d076ac79cb54f7c5e9c80f5b03b93cc8cc1fda"
integrity sha512-RPSegFxEcnp3HUEJSzhS2vBdbJ2PSsrYYuhRlpHp2frO/MfRtTYbIkkLZmPkA/Sg3pPfBlR235gcoKbtdm4mbw==

vis-network@^9.0.4:
version "9.0.4"
resolved "https://registry.yarnpkg.com/vis-network/-/vis-network-9.0.4.tgz#c62d466224897070e9c1720e4d8e6e1dc479ca81"
integrity sha512-F/pq8yBJUuB9lNKXHhtn4GP2h91FV0c2O2nvfU34RX4VCYOlqs+mINdz+J+QkWiYhiPdlVy15gzVEzkhJ9hpaw==

vis-util@^5.0.2:
version "5.0.2"
resolved "https://registry.yarnpkg.com/vis-util/-/vis-util-5.0.2.tgz#47e8a31580c0805680c43d253ac7da21501990b9"
integrity sha512-oPDmPc4o0uQLoKpKai2XD1DjrhYsA7MRz75Wx9KmfX84e9LLgsbno7jVL5tR0K9eNVQkD6jf0Ei8NtbBHDkF1A==

vm-browserify@^1.0.1:
version "1.1.2"
resolved "https://registry.yarnpkg.com/vm-browserify/-/vm-browserify-1.1.2.tgz#78641c488b8e6ca91a75f511e7a3b32a86e5dda0"
Expand Down