Skip to content

Commit 68ecde4

Browse files
committed
Added visualization
1 parent 92a1cd0 commit 68ecde4

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

69 files changed

+3460
-0
lines changed

.github/.DS_Store

6 KB
Binary file not shown.

.gitignore

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Logs
2+
logs
3+
*.log
4+
5+
package-lock.json
6+
# Runtime data
7+
pids
8+
*.pid
9+
*.seed
10+
11+
# Directory for instrumented libs generated by jscoverage/JSCover
12+
lib-cov
13+
14+
# Coverage directory used by tools like istanbul
15+
coverage
16+
17+
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
18+
.grunt
19+
20+
# node-waf configuration
21+
.lock-wscript
22+
23+
build
24+
25+
# Dependency directory
26+
# https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git
27+
node_modules

data/.DS_Store

6 KB
Binary file not shown.

data/leetcode/2015-09-27T13-00-00Z/labels.json

Lines changed: 1 addition & 0 deletions
Large diffs are not rendered by default.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"data": [-2, 1, -4, 3, -6, 5, -7, 5, -9, 8, -11, 10, -12, 10, -13, 10, -14, 10, -16, 15, -17, 15, -19, 18, -21, 20, -22, 20, -23, 20, -24, 20, -26, 25, -28, 27, -30, 29, -32, 31, -33, 31, -34, 31, -36, 35, -37, 35, -38, 35, -39, 35, -40, 35, -41, 35, -42, 35, -43, 35, -44, 35, -45, 35, -46, 35, -48, 47, -50, 49, -51, 49, -53, 52, -54, 52, -56, 55, -58, 57, -60, 59, -62, 61, -64, 63, -65, 63, -67, 66, -69, 68, -71, 70, -72, 70, -74, 73, -76, 75, -78, 77, -79, 77, -80, 77, -81, 77, -82, 77, -84, 83, -86, 85, -87, 85, -88, 85, -89, 85, -90, 85, -91, 85, -92, 85, -93, 85, -94, 85, -95, 85, -96, 85, -97, 85, -98, 85, -99, 85, -100, 85, -101, 85, -102, 85, -103, 85, -104, 85, -105, 85, -106, 85, -107, 85, -109, 108, -111, 110, -113, 112, -114, 112, -115, 112, -117, 116, -118, 116, -120, 119, -122, 121, -123, 121, -124, 121, -126, 125, -128, 127, -130, 129, -131, 129, -133, 132, -135, 134, -136, 134, -137, 134, -138, 134, -139, 134, -140, 134, -141, 134, -142, 134, -143, 134, -144, 134, -145, 134, -147, 146, -148, 146, -149, 146, -151, 150, -153, 152, -155, 154, -157, 156, -159, 158, -160, 158, -162, 161, -164, 163, -166, 165, -168, 167, -169, 167, -171, 170, -173, 172, -175, 174, -176, 174, -178, 177, -180, 179, -182, 181, -184, 183, -186, 185, -187, 185, -188, 185, -190, 189, -191, 189, -192, 189, -194, 193, -195, 193, -196, 193, -197, 193, -198, 193, -200, 199, -202, 201, -203, 201, -205, 204, -207, 206, -209, 208, -211, 210, -212, 210, -214, 213, -216, 215, -218, 217, -219, 217, -220, 217, -222, 221, -224, 223, -225, 223, -227, 226, -229, 228, -231, 230, -233, 232, -235, 234, -236, 234, -237, 234, -239, 238, -241, 240, -242, 240, -244, 243, -246, 245, -247, 245, -249, 248, -251, 250, -252, 250, -253, 250, -254, 250, -256, 255, -257, 255, -258, 255, -259, 255, -260, 255, -262, 261, -263, 261, -264, 261, -266, 265, -267, 265, -268, 265, -269, 265, -271, 270, -272, 270, -274, 273, -275, 273, -277, 276, -279, 278, -281, 280, -282, 280, -284, 283, -286, 285, -287, 285, -289, 288, -290, 288, -291, 288, -292, 288, -293, 288, -294, 288, -295, 288, -297, 296, -298, 296, -300, 299, -302, 301, -304, 303, -306, 305, -308, 307, -310, 309, -312, 311, -314, 313, -315, 313, -317, 316, -319, 318, -321, 320, -322, 320, -324, 323, -325, 323, -327, 326, -329, 328, -331, 330, -333, 332, -335, 334, -337, 336, -338, 336, -339, 336, -341, 340, -343, 342, -344, 342, -345, 342, -347, 346, -348, 346, -350, 349, -352, 351, -353, 351, -354, 351, -355, 351, -356, 351, -357, 351, -359, 358, -361, 360, -363, 362, -365, 364, -367, 366, -369, 368, -370, 368, -371, 368, -373, 372, -374, 372, -375, 372, -376, 372, -377, 372, -379, 378, -381, 380, -383, 382, -385, 384, -387, 386, -389, 388, -390, 388, -391, 388, -393, 392, -395, 394, -396, 394, -397, 394, -399, 398, -400, 398, -402, 401, -404, 403, -405, 403, -407, 406, -409, 408, -410, 408, -411, 408, -412, 408, -413, 408, -415, 414, -417, 416, -418, 416, -419, 416, -421, 420, -423, 422, -424, 422, -426, 425, -427, 425, -429, 428, -431, 430, -433, 432, -435, 434, -437, 436, -438, 436, -439, 436, -440, 436, -442, 441, -444, 443, -445, 443, -446, 443, -448, 447, -450, 449, -452, 451, -454, 453, -456, 455, -458, 457, -460, 459, -462, 461, -464, 463, -466, 465, -467, 465, -468, 465, -470, 469, -472, 471, -474, 473, -476, 475, -478, 477, -479, 477, -480, 477, -481, 477, -482, 477, -483, 477, -485, 484, -487, 486, -489, 488, -491, 490, -492, 490, -493, 490, -494, 490, -496, 495, -498, 497, -500, 499, -502, 501, -503, 501, -504, 501, -505, 501, -506, 501, -507, 501, -508, 501, -510, 509, -512, 511, -514, 513, -516, 515, -518, 517, -519, 517, -520, 517, -522, 521, -524, 523, -526, 525, -527, 525, -528, 525, -529, 525, -530, 525, -531, 525, -532, 525, -534, 533, -536, 535, -538, 537, -539, 537, -541, 540, -543, 542, -545, 544, -546, 544, -548, 547, -550, 549, -551, 549, -552, 549, -554, 553, -556, 555, -558, 557, -559, 557, -561, 560, -563, 562, -564, 562, -565, 562, -567, 566, -569, 568, -570, 568, -571, 568, -572, 568, -573, 568, -575, 574, -577, 576, -579, 578, -580, 578, -582, 581, -584, 583, -586, 585, -587, 585, -589, 588, -591, 590, -593, 592, -595, 594, -597, 596, -599, 598, -601, 600, -602, 600, -603, 600, -604, 600, -606, 605, -607, 605, -609, 608, -610, 608, -612, 611, -613, 611, -615, 614, -617, 616, -619, 618, -620, 618, -621, 618, -622, 618, -624, 623, -626, 625, -628, 627, -630, 629, -631, 629, -632, 629, -634, 633, -635, 633, -637, 636, -639, 638, -640, 638, -642, 641, -643, 641, -645, 644, -647, 646, -648, 646, -649, 646, -651, 650, -653, 652, -654, 652, -656, 655, -657, 655, -659, 658, -661, 660, -663, 662, -665, 664, -667, 666, -669, 668, -671, 670, -673, 672, -675, 674, -677, 676, -678, 676, -680, 679, -682, 681, -683, 681, -685, 684, -687, 686, -689, 688, -691, 690, -693, 692, -694, 692, -695, 692, -697, 696, -698, 696, -699, 696, -700, 696, -701, 696, -703, 702, -704, 702, -706, 705, -708, 707, -710, 709, -712, 711, -714, 713, -715, 713, -717, 716, -718, 716, -720, 719, -721, 719, -723, 722, -724, 722, -726, 725, -728, 727, -729, 727, -730, 727, -732, 731, -734, 733, -735, 733, -737, 736, -738, 736, -740, 739, -742, 741, -744, 743, -746, 745, -748, 747, -750, 749, -752, 751, -754, 753, -756, 755, -757, 755, -759, 758, -760, 758, -762, 761, -764, 763, -766, 765, -768, 767, -770, 769, -771, 769, -772, 769, -773, 769, -774, 769, -775, 769, -777, 776, -779, 778, -780, 778, -781, 778, -782, 778, -784, 783, -786, 785, -788, 787, -789, 787, -790, 787, -792, 791, -794, 793, -796, 795, -798, 797, -799, 797, -800, 797, -801, 797, -803, 802, -805, 804, -807, 806, -808, 806, -810, 809, -812, 811, -814, 813, -815, 813, -816, 813, -818, 817, -819, 817, -820, 817, -821, 817, -823, 822, -825, 824, -827, 826, -829, 828, -831, 830, -833, 832, -834, 832, -835, 832, -836, 832, -838, 837, -840, 839, -842, 841, -843, 841, -845, 844, -847, 846, -849, 848, -850, 848, -852, 851, -854, 853, -855, 853, -856, 853, -857, 853, -859, 858, -860, 858, -861, 858, -863, 862, -865, 864, -866, 864, -867, 864, -869, 868, -870, 868, -871, 868, -873, 872, -875, 874, -876, 874, -877, 874, -878, 874, -879, 874, -880, 874, -881, 874, -882, 874, -884, 883, -886, 885, -888, 887, -890, 889, -891, 889, -893, 892, -894, 892, -896, 895, -898, 897, -900, 899, -901, 899, -902, 899, -904, 903, -906, 905, -908, 907, -910, 909, -911, 909, -913, 912, -914, 912, -915, 912, -917, 916, -919, 918, -921, 920, -922, 920, -924, 923, -925, 923, -926, 923, -927, 923, -929, 928, -930, 928, -932, 931, -934, 933, -936, 935, -938, 937, -939, 937, -940, 937, -941, 937, -943, 942, -945, 944, -947, 946, -949, 948, -951, 950, -953, 952, -955, 954, -957, 956, -959, 958, -961, 960, -963, 962, -964, 962, -966, 965, -967, 965, -969, 968, -971, 970, -973, 972, -975, 974, -977, 976, -979, 978, -981, 980, -983, 982, -985, 984, -987, 986, -989, 988, -991, 990, -992, 990, -993, 990, -995, 994, -997, 996, -999, 998, -1001, 1000, -1002, 1000, -1003, 1000, -1004, 1000, -1005, 1000, -1006, 1000, -1008, 1007, -1010, 1009, -1012, 1011, -1014, 1013, -1016, 1015, -1017, 1015, -1018, 1015, -1020, 1019, -1022, 1021, -1023, 1021, -1024, 1021, -1025, 1021, -1026, 1021, -1027, 1021, -1029, 1028, -1030, 1028, -1031, 1028, -1033, 1032, -1035, 1034, -1036, 1034, -1038, 1037, -1040, 1039, -1042, 1041, -1044, 1043, -1046, 1045, -1048, 1047, -1050, 1049, -1051, 1049, -1052, 1049, -1053, 1049, -1054, 1049, -1055, 1049, -1056, 1049, -1058, 1057, -1060, 1059, -1061, 1059, -1062, 1059, -1063, 1059, -1064, 1059, -1066, 1065, -1068, 1067, -1070, 1069, -1072, 1071, -1074, 1073, -1076, 1075, -1077, 1075, -1079, 1078, -1081, 1080, -1083, 1082, -1085, 1084, -1086, 1084, -1088, 1087, -1090, 1089, -1091, 1089, -1093, 1092, -1094, 1092, -1095, 1092, -1096, 1092, -1097, 1092, -1098, 1092, -1099, 1092, -1101, 1100, -1103, 1102, -1104, 1102, -1106, 1105, -1107, 1105, -1109, 1108, -1111, 1110, -1113, 1112, -1114, 1112, -1116, 1115, -1117, 1115, -1118, 1115, -1119, 1115, -1120, 1115, -1121, 1115, -1123, 1122, -1124, 1122, -1125, 1122, -1126, 1122, -1128, 1127, -1130, 1129, -1132, 1131, -1134, 1133, -1135, 1133, -1136, 1133, -1137, 1133, -1138, 1133, -1139, 1133, -1140, 1133, -1141, 1133, -1142, 1133, -1143, 1133, -1144, 1133, -1146, 1145, -1148, 1147, -1150, 1149, -1152, 1151, -1153, 1151, -1155, 1154, -1157, 1156, -1159, 1158, -1161, 1160, -1162, 1160, -1164, 1163, -1166, 1165, -1167, 1165, -1168, 1165, -1170, 1169, -1172, 1171, -1174, 1173, -1175, 1173, -1177, 1176, -1179, 1178, -1181, 1180, -1183, 1182, -1185, 1184, -1187, 1186, -1189, 1188, -1191, 1190, -1192, 1190, -1194, 1193, -1196, 1195, -1198, 1197, -1199, 1197, -1200, 1197, -1202, 1201, -1204, 1203, -1206, 1205, -1208, 1207, -1210, 1209, -1212, 1211, -1213, 1211, -1215, 1214, -1216, 1214, -1217, 1214, -1218, 1214, -1220, 1219, -1222, 1221, -1223, 1221, -1225, 1224, -1227, 1226, -1229, 1228, -1230, 1228, -1231, 1228, -1233, 1232, -1235, 1234, -1236, 1234, -1238, 1237, -1240, 1239, -1241, 1239, -1242, 1239, -1243, 1239, -1244, 1239, -1245, 1239, -1246, 1239, -1248, 1247, -1250, 1249, -1252, 1251, -1254, 1253, -1256, 1255, -1258, 1257]}

data/leetcode/2015-09-27T13-00-00Z/positions.json

Lines changed: 1 addition & 0 deletions
Large diffs are not rendered by default.

data/leetcode/manifest.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"all": [
3+
"2015-09-27T13-00-00Z"
4+
],
5+
"last": "2015-09-27T13-00-00Z"
6+
}

dev-server.js

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
var devConfig = require('./webpack.local.config');
2+
3+
ensureBuildExists();
4+
5+
// Start webpack:
6+
var webpack = require('webpack');
7+
var WebpackDevServer = require('webpack-dev-server');
8+
var compiler = webpack(devConfig);
9+
10+
new WebpackDevServer(compiler, {
11+
publicPath: devConfig.output.publicPath,
12+
contentBase: "./build",
13+
disableHostCheck: true,
14+
hot: true,
15+
quiet: false,
16+
filename: 'app.js',
17+
stats: { colors: true },
18+
noInfo: false,
19+
historyApiFallback: true
20+
}).listen(devConfig.port, '0.0.0.0', function (err) {
21+
if (err) {
22+
console.log(err);
23+
} else {
24+
console.log('Dev Server listening at http://127.0.0.1:' + devConfig.port);
25+
}
26+
});
27+
28+
function ensureBuildExists() {
29+
var fs = require('fs');
30+
var path = require('path');
31+
var buildDir = path.join(__dirname, 'build');
32+
33+
if (!fs.existsSync(buildDir)) {
34+
fs.mkdirSync(buildDir);
35+
}
36+
37+
var source = path.join(__dirname, 'src', 'index.html');
38+
var dest = path.join(__dirname, 'build', 'index.html');
39+
40+
console.log('Copying ' + source + ' to ' + dest);
41+
fs.createReadStream(source).pipe(fs.createWriteStream(dest));
42+
}

package.json

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
{
2+
"name": "sgraph",
3+
"version": "1.0.0",
4+
"description": "Visualization of solutions",
5+
"main": "index.js",
6+
"scripts": {
7+
"test": "echo \"Error: no test specified\" && exit 1",
8+
"build": "mkdir -p ./build && cp ./src/index.html ./build/ && webpack -p --config webpack.production.config.js",
9+
"start": "PORT=8081 node dev-server.js"
10+
},
11+
"author": "David Kobalia",
12+
"license": "MIT",
13+
"devDependencies": {
14+
"express": "^4.12.3",
15+
"ngraph.generators": "0.0.15",
16+
"react-hot-loader": "^1.2.7",
17+
"webpack-dev-server": "^1.9.0"
18+
},
19+
"dependencies": {
20+
"babel-core": "^5.2.17",
21+
"babel-loader": "^5.0.0",
22+
"bluebird": "^2.9.25",
23+
"bootstrap": "^3.3.4",
24+
"css-loader": "^0.12.0",
25+
"extract-text-webpack-plugin": "^0.8.0",
26+
"file-loader": "^0.8.1",
27+
"history": "^1.17.0",
28+
"keymirror": "^0.1.1",
29+
"less": "^2.5.0",
30+
"less-loader": "^2.2.0",
31+
"maco": "^2.0.3",
32+
"ngraph.events": "0.0.3",
33+
"node-libs-browser": "^0.5.0",
34+
"qs": "^4.0.0",
35+
"rafor": "^1.0.2",
36+
"react": "^0.14.5",
37+
"react-bootstrap": "^0.28.1",
38+
"react-dom": "^0.14.5",
39+
"react-list": "^0.7.10",
40+
"react-router": "^1.0.3",
41+
"style-loader": "^0.12.2",
42+
"three.orientation": "^1.1.0",
43+
"unrender": "git+https://github.com/anvaka/unrender.git",
44+
"url-loader": "^0.5.5",
45+
"webgl-enabled": "^1.0.3",
46+
"webpack": "^1.15.0"
47+
}
48+
}

src/config.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export default {
2+
dataUrl: '/data/'
3+
};

src/destination.jsx

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import React from "react";
2+
3+
const prefix = 'https://raw.githubusercontent.com/blocage/leetcode-algorithms/main/.github/images/';
4+
5+
export default class Destination extends React.Component {
6+
setHoverOn() {
7+
this.setState({ hover: true });
8+
}
9+
10+
setHoverOff() {
11+
this.setState({ hover: false });
12+
}
13+
14+
render() {
15+
let x = this;
16+
let props = x.props;
17+
let isHover = x.state ? x.state.hover : false;
18+
let imageSrc = prefix + props.media;
19+
if (isHover) imageSrc = imageSrc.replace(/_first\.png/, '_150.gif');
20+
if (props.static && props.dynamic) {
21+
imageSrc = isHover ? props.dynamic : props.static;
22+
}
23+
24+
return (
25+
<a className='media col-md-6 col-lg-4' href={props.href}
26+
onMouseEnter={x.setHoverOn.bind(x)} onMouseLeave={x.setHoverOff.bind(x)}>
27+
<div className='media-left'>
28+
<img className='media-object'
29+
width='150px'
30+
height='93px'
31+
src={imageSrc}
32+
alt={props.name}/>
33+
</div>
34+
<div className='media-body'>
35+
<h4 className='media-heading'>{props.name}</h4>
36+
{props.description}
37+
</div>
38+
</a>
39+
);
40+
}
41+
42+
}

src/galaxy/about.jsx

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import React from 'react';
2+
export default require('maco').template(about, React);
3+
4+
function about() {
5+
return (
6+
<div className='label about'>
7+
<a className='reset-color'
8+
target='_blank'
9+
href="https://github.com/blocage">About...</a>
10+
</div>
11+
);
12+
}

src/galaxy/galaxyPage.jsx

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import React from 'react';
2+
import LoadingIndicator from './loadingIndicator.jsx';
3+
import Scene from './scene.jsx';
4+
import appEvents from './service/appEvents.js';
5+
6+
module.exports = require('maco')(galaxyPage, React);
7+
8+
function galaxyPage(x) {
9+
var currentPath;
10+
11+
x.render = function() {
12+
// This doesn't seem to belong here. The whole routing system is a mess
13+
// TODO: Come up with better routing
14+
loadGraphIfRouteChanged();
15+
16+
return (
17+
<div>
18+
<LoadingIndicator />
19+
<Scene />
20+
</div>
21+
);
22+
};
23+
24+
function loadGraphIfRouteChanged() {
25+
var routeChanged = x.props.params.name !== currentPath;
26+
if (routeChanged) {
27+
currentPath = x.props.params.name;
28+
appEvents.downloadGraphRequested.fire(currentPath);
29+
}
30+
appEvents.queryChanged.fire();
31+
}
32+
}

src/galaxy/help.jsx

Lines changed: 175 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,175 @@
1+
/**
2+
* This component shows basic navigation help. The idea is to show it only
3+
* first time when user opens. All subsequent page opening should not trigger
4+
* help screen.
5+
*
6+
* The only possible way to show help again is by triggerign "show help"
7+
* action, which is currently bound to mouse wheel event
8+
*/
9+
import React from 'react';
10+
import appEvents from './service/appEvents.js';
11+
import Key from './utils/key.js';
12+
13+
export default require('maco')(help, React);
14+
15+
var helpWasShown = false;
16+
17+
function help(x) {
18+
var graphDownloaded = false;
19+
20+
x.render = function() {
21+
if (window.orientation !== undefined) {
22+
// no need to show help on orientation enabled devices
23+
return null;
24+
}
25+
26+
if (helpWasShown) {
27+
// no need to annoy people
28+
return null;
29+
}
30+
31+
if (!graphDownloaded) {
32+
// Show help only after all is downloaded
33+
return null;
34+
}
35+
36+
return (
37+
<div className='navigation-help'>
38+
<h3>Movement manual</h3>
39+
<table><tbody>
40+
<tr>
41+
<td colSpan="2"><code className='important-key'>mouse wheel</code></td>
42+
<td colSpan="2">show this help</td>
43+
</tr>
44+
<tr className='spacer-row'>
45+
<td colSpan='2'><code className='important-key' >any key</code></td>
46+
<td colSpan='2'>hide this help</td>
47+
</tr>
48+
<tr>
49+
<td><code>W</code></td>
50+
<td>Move forward</td>
51+
<td><code>Up</code></td>
52+
<td>Rotate up</td>
53+
</tr>
54+
<tr>
55+
<td><code>S</code></td>
56+
<td>Move backward</td>
57+
<td><code>Down</code></td>
58+
<td>Rotate down</td>
59+
</tr>
60+
<tr>
61+
<td><code>A</code></td>
62+
<td>Move left</td>
63+
<td><code>Left</code></td>
64+
<td>Rotate left</td>
65+
</tr>
66+
<tr>
67+
<td><code>D</code></td>
68+
<td>Move right</td>
69+
<td><code>Right</code></td>
70+
<td>Rotate right</td>
71+
</tr>
72+
<tr>
73+
<td><code>Q</code></td>
74+
<td>Roll right</td>
75+
<td><code>R</code></td>
76+
<td>Fly up</td>
77+
</tr>
78+
<tr>
79+
<td><code>E</code></td>
80+
<td>Roll left</td>
81+
<td><code>F</code></td>
82+
<td>Fly down</td>
83+
</tr>
84+
<tr>
85+
<td><code>L</code></td>
86+
<td>Toggle links</td>
87+
<td><code>spacebar</code></td>
88+
<td>Toggle Steering</td>
89+
</tr>
90+
<tr>
91+
<td><code>shift</code></td>
92+
<td>Move faster</td>
93+
<td><code></code></td>
94+
<td></td>
95+
</tr>
96+
</tbody></table>
97+
</div>
98+
);
99+
};
100+
101+
x.componentDidMount = function () {
102+
if (window.orientation !== undefined) return;
103+
appEvents.graphDownloaded.on(showHelpIfNeeded);
104+
appEvents.downloadGraphRequested.on(resetHelp);
105+
appEvents.toggleHelp.on(toggleHelp);
106+
107+
listenToKeys();
108+
listenToWheel();
109+
}
110+
111+
x.componentWillUnmount = function () {
112+
if (window.orientation !== undefined) return;
113+
appEvents.graphDownloaded.off(showHelpIfNeeded);
114+
appEvents.downloadGraphRequested.off(resetHelp);
115+
appEvents.toggleHelp.off(toggleHelp);
116+
117+
releaseKeyListener();
118+
releaseWheel();
119+
}
120+
121+
function showHelpIfNeeded() {
122+
if (helpWasShown) return;
123+
graphDownloaded = true;
124+
125+
x.forceUpdate();
126+
}
127+
128+
function toggleHelp() {
129+
helpWasShown = !helpWasShown;
130+
x.forceUpdate();
131+
}
132+
133+
function resetHelp() {
134+
graphDownloaded = false;
135+
x.forceUpdate();
136+
}
137+
138+
function handlekey(e) {
139+
if (Key.isModifier(e)) {
140+
// ignore modifiers
141+
return;
142+
}
143+
var needsUpdate = !helpWasShown;
144+
helpWasShown = true;
145+
146+
if (needsUpdate) {
147+
x.forceUpdate();
148+
}
149+
}
150+
151+
function handlewheel(e) {
152+
// only show when used on scene
153+
if (e.target && e.target.nodeName === 'CANVAS') {
154+
helpWasShown = false;
155+
x.forceUpdate();
156+
appEvents.focusScene.fire();
157+
}
158+
}
159+
160+
function listenToKeys() {
161+
document.body.addEventListener('keydown', handlekey);
162+
}
163+
164+
function listenToWheel() {
165+
document.body.addEventListener('wheel', handlewheel, true);
166+
}
167+
168+
function releaseKeyListener() {
169+
document.body.removeEventListener('keydown', handlekey, true);
170+
}
171+
172+
function releaseWheel() {
173+
document.body.removeEventListener('wheel', handlewheel, true);
174+
}
175+
}

0 commit comments

Comments
 (0)