diff --git a/.circleci/config.yml b/.circleci/config.yml index 8e3f94c359..9b0a25e279 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -130,23 +130,14 @@ jobs: paths: - "repo/examples" - lint_js: + lint: executor: node steps: - attach_workspace: at: .. - - run: npm run lint:js - - lint_ts: - executor: node - - steps: - - attach_workspace: - at: .. - - - run: npm run lint:ts + - run: npm run lint test_unit: executor: node @@ -234,11 +225,7 @@ workflows: - prepare - build - # - lint_js: - # requires: - # - prepare - - - lint_ts: + - lint: requires: - prepare @@ -259,10 +246,9 @@ workflows: - gh_pages: requires: - # - lint_js - build - examples - - lint_ts + - lint - prepare - test_e2e_functional - test_e2e_visual @@ -274,11 +260,10 @@ workflows: - release: requires: - # - lint_js - build - examples - gh_pages - - lint_ts + - lint - prepare - test_e2e_functional - test_e2e_visual diff --git a/.eslintignore b/.eslintignore index 8c3823b045..55d9b972ef 100644 --- a/.eslintignore +++ b/.eslintignore @@ -1,3 +1,15 @@ -*.min.js -*.min.ts -dist/**/* +/cypress/fixtures/**/*.js +/cypress/fixtures/**/*.js.map +/cypress/integration/**/*.js +/cypress/integration/**/*.js.map +/cypress/pages/**/*.js +/cypress/pages/**/*.js.map +/cypress/screenshots/ +/cypress/snapshots/ +/cypress/support/**/*.js +/cypress/support/**/*.js.map +/cypress/videos/ +/examples/examples.css +/examples/index.html +/examples/static/ +/examples/thumbnails/ diff --git a/.eslintrc.js b/.eslintrc.js index 3534192829..48dc37f7bc 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -10,8 +10,9 @@ module.exports = { parser: '@typescript-eslint/parser', parserOptions: { sourceType: "module", - ecmaVersion: 2019, - project: 'tsconfig.json', + ecmaVersion: 2020, + project: 'tsconfig.lint.json', + extraFileExtensions: [".json"], }, plugins: ["prettier", "@typescript-eslint", "cypress"], @@ -22,12 +23,12 @@ module.exports = { rules: { 'prettier/prettier': ['off'], - complexity: [2, 55], - "max-statements": [2, 115], - "no-unreachable": 1, - "no-useless-escape": 0, + complexity: ['error', 55], + "max-statements": ['error', 115], + "no-unreachable": 'warn', + "no-useless-escape": 'off', - "no-console": 0, + "no-console": 'off', // To flag presence of console.log without breaking linting: //"no-console": ["warn", { allow: ["warn", "error"] }], @@ -39,13 +40,16 @@ module.exports = { ArrowFunctionExpression: false } }], - "valid-jsdoc": [2, { + "valid-jsdoc": ['error', { requireReturnDescription: false, requireReturn: false, requireParamDescription: false, requireReturnType: true }], - "guard-for-in": 1, + "guard-for-in": 'warn', + + "no-var": "error", + "prefer-const": "error", }, overrides: [ { diff --git a/examples/network/datasources/WorldCup2014.js b/examples/network/datasources/WorldCup2014.js index f08a4a41c3..eb0414ae46 100644 --- a/examples/network/datasources/WorldCup2014.js +++ b/examples/network/datasources/WorldCup2014.js @@ -1,3 +1,8 @@ +// These variables will be injected into a page that will use them. +/* eslint no-unused-vars: "off" */ +// Const won't work here, only var. +/* eslint no-var: "off" */ + var nodes = [ {id: 1, label: 'Abdelmoumene Djabou', title: 'Country: ' + 'Algeria' + '
' + 'Team: ' + 'Club Africain', value: 22, group: 24, x: -1392.5499, y: 1124.1614}, {id: 2, label: 'Abel Aguilar', title: 'Country: ' + 'Colombia' + '
' + 'Team: ' + 'Toulouse', value: 24, group: 11, x: -660.82574, y: 1009.18976}, diff --git a/examples/network/datasources/largeHierarchicalDataset.js b/examples/network/datasources/largeHierarchicalDataset.js index cc0607e2f4..4b7face81b 100644 --- a/examples/network/datasources/largeHierarchicalDataset.js +++ b/examples/network/datasources/largeHierarchicalDataset.js @@ -1,2 +1,5 @@ -var nodes = [{id:0,label:"0"},{id:1,label:"1"},{id:2,label:"2"},{id:3,label:"3"},{id:4,label:"4"},{id:5,label:"5"},{id:6,label:"6"},{id:7,label:"7"},{id:8,label:"8"},{id:9,label:"9"},{id:10,label:"10"},{id:11,label:"11"},{id:12,label:"12"},{id:13,label:"13"},{id:14,label:"14"},{id:15,label:"15"},{id:16,label:"16"},{id:17,label:"17"},{id:18,label:"18"},{id:19,label:"19"},{id:20,label:"20"},{id:21,label:"21"},{id:22,label:"22"},{id:23,label:"23"},{id:24,label:"24"},{id:25,label:"25"},{id:26,label:"26"},{id:27,label:"27"},{id:28,label:"28"},{id:29,label:"29"},{id:30,label:"30"},{id:31,label:"31"},{id:32,label:"32"},{id:33,label:"33"},{id:34,label:"34"},{id:35,label:"35"},{id:36,label:"36"},{id:37,label:"37"},{id:38,label:"38"},{id:39,label:"39"},{id:40,label:"40"},{id:41,label:"41"},{id:42,label:"42"},{id:43,label:"43"},{id:44,label:"44"},{id:45,label:"45"},{id:46,label:"46"},{id:47,label:"47"},{id:48,label:"48"},{id:49,label:"49"},{id:50,label:"50"},{id:51,label:"51"},{id:52,label:"52"},{id:53,label:"53"},{id:54,label:"54"},{id:55,label:"55"},{id:56,label:"56"},{id:57,label:"57"},{id:58,label:"58"},{id:59,label:"59"},{id:60,label:"60"},{id:61,label:"61"},{id:62,label:"62"},{id:63,label:"63"},{id:64,label:"64"},{id:65,label:"65"},{id:66,label:"66"},{id:67,label:"67"},{id:68,label:"68"},{id:69,label:"69"},{id:70,label:"70"},{id:71,label:"71"},{id:72,label:"72"},{id:73,label:"73"},{id:74,label:"74"},{id:75,label:"75"},{id:76,label:"76"},{id:77,label:"77"},{id:78,label:"78"},{id:79,label:"79"},{id:80,label:"80"},{id:81,label:"81"},{id:82,label:"82"},{id:83,label:"83"},{id:84,label:"84"},{id:85,label:"85"},{id:86,label:"86"},{id:87,label:"87"},{id:88,label:"88"},{id:89,label:"89"},{id:90,label:"90"},{id:91,label:"91"},{id:92,label:"92"},{id:93,label:"93"},{id:94,label:"94"},{id:95,label:"95"},{id:96,label:"96"},{id:97,label:"97"},{id:98,label:"98"},{id:99,label:"99"},{id:100,label:"100"},{id:101,label:"101"},{id:102,label:"102"},{id:103,label:"103"},{id:104,label:"104"},{id:105,label:"105"},{id:106,label:"106"},{id:107,label:"107"},{id:108,label:"108"},{id:109,label:"109"},{id:110,label:"110"},{id:111,label:"111"},{id:112,label:"112"},{id:113,label:"113"},{id:114,label:"114"},{id:115,label:"115"},{id:116,label:"116"},{id:117,label:"117"},{id:118,label:"118"},{id:119,label:"119"},{id:120,label:"120"},{id:121,label:"121"},{id:122,label:"122"},{id:123,label:"123"},{id:124,label:"124"},{id:125,label:"125"},{id:126,label:"126"},{id:127,label:"127"},{id:128,label:"128"},{id:129,label:"129"},{id:130,label:"130"},{id:131,label:"131"},{id:132,label:"132"},{id:133,label:"133"},{id:134,label:"134"},{id:135,label:"135"},{id:136,label:"136"},{id:137,label:"137"},{id:138,label:"138"},{id:139,label:"139"},{id:140,label:"140"},{id:141,label:"141"},{id:142,label:"142"},{id:143,label:"143"},{id:144,label:"144"},{id:145,label:"145"},{id:146,label:"146"},{id:147,label:"147"},{id:148,label:"148"},{id:149,label:"149"},{id:150,label:"150"},{id:151,label:"151"},{id:152,label:"152"},{id:153,label:"153"},{id:154,label:"154"},{id:155,label:"155"},{id:156,label:"156"},{id:157,label:"157"},{id:158,label:"158"},{id:159,label:"159"},{id:160,label:"160"},{id:161,label:"161"},{id:162,label:"162"},{id:163,label:"163"},{id:164,label:"164"},{id:165,label:"165"},{id:166,label:"166"},{id:167,label:"167"},{id:168,label:"168"},{id:169,label:"169"},{id:170,label:"170"},{id:171,label:"171"},{id:172,label:"172"},{id:173,label:"173"},{id:174,label:"174"},{id:175,label:"175"},{id:176,label:"176"},{id:177,label:"177"},{id:178,label:"178"},{id:179,label:"179"},{id:180,label:"180"},{id:181,label:"181"},{id:182,label:"182"},{id:183,label:"183"},{id:184,label:"184"},{id:185,label:"185"},{id:186,label:"186"},{id:187,label:"187"},{id:188,label:"188"},{id:189,label:"189"},{id:190,label:"190"},{id:191,label:"191"},{id:192,label:"192"},{id:193,label:"193"},{id:194,label:"194"},{id:195,label:"195"},{id:196,label:"196"},{id:197,label:"197"},{id:198,label:"198"},{id:199,label:"199"},{id:200,label:"200"},{id:201,label:"201"},{id:202,label:"202"},{id:203,label:"203"},{id:204,label:"204"},{id:205,label:"205"},{id:206,label:"206"},{id:207,label:"207"},{id:208,label:"208"},{id:209,label:"209"},{id:210,label:"210"},{id:211,label:"211"},{id:212,label:"212"},{id:213,label:"213"},{id:214,label:"214"},{id:215,label:"215"},{id:216,label:"216"},{id:217,label:"217"},{id:218,label:"218"},{id:219,label:"219"},{id:220,label:"220"},{id:221,label:"221"},{id:222,label:"222"},{id:223,label:"223"},{id:224,label:"224"},{id:225,label:"225"},{id:226,label:"226"},{id:227,label:"227"},{id:228,label:"228"},{id:229,label:"229"},{id:230,label:"230"},{id:231,label:"231"},{id:232,label:"232"},{id:233,label:"233"},{id:234,label:"234"},{id:235,label:"235"},{id:236,label:"236"},{id:237,label:"237"},{id:238,label:"238"},{id:239,label:"239"},{id:240,label:"240"},{id:241,label:"241"},{id:242,label:"242"},{id:243,label:"243"},{id:244,label:"244"},{id:245,label:"245"},{id:246,label:"246"},{id:247,label:"247"},{id:248,label:"248"},{id:249,label:"249"},{id:250,label:"250"},{id:251,label:"251"},{id:252,label:"252"},{id:253,label:"253"},{id:254,label:"254"},{id:255,label:"255"},{id:256,label:"256"},{id:257,label:"257"},{id:258,label:"258"},{id:259,label:"259"},{id:260,label:"260"},{id:261,label:"261"},{id:262,label:"262"},{id:263,label:"263"},{id:264,label:"264"},{id:265,label:"265"},{id:266,label:"266"},{id:267,label:"267"},{id:268,label:"268"},{id:269,label:"269"},{id:270,label:"270"},{id:271,label:"271"},{id:272,label:"272"},{id:273,label:"273"},{id:274,label:"274"},{id:275,label:"275"},{id:276,label:"276"},{id:277,label:"277"},{id:278,label:"278"},{id:279,label:"279"},{id:280,label:"280"},{id:281,label:"281"},{id:282,label:"282"},{id:283,label:"283"},{id:284,label:"284"},{id:285,label:"285"},{id:286,label:"286"},{id:287,label:"287"},{id:288,label:"288"},{id:289,label:"289"},{id:290,label:"290"},{id:291,label:"291"},{id:292,label:"292"},{id:293,label:"293"},{id:294,label:"294"},{id:295,label:"295"},{id:296,label:"296"},{id:297,label:"297"},{id:298,label:"298"},{id:299,label:"299"},{id:300,label:"300"},{id:301,label:"301"},{id:302,label:"302"},{id:303,label:"303"},{id:304,label:"304"},{id:305,label:"305"},{id:306,label:"306"},{id:307,label:"307"},{id:308,label:"308"},{id:309,label:"309"},{id:310,label:"310"},{id:311,label:"311"},{id:312,label:"312"},{id:313,label:"313"},{id:314,label:"314"},{id:315,label:"315"},{id:316,label:"316"},{id:317,label:"317"},{id:318,label:"318"},{id:319,label:"319"},{id:320,label:"320"},{id:321,label:"321"},{id:322,label:"322"},{id:323,label:"323"},{id:324,label:"324"},{id:325,label:"325"},{id:326,label:"326"},{id:327,label:"327"},{id:328,label:"328"},{id:329,label:"329"},{id:330,label:"330"},{id:331,label:"331"},{id:332,label:"332"},{id:333,label:"333"},{id:334,label:"334"},{id:335,label:"335"},{id:336,label:"336"},{id:337,label:"337"},{id:338,label:"338"},{id:339,label:"339"},{id:340,label:"340"},{id:341,label:"341"},{id:342,label:"342"},{id:343,label:"343"},{id:344,label:"344"},{id:345,label:"345"},{id:346,label:"346"},{id:347,label:"347"}]; -var edges = [{from:331,to:0,id:"e0"},{from:331,to:1,id:"e1"},{from:302,to:2,id:"e2"},{from:321,to:3,id:"e3"},{from:323,to:4,id:"e4"},{from:326,to:5,id:"e5"},{from:24,to:6,id:"e6"},{from:327,to:7,id:"e7"},{from:50,to:8,id:"e8"},{from:275,to:9,id:"e9"},{from:327,to:10,id:"e10"},{from:30,to:11,id:"e11"},{from:327,to:12,id:"e12"},{from:270,to:13,id:"e13"},{from:204,to:14,id:"e14"},{from:42,to:15,id:"e15"},{from:140,to:16,id:"e16"},{from:327,to:17,id:"e17"},{from:80,to:18,id:"e18"},{from:24,to:19,id:"e19"},{from:60,to:20,id:"e20"},{from:323,to:21,id:"e21"},{from:328,to:22,id:"e22"},{from:58,to:23,id:"e23"},{from:0,to:24,id:"e24"},{from:50,to:25,id:"e25"},{from:50,to:26,id:"e26"},{from:36,to:27,id:"e27"},{from:36,to:28,id:"e28"},{from:303,to:29,id:"e29"},{from:1,to:30,id:"e30"},{from:326,to:31,id:"e31"},{from:81,to:32,id:"e32"},{from:60,to:33,id:"e33"},{from:62,to:34,id:"e34"},{from:24,to:35,id:"e35"},{from:319,to:36,id:"e36"},{from:58,to:37,id:"e37"},{from:58,to:38,id:"e38"},{from:80,to:39,id:"e39"},{from:35,to:40,id:"e40"},{from:73,to:41,id:"e41"},{from:327,to:42,id:"e42"},{from:301,to:43,id:"e43"},{from:36,to:44,id:"e44"},{from:322,to:45,id:"e45"},{from:69,to:46,id:"e46"},{from:329,to:47,id:"e47"},{from:199,to:48,id:"e48"},{from:321,to:49,id:"e49"},{from:331,to:50,id:"e50"},{from:70,to:51,id:"e51"},{from:329,to:52,id:"e52"},{from:140,to:53,id:"e53"},{from:1,to:54,id:"e54"},{from:330,to:55,id:"e55"},{from:304,to:56,id:"e56"},{from:214,to:57,id:"e57"},{from:84,to:58,id:"e58"},{from:141,to:59,id:"e59"},{from:36,to:60,id:"e60"},{from:323,to:61,id:"e61"},{from:326,to:62,id:"e62"},{from:323,to:63,id:"e63"},{from:328,to:64,id:"e64"},{from:331,to:65,id:"e65"},{from:140,to:66,id:"e66"},{from:24,to:67,id:"e67"},{from:324,to:68,id:"e68"},{from:326,to:69,id:"e69"},{from:323,to:70,id:"e70"},{from:283,to:71,id:"e71"},{from:27,to:72,id:"e72"},{from:50,to:73,id:"e73"},{from:325,to:74,id:"e74"},{from:58,to:75,id:"e75"},{from:323,to:76,id:"e76"},{from:15,to:77,id:"e77"},{from:70,to:78,id:"e78"},{from:22,to:79,id:"e79"},{from:328,to:80,id:"e80"},{from:0,to:81,id:"e81"},{from:322,to:82,id:"e82"},{from:326,to:83,id:"e83"},{from:325,to:84,id:"e84"},{from:331,to:85,id:"e85"},{from:184,to:86,id:"e86"},{from:250,to:87,id:"e87"},{from:321,to:88,id:"e88"},{from:322,to:89,id:"e89"},{from:326,to:90,id:"e90"},{from:162,to:91,id:"e91"},{from:162,to:92,id:"e92"},{from:99,to:93,id:"e93"},{from:320,to:94,id:"e94"},{from:326,to:95,id:"e95"},{from:0,to:96,id:"e96"},{from:326,to:97,id:"e97"},{from:327,to:98,id:"e98"},{from:0,to:99,id:"e99"},{from:327,to:100,id:"e100"},{from:0,to:101,id:"e101"},{from:0,to:102,id:"e102"},{from:328,to:103,id:"e103"},{from:256,to:104,id:"e104"},{from:326,to:105,id:"e105"},{from:81,to:106,id:"e106"},{from:322,to:107,id:"e107"},{from:326,to:108,id:"e108"},{from:8,to:109,id:"e109"},{from:204,to:110,id:"e110"},{from:163,to:111,id:"e111"},{from:330,to:112,id:"e112"},{from:330,to:113,id:"e113"},{from:324,to:114,id:"e114"},{from:42,to:115,id:"e115"},{from:328,to:116,id:"e116"},{from:331,to:117,id:"e117"},{from:321,to:118,id:"e118"},{from:141,to:119,id:"e119"},{from:321,to:120,id:"e120"},{from:330,to:121,id:"e121"},{from:324,to:122,id:"e122"},{from:199,to:123,id:"e123"},{from:302,to:124,id:"e124"},{from:328,to:125,id:"e125"},{from:307,to:126,id:"e126"},{from:321,to:127,id:"e127"},{from:329,to:128,id:"e128"},{from:0,to:129,id:"e129"},{from:331,to:130,id:"e130"},{from:287,to:131,id:"e131"},{from:322,to:132,id:"e132"},{from:1,to:133,id:"e133"},{from:304,to:134,id:"e134"},{from:295,to:135,id:"e135"},{from:42,to:136,id:"e136"},{from:104,to:137,id:"e137"},{from:321,to:138,id:"e138"},{from:204,to:139,id:"e139"},{from:109,to:140,id:"e140"},{from:324,to:141,id:"e141"},{from:70,to:142,id:"e142"},{from:73,to:143,id:"e143"},{from:304,to:144,id:"e144"},{from:0,to:145,id:"e145"},{from:0,to:146,id:"e146"},{from:327,to:147,id:"e147"},{from:141,to:148,id:"e148"},{from:323,to:149,id:"e149"},{from:184,to:150,id:"e150"},{from:324,to:151,id:"e151"},{from:330,to:152,id:"e152"},{from:75,to:153,id:"e153"},{from:328,to:154,id:"e154"},{from:60,to:155,id:"e155"},{from:331,to:156,id:"e156"},{from:153,to:157,id:"e157"},{from:214,to:158,id:"e158"},{from:129,to:159,id:"e159"},{from:331,to:160,id:"e160"},{from:324,to:161,id:"e161"},{from:322,to:162,id:"e162"},{from:195,to:163,id:"e163"},{from:323,to:164,id:"e164"},{from:275,to:165,id:"e165"},{from:58,to:166,id:"e166"},{from:321,to:167,id:"e167"},{from:325,to:168,id:"e168"},{from:324,to:169,id:"e169"},{from:330,to:170,id:"e170"},{from:330,to:171,id:"e171"},{from:331,to:172,id:"e172"},{from:1,to:173,id:"e173"},{from:50,to:174,id:"e174"},{from:327,to:175,id:"e175"},{from:331,to:176,id:"e176"},{from:324,to:177,id:"e177"},{from:204,to:178,id:"e178"},{from:330,to:179,id:"e179"},{from:330,to:180,id:"e180"},{from:50,to:181,id:"e181"},{from:323,to:182,id:"e182"},{from:106,to:183,id:"e183"},{from:70,to:184,id:"e184"},{from:58,to:185,id:"e185"},{from:0,to:186,id:"e186"},{from:321,to:187,id:"e187"},{from:304,to:188,id:"e188"},{from:307,to:189,id:"e189"},{from:140,to:190,id:"e190"},{from:104,to:191,id:"e191"},{from:50,to:192,id:"e192"},{from:60,to:193,id:"e193"},{from:27,to:194,id:"e194"},{from:297,to:195,id:"e195"},{from:321,to:196,id:"e196"},{from:27,to:197,id:"e197"},{from:1,to:198,id:"e198"},{from:321,to:199,id:"e199"},{from:75,to:200,id:"e200"},{from:30,to:201,id:"e201"},{from:50,to:202,id:"e202"},{from:325,to:203,id:"e203"},{from:173,to:204,id:"e204"},{from:307,to:205,id:"e205"},{from:275,to:206,id:"e206"},{from:275,to:207,id:"e207"},{from:331,to:208,id:"e208"},{from:109,to:209,id:"e209"},{from:0,to:210,id:"e210"},{from:327,to:211,id:"e211"},{from:275,to:212,id:"e212"},{from:304,to:213,id:"e213"},{from:104,to:214,id:"e214"},{from:327,to:215,id:"e215"},{from:53,to:216,id:"e216"},{from:60,to:217,id:"e217"},{from:60,to:218,id:"e218"},{from:109,to:219,id:"e219"},{from:192,to:220,id:"e220"},{from:275,to:221,id:"e221"},{from:326,to:222,id:"e222"},{from:250,to:223,id:"e223"},{from:325,to:224,id:"e224"},{from:321,to:225,id:"e225"},{from:1,to:226,id:"e226"},{from:323,to:227,id:"e227"},{from:322,to:228,id:"e228"},{from:327,to:229,id:"e229"},{from:256,to:230,id:"e230"},{from:250,to:231,id:"e231"},{from:330,to:232,id:"e232"},{from:36,to:233,id:"e233"},{from:328,to:234,id:"e234"},{from:323,to:235,id:"e235"},{from:327,to:236,id:"e236"},{from:328,to:237,id:"e237"},{from:250,to:238,id:"e238"},{from:326,to:239,id:"e239"},{from:327,to:240,id:"e240"},{from:329,to:241,id:"e241"},{from:329,to:242,id:"e242"},{from:109,to:243,id:"e243"},{from:323,to:244,id:"e244"},{from:220,to:245,id:"e245"},{from:326,to:246,id:"e246"},{from:267,to:247,id:"e247"},{from:250,to:248,id:"e248"},{from:256,to:249,id:"e249"},{from:322,to:250,id:"e250"},{from:322,to:251,id:"e251"},{from:322,to:252,id:"e252"},{from:109,to:253,id:"e253"},{from:101,to:254,id:"e254"},{from:328,to:255,id:"e255"},{from:331,to:256,id:"e256"},{from:327,to:257,id:"e257"},{from:24,to:258,id:"e258"},{from:124,to:259,id:"e259"},{from:324,to:260,id:"e260"},{from:322,to:261,id:"e261"},{from:322,to:262,id:"e262"},{from:321,to:263,id:"e263"},{from:283,to:264,id:"e264"},{from:318,to:265,id:"e265"},{from:30,to:266,id:"e266"},{from:8,to:267,id:"e267"},{from:140,to:268,id:"e268"},{from:322,to:269,id:"e269"},{from:24,to:270,id:"e270"},{from:9,to:271,id:"e271"},{from:322,to:272,id:"e272"},{from:99,to:273,id:"e273"},{from:24,to:274,id:"e274"},{from:282,to:275,id:"e275"},{from:250,to:276,id:"e276"},{from:70,to:277,id:"e277"},{from:328,to:278,id:"e278"},{from:250,to:279,id:"e279"},{from:50,to:280,id:"e280"},{from:250,to:281,id:"e281"},{from:173,to:282,id:"e282"},{from:320,to:283,id:"e283"},{from:320,to:284,id:"e284"},{from:250,to:285,id:"e285"},{from:325,to:286,id:"e286"},{from:1,to:287,id:"e287"},{from:1,to:288,id:"e288"},{from:109,to:289,id:"e289"},{from:50,to:290,id:"e290"},{from:250,to:291,id:"e291"},{from:195,to:292,id:"e292"},{from:320,to:293,id:"e293"},{from:331,to:294,id:"e294"},{from:331,to:295,id:"e295"},{from:101,to:296,id:"e296"},{from:58,to:297,id:"e297"},{from:24,to:298,id:"e298"},{from:291,to:299,id:"e299"},{from:302,to:300,id:"e300"},{from:323,to:301,id:"e301"},{from:226,to:302,id:"e302"},{from:53,to:303,id:"e303"},{from:110,to:304,id:"e304"},{from:163,to:305,id:"e305"},{from:324,to:306,id:"e306"},{from:304,to:307,id:"e307"},{from:322,to:308,id:"e308"},{from:140,to:309,id:"e309"},{from:323,to:310,id:"e310"},{from:0,to:311,id:"e311"},{from:250,to:312,id:"e312"},{from:30,to:313,id:"e313"},{from:58,to:314,id:"e314"},{from:104,to:315,id:"e315"},{from:75,to:316,id:"e316"},{from:323,to:317,id:"e317"},{from:321,to:318,id:"e318"},{from:256,to:319,id:"e319"},{from:250,to:320,id:"e320"},{from:330,to:321,id:"e321"},{from:327,to:322,id:"e322"},{from:326,to:323,id:"e323"},{from:328,to:324,id:"e324"},{from:328,to:325,id:"e325"},{from:327,to:326,id:"e326"},{from:0,to:327,id:"e327"},{from:70,to:328,id:"e328"},{from:327,to:329,id:"e329"},{from:324,to:330,id:"e330"},{from:69,to:332,id:"e331"},{from:346,to:333,id:"e332"},{from:346,to:334,id:"e333"},{from:337,to:335,id:"e334"},{from:106,to:336,id:"e335"},{from:341,to:337,id:"e336"},{from:341,to:338,id:"e337"},{from:346,to:339,id:"e338"},{from:337,to:340,id:"e339"},{from:334,to:341,id:"e340"},{from:334,to:342,id:"e341"},{from:334,to:343,id:"e342"},{from:334,to:344,id:"e343"},{from:84,to:345,id:"e344"},{from:14,to:346,id:"e345"},{from:331,to:347,id:"e346"}] +// These variables will be injected into a page that will use them. +/* eslint no-unused-vars: "off" */ + +const nodes = [{id:0,label:"0"},{id:1,label:"1"},{id:2,label:"2"},{id:3,label:"3"},{id:4,label:"4"},{id:5,label:"5"},{id:6,label:"6"},{id:7,label:"7"},{id:8,label:"8"},{id:9,label:"9"},{id:10,label:"10"},{id:11,label:"11"},{id:12,label:"12"},{id:13,label:"13"},{id:14,label:"14"},{id:15,label:"15"},{id:16,label:"16"},{id:17,label:"17"},{id:18,label:"18"},{id:19,label:"19"},{id:20,label:"20"},{id:21,label:"21"},{id:22,label:"22"},{id:23,label:"23"},{id:24,label:"24"},{id:25,label:"25"},{id:26,label:"26"},{id:27,label:"27"},{id:28,label:"28"},{id:29,label:"29"},{id:30,label:"30"},{id:31,label:"31"},{id:32,label:"32"},{id:33,label:"33"},{id:34,label:"34"},{id:35,label:"35"},{id:36,label:"36"},{id:37,label:"37"},{id:38,label:"38"},{id:39,label:"39"},{id:40,label:"40"},{id:41,label:"41"},{id:42,label:"42"},{id:43,label:"43"},{id:44,label:"44"},{id:45,label:"45"},{id:46,label:"46"},{id:47,label:"47"},{id:48,label:"48"},{id:49,label:"49"},{id:50,label:"50"},{id:51,label:"51"},{id:52,label:"52"},{id:53,label:"53"},{id:54,label:"54"},{id:55,label:"55"},{id:56,label:"56"},{id:57,label:"57"},{id:58,label:"58"},{id:59,label:"59"},{id:60,label:"60"},{id:61,label:"61"},{id:62,label:"62"},{id:63,label:"63"},{id:64,label:"64"},{id:65,label:"65"},{id:66,label:"66"},{id:67,label:"67"},{id:68,label:"68"},{id:69,label:"69"},{id:70,label:"70"},{id:71,label:"71"},{id:72,label:"72"},{id:73,label:"73"},{id:74,label:"74"},{id:75,label:"75"},{id:76,label:"76"},{id:77,label:"77"},{id:78,label:"78"},{id:79,label:"79"},{id:80,label:"80"},{id:81,label:"81"},{id:82,label:"82"},{id:83,label:"83"},{id:84,label:"84"},{id:85,label:"85"},{id:86,label:"86"},{id:87,label:"87"},{id:88,label:"88"},{id:89,label:"89"},{id:90,label:"90"},{id:91,label:"91"},{id:92,label:"92"},{id:93,label:"93"},{id:94,label:"94"},{id:95,label:"95"},{id:96,label:"96"},{id:97,label:"97"},{id:98,label:"98"},{id:99,label:"99"},{id:100,label:"100"},{id:101,label:"101"},{id:102,label:"102"},{id:103,label:"103"},{id:104,label:"104"},{id:105,label:"105"},{id:106,label:"106"},{id:107,label:"107"},{id:108,label:"108"},{id:109,label:"109"},{id:110,label:"110"},{id:111,label:"111"},{id:112,label:"112"},{id:113,label:"113"},{id:114,label:"114"},{id:115,label:"115"},{id:116,label:"116"},{id:117,label:"117"},{id:118,label:"118"},{id:119,label:"119"},{id:120,label:"120"},{id:121,label:"121"},{id:122,label:"122"},{id:123,label:"123"},{id:124,label:"124"},{id:125,label:"125"},{id:126,label:"126"},{id:127,label:"127"},{id:128,label:"128"},{id:129,label:"129"},{id:130,label:"130"},{id:131,label:"131"},{id:132,label:"132"},{id:133,label:"133"},{id:134,label:"134"},{id:135,label:"135"},{id:136,label:"136"},{id:137,label:"137"},{id:138,label:"138"},{id:139,label:"139"},{id:140,label:"140"},{id:141,label:"141"},{id:142,label:"142"},{id:143,label:"143"},{id:144,label:"144"},{id:145,label:"145"},{id:146,label:"146"},{id:147,label:"147"},{id:148,label:"148"},{id:149,label:"149"},{id:150,label:"150"},{id:151,label:"151"},{id:152,label:"152"},{id:153,label:"153"},{id:154,label:"154"},{id:155,label:"155"},{id:156,label:"156"},{id:157,label:"157"},{id:158,label:"158"},{id:159,label:"159"},{id:160,label:"160"},{id:161,label:"161"},{id:162,label:"162"},{id:163,label:"163"},{id:164,label:"164"},{id:165,label:"165"},{id:166,label:"166"},{id:167,label:"167"},{id:168,label:"168"},{id:169,label:"169"},{id:170,label:"170"},{id:171,label:"171"},{id:172,label:"172"},{id:173,label:"173"},{id:174,label:"174"},{id:175,label:"175"},{id:176,label:"176"},{id:177,label:"177"},{id:178,label:"178"},{id:179,label:"179"},{id:180,label:"180"},{id:181,label:"181"},{id:182,label:"182"},{id:183,label:"183"},{id:184,label:"184"},{id:185,label:"185"},{id:186,label:"186"},{id:187,label:"187"},{id:188,label:"188"},{id:189,label:"189"},{id:190,label:"190"},{id:191,label:"191"},{id:192,label:"192"},{id:193,label:"193"},{id:194,label:"194"},{id:195,label:"195"},{id:196,label:"196"},{id:197,label:"197"},{id:198,label:"198"},{id:199,label:"199"},{id:200,label:"200"},{id:201,label:"201"},{id:202,label:"202"},{id:203,label:"203"},{id:204,label:"204"},{id:205,label:"205"},{id:206,label:"206"},{id:207,label:"207"},{id:208,label:"208"},{id:209,label:"209"},{id:210,label:"210"},{id:211,label:"211"},{id:212,label:"212"},{id:213,label:"213"},{id:214,label:"214"},{id:215,label:"215"},{id:216,label:"216"},{id:217,label:"217"},{id:218,label:"218"},{id:219,label:"219"},{id:220,label:"220"},{id:221,label:"221"},{id:222,label:"222"},{id:223,label:"223"},{id:224,label:"224"},{id:225,label:"225"},{id:226,label:"226"},{id:227,label:"227"},{id:228,label:"228"},{id:229,label:"229"},{id:230,label:"230"},{id:231,label:"231"},{id:232,label:"232"},{id:233,label:"233"},{id:234,label:"234"},{id:235,label:"235"},{id:236,label:"236"},{id:237,label:"237"},{id:238,label:"238"},{id:239,label:"239"},{id:240,label:"240"},{id:241,label:"241"},{id:242,label:"242"},{id:243,label:"243"},{id:244,label:"244"},{id:245,label:"245"},{id:246,label:"246"},{id:247,label:"247"},{id:248,label:"248"},{id:249,label:"249"},{id:250,label:"250"},{id:251,label:"251"},{id:252,label:"252"},{id:253,label:"253"},{id:254,label:"254"},{id:255,label:"255"},{id:256,label:"256"},{id:257,label:"257"},{id:258,label:"258"},{id:259,label:"259"},{id:260,label:"260"},{id:261,label:"261"},{id:262,label:"262"},{id:263,label:"263"},{id:264,label:"264"},{id:265,label:"265"},{id:266,label:"266"},{id:267,label:"267"},{id:268,label:"268"},{id:269,label:"269"},{id:270,label:"270"},{id:271,label:"271"},{id:272,label:"272"},{id:273,label:"273"},{id:274,label:"274"},{id:275,label:"275"},{id:276,label:"276"},{id:277,label:"277"},{id:278,label:"278"},{id:279,label:"279"},{id:280,label:"280"},{id:281,label:"281"},{id:282,label:"282"},{id:283,label:"283"},{id:284,label:"284"},{id:285,label:"285"},{id:286,label:"286"},{id:287,label:"287"},{id:288,label:"288"},{id:289,label:"289"},{id:290,label:"290"},{id:291,label:"291"},{id:292,label:"292"},{id:293,label:"293"},{id:294,label:"294"},{id:295,label:"295"},{id:296,label:"296"},{id:297,label:"297"},{id:298,label:"298"},{id:299,label:"299"},{id:300,label:"300"},{id:301,label:"301"},{id:302,label:"302"},{id:303,label:"303"},{id:304,label:"304"},{id:305,label:"305"},{id:306,label:"306"},{id:307,label:"307"},{id:308,label:"308"},{id:309,label:"309"},{id:310,label:"310"},{id:311,label:"311"},{id:312,label:"312"},{id:313,label:"313"},{id:314,label:"314"},{id:315,label:"315"},{id:316,label:"316"},{id:317,label:"317"},{id:318,label:"318"},{id:319,label:"319"},{id:320,label:"320"},{id:321,label:"321"},{id:322,label:"322"},{id:323,label:"323"},{id:324,label:"324"},{id:325,label:"325"},{id:326,label:"326"},{id:327,label:"327"},{id:328,label:"328"},{id:329,label:"329"},{id:330,label:"330"},{id:331,label:"331"},{id:332,label:"332"},{id:333,label:"333"},{id:334,label:"334"},{id:335,label:"335"},{id:336,label:"336"},{id:337,label:"337"},{id:338,label:"338"},{id:339,label:"339"},{id:340,label:"340"},{id:341,label:"341"},{id:342,label:"342"},{id:343,label:"343"},{id:344,label:"344"},{id:345,label:"345"},{id:346,label:"346"},{id:347,label:"347"}]; +const edges = [{from:331,to:0,id:"e0"},{from:331,to:1,id:"e1"},{from:302,to:2,id:"e2"},{from:321,to:3,id:"e3"},{from:323,to:4,id:"e4"},{from:326,to:5,id:"e5"},{from:24,to:6,id:"e6"},{from:327,to:7,id:"e7"},{from:50,to:8,id:"e8"},{from:275,to:9,id:"e9"},{from:327,to:10,id:"e10"},{from:30,to:11,id:"e11"},{from:327,to:12,id:"e12"},{from:270,to:13,id:"e13"},{from:204,to:14,id:"e14"},{from:42,to:15,id:"e15"},{from:140,to:16,id:"e16"},{from:327,to:17,id:"e17"},{from:80,to:18,id:"e18"},{from:24,to:19,id:"e19"},{from:60,to:20,id:"e20"},{from:323,to:21,id:"e21"},{from:328,to:22,id:"e22"},{from:58,to:23,id:"e23"},{from:0,to:24,id:"e24"},{from:50,to:25,id:"e25"},{from:50,to:26,id:"e26"},{from:36,to:27,id:"e27"},{from:36,to:28,id:"e28"},{from:303,to:29,id:"e29"},{from:1,to:30,id:"e30"},{from:326,to:31,id:"e31"},{from:81,to:32,id:"e32"},{from:60,to:33,id:"e33"},{from:62,to:34,id:"e34"},{from:24,to:35,id:"e35"},{from:319,to:36,id:"e36"},{from:58,to:37,id:"e37"},{from:58,to:38,id:"e38"},{from:80,to:39,id:"e39"},{from:35,to:40,id:"e40"},{from:73,to:41,id:"e41"},{from:327,to:42,id:"e42"},{from:301,to:43,id:"e43"},{from:36,to:44,id:"e44"},{from:322,to:45,id:"e45"},{from:69,to:46,id:"e46"},{from:329,to:47,id:"e47"},{from:199,to:48,id:"e48"},{from:321,to:49,id:"e49"},{from:331,to:50,id:"e50"},{from:70,to:51,id:"e51"},{from:329,to:52,id:"e52"},{from:140,to:53,id:"e53"},{from:1,to:54,id:"e54"},{from:330,to:55,id:"e55"},{from:304,to:56,id:"e56"},{from:214,to:57,id:"e57"},{from:84,to:58,id:"e58"},{from:141,to:59,id:"e59"},{from:36,to:60,id:"e60"},{from:323,to:61,id:"e61"},{from:326,to:62,id:"e62"},{from:323,to:63,id:"e63"},{from:328,to:64,id:"e64"},{from:331,to:65,id:"e65"},{from:140,to:66,id:"e66"},{from:24,to:67,id:"e67"},{from:324,to:68,id:"e68"},{from:326,to:69,id:"e69"},{from:323,to:70,id:"e70"},{from:283,to:71,id:"e71"},{from:27,to:72,id:"e72"},{from:50,to:73,id:"e73"},{from:325,to:74,id:"e74"},{from:58,to:75,id:"e75"},{from:323,to:76,id:"e76"},{from:15,to:77,id:"e77"},{from:70,to:78,id:"e78"},{from:22,to:79,id:"e79"},{from:328,to:80,id:"e80"},{from:0,to:81,id:"e81"},{from:322,to:82,id:"e82"},{from:326,to:83,id:"e83"},{from:325,to:84,id:"e84"},{from:331,to:85,id:"e85"},{from:184,to:86,id:"e86"},{from:250,to:87,id:"e87"},{from:321,to:88,id:"e88"},{from:322,to:89,id:"e89"},{from:326,to:90,id:"e90"},{from:162,to:91,id:"e91"},{from:162,to:92,id:"e92"},{from:99,to:93,id:"e93"},{from:320,to:94,id:"e94"},{from:326,to:95,id:"e95"},{from:0,to:96,id:"e96"},{from:326,to:97,id:"e97"},{from:327,to:98,id:"e98"},{from:0,to:99,id:"e99"},{from:327,to:100,id:"e100"},{from:0,to:101,id:"e101"},{from:0,to:102,id:"e102"},{from:328,to:103,id:"e103"},{from:256,to:104,id:"e104"},{from:326,to:105,id:"e105"},{from:81,to:106,id:"e106"},{from:322,to:107,id:"e107"},{from:326,to:108,id:"e108"},{from:8,to:109,id:"e109"},{from:204,to:110,id:"e110"},{from:163,to:111,id:"e111"},{from:330,to:112,id:"e112"},{from:330,to:113,id:"e113"},{from:324,to:114,id:"e114"},{from:42,to:115,id:"e115"},{from:328,to:116,id:"e116"},{from:331,to:117,id:"e117"},{from:321,to:118,id:"e118"},{from:141,to:119,id:"e119"},{from:321,to:120,id:"e120"},{from:330,to:121,id:"e121"},{from:324,to:122,id:"e122"},{from:199,to:123,id:"e123"},{from:302,to:124,id:"e124"},{from:328,to:125,id:"e125"},{from:307,to:126,id:"e126"},{from:321,to:127,id:"e127"},{from:329,to:128,id:"e128"},{from:0,to:129,id:"e129"},{from:331,to:130,id:"e130"},{from:287,to:131,id:"e131"},{from:322,to:132,id:"e132"},{from:1,to:133,id:"e133"},{from:304,to:134,id:"e134"},{from:295,to:135,id:"e135"},{from:42,to:136,id:"e136"},{from:104,to:137,id:"e137"},{from:321,to:138,id:"e138"},{from:204,to:139,id:"e139"},{from:109,to:140,id:"e140"},{from:324,to:141,id:"e141"},{from:70,to:142,id:"e142"},{from:73,to:143,id:"e143"},{from:304,to:144,id:"e144"},{from:0,to:145,id:"e145"},{from:0,to:146,id:"e146"},{from:327,to:147,id:"e147"},{from:141,to:148,id:"e148"},{from:323,to:149,id:"e149"},{from:184,to:150,id:"e150"},{from:324,to:151,id:"e151"},{from:330,to:152,id:"e152"},{from:75,to:153,id:"e153"},{from:328,to:154,id:"e154"},{from:60,to:155,id:"e155"},{from:331,to:156,id:"e156"},{from:153,to:157,id:"e157"},{from:214,to:158,id:"e158"},{from:129,to:159,id:"e159"},{from:331,to:160,id:"e160"},{from:324,to:161,id:"e161"},{from:322,to:162,id:"e162"},{from:195,to:163,id:"e163"},{from:323,to:164,id:"e164"},{from:275,to:165,id:"e165"},{from:58,to:166,id:"e166"},{from:321,to:167,id:"e167"},{from:325,to:168,id:"e168"},{from:324,to:169,id:"e169"},{from:330,to:170,id:"e170"},{from:330,to:171,id:"e171"},{from:331,to:172,id:"e172"},{from:1,to:173,id:"e173"},{from:50,to:174,id:"e174"},{from:327,to:175,id:"e175"},{from:331,to:176,id:"e176"},{from:324,to:177,id:"e177"},{from:204,to:178,id:"e178"},{from:330,to:179,id:"e179"},{from:330,to:180,id:"e180"},{from:50,to:181,id:"e181"},{from:323,to:182,id:"e182"},{from:106,to:183,id:"e183"},{from:70,to:184,id:"e184"},{from:58,to:185,id:"e185"},{from:0,to:186,id:"e186"},{from:321,to:187,id:"e187"},{from:304,to:188,id:"e188"},{from:307,to:189,id:"e189"},{from:140,to:190,id:"e190"},{from:104,to:191,id:"e191"},{from:50,to:192,id:"e192"},{from:60,to:193,id:"e193"},{from:27,to:194,id:"e194"},{from:297,to:195,id:"e195"},{from:321,to:196,id:"e196"},{from:27,to:197,id:"e197"},{from:1,to:198,id:"e198"},{from:321,to:199,id:"e199"},{from:75,to:200,id:"e200"},{from:30,to:201,id:"e201"},{from:50,to:202,id:"e202"},{from:325,to:203,id:"e203"},{from:173,to:204,id:"e204"},{from:307,to:205,id:"e205"},{from:275,to:206,id:"e206"},{from:275,to:207,id:"e207"},{from:331,to:208,id:"e208"},{from:109,to:209,id:"e209"},{from:0,to:210,id:"e210"},{from:327,to:211,id:"e211"},{from:275,to:212,id:"e212"},{from:304,to:213,id:"e213"},{from:104,to:214,id:"e214"},{from:327,to:215,id:"e215"},{from:53,to:216,id:"e216"},{from:60,to:217,id:"e217"},{from:60,to:218,id:"e218"},{from:109,to:219,id:"e219"},{from:192,to:220,id:"e220"},{from:275,to:221,id:"e221"},{from:326,to:222,id:"e222"},{from:250,to:223,id:"e223"},{from:325,to:224,id:"e224"},{from:321,to:225,id:"e225"},{from:1,to:226,id:"e226"},{from:323,to:227,id:"e227"},{from:322,to:228,id:"e228"},{from:327,to:229,id:"e229"},{from:256,to:230,id:"e230"},{from:250,to:231,id:"e231"},{from:330,to:232,id:"e232"},{from:36,to:233,id:"e233"},{from:328,to:234,id:"e234"},{from:323,to:235,id:"e235"},{from:327,to:236,id:"e236"},{from:328,to:237,id:"e237"},{from:250,to:238,id:"e238"},{from:326,to:239,id:"e239"},{from:327,to:240,id:"e240"},{from:329,to:241,id:"e241"},{from:329,to:242,id:"e242"},{from:109,to:243,id:"e243"},{from:323,to:244,id:"e244"},{from:220,to:245,id:"e245"},{from:326,to:246,id:"e246"},{from:267,to:247,id:"e247"},{from:250,to:248,id:"e248"},{from:256,to:249,id:"e249"},{from:322,to:250,id:"e250"},{from:322,to:251,id:"e251"},{from:322,to:252,id:"e252"},{from:109,to:253,id:"e253"},{from:101,to:254,id:"e254"},{from:328,to:255,id:"e255"},{from:331,to:256,id:"e256"},{from:327,to:257,id:"e257"},{from:24,to:258,id:"e258"},{from:124,to:259,id:"e259"},{from:324,to:260,id:"e260"},{from:322,to:261,id:"e261"},{from:322,to:262,id:"e262"},{from:321,to:263,id:"e263"},{from:283,to:264,id:"e264"},{from:318,to:265,id:"e265"},{from:30,to:266,id:"e266"},{from:8,to:267,id:"e267"},{from:140,to:268,id:"e268"},{from:322,to:269,id:"e269"},{from:24,to:270,id:"e270"},{from:9,to:271,id:"e271"},{from:322,to:272,id:"e272"},{from:99,to:273,id:"e273"},{from:24,to:274,id:"e274"},{from:282,to:275,id:"e275"},{from:250,to:276,id:"e276"},{from:70,to:277,id:"e277"},{from:328,to:278,id:"e278"},{from:250,to:279,id:"e279"},{from:50,to:280,id:"e280"},{from:250,to:281,id:"e281"},{from:173,to:282,id:"e282"},{from:320,to:283,id:"e283"},{from:320,to:284,id:"e284"},{from:250,to:285,id:"e285"},{from:325,to:286,id:"e286"},{from:1,to:287,id:"e287"},{from:1,to:288,id:"e288"},{from:109,to:289,id:"e289"},{from:50,to:290,id:"e290"},{from:250,to:291,id:"e291"},{from:195,to:292,id:"e292"},{from:320,to:293,id:"e293"},{from:331,to:294,id:"e294"},{from:331,to:295,id:"e295"},{from:101,to:296,id:"e296"},{from:58,to:297,id:"e297"},{from:24,to:298,id:"e298"},{from:291,to:299,id:"e299"},{from:302,to:300,id:"e300"},{from:323,to:301,id:"e301"},{from:226,to:302,id:"e302"},{from:53,to:303,id:"e303"},{from:110,to:304,id:"e304"},{from:163,to:305,id:"e305"},{from:324,to:306,id:"e306"},{from:304,to:307,id:"e307"},{from:322,to:308,id:"e308"},{from:140,to:309,id:"e309"},{from:323,to:310,id:"e310"},{from:0,to:311,id:"e311"},{from:250,to:312,id:"e312"},{from:30,to:313,id:"e313"},{from:58,to:314,id:"e314"},{from:104,to:315,id:"e315"},{from:75,to:316,id:"e316"},{from:323,to:317,id:"e317"},{from:321,to:318,id:"e318"},{from:256,to:319,id:"e319"},{from:250,to:320,id:"e320"},{from:330,to:321,id:"e321"},{from:327,to:322,id:"e322"},{from:326,to:323,id:"e323"},{from:328,to:324,id:"e324"},{from:328,to:325,id:"e325"},{from:327,to:326,id:"e326"},{from:0,to:327,id:"e327"},{from:70,to:328,id:"e328"},{from:327,to:329,id:"e329"},{from:324,to:330,id:"e330"},{from:69,to:332,id:"e331"},{from:346,to:333,id:"e332"},{from:346,to:334,id:"e333"},{from:337,to:335,id:"e334"},{from:106,to:336,id:"e335"},{from:341,to:337,id:"e336"},{from:341,to:338,id:"e337"},{from:346,to:339,id:"e338"},{from:337,to:340,id:"e339"},{from:334,to:341,id:"e340"},{from:334,to:342,id:"e341"},{from:334,to:343,id:"e342"},{from:334,to:344,id:"e343"},{from:84,to:345,id:"e344"},{from:14,to:346,id:"e345"},{from:331,to:347,id:"e346"}] diff --git a/examples/network/exampleApplications/disassemblerExample.js b/examples/network/exampleApplications/disassemblerExample.js index c22fb28977..cf2a49adfd 100644 --- a/examples/network/exampleApplications/disassemblerExample.js +++ b/examples/network/exampleApplications/disassemblerExample.js @@ -1,4 +1,7 @@ -var options = { +// These variables will be injected into a page that will use them. +/* eslint no-unused-vars: "off" */ + +const options = { manipulation: false, height: '90%', layout: { @@ -14,7 +17,7 @@ var options = { } }; -var nodes = [ +const nodes = [ {'id': 'cfg_0x00405a2e', 'size': 150, 'label': "0x00405a2e:\nmov DWORD PTR ss:[esp + 0x000000b0], 0x00000002\nmov DWORD PTR ss:[ebp + 0x00], esi\ntest bl, 0x02\nje 0x00405a49<>\n", 'color': "#FFCFCF", 'shape': 'box', 'font': {'face': 'monospace', 'align': 'left'}}, {'id': 'cfg_0x00405a49', 'size': 150, 'label': "0x00405a49:\ntest bl, 0x01\nje 0x00405a62<>\n", 'color': "#FFCFCF", 'shape': 'box', 'font': {'face': 'monospace', 'align': 'left'}}, {'id': 'cfg_0x00405a55', 'size': 150, 'label': "0x00405a55:\nmov ecx, DWORD PTR ss:[esp + 0x1c]\npush ecx\ncall 0x004095c6<>\n", 'color': "#FFCFCF", 'shape': 'box', 'font': {'face': 'monospace', 'align': 'left'}}, @@ -35,7 +38,7 @@ var nodes = [ // // The edges with these id's will not load into the Network instance. // -var edges = [ +const edges = [ {'from': "cfg_0x00405a2e", 'to': "cfg_0x00405a39", 'arrows': 'to', 'physics': false, 'smooth': {'type': 'cubicBezier'}}, {'from': "cfg_0x00405a2e", 'to': "cfg_0x00405a49", 'arrows': 'to', 'physics': false, 'smooth': {'type': 'cubicBezier'}}, {'from': "cfg_0x00405a49", 'to': "cfg_0x00405a4e", 'arrows': 'to', 'physics': false, 'smooth': {'type': 'cubicBezier'}}, diff --git a/examples/network/exampleUtil.js b/examples/network/exampleUtil.js index 77bfa2ad8d..ed2ccd51ed 100644 --- a/examples/network/exampleUtil.js +++ b/examples/network/exampleUtil.js @@ -1,3 +1,13 @@ +// These globals will be injected into a page that will use them. +/* eslint no-unused-vars: "off" */ + +// This is quite old and I don't want to waste too much time here. We probably +// should stop using this altogether as the examples should be easy and +// straightforward to understand and this only obscures it. +/* eslint require-jsdoc: "off" */ + +/* global Alea:false seededRandom:true */ + /** * Created by Alex on 5/20/2015. * @@ -6,7 +16,7 @@ */ function loadJSON(path, success, error) { - var xhr = new XMLHttpRequest(); + const xhr = new XMLHttpRequest(); xhr.onreadystatechange = function () { if (xhr.readyState === 4) { if (xhr.status === 200) { @@ -23,12 +33,12 @@ function loadJSON(path, success, error) { function getScaleFreeNetwork(nodeCount) { - var nodes = []; - var edges = []; - var connectionCount = []; + const nodes = []; + const edges = []; + const connectionCount = []; // randomly create some nodes and edges - for (var i = 0; i < nodeCount; i++) { + for (let i = 0; i < nodeCount; i++) { nodes.push({ id: i, label: String(i) @@ -38,8 +48,8 @@ function getScaleFreeNetwork(nodeCount) { // create edges in a scale-free-network way if (i == 1) { - var from = i; - var to = 0; + const from = i; + const to = 0; edges.push({ from: from, to: to @@ -48,18 +58,18 @@ function getScaleFreeNetwork(nodeCount) { connectionCount[to]++; } else if (i > 1) { - var conn = edges.length * 2; - var rand = Math.floor(seededRandom() * conn); - var cum = 0; - var j = 0; + const conn = edges.length * 2; + const rand = Math.floor(seededRandom() * conn); + let cum = 0; + let j = 0; while (j < connectionCount.length && cum < rand) { cum += connectionCount[j]; j++; } - var from = i; - var to = j; + const from = i; + const to = j; edges.push({ from: from, to: to @@ -72,20 +82,17 @@ function getScaleFreeNetwork(nodeCount) { return {nodes:nodes, edges:edges}; } -var seededRandom = Alea('SEED') +seededRandom = Alea('SEED') -function getScaleFreeNetworkSeeded(nodeCount, seed) { - if (seed) { - randomSeed = Number(seed); - } - var nodes = []; - var edges = []; - var connectionCount = []; - var edgesId = 0; +function getScaleFreeNetworkSeeded(nodeCount) { + const nodes = []; + const edges = []; + const connectionCount = []; + let edgesId = 0; // randomly create some nodes and edges - for (var i = 0; i < nodeCount; i++) { + for (let i = 0; i < nodeCount; i++) { nodes.push({ id: i, label: String(i) @@ -95,8 +102,8 @@ function getScaleFreeNetworkSeeded(nodeCount, seed) { // create edges in a scale-free-network way if (i == 1) { - var from = i; - var to = 0; + const from = i; + const to = 0; edges.push({ id: edgesId++, from: from, @@ -106,18 +113,18 @@ function getScaleFreeNetworkSeeded(nodeCount, seed) { connectionCount[to]++; } else if (i > 1) { - var conn = edges.length * 2; - var rand = Math.floor(seededRandom() * conn); - var cum = 0; - var j = 0; + const conn = edges.length * 2; + const rand = Math.floor(seededRandom() * conn); + let cum = 0; + let j = 0; while (j < connectionCount.length && cum < rand) { cum += connectionCount[j]; j++; } - var from = i; - var to = j; + const from = i; + const to = j; edges.push({ id: edgesId++, from: from, diff --git a/lib/DOMutil.js b/lib/DOMutil.js index 15d9087904..5a2d75f7e5 100644 --- a/lib/DOMutil.js +++ b/lib/DOMutil.js @@ -7,8 +7,8 @@ */ export function prepareElements (JSONcontainer) { // cleanup the redundant svgElements; - for (var elementType in JSONcontainer) { - if (JSONcontainer.hasOwnProperty(elementType)) { + for (const elementType in JSONcontainer) { + if (Object.prototype.hasOwnProperty.call(JSONcontainer, elementType)) { JSONcontainer[elementType].redundant = JSONcontainer[elementType].used; JSONcontainer[elementType].used = []; } @@ -24,10 +24,10 @@ export function prepareElements (JSONcontainer) { */ export function cleanupElements (JSONcontainer) { // cleanup the redundant svgElements; - for (var elementType in JSONcontainer) { - if (JSONcontainer.hasOwnProperty(elementType)) { + for (const elementType in JSONcontainer) { + if (Object.prototype.hasOwnProperty.call(JSONcontainer, elementType)) { if (JSONcontainer[elementType].redundant) { - for (var i = 0; i < JSONcontainer[elementType].redundant.length; i++) { + for (let i = 0; i < JSONcontainer[elementType].redundant.length; i++) { JSONcontainer[elementType].redundant[i].parentNode.removeChild(JSONcontainer[elementType].redundant[i]); } JSONcontainer[elementType].redundant = []; @@ -57,9 +57,9 @@ export function resetElements (JSONcontainer) { * @private */ export function getSVGElement (elementType, JSONcontainer, svgContainer) { - var element; + let element; // allocate SVG element, if it doesnt yet exist, create one. - if (JSONcontainer.hasOwnProperty(elementType)) { // this element has been created before + if (Object.prototype.hasOwnProperty.call(JSONcontainer, elementType)) { // this element has been created before // check if there is an redundant element if (JSONcontainer[elementType].redundant.length > 0) { element = JSONcontainer[elementType].redundant[0]; @@ -93,9 +93,9 @@ export function getSVGElement (elementType, JSONcontainer, svgContainer) { * @returns {*} */ export function getDOMElement (elementType, JSONcontainer, DOMContainer, insertBefore) { - var element; + let element; // allocate DOM element, if it doesnt yet exist, create one. - if (JSONcontainer.hasOwnProperty(elementType)) { // this element has been created before + if (Object.prototype.hasOwnProperty.call(JSONcontainer, elementType)) { // this element has been created before // check if there is an redundant element if (JSONcontainer[elementType].redundant.length > 0) { element = JSONcontainer[elementType].redundant[0]; @@ -144,7 +144,7 @@ export function getDOMElement (elementType, JSONcontainer, DOMContainer, insertB * @returns {vis.PointItem} */ export function drawPoint (x, y, groupTemplate, JSONcontainer, svgContainer, labelObj) { - var point; + let point; if (groupTemplate.style == 'circle') { point = getSVGElement('circle', JSONcontainer, svgContainer); point.setAttributeNS(null, "cx", x); diff --git a/lib/hammerUtil.js b/lib/hammerUtil.js index f155a6e414..b1dbcc6876 100644 --- a/lib/hammerUtil.js +++ b/lib/hammerUtil.js @@ -56,7 +56,7 @@ export const offRelease = offTouch; * @return {Hammer.Pinch} returns the pinchRecognizer */ export function disablePreventDefaultVertically (pinchRecognizer) { - var TOUCH_ACTION_PAN_Y = 'pan-y'; + const TOUCH_ACTION_PAN_Y = 'pan-y'; pinchRecognizer.getTouchAction = function() { // default method returns [TOUCH_ACTION_NONE] diff --git a/lib/module/hammer.js b/lib/module/hammer.js index 559d19788c..f492ac554b 100644 --- a/lib/module/hammer.js +++ b/lib/module/hammer.js @@ -24,7 +24,7 @@ function hammerMock() { if (typeof window !== 'undefined') { - var Hammer = window['Hammer'] || require('@egjs/hammerjs'); + const Hammer = window['Hammer'] || require('@egjs/hammerjs'); module.exports = Hammer; } else { diff --git a/lib/network/CachedImage.js b/lib/network/CachedImage.js index 317aa4ce84..7136f0009d 100644 --- a/lib/network/CachedImage.js +++ b/lib/network/CachedImage.js @@ -29,22 +29,22 @@ class CachedImage { if (this.initialized()) return; this.src = this.image.src; // For same interface with Image - var w = this.image.width; - var h = this.image.height; + const w = this.image.width; + const h = this.image.height; // Ease external access this.width = w; this.height = h; - var h2 = Math.floor(h/2); - var h4 = Math.floor(h/4); - var h8 = Math.floor(h/8); - var h16 = Math.floor(h/16); + const h2 = Math.floor(h/2); + const h4 = Math.floor(h/4); + const h8 = Math.floor(h/8); + const h16 = Math.floor(h/16); - var w2 = Math.floor(w/2); - var w4 = Math.floor(w/4); - var w8 = Math.floor(w/8); - var w16 = Math.floor(w/16); + const w2 = Math.floor(w/2); + const w4 = Math.floor(w/4); + const w8 = Math.floor(w/8); + const w16 = Math.floor(w/16); // Make canvas as small as possible this.canvas.width = 3*w4; @@ -90,16 +90,16 @@ class CachedImage { * @private */ _fillMipMap() { - var ctx = this.canvas.getContext('2d'); + const ctx = this.canvas.getContext('2d'); // First zoom-level comes from the image - var to = this.coordinates[0]; + const to = this.coordinates[0]; ctx.drawImage(this.image, to[0], to[1], to[2], to[3]); // The rest are copy actions internal to the canvas/context for (let iterations = 1; iterations < this.NUM_ITERATIONS; iterations++) { - let from = this.coordinates[iterations - 1]; - let to = this.coordinates[iterations]; + const from = this.coordinates[iterations - 1]; + const to = this.coordinates[iterations]; ctx.drawImage(this.canvas, from[0], from[1], from[2], from[3], @@ -143,7 +143,7 @@ class CachedImage { } //console.log("iterations: " + iterations); - let from = this.coordinates[iterations]; + const from = this.coordinates[iterations]; ctx.drawImage(this.canvas, from[0], from[1], from[2], from[3], left, top, width, height diff --git a/lib/network/Images.js b/lib/network/Images.js index 4d556ca183..40419f1362 100644 --- a/lib/network/Images.js +++ b/lib/network/Images.js @@ -62,11 +62,11 @@ class Images { */ load (url, brokenUrl) { //Try and get the image from the cache, if successful then return the cached image - var cachedImage = this.images[url]; + const cachedImage = this.images[url]; if (cachedImage) return cachedImage; //Create a new image - var img = new CachedImage(); + const img = new CachedImage(); // Need to add to cache here, otherwise final return will spawn different copies of the same image, // Also, there will be multiple loads of the same image. diff --git a/lib/network/Network.js b/lib/network/Network.js index fd3e4e21d8..eede1561e9 100644 --- a/lib/network/Network.js +++ b/lib/network/Network.js @@ -170,13 +170,13 @@ Network.prototype.setOptions = function (options) { } if (options !== undefined) { - let errorFound = Validator.validate(options, allOptions); + const errorFound = Validator.validate(options, allOptions); if (errorFound === true) { console.log('%cErrors have been found in the supplied options object.', printStyle); } // copy the global fields over - let fields = ['locale','locales','clickToUse']; + const fields = ['locale','locales','clickToUse']; selectiveDeepExtend(fields,this.options, options); // normalize the locale or use English @@ -221,7 +221,7 @@ Network.prototype.setOptions = function (options) { // if the configuration system is enabled, copy all options and put them into the config system if (this.configurator && this.configurator.options.enabled === true) { - let networkOptions = {nodes:{},edges:{},layout:{},interaction:{},manipulation:{},physics:{},global:{}}; + const networkOptions = {nodes:{},edges:{},layout:{},interaction:{},manipulation:{},physics:{},global:{}}; deepExtend(networkOptions.nodes, this.nodesHandler.options); deepExtend(networkOptions.edges, this.edgesHandler.options); deepExtend(networkOptions.layout, this.layoutEngine.options); @@ -277,30 +277,30 @@ Network.prototype.setOptions = function (options) { * @private */ Network.prototype._updateVisibleIndices = function () { - let nodes = this.body.nodes; - let edges = this.body.edges; + const nodes = this.body.nodes; + const edges = this.body.edges; this.body.nodeIndices = []; this.body.edgeIndices = []; - for (let nodeId in nodes) { - if (nodes.hasOwnProperty(nodeId)) { + for (const nodeId in nodes) { + if (Object.prototype.hasOwnProperty.call(nodes, nodeId)) { if (!this.clustering._isClusteredNode(nodeId) && nodes[nodeId].options.hidden === false) { this.body.nodeIndices.push(nodes[nodeId].id); } } } - for (let edgeId in edges) { - if (edges.hasOwnProperty(edgeId)) { - let edge = edges[edgeId]; + for (const edgeId in edges) { + if (Object.prototype.hasOwnProperty.call(edges, edgeId)) { + const edge = edges[edgeId]; // It can happen that this is executed *after* a node edge has been removed, // but *before* the edge itself has been removed. Taking this into account. - let fromNode = nodes[edge.fromId]; - let toNode = nodes[edge.toId]; - let edgeNodesPresent = (fromNode !== undefined) && (toNode !== undefined); + const fromNode = nodes[edge.fromId]; + const toNode = nodes[edge.toId]; + const edgeNodesPresent = (fromNode !== undefined) && (toNode !== undefined); - let isVisible = + const isVisible = !this.clustering._isClusteredEdge(edgeId) && edge.options.hidden === false && edgeNodesPresent @@ -370,14 +370,14 @@ Network.prototype.setData = function (data) { if (data && data.dot) { console.log('The dot property has been deprecated. Please use the static convertDot method to convert DOT into vis.network format and use the normal data format with nodes and edges. This converter is used like this: var data = vis.network.convertDot(dotString);'); // parse DOT file - var dotData = DOTToGraph(data.dot); + const dotData = DOTToGraph(data.dot); this.setData(dotData); return; } else if (data && data.gephi) { // parse DOT file console.log('The gephi property has been deprecated. Please use the static convertGephi method to convert gephi into vis.network format and use the normal data format with nodes and edges. This converter is used like this: var data = vis.network.convertGephi(gephiJson);'); - var gephiData = parseGephi(data.gephi); + const gephiData = parseGephi(data.gephi); this.setData(gephiData); return; } @@ -425,13 +425,13 @@ Network.prototype.destroy = function () { delete this.configurator; delete this.images; - for (var nodeId in this.body.nodes) { - if (!this.body.nodes.hasOwnProperty(nodeId)) continue; + for (const nodeId in this.body.nodes) { + if (!Object.prototype.hasOwnProperty.call(this.body.nodes, nodeId)) continue; delete this.body.nodes[nodeId]; } - for (var edgeId in this.body.edges) { - if (!this.body.edges.hasOwnProperty(edgeId)) continue; + for (const edgeId in this.body.edges) { + if (!Object.prototype.hasOwnProperty.call(this.body.edges, edgeId)) continue; delete this.body.edges[edgeId]; } @@ -449,15 +449,15 @@ Network.prototype.destroy = function () { * @private */ Network.prototype._updateValueRange = function (obj) { - var id; + let id; // determine the range of the objects - var valueMin = undefined; - var valueMax = undefined; - var valueTotal = 0; + let valueMin = undefined; + let valueMax = undefined; + let valueTotal = 0; for (id in obj) { - if (obj.hasOwnProperty(id)) { - var value = obj[id].getValue(); + if (Object.prototype.hasOwnProperty.call(obj, id)) { + const value = obj[id].getValue(); if (value !== undefined) { valueMin = (valueMin === undefined) ? value : Math.min(value, valueMin); valueMax = (valueMax === undefined) ? value : Math.max(value, valueMax); @@ -469,7 +469,7 @@ Network.prototype._updateValueRange = function (obj) { // adjust the range of all objects if (valueMin !== undefined && valueMax !== undefined) { for (id in obj) { - if (obj.hasOwnProperty(id)) { + if (Object.prototype.hasOwnProperty.call(obj, id)) { obj[id].setValueRange(valueMin, valueMax, valueTotal); } } @@ -562,14 +562,14 @@ Network.prototype.setSelection = function() {return this.selectionHandler Network.prototype.getSelectedNodes = function() {return this.selectionHandler.getSelectedNodes.apply(this.selectionHandler,arguments);}; Network.prototype.getSelectedEdges = function() {return this.selectionHandler.getSelectedEdges.apply(this.selectionHandler,arguments);}; Network.prototype.getNodeAt = function() { - var node = this.selectionHandler.getNodeAt.apply(this.selectionHandler,arguments); + const node = this.selectionHandler.getNodeAt.apply(this.selectionHandler,arguments); if (node !== undefined && node.id !== undefined) { return node.id; } return node; }; Network.prototype.getEdgeAt = function() { - var edge = this.selectionHandler.getEdgeAt.apply(this.selectionHandler,arguments); + const edge = this.selectionHandler.getEdgeAt.apply(this.selectionHandler,arguments); if (edge !== undefined && edge.id !== undefined) { return edge.id; } diff --git a/lib/network/NetworkUtil.js b/lib/network/NetworkUtil.js index 5a4aceca8e..5f8ec4f26d 100644 --- a/lib/network/NetworkUtil.js +++ b/lib/network/NetworkUtil.js @@ -18,9 +18,9 @@ class NetworkUtil { * @static */ static getRange(allNodes, specificNodes = []) { - var minY = 1e9, maxY = -1e9, minX = 1e9, maxX = -1e9, node; + let minY = 1e9, maxY = -1e9, minX = 1e9, maxX = -1e9, node; if (specificNodes.length > 0) { - for (var i = 0; i < specificNodes.length; i++) { + for (let i = 0; i < specificNodes.length; i++) { node = allNodes[specificNodes[i]]; if (minX > node.shape.boundingBox.left) { minX = node.shape.boundingBox.left; @@ -52,9 +52,9 @@ class NetworkUtil { * @static */ static getRangeCore(allNodes, specificNodes = []) { - var minY = 1e9, maxY = -1e9, minX = 1e9, maxX = -1e9, node; + let minY = 1e9, maxY = -1e9, minX = 1e9, maxX = -1e9, node; if (specificNodes.length > 0) { - for (var i = 0; i < specificNodes.length; i++) { + for (let i = 0; i < specificNodes.length; i++) { node = allNodes[specificNodes[i]]; if (minX > node.x) { minX = node.x; @@ -97,7 +97,7 @@ class NetworkUtil { * @static */ static cloneOptions(item, type) { - let clonedOptions = {}; + const clonedOptions = {}; if (type === undefined || type === 'node') { deepExtend(clonedOptions, item.options, true); clonedOptions.x = item.x; diff --git a/lib/network/dotparser.js b/lib/network/dotparser.js index 5b072acf62..c31395ab0c 100644 --- a/lib/network/dotparser.js +++ b/lib/network/dotparser.js @@ -1,3 +1,8 @@ +/* eslint-disable max-statements */ +/* eslint-disable no-prototype-builtins */ +/* eslint-disable no-unused-vars */ +/* eslint-disable no-var */ + /** * Parse a text source containing data in DOT language into a JSON object. * The object contains two lists: one with nodes and one with edges. diff --git a/lib/network/modules/Canvas.js b/lib/network/modules/Canvas.js index f59a419c57..ffb105f7f7 100644 --- a/lib/network/modules/Canvas.js +++ b/lib/network/modules/Canvas.js @@ -63,7 +63,7 @@ class Canvas { */ setOptions(options) { if (options !== undefined) { - let fields = ['width','height','autoResize']; + const fields = ['width','height','autoResize']; selectiveDeepExtend(fields,this.options, options); } @@ -71,7 +71,7 @@ class Canvas { // automatically adapt to a changing size of the browser. this._cleanUp(); this.resizeTimer = setInterval(() => { - let changed = this.setSize(); + const changed = this.setSize(); if (changed === true) { this.body.emitter.emit("_requestRedraw"); } @@ -133,8 +133,8 @@ class Canvas { this.cameraState.previousHeight > 0 ) { - let widthRatio = (this.frame.canvas.width / this.pixelRatio) / this.cameraState.previousWidth; - let heightRatio = (this.frame.canvas.height / this.pixelRatio) / this.cameraState.previousHeight; + const widthRatio = (this.frame.canvas.width / this.pixelRatio) / this.cameraState.previousWidth; + const heightRatio = (this.frame.canvas.height / this.pixelRatio) / this.cameraState.previousHeight; let newScale = this.cameraState.scale; if (widthRatio != 1 && heightRatio != 1) { @@ -149,12 +149,12 @@ class Canvas { this.body.view.scale = newScale; // this comes from the view module. - var currentViewCenter = this.DOMtoCanvas({ + const currentViewCenter = this.DOMtoCanvas({ x: 0.5 * this.frame.canvas.clientWidth, y: 0.5 * this.frame.canvas.clientHeight }); - var distanceFromCenter = { // offset from view, distance view has to change by these x and y to center the node + const distanceFromCenter = { // offset from view, distance view has to change by these x and y to center the node x: currentViewCenter.x - this.cameraState.position.x, y: currentViewCenter.y - this.cameraState.position.y }; @@ -207,7 +207,7 @@ class Canvas { this.frame.appendChild(this.frame.canvas); if (!this.frame.canvas.getContext) { - let noCanvas = document.createElement( 'DIV' ); + const noCanvas = document.createElement( 'DIV' ); noCanvas.style.color = 'red'; noCanvas.style.fontWeight = 'bold' ; noCanvas.style.padding = '10px'; @@ -279,8 +279,8 @@ class Canvas { height= this._prepareValue(height); let emitEvent = false; - let oldWidth = this.frame.canvas.width; - let oldHeight = this.frame.canvas.height; + const oldWidth = this.frame.canvas.width; + const oldHeight = this.frame.canvas.height; // update the pixel ratio // @@ -294,7 +294,7 @@ class Canvas { // // For the time being, I will humor the assumption here, and in the rest of the code assume it is // constant. - let previousRatio = this.pixelRatio; // we cache this because the camera state storage needs the old value + const previousRatio = this.pixelRatio; // we cache this because the camera state storage needs the old value this._setPixelRatio(); if (width != this.options.width || height != this.options.height || this.frame.style.width != width || this.frame.style.height != height) { @@ -323,8 +323,8 @@ class Canvas { // this would adapt the width of the canvas to the width from 100% if and only if // there is a change. - let newWidth = Math.round(this.frame.canvas.clientWidth * this.pixelRatio); - let newHeight = Math.round(this.frame.canvas.clientHeight * this.pixelRatio); + const newWidth = Math.round(this.frame.canvas.clientWidth * this.pixelRatio); + const newHeight = Math.round(this.frame.canvas.clientHeight * this.pixelRatio); // store the camera if there is a change in size. if (this.frame.canvas.width !== newWidth || this.frame.canvas.height !== newHeight) { @@ -374,18 +374,18 @@ class Canvas { * @private */ _determinePixelRatio() { - let ctx = this.getContext(); + const ctx = this.getContext(); if (ctx === undefined) { throw new Error("Could not get canvax context"); } - var numerator = 1; + let numerator = 1; if(typeof window !== 'undefined') { // (window !== undefined) doesn't work here! // Protection during unit tests, where 'window' can be missing numerator = (window.devicePixelRatio || 1); } - var denominator = (ctx.webkitBackingStorePixelRatio || + const denominator = (ctx.webkitBackingStorePixelRatio || ctx.mozBackingStorePixelRatio || ctx.msBackingStorePixelRatio || ctx.oBackingStorePixelRatio || @@ -407,7 +407,7 @@ class Canvas { * Set the transform in the contained context, based on its pixelRatio */ setTransform() { - let ctx = this.getContext(); + const ctx = this.getContext(); if (ctx === undefined) { throw new Error("Could not get canvax context"); } diff --git a/lib/network/modules/CanvasRenderer.js b/lib/network/modules/CanvasRenderer.js index 11ded58d22..ed8283d8f4 100644 --- a/lib/network/modules/CanvasRenderer.js +++ b/lib/network/modules/CanvasRenderer.js @@ -22,7 +22,7 @@ import { selectiveDeepExtend } from 'vis-util/esnext'; * @private */ function _initRequestAnimationFrame() { - var func; + let func; if (window !== undefined) { func = window.requestAnimationFrame @@ -132,7 +132,7 @@ class CanvasRenderer { */ setOptions(options) { if (options !== undefined) { - let fields = ['hideEdgesOnDrag', 'hideEdgesOnZoom', 'hideNodesOnDrag']; + const fields = ['hideEdgesOnDrag', 'hideEdgesOnZoom', 'hideNodesOnDrag']; selectiveDeepExtend(fields,this.options, options); } } @@ -164,7 +164,7 @@ class CanvasRenderer { let timer; - var myWindow = window; // Grab a reference to reduce the possibility that 'window' is reset + const myWindow = window; // Grab a reference to reduce the possibility that 'window' is reset // while running this method. if (this.requiresTimeout === true) { @@ -253,11 +253,11 @@ class CanvasRenderer { this.canvas.setTransform(); - let ctx = this.canvas.getContext(); + const ctx = this.canvas.getContext(); // clear the canvas - let w = this.canvas.frame.canvas.clientWidth; - let h = this.canvas.frame.canvas.clientHeight; + const w = this.canvas.frame.canvas.clientWidth; + const h = this.canvas.frame.canvas.clientHeight; ctx.clearRect(0, 0, w, h); // if the div is hidden, we stop the redraw here for performance. @@ -325,17 +325,17 @@ class CanvasRenderer { */ _resizeNodes() { this.canvas.setTransform(); - let ctx = this.canvas.getContext(); + const ctx = this.canvas.getContext(); ctx.save(); ctx.translate(this.body.view.translation.x, this.body.view.translation.y); ctx.scale(this.body.view.scale, this.body.view.scale); - let nodes = this.body.nodes; + const nodes = this.body.nodes; let node; // resize all nodes - for (let nodeId in nodes) { - if (nodes.hasOwnProperty(nodeId)) { + for (const nodeId in nodes) { + if (Object.prototype.hasOwnProperty.call(nodes, nodeId)) { node = nodes[nodeId]; node.resize(ctx); node.updateBoundingBox(ctx, node.selected); @@ -354,18 +354,18 @@ class CanvasRenderer { * @private */ _drawNodes(ctx, alwaysShow = false) { - let nodes = this.body.nodes; - let nodeIndices = this.body.nodeIndices; + const nodes = this.body.nodes; + const nodeIndices = this.body.nodeIndices; let node; - let selected = []; - let hovered = []; - let margin = 20; - let topLeft = this.canvas.DOMtoCanvas({x:-margin,y:-margin}); - let bottomRight = this.canvas.DOMtoCanvas({ + const selected = []; + const hovered = []; + const margin = 20; + const topLeft = this.canvas.DOMtoCanvas({x:-margin,y:-margin}); + const bottomRight = this.canvas.DOMtoCanvas({ x: this.canvas.frame.canvas.clientWidth+margin, y: this.canvas.frame.canvas.clientHeight+margin }); - let viewableArea = {top:topLeft.y,left:topLeft.x,bottom:bottomRight.y,right:bottomRight.x}; + const viewableArea = {top:topLeft.y,left:topLeft.x,bottom:bottomRight.y,right:bottomRight.x}; // draw unselected nodes; for (let i = 0; i < nodeIndices.length; i++) { @@ -414,8 +414,8 @@ class CanvasRenderer { * @private */ _drawEdges(ctx) { - let edges = this.body.edges; - let edgeIndices = this.body.edgeIndices; + const edges = this.body.edges; + const edgeIndices = this.body.edgeIndices; for (let i = 0; i < edgeIndices.length; i++) { const edge = edges[edgeIndices[i]]; @@ -431,8 +431,8 @@ class CanvasRenderer { * @private */ _drawArrows(ctx) { - let edges = this.body.edges; - let edgeIndices = this.body.edgeIndices; + const edges = this.body.edges; + const edgeIndices = this.body.edgeIndices; for (let i = 0; i < edgeIndices.length; i++) { const edge = edges[edgeIndices[i]]; @@ -449,7 +449,7 @@ class CanvasRenderer { */ _determineBrowserMethod() { if (typeof window !== 'undefined') { - let browserType = navigator.userAgent.toLowerCase(); + const browserType = navigator.userAgent.toLowerCase(); this.requiresTimeout = false; if (browserType.indexOf('msie 9.0') != -1) { // IE 9 this.requiresTimeout = true; diff --git a/lib/network/modules/Clustering.js b/lib/network/modules/Clustering.js index 8c53f75f0f..b125ff14dd 100644 --- a/lib/network/modules/Clustering.js +++ b/lib/network/modules/Clustering.js @@ -130,9 +130,9 @@ class ClusterEngine { hubsize = this._getHubSize(); } - let nodesToCluster = []; + const nodesToCluster = []; for (let i = 0; i < this.body.nodeIndices.length; i++) { - let node = this.body.nodes[this.body.nodeIndices[i]]; + const node = this.body.nodes[this.body.nodeIndices[i]]; if (node.edges.length >= hubsize) { nodesToCluster.push(node.id); } @@ -157,8 +157,8 @@ class ClusterEngine { // check if the options object is fine, append if needed options = this._checkOptions(options); - let childNodesObj = {}; - let childEdgesObj = {}; + const childNodesObj = {}; + const childEdgesObj = {}; // collect the nodes that will be in the cluster forEach(this.body.nodes, (node, nodeId) => { @@ -186,15 +186,15 @@ class ClusterEngine { */ clusterByEdgeCount(edgeCount, options, refreshData = true) { options = this._checkOptions(options); - let clusters = []; - let usedNodes = {}; + const clusters = []; + const usedNodes = {}; let edge, edges, relevantEdgeCount; // collect the nodes that will be in the cluster for (let i = 0; i < this.body.nodeIndices.length; i++) { - let childNodesObj = {}; - let childEdgesObj = {}; - let nodeId = this.body.nodeIndices[i]; - let node = this.body.nodes[nodeId]; + const childNodesObj = {}; + const childEdgesObj = {}; + const nodeId = this.body.nodeIndices[i]; + const node = this.body.nodes[nodeId]; // if this node is already used in another cluster this session, we do not have to re-evaluate it. if (usedNodes[nodeId] === undefined) { @@ -212,19 +212,19 @@ class ClusterEngine { // this node qualifies, we collect its neighbours to start the clustering process. if (relevantEdgeCount === edgeCount) { - var checkJoinCondition = function(node) { + const checkJoinCondition = function(node) { if (options.joinCondition === undefined || options.joinCondition === null) { return true; } - let clonedOptions = NetworkUtil.cloneOptions(node); + const clonedOptions = NetworkUtil.cloneOptions(node); return options.joinCondition(clonedOptions); } let gatheringSuccessful = true; for (let j = 0; j < edges.length; j++) { edge = edges[j]; - let childNodeId = this._getConnectedId(edge, nodeId); + const childNodeId = this._getConnectedId(edge, nodeId); // add the nodes to the list by the join condition. if (checkJoinCondition(node)) { childEdgesObj[edge.id] = edge; @@ -244,10 +244,10 @@ class ClusterEngine { * Search for cluster data that contains any of the node id's * @returns {Boolean} true if no joinCondition, otherwise return value of joinCondition */ - var findClusterData = function() { + const findClusterData = function() { for (let n = 0; n < clusters.length; ++n) { // Search for a cluster containing any of the node id's - for (var m in childNodesObj) { + for (const m in childNodesObj) { if (clusters[n].nodes[m] !== undefined) { return clusters[n]; } @@ -260,17 +260,17 @@ class ClusterEngine { // If any of the found nodes is part of a cluster found in this method, // add the current values to that cluster - var foundCluster = findClusterData(); + const foundCluster = findClusterData(); if (foundCluster !== undefined) { // Add nodes to found cluster if not present - for (let m in childNodesObj) { + for (const m in childNodesObj) { if (foundCluster.nodes[m] === undefined) { foundCluster.nodes[m] = childNodesObj[m]; } } // Add edges to found cluster, if not present - for (let m in childEdgesObj) { + for (const m in childEdgesObj) { if (foundCluster.edges[m] === undefined) { foundCluster.edges[m] = childEdgesObj[m]; } @@ -324,7 +324,7 @@ class ClusterEngine { if (nodeId === undefined) {throw new Error("No nodeId supplied to clusterByConnection!");} if (this.body.nodes[nodeId] === undefined) {throw new Error("The nodeId given to clusterByConnection does not exist!");} - let node = this.body.nodes[nodeId]; + const node = this.body.nodes[nodeId]; options = this._checkOptions(options, node); if (options.clusterNodeProperties.x === undefined) {options.clusterNodeProperties.x = node.x;} if (options.clusterNodeProperties.y === undefined) {options.clusterNodeProperties.y = node.y;} @@ -335,17 +335,17 @@ class ClusterEngine { } - let childNodesObj = {}; - let childEdgesObj = {}; - let parentNodeId = node.id; - let parentClonedOptions = NetworkUtil.cloneOptions(node); + const childNodesObj = {}; + const childEdgesObj = {}; + const parentNodeId = node.id; + const parentClonedOptions = NetworkUtil.cloneOptions(node); childNodesObj[parentNodeId] = node; // collect the nodes that will be in the cluster for (let i = 0; i < node.edges.length; i++) { - let edge = node.edges[i]; + const edge = node.edges[i]; if (this.clusteredEdges[edge.id] === undefined) { - let childNodeId = this._getConnectedId(edge, parentNodeId); + const childNodeId = this._getConnectedId(edge, parentNodeId); // if the child node is not in a cluster if (this.clusteredNodes[childNodeId] === undefined) { @@ -356,7 +356,7 @@ class ClusterEngine { } else { // clone the options and insert some additional parameters that could be interesting. - let childClonedOptions = NetworkUtil.cloneOptions(this.body.nodes[childNodeId]); + const childClonedOptions = NetworkUtil.cloneOptions(this.body.nodes[childNodeId]); if (options.joinCondition(parentClonedOptions, childClonedOptions) === true) { childEdgesObj[edge.id] = edge; childNodesObj[childNodeId] = this.body.nodes[childNodeId]; @@ -370,16 +370,16 @@ class ClusterEngine { } } } - var childNodeIDs = Object.keys(childNodesObj).map(function(childNode){ + const childNodeIDs = Object.keys(childNodesObj).map(function(childNode){ return childNodesObj[childNode].id; }) - for (childNode in childNodesObj) { - if (!childNodesObj.hasOwnProperty(childNode)) continue; + for (const childNodeKey in childNodesObj) { + if (!Object.prototype.hasOwnProperty.call(childNodesObj, childNodeKey)) continue; - var childNode = childNodesObj[childNode]; - for (var y=0; y < childNode.edges.length; y++){ - var childEdge = childNode.edges[y]; + const childNode = childNodesObj[childNodeKey]; + for (let y=0; y < childNode.edges.length; y++){ + const childEdge = childNode.edges[y]; if (childNodeIDs.indexOf(this._getConnectedId(childEdge,childNode.id)) > -1){ childEdgesObj[childEdge.id] = childEdge; } @@ -404,8 +404,8 @@ class ClusterEngine { // loop over all child nodes and their edges to find edges going out of the cluster // these edges will be replaced by clusterEdges. - let childKeys = Object.keys(childNodesObj); - let createEdges = []; + const childKeys = Object.keys(childNodesObj); + const createEdges = []; for (let i = 0; i < childKeys.length; i++) { childNodeId = childKeys[i]; childNode = childNodesObj[childNodeId]; @@ -450,20 +450,20 @@ class ClusterEngine { // // NOTE: a clustered edge can have multiple base edges! // - var newEdges = []; + const newEdges = []; /** * Find a cluster edge which matches the given created edge. * @param {vis.Edge} createdEdge * @returns {vis.Edge} */ - var getNewEdge = function(createdEdge) { + const getNewEdge = function(createdEdge) { for (let j = 0; j < newEdges.length; j++) { - let newEdge = newEdges[j]; + const newEdge = newEdges[j]; // We replace both to and from edges with a single cluster edge - let matchToDirection = (createdEdge.fromId === newEdge.fromId && createdEdge.toId === newEdge.toId); - let matchFromDirection = (createdEdge.fromId === newEdge.toId && createdEdge.toId === newEdge.fromId); + const matchToDirection = (createdEdge.fromId === newEdge.fromId && createdEdge.toId === newEdge.toId); + const matchFromDirection = (createdEdge.fromId === newEdge.toId && createdEdge.toId === newEdge.fromId); if (matchToDirection || matchFromDirection ) { return newEdge; @@ -475,8 +475,8 @@ class ClusterEngine { for (let j = 0; j < createEdges.length; j++) { - let createdEdge = createEdges[j]; - let edge = createdEdge.edge; + const createdEdge = createEdges[j]; + const edge = createdEdge.edge; let newEdge = getNewEdge(createdEdge); if (newEdge === null) { @@ -525,16 +525,16 @@ class ClusterEngine { */ _cluster(childNodesObj, childEdgesObj, options, refreshData = true) { // Remove nodes which are already clustered - var tmpNodesToRemove = [] - for (let nodeId in childNodesObj) { - if (childNodesObj.hasOwnProperty(nodeId)) { + const tmpNodesToRemove = [] + for (const nodeId in childNodesObj) { + if (Object.prototype.hasOwnProperty.call(childNodesObj, nodeId)) { if (this.clusteredNodes[nodeId] !== undefined) { tmpNodesToRemove.push(nodeId); } } } - for (var n = 0; n < tmpNodesToRemove.length; ++n) { + for (let n = 0; n < tmpNodesToRemove.length; ++n) { delete childNodesObj[tmpNodesToRemove[n]]; } @@ -549,21 +549,21 @@ class ClusterEngine { // construct the clusterNodeProperties if (options.processProperties !== undefined) { // get the childNode options - let childNodesOptions = []; - for (let nodeId in childNodesObj) { - if (childNodesObj.hasOwnProperty(nodeId)) { - let clonedOptions = NetworkUtil.cloneOptions(childNodesObj[nodeId]); + const childNodesOptions = []; + for (const nodeId in childNodesObj) { + if (Object.prototype.hasOwnProperty.call(childNodesObj, nodeId)) { + const clonedOptions = NetworkUtil.cloneOptions(childNodesObj[nodeId]); childNodesOptions.push(clonedOptions); } } // get cluster properties based on childNodes - let childEdgesOptions = []; - for (let edgeId in childEdgesObj) { - if (childEdgesObj.hasOwnProperty(edgeId)) { + const childEdgesOptions = []; + for (const edgeId in childEdgesObj) { + if (Object.prototype.hasOwnProperty.call(childEdgesObj, edgeId)) { // these cluster edges will be removed on creation of the cluster. if (edgeId.substr(0, 12) !== "clusterEdge:") { - let clonedOptions = NetworkUtil.cloneOptions(childEdgesObj[edgeId], 'edge'); + const clonedOptions = NetworkUtil.cloneOptions(childEdgesObj[edgeId], 'edge'); childEdgesOptions.push(clonedOptions); } } @@ -577,7 +577,7 @@ class ClusterEngine { // check if we have an unique id; if (clusterNodeProperties.id === undefined) {clusterNodeProperties.id = 'cluster:' + randomUUID();} - let clusterId = clusterNodeProperties.id; + const clusterId = clusterNodeProperties.id; if (clusterNodeProperties.label === undefined) { clusterNodeProperties.label = 'cluster'; @@ -600,7 +600,7 @@ class ClusterEngine { // create the cluster Node // Note that allowSingleNodeCluster, if present, is stored in the options as well - let clusterNode = this.body.functions.createNode(clusterNodeProperties, Cluster); + const clusterNode = this.body.functions.createNode(clusterNodeProperties, Cluster); clusterNode.containedNodes = childNodesObj; clusterNode.containedEdges = childEdgesObj; // cache a copy from the cluster edge properties if we have to reconnect others later on @@ -637,7 +637,7 @@ class ClusterEngine { * @private */ _restoreEdge(edge) { - let originalOptions = this.clusteredEdges[edge.id]; + const originalOptions = this.clusteredEdges[edge.id]; if (originalOptions !== undefined) { edge.setOptions({physics: originalOptions.physics}); delete this.clusteredEdges[edge.id]; @@ -667,7 +667,7 @@ class ClusterEngine { * @private */ _getClusterPosition(childNodesObj) { - let childKeys = Object.keys(childNodesObj); + const childKeys = Object.keys(childNodesObj); let minX = childNodesObj[childKeys[0]].x; let maxX = childNodesObj[childKeys[0]].x; let minY = childNodesObj[childKeys[0]].y; @@ -698,7 +698,7 @@ class ClusterEngine { throw new Error("No clusterNodeId supplied to openCluster."); } - let clusterNode = this.body.nodes[clusterNodeId]; + const clusterNode = this.body.nodes[clusterNodeId]; if (clusterNode === undefined) { throw new Error("The clusterNodeId supplied to openCluster does not exist."); @@ -710,12 +710,12 @@ class ClusterEngine { } // Check if current cluster is clustered itself - let stack = this.findNode(clusterNodeId); - let parentIndex = stack.indexOf(clusterNodeId) - 1; + const stack = this.findNode(clusterNodeId); + const parentIndex = stack.indexOf(clusterNodeId) - 1; if (parentIndex >= 0) { // Current cluster is clustered; transfer contained nodes and edges to parent - let parentClusterNodeId = stack[parentIndex]; - let parentClusterNode = this.body.nodes[parentClusterNodeId]; + const parentClusterNodeId = stack[parentIndex]; + const parentClusterNode = this.body.nodes[parentClusterNodeId]; // clustering.clusteredNodes and clustering.clusteredEdges remain unchanged parentClusterNode._openChildCluster(clusterNodeId); @@ -730,24 +730,24 @@ class ClusterEngine { } // main body - let containedNodes = clusterNode.containedNodes; - let containedEdges = clusterNode.containedEdges; + const containedNodes = clusterNode.containedNodes; + const containedEdges = clusterNode.containedEdges; // allow the user to position the nodes after release. if (options !== undefined && options.releaseFunction !== undefined && typeof options.releaseFunction === 'function') { - let positions = {}; - let clusterPosition = {x:clusterNode.x, y:clusterNode.y}; - for (let nodeId in containedNodes) { - if (containedNodes.hasOwnProperty(nodeId)) { - let containedNode = this.body.nodes[nodeId]; + const positions = {}; + const clusterPosition = {x:clusterNode.x, y:clusterNode.y}; + for (const nodeId in containedNodes) { + if (Object.prototype.hasOwnProperty.call(containedNodes, nodeId)) { + const containedNode = this.body.nodes[nodeId]; positions[nodeId] = {x: containedNode.x, y: containedNode.y}; } } - let newPositions = options.releaseFunction(clusterPosition, positions); + const newPositions = options.releaseFunction(clusterPosition, positions); - for (let nodeId in containedNodes) { - if (containedNodes.hasOwnProperty(nodeId)) { - let containedNode = this.body.nodes[nodeId]; + for (const nodeId in containedNodes) { + if (Object.prototype.hasOwnProperty.call(containedNodes, nodeId)) { + const containedNode = this.body.nodes[nodeId]; if (newPositions[nodeId] !== undefined) { containedNode.x = (newPositions[nodeId].x === undefined ? clusterNode.x : newPositions[nodeId].x); containedNode.y = (newPositions[nodeId].y === undefined ? clusterNode.y : newPositions[nodeId].y); @@ -765,9 +765,9 @@ class ClusterEngine { } // release nodes - for (let nodeId in containedNodes) { - if (containedNodes.hasOwnProperty(nodeId)) { - let containedNode = this.body.nodes[nodeId]; + for (const nodeId in containedNodes) { + if (Object.prototype.hasOwnProperty.call(containedNodes, nodeId)) { + const containedNode = this.body.nodes[nodeId]; // inherit speed containedNode.vx = clusterNode.vx; @@ -780,26 +780,26 @@ class ClusterEngine { } // copy the clusterNode edges because we cannot iterate over an object that we add or remove from. - let edgesToBeDeleted = []; + const edgesToBeDeleted = []; for (let i = 0; i < clusterNode.edges.length; i++) { edgesToBeDeleted.push(clusterNode.edges[i]); } // actually handling the deleting. for (let i = 0; i < edgesToBeDeleted.length; i++) { - let edge = edgesToBeDeleted[i]; - let otherNodeId = this._getConnectedId(edge, clusterNodeId); - let otherNode = this.clusteredNodes[otherNodeId]; + const edge = edgesToBeDeleted[i]; + const otherNodeId = this._getConnectedId(edge, clusterNodeId); + const otherNode = this.clusteredNodes[otherNodeId]; for (let j = 0; j < edge.clusteringEdgeReplacingIds.length; j++) { - let transferId = edge.clusteringEdgeReplacingIds[j]; - let transferEdge = this.body.edges[transferId]; + const transferId = edge.clusteringEdgeReplacingIds[j]; + const transferEdge = this.body.edges[transferId]; if (transferEdge === undefined) continue; // if the other node is in another cluster, we transfer ownership of this edge to the other cluster if (otherNode !== undefined) { // transfer ownership: - let otherCluster = this.body.nodes[otherNode.clusterId]; + const otherCluster = this.body.nodes[otherNode.clusterId]; otherCluster.containedEdges[transferEdge.id] = transferEdge; // delete local reference @@ -832,8 +832,8 @@ class ClusterEngine { } // handle the releasing of the edges - for (let edgeId in containedEdges) { - if (containedEdges.hasOwnProperty(edgeId)) { + for (const edgeId in containedEdges) { + if (Object.prototype.hasOwnProperty.call(containedEdges, edgeId)) { this._restoreEdge(containedEdges[edgeId]); } } @@ -852,11 +852,11 @@ class ClusterEngine { * @returns {Array.} */ getNodesInCluster(clusterId) { - let nodesArray = []; + const nodesArray = []; if (this.isCluster(clusterId) === true) { - let containedNodes = this.body.nodes[clusterId].containedNodes; - for (let nodeId in containedNodes) { - if (containedNodes.hasOwnProperty(nodeId)) { + const containedNodes = this.body.nodes[clusterId].containedNodes; + for (const nodeId in containedNodes) { + if (Object.prototype.hasOwnProperty.call(containedNodes, nodeId)) { nodesArray.push(this.body.nodes[nodeId].id) } } @@ -874,8 +874,8 @@ class ClusterEngine { * @returns {Array} */ findNode(nodeId) { - let stack = []; - let max = 100; + const stack = []; + const max = 100; let counter = 0; let node; @@ -920,9 +920,9 @@ class ClusterEngine { if (newOptions === undefined) {throw new Error("No newOptions supplied to updateEdge.");} if (this.body.edges[startEdgeId] === undefined) {throw new Error("The startEdgeId supplied to updateEdge does not exist.");} - let allEdgeIds = this.getClusteredEdges(startEdgeId); + const allEdgeIds = this.getClusteredEdges(startEdgeId); for (let i = 0; i < allEdgeIds.length; i++) { - var edge = this.body.edges[allEdgeIds[i]]; + const edge = this.body.edges[allEdgeIds[i]]; edge.setOptions(newOptions); } this.body.emitter.emit('_dataChanged'); @@ -934,8 +934,8 @@ class ClusterEngine { * @returns {Array.} */ getClusteredEdges(edgeId) { - let stack = []; - let max = 100; + const stack = []; + const max = 100; let counter = 0; while (edgeId !== undefined && this.body.edges[edgeId] !== undefined && counter < max) { @@ -967,27 +967,27 @@ class ClusterEngine { * @returns {Array.} all baseEdgeId's under this clustered edge */ getBaseEdges(clusteredEdgeId) { - let IdsToHandle = [clusteredEdgeId]; - let doneIds = []; - let foundIds = []; - let max = 100; + const IdsToHandle = [clusteredEdgeId]; + const doneIds = []; + const foundIds = []; + const max = 100; let counter = 0; while (IdsToHandle.length > 0 && counter < max) { - let nextId = IdsToHandle.pop(); + const nextId = IdsToHandle.pop(); if (nextId === undefined) continue; // Paranoia here and onwards - let nextEdge = this.body.edges[nextId]; + const nextEdge = this.body.edges[nextId]; if (nextEdge === undefined) continue; counter++; - let replacingIds = nextEdge.clusteringEdgeReplacingIds; + const replacingIds = nextEdge.clusteringEdgeReplacingIds; if (replacingIds === undefined) { // nextId is a base id foundIds.push(nextId); } else { // Another cluster edge, unravel this one as well for (let i = 0; i < replacingIds.length; ++i) { - let replacingId = replacingIds[i]; + const replacingId = replacingIds[i]; // Don't add if already handled // TODO: never triggers; find a test-case which does @@ -1039,7 +1039,7 @@ class ClusterEngine { let largestHub = 0; for (let i = 0; i < this.body.nodeIndices.length; i++) { - let node = this.body.nodes[this.body.nodeIndices[i]]; + const node = this.body.nodes[this.body.nodeIndices[i]]; if (node.edges.length > largestHub) { largestHub = node.edges.length; } @@ -1050,8 +1050,8 @@ class ClusterEngine { average = average / hubCounter; averageSquared = averageSquared / hubCounter; - let variance = averageSquared - Math.pow(average,2); - let standardDeviation = Math.sqrt(variance); + const variance = averageSquared - Math.pow(average,2); + const standardDeviation = Math.sqrt(variance); let hubThreshold = Math.floor(average + 2*standardDeviation); @@ -1077,7 +1077,7 @@ class ClusterEngine { */ _createClusteredEdge(fromId, toId, baseEdge, clusterEdgeProperties, extraOptions) { // copy the options of the edge we will replace - let clonedOptions = NetworkUtil.cloneOptions(baseEdge, 'edge'); + const clonedOptions = NetworkUtil.cloneOptions(baseEdge, 'edge'); // make sure the properties of clusterEdges are superimposed on it deepExtend(clonedOptions, clusterEdgeProperties); @@ -1091,7 +1091,7 @@ class ClusterEngine { deepExtend(clonedOptions, extraOptions); } - let newEdge = this.body.functions.createEdge(clonedOptions); + const newEdge = this.body.functions.createEdge(clonedOptions); newEdge.clusteringEdgeReplacingIds = [baseEdge.id]; newEdge.connect(); @@ -1113,15 +1113,15 @@ class ClusterEngine { */ _clusterEdges(childNodes, childEdges, clusterNode, clusterEdgeProperties) { if (childEdges instanceof Edge) { - let edge = childEdges; - let obj = {}; + const edge = childEdges; + const obj = {}; obj[edge.id] = edge; childEdges = obj; } if (childNodes instanceof Node) { - let node = childNodes; - let obj = {}; + const node = childNodes; + const obj = {}; obj[node.id] = node; childNodes = obj; } @@ -1140,10 +1140,10 @@ class ClusterEngine { this._createClusterEdges(childNodes, childEdges, clusterNode, clusterEdgeProperties); // disable the childEdges - for (let edgeId in childEdges) { - if (childEdges.hasOwnProperty(edgeId)) { + for (const edgeId in childEdges) { + if (Object.prototype.hasOwnProperty.call(childEdges, edgeId)) { if (this.body.edges[edgeId] !== undefined) { - let edge = this.body.edges[edgeId]; + const edge = this.body.edges[edgeId]; // cache the options before changing this._backupEdgeOptions(edge); // disable physics and hide the edge @@ -1153,8 +1153,8 @@ class ClusterEngine { } // disable the childNodes - for (let nodeId in childNodes) { - if (childNodes.hasOwnProperty(nodeId)) { + for (const nodeId in childNodes) { + if (Object.prototype.hasOwnProperty.call(childNodes, nodeId)) { this.clusteredNodes[nodeId] = {clusterId:clusterNode.id, node: this.body.nodes[nodeId]}; this.body.nodes[nodeId].setOptions({physics:false}); } @@ -1175,11 +1175,11 @@ class ClusterEngine { */ _getClusterNodeForNode(nodeId) { if (nodeId === undefined) return undefined; - let clusteredNode = this.clusteredNodes[nodeId]; + const clusteredNode = this.clusteredNodes[nodeId]; // NOTE: If no cluster info found, it should actually be an error if (clusteredNode === undefined) return undefined; - let clusterId = clusteredNode.clusterId; + const clusterId = clusteredNode.clusterId; if (clusterId === undefined) return undefined; return this.body.nodes[clusterId]; @@ -1197,7 +1197,7 @@ class ClusterEngine { * @private */ _filter(arr, callback) { - let ret = []; + const ret = []; forEach(arr, (item) => { if (callback(item)) { @@ -1220,15 +1220,15 @@ class ClusterEngine { */ _updateState() { let nodeId; - let deletedNodeIds = []; - let deletedEdgeIds = {}; + const deletedNodeIds = []; + const deletedEdgeIds = {}; /** * Utility function to iterate over clustering nodes only * * @param {Function} callback function to call for each cluster node */ - let eachClusterNode = (callback) => { + const eachClusterNode = (callback) => { forEach(this.body.nodes, (node) => { if (node.isCluster === true) { callback(node); @@ -1243,8 +1243,8 @@ class ClusterEngine { // Determine the deleted nodes for (nodeId in this.clusteredNodes) { - if (!this.clusteredNodes.hasOwnProperty(nodeId)) continue; - let node = this.body.nodes[nodeId]; + if (!Object.prototype.hasOwnProperty.call(this.clusteredNodes, nodeId)) continue; + const node = this.body.nodes[nodeId]; if (node === undefined) { deletedNodeIds.push(nodeId); @@ -1270,7 +1270,7 @@ class ClusterEngine { // Add the deleted clustered edges to the list forEach(this.clusteredEdges, (edgeId) => { - let edge = this.body.edges[edgeId]; + const edge = this.body.edges[edgeId]; if (edge === undefined || !edge.endPointsValid()) { deletedEdgeIds[edgeId] = edgeId; } @@ -1292,12 +1292,12 @@ class ClusterEngine { forEach(this.body.edges, (edge, edgeId) => { // Explicitly scan the contained edges for validity let isValid = true; - let replacedIds = edge.clusteringEdgeReplacingIds; + const replacedIds = edge.clusteringEdgeReplacingIds; if (replacedIds !== undefined) { let numValid = 0; forEach(replacedIds, (containedEdgeId) => { - let containedEdge = this.body.edges[containedEdgeId]; + const containedEdge = this.body.edges[containedEdgeId]; if (containedEdge !== undefined && containedEdge.endPointsValid()) { numValid += 1; @@ -1352,23 +1352,23 @@ class ClusterEngine { // // Iterating over keys here, because edges may be removed in the loop - let ids = Object.keys(this.body.edges); + const ids = Object.keys(this.body.edges); forEach(ids, (edgeId) => { - let edge = this.body.edges[edgeId]; + const edge = this.body.edges[edgeId]; - let shouldBeClustered = this._isClusteredNode(edge.fromId) || this._isClusteredNode(edge.toId); + const shouldBeClustered = this._isClusteredNode(edge.fromId) || this._isClusteredNode(edge.toId); if (shouldBeClustered === this._isClusteredEdge(edge.id)) { return; // all is well } if (shouldBeClustered) { // add edge to clustering - let clusterFrom = this._getClusterNodeForNode(edge.fromId); + const clusterFrom = this._getClusterNodeForNode(edge.fromId); if (clusterFrom !== undefined) { this._clusterEdges(this.body.nodes[edge.fromId], edge, clusterFrom); } - let clusterTo = this._getClusterNodeForNode(edge.toId); + const clusterTo = this._getClusterNodeForNode(edge.toId); if (clusterTo !== undefined) { this._clusterEdges(this.body.nodes[edge.toId], edge, clusterTo); } @@ -1389,15 +1389,15 @@ class ClusterEngine { // Clusters may be nested to any level. Keep on opening until nothing to open - var changed = false; - var continueLoop = true; + let changed = false; + let continueLoop = true; while (continueLoop) { - let clustersToOpen = []; + const clustersToOpen = []; // Determine the id's of clusters that need opening eachClusterNode(function(clusterNode) { - let numNodes = Object.keys(clusterNode.containedNodes).length; - let allowSingle = (clusterNode.options.allowSingleNodeCluster === true); + const numNodes = Object.keys(clusterNode.containedNodes).length; + const allowSingle = (clusterNode.options.allowSingleNodeCluster === true); if ((allowSingle && numNodes < 1) || (!allowSingle && numNodes < 2)) { clustersToOpen.push(clusterNode.id); } diff --git a/lib/network/modules/EdgesHandler.js b/lib/network/modules/EdgesHandler.js index 3e6455d1f2..e0ecf5b4f9 100644 --- a/lib/network/modules/EdgesHandler.js +++ b/lib/network/modules/EdgesHandler.js @@ -92,7 +92,7 @@ class EdgesHandler { return 0.5; } else { - var scale = 1 / (max - min); + const scale = 1 / (max - min); return Math.max(0,(value - min)*scale); } } @@ -142,15 +142,15 @@ class EdgesHandler { type = 'continuous'; } let dataChanged = false; - for (let edgeId in this.body.edges) { - if (this.body.edges.hasOwnProperty(edgeId)) { - let edge = this.body.edges[edgeId]; + for (const edgeId in this.body.edges) { + if (Object.prototype.hasOwnProperty.call(this.body.edges, edgeId)) { + const edge = this.body.edges[edgeId]; const edgeData = this.body.data.edges.get(edgeId); // only forcibly remove the smooth curve if the data has been set of the edge has the smooth curves defined. // this is because a change in the global would not affect these curves. if (edgeData != null) { - let smoothOptions = edgeData.smooth; + const smoothOptions = edgeData.smooth; if (smoothOptions !== undefined) { if (smoothOptions.enabled === true && smoothOptions.type === 'dynamic') { if (type === undefined) { @@ -211,8 +211,8 @@ class EdgesHandler { // update smooth settings in all edges let dataChanged = false; if (options.smooth !== undefined) { - for (let edgeId in this.body.edges) { - if (this.body.edges.hasOwnProperty(edgeId)) { + for (const edgeId in this.body.edges) { + if (Object.prototype.hasOwnProperty.call(this.body.edges, edgeId)) { dataChanged = this.body.edges[edgeId].updateEdgeType() || dataChanged; } } @@ -220,8 +220,8 @@ class EdgesHandler { // update fonts in all edges if (options.font !== undefined) { - for (let edgeId in this.body.edges) { - if (this.body.edges.hasOwnProperty(edgeId)) { + for (const edgeId in this.body.edges) { + if (Object.prototype.hasOwnProperty.call(this.body.edges, edgeId)) { this.body.edges[edgeId].updateLabelModule(); } } @@ -242,7 +242,7 @@ class EdgesHandler { * @private */ setData(edges, doNotEmit = false) { - var oldEdgesData = this.body.data.edges; + const oldEdgesData = this.body.data.edges; if (edges instanceof DataSet || edges instanceof DataView) { this.body.data.edges = edges; @@ -273,7 +273,7 @@ class EdgesHandler { forEach(this.edgesListeners, (callback, event) => {this.body.data.edges.on(event, callback);}); // draw all new nodes - var ids = this.body.data.edges.getIds(); + const ids = this.body.data.edges.getIds(); this.add(ids, true); } @@ -291,18 +291,18 @@ class EdgesHandler { * @private */ add(ids, doNotEmit = false) { - var edges = this.body.edges; - var edgesData = this.body.data.edges; + const edges = this.body.edges; + const edgesData = this.body.data.edges; for (let i = 0; i < ids.length; i++) { - var id = ids[i]; + const id = ids[i]; - var oldEdge = edges[id]; + const oldEdge = edges[id]; if (oldEdge) { oldEdge.disconnect(); } - var data = edgesData.get(id, {"showInternalIds" : true}); + const data = edgesData.get(id, {"showInternalIds" : true}); edges[id] = this.create(data); } @@ -321,13 +321,13 @@ class EdgesHandler { * @private */ update(ids) { - var edges = this.body.edges; - var edgesData = this.body.data.edges; - var dataChanged = false; - for (var i = 0; i < ids.length; i++) { - var id = ids[i]; - var data = edgesData.get(id); - var edge = edges[id]; + const edges = this.body.edges; + const edgesData = this.body.data.edges; + let dataChanged = false; + for (let i = 0; i < ids.length; i++) { + const id = ids[i]; + const data = edgesData.get(id); + const edge = edges[id]; if (edge !== undefined) { // update edge edge.disconnect(); @@ -360,9 +360,9 @@ class EdgesHandler { remove(ids, emit = true) { if (ids.length === 0) return; // early out - var edges = this.body.edges; + const edges = this.body.edges; forEach(ids, (id) => { - var edge = edges[id]; + const edge = edges[id]; if (edge !== undefined) { edge.remove(); } @@ -405,19 +405,19 @@ class EdgesHandler { * @private */ reconnectEdges() { - var id; - var nodes = this.body.nodes; - var edges = this.body.edges; + let id; + const nodes = this.body.nodes; + const edges = this.body.edges; for (id in nodes) { - if (nodes.hasOwnProperty(id)) { + if (Object.prototype.hasOwnProperty.call(nodes, id)) { nodes[id].edges = []; } } for (id in edges) { - if (edges.hasOwnProperty(id)) { - var edge = edges[id]; + if (Object.prototype.hasOwnProperty.call(edges, id)) { + const edge = edges[id]; edge.from = null; edge.to = null; edge.connect(); @@ -431,9 +431,9 @@ class EdgesHandler { * @returns {Array} */ getConnectedNodes(edgeId) { - let nodeList = []; + const nodeList = []; if (this.body.edges[edgeId] !== undefined) { - let edge = this.body.edges[edgeId]; + const edge = this.body.edges[edgeId]; if (edge.fromId !== undefined) {nodeList.push(edge.fromId);} if (edge.toId !== undefined) {nodeList.push(edge.toId);} } @@ -455,11 +455,11 @@ class EdgesHandler { */ _removeInvalidEdges() { - let edgesToDelete = []; + const edgesToDelete = []; forEach(this.body.edges, (edge, id) => { - let toNode = this.body.nodes[edge.toId]; - let fromNode = this.body.nodes[edge.fromId]; + const toNode = this.body.nodes[edge.toId]; + const fromNode = this.body.nodes[edge.fromId]; // Skip clustering edges here, let the Clustering module handle those if ((toNode !== undefined && toNode.isCluster === true) @@ -480,16 +480,16 @@ class EdgesHandler { * @private */ _addMissingEdges() { - let edgesData = this.body.data.edges; + const edgesData = this.body.data.edges; if (edgesData === undefined || edgesData === null) { return; // No edges DataSet yet; can happen on startup } - let edges = this.body.edges; - let addIds = []; + const edges = this.body.edges; + const addIds = []; edgesData.forEach((edgeData, edgeId) => { - let edge = edges[edgeId]; + const edge = edges[edgeId]; if(edge===undefined) { addIds.push(edgeId); } diff --git a/lib/network/modules/Groups.js b/lib/network/modules/Groups.js index b0b18af0df..aae9e3c871 100644 --- a/lib/network/modules/Groups.js +++ b/lib/network/modules/Groups.js @@ -49,13 +49,13 @@ class Groups { * @param {Object} options */ setOptions(options) { - let optionFields = ['useDefaultGroups']; + const optionFields = ['useDefaultGroups']; if (options !== undefined) { - for (let groupName in options) { - if (options.hasOwnProperty(groupName)) { + for (const groupName in options) { + if (Object.prototype.hasOwnProperty.call(options, groupName)) { if (optionFields.indexOf(groupName) === -1) { - let group = options[groupName]; + const group = options[groupName]; this.add(groupName, group); } } @@ -86,7 +86,7 @@ class Groups { if (group === undefined && shouldCreate) { if (this.options.useDefaultGroups === false && this.groupsArray.length > 0) { // create new group - let index = this.groupIndex % this.groupsArray.length; + const index = this.groupIndex % this.groupsArray.length; this.groupIndex++; group = {}; group.color = this.groups[this.groupsArray[index]]; @@ -94,7 +94,7 @@ class Groups { } else { // create new group - let index = this.defaultIndex % this.defaultGroups.length; + const index = this.defaultIndex % this.defaultGroups.length; this.defaultIndex++; group = {}; group.color = this.defaultGroups[index]; diff --git a/lib/network/modules/InteractionHandler.js b/lib/network/modules/InteractionHandler.js index 5652f35b8b..06eca894f8 100644 --- a/lib/network/modules/InteractionHandler.js +++ b/lib/network/modules/InteractionHandler.js @@ -84,7 +84,7 @@ class InteractionHandler { setOptions(options) { if (options !== undefined) { // extend all but the values in fields - let fields = ['hideEdgesOnDrag', 'hideEdgesOnZoom', 'hideNodesOnDrag','keyboard','multiselect','selectable','selectConnectedEdges']; + const fields = ['hideEdgesOnDrag', 'hideEdgesOnZoom', 'hideNodesOnDrag','keyboard','multiselect','selectable','selectConnectedEdges']; selectiveNotDeepExtend(fields, this.options, options); // merge the keyboard options in. @@ -138,8 +138,8 @@ class InteractionHandler { * @private */ onTap(event) { - let pointer = this.getPointer(event.center); - let multiselect = this.selectionHandler.options.multiselect && + const pointer = this.getPointer(event.center); + const multiselect = this.selectionHandler.options.multiselect && (event.changedPointers[0].ctrlKey || event.changedPointers[0].metaKey); this.checkSelectionChanges(pointer, event, multiselect); @@ -153,7 +153,7 @@ class InteractionHandler { * @private */ onDoubleTap(event) { - let pointer = this.getPointer(event.center); + const pointer = this.getPointer(event.center); this.selectionHandler._generateClickEvent('doubleClick', event, pointer); } @@ -164,8 +164,8 @@ class InteractionHandler { * @private */ onHold(event) { - let pointer = this.getPointer(event.center); - let multiselect = this.selectionHandler.options.multiselect; + const pointer = this.getPointer(event.center); + const multiselect = this.selectionHandler.options.multiselect; this.checkSelectionChanges(pointer, event, multiselect); @@ -182,7 +182,7 @@ class InteractionHandler { */ onRelease(event) { if (new Date().valueOf() - this.touchTime > 10) { - let pointer = this.getPointer(event.center); + const pointer = this.getPointer(event.center); this.selectionHandler._generateClickEvent('release', event, pointer); // to avoid double fireing of this event because we have two hammer instances. (on canvas and on frame) this.touchTime = new Date().valueOf(); @@ -194,7 +194,7 @@ class InteractionHandler { * @param {Event} event */ onContext(event) { - let pointer = this.getPointer({x:event.clientX, y:event.clientY}); + const pointer = this.getPointer({x:event.clientX, y:event.clientY}); this.selectionHandler._generateClickEvent('oncontext', event, pointer); } @@ -215,7 +215,7 @@ class InteractionHandler { * @param {boolean} [add=false] */ checkSelectionChanges(pointer, event, add = false) { - let previousSelection = this.selectionHandler.getSelection(); + const previousSelection = this.selectionHandler.getSelection(); let selected = false; if (add === true) { selected = this.selectionHandler.selectAdditionalOnPoint(pointer); @@ -223,11 +223,11 @@ class InteractionHandler { else { selected = this.selectionHandler.selectOnPoint(pointer); } - let currentSelection = this.selectionHandler.getSelection(); + const currentSelection = this.selectionHandler.getSelection(); // See NOTE in method comment for the reason to do it like this - let deselectedItems = this._determineDifference(previousSelection, currentSelection); - let selectedItems = this._determineDifference(currentSelection , previousSelection); + const deselectedItems = this._determineDifference(previousSelection, currentSelection); + const selectedItems = this._determineDifference(currentSelection , previousSelection); if (deselectedItems.edges.length > 0) { this.selectionHandler._generateClickEvent('deselectEdge', event, pointer, previousSelection); @@ -265,11 +265,11 @@ class InteractionHandler { * @private */ _determineDifference(firstSet, secondSet) { - let arrayDiff = function(firstArr, secondArr) { - let result = []; + const arrayDiff = function(firstArr, secondArr) { + const result = []; for (let i = 0; i < firstArr.length; i++) { - let value = firstArr[i]; + const value = firstArr[i]; if (secondArr.indexOf(value) === -1) { result.push(value); } @@ -305,7 +305,7 @@ class InteractionHandler { } // note: drag.pointer is set in onTouch to get the initial touch location - let node = this.selectionHandler.getNodeAt(this.drag.pointer); + const node = this.selectionHandler.getNodeAt(this.drag.pointer); this.drag.dragging = true; this.drag.selection = []; @@ -314,7 +314,7 @@ class InteractionHandler { if (event.srcEvent.shiftKey) { this.body.selectionBox.show = true; - let pointer = this.getPointer(event.center); + const pointer = this.getPointer(event.center); this.body.selectionBox.position.start = { x: this.canvas._XconvertDOMtoCanvas(pointer.x), y: this.canvas._YconvertDOMtoCanvas(pointer.y) }; this.body.selectionBox.position.end = { x: this.canvas._XconvertDOMtoCanvas(pointer.x), y: this.canvas._YconvertDOMtoCanvas(pointer.y) }; @@ -331,12 +331,12 @@ class InteractionHandler { // after select to contain the node this.selectionHandler._generateClickEvent('dragStart', event, this.drag.pointer); - let selection = this.selectionHandler.selectionObj.nodes; + const selection = this.selectionHandler.selectionObj.nodes; // create an array with the selected nodes and their original location and status - for (let nodeId in selection) { - if (selection.hasOwnProperty(nodeId)) { - let object = selection[nodeId]; - let s = { + for (const nodeId in selection) { + if (Object.prototype.hasOwnProperty.call(selection, nodeId)) { + const object = selection[nodeId]; + const s = { id: object.id, node: object, @@ -374,19 +374,19 @@ class InteractionHandler { // remove the focus on node if it is focussed on by the focusOnNode this.body.emitter.emit('unlockNode'); - let pointer = this.getPointer(event.center); + const pointer = this.getPointer(event.center); - let selection = this.drag.selection; + const selection = this.drag.selection; if (selection && selection.length && this.options.dragNodes === true) { this.selectionHandler._generateClickEvent('dragging', event, pointer); // calculate delta's and new location - let deltaX = pointer.x - this.drag.pointer.x; - let deltaY = pointer.y - this.drag.pointer.y; + const deltaX = pointer.x - this.drag.pointer.x; + const deltaY = pointer.y - this.drag.pointer.y; // update position of all selected nodes selection.forEach((selection) => { - let node = selection.node; + const node = selection.node; // only move the node if it was not fixed initially if (selection.xFixed === false) { node.x = this.canvas._XconvertDOMtoCanvas(this.canvas._XconvertCanvasToDOM(selection.x) + deltaX); @@ -425,8 +425,8 @@ class InteractionHandler { return; } - let diffX = pointer.x - this.drag.pointer.x; - let diffY = pointer.y - this.drag.pointer.y; + const diffX = pointer.x - this.drag.pointer.x; + const diffY = pointer.y - this.drag.pointer.y; this.body.view.translation = {x:this.drag.translation.x + diffX, y:this.drag.translation.y + diffY}; this.body.emitter.emit('_requestRedraw'); @@ -465,7 +465,7 @@ class InteractionHandler { this.selectionHandler._generateClickEvent('dragEnd', event, this.getPointer(event.center), undefined, true); this.body.emitter.emit('_requestRedraw'); } else { - let selection = this.drag.selection; + const selection = this.drag.selection; if (selection && selection.length) { selection.forEach(function (s) { // restore original xFixed and yFixed @@ -490,7 +490,7 @@ class InteractionHandler { * @private */ onPinch(event) { - let pointer = this.getPointer(event.center); + const pointer = this.getPointer(event.center); this.drag.pinched = true; if (this.pinch['scale'] === undefined) { @@ -498,7 +498,7 @@ class InteractionHandler { } // TODO: enabled moving while pinching? - let scale = this.pinch.scale * event.scale; + const scale = this.pinch.scale * event.scale; this.zoom(scale, pointer) } @@ -511,7 +511,7 @@ class InteractionHandler { */ zoom(scale, pointer) { if (this.options.zoomView === true) { - let scaleOld = this.body.view.scale; + const scaleOld = this.body.view.scale; if (scale < 0.00001) { scale = 0.00001; } @@ -526,17 +526,17 @@ class InteractionHandler { } } // + this.canvas.frame.canvas.clientHeight / 2 - let translation = this.body.view.translation; + const translation = this.body.view.translation; - let scaleFrac = scale / scaleOld; - let tx = (1 - scaleFrac) * pointer.x + translation.x * scaleFrac; - let ty = (1 - scaleFrac) * pointer.y + translation.y * scaleFrac; + const scaleFrac = scale / scaleOld; + const tx = (1 - scaleFrac) * pointer.x + translation.x * scaleFrac; + const ty = (1 - scaleFrac) * pointer.y + translation.y * scaleFrac; this.body.view.scale = scale; this.body.view.translation = {x:tx, y:ty}; if (preScaleDragPointer != undefined) { - let postScaleDragPointer = this.canvas.canvasToDOM(preScaleDragPointer); + const postScaleDragPointer = this.canvas.canvasToDOM(preScaleDragPointer); this.drag.pointer.x = postScaleDragPointer.x; this.drag.pointer.y = postScaleDragPointer.y; } @@ -572,7 +572,7 @@ class InteractionHandler { scale *= 1 + (event.deltaY < 0 ? 1 : -1) * (this.options.zoomSpeed * 0.1); // calculate the pointer location - let pointer = this.getPointer({x: event.clientX, y: event.clientY}); + const pointer = this.getPointer({x: event.clientX, y: event.clientY}); // apply the new scale this.zoom(scale, pointer); @@ -590,7 +590,7 @@ class InteractionHandler { * @private */ onMouseMove(event) { - let pointer = this.getPointer({x:event.clientX, y:event.clientY}); + const pointer = this.getPointer({x:event.clientX, y:event.clientY}); let popupVisible = false; // check if the previously selected node is still selected @@ -640,26 +640,26 @@ class InteractionHandler { * @private */ _checkShowPopup(pointer) { - let x = this.canvas._XconvertDOMtoCanvas(pointer.x); - let y = this.canvas._YconvertDOMtoCanvas(pointer.y); - let pointerObj = { + const x = this.canvas._XconvertDOMtoCanvas(pointer.x); + const y = this.canvas._YconvertDOMtoCanvas(pointer.y); + const pointerObj = { left: x, top: y, right: x, bottom: y }; - let previousPopupObjId = this.popupObj === undefined ? undefined : this.popupObj.id; + const previousPopupObjId = this.popupObj === undefined ? undefined : this.popupObj.id; let nodeUnderCursor = false; let popupType = 'node'; // check if a node is under the cursor. if (this.popupObj === undefined) { // search the nodes for overlap, select the top one in case of multiple nodes - let nodeIndices = this.body.nodeIndices; - let nodes = this.body.nodes; + const nodeIndices = this.body.nodeIndices; + const nodes = this.body.nodes; let node; - let overlappingNodes = []; + const overlappingNodes = []; for (let i = 0; i < nodeIndices.length; i++) { node = nodes[nodeIndices[i]]; if (node.isOverlappingWith(pointerObj) === true) { @@ -680,10 +680,10 @@ class InteractionHandler { if (this.popupObj === undefined && nodeUnderCursor === false) { // search the edges for overlap - let edgeIndices = this.body.edgeIndices; - let edges = this.body.edges; + const edgeIndices = this.body.edgeIndices; + const edges = this.body.edges; let edge; - let overlappingEdges = []; + const overlappingEdges = []; for (let i = 0; i < edgeIndices.length; i++) { edge = edges[edgeIndices[i]]; if (edge.isOverlappingWith(pointerObj) === true) { @@ -734,7 +734,7 @@ class InteractionHandler { * @private */ _checkHidePopup(pointer) { - let pointerObj = this.selectionHandler._pointerToPositionObject(pointer); + const pointerObj = this.selectionHandler._pointerToPositionObject(pointer); let stillOnObj = false; if (this.popup.popupTargetType === 'node') { @@ -744,7 +744,7 @@ class InteractionHandler { // if the mouse is still one the node, we have to check if it is not also on one that is drawn on top of it. // we initially only check stillOnObj because this is much faster. if (stillOnObj === true) { - let overNode = this.selectionHandler.getNodeAt(pointer); + const overNode = this.selectionHandler.getNodeAt(pointer); stillOnObj = overNode === undefined ? false : overNode.id === this.popup.popupTargetId; } } diff --git a/lib/network/modules/KamadaKawai.js b/lib/network/modules/KamadaKawai.js index f12df5135f..cf6ef8aecd 100644 --- a/lib/network/modules/KamadaKawai.js +++ b/lib/network/modules/KamadaKawai.js @@ -47,7 +47,7 @@ class KamadaKawai { */ solve(nodesArray, edgesArray, ignoreClusters = false) { // get distance matrix - let D_matrix = this.distanceSolver.getDistances(this.body, nodesArray, edgesArray); // distance matrix + const D_matrix = this.distanceSolver.getDistances(this.body, nodesArray, edgesArray); // distance matrix // get the L Matrix this._createL_matrix(D_matrix); @@ -59,11 +59,11 @@ class KamadaKawai { this._createE_matrix(); // calculate positions - let threshold = 0.01; - let innerThreshold = 1; + const threshold = 0.01; + const innerThreshold = 1; let iterations = 0; - let maxIterations = Math.max(1000, Math.min(10 * this.body.nodeIndices.length, 6000)); - let maxInnerIterations = 5; + const maxIterations = Math.max(1000, Math.min(10 * this.body.nodeIndices.length, 6000)); + const maxInnerIterations = 5; let maxEnergy = 1e9; let highE_nodeId = 0, dE_dx = 0, dE_dy = 0, delta_m = 0, subIterations = 0; @@ -88,17 +88,17 @@ class KamadaKawai { * @private */ _getHighestEnergyNode(ignoreClusters) { - let nodesArray = this.body.nodeIndices; - let nodes = this.body.nodes; + const nodesArray = this.body.nodeIndices; + const nodes = this.body.nodes; let maxEnergy = 0; let maxEnergyNodeId = nodesArray[0]; let dE_dx_max = 0, dE_dy_max = 0; for (let nodeIdx = 0; nodeIdx < nodesArray.length; nodeIdx++) { - let m = nodesArray[nodeIdx]; + const m = nodesArray[nodeIdx]; // by not evaluating nodes with predefined positions we should only move nodes that have no positions. if ((nodes[m].predefinedPosition === false || nodes[m].isCluster === true && ignoreClusters === true) || nodes[m].options.fixed.x === true || nodes[m].options.fixed.y === true) { - let [delta_m,dE_dx,dE_dy] = this._getEnergy(m); + const [delta_m,dE_dx,dE_dy] = this._getEnergy(m); if (maxEnergy < delta_m) { maxEnergy = delta_m; maxEnergyNodeId = m; @@ -118,8 +118,8 @@ class KamadaKawai { * @private */ _getEnergy(m) { - let [dE_dx,dE_dy] = this.E_sums[m]; - let delta_m = Math.sqrt((dE_dx ** 2) + (dE_dy ** 2)); + const [dE_dx,dE_dy] = this.E_sums[m]; + const delta_m = Math.sqrt((dE_dx ** 2) + (dE_dy ** 2)); return [delta_m, dE_dx, dE_dy]; } @@ -132,36 +132,36 @@ class KamadaKawai { * @private */ _moveNode(m, dE_dx, dE_dy) { - let nodesArray = this.body.nodeIndices; - let nodes = this.body.nodes; + const nodesArray = this.body.nodeIndices; + const nodes = this.body.nodes; let d2E_dx2 = 0; let d2E_dxdy = 0; let d2E_dy2 = 0; - let x_m = nodes[m].x; - let y_m = nodes[m].y; - let km = this.K_matrix[m]; - let lm = this.L_matrix[m]; + const x_m = nodes[m].x; + const y_m = nodes[m].y; + const km = this.K_matrix[m]; + const lm = this.L_matrix[m]; for (let iIdx = 0; iIdx < nodesArray.length; iIdx++) { - let i = nodesArray[iIdx]; + const i = nodesArray[iIdx]; if (i !== m) { - let x_i = nodes[i].x; - let y_i = nodes[i].y; - let kmat = km[i]; - let lmat = lm[i]; - let denominator = 1.0 / ((((x_m - x_i) ** 2) + ((y_m - y_i) ** 2)) ** 1.5); + const x_i = nodes[i].x; + const y_i = nodes[i].y; + const kmat = km[i]; + const lmat = lm[i]; + const denominator = 1.0 / ((((x_m - x_i) ** 2) + ((y_m - y_i) ** 2)) ** 1.5); d2E_dx2 += kmat * (1 - lmat * ((y_m - y_i) ** 2) * denominator); d2E_dxdy += kmat * (lmat * (x_m - x_i) * (y_m - y_i) * denominator); d2E_dy2 += kmat * (1 - lmat * ((x_m - x_i) ** 2) * denominator); } } // make the variable names easier to make the solving of the linear system easier to read - let A = d2E_dx2, B = d2E_dxdy, C = dE_dx, D = d2E_dy2, E = dE_dy; + const A = d2E_dx2, B = d2E_dxdy, C = dE_dx, D = d2E_dy2, E = dE_dy; // solve the linear system for dx and dy - let dy = (C / A + E / B) / (B / A - D / B); - let dx = -(B * dy + C) / A; + const dy = (C / A + E / B) / (B / A - D / B); + const dx = -(B * dy + C) / A; // move the node nodes[m].x += dx; @@ -178,8 +178,8 @@ class KamadaKawai { * @private */ _createL_matrix(D_matrix) { - let nodesArray = this.body.nodeIndices; - let edgeLength = this.springLength; + const nodesArray = this.body.nodeIndices; + const edgeLength = this.springLength; this.L_matrix = []; for (let i = 0; i < nodesArray.length; i++) { @@ -197,8 +197,8 @@ class KamadaKawai { * @private */ _createK_matrix(D_matrix) { - let nodesArray = this.body.nodeIndices; - let edgeStrength = this.springConstant; + const nodesArray = this.body.nodeIndices; + const edgeStrength = this.springConstant; this.K_matrix = []; for (let i = 0; i < nodesArray.length; i++) { @@ -214,25 +214,25 @@ class KamadaKawai { * @private */ _createE_matrix() { - let nodesArray = this.body.nodeIndices; - let nodes = this.body.nodes; + const nodesArray = this.body.nodeIndices; + const nodes = this.body.nodes; this.E_matrix = {}; this.E_sums = {}; for (let mIdx = 0; mIdx < nodesArray.length; mIdx++) { this.E_matrix[nodesArray[mIdx]] = []; } for (let mIdx = 0; mIdx < nodesArray.length; mIdx++) { - let m = nodesArray[mIdx]; - let x_m = nodes[m].x; - let y_m = nodes[m].y; + const m = nodesArray[mIdx]; + const x_m = nodes[m].x; + const y_m = nodes[m].y; let dE_dx = 0; let dE_dy = 0; for (let iIdx = mIdx; iIdx < nodesArray.length; iIdx++) { - let i = nodesArray[iIdx]; + const i = nodesArray[iIdx]; if (i !== m) { - let x_i = nodes[i].x; - let y_i = nodes[i].y; - let denominator = 1.0 / Math.sqrt(((x_m - x_i) ** 2) + ((y_m - y_i) ** 2)); + const x_i = nodes[i].x; + const y_i = nodes[i].y; + const denominator = 1.0 / Math.sqrt(((x_m - x_i) ** 2) + ((y_m - y_i) ** 2)); this.E_matrix[m][iIdx] = [ this.K_matrix[m][i] * ((x_m - x_i) - this.L_matrix[m][i] * (x_m - x_i) * denominator), this.K_matrix[m][i] * ((y_m - y_i) - this.L_matrix[m][i] * (y_m - y_i) * denominator) @@ -254,35 +254,35 @@ class KamadaKawai { * @private */ _updateE_matrix(m) { - let nodesArray = this.body.nodeIndices; - let nodes = this.body.nodes; - let colm = this.E_matrix[m]; - let kcolm = this.K_matrix[m]; - let lcolm = this.L_matrix[m]; - let x_m = nodes[m].x; - let y_m = nodes[m].y; + const nodesArray = this.body.nodeIndices; + const nodes = this.body.nodes; + const colm = this.E_matrix[m]; + const kcolm = this.K_matrix[m]; + const lcolm = this.L_matrix[m]; + const x_m = nodes[m].x; + const y_m = nodes[m].y; let dE_dx = 0; let dE_dy = 0; for (let iIdx = 0; iIdx < nodesArray.length; iIdx++) { - let i = nodesArray[iIdx]; + const i = nodesArray[iIdx]; if (i !== m) { //Keep old energy value for sum modification below - let cell = colm[iIdx]; - let oldDx = cell[0]; - let oldDy = cell[1]; + const cell = colm[iIdx]; + const oldDx = cell[0]; + const oldDy = cell[1]; //Calc new energy: - let x_i = nodes[i].x; - let y_i = nodes[i].y; - let denominator = 1.0 / Math.sqrt(((x_m - x_i) ** 2) + ((y_m - y_i) ** 2)); - let dx = kcolm[i] * ((x_m - x_i) - lcolm[i] * (x_m - x_i) * denominator); - let dy = kcolm[i] * ((y_m - y_i) - lcolm[i] * (y_m - y_i) * denominator); + const x_i = nodes[i].x; + const y_i = nodes[i].y; + const denominator = 1.0 / Math.sqrt(((x_m - x_i) ** 2) + ((y_m - y_i) ** 2)); + const dx = kcolm[i] * ((x_m - x_i) - lcolm[i] * (x_m - x_i) * denominator); + const dy = kcolm[i] * ((y_m - y_i) - lcolm[i] * (y_m - y_i) * denominator); colm[iIdx] = [dx, dy]; dE_dx += dx; dE_dy += dy; //add new energy to sum of each column - let sum = this.E_sums[i]; + const sum = this.E_sums[i]; sum[0] += (dx-oldDx); sum[1] += (dy-oldDy); } diff --git a/lib/network/modules/LayoutEngine.js b/lib/network/modules/LayoutEngine.js index 5410c3e2ae..e2f05113af 100644 --- a/lib/network/modules/LayoutEngine.js +++ b/lib/network/modules/LayoutEngine.js @@ -95,7 +95,7 @@ class HierarchicalStatus { * Pre: parentReference init'ed properly for current network */ checkIfTree() { - for (let i in this.parentReference) { + for (const i in this.parentReference) { if (this.parentReference[i].length > 1) { this.isTree = false; return; @@ -152,15 +152,15 @@ class HierarchicalStatus { * @returns {number} */ getMaxLevel(nodeId) { - let accumulator = {}; + const accumulator = {}; - let _getMaxLevel = (nodeId) => { + const _getMaxLevel = (nodeId) => { if (accumulator[nodeId] !== undefined) { return accumulator[nodeId]; } let level = this.levels[nodeId]; if (this.childrenReference[nodeId]) { - let children = this.childrenReference[nodeId]; + const children = this.childrenReference[nodeId]; if (children.length > 0) { for (let i = 0; i < children.length; i++) { level = Math.max(level,_getMaxLevel(children[i])); @@ -200,8 +200,8 @@ class HierarchicalStatus { setMinLevelToZero(nodes) { let minLevel = 1e9; // get the minimum level - for (let nodeId in nodes) { - if (nodes.hasOwnProperty(nodeId)) { + for (const nodeId in nodes) { + if (Object.prototype.hasOwnProperty.call(nodes, nodeId)) { if (this.levels[nodeId] !== undefined) { minLevel = Math.min(this.levels[nodeId], minLevel); } @@ -209,8 +209,8 @@ class HierarchicalStatus { } // subtract the minimum from the set so we have a range starting from 0 - for (let nodeId in nodes) { - if (nodes.hasOwnProperty(nodeId)) { + for (const nodeId in nodes) { + if (Object.prototype.hasOwnProperty.call(nodes, nodeId)) { if (this.levels[nodeId] !== undefined) { this.levels[nodeId] -= minLevel; } @@ -232,10 +232,10 @@ class HierarchicalStatus { let min_y = 1e9; let max_y = -1e9; - for (let nodeId in this.trees) { - if (this.trees.hasOwnProperty(nodeId)) { + for (const nodeId in this.trees) { + if (Object.prototype.hasOwnProperty.call(this.trees, nodeId)) { if (this.trees[nodeId] === index) { - let node = nodes[nodeId]; + const node = nodes[nodeId]; min_x = Math.min(node.x, min_x); max_x = Math.max(node.x, max_x); min_y = Math.min(node.y, min_y); @@ -261,8 +261,8 @@ class HierarchicalStatus { * @return {boolean} true if the two nodes have a same ancestor node, false otherwise */ hasSameParent(node1, node2) { - let parents1 = this.parentReference[node1.id]; - let parents2 = this.parentReference[node2.id]; + const parents1 = this.parentReference[node1.id]; + const parents2 = this.parentReference[node2.id]; if (parents1 === undefined || parents2 === undefined) { return false; } @@ -311,9 +311,9 @@ class HierarchicalStatus { this.distributionOrdering[level] = []; } - var isPresent = false; - var curLevel = this.distributionOrdering[level]; - for (var n in curLevel) { + let isPresent = false; + const curLevel = this.distributionOrdering[level]; + for (const n in curLevel) { //if (curLevel[n].id === node.id) { if (curLevel[n] === node) { isPresent = true; @@ -384,7 +384,7 @@ class LayoutEngine { return; } // get the type of static smooth curve in case it is required - let type = this.direction.curveType(); + const type = this.direction.curveType(); // force all edges into static smooth curves. this.body.emitter.emit('_forceDisableDynamicCurves', type, false); @@ -399,8 +399,8 @@ class LayoutEngine { */ setOptions(options, allOptions) { if (options !== undefined) { - let hierarchical = this.options.hierarchical; - let prevHierarchicalState = hierarchical.enabled; + const hierarchical = this.options.hierarchical; + const prevHierarchicalState = hierarchical.enabled; selectiveDeepExtend(["randomSeed", "improvedLayout", "clusterThreshold"],this.options, options); mergeOptions(this.options, options, 'hierarchical'); @@ -461,7 +461,7 @@ class LayoutEngine { */ adaptAllOptionsForHierarchicalLayout(allOptions) { if (this.options.hierarchical.enabled === true) { - let backupPhysics = this.optionsBackup.physics; + const backupPhysics = this.optionsBackup.physics; // set the physics if (allOptions.physics === undefined || allOptions.physics === true) { @@ -501,7 +501,7 @@ class LayoutEngine { allOptions.edges.smooth = {enabled: allOptions.edges.smooth, type:type} } else { - let smooth = allOptions.edges.smooth; + const smooth = allOptions.edges.smooth; // allow custom types except for dynamic if (smooth.type !== undefined && smooth.type !== 'dynamic') { @@ -544,10 +544,10 @@ class LayoutEngine { positionInitially(nodesArray) { if (this.options.hierarchical.enabled !== true) { this._resetRNG(this.initialRandomSeed); - let radius = nodesArray.length + 50; + const radius = nodesArray.length + 50; for (let i = 0; i < nodesArray.length; i++) { - let node = nodesArray[i]; - let angle = 2 * Math.PI * this._rng(); + const node = nodesArray[i]; + const angle = 2 * Math.PI * this._rng(); if (node.x === undefined) { node.x = radius * Math.cos(angle); } @@ -565,13 +565,13 @@ class LayoutEngine { */ layoutNetwork() { if (this.options.hierarchical.enabled !== true && this.options.improvedLayout === true) { - let indices = this.body.nodeIndices; + const indices = this.body.nodeIndices; // first check if we should Kamada Kawai to layout. The threshold is if less than half of the visible // nodes have predefined positions we use this. let positionDefined = 0; for (let i = 0; i < indices.length; i++) { - let node = this.body.nodes[indices[i]]; + const node = this.body.nodes[indices[i]]; if (node.predefinedPosition === true) { positionDefined += 1; } @@ -579,9 +579,9 @@ class LayoutEngine { // if less than half of the nodes have a predefined position we continue if (positionDefined < 0.5 * indices.length) { - let MAX_LEVELS = 10; + const MAX_LEVELS = 10; let level = 0; - let clusterThreshold = this.options.clusterThreshold; + const clusterThreshold = this.options.clusterThreshold; // // Define the options for the hidden cluster nodes @@ -595,7 +595,7 @@ class LayoutEngine { // // All settings here are performance related, except when noted otherwise. // - let clusterOptions = { + const clusterOptions = { clusterNodeProperties:{ shape: 'ellipse', // Bugfix: avoid type 'image', no images supplied label: '', // avoid label handling @@ -616,11 +616,11 @@ class LayoutEngine { // be easily clusterable. // TODO: examine why this is so if (indices.length > clusterThreshold) { - let startLength = indices.length; + const startLength = indices.length; while (indices.length > clusterThreshold && level <= MAX_LEVELS) { //console.time("clustering") level += 1; - let before = indices.length; + const before = indices.length; // if there are many nodes we do a hubsize cluster if (level % 3 === 0) { this.body.modules.clustering.clusterBridges(clusterOptions); @@ -628,7 +628,7 @@ class LayoutEngine { else { this.body.modules.clustering.clusterOutliers(clusterOptions); } - let after = indices.length; + const after = indices.length; if (before == after && level % 3 !== 0) { this._declusterAll(); this.body.emitter.emit("_layoutFailed"); @@ -654,10 +654,10 @@ class LayoutEngine { this._shiftToCenter(); // perturb the nodes a little bit to force the physics to kick in - let offset = 70; + const offset = 70; for (let i = 0; i < indices.length; i++) { // Only perturb the nodes that aren't fixed - let node = this.body.nodes[indices[i]]; + const node = this.body.nodes[indices[i]]; if (node.predefinedPosition === false) { node.x += (0.5 - this._rng())*offset; node.y += (0.5 - this._rng())*offset; @@ -678,10 +678,10 @@ class LayoutEngine { * @private */ _shiftToCenter() { - let range = NetworkUtil.getRangeCore(this.body.nodes, this.body.nodeIndices); - let center = NetworkUtil.findCenter(range); + const range = NetworkUtil.getRangeCore(this.body.nodes, this.body.nodeIndices); + const center = NetworkUtil.findCenter(range); for (let i = 0; i < this.body.nodeIndices.length; i++) { - let node = this.body.nodes[this.body.nodeIndices[i]]; + const node = this.body.nodes[this.body.nodeIndices[i]]; node.x -= center.x; node.y -= center.y; } @@ -731,7 +731,7 @@ class LayoutEngine { this.hierarchical = new HierarchicalStatus(); for (nodeId in this.body.nodes) { - if (this.body.nodes.hasOwnProperty(nodeId)) { + if (Object.prototype.hasOwnProperty.call(this.body.nodes, nodeId)) { node = this.body.nodes[nodeId]; if (node.options.level !== undefined) { definedLevel = true; @@ -751,7 +751,7 @@ class LayoutEngine { else { // define levels if undefined by the users. Based on hubsize. if (undefinedLevel === true) { - let sortMethod = this.options.hierarchical.sortMethod; + const sortMethod = this.options.hierarchical.sortMethod; if (sortMethod === 'hubsize') { this._determineLevelsByHubsize(); } @@ -765,13 +765,13 @@ class LayoutEngine { // fallback for cases where there are nodes but no edges - for (let nodeId in this.body.nodes) { - if (this.body.nodes.hasOwnProperty(nodeId)) { + for (const nodeId in this.body.nodes) { + if (Object.prototype.hasOwnProperty.call(this.body.nodes, nodeId)) { this.hierarchical.ensureLevel(nodeId); } } // check the distribution of the nodes per level. - let distribution = this._getDistribution(); + const distribution = this._getDistribution(); // get the parent children relations. this._generateMap(); @@ -794,25 +794,25 @@ class LayoutEngine { _condenseHierarchy() { // Global var in this scope to define when the movement has stopped. let stillShifting = false; - let branches = {}; + const branches = {}; // first we have some methods to help shifting trees around. // the main method to shift the trees - let shiftTrees = () => { - let treeSizes = getTreeSizes(); + const shiftTrees = () => { + const treeSizes = getTreeSizes(); let shiftBy = 0; for (let i = 0; i < treeSizes.length - 1; i++) { - let diff = treeSizes[i].max - treeSizes[i+1].min; + const diff = treeSizes[i].max - treeSizes[i+1].min; shiftBy += diff + this.options.hierarchical.treeSpacing; shiftTree(i + 1, shiftBy); } }; // shift a single tree by an offset - let shiftTree = (index, offset) => { - let trees = this.hierarchical.trees; + const shiftTree = (index, offset) => { + const trees = this.hierarchical.trees; - for (let nodeId in trees) { - if (trees.hasOwnProperty(nodeId)) { + for (const nodeId in trees) { + if (Object.prototype.hasOwnProperty.call(trees, nodeId)) { if (trees[nodeId] === index) { this.direction.shift(nodeId, offset); } @@ -821,8 +821,8 @@ class LayoutEngine { }; // get the width of all trees - let getTreeSizes = () => { - let treeWidths = []; + const getTreeSizes = () => { + const treeWidths = []; for (let i = 0; i < this.hierarchical.numTrees(); i++) { treeWidths.push(this.direction.getTreeSize(i)); } @@ -831,13 +831,13 @@ class LayoutEngine { // get a map of all nodes in this branch - let getBranchNodes = (source, map) => { + const getBranchNodes = (source, map) => { if (map[source.id]) { return; } map[source.id] = true; if (this.hierarchical.childrenReference[source.id]) { - let children = this.hierarchical.childrenReference[source.id]; + const children = this.hierarchical.childrenReference[source.id]; if (children.length > 0) { for (let i = 0; i < children.length; i++) { getBranchNodes(this.body.nodes[children[i]], map); @@ -848,19 +848,19 @@ class LayoutEngine { // get a min max width as well as the maximum movement space it has on either sides // we use min max terminology because width and height can interchange depending on the direction of the layout - let getBranchBoundary = (branchMap, maxLevel = 1e9) => { + const getBranchBoundary = (branchMap, maxLevel = 1e9) => { let minSpace = 1e9; let maxSpace = 1e9; let min = 1e9; let max = -1e9; - for (let branchNode in branchMap) { - if (branchMap.hasOwnProperty(branchNode)) { - let node = this.body.nodes[branchNode]; - let level = this.hierarchical.levels[node.id]; - let position = this.direction.getPosition(node); + for (const branchNode in branchMap) { + if (Object.prototype.hasOwnProperty.call(branchMap, branchNode)) { + const node = this.body.nodes[branchNode]; + const level = this.hierarchical.levels[node.id]; + const position = this.direction.getPosition(node); // get the space around the node. - let [minSpaceNode, maxSpaceNode] = this._getSpaceAroundNode(node,branchMap); + const [minSpaceNode, maxSpaceNode] = this._getSpaceAroundNode(node,branchMap); minSpace = Math.min(minSpaceNode, minSpace); maxSpace = Math.min(maxSpaceNode, maxSpace); @@ -877,9 +877,9 @@ class LayoutEngine { // check what the maximum level is these nodes have in common. - let getCollisionLevel = (node1, node2) => { - let maxLevel1 = this.hierarchical.getMaxLevel(node1.id); - let maxLevel2 = this.hierarchical.getMaxLevel(node2.id); + const getCollisionLevel = (node1, node2) => { + const maxLevel1 = this.hierarchical.getMaxLevel(node1.id); + const maxLevel2 = this.hierarchical.getMaxLevel(node2.id); return Math.min(maxLevel1, maxLevel2); }; @@ -891,16 +891,16 @@ class LayoutEngine { * @param {Array.} levels * @param {*} centerParents */ - let shiftElementsCloser = (callback, levels, centerParents) => { - let hier = this.hierarchical; + const shiftElementsCloser = (callback, levels, centerParents) => { + const hier = this.hierarchical; for (let i = 0; i < levels.length; i++) { - let level = levels[i]; - let levelNodes = hier.distributionOrdering[level]; + const level = levels[i]; + const levelNodes = hier.distributionOrdering[level]; if (levelNodes.length > 1) { for (let j = 0; j < levelNodes.length - 1; j++) { - let node1 = levelNodes[j]; - let node2 = levelNodes[j+1]; + const node1 = levelNodes[j]; + const node2 = levelNodes[j+1]; // NOTE: logic maintained as it was; if nodes have same ancestor, // then of course they are in the same sub-network. @@ -914,31 +914,31 @@ class LayoutEngine { // callback for shifting branches - let branchShiftCallback = (node1, node2, centerParent = false) => { + const branchShiftCallback = (node1, node2, centerParent = false) => { //window.CALLBACKS.push(() => { - let pos1 = this.direction.getPosition(node1); - let pos2 = this.direction.getPosition(node2); - let diffAbs = Math.abs(pos2 - pos1); - let nodeSpacing = this.options.hierarchical.nodeSpacing; + const pos1 = this.direction.getPosition(node1); + const pos2 = this.direction.getPosition(node2); + const diffAbs = Math.abs(pos2 - pos1); + const nodeSpacing = this.options.hierarchical.nodeSpacing; //console.log("NOW CHECKING:", node1.id, node2.id, diffAbs); if (diffAbs > nodeSpacing) { - let branchNodes1 = {}; - let branchNodes2 = {}; + const branchNodes1 = {}; + const branchNodes2 = {}; getBranchNodes(node1, branchNodes1); getBranchNodes(node2, branchNodes2); // check the largest distance between the branches - let maxLevel = getCollisionLevel(node1, node2); - let branchNodeBoundary1 = getBranchBoundary(branchNodes1, maxLevel); - let branchNodeBoundary2 = getBranchBoundary(branchNodes2, maxLevel); - let max1 = branchNodeBoundary1[1]; - let min2 = branchNodeBoundary2[0]; - let minSpace2 = branchNodeBoundary2[2]; + const maxLevel = getCollisionLevel(node1, node2); + const branchNodeBoundary1 = getBranchBoundary(branchNodes1, maxLevel); + const branchNodeBoundary2 = getBranchBoundary(branchNodes2, maxLevel); + const max1 = branchNodeBoundary1[1]; + const min2 = branchNodeBoundary2[0]; + const minSpace2 = branchNodeBoundary2[2]; //console.log(node1.id, getBranchBoundary(branchNodes1, maxLevel), node2.id, // getBranchBoundary(branchNodes2, maxLevel), maxLevel); - let diffBranch = Math.abs(max1 - min2); + const diffBranch = Math.abs(max1 - min2); if (diffBranch > nodeSpacing) { let offset = max1 - min2 + nodeSpacing; if (offset < -minSpace2 + nodeSpacing) { @@ -959,21 +959,21 @@ class LayoutEngine { //this.body.emitter.emit("_redraw");}) }; - let minimizeEdgeLength = (iterations, node) => { + const minimizeEdgeLength = (iterations, node) => { //window.CALLBACKS.push(() => { // console.log("ts",node.id); - let nodeId = node.id; - let allEdges = node.edges; - let nodeLevel = this.hierarchical.levels[node.id]; + const nodeId = node.id; + const allEdges = node.edges; + const nodeLevel = this.hierarchical.levels[node.id]; // gather constants - let C2 = this.options.hierarchical.levelSeparation * this.options.hierarchical.levelSeparation; - let referenceNodes = {}; - let aboveEdges = []; + const C2 = this.options.hierarchical.levelSeparation * this.options.hierarchical.levelSeparation; + const referenceNodes = {}; + const aboveEdges = []; for (let i = 0; i < allEdges.length; i++) { - let edge = allEdges[i]; + const edge = allEdges[i]; if (edge.toId != edge.fromId) { - let otherNode = edge.toId == nodeId ? edge.from : edge.to; + const otherNode = edge.toId == nodeId ? edge.from : edge.to; referenceNodes[allEdges[i].id] = otherNode; if (this.hierarchical.levels[otherNode.id] < nodeLevel) { aboveEdges.push(edge); @@ -982,11 +982,11 @@ class LayoutEngine { } // differentiated sum of lengths based on only moving one node over one axis - let getFx = (point, edges) => { + const getFx = (point, edges) => { let sum = 0; for (let i = 0; i < edges.length; i++) { if (referenceNodes[edges[i].id] !== undefined) { - let a = this.direction.getPosition(referenceNodes[edges[i].id]) - point; + const a = this.direction.getPosition(referenceNodes[edges[i].id]) - point; sum += a / Math.sqrt(a * a + C2); } } @@ -994,28 +994,28 @@ class LayoutEngine { }; // doubly differentiated sum of lengths based on only moving one node over one axis - let getDFx = (point, edges) => { + const getDFx = (point, edges) => { let sum = 0; for (let i = 0; i < edges.length; i++) { if (referenceNodes[edges[i].id] !== undefined) { - let a = this.direction.getPosition(referenceNodes[edges[i].id]) - point; + const a = this.direction.getPosition(referenceNodes[edges[i].id]) - point; sum -= (C2 * Math.pow(a * a + C2, -1.5)); } } return sum; }; - let getGuess = (iterations, edges) => { + const getGuess = (iterations, edges) => { let guess = this.direction.getPosition(node); // Newton's method for optimization - let guessMap = {}; + const guessMap = {}; for (let i = 0; i < iterations; i++) { - let fx = getFx(guess, edges); - let dfx = getDFx(guess, edges); + const fx = getFx(guess, edges); + const dfx = getDFx(guess, edges); // we limit the movement to avoid instability. - let limit = 40; - let ratio = Math.max(-limit, Math.min(limit, Math.round(fx/dfx))); + const limit = 40; + const ratio = Math.max(-limit, Math.min(limit, Math.round(fx/dfx))); guess = guess - ratio; // reduce duplicates if (guessMap[guess] !== undefined) { @@ -1026,21 +1026,21 @@ class LayoutEngine { return guess; }; - let moveBranch = (guess) => { + const moveBranch = (guess) => { // position node if there is space - let nodePosition = this.direction.getPosition(node); + const nodePosition = this.direction.getPosition(node); // check movable area of the branch if (branches[node.id] === undefined) { - let branchNodes = {}; + const branchNodes = {}; getBranchNodes(node, branchNodes); branches[node.id] = branchNodes; } - let branchBoundary = getBranchBoundary(branches[node.id]); - let minSpaceBranch = branchBoundary[2]; - let maxSpaceBranch = branchBoundary[3]; + const branchBoundary = getBranchBoundary(branches[node.id]); + const minSpaceBranch = branchBoundary[2]; + const maxSpaceBranch = branchBoundary[3]; - let diff = guess - nodePosition; + const diff = guess - nodePosition; // check if we are allowed to move the node: let branchOffset = 0; @@ -1059,12 +1059,12 @@ class LayoutEngine { } }; - let moveNode = (guess) => { - let nodePosition = this.direction.getPosition(node); + const moveNode = (guess) => { + const nodePosition = this.direction.getPosition(node); // position node if there is space - let [minSpace, maxSpace] = this._getSpaceAroundNode(node); - let diff = guess - nodePosition; + const [minSpace, maxSpace] = this._getSpaceAroundNode(node); + const diff = guess - nodePosition; // check if we are allowed to move the node: let newPosition = nodePosition; if (diff > 0) { @@ -1090,14 +1090,14 @@ class LayoutEngine { }; // method to remove whitespace between branches. Because we do bottom up, we can center the parents. - let minimizeEdgeLengthBottomUp = (iterations) => { + const minimizeEdgeLengthBottomUp = (iterations) => { let levels = this.hierarchical.getLevels(); levels = levels.reverse(); for (let i = 0; i < iterations; i++) { stillShifting = false; for (let j = 0; j < levels.length; j++) { - let level = levels[j]; - let levelNodes = this.hierarchical.distributionOrdering[level]; + const level = levels[j]; + const levelNodes = this.hierarchical.distributionOrdering[level]; for (let k = 0; k < levelNodes.length; k++) { minimizeEdgeLength(1000, levelNodes[k]); } @@ -1110,7 +1110,7 @@ class LayoutEngine { }; // method to remove whitespace between branches. Because we do bottom up, we can center the parents. - let shiftBranchesCloserBottomUp = (iterations) => { + const shiftBranchesCloserBottomUp = (iterations) => { let levels = this.hierarchical.getLevels(); levels = levels.reverse(); for (let i = 0; i < iterations; i++) { @@ -1124,20 +1124,20 @@ class LayoutEngine { }; // center all parents - let centerAllParents = () => { - for (let nodeId in this.body.nodes) { - if (this.body.nodes.hasOwnProperty(nodeId)) + const centerAllParents = () => { + for (const nodeId in this.body.nodes) { + if (Object.prototype.hasOwnProperty.call(this.body.nodes, nodeId)) this._centerParent(this.body.nodes[nodeId]); } }; // center all parents - let centerAllParentsBottomUp = () => { + const centerAllParentsBottomUp = () => { let levels = this.hierarchical.getLevels(); levels = levels.reverse(); for (let i = 0; i < levels.length; i++) { - let level = levels[i]; - let levelNodes = this.hierarchical.distributionOrdering[level]; + const level = levels[i]; + const levelNodes = this.hierarchical.distributionOrdering[level]; for (let j = 0; j < levelNodes.length; j++) { this._centerParent(levelNodes[j]); } @@ -1175,25 +1175,25 @@ class LayoutEngine { if (map === undefined) { useMap = false; } - let level = this.hierarchical.levels[node.id]; + const level = this.hierarchical.levels[node.id]; if (level !== undefined) { - let index = this.hierarchical.distributionIndex[node.id]; - let position = this.direction.getPosition(node); - let ordering = this.hierarchical.distributionOrdering[level]; + const index = this.hierarchical.distributionIndex[node.id]; + const position = this.direction.getPosition(node); + const ordering = this.hierarchical.distributionOrdering[level]; let minSpace = 1e9; let maxSpace = 1e9; if (index !== 0) { - let prevNode = ordering[index - 1]; + const prevNode = ordering[index - 1]; if ((useMap === true && map[prevNode.id] === undefined) || useMap === false) { - let prevPos = this.direction.getPosition(prevNode); + const prevPos = this.direction.getPosition(prevNode); minSpace = position - prevPos; } } if (index != ordering.length - 1) { - let nextNode = ordering[index + 1]; + const nextNode = ordering[index + 1]; if ((useMap === true && map[nextNode.id] === undefined) || useMap === false) { - let nextPos = this.direction.getPosition(nextNode); + const nextPos = this.direction.getPosition(nextNode); maxSpace = Math.min(maxSpace, nextPos - position); } } @@ -1213,19 +1213,19 @@ class LayoutEngine { */ _centerParent(node) { if (this.hierarchical.parentReference[node.id]) { - let parents = this.hierarchical.parentReference[node.id]; - for (var i = 0; i < parents.length; i++) { - let parentId = parents[i]; - let parentNode = this.body.nodes[parentId]; - let children = this.hierarchical.childrenReference[parentId]; + const parents = this.hierarchical.parentReference[node.id]; + for (let i = 0; i < parents.length; i++) { + const parentId = parents[i]; + const parentNode = this.body.nodes[parentId]; + const children = this.hierarchical.childrenReference[parentId]; if (children !== undefined) { // get the range of the children - let newPosition = this._getCenterPosition(children); + const newPosition = this._getCenterPosition(children); - let position = this.direction.getPosition(parentNode); - let [minSpace, maxSpace] = this._getSpaceAroundNode(parentNode); - let diff = position - newPosition; + const position = this.direction.getPosition(parentNode); + const [minSpace, maxSpace] = this._getSpaceAroundNode(parentNode); + const diff = position - newPosition; if ((diff < 0 && Math.abs(diff) < maxSpace - this.options.hierarchical.nodeSpacing) || (diff > 0 && Math.abs(diff) < minSpace - this.options.hierarchical.nodeSpacing)) { this.direction.setPosition(parentNode, newPosition); @@ -1245,8 +1245,8 @@ class LayoutEngine { _placeNodesByHierarchy(distribution) { this.positionedNodes = {}; // start placing all the level 0 nodes first. Then recursively position their branches. - for (let level in distribution) { - if (distribution.hasOwnProperty(level)) { + for (const level in distribution) { + if (Object.prototype.hasOwnProperty.call(distribution, level)) { // sort nodes in level by position: let nodeArray = Object.keys(distribution[level]); nodeArray = this._indexArrayToNodes(nodeArray); @@ -1254,9 +1254,9 @@ class LayoutEngine { let handledNodeCount = 0; for (let i = 0; i < nodeArray.length; i++) { - let node = nodeArray[i]; + const node = nodeArray[i]; if (this.positionedNodes[node.id] === undefined) { - let spacing = this.options.hierarchical.nodeSpacing; + const spacing = this.options.hierarchical.nodeSpacing; let pos = spacing * handledNodeCount; // We get the X or Y values we need and store them in pos and previousPos. // The get and set make sure we get X or Y @@ -1283,7 +1283,7 @@ class LayoutEngine { * @private */ _placeBranchNodes(parentId, parentLevel) { - let childRef = this.hierarchical.childrenReference[parentId]; + const childRef = this.hierarchical.childrenReference[parentId]; // if this is not a parent, cancel the placing. This can happen with multiple parents to one child. if (childRef === undefined) { @@ -1291,7 +1291,7 @@ class LayoutEngine { } // get a list of childNodes - let childNodes = []; + const childNodes = []; for (let i = 0; i < childRef.length; i++) { childNodes.push(this.body.nodes[childRef[i]]); } @@ -1301,12 +1301,12 @@ class LayoutEngine { // position the childNodes for (let i = 0; i < childNodes.length; i++) { - let childNode = childNodes[i]; - let childNodeLevel = this.hierarchical.levels[childNode.id]; + const childNode = childNodes[i]; + const childNodeLevel = this.hierarchical.levels[childNode.id]; // check if the child node is below the parent node and if it has already been positioned. if (childNodeLevel > parentLevel && this.positionedNodes[childNode.id] === undefined) { // get the amount of space required for this node. If parent the width is based on the amount of children. - let spacing = this.options.hierarchical.nodeSpacing; + const spacing = this.options.hierarchical.nodeSpacing; let pos; // we get the X or Y values we need and store them in pos and previousPos. @@ -1325,7 +1325,7 @@ class LayoutEngine { } // center the parent nodes. - let center = this._getCenterPosition(childNodes); + const center = this._getCenterPosition(childNodes); this.direction.setPosition(this.body.nodes[parentId], center, parentLevel); } @@ -1345,10 +1345,10 @@ class LayoutEngine { // if overlap has been detected, we shift the branch if (this.lastNodeOnLevel[level] !== undefined) { - let previousPos = this.direction.getPosition(this.body.nodes[this.lastNodeOnLevel[level]]); + const previousPos = this.direction.getPosition(this.body.nodes[this.lastNodeOnLevel[level]]); if (pos - previousPos < this.options.hierarchical.nodeSpacing) { - let diff = (previousPos + this.options.hierarchical.nodeSpacing) - pos; - let sharedParent = this._findCommonParent(this.lastNodeOnLevel[level], node.id); + const diff = (previousPos + this.options.hierarchical.nodeSpacing) - pos; + const sharedParent = this._findCommonParent(this.lastNodeOnLevel[level], node.id); this._shiftBlock(sharedParent.withChild, diff); } } @@ -1365,7 +1365,7 @@ class LayoutEngine { * @returns {Array.} */ _indexArrayToNodes(idArray) { - let array = []; + const array = []; for (let i = 0; i < idArray.length; i++) { array.push(this.body.nodes[idArray[i]]) } @@ -1379,16 +1379,16 @@ class LayoutEngine { * @private */ _getDistribution() { - let distribution = {}; + const distribution = {}; let nodeId, node; // we fix Y because the hierarchy is vertical, // we fix X so we do not give a node an x position for a second time. // the fix of X is removed after the x value has been set. for (nodeId in this.body.nodes) { - if (this.body.nodes.hasOwnProperty(nodeId)) { + if (Object.prototype.hasOwnProperty.call(this.body.nodes, nodeId)) { node = this.body.nodes[nodeId]; - let level = this.hierarchical.levels[nodeId] === undefined ? 0 : this.hierarchical.levels[nodeId]; + const level = this.hierarchical.levels[nodeId] === undefined ? 0 : this.hierarchical.levels[nodeId]; this.direction.fix(node, level); if (distribution[level] === undefined) { distribution[level] = {}; @@ -1408,7 +1408,7 @@ class LayoutEngine { * @private */ _getActiveEdges(node) { - let result = []; + const result = []; forEach(node.edges, (edge) => { if (this.body.edgeIndices.indexOf(edge.id) !== -1) { @@ -1427,17 +1427,17 @@ class LayoutEngine { * @private */ _getHubSizes() { - let hubSizes = {}; - let nodeIds = this.body.nodeIndices; + const hubSizes = {}; + const nodeIds = this.body.nodeIndices; forEach(nodeIds, (nodeId) => { - let node = this.body.nodes[nodeId]; - let hubSize = this._getActiveEdges(node).length; + const node = this.body.nodes[nodeId]; + const hubSize = this._getActiveEdges(node).length; hubSizes[hubSize] = true; }); // Make an array of the size sorted descending - let result = []; + const result = []; forEach(hubSizes, (size) => { result.push(Number(size)); }); @@ -1456,18 +1456,18 @@ class LayoutEngine { * @private */ _determineLevelsByHubsize() { - let levelDownstream = (nodeA, nodeB) => { + const levelDownstream = (nodeA, nodeB) => { this.hierarchical.levelDownstream(nodeA, nodeB); } - let hubSizes = this._getHubSizes(); + const hubSizes = this._getHubSizes(); for (let i = 0; i < hubSizes.length; ++i ) { - let hubSize = hubSizes[i]; + const hubSize = hubSizes[i]; if (hubSize === 0) break; forEach(this.body.nodeIndices, (nodeId) => { - let node = this.body.nodes[nodeId]; + const node = this.body.nodes[nodeId]; if (hubSize === this._getActiveEdges(node).length) { this._crawlNetwork(levelDownstream, nodeId); @@ -1484,21 +1484,21 @@ class LayoutEngine { * @private */ _determineLevelsCustomCallback() { - let minLevel = 100000; + const minLevel = 100000; // TODO: this should come from options. - let customCallback = function(nodeA, nodeB, edge) { // eslint-disable-line no-unused-vars + const customCallback = function(nodeA, nodeB, edge) { // eslint-disable-line no-unused-vars }; // TODO: perhaps move to HierarchicalStatus. // But I currently don't see the point, this method is not used. - let levelByDirection = (nodeA, nodeB, edge) => { + const levelByDirection = (nodeA, nodeB, edge) => { let levelA = this.hierarchical.levels[nodeA.id]; // set initial level if (levelA === undefined) { levelA = this.hierarchical.levels[nodeA.id] = minLevel;} - let diff = customCallback( + const diff = customCallback( NetworkUtil.cloneOptions(nodeA,'node'), NetworkUtil.cloneOptions(nodeB,'node'), NetworkUtil.cloneOptions(edge,'edge') @@ -1538,7 +1538,7 @@ class LayoutEngine { * @private */ _generateMap() { - let fillInRelations = (parentNode, childNode) => { + const fillInRelations = (parentNode, childNode) => { if (this.hierarchical.levels[childNode.id] > this.hierarchical.levels[parentNode.id]) { this.hierarchical.addRelation(parentNode.id, childNode.id); } @@ -1556,17 +1556,17 @@ class LayoutEngine { * @private */ _crawlNetwork(callback = function() {}, startingNodeId) { - let progress = {}; + const progress = {}; - let crawler = (node, tree) => { + const crawler = (node, tree) => { if (progress[node.id] === undefined) { this.hierarchical.setTreeIndex(node, tree); progress[node.id] = true; let childNode; - let edges = this._getActiveEdges(node); + const edges = this._getActiveEdges(node); for (let i = 0; i < edges.length; i++) { - let edge = edges[i]; + const edge = edges[i]; if (edge.connected === true) { if (edge.toId == node.id) { // Not '===' because id's can be string and numeric childNode = edge.from; @@ -1590,10 +1590,10 @@ class LayoutEngine { let treeIndex = 0; // Serves to pass a unique id for the current distinct tree for (let i = 0; i < this.body.nodeIndices.length; i++) { - let nodeId = this.body.nodeIndices[i]; + const nodeId = this.body.nodeIndices[i]; if (progress[nodeId] === undefined) { - let node = this.body.nodes[nodeId]; + const node = this.body.nodes[nodeId]; crawler(node, treeIndex); treeIndex += 1; } @@ -1601,7 +1601,7 @@ class LayoutEngine { } else { // Crawl from the given starting node - let node = this.body.nodes[startingNodeId]; + const node = this.body.nodes[startingNodeId]; if (node === undefined) { console.error("Node not found:", startingNodeId); return; @@ -1618,15 +1618,15 @@ class LayoutEngine { * @private */ _shiftBlock(parentId, diff) { - let progress = {}; - let shifter = (parentId) => { + const progress = {}; + const shifter = (parentId) => { if (progress[parentId]) { return; } progress[parentId] = true; this.direction.shift(parentId, diff); - let childRef = this.hierarchical.childrenReference[parentId]; + const childRef = this.hierarchical.childrenReference[parentId]; if (childRef !== undefined) { for (let i = 0; i < childRef.length; i++) { shifter(childRef[i]); @@ -1645,26 +1645,26 @@ class LayoutEngine { * @private */ _findCommonParent(childA,childB) { - let parents = {}; - let iterateParents = (parents,child) => { - let parentRef = this.hierarchical.parentReference[child]; + const parents = {}; + const iterateParents = (parents,child) => { + const parentRef = this.hierarchical.parentReference[child]; if (parentRef !== undefined) { for (let i = 0; i < parentRef.length; i++) { - let parent = parentRef[i]; + const parent = parentRef[i]; parents[parent] = true; iterateParents(parents, parent) } } }; - let findParent = (parents, child) => { - let parentRef = this.hierarchical.parentReference[child]; + const findParent = (parents, child) => { + const parentRef = this.hierarchical.parentReference[child]; if (parentRef !== undefined) { for (let i = 0; i < parentRef.length; i++) { - let parent = parentRef[i]; + const parent = parentRef[i]; if (parents[parent] !== undefined) { return {foundParent:parent, withChild:child}; } - let branch = findParent(parents, parent); + const branch = findParent(parents, parent); if (branch.foundParent !== null) { return branch; } @@ -1690,7 +1690,7 @@ class LayoutEngine { * @private */ setDirectionStrategy() { - var isVertical = (this.options.hierarchical.direction === 'UD' + const isVertical = (this.options.hierarchical.direction === 'UD' || this.options.hierarchical.direction === 'DU'); if(isVertical) { @@ -1718,11 +1718,11 @@ class LayoutEngine { if (childNodes[i].id !== undefined) { childNode = childNodes[i]; } else { - let childNodeId = childNodes[i]; + const childNodeId = childNodes[i]; childNode = this.body.nodes[childNodeId]; } - let position = this.direction.getPosition(childNode); + const position = this.direction.getPosition(childNode); minPos = Math.min(minPos, position); maxPos = Math.max(maxPos, position); } diff --git a/lib/network/modules/ManipulationSystem.js b/lib/network/modules/ManipulationSystem.js index 316ae409ce..37c5583d90 100644 --- a/lib/network/modules/ManipulationSystem.js +++ b/lib/network/modules/ManipulationSystem.js @@ -15,6 +15,7 @@ class ManipulationSystem { * @param {Object} body * @param {Canvas} canvas * @param {SelectionHandler} selectionHandler + * @param {InteractionHandler} interactionHandler */ constructor(body, canvas, selectionHandler, interactionHandler) { this.body = body; @@ -171,10 +172,10 @@ class ManipulationSystem { this.manipulationDiv.style.display = 'block'; this.closeDiv.style.display = 'block'; - let selectedNodeCount = this.selectionHandler._getSelectedNodeCount(); - let selectedEdgeCount = this.selectionHandler._getSelectedEdgeCount(); - let selectedTotalCount = selectedNodeCount + selectedEdgeCount; - let locale = this.options.locales[this.options.locale]; + const selectedNodeCount = this.selectionHandler._getSelectedNodeCount(); + const selectedEdgeCount = this.selectionHandler._getSelectedEdgeCount(); + const selectedTotalCount = selectedNodeCount + selectedEdgeCount; + const locale = this.options.locales[this.options.locale]; let needSeperator = false; @@ -251,7 +252,7 @@ class ManipulationSystem { this.inMode = 'addNode'; if (this.guiEnabled === true) { - let locale = this.options.locales[this.options.locale]; + const locale = this.options.locales[this.options.locale]; this.manipulationDOM = {}; this._createBackButton(locale); this._createSeperator(); @@ -275,12 +276,12 @@ class ManipulationSystem { // restore the state of any bound functions or events, remove control nodes, restore physics this._clean(); - let node = this.selectionHandler._getSelectedNode(); + const node = this.selectionHandler._getSelectedNode(); if (node !== undefined) { this.inMode = 'editNode'; if (typeof this.options.editNode === 'function') { if (node.isCluster !== true) { - let data = deepExtend({}, node.options, false); + const data = deepExtend({}, node.options, false); data.x = node.x; data.y = node.y; @@ -324,7 +325,7 @@ class ManipulationSystem { this.inMode = 'addEdge'; if (this.guiEnabled === true) { - let locale = this.options.locales[this.options.locale]; + const locale = this.options.locales[this.options.locale]; this.manipulationDOM = {}; this._createBackButton(locale); this._createSeperator(); @@ -359,13 +360,13 @@ class ManipulationSystem { if (typeof this.options.editEdge === 'object' && typeof this.options.editEdge.editWithoutDrag === "function") { this.edgeBeingEditedId = this.selectionHandler.getSelectedEdges()[0]; if (this.edgeBeingEditedId !== undefined) { - var edge = this.body.edges[this.edgeBeingEditedId]; + const edge = this.body.edges[this.edgeBeingEditedId]; this._performEditEdge(edge.from.id, edge.to.id); return; } } if (this.guiEnabled === true) { - let locale = this.options.locales[this.options.locale]; + const locale = this.options.locales[this.options.locale]; this.manipulationDOM = {}; this._createBackButton(locale); this._createSeperator(); @@ -377,11 +378,11 @@ class ManipulationSystem { this.edgeBeingEditedId = this.selectionHandler.getSelectedEdges()[0]; if (this.edgeBeingEditedId !== undefined) { - let edge = this.body.edges[this.edgeBeingEditedId]; + const edge = this.body.edges[this.edgeBeingEditedId]; // create control nodes - let controlNodeFrom = this._getNewTargetNode(edge.from.x, edge.from.y); - let controlNodeTo = this._getNewTargetNode(edge.to.x, edge.to.y); + const controlNodeFrom = this._getNewTargetNode(edge.from.x, edge.from.y); + const controlNodeTo = this._getNewTargetNode(edge.to.x, edge.to.y); this.temporaryIds.nodes.push(controlNodeFrom.id); this.temporaryIds.nodes.push(controlNodeTo.id); @@ -403,7 +404,7 @@ class ManipulationSystem { // create function to position control nodes correctly on movement // automatically cleaned up because we use the temporary bind this._temporaryBindEvent('beforeDrawing', (ctx) => { - let positions = edge.edgeType.findBorderPositions(ctx); + const positions = edge.edgeType.findBorderPositions(ctx); if (controlNodeFrom.selected === false) { controlNodeFrom.x = positions.from.x; controlNodeFrom.y = positions.from.y; @@ -434,8 +435,8 @@ class ManipulationSystem { this._clean(); this.inMode = 'delete'; - let selectedNodes = this.selectionHandler.getSelectedNodes(); - let selectedEdges = this.selectionHandler.getSelectedEdges(); + const selectedNodes = this.selectionHandler.getSelectedNodes(); + const selectedEdges = this.selectionHandler.getSelectedEdges(); let deleteFunction = undefined; if (selectedNodes.length > 0) { for (let i = 0; i < selectedNodes.length; i++) { @@ -456,7 +457,7 @@ class ManipulationSystem { } if (typeof deleteFunction === 'function') { - let data = {nodes: selectedNodes, edges: selectedEdges}; + const data = {nodes: selectedNodes, edges: selectedEdges}; if (deleteFunction.length === 2) { deleteFunction(data, (finalizedData) => { if (finalizedData !== null && finalizedData !== undefined && this.inMode === 'delete') { // if for whatever reason the mode has changes (due to dataset change) disregard the callback) { @@ -565,7 +566,7 @@ class ManipulationSystem { * @private */ _getNewTargetNode(x,y) { - let controlNodeStyle = deepExtend({}, this.options.controlNodeStyle); + const controlNodeStyle = deepExtend({}, this.options.controlNodeStyle); controlNodeStyle.id = 'targetNode' + randomUUID(); controlNodeStyle.hidden = false; @@ -574,7 +575,7 @@ class ManipulationSystem { controlNodeStyle.y = y; // we have to define the bounding box in order for the nodes to be drawn immediately - let node = this.body.functions.createNode(controlNodeStyle); + const node = this.body.functions.createNode(controlNodeStyle); node.shape.boundingBox = {left: x, right:x, top:y, bottom:y}; return node; @@ -596,8 +597,8 @@ class ManipulationSystem { // create the contents for the editMode button - let locale = this.options.locales[this.options.locale]; - let button = this._createButton('editMode', 'vis-button vis-edit vis-edit-mode', locale['edit'] || this.options.locales['en']['edit']); + const locale = this.options.locales[this.options.locale]; + const button = this._createButton('editMode', 'vis-button vis-edit vis-edit-mode', locale['edit'] || this.options.locales['en']['edit']); this.editModeDiv.appendChild(button); // bind a hammer listener to the button, calling the function toggleEditMode. @@ -695,7 +696,7 @@ class ManipulationSystem { * @private */ _createAddNodeButton(locale) { - let button = this._createButton('addNode', 'vis-button vis-add', locale['addNode'] || this.options.locales['en']['addNode']); + const button = this._createButton('addNode', 'vis-button vis-add', locale['addNode'] || this.options.locales['en']['addNode']); this.manipulationDiv.appendChild(button); this._bindHammerToDiv(button, this.addNodeMode.bind(this)); } @@ -706,7 +707,7 @@ class ManipulationSystem { * @private */ _createAddEdgeButton(locale) { - let button = this._createButton('addEdge', 'vis-button vis-connect', locale['addEdge'] || this.options.locales['en']['addEdge']); + const button = this._createButton('addEdge', 'vis-button vis-connect', locale['addEdge'] || this.options.locales['en']['addEdge']); this.manipulationDiv.appendChild(button); this._bindHammerToDiv(button, this.addEdgeMode.bind(this)); } @@ -717,7 +718,7 @@ class ManipulationSystem { * @private */ _createEditNodeButton(locale) { - let button = this._createButton('editNode', 'vis-button vis-edit', locale['editNode'] || this.options.locales['en']['editNode']); + const button = this._createButton('editNode', 'vis-button vis-edit', locale['editNode'] || this.options.locales['en']['editNode']); this.manipulationDiv.appendChild(button); this._bindHammerToDiv(button, this.editNode.bind(this)); } @@ -728,7 +729,7 @@ class ManipulationSystem { * @private */ _createEditEdgeButton(locale) { - let button = this._createButton('editEdge', 'vis-button vis-edit', locale['editEdge'] || this.options.locales['en']['editEdge']); + const button = this._createButton('editEdge', 'vis-button vis-edit', locale['editEdge'] || this.options.locales['en']['editEdge']); this.manipulationDiv.appendChild(button); this._bindHammerToDiv(button, this.editEdgeMode.bind(this)); } @@ -739,13 +740,13 @@ class ManipulationSystem { * @private */ _createDeleteButton(locale) { - var deleteBtnClass; + let deleteBtnClass; if (this.options.rtl) { deleteBtnClass = 'vis-button vis-delete-rtl'; } else { deleteBtnClass = 'vis-button vis-delete'; } - let button = this._createButton('delete', deleteBtnClass, locale['del'] || this.options.locales['en']['del']); + const button = this._createButton('delete', deleteBtnClass, locale['del'] || this.options.locales['en']['del']); this.manipulationDiv.appendChild(button); this._bindHammerToDiv(button, this.deleteSelected.bind(this)); } @@ -756,7 +757,7 @@ class ManipulationSystem { * @private */ _createBackButton(locale) { - let button = this._createButton('back', 'vis-button vis-back', locale['back'] || this.options.locales['en']['back']); + const button = this._createButton('back', 'vis-button vis-back', locale['back'] || this.options.locales['en']['back']); this.manipulationDiv.appendChild(button); this._bindHammerToDiv(button, this.showManipulatorToolbar.bind(this)); } @@ -827,8 +828,8 @@ class ManipulationSystem { * @private */ _unbindTemporaryUIs() { - for (let functionName in this.temporaryUIFunctions) { - if (this.temporaryUIFunctions.hasOwnProperty(functionName)) { + for (const functionName in this.temporaryUIFunctions) { + if (Object.prototype.hasOwnProperty.call(this.temporaryUIFunctions, functionName)) { this.body.eventListeners[functionName] = this.temporaryUIFunctions[functionName]; delete this.temporaryUIFunctions[functionName]; } @@ -842,8 +843,8 @@ class ManipulationSystem { */ _unbindTemporaryEvents() { for (let i = 0; i < this.temporaryEventFunctions.length; i++) { - let eventName = this.temporaryEventFunctions[i].event; - let boundFunction = this.temporaryEventFunctions[i].boundFunction; + const eventName = this.temporaryEventFunctions[i].event; + const boundFunction = this.temporaryEventFunctions[i].boundFunction; this.body.emitter.off(eventName, boundFunction); } this.temporaryEventFunctions = []; @@ -856,7 +857,7 @@ class ManipulationSystem { * @param {function} boundFunction */ _bindHammerToDiv(domElement, boundFunction) { - let hammer = new Hammer(domElement, {}); + const hammer = new Hammer(domElement, {}); onTouch(hammer, boundFunction); this.manipulationHammers.push(hammer); } @@ -871,14 +872,14 @@ class ManipulationSystem { for (let i = 0; i < this.temporaryIds.edges.length; i++) { this.body.edges[this.temporaryIds.edges[i]].disconnect(); delete this.body.edges[this.temporaryIds.edges[i]]; - let indexTempEdge = this.body.edgeIndices.indexOf(this.temporaryIds.edges[i]); + const indexTempEdge = this.body.edgeIndices.indexOf(this.temporaryIds.edges[i]); if (indexTempEdge !== -1) {this.body.edgeIndices.splice(indexTempEdge,1);} } // _clean temporary nodes for (let i = 0; i < this.temporaryIds.nodes.length; i++) { delete this.body.nodes[this.temporaryIds.nodes[i]]; - let indexTempNode = this.body.nodeIndices.indexOf(this.temporaryIds.nodes[i]); + const indexTempNode = this.body.nodeIndices.indexOf(this.temporaryIds.nodes[i]); if (indexTempNode !== -1) {this.body.nodeIndices.splice(indexTempNode,1);} } @@ -905,15 +906,15 @@ class ManipulationSystem { * @private */ _controlNodeDragStart(event) { // eslint-disable-line no-unused-vars - let pointer = this.lastTouch; - let pointerObj = this.selectionHandler._pointerToPositionObject(pointer); - let from = this.body.nodes[this.temporaryIds.nodes[0]]; - let to = this.body.nodes[this.temporaryIds.nodes[1]]; - let edge = this.body.edges[this.edgeBeingEditedId]; + const pointer = this.lastTouch; + const pointerObj = this.selectionHandler._pointerToPositionObject(pointer); + const from = this.body.nodes[this.temporaryIds.nodes[0]]; + const to = this.body.nodes[this.temporaryIds.nodes[1]]; + const edge = this.body.edges[this.edgeBeingEditedId]; this.selectedControlNode = undefined; - let fromSelect = from.isOverlappingWith(pointerObj); - let toSelect = to.isOverlappingWith(pointerObj); + const fromSelect = from.isOverlappingWith(pointerObj); + const toSelect = to.isOverlappingWith(pointerObj); if (fromSelect === true) { this.selectedControlNode = from; @@ -939,8 +940,8 @@ class ManipulationSystem { */ _controlNodeDrag(event) { this.body.emitter.emit('disablePhysics'); - let pointer = this.body.functions.getPointer(event.center); - let pos = this.canvas.DOMtoCanvas(pointer); + const pointer = this.body.functions.getPointer(event.center); + const pos = this.canvas.DOMtoCanvas(pointer); if (this.selectedControlNode !== undefined) { this.selectedControlNode.x = pos.x; this.selectedControlNode.y = pos.y; @@ -958,9 +959,9 @@ class ManipulationSystem { * @private */ _controlNodeDragEnd(event) { - let pointer = this.body.functions.getPointer(event.center); - let pointerObj = this.selectionHandler._pointerToPositionObject(pointer); - let edge = this.body.edges[this.edgeBeingEditedId]; + const pointer = this.body.functions.getPointer(event.center); + const pointerObj = this.selectionHandler._pointerToPositionObject(pointer); + const edge = this.body.edges[this.edgeBeingEditedId]; // if the node that was dragged is not a control node, return if (this.selectedControlNode === undefined) { return; @@ -968,7 +969,7 @@ class ManipulationSystem { // we use the selection to find the node that is being dragged. We explicitly DEselect the control node here. this.selectionHandler.unselectAll(); - let overlappingNodeIds = this.selectionHandler._getAllNodesOverlappingWith(pointerObj); + const overlappingNodeIds = this.selectionHandler._getAllNodesOverlappingWith(pointerObj); let node = undefined; for (let i = overlappingNodeIds.length-1; i >= 0; i--) { if (overlappingNodeIds[i] !== this.selectedControlNode.id) { @@ -982,7 +983,7 @@ class ManipulationSystem { alert(this.options.locales[this.options.locale]['createEdgeError'] || this.options.locales['en']['createEdgeError']) } else { - let from = this.body.nodes[this.temporaryIds.nodes[0]]; + const from = this.body.nodes[this.temporaryIds.nodes[0]]; if (this.selectedControlNode.id === from.id) { this._performEditEdge(node.id, edge.to.id); } @@ -1020,8 +1021,8 @@ class ManipulationSystem { this.interactionHandler.drag.pointer = this.lastTouch; // Drag pointer is not updated when adding edges this.interactionHandler.drag.translation = this.lastTouch.translation; - let pointer = this.lastTouch; - let node = this.selectionHandler.getNodeAt(pointer); + const pointer = this.lastTouch; + const node = this.selectionHandler.getNodeAt(pointer); if (node !== undefined) { if (node.isCluster === true) { @@ -1029,12 +1030,12 @@ class ManipulationSystem { } else { // create a node the temporary line can look at - let targetNode = this._getNewTargetNode(node.x,node.y); + const targetNode = this._getNewTargetNode(node.x,node.y); this.body.nodes[targetNode.id] = targetNode; this.body.nodeIndices.push(targetNode.id); // create a temporary edge - let connectionEdge = this.body.functions.createEdge({ + const connectionEdge = this.body.functions.createEdge({ id: 'connectionEdge' + randomUUID(), from: node.id, to: targetNode.id, @@ -1062,19 +1063,19 @@ class ManipulationSystem { * @private */ _dragControlNode(event) { - let pointer = this.body.functions.getPointer(event.center); + const pointer = this.body.functions.getPointer(event.center); - var pointerObj = this.selectionHandler._pointerToPositionObject(pointer); + const pointerObj = this.selectionHandler._pointerToPositionObject(pointer); // remember the edge id - var connectFromId = undefined; + let connectFromId = undefined; if (this.temporaryIds.edges[0] !== undefined) { connectFromId = this.body.edges[this.temporaryIds.edges[0]].fromId; } // get the overlapping node but NOT the temporary node; - var overlappingNodeIds = this.selectionHandler._getAllNodesOverlappingWith(pointerObj); - var node = undefined; - for (var i = overlappingNodeIds.length - 1; i >= 0; i--) { + const overlappingNodeIds = this.selectionHandler._getAllNodesOverlappingWith(pointerObj); + let node = undefined; + for (let i = overlappingNodeIds.length - 1; i >= 0; i--) { // if the node id is NOT a temporary node, accept the node. if (this.temporaryIds.nodes.indexOf(overlappingNodeIds[i]) === -1) { node = this.body.nodes[overlappingNodeIds[i]]; @@ -1086,7 +1087,7 @@ class ManipulationSystem { this.selectionHandler._generateClickEvent('controlNodeDragging', event, pointer); if (this.temporaryIds.nodes[0] !== undefined) { - let targetNode = this.body.nodes[this.temporaryIds.nodes[0]]; // there is only one temp node in the add edge mode. + const targetNode = this.body.nodes[this.temporaryIds.nodes[0]]; // there is only one temp node in the add edge mode. targetNode.x = this.canvas._XconvertDOMtoCanvas(pointer.x); targetNode.y = this.canvas._YconvertDOMtoCanvas(pointer.y); this.body.emitter.emit('_redraw'); @@ -1104,8 +1105,8 @@ class ManipulationSystem { * @private */ _finishConnect(event) { - let pointer = this.body.functions.getPointer(event.center); - let pointerObj = this.selectionHandler._pointerToPositionObject(pointer); + const pointer = this.body.functions.getPointer(event.center); + const pointerObj = this.selectionHandler._pointerToPositionObject(pointer); // remember the edge id let connectFromId = undefined; @@ -1114,7 +1115,7 @@ class ManipulationSystem { } // get the overlapping node but NOT the temporary node; - let overlappingNodeIds = this.selectionHandler._getAllNodesOverlappingWith(pointerObj); + const overlappingNodeIds = this.selectionHandler._getAllNodesOverlappingWith(pointerObj); let node = undefined; for (let i = overlappingNodeIds.length-1; i >= 0; i--) { // if the node id is NOT a temporary node, accept the node. @@ -1153,7 +1154,7 @@ class ManipulationSystem { * @private */ _dragStartEdge(event) { - let pointer = this.lastTouch; + const pointer = this.lastTouch; this.selectionHandler._generateClickEvent('dragStart', event, pointer, undefined, true); } @@ -1169,7 +1170,7 @@ class ManipulationSystem { * @private */ _performAddNode(clickData) { - let defaultData = { + const defaultData = { id: randomUUID(), x: clickData.pointer.canvas.x, y: clickData.pointer.canvas.y, @@ -1205,7 +1206,7 @@ class ManipulationSystem { * @private */ _performAddEdge(sourceNodeId, targetNodeId) { - let defaultData = {from: sourceNodeId, to: targetNodeId}; + const defaultData = {from: sourceNodeId, to: targetNodeId}; if (typeof this.options.addEdge === 'function') { if (this.options.addEdge.length === 2) { this.options.addEdge(defaultData, (finalizedData) => { diff --git a/lib/network/modules/NodesHandler.js b/lib/network/modules/NodesHandler.js index d4cc26a6fc..a7e464ce7e 100644 --- a/lib/network/modules/NodesHandler.js +++ b/lib/network/modules/NodesHandler.js @@ -115,7 +115,7 @@ class NodesHandler { return 0.5; } else { - let scale = 1 / (max - min); + const scale = 1 / (max - min); return Math.max(0, (value - min) * scale); } } @@ -194,8 +194,8 @@ class NodesHandler { // update the shape in all nodes if (options.shape !== undefined) { - for (let nodeId in this.body.nodes) { - if (this.body.nodes.hasOwnProperty(nodeId)) { + for (const nodeId in this.body.nodes) { + if (Object.prototype.hasOwnProperty.call(this.body.nodes, nodeId)) { this.body.nodes[nodeId].updateShape(); } } @@ -207,7 +207,7 @@ class NodesHandler { typeof options.widthConstraint !== "undefined" || typeof options.heightConstraint !== "undefined" ) { - for (let nodeId of Object.keys(this.body.nodes)) { + for (const nodeId of Object.keys(this.body.nodes)) { this.body.nodes[nodeId].updateLabelModule(); this.body.nodes[nodeId].needsRefresh(); } @@ -215,8 +215,8 @@ class NodesHandler { // update the shape size in all nodes if (options.size !== undefined) { - for (let nodeId in this.body.nodes) { - if (this.body.nodes.hasOwnProperty(nodeId)) { + for (const nodeId in this.body.nodes) { + if (Object.prototype.hasOwnProperty.call(this.body.nodes, nodeId)) { this.body.nodes[nodeId].needsRefresh(); } } @@ -236,7 +236,7 @@ class NodesHandler { * @private */ setData(nodes, doNotEmit = false) { - let oldNodesData = this.body.data.nodes; + const oldNodesData = this.body.data.nodes; if (nodes instanceof DataSet || nodes instanceof DataView) { this.body.data.nodes = nodes; @@ -264,13 +264,13 @@ class NodesHandler { if (this.body.data.nodes) { // subscribe to new dataset - let me = this; + const me = this; forEach(this.nodesListeners, function (callback, event) { me.body.data.nodes.on(event, callback); }); // draw all new nodes - let ids = this.body.data.nodes.getIds(); + const ids = this.body.data.nodes.getIds(); this.add(ids, true); } @@ -288,11 +288,11 @@ class NodesHandler { */ add(ids, doNotEmit = false) { let id; - let newNodes = []; + const newNodes = []; for (let i = 0; i < ids.length; i++) { id = ids[i]; - let properties = this.body.data.nodes.get(id); - let node = this.create(properties); + const properties = this.body.data.nodes.get(id); + const node = this.create(properties); newNodes.push(node); this.body.nodes[id] = node; // note: this may replace an existing node } @@ -312,12 +312,12 @@ class NodesHandler { * @private */ update(ids, changedData, oldData) { - let nodes = this.body.nodes; + const nodes = this.body.nodes; let dataChanged = false; for (let i = 0; i < ids.length; i++) { - let id = ids[i]; + const id = ids[i]; let node = nodes[id]; - let data = changedData[i]; + const data = changedData[i]; if (node !== undefined) { // update node if (node.setOptions(data)) { @@ -337,7 +337,7 @@ class NodesHandler { // For now, this is just 'level' for hierarchical layout // Assumption: old and new data arranged in same order; at time of writing, this holds. dataChanged = changedData.some(function(newValue, index) { - let oldValue = oldData[index]; + const oldValue = oldData[index]; return (oldValue && oldValue.level !== newValue.level); }); } @@ -356,10 +356,10 @@ class NodesHandler { * @private */ remove(ids) { - let nodes = this.body.nodes; + const nodes = this.body.nodes; for (let i = 0; i < ids.length; i++) { - let id = ids[i]; + const id = ids[i]; delete nodes[id]; } @@ -384,7 +384,7 @@ class NodesHandler { */ refresh(clearPositions = false) { forEach(this.body.nodes, (node, nodeId) => { - let data = this.body.data.nodes.get(nodeId); + const data = this.body.data.nodes.get(nodeId); if (data !== undefined) { if (clearPositions === true) { node.setOptions({x:null, y:null}); @@ -402,26 +402,26 @@ class NodesHandler { * @returns {{}} */ getPositions(ids) { - let dataArray = {}; + const dataArray = {}; if (ids !== undefined) { if (Array.isArray(ids) === true) { for (let i = 0; i < ids.length; i++) { if (this.body.nodes[ids[i]] !== undefined) { - let node = this.body.nodes[ids[i]]; + const node = this.body.nodes[ids[i]]; dataArray[ids[i]] = { x: Math.round(node.x), y: Math.round(node.y) }; } } } else { if (this.body.nodes[ids] !== undefined) { - let node = this.body.nodes[ids]; + const node = this.body.nodes[ids]; dataArray[ids] = { x: Math.round(node.x), y: Math.round(node.y) }; } } } else { for (let i = 0; i < this.body.nodeIndices.length; i++) { - let node = this.body.nodes[this.body.nodeIndices[i]]; + const node = this.body.nodes[this.body.nodeIndices[i]]; dataArray[this.body.nodeIndices[i]] = { x: Math.round(node.x), y: Math.round(node.y) }; } } @@ -430,9 +430,13 @@ class NodesHandler { /** * Retrieves the x y position of a specific id. + * * @param {string} id The id to retrieve. + * * @throws {TypeError} If no id is included. * @throws {ReferenceError} If an invalid id is provided. + * + * @returns {{ x: number, y: number }} Returns X, Y canvas position of the node with given id. */ getPosition(id) { if (id == undefined) { @@ -487,12 +491,12 @@ class NodesHandler { * @returns {Array} */ getConnectedNodes(nodeId, direction) { - let nodeList = []; + const nodeList = []; if (this.body.nodes[nodeId] !== undefined) { - let node = this.body.nodes[nodeId]; - let nodeObj = {}; // used to quickly check if node already exists + const node = this.body.nodes[nodeId]; + const nodeObj = {}; // used to quickly check if node already exists for (let i = 0; i < node.edges.length; i++) { - let edge = node.edges[i]; + const edge = node.edges[i]; if (direction !== 'to' && edge.toId == node.id) { // these are double equals since ids can be numeric or string if (nodeObj[edge.fromId] === undefined) { nodeList.push(edge.fromId); @@ -516,9 +520,9 @@ class NodesHandler { * @returns {*} */ getConnectedEdges(nodeId) { - let edgeList = []; + const edgeList = []; if (this.body.nodes[nodeId] !== undefined) { - let node = this.body.nodes[nodeId]; + const node = this.body.nodes[nodeId]; for (let i = 0; i < node.edges.length; i++) { edgeList.push(node.edges[i].id) } diff --git a/lib/network/modules/PhysicsEngine.js b/lib/network/modules/PhysicsEngine.js index a0e854232d..4d9f4092f8 100644 --- a/lib/network/modules/PhysicsEngine.js +++ b/lib/network/modules/PhysicsEngine.js @@ -188,7 +188,7 @@ class PhysicsEngine { * configure the engine. */ init() { - var options; + let options; if (this.options.solver === 'forceAtlas2Based') { options = this.options.forceAtlas2Based; this.nodesSolver = new ForceAtlas2BasedRepulsionSolver(this.body, this.physicsBody, options); @@ -288,9 +288,9 @@ class PhysicsEngine { */ simulationStep() { // check if the physics have settled - var startTime = Date.now(); + const startTime = Date.now(); this.physicsTick(); - var physicsTime = Date.now() - startTime; + const physicsTime = Date.now() - startTime; // run double speed if it is a little graph if ((physicsTime < 0.4 * this.simulationInterval || this.runDoubleSpeed === true) && this.stabilized === false) { @@ -377,7 +377,7 @@ class PhysicsEngine { // adaptivity means the timestep adapts to the situation, only applicable for stabilization if (this.adaptiveTimestep === true && this.adaptiveTimestepEnabled === true) { // timestep remains stable for "interval" iterations. - let doAdaptive = (this.adaptiveCounter % this.adaptiveInterval === 0); + const doAdaptive = (this.adaptiveCounter % this.adaptiveInterval === 0); if (doAdaptive) { // first the big step and revert. @@ -420,12 +420,12 @@ class PhysicsEngine { this.physicsBody.forces = {}; this.physicsBody.physicsNodeIndices = []; this.physicsBody.physicsEdgeIndices = []; - let nodes = this.body.nodes; - let edges = this.body.edges; + const nodes = this.body.nodes; + const edges = this.body.edges; // get node indices for physics - for (let nodeId in nodes) { - if (nodes.hasOwnProperty(nodeId)) { + for (const nodeId in nodes) { + if (Object.prototype.hasOwnProperty.call(nodes, nodeId)) { if (nodes[nodeId].options.physics === true) { this.physicsBody.physicsNodeIndices.push(nodes[nodeId].id); } @@ -433,8 +433,8 @@ class PhysicsEngine { } // get edge indices for physics - for (let edgeId in edges) { - if (edges.hasOwnProperty(edgeId)) { + for (const edgeId in edges) { + if (Object.prototype.hasOwnProperty.call(edges, edgeId)) { if (edges[edgeId].options.physics === true) { this.physicsBody.physicsEdgeIndices.push(edges[edgeId].id); } @@ -443,7 +443,7 @@ class PhysicsEngine { // get the velocity and the forces vector for (let i = 0; i < this.physicsBody.physicsNodeIndices.length; i++) { - let nodeId = this.physicsBody.physicsNodeIndices[i]; + const nodeId = this.physicsBody.physicsNodeIndices[i]; this.physicsBody.forces[nodeId] = {x:0,y:0}; // forces can be reset because they are recalculated. Velocities have to persist. @@ -453,7 +453,7 @@ class PhysicsEngine { } // clean deleted nodes from the velocity vector - for (let nodeId in this.physicsBody.velocities) { + for (const nodeId in this.physicsBody.velocities) { if (nodes[nodeId] === undefined) { delete this.physicsBody.velocities[nodeId]; } @@ -465,13 +465,13 @@ class PhysicsEngine { * Revert the simulation one step. This is done so after stabilization, every new start of the simulation will also say stabilized. */ revert() { - var nodeIds = Object.keys(this.previousStates); - var nodes = this.body.nodes; - var velocities = this.physicsBody.velocities; + const nodeIds = Object.keys(this.previousStates); + const nodes = this.body.nodes; + const velocities = this.physicsBody.velocities; this.referenceState = {}; for (let i = 0; i < nodeIds.length; i++) { - let nodeId = nodeIds[i]; + const nodeId = nodeIds[i]; if (nodes[nodeId] !== undefined) { if (nodes[nodeId].options.physics === true) { this.referenceState[nodeId] = { @@ -497,12 +497,12 @@ class PhysicsEngine { */ _evaluateStepQuality() { let dx, dy, dpos; - let nodes = this.body.nodes; - let reference = this.referenceState; - let posThreshold = 0.3; + const nodes = this.body.nodes; + const reference = this.referenceState; + const posThreshold = 0.3; - for (let nodeId in this.referenceState) { - if (this.referenceState.hasOwnProperty(nodeId) && nodes[nodeId] !== undefined) { + for (const nodeId in this.referenceState) { + if (Object.prototype.hasOwnProperty.call(this.referenceState, nodeId) && nodes[nodeId] !== undefined) { dx = nodes[nodeId].x - reference[nodeId].positions.x; dy = nodes[nodeId].y - reference[nodeId].positions.y; @@ -520,16 +520,16 @@ class PhysicsEngine { * move the nodes one timestep and check if they are stabilized */ moveNodes() { - var nodeIndices = this.physicsBody.physicsNodeIndices; - var maxNodeVelocity = 0; - var averageNodeVelocity = 0; + const nodeIndices = this.physicsBody.physicsNodeIndices; + let maxNodeVelocity = 0; + let averageNodeVelocity = 0; // the velocity threshold (energy in the system) for the adaptivity toggle - var velocityAdaptiveThreshold = 5; + const velocityAdaptiveThreshold = 5; for (let i = 0; i < nodeIndices.length; i++) { - let nodeId = nodeIndices[i]; - let nodeVelocity = this._performStep(nodeId); + const nodeId = nodeIndices[i]; + const nodeVelocity = this._performStep(nodeId); // stabilized is true if stabilized is true and velocity is smaller than vmin --> all nodes must be stabilized maxNodeVelocity = Math.max(maxNodeVelocity, nodeVelocity); averageNodeVelocity += nodeVelocity; @@ -551,13 +551,13 @@ class PhysicsEngine { * @private */ calculateComponentVelocity(v,f, m) { - let df = this.modelOptions.damping * v; // damping force - let a = (f - df) / m; // acceleration + const df = this.modelOptions.damping * v; // damping force + const a = (f - df) / m; // acceleration v += a * this.timestep; // Put a limit on the velocities if it is really high - let maxV = this.options.maxVelocity || 1e9; + const maxV = this.options.maxVelocity || 1e9; if (Math.abs(v) > maxV) { v = ((v > 0) ? maxV: -maxV); } @@ -574,15 +574,15 @@ class PhysicsEngine { * @private */ _performStep(nodeId) { - let node = this.body.nodes[nodeId]; - let force = this.physicsBody.forces[nodeId]; + const node = this.body.nodes[nodeId]; + const force = this.physicsBody.forces[nodeId]; if (this.options.wind) { force.x += this.options.wind.x; force.y += this.options.wind.y; } - let velocity = this.physicsBody.velocities[nodeId]; + const velocity = this.physicsBody.velocities[nodeId]; // store the state so we can revert this.previousStates[nodeId] = {x:node.x, y:node.y, vx:velocity.x, vy:velocity.y}; @@ -605,7 +605,7 @@ class PhysicsEngine { velocity.y = 0; } - let totalVelocity = Math.sqrt(Math.pow(velocity.x,2) + Math.pow(velocity.y,2)); + const totalVelocity = Math.sqrt(Math.pow(velocity.x,2) + Math.pow(velocity.y,2)); return totalVelocity; } @@ -617,11 +617,11 @@ class PhysicsEngine { * @private */ _freezeNodes() { - var nodes = this.body.nodes; - for (var id in nodes) { - if (nodes.hasOwnProperty(id)) { + const nodes = this.body.nodes; + for (const id in nodes) { + if (Object.prototype.hasOwnProperty.call(nodes, id)) { if (nodes[id].x && nodes[id].y) { - let fixed = nodes[id].options.fixed; + const fixed = nodes[id].options.fixed; this.freezeCache[id] = {x:fixed.x, y:fixed.y}; fixed.x = true; fixed.y = true; @@ -637,9 +637,9 @@ class PhysicsEngine { * @private */ _restoreFrozenNodes() { - var nodes = this.body.nodes; - for (var id in nodes) { - if (nodes.hasOwnProperty(id)) { + const nodes = this.body.nodes; + for (const id in nodes) { + if (Object.prototype.hasOwnProperty.call(nodes, id)) { if (this.freezeCache[id] !== undefined) { nodes[id].options.fixed.x = this.freezeCache[id].x; nodes[id].options.fixed.y = this.freezeCache[id].y; @@ -708,9 +708,9 @@ class PhysicsEngine { * @private */ _stabilizationBatch() { - var running = () => (this.stabilized === false && this.stabilizationIterations < this.targetIterations); + const running = () => (this.stabilized === false && this.stabilizationIterations < this.targetIterations); - var sendProgress = () => { + const sendProgress = () => { this.body.emitter.emit('stabilizationProgress', { iterations: this.stabilizationIterations, total: this.targetIterations @@ -721,7 +721,7 @@ class PhysicsEngine { sendProgress(); // Ensure that there is at least one start event. } - var count = 0; + let count = 0; while (running() && count < this.options.stabilization.updateInterval) { this.physicsTick(); count++; @@ -778,20 +778,20 @@ class PhysicsEngine { * @private */ _drawForces(ctx) { - for (var i = 0; i < this.physicsBody.physicsNodeIndices.length; i++) { - let index = this.physicsBody.physicsNodeIndices[i]; - let node = this.body.nodes[index]; - let force = this.physicsBody.forces[index]; - let factor = 20; - let colorFactor = 0.03; - let forceSize = Math.sqrt(Math.pow(force.x,2) + Math.pow(force.x,2)); + for (let i = 0; i < this.physicsBody.physicsNodeIndices.length; i++) { + const index = this.physicsBody.physicsNodeIndices[i]; + const node = this.body.nodes[index]; + const force = this.physicsBody.forces[index]; + const factor = 20; + const colorFactor = 0.03; + const forceSize = Math.sqrt(Math.pow(force.x,2) + Math.pow(force.x,2)); - let size = Math.min(Math.max(5,forceSize),15); - let arrowSize = 3*size; + const size = Math.min(Math.max(5,forceSize),15); + const arrowSize = 3*size; - let color = HSVToHex((180 - Math.min(1,Math.max(0,colorFactor*forceSize))*180) / 360,1,1); + const color = HSVToHex((180 - Math.min(1,Math.max(0,colorFactor*forceSize))*180) / 360,1,1); - let point = { + const point = { x: node.x + factor*force.x, y: node.y + factor*force.y }; @@ -803,7 +803,7 @@ class PhysicsEngine { ctx.lineTo(point.x, point.y); ctx.stroke(); - let angle = Math.atan2(force.y, force.x); + const angle = Math.atan2(force.y, force.x); ctx.fillStyle = color; EndPoints.draw(ctx, {type: 'arrow', point: point, angle: angle, length: arrowSize}); ctx.fill(); diff --git a/lib/network/modules/SelectionHandler.js b/lib/network/modules/SelectionHandler.js index 449b88c79e..2769830cf7 100644 --- a/lib/network/modules/SelectionHandler.js +++ b/lib/network/modules/SelectionHandler.js @@ -38,7 +38,7 @@ class SelectionHandler { */ setOptions(options) { if (options !== undefined) { - let fields = ['multiselect', 'hoverConnectedEdges', 'selectable', 'selectConnectedEdges']; + const fields = ['multiselect', 'hoverConnectedEdges', 'selectable', 'selectConnectedEdges']; selectiveDeepExtend(fields, this.options, options); } } @@ -53,7 +53,7 @@ class SelectionHandler { selectOnPoint(pointer) { let selected = false; if (this.options.selectable === true) { - let obj = this.getNodeAt(pointer) || this.getEdgeAt(pointer); + const obj = this.getNodeAt(pointer) || this.getEdgeAt(pointer); // unselect after getting the objects in order to restore width and height. this.unselectAll(); @@ -74,7 +74,7 @@ class SelectionHandler { selectAdditionalOnPoint(pointer) { let selectionChanged = false; if (this.options.selectable === true) { - let obj = this.getNodeAt(pointer) || this.getEdgeAt(pointer); + const obj = this.getNodeAt(pointer) || this.getEdgeAt(pointer); if (obj !== undefined) { selectionChanged = true; @@ -101,7 +101,7 @@ class SelectionHandler { * @private */ _initBaseEvent(event, pointer) { - let properties = {}; + const properties = {}; properties['pointer'] = { DOM: { x: pointer.x, y: pointer.y }, @@ -126,14 +126,14 @@ class SelectionHandler { * @param {boolean|undefined} [emptySelection=false] Indicate if selection data should be passed */ _generateClickEvent(eventType, event, pointer, oldSelection, emptySelection = false) { - let properties = this._initBaseEvent(event, pointer); + const properties = this._initBaseEvent(event, pointer); if (emptySelection === true) { properties.nodes = []; properties.edges = []; } else { - let tmp = this.getSelection(); + const tmp = this.getSelection(); properties.nodes = tmp.nodes; properties.edges = tmp.edges; } @@ -195,10 +195,10 @@ class SelectionHandler { * @private */ _getAllNodesOverlappingWith(object) { - let overlappingNodes = []; - let nodes = this.body.nodes; + const overlappingNodes = []; + const nodes = this.body.nodes; for (let i = 0; i < this.body.nodeIndices.length; i++) { - let nodeId = this.body.nodeIndices[i]; + const nodeId = this.body.nodeIndices[i]; if (nodes[nodeId].isOverlappingWith(object)) { overlappingNodes.push(nodeId); } @@ -215,7 +215,7 @@ class SelectionHandler { * @private */ _pointerToPositionObject(pointer) { - let canvasPos = this.canvas.DOMtoCanvas(pointer); + const canvasPos = this.canvas.DOMtoCanvas(pointer); return { left: canvasPos.x - 1, top: canvasPos.y + 1, @@ -234,8 +234,8 @@ class SelectionHandler { */ getNodeAt(pointer, returnNode = true) { // we first check if this is an navigation controls element - let positionObject = this._pointerToPositionObject(pointer); - let overlappingNodes = this._getAllNodesOverlappingWith(positionObject); + const positionObject = this._pointerToPositionObject(pointer); + const overlappingNodes = this._getAllNodesOverlappingWith(positionObject); // if there are overlapping nodes, select the last one, this is the // one which is drawn on top of the others if (overlappingNodes.length > 0) { @@ -259,9 +259,9 @@ class SelectionHandler { * @private */ _getEdgesOverlappingWith(object, overlappingEdges) { - let edges = this.body.edges; + const edges = this.body.edges; for (let i = 0; i < this.body.edgeIndices.length; i++) { - let edgeId = this.body.edgeIndices[i]; + const edgeId = this.body.edgeIndices[i]; if (edges[edgeId].isOverlappingWith(object)) { overlappingEdges.push(edgeId); } @@ -276,7 +276,7 @@ class SelectionHandler { * @private */ _getAllEdgesOverlappingWith(object) { - let overlappingEdges = []; + const overlappingEdges = []; this._getEdgesOverlappingWith(object, overlappingEdges); return overlappingEdges; } @@ -291,19 +291,19 @@ class SelectionHandler { */ getEdgeAt(pointer, returnEdge = true) { // Iterate over edges, pick closest within 10 - var canvasPos = this.canvas.DOMtoCanvas(pointer); - var mindist = 10; - var overlappingEdge = null; - var edges = this.body.edges; - for (var i = 0; i < this.body.edgeIndices.length; i++) { - var edgeId = this.body.edgeIndices[i]; - var edge = edges[edgeId]; + const canvasPos = this.canvas.DOMtoCanvas(pointer); + let mindist = 10; + let overlappingEdge = null; + const edges = this.body.edges; + for (let i = 0; i < this.body.edgeIndices.length; i++) { + const edgeId = this.body.edgeIndices[i]; + const edge = edges[edgeId]; if (edge.connected) { - var xFrom = edge.from.x; - var yFrom = edge.from.y; - var xTo = edge.to.x; - var yTo = edge.to.y; - var dist = edge.edgeType.getDistanceToEdge(xFrom, yFrom, xTo, yTo, canvasPos.x, canvasPos.y); + const xFrom = edge.from.x; + const yFrom = edge.from.y; + const xTo = edge.to.x; + const yTo = edge.to.y; + const dist = edge.edgeType.getDistanceToEdge(xFrom, yFrom, xTo, yTo, canvasPos.x, canvasPos.y); if (dist < mindist) { overlappingEdge = edgeId; mindist = dist; @@ -375,13 +375,13 @@ class SelectionHandler { * Unselect all. The selectionObj is useful for this. */ unselectAll() { - for (let nodeId in this.selectionObj.nodes) { - if (this.selectionObj.nodes.hasOwnProperty(nodeId)) { + for (const nodeId in this.selectionObj.nodes) { + if (Object.prototype.hasOwnProperty.call(this.selectionObj.nodes, nodeId)) { this.selectionObj.nodes[nodeId].unselect(); } } - for (let edgeId in this.selectionObj.edges) { - if (this.selectionObj.edges.hasOwnProperty(edgeId)) { + for (const edgeId in this.selectionObj.edges) { + if (Object.prototype.hasOwnProperty.call(this.selectionObj.edges, edgeId)) { this.selectionObj.edges[edgeId].unselect(); } } @@ -398,8 +398,8 @@ class SelectionHandler { */ _getSelectedNodeCount() { let count = 0; - for (let nodeId in this.selectionObj.nodes) { - if (this.selectionObj.nodes.hasOwnProperty(nodeId)) { + for (const nodeId in this.selectionObj.nodes) { + if (Object.prototype.hasOwnProperty.call(this.selectionObj.nodes, nodeId)) { count += 1; } } @@ -413,8 +413,8 @@ class SelectionHandler { * @private */ _getSelectedNode() { - for (let nodeId in this.selectionObj.nodes) { - if (this.selectionObj.nodes.hasOwnProperty(nodeId)) { + for (const nodeId in this.selectionObj.nodes) { + if (Object.prototype.hasOwnProperty.call(this.selectionObj.nodes, nodeId)) { return this.selectionObj.nodes[nodeId]; } } @@ -428,8 +428,8 @@ class SelectionHandler { * @private */ _getSelectedEdge() { - for (let edgeId in this.selectionObj.edges) { - if (this.selectionObj.edges.hasOwnProperty(edgeId)) { + for (const edgeId in this.selectionObj.edges) { + if (Object.prototype.hasOwnProperty.call(this.selectionObj.edges, edgeId)) { return this.selectionObj.edges[edgeId]; } } @@ -445,8 +445,8 @@ class SelectionHandler { */ _getSelectedEdgeCount() { let count = 0; - for (let edgeId in this.selectionObj.edges) { - if (this.selectionObj.edges.hasOwnProperty(edgeId)) { + for (const edgeId in this.selectionObj.edges) { + if (Object.prototype.hasOwnProperty.call(this.selectionObj.edges, edgeId)) { count += 1; } } @@ -462,13 +462,13 @@ class SelectionHandler { */ _getSelectedObjectCount() { let count = 0; - for (let nodeId in this.selectionObj.nodes) { - if (this.selectionObj.nodes.hasOwnProperty(nodeId)) { + for (const nodeId in this.selectionObj.nodes) { + if (Object.prototype.hasOwnProperty.call(this.selectionObj.nodes, nodeId)) { count += 1; } } - for (let edgeId in this.selectionObj.edges) { - if (this.selectionObj.edges.hasOwnProperty(edgeId)) { + for (const edgeId in this.selectionObj.edges) { + if (Object.prototype.hasOwnProperty.call(this.selectionObj.edges, edgeId)) { count += 1; } } @@ -482,13 +482,13 @@ class SelectionHandler { * @private */ _selectionIsEmpty() { - for (let nodeId in this.selectionObj.nodes) { - if (this.selectionObj.nodes.hasOwnProperty(nodeId)) { + for (const nodeId in this.selectionObj.nodes) { + if (Object.prototype.hasOwnProperty.call(this.selectionObj.nodes, nodeId)) { return false; } } - for (let edgeId in this.selectionObj.edges) { - if (this.selectionObj.edges.hasOwnProperty(edgeId)) { + for (const edgeId in this.selectionObj.edges) { + if (Object.prototype.hasOwnProperty.call(this.selectionObj.edges, edgeId)) { return false; } } @@ -503,8 +503,8 @@ class SelectionHandler { * @private */ _clusterInSelection() { - for (let nodeId in this.selectionObj.nodes) { - if (this.selectionObj.nodes.hasOwnProperty(nodeId)) { + for (const nodeId in this.selectionObj.nodes) { + if (Object.prototype.hasOwnProperty.call(this.selectionObj.nodes, nodeId)) { if (this.selectionObj.nodes[nodeId].clusterSize > 1) { return true; } @@ -521,7 +521,7 @@ class SelectionHandler { */ _selectConnectedEdges(node) { for (let i = 0; i < node.edges.length; i++) { - let edge = node.edges[i]; + const edge = node.edges[i]; edge.select(); this._addToSelection(edge); } @@ -535,7 +535,7 @@ class SelectionHandler { */ _hoverConnectedEdges(node) { for (let i = 0; i < node.edges.length; i++) { - let edge = node.edges[i]; + const edge = node.edges[i]; edge.hover = true; this._addToHover(edge); } @@ -550,7 +550,7 @@ class SelectionHandler { */ _unselectConnectedEdges(node) { for (let i = 0; i < node.edges.length; i++) { - let edge = node.edges[i]; + const edge = node.edges[i]; edge.unselect(); this._removeFromSelection(edge); } @@ -566,7 +566,7 @@ class SelectionHandler { * @private */ emitBlurEvent(event, pointer, object) { - let properties = this._initBaseEvent(event, pointer); + const properties = this._initBaseEvent(event, pointer); if (object.hover === true) { object.hover = false; @@ -592,7 +592,7 @@ class SelectionHandler { * @private */ emitHoverEvent(event, pointer, object) { - let properties = this._initBaseEvent(event, pointer); + const properties = this._initBaseEvent(event, pointer); let hoverChanged = false; if (object.hover === false) { @@ -627,8 +627,8 @@ class SelectionHandler { let hoverChanged = false; // remove all node hover highlights - for (let nodeId in this.hoverObj.nodes) { - if (this.hoverObj.nodes.hasOwnProperty(nodeId)) { + for (const nodeId in this.hoverObj.nodes) { + if (Object.prototype.hasOwnProperty.call(this.hoverObj.nodes, nodeId)) { if (object === undefined || (object instanceof Node && object.id != nodeId) || object instanceof Edge) { this.emitBlurEvent(event, pointer, this.hoverObj.nodes[nodeId]); delete this.hoverObj.nodes[nodeId]; @@ -638,8 +638,8 @@ class SelectionHandler { } // removing all edge hover highlights - for (let edgeId in this.hoverObj.edges) { - if (this.hoverObj.edges.hasOwnProperty(edgeId)) { + for (const edgeId in this.hoverObj.edges) { + if (Object.prototype.hasOwnProperty.call(this.hoverObj.edges, edgeId)) { // if the hover has been changed here it means that the node has been hovered over or off // we then do not use the emitBlurEvent method here. if (hoverChanged === true) { @@ -685,8 +685,8 @@ class SelectionHandler { * @return {{nodes: Array., edges: Array.}} selection */ getSelection() { - let nodeIds = this.getSelectedNodes(); - let edgeIds = this.getSelectedEdges(); + const nodeIds = this.getSelectedNodes(); + const edgeIds = this.getSelectedEdges(); return { nodes: nodeIds, edges: edgeIds }; } @@ -697,10 +697,10 @@ class SelectionHandler { * selected nodes. */ getSelectedNodes() { - let idArray = []; + const idArray = []; if (this.options.selectable === true) { - for (let nodeId in this.selectionObj.nodes) { - if (this.selectionObj.nodes.hasOwnProperty(nodeId)) { + for (const nodeId in this.selectionObj.nodes) { + if (Object.prototype.hasOwnProperty.call(this.selectionObj.nodes, nodeId)) { idArray.push(this.selectionObj.nodes[nodeId].id); } } @@ -715,10 +715,10 @@ class SelectionHandler { * selected nodes. */ getSelectedEdges() { - let idArray = []; + const idArray = []; if (this.options.selectable === true) { - for (let edgeId in this.selectionObj.edges) { - if (this.selectionObj.edges.hasOwnProperty(edgeId)) { + for (const edgeId in this.selectionObj.edges) { + if (Object.prototype.hasOwnProperty.call(this.selectionObj.edges, edgeId)) { idArray.push(this.selectionObj.edges[edgeId].id); } } @@ -744,7 +744,7 @@ class SelectionHandler { for (i = 0; i < selection.nodes.length; i++) { id = selection.nodes[i]; - let node = this.body.nodes[id]; + const node = this.body.nodes[id]; if (!node) { throw new RangeError('Node with id "' + id + '" not found'); } @@ -757,7 +757,7 @@ class SelectionHandler { for (i = 0; i < selection.edges.length; i++) { id = selection.edges[i]; - let edge = this.body.edges[id]; + const edge = this.body.edges[id]; if (!edge) { throw new RangeError('Edge with id "' + id + '" not found'); } @@ -799,16 +799,16 @@ class SelectionHandler { * @private */ updateSelection() { - for (let nodeId in this.selectionObj.nodes) { - if (this.selectionObj.nodes.hasOwnProperty(nodeId)) { - if (!this.body.nodes.hasOwnProperty(nodeId)) { + for (const nodeId in this.selectionObj.nodes) { + if (Object.prototype.hasOwnProperty.call(this.selectionObj.nodes, nodeId)) { + if (!Object.prototype.hasOwnProperty.call(this.body.nodes, nodeId)) { delete this.selectionObj.nodes[nodeId]; } } } - for (let edgeId in this.selectionObj.edges) { - if (this.selectionObj.edges.hasOwnProperty(edgeId)) { - if (!this.body.edges.hasOwnProperty(edgeId)) { + for (const edgeId in this.selectionObj.edges) { + if (Object.prototype.hasOwnProperty.call(this.selectionObj.edges, edgeId)) { + if (!Object.prototype.hasOwnProperty.call(this.body.edges, edgeId)) { delete this.selectionObj.edges[edgeId]; } } @@ -842,24 +842,24 @@ class SelectionHandler { * @private */ getClickedItems(pointer) { - let point = this.canvas.DOMtoCanvas(pointer); - var items = []; + const point = this.canvas.DOMtoCanvas(pointer); + const items = []; // Note reverse order; we want the topmost clicked items to be first in the array // Also note that selected nodes are disregarded here; these normally display on top - let nodeIndices = this.body.nodeIndices; - let nodes = this.body.nodes; + const nodeIndices = this.body.nodeIndices; + const nodes = this.body.nodes; for (let i = nodeIndices.length - 1; i >= 0; i--) { - let node = nodes[nodeIndices[i]]; - let ret = node.getItemsOnPoint(point); + const node = nodes[nodeIndices[i]]; + const ret = node.getItemsOnPoint(point); items.push.apply(items, ret); // Append the return value to the running list. } - let edgeIndices = this.body.edgeIndices; - let edges = this.body.edges; + const edgeIndices = this.body.edgeIndices; + const edges = this.body.edges; for (let i = edgeIndices.length - 1; i >= 0; i--) { - let edge = edges[edgeIndices[i]]; - let ret = edge.getItemsOnPoint(point); + const edge = edges[edgeIndices[i]]; + const ret = edge.getItemsOnPoint(point); items.push.apply(items, ret); // Append the return value to the running list. } diff --git a/lib/network/modules/View.js b/lib/network/modules/View.js index fa2ab0920f..09b52900c6 100644 --- a/lib/network/modules/View.js +++ b/lib/network/modules/View.js @@ -69,9 +69,9 @@ class View { } else if (initialZoom === true) { // check if more than half of the nodes have a predefined position. If so, we use the range, not the approximation. let positionDefined = 0; - for (let nodeId in this.body.nodes) { - if (this.body.nodes.hasOwnProperty(nodeId)) { - let node = this.body.nodes[nodeId]; + for (const nodeId in this.body.nodes) { + if (Object.prototype.hasOwnProperty.call(this.body.nodes, nodeId)) { + const node = this.body.nodes[nodeId]; if (node.predefinedPosition === true) { positionDefined += 1; } @@ -84,7 +84,7 @@ class View { range = NetworkUtil.getRange(this.body.nodes, options.nodes); - let numberOfNodes = this.body.nodeIndices.length; + const numberOfNodes = this.body.nodeIndices.length; zoomLevel = 12.662 / (numberOfNodes + 7.4147) + 0.0964822; // this is obtained from fitting a dataset from 5 points with scale levels that looked good. // correct for larger canvasses. @@ -95,8 +95,8 @@ class View { this.body.emitter.emit("_resizeNodes"); range = NetworkUtil.getRange(this.body.nodes, options.nodes); - let xDistance = Math.abs(range.maxX - range.minX) * 1.1; - let yDistance = Math.abs(range.maxY - range.minY) * 1.1; + const xDistance = Math.abs(range.maxX - range.minX) * 1.1; + const yDistance = Math.abs(range.maxY - range.minY) * 1.1; const xZoomLevel = canvasWidth / xDistance; const yZoomLevel = canvasHeight / yDistance; @@ -111,8 +111,8 @@ class View { zoomLevel = 1.0; } - let center = NetworkUtil.findCenter(range); - let animationOptions = {position: center, scale: zoomLevel, animation: options.animation}; + const center = NetworkUtil.findCenter(range); + const animationOptions = {position: center, scale: zoomLevel, animation: options.animation}; this.moveTo(animationOptions); } @@ -126,7 +126,7 @@ class View { */ focus(nodeId, options = {}) { if (this.body.nodes[nodeId] !== undefined) { - let nodePosition = {x: this.body.nodes[nodeId].x, y: this.body.nodes[nodeId].y}; + const nodePosition = {x: this.body.nodes[nodeId].x, y: this.body.nodes[nodeId].y}; options.position = nodePosition; options.lockedOnNode = nodeId; @@ -255,9 +255,9 @@ class View { // set the scale so the viewCenter is based on the correct zoom level. This is overridden in the transitionRedraw // but at least then we'll have the target transition this.body.view.scale = this.targetScale; - let viewCenter = this.canvas.DOMtoCanvas({x: 0.5 * this.canvas.frame.canvas.clientWidth, y: 0.5 * this.canvas.frame.canvas.clientHeight}); + const viewCenter = this.canvas.DOMtoCanvas({x: 0.5 * this.canvas.frame.canvas.clientWidth, y: 0.5 * this.canvas.frame.canvas.clientHeight}); - let distanceFromCenter = { // offset from view, distance view has to change by these x and y to center the node + const distanceFromCenter = { // offset from view, distance view has to change by these x and y to center the node x: viewCenter.x - options.position.x, y: viewCenter.y - options.position.y }; @@ -294,14 +294,14 @@ class View { * @private */ _lockedRedraw() { - let nodePosition = {x: this.body.nodes[this.lockedOnNodeId].x, y: this.body.nodes[this.lockedOnNodeId].y}; - let viewCenter = this.canvas.DOMtoCanvas({x: 0.5 * this.canvas.frame.canvas.clientWidth, y: 0.5 * this.canvas.frame.canvas.clientHeight}); - let distanceFromCenter = { // offset from view, distance view has to change by these x and y to center the node + const nodePosition = {x: this.body.nodes[this.lockedOnNodeId].x, y: this.body.nodes[this.lockedOnNodeId].y}; + const viewCenter = this.canvas.DOMtoCanvas({x: 0.5 * this.canvas.frame.canvas.clientWidth, y: 0.5 * this.canvas.frame.canvas.clientHeight}); + const distanceFromCenter = { // offset from view, distance view has to change by these x and y to center the node x: viewCenter.x - nodePosition.x, y: viewCenter.y - nodePosition.y }; - let sourceTranslation = this.body.view.translation; - let targetTranslation = { + const sourceTranslation = this.body.view.translation; + const targetTranslation = { x: sourceTranslation.x + distanceFromCenter.x * this.body.view.scale + this.lockedOnNodeOffset.x, y: sourceTranslation.y + distanceFromCenter.y * this.body.view.scale + this.lockedOnNodeOffset.y }; @@ -328,7 +328,7 @@ class View { this.easingTime += this.animationSpeed; this.easingTime = finished === true ? 1.0 : this.easingTime; - let progress = easingFunctions[this.animationEasingFunction](this.easingTime); + const progress = easingFunctions[this.animationEasingFunction](this.easingTime); this.body.view.scale = this.sourceScale + (this.targetScale - this.sourceScale) * progress; this.body.view.translation = { diff --git a/lib/network/modules/components/DirectionStrategy.js b/lib/network/modules/components/DirectionStrategy.js index 0cb2a4c7d2..0000f7899b 100644 --- a/lib/network/modules/components/DirectionStrategy.js +++ b/lib/network/modules/components/DirectionStrategy.js @@ -161,7 +161,7 @@ class VerticalStrategy extends DirectionInterface { /** @inheritdoc */ getTreeSize(index) { - let res = this.layout.hierarchical.getTreeSize(this.layout.body.nodes, index); + const res = this.layout.hierarchical.getTreeSize(this.layout.body.nodes, index); return {min: res.min_x, max: res.max_x}; } @@ -224,7 +224,7 @@ class HorizontalStrategy extends DirectionInterface { /** @inheritdoc */ getTreeSize(index) { - let res = this.layout.hierarchical.getTreeSize(this.layout.body.nodes, index); + const res = this.layout.hierarchical.getTreeSize(this.layout.body.nodes, index); return {min: res.min_y, max: res.max_y}; } diff --git a/lib/network/modules/components/Edge.js b/lib/network/modules/components/Edge.js index 2e799bce9c..a6ce781d22 100644 --- a/lib/network/modules/components/Edge.js +++ b/lib/network/modules/components/Edge.js @@ -99,7 +99,7 @@ class Edge { options.value = parseFloat(options.value); } - let pile = [options, this.options, this.defaultOptions]; + const pile = [options, this.options, this.defaultOptions]; this.chooser = choosify('edge', pile); // update label Module @@ -127,7 +127,7 @@ class Edge { * @param {boolean} [copyFromGlobals=false] */ static parseOptions(parentOptions, newOptions, allowDeletion = false, globalOptions = {}, copyFromGlobals = false) { - var fields = [ + const fields = [ 'endPointOffset', 'arrowStrikethrough', 'id', @@ -205,7 +205,7 @@ class Edge { // handle multiple input cases for arrows if (newOptions.arrows !== undefined && newOptions.arrows !== null) { if (typeof newOptions.arrows === 'string') { - let arrows = newOptions.arrows.toLowerCase(); + const arrows = newOptions.arrows.toLowerCase(); parentOptions.arrows.to.enabled = arrows.indexOf("to") != -1; parentOptions.arrows.middle.enabled = arrows.indexOf("middle") != -1; parentOptions.arrows.from.enabled = arrows.indexOf("from") != -1; @@ -234,15 +234,15 @@ class Edge { opacity: 1 } : newOptions.color; - let toColor = parentOptions.color; + const toColor = parentOptions.color; // If passed, fill in values from default options - required in the case of no prototype bridging if (copyFromGlobals) { deepExtend(toColor, globalOptions.color, false, allowDeletion); } else { // Clear local properties - need to do it like this in order to retain prototype bridges - for (var i in toColor) { - if (toColor.hasOwnProperty(i)) { + for (const i in toColor) { + if (Object.prototype.hasOwnProperty.call(toColor, i)) { delete toColor[i]; } } @@ -282,7 +282,7 @@ class Edge { parentOptions.font = bridgeObject(globalOptions.font); // set the object back to the global options } - if(newOptions.hasOwnProperty("selfReferenceSize")){ + if(Object.prototype.hasOwnProperty.call(newOptions, "selfReferenceSize")){ console.log('The selfReferenceSize property has been deprecated. Please use selfReference property instead. The selfReference can be set like thise selfReference:{size:30, angle:Math.PI / 4}'); parentOptions.selfReference.size = newOptions.selfReferenceSize } @@ -295,11 +295,11 @@ class Edge { * @returns {ArrowOptions} */ getFormattingValues() { - let toArrow = (this.options.arrows.to === true) || (this.options.arrows.to.enabled === true) - let fromArrow = (this.options.arrows.from === true) || (this.options.arrows.from.enabled === true) - let middleArrow = (this.options.arrows.middle === true) || (this.options.arrows.middle.enabled === true) - let inheritsColor = this.options.color.inherit; - let values = { + const toArrow = (this.options.arrows.to === true) || (this.options.arrows.to.enabled === true) + const fromArrow = (this.options.arrows.from === true) || (this.options.arrows.from.enabled === true) + const middleArrow = (this.options.arrows.middle === true) || (this.options.arrows.middle.enabled === true) + const inheritsColor = this.options.color.inherit; + const values = { toArrow: toArrow, toArrowScale: this.options.arrows.to.scaleFactor, toArrowType: this.options.arrows.to.type, @@ -339,7 +339,7 @@ class Edge { if (this.selected || this.hover) { if (this.chooser === true) { if (this.selected) { - let selectedWidth = this.options.selectionWidth; + const selectedWidth = this.options.selectionWidth; if (typeof selectedWidth === 'function') { values.width = selectedWidth(values.width); } else if (typeof selectedWidth === 'number') { @@ -349,7 +349,7 @@ class Edge { values.color = this.options.color.highlight; values.shadow = this.options.shadow.enabled; } else if (this.hover) { - let hoverWidth = this.options.hoverWidth; + const hoverWidth = this.options.hoverWidth; if (typeof hoverWidth === 'function') { values.width = hoverWidth(values.width); } else if (typeof hoverWidth === 'number') { @@ -386,7 +386,7 @@ class Edge { * @param {Object} options */ updateLabelModule(options) { - let pile = [ + const pile = [ options, this.options, this.globalOptions, // Currently set global edge options @@ -405,7 +405,7 @@ class Edge { * @returns {boolean} */ updateEdgeType() { - let smooth = this.options.smooth; + const smooth = this.options.smooth; let dataChanged = false; let changeInType = true; if (this.edgeType !== undefined) { @@ -527,10 +527,10 @@ class Edge { */ setValueRange(min, max, total) { if (this.options.value !== undefined) { - var scale = this.options.scaling.customScalingFunction(min, max, total, this.options.value); - var widthDiff = this.options.scaling.max - this.options.scaling.min; + const scale = this.options.scaling.customScalingFunction(min, max, total, this.options.value); + const widthDiff = this.options.scaling.max - this.options.scaling.min; if (this.options.scaling.label.enabled === true) { - var fontDiff = this.options.scaling.label.max - this.options.scaling.label.min; + const fontDiff = this.options.scaling.label.max - this.options.scaling.label.min; this.options.font.size = this.options.scaling.label.min + scale * fontDiff; } this.options.width = this.options.scaling.min + scale * widthDiff; @@ -688,19 +688,20 @@ class Edge { drawLabel(ctx, viaNode) { if (this.options.label !== undefined) { // set style - var node1 = this.from; - var node2 = this.to; + const node1 = this.from; + const node2 = this.to; if (this.labelModule.differentState(this.selected, this.hover)) { this.labelModule.getTextSize(ctx, this.selected, this.hover); } + let point; if (node1.id != node2.id) { this.labelModule.pointToSelf = false; - var point = this.edgeType.getPoint(0.5, viaNode); + point = this.edgeType.getPoint(0.5, viaNode); ctx.save(); - let rotationPoint = this._getRotation(ctx); + const rotationPoint = this._getRotation(ctx); if (rotationPoint.angle != 0) { ctx.translate(rotationPoint.x, rotationPoint.y); ctx.rotate(rotationPoint.angle); @@ -753,16 +754,16 @@ class Edge { * @returns {Array.} list with the items which are on the point */ getItemsOnPoint(point) { - var ret = []; + const ret = []; if (this.labelModule.visible()) { - let rotationPoint = this._getRotation(); + const rotationPoint = this._getRotation(); if (pointInRect(this.labelModule.getSize(), point, rotationPoint)) { ret.push({edgeId:this.id, labelId:0}); } } - let obj = { + const obj = { left: point.x, top: point.y }; @@ -782,15 +783,15 @@ class Edge { */ isOverlappingWith(obj) { if (this.connected) { - var distMax = 10; - var xFrom = this.from.x; - var yFrom = this.from.y; - var xTo = this.to.x; - var yTo = this.to.y; - var xObj = obj.left; - var yObj = obj.top; + const distMax = 10; + const xFrom = this.from.x; + const yFrom = this.from.y; + const xTo = this.to.x; + const yTo = this.to.y; + const xObj = obj.left; + const yObj = obj.top; - var dist = this.edgeType.getDistanceToEdge(xFrom, yFrom, xTo, yTo, xObj, yObj); + const dist = this.edgeType.getDistanceToEdge(xFrom, yFrom, xTo, yTo, xObj, yObj); return (dist < distMax); } @@ -808,14 +809,14 @@ class Edge { * @private */ _getRotation(ctx) { - let viaNode = this.edgeType.getViaNode(); - let point = this.edgeType.getPoint(0.5, viaNode); + const viaNode = this.edgeType.getViaNode(); + const point = this.edgeType.getPoint(0.5, viaNode); if (ctx !== undefined) { this.labelModule.calculateLabelSize(ctx, this.selected, this.hover, point.x, point.y); } - let ret = { + const ret = { x: point.x, y: this.labelModule.size.yLine, angle: 0 @@ -829,9 +830,9 @@ class Edge { return ret; // No need to calculate angle } - var dy = this.from.y - this.to.y; - var dx = this.from.x - this.to.x; - var angle = Math.atan2(dy, dx); // radians + const dy = this.from.y - this.to.y; + const dx = this.from.x - this.to.x; + let angle = Math.atan2(dy, dx); // radians // rotate so that label is readable if ((angle < -1 && dx < 0) || (angle > 0 && dx < 0)) { diff --git a/lib/network/modules/components/NavigationHandler.js b/lib/network/modules/components/NavigationHandler.js index bcea3fda1b..c229cd0776 100644 --- a/lib/network/modules/components/NavigationHandler.js +++ b/lib/network/modules/components/NavigationHandler.js @@ -63,7 +63,7 @@ class NavigationHandler { cleanNavigation() { // clean hammer bindings if (this.navigationHammers.length != 0) { - for (var i = 0; i < this.navigationHammers.length; i++) { + for (let i = 0; i < this.navigationHammers.length; i++) { this.navigationHammers[i].destroy(); } this.navigationHammers = []; @@ -89,19 +89,19 @@ class NavigationHandler { this.cleanNavigation(); this.navigationDOM = {}; - var navigationDivs = ['up','down','left','right','zoomIn','zoomOut','zoomExtends']; - var navigationDivActions = ['_moveUp','_moveDown','_moveLeft','_moveRight','_zoomIn','_zoomOut','_fit']; + const navigationDivs = ['up','down','left','right','zoomIn','zoomOut','zoomExtends']; + const navigationDivActions = ['_moveUp','_moveDown','_moveLeft','_moveRight','_zoomIn','_zoomOut','_fit']; this.navigationDOM['wrapper'] = document.createElement('div'); this.navigationDOM['wrapper'].className = 'vis-navigation'; this.canvas.frame.appendChild(this.navigationDOM['wrapper']); - for (var i = 0; i < navigationDivs.length; i++) { + for (let i = 0; i < navigationDivs.length; i++) { this.navigationDOM[navigationDivs[i]] = document.createElement('div'); this.navigationDOM[navigationDivs[i]].className = 'vis-button vis-' + navigationDivs[i]; this.navigationDOM['wrapper'].appendChild(this.navigationDOM[navigationDivs[i]]); - var hammer = new Hammer(this.navigationDOM[navigationDivs[i]]); + const hammer = new Hammer(this.navigationDOM[navigationDivs[i]]); if (navigationDivActions[i] === "_fit") { onTouch(hammer, this._fit.bind(this)); } @@ -114,7 +114,7 @@ class NavigationHandler { // use a hammer for the release so we do not require the one used in the rest of the network // the one the rest uses can be overloaded by the manipulation system. - var hammerFrame = new Hammer(this.canvas.frame); + const hammerFrame = new Hammer(this.canvas.frame); onRelease(hammerFrame, () => {this._stopMovement();}); this.navigationHammers.push(hammerFrame); @@ -163,8 +163,8 @@ class NavigationHandler { * @private */ _stopMovement() { - for (let boundAction in this.boundFunctions) { - if (this.boundFunctions.hasOwnProperty(boundAction)) { + for (const boundAction in this.boundFunctions) { + if (Object.prototype.hasOwnProperty.call(this.boundFunctions, boundAction)) { this.body.emitter.off("initRedraw", this.boundFunctions[boundAction]); this.body.emitter.emit("_stopRendering"); } @@ -196,12 +196,12 @@ class NavigationHandler { * @private */ _zoomIn() { - var scaleOld = this.body.view.scale; - var scale = this.body.view.scale * (1 + this.options.keyboard.speed.zoom); - var translation = this.body.view.translation; - var scaleFrac = scale / scaleOld; - var tx = (1 - scaleFrac) * this.canvas.canvasViewCenter.x + translation.x * scaleFrac; - var ty = (1 - scaleFrac) * this.canvas.canvasViewCenter.y + translation.y * scaleFrac; + const scaleOld = this.body.view.scale; + const scale = this.body.view.scale * (1 + this.options.keyboard.speed.zoom); + const translation = this.body.view.translation; + const scaleFrac = scale / scaleOld; + const tx = (1 - scaleFrac) * this.canvas.canvasViewCenter.x + translation.x * scaleFrac; + const ty = (1 - scaleFrac) * this.canvas.canvasViewCenter.y + translation.y * scaleFrac; this.body.view.scale = scale; this.body.view.translation = { x: tx, y: ty }; @@ -214,12 +214,12 @@ class NavigationHandler { * @private */ _zoomOut() { - var scaleOld = this.body.view.scale; - var scale = this.body.view.scale / (1 + this.options.keyboard.speed.zoom); - var translation = this.body.view.translation; - var scaleFrac = scale / scaleOld; - var tx = (1 - scaleFrac) * this.canvas.canvasViewCenter.x + translation.x * scaleFrac; - var ty = (1 - scaleFrac) * this.canvas.canvasViewCenter.y + translation.y * scaleFrac; + const scaleOld = this.body.view.scale; + const scale = this.body.view.scale / (1 + this.options.keyboard.speed.zoom); + const translation = this.body.view.translation; + const scaleFrac = scale / scaleOld; + const tx = (1 - scaleFrac) * this.canvas.canvasViewCenter.x + translation.x * scaleFrac; + const ty = (1 - scaleFrac) * this.canvas.canvasViewCenter.y + translation.y * scaleFrac; this.body.view.scale = scale; this.body.view.translation = { x: tx, y: ty }; diff --git a/lib/network/modules/components/Node.js b/lib/network/modules/components/Node.js index 934e534cfb..7759f8678c 100644 --- a/lib/network/modules/components/Node.js +++ b/lib/network/modules/components/Node.js @@ -96,7 +96,7 @@ class Node { * @param {Edge} edge */ detachEdge(edge) { - var index = this.edges.indexOf(edge); + const index = this.edges.indexOf(edge); if (index != -1) { this.edges.splice(index, 1); } @@ -110,7 +110,7 @@ class Node { * @returns {null|boolean} */ setOptions(options) { - let currentShape = this.options.shape; + const currentShape = this.options.shape; if (!options) { return; // Note that the return value will be 'undefined'! This is OK. @@ -149,7 +149,7 @@ class Node { // this transforms all shorthands into fully defined options Node.parseOptions(this.options, options, true, this.globalOptions, this.grouplist); - let pile = [options, this.options, this.defaultOptions]; + const pile = [options, this.options, this.defaultOptions]; this.chooser = choosify('node', pile); @@ -243,7 +243,7 @@ class Node { static updateGroupOptions(parentOptions, newOptions, groupList) { if (groupList === undefined) return; // No groups, nothing to do - var group = parentOptions.group; + const group = parentOptions.group; // paranoia: the selected group is already merged into node options, check. if (newOptions !== undefined && newOptions.group !== undefined && group !== newOptions.group) { @@ -251,11 +251,11 @@ class Node { } - var hasGroup = (typeof group === 'number' || (typeof group === 'string' && group != '')); + const hasGroup = (typeof group === 'number' || (typeof group === 'string' && group != '')); if (!hasGroup) return; // current node has no group, no need to merge - var groupObj = groupList.get(group); + const groupObj = groupList.get(group); if (groupObj.opacity !== undefined && newOptions.opacity === undefined) { if (!Node.checkOpacity(groupObj.opacity)) { @@ -288,7 +288,7 @@ class Node { * @static */ static parseOptions(parentOptions, newOptions, allowDeletion = false, globalOptions = {}, groupList) { - var fields = [ + const fields = [ 'color', 'fixed', 'shadow' @@ -321,7 +321,7 @@ class Node { // individual shape newOptions if (newOptions.color !== undefined && newOptions.color !== null) { - let parsedColor = parseColor(newOptions.color); + const parsedColor = parseColor(newOptions.color); fillIfDefined(parentOptions.color, parsedColor); } else if (allowDeletion === true && newOptions.color === null) { @@ -362,7 +362,7 @@ class Node { * @returns {{color: *, borderWidth: *, borderColor: *, size: *, borderDashes: (boolean|Array|allOptions.nodes.shapeProperties.borderDashes|{boolean, array}), borderRadius: (number|allOptions.nodes.shapeProperties.borderRadius|{number}|Array), shadow: *, shadowColor: *, shadowSize: *, shadowX: *, shadowY: *}} */ getFormattingValues() { - let values = { + const values = { color: this.options.color.background, opacity: this.options.opacity, borderWidth: this.options.borderWidth, @@ -440,8 +440,8 @@ class Node { // WE DON'T WANT THE ORDER OF THE PROTOTYPES!!!! At least, not for font handling of labels. // This is a good indication that the prototype usage of options is deficient. // - var currentGroup = this.grouplist.get(this.options.group, false); - let pile = [ + const currentGroup = this.grouplist.get(this.options.group, false); + const pile = [ options, // new options this.options, // current node options, see comment above for prototype currentGroup, // group options, if any @@ -618,10 +618,10 @@ class Node { */ setValueRange(min, max, total) { if (this.options.value !== undefined) { - var scale = this.options.scaling.customScalingFunction(min, max, total, this.options.value); - var sizeDiff = this.options.scaling.max - this.options.scaling.min; + const scale = this.options.scaling.customScalingFunction(min, max, total, this.options.value); + const sizeDiff = this.options.scaling.max - this.options.scaling.min; if (this.options.scaling.label.enabled === true) { - var fontDiff = this.options.scaling.label.max - this.options.scaling.label.min; + const fontDiff = this.options.scaling.label.max - this.options.scaling.label.min; this.options.font.size = this.options.scaling.label.min + scale * fontDiff; } this.options.size = this.options.scaling.min + scale * sizeDiff; @@ -641,7 +641,7 @@ class Node { * @param {CanvasRenderingContext2D} ctx */ draw(ctx) { - let values = this.getFormattingValues(); + const values = this.getFormattingValues(); this.shape.draw(ctx, this.x, this.y, this.selected, this.hover, values); } @@ -661,7 +661,7 @@ class Node { * @param {CanvasRenderingContext2D} ctx */ resize(ctx) { - let values = this.getFormattingValues(); + const values = this.getFormattingValues(); this.shape.resize(ctx, this.selected, this.hover, values); } @@ -674,7 +674,7 @@ class Node { * @returns {Array.} list with the items which are on the point */ getItemsOnPoint(point) { - var ret = []; + const ret = []; if (this.labelModule.visible()) { if (pointInRect(this.labelModule.getSize(), point)) { diff --git a/lib/network/modules/components/algorithms/FloydWarshall.js b/lib/network/modules/components/algorithms/FloydWarshall.js index 5b481c18ba..e11635e2a6 100644 --- a/lib/network/modules/components/algorithms/FloydWarshall.js +++ b/lib/network/modules/components/algorithms/FloydWarshall.js @@ -18,13 +18,13 @@ class FloydWarshall { * @returns {{}} */ getDistances(body, nodesArray, edgesArray) { - let D_matrix = {}; - let edges = body.edges; + const D_matrix = {}; + const edges = body.edges; // prepare matrix with large numbers for (let i = 0; i < nodesArray.length; i++) { - let node = nodesArray[i]; - let cell = {}; + const node = nodesArray[i]; + const cell = {}; D_matrix[node] = cell; for (let j = 0; j < nodesArray.length; j++) { cell[nodesArray[j]] = (i == j ? 0 : 1e9); @@ -33,7 +33,7 @@ class FloydWarshall { // put the weights for the edges in. This assumes unidirectionality. for (let i = 0; i < edgesArray.length; i++) { - let edge = edges[edgesArray[i]]; + const edge = edges[edgesArray[i]]; // edge has to be connected if it counts to the distances. If it is connected to inner clusters it will crash so we also check if it is in the D_matrix if (edge.connected === true && D_matrix[edge.fromId] !== undefined && D_matrix[edge.toId] !== undefined) { D_matrix[edge.fromId][edge.toId] = 1; @@ -41,20 +41,20 @@ class FloydWarshall { } } - let nodeCount = nodesArray.length; + const nodeCount = nodesArray.length; // Adapted FloydWarshall based on unidirectionality to greatly reduce complexity. for (let k = 0; k < nodeCount; k++) { - let knode = nodesArray[k]; - let kcolm = D_matrix[knode]; + const knode = nodesArray[k]; + const kcolm = D_matrix[knode]; for (let i = 0; i < nodeCount - 1; i++) { - let inode = nodesArray[i]; - let icolm = D_matrix[inode]; + const inode = nodesArray[i]; + const icolm = D_matrix[inode]; for (let j = i + 1; j < nodeCount; j++) { - let jnode = nodesArray[j]; - let jcolm = D_matrix[jnode]; + const jnode = nodesArray[j]; + const jcolm = D_matrix[jnode]; - let val = Math.min(icolm[jnode], icolm[knode] + kcolm[jnode]); + const val = Math.min(icolm[jnode], icolm[knode] + kcolm[jnode]); icolm[jnode] = val; jcolm[inode] = val; } diff --git a/lib/network/modules/components/edges/cubic-bezier-edge.ts b/lib/network/modules/components/edges/cubic-bezier-edge.ts index 23d827cbe1..32f6caef12 100644 --- a/lib/network/modules/components/edges/cubic-bezier-edge.ts +++ b/lib/network/modules/components/edges/cubic-bezier-edge.ts @@ -40,8 +40,8 @@ export class CubicBezierEdge extends CubicBezierEdgeBase<[Point, Point]> { viaNodes: [Point, Point] ): void { // get the coordinates of the support points. - let via1 = viaNodes[0]; - let via2 = viaNodes[1]; + const via1 = viaNodes[0]; + const via2 = viaNodes[1]; this._bezierCurve(ctx, values, via1, via2); } diff --git a/lib/network/modules/components/edges/util/edge-base.ts b/lib/network/modules/components/edges/util/edge-base.ts index 3b6ede1a2b..35e21b4d66 100644 --- a/lib/network/modules/components/edges/util/edge-base.ts +++ b/lib/network/modules/components/edges/util/edge-base.ts @@ -724,7 +724,7 @@ export abstract class EdgeBase implements EdgeType { let reversed: boolean; let scaleFactor: number; let type: ArrowType; - let lineWidth: number = values.width; + const lineWidth: number = values.width; if (position === "from") { node1 = this.from; diff --git a/lib/network/modules/components/nodes/Cluster.js b/lib/network/modules/components/nodes/Cluster.js index bfe80594b9..ee56d1f3ca 100644 --- a/lib/network/modules/components/nodes/Cluster.js +++ b/lib/network/modules/components/nodes/Cluster.js @@ -33,7 +33,7 @@ class Cluster extends Node { * @param {string|number} childClusterId id of child cluster to open */ _openChildCluster(childClusterId) { - let childCluster = this.body.nodes[childClusterId]; + const childCluster = this.body.nodes[childClusterId]; if (this.containedNodes[childClusterId] === undefined) { throw new Error('node with id: ' + childClusterId + ' not in current cluster'); } @@ -63,7 +63,7 @@ class Cluster extends Node { forEach(this.edges, (parentClusterEdge) => { // Assumption: a clustered edge can only be present in a single clustering edge // Not tested here - let index = parentClusterEdge.clusteringEdgeReplacingIds.indexOf(clusterEdge.id); + const index = parentClusterEdge.clusteringEdgeReplacingIds.indexOf(clusterEdge.id); if (index === -1) return; forEach(clusterEdge.clusteringEdgeReplacingIds, (srcId) => { diff --git a/lib/network/modules/components/nodes/shapes/Box.js b/lib/network/modules/components/nodes/shapes/Box.js index 7de47bcc4d..3f0192c91b 100644 --- a/lib/network/modules/components/nodes/shapes/Box.js +++ b/lib/network/modules/components/nodes/shapes/Box.js @@ -27,7 +27,7 @@ class Box extends NodeBase { */ resize(ctx, selected = this.selected, hover = this.hover) { if (this.needsRefresh(selected, hover)) { - var dimensions = this.getDimensionsFromLabel(ctx, selected, hover); + const dimensions = this.getDimensionsFromLabel(ctx, selected, hover); this.width = dimensions.width + this.margin.right + this.margin.left; this.height = dimensions.height + this.margin.top + this.margin.bottom; @@ -69,7 +69,7 @@ class Box extends NodeBase { updateBoundingBox(x, y, ctx, selected, hover) { this._updateBoundingBox(x, y, ctx, selected, hover); - let borderRadius = this.options.shapeProperties.borderRadius; // only effective for box + const borderRadius = this.options.shapeProperties.borderRadius; // only effective for box this._addBoundingBoxMargin(borderRadius); } @@ -83,7 +83,7 @@ class Box extends NodeBase { if (ctx) { this.resize(ctx); } - let borderWidth = this.options.borderWidth; + const borderWidth = this.options.borderWidth; return Math.min( Math.abs((this.width) / 2 / Math.cos(angle)), diff --git a/lib/network/modules/components/nodes/shapes/Circle.js b/lib/network/modules/components/nodes/shapes/Circle.js index 4c8afc82fe..f5c189e343 100644 --- a/lib/network/modules/components/nodes/shapes/Circle.js +++ b/lib/network/modules/components/nodes/shapes/Circle.js @@ -26,9 +26,9 @@ class Circle extends CircleImageBase { */ resize(ctx, selected = this.selected, hover = this.hover) { if (this.needsRefresh(selected, hover)) { - var dimensions = this.getDimensionsFromLabel(ctx, selected, hover); + const dimensions = this.getDimensionsFromLabel(ctx, selected, hover); - var diameter = Math.max(dimensions.width + this.margin.right + this.margin.left, + const diameter = Math.max(dimensions.width + this.margin.right + this.margin.left, dimensions.height + this.margin.top + this.margin.bottom); this.options.size = diameter / 2; // NOTE: this size field only set here, not in Ellipse, Database, Box diff --git a/lib/network/modules/components/nodes/shapes/CircularImage.js b/lib/network/modules/components/nodes/shapes/CircularImage.js index 27bed8ed0a..dfd0b1759b 100644 --- a/lib/network/modules/components/nodes/shapes/CircularImage.js +++ b/lib/network/modules/components/nodes/shapes/CircularImage.js @@ -28,12 +28,12 @@ class CircularImage extends CircleImageBase { * @param {boolean} [hover] */ resize(ctx, selected = this.selected, hover = this.hover) { - var imageAbsent = (this.imageObj.src === undefined) || + const imageAbsent = (this.imageObj.src === undefined) || (this.imageObj.width === undefined) || (this.imageObj.height === undefined); if (imageAbsent) { - var diameter = this.options.size * 2; + const diameter = this.options.size * 2; this.width = diameter; this.height = diameter; this.radius = 0.5*this.width; diff --git a/lib/network/modules/components/nodes/shapes/Database.js b/lib/network/modules/components/nodes/shapes/Database.js index 47c7e2629d..eff7ba5d7c 100644 --- a/lib/network/modules/components/nodes/shapes/Database.js +++ b/lib/network/modules/components/nodes/shapes/Database.js @@ -27,8 +27,8 @@ class Database extends NodeBase { */ resize(ctx, selected, hover) { if (this.needsRefresh(selected, hover)) { - var dimensions = this.getDimensionsFromLabel(ctx, selected, hover); - var size = dimensions.width + this.margin.right + this.margin.left; + const dimensions = this.getDimensionsFromLabel(ctx, selected, hover); + const size = dimensions.width + this.margin.right + this.margin.left; this.width = size; this.height = size; diff --git a/lib/network/modules/components/nodes/shapes/Ellipse.js b/lib/network/modules/components/nodes/shapes/Ellipse.js index 93af9e960a..d0b93341a1 100644 --- a/lib/network/modules/components/nodes/shapes/Ellipse.js +++ b/lib/network/modules/components/nodes/shapes/Ellipse.js @@ -26,7 +26,7 @@ class Ellipse extends NodeBase { */ resize(ctx, selected = this.selected, hover = this.hover) { if (this.needsRefresh(selected, hover)) { - var dimensions = this.getDimensionsFromLabel(ctx, selected, hover); + const dimensions = this.getDimensionsFromLabel(ctx, selected, hover); this.height = dimensions.height * 2; this.width = dimensions.width + dimensions.height; @@ -66,10 +66,10 @@ class Ellipse extends NodeBase { if (ctx) { this.resize(ctx); } - var a = this.width * 0.5; - var b = this.height * 0.5; - var w = (Math.sin(angle) * a); - var h = (Math.cos(angle) * b); + const a = this.width * 0.5; + const b = this.height * 0.5; + const w = (Math.sin(angle) * a); + const h = (Math.cos(angle) * b); return a * b / Math.sqrt(w * w + h * h); } } diff --git a/lib/network/modules/components/nodes/shapes/Icon.js b/lib/network/modules/components/nodes/shapes/Icon.js index b596512132..1f3a9fa00c 100644 --- a/lib/network/modules/components/nodes/shapes/Icon.js +++ b/lib/network/modules/components/nodes/shapes/Icon.js @@ -54,7 +54,7 @@ class Icon extends NodeBase { this._icon(ctx, x, y, selected, hover, values); if (this.options.label !== undefined) { - var iconTextSpacing = 5; + const iconTextSpacing = 5; this.labelModule.draw(ctx, this.left + this.iconSize.width / 2 + this.margin.left, y + this.height / 2 + iconTextSpacing, selected); } @@ -74,7 +74,7 @@ class Icon extends NodeBase { this.boundingBox.bottom = y + this.options.icon.size * 0.5; if (this.options.label !== undefined && this.labelModule.size.width > 0) { - var iconTextSpacing = 5; + const iconTextSpacing = 5; this.boundingBox.left = Math.min(this.boundingBox.left, this.labelModule.size.left); this.boundingBox.right = Math.max(this.boundingBox.right, this.labelModule.size.left + this.labelModule.size.width); this.boundingBox.bottom = Math.max(this.boundingBox.bottom, this.boundingBox.bottom + this.labelModule.size.height + iconTextSpacing); @@ -91,7 +91,7 @@ class Icon extends NodeBase { * @param {ArrowOptions} values */ _icon(ctx, x, y, selected, hover, values) { - let iconSize = Number(this.options.icon.size); + const iconSize = Number(this.options.icon.size); if (this.options.icon.code !== undefined) { ctx.font = [ diff --git a/lib/network/modules/components/nodes/shapes/Image.js b/lib/network/modules/components/nodes/shapes/Image.js index ef5a2a6440..93cd7bdc3b 100644 --- a/lib/network/modules/components/nodes/shapes/Image.js +++ b/lib/network/modules/components/nodes/shapes/Image.js @@ -29,12 +29,12 @@ class Image extends CircleImageBase { * @param {boolean} [hover] */ resize(ctx, selected = this.selected, hover = this.hover) { - var imageAbsent = (this.imageObj.src === undefined) || + const imageAbsent = (this.imageObj.src === undefined) || (this.imageObj.width === undefined) || (this.imageObj.height === undefined); if (imageAbsent) { - var side = this.options.size * 2; + const side = this.options.size * 2; this.width = side; this.height = side; return; @@ -73,9 +73,9 @@ class Image extends CircleImageBase { } if (this.options.shapeProperties.useBorderWithImage === true) { - var neutralborderWidth = this.options.borderWidth; - var selectionLineWidth = this.options.borderWidthSelected || 2 * this.options.borderWidth; - var borderWidth = (selected ? selectionLineWidth : neutralborderWidth) / this.body.view.scale; + const neutralborderWidth = this.options.borderWidth; + const selectionLineWidth = this.options.borderWidthSelected || 2 * this.options.borderWidth; + const borderWidth = (selected ? selectionLineWidth : neutralborderWidth) / this.body.view.scale; ctx.lineWidth = Math.min(this.width, borderWidth); ctx.beginPath(); diff --git a/lib/network/modules/components/nodes/util/CircleImageBase.js b/lib/network/modules/components/nodes/util/CircleImageBase.js index d5077c48f7..0545a8129d 100644 --- a/lib/network/modules/components/nodes/util/CircleImageBase.js +++ b/lib/network/modules/components/nodes/util/CircleImageBase.js @@ -73,11 +73,11 @@ class CircleImageBase extends NodeBase { * @param {boolean} selected value of new selected state for current node */ switchImages(selected) { - var selection_changed = ((selected && !this.selected) || (!selected && this.selected)); + const selection_changed = ((selected && !this.selected) || (!selected && this.selected)); this.selected = selected; // Remember new selection if (this.imageObjAlt !== undefined && selection_changed) { - let imageTmp = this.imageObj; + const imageTmp = this.imageObj; this.imageObj = this.imageObjAlt; this.imageObjAlt = imageTmp; } @@ -90,9 +90,9 @@ class CircleImageBase extends NodeBase { * @private */ _getImagePadding() { - var imgPadding = { top: 0, right: 0, bottom: 0, left: 0} + const imgPadding = { top: 0, right: 0, bottom: 0, left: 0} if (this.options.imagePadding) { - var optImgPadding = this.options.imagePadding + const optImgPadding = this.options.imagePadding if (typeof optImgPadding == 'object') { imgPadding.top = optImgPadding.top; imgPadding.right = optImgPadding.right; @@ -115,12 +115,12 @@ class CircleImageBase extends NodeBase { * Pre: this.imageObj is valid */ _resizeImage() { - var width, height; + let width, height; if (this.options.shapeProperties.useImageSize === false) { // Use the size property - var ratio_width = 1; - var ratio_height = 1; + let ratio_width = 1; + let ratio_height = 1; // Only calculate the proper ratio if both width and height not zero if (this.imageObj.width && this.imageObj.height) { @@ -137,7 +137,7 @@ class CircleImageBase extends NodeBase { } else { // Use the image size with image padding - var imgPadding = this._getImagePadding() + const imgPadding = this._getImagePadding() width = this.imageObj.width + imgPadding.left + imgPadding.right; height = this.imageObj.height + imgPadding.top + imgPadding.bottom; } @@ -180,12 +180,12 @@ class CircleImageBase extends NodeBase { factor = (this.imageObj.width / this.width) / this.body.view.scale; } - var imgPadding = this._getImagePadding() + const imgPadding = this._getImagePadding() - var imgPosLeft = this.left + imgPadding.left - var imgPosTop = this.top + imgPadding.top - var imgWidth = this.width - imgPadding.left - imgPadding.right - var imgHeight = this.height - imgPadding.top - imgPadding.bottom + const imgPosLeft = this.left + imgPadding.left + const imgPosTop = this.top + imgPadding.top + const imgWidth = this.width - imgPadding.left - imgPadding.right + const imgHeight = this.height - imgPadding.top - imgPadding.bottom this.imageObj.drawImageAtPosition(ctx, factor, imgPosLeft, imgPosTop, imgWidth, imgHeight); // disable shadows for other elements. @@ -203,18 +203,17 @@ class CircleImageBase extends NodeBase { * @private */ _drawImageLabel(ctx, x, y, selected, hover) { - var yLabel; - var offset = 0; + let offset = 0; if (this.height !== undefined) { offset = this.height * 0.5; - var labelDimensions = this.labelModule.getTextSize(ctx, selected, hover); + const labelDimensions = this.labelModule.getTextSize(ctx, selected, hover); if (labelDimensions.lineCount >= 1) { offset += labelDimensions.height / 2; } } - yLabel = y + offset; + const yLabel = y + offset; if (this.options.label) { this.labelOffset = offset; diff --git a/lib/network/modules/components/nodes/util/NodeBase.js b/lib/network/modules/components/nodes/util/NodeBase.js index ab1ba64f03..9564cb4bd3 100644 --- a/lib/network/modules/components/nodes/util/NodeBase.js +++ b/lib/network/modules/components/nodes/util/NodeBase.js @@ -60,7 +60,7 @@ class NodeBase { * @private */ _distanceToBorder(ctx,angle) { - var borderWidth = this.options.borderWidth; + const borderWidth = this.options.borderWidth; if (ctx){ this.resize(ctx); } @@ -162,7 +162,7 @@ class NodeBase { * @param {ArrowOptions} values */ initContextForDraw(ctx, values) { - var borderWidth = values.borderWidth / this.body.view.scale; + const borderWidth = values.borderWidth / this.body.view.scale; ctx.lineWidth = Math.min(this.width, borderWidth); ctx.strokeStyle = values.borderColor; @@ -175,7 +175,7 @@ class NodeBase { * @param {ArrowOptions} values */ performStroke(ctx, values) { - var borderWidth = values.borderWidth / this.body.view.scale; + const borderWidth = values.borderWidth / this.body.view.scale; //draw dashed border if enabled, save and restore is required for firefox not to crash on unix. ctx.save(); @@ -283,8 +283,8 @@ class NodeBase { // NOTE: previously 'textSize' was not put in 'this' for Ellipse // TODO: examine the consequences. this.textSize = this.labelModule.getTextSize(ctx, selected, hover); - var width = this.textSize.width; - var height = this.textSize.height; + let width = this.textSize.width; + let height = this.textSize.height; const DEFAULT_SIZE = 14; if (width === 0) { diff --git a/lib/network/modules/components/nodes/util/ShapeBase.js b/lib/network/modules/components/nodes/util/ShapeBase.js index a7496caa41..7a5a3d2acc 100644 --- a/lib/network/modules/components/nodes/util/ShapeBase.js +++ b/lib/network/modules/components/nodes/util/ShapeBase.js @@ -26,7 +26,7 @@ class ShapeBase extends NodeBase { resize(ctx, selected = this.selected, hover = this.hover, values = { size: this.options.size }) { if (this.needsRefresh(selected, hover)) { this.labelModule.getTextSize(ctx, selected, hover); - var size = 2 * values.size; + const size = 2 * values.size; this.width = size; this.height = size; this.radius = 0.5*this.width; @@ -76,7 +76,7 @@ class ShapeBase extends NodeBase { if (this.options.label !== undefined) { // Need to call following here in order to ensure value for `this.labelModule.size.height` this.labelModule.calculateLabelSize(ctx, selected, hover, x, y, 'hanging') - let yLabel = y + 0.5 * this.height + 0.5 * this.labelModule.size.height; + const yLabel = y + 0.5 * this.height + 0.5 * this.labelModule.size.height; this.labelModule.draw(ctx, x, yLabel, selected, hover, 'hanging'); } diff --git a/lib/network/modules/components/physics/BarnesHutSolver.js b/lib/network/modules/components/physics/BarnesHutSolver.js index d06809263e..8c4b16dfd8 100644 --- a/lib/network/modules/components/physics/BarnesHutSolver.js +++ b/lib/network/modules/components/physics/BarnesHutSolver.js @@ -41,12 +41,12 @@ class BarnesHutSolver { solve() { if (this.options.gravitationalConstant !== 0 && this.physicsBody.physicsNodeIndices.length > 0) { let node; - let nodes = this.body.nodes; - let nodeIndices = this.physicsBody.physicsNodeIndices; - let nodeCount = nodeIndices.length; + const nodes = this.body.nodes; + const nodeIndices = this.physicsBody.physicsNodeIndices; + const nodeCount = nodeIndices.length; // create the tree - let barnesHutTree = this._formBarnesHutTree(nodes, nodeIndices); + const barnesHutTree = this._formBarnesHutTree(nodes, nodeIndices); // for debugging this.barnesHutTree = barnesHutTree; @@ -87,12 +87,10 @@ class BarnesHutSolver { _getForceContribution(parentBranch, node) { // we get no force contribution from an empty region if (parentBranch.childrenCount > 0) { - let dx, dy, distance; - // get the distance from the center of mass to the node. - dx = parentBranch.centerOfMass.x - node.x; - dy = parentBranch.centerOfMass.y - node.y; - distance = Math.sqrt(dx * dx + dy * dy); + const dx = parentBranch.centerOfMass.x - node.x; + const dy = parentBranch.centerOfMass.y - node.y; + const distance = Math.sqrt(dx * dx + dy * dy); // BarnesHutSolver condition // original condition : s/d < theta = passed === d/s > 1/theta = passed @@ -137,9 +135,9 @@ class BarnesHutSolver { // the dividing by the distance cubed instead of squared allows us to get the fx and fy components without sines and cosines // it is shorthand for gravityforce with distance squared and fx = dx/distance * gravityForce - let gravityForce = this.options.gravitationalConstant * parentBranch.mass * node.options.mass / Math.pow(distance,3); - let fx = dx * gravityForce; - let fy = dy * gravityForce; + const gravityForce = this.options.gravitationalConstant * parentBranch.mass * node.options.mass / Math.pow(distance,3); + const fx = dx * gravityForce; + const fy = dy * gravityForce; this.physicsBody.forces[node.id].x += fx; this.physicsBody.forces[node.id].y += fy; @@ -156,7 +154,7 @@ class BarnesHutSolver { */ _formBarnesHutTree(nodes, nodeIndices) { let node; - let nodeCount = nodeIndices.length; + const nodeCount = nodeIndices.length; let minX = nodes[nodeIndices[0]].x; let minY = nodes[nodeIndices[0]].y; @@ -165,9 +163,9 @@ class BarnesHutSolver { // get the range of the nodes for (let i = 1; i < nodeCount; i++) { - let node = nodes[nodeIndices[i]]; - let x = node.x; - let y = node.y; + const node = nodes[nodeIndices[i]]; + const x = node.x; + const y = node.y; if (node.options.mass > 0) { if (x < minX) { minX = x; @@ -184,7 +182,7 @@ class BarnesHutSolver { } } // make the range a square - let sizeDiff = Math.abs(maxX - minX) - Math.abs(maxY - minY); // difference between X and Y + const sizeDiff = Math.abs(maxX - minX) - Math.abs(maxY - minY); // difference between X and Y if (sizeDiff > 0) { minY -= 0.5 * sizeDiff; maxY += 0.5 * sizeDiff; @@ -195,13 +193,13 @@ class BarnesHutSolver { } // xSize < ySize - let minimumTreeSize = 1e-5; - let rootSize = Math.max(minimumTreeSize, Math.abs(maxX - minX)); - let halfRootSize = 0.5 * rootSize; - let centerX = 0.5 * (minX + maxX), centerY = 0.5 * (minY + maxY); + const minimumTreeSize = 1e-5; + const rootSize = Math.max(minimumTreeSize, Math.abs(maxX - minX)); + const halfRootSize = 0.5 * rootSize; + const centerX = 0.5 * (minX + maxX), centerY = 0.5 * (minY + maxY); // construct the barnesHutTree - let barnesHutTree = { + const barnesHutTree = { root: { centerOfMass: {x: 0, y: 0}, mass: 0, @@ -240,9 +238,9 @@ class BarnesHutSolver { * @private */ _updateBranchMass(parentBranch, node) { - let centerOfMass = parentBranch.centerOfMass; - let totalMass = parentBranch.mass + node.options.mass; - let totalMassInv = 1 / totalMass; + const centerOfMass = parentBranch.centerOfMass; + const totalMass = parentBranch.mass + node.options.mass; + const totalMassInv = 1 / totalMass; centerOfMass.x = centerOfMass.x * parentBranch.mass + node.x * node.options.mass; centerOfMass.x *= totalMassInv; @@ -251,7 +249,7 @@ class BarnesHutSolver { centerOfMass.y *= totalMassInv; parentBranch.mass = totalMass; - let biggestSize = Math.max(Math.max(node.height, node.radius), node.width); + const biggestSize = Math.max(Math.max(node.height, node.radius), node.width); parentBranch.maxWidth = (parentBranch.maxWidth < biggestSize) ? biggestSize : parentBranch.maxWidth; } @@ -271,7 +269,7 @@ class BarnesHutSolver { this._updateBranchMass(parentBranch, node); } - let range = parentBranch.children.NW.range; + const range = parentBranch.children.NW.range; let region; if (range.maxX > node.x) { // in NW or SW if (range.maxY > node.y) { @@ -303,7 +301,7 @@ class BarnesHutSolver { * @private */ _placeInRegion(parentBranch, node, region) { - let children = parentBranch.children[region]; + const children = parentBranch.children[region]; switch (children.childrenCount) { case 0: // place node here @@ -370,7 +368,7 @@ class BarnesHutSolver { */ _insertRegion(parentBranch, region) { let minX, maxX, minY, maxY; - let childSize = 0.5 * parentBranch.size; + const childSize = 0.5 * parentBranch.size; switch (region) { case "NW": minX = parentBranch.range.minX; diff --git a/lib/network/modules/components/physics/CentralGravitySolver.js b/lib/network/modules/components/physics/CentralGravitySolver.js index ec914d0150..d94c5f8141 100644 --- a/lib/network/modules/components/physics/CentralGravitySolver.js +++ b/lib/network/modules/components/physics/CentralGravitySolver.js @@ -26,12 +26,12 @@ class CentralGravitySolver { */ solve() { let dx, dy, distance, node; - let nodes = this.body.nodes; - let nodeIndices = this.physicsBody.physicsNodeIndices; - let forces = this.physicsBody.forces; + const nodes = this.body.nodes; + const nodeIndices = this.physicsBody.physicsNodeIndices; + const forces = this.physicsBody.forces; for (let i = 0; i < nodeIndices.length; i++) { - let nodeId = nodeIndices[i]; + const nodeId = nodeIndices[i]; node = nodes[nodeId]; dx = -node.x; dy = -node.y; @@ -51,7 +51,7 @@ class CentralGravitySolver { * @private */ _calculateForces(distance, dx, dy, forces, node) { - let gravityForce = (distance === 0) ? 0 : (this.options.centralGravity / distance); + const gravityForce = (distance === 0) ? 0 : (this.options.centralGravity / distance); forces[node.id].x = dx * gravityForce; forces[node.id].y = dy * gravityForce; } diff --git a/lib/network/modules/components/physics/FA2BasedCentralGravitySolver.js b/lib/network/modules/components/physics/FA2BasedCentralGravitySolver.js index 7c708669a7..d04b8c2b8a 100644 --- a/lib/network/modules/components/physics/FA2BasedCentralGravitySolver.js +++ b/lib/network/modules/components/physics/FA2BasedCentralGravitySolver.js @@ -26,8 +26,8 @@ class ForceAtlas2BasedCentralGravitySolver extends CentralGravitySolver { */ _calculateForces(distance, dx, dy, forces, node) { if (distance > 0) { - let degree = (node.edges.length + 1); - let gravityForce = this.options.centralGravity * degree * node.options.mass; + const degree = (node.edges.length + 1); + const gravityForce = this.options.centralGravity * degree * node.options.mass; forces[node.id].x = dx * gravityForce; forces[node.id].y = dy * gravityForce; } diff --git a/lib/network/modules/components/physics/FA2BasedRepulsionSolver.js b/lib/network/modules/components/physics/FA2BasedRepulsionSolver.js index e4539c7fe9..aeac81c21f 100644 --- a/lib/network/modules/components/physics/FA2BasedRepulsionSolver.js +++ b/lib/network/modules/components/physics/FA2BasedRepulsionSolver.js @@ -36,12 +36,12 @@ class ForceAtlas2BasedRepulsionSolver extends BarnesHutSolver { distance = Math.max(0.1 + (this.overlapAvoidanceFactor * node.shape.radius), distance - node.shape.radius); } - let degree = (node.edges.length + 1); + const degree = (node.edges.length + 1); // the dividing by the distance cubed instead of squared allows us to get the fx and fy components without sines and cosines // it is shorthand for gravityforce with distance squared and fx = dx/distance * gravityForce - let gravityForce = this.options.gravitationalConstant * parentBranch.mass * node.options.mass * degree / Math.pow(distance,2); - let fx = dx * gravityForce; - let fy = dy * gravityForce; + const gravityForce = this.options.gravitationalConstant * parentBranch.mass * node.options.mass * degree / Math.pow(distance,2); + const fx = dx * gravityForce; + const fy = dy * gravityForce; this.physicsBody.forces[node.id].x += fx; this.physicsBody.forces[node.id].y += fy; diff --git a/lib/network/modules/components/physics/HierarchicalRepulsionSolver.js b/lib/network/modules/components/physics/HierarchicalRepulsionSolver.js index 644f810e1f..3c84881f12 100644 --- a/lib/network/modules/components/physics/HierarchicalRepulsionSolver.js +++ b/lib/network/modules/components/physics/HierarchicalRepulsionSolver.js @@ -32,12 +32,12 @@ class HierarchicalRepulsionSolver { * @private */ solve() { - var nodes = this.body.nodes; - var nodeIndices = this.physicsBody.physicsNodeIndices; - var forces = this.physicsBody.forces; + const nodes = this.body.nodes; + const nodeIndices = this.physicsBody.physicsNodeIndices; + const forces = this.physicsBody.forces; // repulsing forces between nodes - var nodeDistance = this.options.nodeDistance; + const nodeDistance = this.options.nodeDistance; // we loop from i over all but the last entree in the array // j loops from i+1 to the last. This way we do not double count any of the indices, nor i === j diff --git a/lib/network/modules/components/physics/HierarchicalSpringSolver.js b/lib/network/modules/components/physics/HierarchicalSpringSolver.js index ad444c0954..58f607f374 100644 --- a/lib/network/modules/components/physics/HierarchicalSpringSolver.js +++ b/lib/network/modules/components/physics/HierarchicalSpringSolver.js @@ -27,18 +27,18 @@ class HierarchicalSpringSolver { * @private */ solve() { - var edgeLength, edge; - var dx, dy, fx, fy, springForce, distance; - var edges = this.body.edges; - var factor = 0.5; + let edgeLength, edge; + let dx, dy, fx, fy, springForce, distance; + const edges = this.body.edges; + const factor = 0.5; - var edgeIndices = this.physicsBody.physicsEdgeIndices; - var nodeIndices = this.physicsBody.physicsNodeIndices; - var forces = this.physicsBody.forces; + const edgeIndices = this.physicsBody.physicsEdgeIndices; + const nodeIndices = this.physicsBody.physicsNodeIndices; + const forces = this.physicsBody.forces; // initialize the spring force counters for (let i = 0; i < nodeIndices.length; i++) { - let nodeId = nodeIndices[i]; + const nodeId = nodeIndices[i]; forces[nodeId].springFx = 0; forces[nodeId].springFy = 0; } @@ -86,9 +86,9 @@ class HierarchicalSpringSolver { // normalize spring forces springForce = 1; - var springFx, springFy; + let springFx, springFy; for (let i = 0; i < nodeIndices.length; i++) { - let nodeId = nodeIndices[i]; + const nodeId = nodeIndices[i]; springFx = Math.min(springForce,Math.max(-springForce,forces[nodeId].springFx)); springFy = Math.min(springForce,Math.max(-springForce,forces[nodeId].springFy)); @@ -97,18 +97,18 @@ class HierarchicalSpringSolver { } // retain energy balance - var totalFx = 0; - var totalFy = 0; + let totalFx = 0; + let totalFy = 0; for (let i = 0; i < nodeIndices.length; i++) { - let nodeId = nodeIndices[i]; + const nodeId = nodeIndices[i]; totalFx += forces[nodeId].x; totalFy += forces[nodeId].y; } - var correctionFx = totalFx / nodeIndices.length; - var correctionFy = totalFy / nodeIndices.length; + const correctionFx = totalFx / nodeIndices.length; + const correctionFy = totalFy / nodeIndices.length; for (let i = 0; i < nodeIndices.length; i++) { - let nodeId = nodeIndices[i]; + const nodeId = nodeIndices[i]; forces[nodeId].x -= correctionFx; forces[nodeId].y -= correctionFy; } diff --git a/lib/network/modules/components/physics/RepulsionSolver.js b/lib/network/modules/components/physics/RepulsionSolver.js index bd994e18d4..39ea699b95 100644 --- a/lib/network/modules/components/physics/RepulsionSolver.js +++ b/lib/network/modules/components/physics/RepulsionSolver.js @@ -32,18 +32,18 @@ class RepulsionSolver { * @private */ solve() { - var dx, dy, distance, fx, fy, repulsingForce, node1, node2; + let dx, dy, distance, fx, fy, repulsingForce, node1, node2; - var nodes = this.body.nodes; - var nodeIndices = this.physicsBody.physicsNodeIndices; - var forces = this.physicsBody.forces; + const nodes = this.body.nodes; + const nodeIndices = this.physicsBody.physicsNodeIndices; + const forces = this.physicsBody.forces; // repulsing forces between nodes - var nodeDistance = this.options.nodeDistance; + const nodeDistance = this.options.nodeDistance; // approximation constants - var a = (-2 / 3) / nodeDistance; - var b = 4 / 3; + const a = (-2 / 3) / nodeDistance; + const b = 4 / 3; // we loop from i over all but the last entree in the array // j loops from i+1 to the last. This way we do not double count any of the indices, nor i === j diff --git a/lib/network/modules/components/physics/SpringSolver.js b/lib/network/modules/components/physics/SpringSolver.js index eb011e2a38..829bc51a2e 100644 --- a/lib/network/modules/components/physics/SpringSolver.js +++ b/lib/network/modules/components/physics/SpringSolver.js @@ -28,8 +28,8 @@ class SpringSolver { */ solve() { let edgeLength, edge; - let edgeIndices = this.physicsBody.physicsEdgeIndices; - let edges = this.body.edges; + const edgeIndices = this.physicsBody.physicsEdgeIndices; + const edges = this.body.edges; let node1, node2, node3; // forces caused by the edges, modelled as springs @@ -68,15 +68,15 @@ class SpringSolver { * @private */ _calculateSpringForce(node1, node2, edgeLength) { - let dx = (node1.x - node2.x); - let dy = (node1.y - node2.y); - let distance = Math.max(Math.sqrt(dx * dx + dy * dy),0.01); + const dx = (node1.x - node2.x); + const dy = (node1.y - node2.y); + const distance = Math.max(Math.sqrt(dx * dx + dy * dy),0.01); // the 1/distance is so the fx and fy can be calculated without sine or cosine. - let springForce = this.options.springConstant * (edgeLength - distance) / distance; + const springForce = this.options.springConstant * (edgeLength - distance) / distance; - let fx = dx * springForce; - let fy = dy * springForce; + const fx = dx * springForce; + const fy = dy * springForce; // handle the case where one node is not part of the physcis if (this.physicsBody.forces[node1.id] !== undefined) { diff --git a/lib/network/modules/components/shared/ComponentUtil.js b/lib/network/modules/components/shared/ComponentUtil.js index 05fd6840b9..ad9aa50daf 100644 --- a/lib/network/modules/components/shared/ComponentUtil.js +++ b/lib/network/modules/components/shared/ComponentUtil.js @@ -28,10 +28,10 @@ import { topMost } from 'vis-util/esnext'; */ export function choosify(subOption, pile) { // allowed values for subOption - let allowed = [ 'node', 'edge', 'label']; + const allowed = [ 'node', 'edge', 'label']; let value = true; - let chosen = topMost(pile, 'chosen'); + const chosen = topMost(pile, 'chosen'); if (typeof chosen === 'boolean') { value = chosen; } else if (typeof chosen === 'object') { @@ -40,7 +40,7 @@ import { topMost } from 'vis-util/esnext'; + "'" + allowed.join("', '") + "'"); } - let chosenEdge = topMost(pile, ['chosen', subOption]); + const chosenEdge = topMost(pile, ['chosen', subOption]); if ((typeof chosenEdge === 'boolean') || (typeof chosenEdge === 'function')) { value = chosenEdge; } @@ -65,7 +65,7 @@ import { topMost } from 'vis-util/esnext'; if (rotationPoint !== undefined) { // Rotate the point the same amount as the rectangle - var tmp = { + const tmp = { x: point.x - rotationPoint.x, y: point.y - rotationPoint.y }; @@ -73,9 +73,9 @@ import { topMost } from 'vis-util/esnext'; if (rotationPoint.angle !== 0) { // In order to get the coordinates the same, you need to // rotate in the reverse direction - var angle = -rotationPoint.angle; + const angle = -rotationPoint.angle; - var tmp2 = { + const tmp2 = { x: Math.cos(angle)*tmp.x - Math.sin(angle)*tmp.y, y: Math.sin(angle)*tmp.x + Math.cos(angle)*tmp.y }; @@ -90,8 +90,8 @@ import { topMost } from 'vis-util/esnext'; // back in this case. } - var right = rect.x + rect.width; - var bottom = rect.y + rect.width; + const right = rect.x + rect.width; + const bottom = rect.y + rect.width; return ( rect.left < point.x && @@ -119,7 +119,8 @@ import { topMost } from 'vis-util/esnext'; * @param {Object} ctx * @param {number} angle * @param {number} radius - * @return {Object} node + * @param {VisNode} node + * * @returns {Object} x and y coordinates */ export function getSelfRefCoordinates(ctx, angle, radius, node){ diff --git a/lib/network/modules/components/shared/Label.js b/lib/network/modules/components/shared/Label.js index 6ad84a868d..32a42e1cbb 100644 --- a/lib/network/modules/components/shared/Label.js +++ b/lib/network/modules/components/shared/Label.js @@ -56,7 +56,7 @@ class Label { this.baseSize = this.fontOptions.size; } else if (typeof options.font === 'object') { - let size = options.font.size; + const size = options.font.size; if (size !== undefined) { this.baseSize = size; @@ -111,7 +111,7 @@ class Label { static parseFontString(outOptions, inOptions) { if (!inOptions || typeof inOptions !== 'string') return false; - let newOptionsArray = inOptions.split(" "); + const newOptionsArray = inOptions.split(" "); outOptions.size = +newOptionsArray[0].replace("px",''); outOptions.face = newOptionsArray[1]; @@ -132,7 +132,7 @@ class Label { // NOTE: constrainWidth and constrainHeight never set! // NOTE: for edge labels, only 'maxWdt' set // Node labels can set all the fields - let fontOptions = { + const fontOptions = { constrainWidth: false, maxWdt: -1, minWdt: -1, @@ -141,31 +141,31 @@ class Label { valign: 'middle', } - let widthConstraint = topMost(pile, 'widthConstraint'); + const widthConstraint = topMost(pile, 'widthConstraint'); if (typeof widthConstraint === 'number') { fontOptions.maxWdt = Number(widthConstraint); fontOptions.minWdt = Number(widthConstraint); } else if (typeof widthConstraint === 'object') { - let widthConstraintMaximum = topMost(pile, ['widthConstraint', 'maximum']); + const widthConstraintMaximum = topMost(pile, ['widthConstraint', 'maximum']); if (typeof widthConstraintMaximum === 'number') { fontOptions.maxWdt = Number(widthConstraintMaximum); } - let widthConstraintMinimum = topMost(pile, ['widthConstraint', 'minimum']) + const widthConstraintMinimum = topMost(pile, ['widthConstraint', 'minimum']) if (typeof widthConstraintMinimum === 'number') { fontOptions.minWdt = Number(widthConstraintMinimum); } } - let heightConstraint = topMost(pile, 'heightConstraint'); + const heightConstraint = topMost(pile, 'heightConstraint'); if (typeof heightConstraint === 'number') { fontOptions.minHgt = Number(heightConstraint); } else if (typeof heightConstraint === 'object') { - let heightConstraintMinimum = topMost(pile, ['heightConstraint', 'minimum']); + const heightConstraintMinimum = topMost(pile, ['heightConstraint', 'minimum']); if (typeof heightConstraintMinimum === 'number') { fontOptions.minHgt = Number(heightConstraintMinimum); } - let heightConstraintValign = topMost(pile, ['heightConstraint', 'valign']); + const heightConstraintValign = topMost(pile, ['heightConstraint', 'valign']); if (typeof heightConstraintValign === 'string') { if ((heightConstraintValign === 'top')|| (heightConstraintValign === 'bottom')) { fontOptions.valign = heightConstraintValign; @@ -198,12 +198,12 @@ class Label { * @param {{top: number, right: number, bottom: number, left: number}} margins */ adjustSizes(margins) { - let widthBias = (margins) ? (margins.right + margins.left) : 0; + const widthBias = (margins) ? (margins.right + margins.left) : 0; if (this.fontOptions.constrainWidth) { this.fontOptions.maxWdt -= widthBias; this.fontOptions.minWdt -= widthBias; } - let heightBias = (margins) ? (margins.top + margins.bottom) : 0; + const heightBias = (margins) ? (margins.top + margins.bottom) : 0; if (this.fontOptions.constrainHeight) { this.fontOptions.minHgt -= heightBias; } @@ -241,7 +241,7 @@ class Label { if (options === undefined) return; if (options.font === undefined || options.font === null) return; - let item = options.font; + const item = options.font; pile.push(item); } @@ -254,21 +254,21 @@ class Label { * @private */ getBasicOptions(pile) { - let ret = {}; + const ret = {}; // Scans the whole pile to get all options present for (let n = 0; n < pile.length; ++n) { let fontOptions = pile[n]; // Convert shorthand if necessary - let tmpShorthand = {}; + const tmpShorthand = {}; if (Label.parseFontString(tmpShorthand, fontOptions)) { fontOptions = tmpShorthand; } forEach(fontOptions, (opt, name) => { if (opt === undefined) return; // multi-font option need not be present - if (ret.hasOwnProperty(name)) return; // Keep first value we encounter + if (Object.prototype.hasOwnProperty.call(ret, name)) return; // Keep first value we encounter if (multiFontStyle.indexOf(name) !== -1) { // Skip multi-font properties but we do need the structure @@ -315,20 +315,20 @@ class Label { // Search multi font in local properties for (let n = 0; n < pile.length; ++n) { - let fontOptions = pile[n]; + const fontOptions = pile[n]; - if (fontOptions.hasOwnProperty(multiName)) { + if (Object.prototype.hasOwnProperty.call(fontOptions, multiName)) { multiFont = fontOptions[multiName]; if (multiFont === undefined || multiFont === null) continue; // Convert shorthand if necessary // TODO: inefficient to do this conversion every time; find a better way. - let tmpShorthand = {}; + const tmpShorthand = {}; if (Label.parseFontString(tmpShorthand, multiFont)) { multiFont = tmpShorthand; } - if (multiFont.hasOwnProperty(option)) { + if (Object.prototype.hasOwnProperty.call(multiFont, option)) { return multiFont[option]; } } @@ -336,7 +336,7 @@ class Label { // Option is not mentioned in the multi font options; take it from the parent font options. // These have already been converted with getBasicOptions(), so use the converted values. - if (this.fontOptions.hasOwnProperty(option)) { + if (Object.prototype.hasOwnProperty.call(this.fontOptions, option)) { return this.fontOptions[option]; } @@ -356,11 +356,11 @@ class Label { * @private */ getFontOptions(pile, multiName) { - let result = {}; - let optionNames = ['color', 'size', 'face', 'mod', 'vadjust']; // List of allowed options per multi-font + const result = {}; + const optionNames = ['color', 'size', 'face', 'mod', 'vadjust']; // List of allowed options per multi-font for (let i = 0; i < optionNames.length; ++i) { - let mod = optionNames[i]; + const mod = optionNames[i]; result[mod] = this.getFontOption(pile, multiName, mod); } @@ -380,7 +380,7 @@ class Label { * First item in list assumed to be the newly set options. */ propagateFonts(pile) { - let fontPile = []; // sequence of font objects to consider, order important + const fontPile = []; // sequence of font objects to consider, order important // Note that this.elementOptions is not used here. this.addFontOptionsToPile(fontPile, pile); @@ -388,9 +388,9 @@ class Label { // We set multifont values even if multi === false, for consistency (things break otherwise) for (let i = 0; i < multiFontStyle.length; ++i) { - let mod = multiFontStyle[i]; - let modOptions = this.fontOptions[mod]; - let tmpMultiFontOptions = this.getFontOptions(fontPile, mod); + const mod = multiFontStyle[i]; + const modOptions = this.fontOptions[mod]; + const tmpMultiFontOptions = this.getFontOptions(fontPile, mod); // Copy over found values forEach(tmpMultiFontOptions, (option, n) => { @@ -443,7 +443,7 @@ class Label { _drawBackground(ctx) { if (this.fontOptions.background !== undefined && this.fontOptions.background !== "none") { ctx.fillStyle = this.fontOptions.background; - let size = this.getSize(); + const size = this.getSize(); ctx.fillRect(size.left, size.top, size.width, size.height); } } @@ -474,7 +474,7 @@ class Label { // draw the text for (let i = 0; i < this.lineCount; i++) { - let line = this.lines[i]; + const line = this.lines[i]; if (line && line.blocks) { let width = 0; if (this.isEdgeLabel || this.fontOptions.align === 'center') { @@ -483,9 +483,9 @@ class Label { width += (this.size.width - line.width) } for (let j = 0; j < line.blocks.length; j++) { - let block = line.blocks[j]; + const block = line.blocks[j]; ctx.font = block.font; - let [fontColor, strokeColor] = this._getColor(block.color, viewFontSize, block.strokeColor); + const [fontColor, strokeColor] = this._getColor(block.color, viewFontSize, block.strokeColor); if (block.strokeWidth > 0) { ctx.lineWidth = block.strokeWidth; ctx.strokeStyle = strokeColor; @@ -520,7 +520,7 @@ class Label { x = 0; y = 0; - let lineMargin = 2; + const lineMargin = 2; if (this.fontOptions.align === 'top') { ctx.textBaseline = 'alphabetic'; y -= 2 * lineMargin; // distance from edge, required because we use alphabetic. Alphabetic has less difference between browsers @@ -553,7 +553,7 @@ class Label { let fontColor = color || '#000000'; let strokeColor = initialStrokeColor || '#ffffff'; if (viewFontSize <= this.elementOptions.scaling.label.drawThreshold) { - let opacity = Math.max(0, Math.min(1, 1 - (this.elementOptions.scaling.label.drawThreshold - viewFontSize))); + const opacity = Math.max(0, Math.min(1, 1 - (this.elementOptions.scaling.label.drawThreshold - viewFontSize))); fontColor = overrideOpacity(fontColor, opacity); strokeColor = overrideOpacity(strokeColor, opacity); } @@ -583,7 +583,7 @@ class Label { * @return {rect} */ getSize() { - let lineMargin = 2; + const lineMargin = 2; let x = this.size.left; // default values which might be overridden below let y = this.size.top - 0.5*lineMargin; // idem @@ -606,7 +606,7 @@ class Label { } } - var ret = { + const ret = { left : x, top : y, width : this.size.width, @@ -648,7 +648,7 @@ class Label { * @returns {{color, size, face, mod, vadjust, strokeWidth: *, strokeColor: (*|string|allOptions.edges.font.strokeColor|{string}|allOptions.nodes.font.strokeColor|Array)}} */ getFormattingValues(ctx, selected, hover, mod) { - let getValue = function(fontOptions, mod, option) { + const getValue = function(fontOptions, mod, option) { if (mod === "normal") { if (option === 'mod' ) return ""; return fontOptions[option]; @@ -662,7 +662,7 @@ class Label { } }; - let values = { + const values = { color : getValue(this.fontOptions, mod, 'color' ), size : getValue(this.fontOptions, mod, 'size' ), face : getValue(this.fontOptions, mod, 'face' ), @@ -716,7 +716,7 @@ class Label { * @private */ _processLabelText(ctx, selected, hover, inText) { - let splitter = new LabelSplitter(ctx, this, selected, hover); + const splitter = new LabelSplitter(ctx, this, selected, hover); return splitter.process(inText); } @@ -733,7 +733,7 @@ class Label { if(this.labelDirty === false && !this.differentState(selected,hover)) return; - let state = this._processLabelText(ctx, selected, hover, this.elementOptions.label); + const state = this._processLabelText(ctx, selected, hover, this.elementOptions.label); if ((this.fontOptions.minWdt > 0) && (state.width < this.fontOptions.minWdt)) { state.width = this.fontOptions.minWdt; @@ -766,7 +766,7 @@ class Label { return false; // nothing to display } - let viewFontSize = this.fontOptions.size * this.body.view.scale; + const viewFontSize = this.fontOptions.size * this.body.view.scale; if (viewFontSize < this.elementOptions.scaling.label.drawThreshold - 1) { return false; // Too small or too far away to show } diff --git a/lib/network/modules/components/shared/LabelAccumulator.js b/lib/network/modules/components/shared/LabelAccumulator.js index 5a05769a44..ae81f91de0 100644 --- a/lib/network/modules/components/shared/LabelAccumulator.js +++ b/lib/network/modules/components/shared/LabelAccumulator.js @@ -54,8 +54,8 @@ class LabelAccumulator { if (text === undefined || text === "") tmpText = " "; // Determine width and get the font properties - let result = this.measureText(tmpText, mod); - let block = Object.assign({}, result.values); + const result = this.measureText(tmpText, mod); + const block = Object.assign({}, result.values); block.text = text; block.width = result.width; block.mod = mod; @@ -77,7 +77,7 @@ class LabelAccumulator { * @returns {number} */ curWidth() { - let line = this.lines[this.current]; + const line = this.lines[this.current]; if (line === undefined) return 0; return line.width; @@ -116,14 +116,14 @@ class LabelAccumulator { */ determineLineHeights() { for (let k = 0; k < this.lines.length; k++) { - let line = this.lines[k]; + const line = this.lines[k]; // Looking for max height of blocks in line let height = 0; if (line.blocks !== undefined) { // Can happen if text contains e.g. '\n ' for (let l = 0; l < line.blocks.length; l++) { - let block = line.blocks[l]; + const block = line.blocks[l]; if (height < block.height) { height = block.height; @@ -145,7 +145,7 @@ class LabelAccumulator { let width = 0; let height = 0; for (let k = 0; k < this.lines.length; k++) { - let line = this.lines[k]; + const line = this.lines[k]; if (line.width > width) { width = line.width; @@ -168,9 +168,9 @@ class LabelAccumulator { * @private */ removeEmptyBlocks() { - let tmpLines = []; + const tmpLines = []; for (let k = 0; k < this.lines.length; k++) { - let line = this.lines[k]; + const line = this.lines[k]; // Note: an empty line in between text has width zero but is still relevant to layout. // So we can't use width for testing empty line here @@ -181,14 +181,14 @@ class LabelAccumulator { if (line.width === 0) continue; } - let tmpLine = {}; + const tmpLine = {}; Object.assign(tmpLine, line); tmpLine.blocks = []; let firstEmptyBlock; - let tmpBlocks = [] + const tmpBlocks = [] for (let l = 0; l < line.blocks.length; l++) { - let block = line.blocks[l]; + const block = line.blocks[l]; if (block.width !== 0) { tmpBlocks.push(block); } else { @@ -222,7 +222,7 @@ class LabelAccumulator { this.determineLineHeights(); this.determineLabelSize(); - let tmpLines = this.removeEmptyBlocks(); + const tmpLines = this.removeEmptyBlocks(); // Return a simple hash object for further processing. diff --git a/lib/network/modules/components/shared/LabelSplitter.js b/lib/network/modules/components/shared/LabelSplitter.js index 2e6a079394..e4a3cce3eb 100644 --- a/lib/network/modules/components/shared/LabelSplitter.js +++ b/lib/network/modules/components/shared/LabelSplitter.js @@ -2,7 +2,7 @@ import LabelAccumulator from './LabelAccumulator'; import { isValidLabel } from './ComponentUtil'; // Hash of prepared regexp's for tags -var tagPattern = { +const tagPattern = { // HTML '': //, '': //, @@ -181,8 +181,8 @@ class MarkupAccumulator { * @private */ match(tag, advance = true) { - let [regExp, length] = this.prepareRegExp(tag); - let matched = regExp.test(this.text.substr(this.position, length)); + const [regExp, length] = this.prepareRegExp(tag); + const matched = regExp.test(this.text.substr(this.position, length)); if (matched && advance) { this.position += length - 1; @@ -259,7 +259,7 @@ class MarkupAccumulator { length = 1; // ASSUMPTION: regexp only tests one character } else { // use prepared regexp if present - var prepared = tagPattern[tag]; + const prepared = tagPattern[tag]; if (prepared !== undefined) { regExp = prepared; } else { @@ -300,16 +300,16 @@ class LabelSplitter { * @param {String} mod font type to use for this text * @return {Object} { width, values} width in pixels and font attributes */ - let textWidth = (text, mod) => { + const textWidth = (text, mod) => { if (text === undefined) return 0; // TODO: This can be done more efficiently with caching // This will set the ctx.font correctly, depending on selected/hover and mod - so that ctx.measureText() will be accurate. - let values = this.parent.getFormattingValues(ctx, selected, hover, mod); + const values = this.parent.getFormattingValues(ctx, selected, hover, mod); let width = 0; if (text !== '') { - let measure = this.ctx.measureText(text); + const measure = this.ctx.measureText(text); width = measure.width; } @@ -343,7 +343,7 @@ class LabelSplitter { return this.lines.finalize(); } - var font = this.parent.fontOptions; + const font = this.parent.fontOptions; // Normalize the end-of-line's to a single representation - order important text = text.replace(/\r\n/g, '\n'); // Dos EOL's @@ -352,13 +352,13 @@ class LabelSplitter { // Note that at this point, there can be no \r's in the text. // This is used later on splitStringIntoLines() to split multifont texts. - let nlLines = String(text).split('\n'); - let lineCount = nlLines.length; + const nlLines = String(text).split('\n'); + const lineCount = nlLines.length; if (font.multi) { // Multi-font case: styling tags active for (let i = 0; i < lineCount; i++) { - let blocks = this.splitBlocks(nlLines[i], font.multi); + const blocks = this.splitBlocks(nlLines[i], font.multi); // Post: Sequences of tabs and spaces are reduced to single space if (blocks === undefined) continue; @@ -372,15 +372,15 @@ class LabelSplitter { // widthConstraint.maximum defined //console.log('Running widthConstraint multi, max: ' + this.fontOptions.maxWdt); for (let j = 0; j < blocks.length; j++) { - let mod = blocks[j].mod; - let text = blocks[j].text; + const mod = blocks[j].mod; + const text = blocks[j].text; this.splitStringIntoLines(text, mod, true); } } else { // widthConstraint.maximum NOT defined for (let j = 0; j < blocks.length; j++) { - let mod = blocks[j].mod; - let text = blocks[j].text; + const mod = blocks[j].mod; + const text = blocks[j].text; this.lines.append(text, mod); } } @@ -430,11 +430,11 @@ class LabelSplitter { * @returns {Array} */ splitHtmlBlocks(text) { - let s = new MarkupAccumulator(text); + const s = new MarkupAccumulator(text); - let parseEntities = (ch) => { + const parseEntities = (ch) => { if (/&/.test(ch)) { - let parsed = s.replace(s.text, '<', '<') + const parsed = s.replace(s.text, '<', '<') || s.replace(s.text, '&', '&'); if (!parsed) { @@ -448,9 +448,9 @@ class LabelSplitter { }; while (s.position < s.text.length) { - let ch = s.text.charAt(s.position); + const ch = s.text.charAt(s.position); - let parsed = s.parseWS(ch) + const parsed = s.parseWS(ch) || (/') || s.parseStartTag('ital', '') @@ -476,10 +476,10 @@ class LabelSplitter { * @returns {Array} */ splitMarkdownBlocks(text) { - let s = new MarkupAccumulator(text); + const s = new MarkupAccumulator(text); let beginable = true; - let parseOverride = (ch) => { + const parseOverride = (ch) => { if (/\\/.test(ch)) { if (s.position < this.text.length + 1) { s.position++; @@ -499,9 +499,9 @@ class LabelSplitter { } while (s.position < s.text.length) { - let ch = s.text.charAt(s.position); + const ch = s.text.charAt(s.position); - let parsed = s.parseWS(ch) + const parsed = s.parseWS(ch) || parseOverride(ch) || ((beginable || s.spacing) && ( s.parseStartTag('bold', '*') @@ -531,7 +531,7 @@ class LabelSplitter { * @private */ splitBlocks(text, markupSystem) { - let system = this.decodeMarkupSystem(markupSystem); + const system = this.decodeMarkupSystem(markupSystem); if (system === 'none') { return [{ text: text, @@ -551,7 +551,7 @@ class LabelSplitter { * @private */ overMaxWidth(text) { - let width = this.ctx.measureText(text).width; + const width = this.ctx.measureText(text).width; return (this.lines.curWidth() + width > this.parent.fontOptions.maxWdt); } @@ -569,8 +569,8 @@ class LabelSplitter { let w = 0; while (w < words.length) { - let pre = (text === '') ? '' : ' '; - let newText = text + pre + words[w]; + const pre = (text === '') ? '' : ' '; + const newText = text + pre + words[w]; if (this.overMaxWidth(newText)) break; text = newText; @@ -630,10 +630,10 @@ class LabelSplitter { if (w === 0) { // Special case: the first word is already larger than the max width. - let word = words[0]; + const word = words[0]; // Break the word to the largest part that fits the line - let x = this.getLongestFitWord(word); + const x = this.getLongestFitWord(word); this.lines.newLine(word.slice(0, x), mod); // Adjust the word, so that the rest will be done next iteration @@ -647,7 +647,7 @@ class LabelSplitter { newW++; } - let text = words.slice(0, w).join(""); + const text = words.slice(0, w).join(""); if (w == words.length && appendLast) { this.lines.append(text, mod); diff --git a/lib/network/options.js b/lib/network/options.js index 34542290af..bf8a7cf89b 100644 --- a/lib/network/options.js +++ b/lib/network/options.js @@ -5,16 +5,16 @@ * __any__ means that the name of the property does not matter. * __type__ is a required field for all objects and contains the allowed types of all objects */ -let string = 'string'; -let bool = 'boolean'; -let number = 'number'; -let array = 'array'; -let object = 'object'; // should only be in a __type__ property -let dom = 'dom'; -let any = 'any'; +const string = 'string'; +const bool = 'boolean'; +const number = 'number'; +const array = 'array'; +const object = 'object'; // should only be in a __type__ property +const dom = 'dom'; +const any = 'any'; // List of endpoints -let endPoints = [ +const endPoints = [ "arrow", "bar", "box", @@ -29,7 +29,7 @@ let endPoints = [ "vee" ]; -let allOptions = { +const allOptions = { configure: { enabled: { boolean: bool }, filter: { boolean: bool, string, array, 'function': 'function' }, @@ -518,7 +518,7 @@ allOptions.manipulation.controlNodeStyle = allOptions.nodes; * The first value says this will be a color picker not a dropdown menu. The * next value is the initial color. */ -let configureOptions = { +const configureOptions = { nodes: { borderWidth: [1, 0, 10, 1], borderWidthSelected: [2, 0, 10, 1], diff --git a/lib/shared/Activator.js b/lib/shared/Activator.js index 56891910ba..fa5bdb817f 100644 --- a/lib/shared/Activator.js +++ b/lib/shared/Activator.js @@ -31,7 +31,7 @@ function Activator(container) { this.hammer.on('tap', this._onTapOverlay.bind(this)); // block all touch events (except tap) - var events = [ + const events = [ 'tap', 'doubletap', 'press', 'pinch', 'pan', 'panstart', 'panmove', 'panend' diff --git a/lib/shared/ColorPicker.js b/lib/shared/ColorPicker.js index 0b2c46003a..2227a5f774 100644 --- a/lib/shared/ColorPicker.js +++ b/lib/shared/ColorPicker.js @@ -13,7 +13,7 @@ import { } from 'vis-util/esnext'; -var htmlColors = {black: '#000000', navy: '#000080', darkblue: '#00008B', mediumblue: '#0000CD', blue: '#0000FF', darkgreen: '#006400', green: '#008000', teal: '#008080', darkcyan: '#008B8B', deepskyblue: '#00BFFF', darkturquoise: '#00CED1', mediumspringgreen: '#00FA9A', lime: '#00FF00', springgreen: '#00FF7F', aqua: '#00FFFF', cyan: '#00FFFF', midnightblue: '#191970', dodgerblue: '#1E90FF', lightseagreen: '#20B2AA', forestgreen: '#228B22', seagreen: '#2E8B57', darkslategray: '#2F4F4F', limegreen: '#32CD32', mediumseagreen: '#3CB371', turquoise: '#40E0D0', royalblue: '#4169E1', steelblue: '#4682B4', darkslateblue: '#483D8B', mediumturquoise: '#48D1CC', indigo: '#4B0082', darkolivegreen: '#556B2F', cadetblue: '#5F9EA0', cornflowerblue: '#6495ED', mediumaquamarine: '#66CDAA', dimgray: '#696969', slateblue: '#6A5ACD', olivedrab: '#6B8E23', slategray: '#708090', lightslategray: '#778899', mediumslateblue: '#7B68EE', lawngreen: '#7CFC00', chartreuse: '#7FFF00', aquamarine: '#7FFFD4', maroon: '#800000', purple: '#800080', olive: '#808000', gray: '#808080', skyblue: '#87CEEB', lightskyblue: '#87CEFA', blueviolet: '#8A2BE2', darkred: '#8B0000', darkmagenta: '#8B008B', saddlebrown: '#8B4513', darkseagreen: '#8FBC8F', lightgreen: '#90EE90', mediumpurple: '#9370D8', darkviolet: '#9400D3', palegreen: '#98FB98', darkorchid: '#9932CC', yellowgreen: '#9ACD32', sienna: '#A0522D', brown: '#A52A2A', darkgray: '#A9A9A9', lightblue: '#ADD8E6', greenyellow: '#ADFF2F', paleturquoise: '#AFEEEE', lightsteelblue: '#B0C4DE', powderblue: '#B0E0E6', firebrick: '#B22222', darkgoldenrod: '#B8860B', mediumorchid: '#BA55D3', rosybrown: '#BC8F8F', darkkhaki: '#BDB76B', silver: '#C0C0C0', mediumvioletred: '#C71585', indianred: '#CD5C5C', peru: '#CD853F', chocolate: '#D2691E', tan: '#D2B48C', lightgrey: '#D3D3D3', palevioletred: '#D87093', thistle: '#D8BFD8', orchid: '#DA70D6', goldenrod: '#DAA520', crimson: '#DC143C', gainsboro: '#DCDCDC', plum: '#DDA0DD', burlywood: '#DEB887', lightcyan: '#E0FFFF', lavender: '#E6E6FA', darksalmon: '#E9967A', violet: '#EE82EE', palegoldenrod: '#EEE8AA', lightcoral: '#F08080', khaki: '#F0E68C', aliceblue: '#F0F8FF', honeydew: '#F0FFF0', azure: '#F0FFFF', sandybrown: '#F4A460', wheat: '#F5DEB3', beige: '#F5F5DC', whitesmoke: '#F5F5F5', mintcream: '#F5FFFA', ghostwhite: '#F8F8FF', salmon: '#FA8072', antiquewhite: '#FAEBD7', linen: '#FAF0E6', lightgoldenrodyellow: '#FAFAD2', oldlace: '#FDF5E6', red: '#FF0000', fuchsia: '#FF00FF', magenta: '#FF00FF', deeppink: '#FF1493', orangered: '#FF4500', tomato: '#FF6347', hotpink: '#FF69B4', coral: '#FF7F50', darkorange: '#FF8C00', lightsalmon: '#FFA07A', orange: '#FFA500', lightpink: '#FFB6C1', pink: '#FFC0CB', gold: '#FFD700', peachpuff: '#FFDAB9', navajowhite: '#FFDEAD', moccasin: '#FFE4B5', bisque: '#FFE4C4', mistyrose: '#FFE4E1', blanchedalmond: '#FFEBCD', papayawhip: '#FFEFD5', lavenderblush: '#FFF0F5', seashell: '#FFF5EE', cornsilk: '#FFF8DC', lemonchiffon: '#FFFACD', floralwhite: '#FFFAF0', snow: '#FFFAFA', yellow: '#FFFF00', lightyellow: '#FFFFE0', ivory: '#FFFFF0', white: '#FFFFFF'}; +const htmlColors = {black: '#000000', navy: '#000080', darkblue: '#00008B', mediumblue: '#0000CD', blue: '#0000FF', darkgreen: '#006400', green: '#008000', teal: '#008080', darkcyan: '#008B8B', deepskyblue: '#00BFFF', darkturquoise: '#00CED1', mediumspringgreen: '#00FA9A', lime: '#00FF00', springgreen: '#00FF7F', aqua: '#00FFFF', cyan: '#00FFFF', midnightblue: '#191970', dodgerblue: '#1E90FF', lightseagreen: '#20B2AA', forestgreen: '#228B22', seagreen: '#2E8B57', darkslategray: '#2F4F4F', limegreen: '#32CD32', mediumseagreen: '#3CB371', turquoise: '#40E0D0', royalblue: '#4169E1', steelblue: '#4682B4', darkslateblue: '#483D8B', mediumturquoise: '#48D1CC', indigo: '#4B0082', darkolivegreen: '#556B2F', cadetblue: '#5F9EA0', cornflowerblue: '#6495ED', mediumaquamarine: '#66CDAA', dimgray: '#696969', slateblue: '#6A5ACD', olivedrab: '#6B8E23', slategray: '#708090', lightslategray: '#778899', mediumslateblue: '#7B68EE', lawngreen: '#7CFC00', chartreuse: '#7FFF00', aquamarine: '#7FFFD4', maroon: '#800000', purple: '#800080', olive: '#808000', gray: '#808080', skyblue: '#87CEEB', lightskyblue: '#87CEFA', blueviolet: '#8A2BE2', darkred: '#8B0000', darkmagenta: '#8B008B', saddlebrown: '#8B4513', darkseagreen: '#8FBC8F', lightgreen: '#90EE90', mediumpurple: '#9370D8', darkviolet: '#9400D3', palegreen: '#98FB98', darkorchid: '#9932CC', yellowgreen: '#9ACD32', sienna: '#A0522D', brown: '#A52A2A', darkgray: '#A9A9A9', lightblue: '#ADD8E6', greenyellow: '#ADFF2F', paleturquoise: '#AFEEEE', lightsteelblue: '#B0C4DE', powderblue: '#B0E0E6', firebrick: '#B22222', darkgoldenrod: '#B8860B', mediumorchid: '#BA55D3', rosybrown: '#BC8F8F', darkkhaki: '#BDB76B', silver: '#C0C0C0', mediumvioletred: '#C71585', indianred: '#CD5C5C', peru: '#CD853F', chocolate: '#D2691E', tan: '#D2B48C', lightgrey: '#D3D3D3', palevioletred: '#D87093', thistle: '#D8BFD8', orchid: '#DA70D6', goldenrod: '#DAA520', crimson: '#DC143C', gainsboro: '#DCDCDC', plum: '#DDA0DD', burlywood: '#DEB887', lightcyan: '#E0FFFF', lavender: '#E6E6FA', darksalmon: '#E9967A', violet: '#EE82EE', palegoldenrod: '#EEE8AA', lightcoral: '#F08080', khaki: '#F0E68C', aliceblue: '#F0F8FF', honeydew: '#F0FFF0', azure: '#F0FFFF', sandybrown: '#F4A460', wheat: '#F5DEB3', beige: '#F5F5DC', whitesmoke: '#F5F5F5', mintcream: '#F5FFFA', ghostwhite: '#F8F8FF', salmon: '#FA8072', antiquewhite: '#FAEBD7', linen: '#FAF0E6', lightgoldenrodyellow: '#FAFAD2', oldlace: '#FDF5E6', red: '#FF0000', fuchsia: '#FF00FF', magenta: '#FF00FF', deeppink: '#FF1493', orangered: '#FF4500', tomato: '#FF6347', hotpink: '#FF69B4', coral: '#FF7F50', darkorange: '#FF8C00', lightsalmon: '#FFA07A', orange: '#FFA500', lightpink: '#FFB6C1', pink: '#FFC0CB', gold: '#FFD700', peachpuff: '#FFDAB9', navajowhite: '#FFDEAD', moccasin: '#FFE4B5', bisque: '#FFE4C4', mistyrose: '#FFE4E1', blanchedalmond: '#FFEBCD', papayawhip: '#FFEFD5', lavenderblush: '#FFF0F5', seashell: '#FFF5EE', cornsilk: '#FFF8DC', lemonchiffon: '#FFFACD', floralwhite: '#FFFAF0', snow: '#FFFAFA', yellow: '#FFFF00', lightyellow: '#FFFFE0', ivory: '#FFFFF0', white: '#FFFFFF'}; /** * @param {number} [pixelRatio=1] @@ -117,7 +117,7 @@ class ColorPicker { let rgba; // if a html color shorthand is used, convert to hex - var htmlColor = this._isColorString(color); + const htmlColor = this._isColorString(color); if (htmlColor !== undefined) { color = htmlColor; } @@ -125,22 +125,22 @@ class ColorPicker { // check format if (isString(color) === true) { if (isValidRGB(color) === true) { - let rgbaArray = color.substr(4).substr(0, color.length - 5).split(','); + const rgbaArray = color.substr(4).substr(0, color.length - 5).split(','); rgba = {r:rgbaArray[0], g:rgbaArray[1], b:rgbaArray[2], a:1.0}; } else if (isValidRGBA(color) === true) { - let rgbaArray = color.substr(5).substr(0, color.length - 6).split(','); + const rgbaArray = color.substr(5).substr(0, color.length - 6).split(','); rgba = {r:rgbaArray[0], g:rgbaArray[1], b:rgbaArray[2], a:rgbaArray[3]}; } else if (isValidHex(color) === true) { - let rgbObj = hexToRGB(color); + const rgbObj = hexToRGB(color); rgba = {r:rgbObj.r, g:rgbObj.g, b:rgbObj.b, a:1.0}; } } else { if (color instanceof Object) { if (color.r !== undefined && color.g !== undefined && color.b !== undefined) { - let alpha = color.a !== undefined ? color.a : '1.0'; + const alpha = color.a !== undefined ? color.a : '1.0'; rgba = {r:color.r, g:color.g, b:color.b, a:alpha}; } } @@ -251,12 +251,12 @@ class ColorPicker { } this.color = rgba; - let hsv = RGBToHSV(rgba.r, rgba.g, rgba.b); + const hsv = RGBToHSV(rgba.r, rgba.g, rgba.b); - let angleConvert = 2 * Math.PI; - let radius = this.r * hsv.s; - let x = this.centerCoordinates.x + radius * Math.sin(angleConvert * hsv.h); - let y = this.centerCoordinates.y + radius * Math.cos(angleConvert * hsv.h); + const angleConvert = 2 * Math.PI; + const radius = this.r * hsv.s; + const x = this.centerCoordinates.x + radius * Math.sin(angleConvert * hsv.h); + const y = this.centerCoordinates.y + radius * Math.cos(angleConvert * hsv.h); this.colorPickerSelector.style.left = x - 0.5 * this.colorPickerSelector.clientWidth + 'px'; this.colorPickerSelector.style.top = y - 0.5 * this.colorPickerSelector.clientHeight + 'px'; @@ -282,9 +282,9 @@ class ColorPicker { * @private */ _setBrightness(value) { - let hsv = RGBToHSV(this.color.r, this.color.g, this.color.b); + const hsv = RGBToHSV(this.color.r, this.color.g, this.color.b); hsv.v = value / 100; - let rgba = HSVToRGB(hsv.h, hsv.s, hsv.v); + const rgba = HSVToRGB(hsv.h, hsv.s, hsv.v); rgba['a'] = this.color.a; this.color = rgba; this._updatePicker(); @@ -297,8 +297,8 @@ class ColorPicker { * @private */ _updatePicker(rgba = this.color) { - let hsv = RGBToHSV(rgba.r, rgba.g, rgba.b); - let ctx = this.colorPickerCanvas.getContext('2d'); + const hsv = RGBToHSV(rgba.r, rgba.g, rgba.b); + const ctx = this.colorPickerCanvas.getContext('2d'); if (this.pixelRation === undefined) { this.pixelRatio = (window.devicePixelRatio || 1) / (ctx.webkitBackingStorePixelRatio || ctx.mozBackingStorePixelRatio || @@ -309,8 +309,8 @@ class ColorPicker { ctx.setTransform(this.pixelRatio, 0, 0, this.pixelRatio, 0, 0); // clear the canvas - let w = this.colorPickerCanvas.clientWidth; - let h = this.colorPickerCanvas.clientHeight; + const w = this.colorPickerCanvas.clientWidth; + const h = this.colorPickerCanvas.clientHeight; ctx.clearRect(0, 0, w, h); ctx.putImageData(this.hueCircle, 0,0); @@ -357,7 +357,7 @@ class ColorPicker { this.colorPickerDiv.appendChild(this.colorPickerCanvas); if (!this.colorPickerCanvas.getContext) { - let noCanvas = document.createElement( 'DIV' ); + const noCanvas = document.createElement( 'DIV' ); noCanvas.style.color = 'red'; noCanvas.style.fontWeight = 'bold' ; noCanvas.style.padding = '10px'; @@ -365,7 +365,7 @@ class ColorPicker { this.colorPickerCanvas.appendChild(noCanvas); } else { - let ctx = this.colorPickerCanvas.getContext("2d"); + const ctx = this.colorPickerCanvas.getContext("2d"); this.pixelRatio = (window.devicePixelRatio || 1) / (ctx.webkitBackingStorePixelRatio || ctx.mozBackingStorePixelRatio || ctx.msBackingStorePixelRatio || @@ -410,7 +410,7 @@ class ColorPicker { this.opacityDiv.appendChild(this.opacityRange); this.brightnessDiv.appendChild(this.brightnessRange); - var me = this; + const me = this; this.opacityRange.onchange = function () {me._setOpacity(this.value);}; this.opacityRange.oninput = function () {me._setOpacity(this.value);}; this.brightnessRange.onchange = function () {me._setBrightness(this.value);}; @@ -492,7 +492,7 @@ class ColorPicker { */ _generateHueCircle() { if (this.generated === false) { - let ctx = this.colorPickerCanvas.getContext('2d'); + const ctx = this.colorPickerCanvas.getContext('2d'); if (this.pixelRation === undefined) { this.pixelRatio = (window.devicePixelRatio || 1) / (ctx.webkitBackingStorePixelRatio || ctx.mozBackingStorePixelRatio || @@ -503,8 +503,8 @@ class ColorPicker { ctx.setTransform(this.pixelRatio, 0, 0, this.pixelRatio, 0, 0); // clear the canvas - let w = this.colorPickerCanvas.clientWidth; - let h = this.colorPickerCanvas.clientHeight; + const w = this.colorPickerCanvas.clientWidth; + const h = this.colorPickerCanvas.clientHeight; ctx.clearRect(0, 0, w, h); @@ -512,9 +512,9 @@ class ColorPicker { let x, y, hue, sat; this.centerCoordinates = {x: w * 0.5, y: h * 0.5}; this.r = 0.49 * w; - let angleConvert = (2 * Math.PI) / 360; - let hfac = 1 / 360; - let sfac = 1 / this.r; + const angleConvert = (2 * Math.PI) / 360; + const hfac = 1 / 360; + const sfac = 1 / this.r; let rgb; for (hue = 0; hue < 360; hue++) { for (sat = 0; sat < this.r; sat++) { @@ -542,21 +542,21 @@ class ColorPicker { * @private */ _moveSelector(event) { - let rect = this.colorPickerDiv.getBoundingClientRect(); - let left = event.center.x - rect.left; - let top = event.center.y - rect.top; + const rect = this.colorPickerDiv.getBoundingClientRect(); + const left = event.center.x - rect.left; + const top = event.center.y - rect.top; - let centerY = 0.5 * this.colorPickerDiv.clientHeight; - let centerX = 0.5 * this.colorPickerDiv.clientWidth; + const centerY = 0.5 * this.colorPickerDiv.clientHeight; + const centerX = 0.5 * this.colorPickerDiv.clientWidth; - let x = left - centerX; - let y = top - centerY; + const x = left - centerX; + const y = top - centerY; - let angle = Math.atan2(x,y); - let radius = 0.98 * Math.min(Math.sqrt(x * x + y * y), centerX); + const angle = Math.atan2(x,y); + const radius = 0.98 * Math.min(Math.sqrt(x * x + y * y), centerX); - let newTop = Math.cos(angle) * radius + centerY; - let newLeft = Math.sin(angle) * radius + centerX; + const newTop = Math.cos(angle) * radius + centerY; + const newLeft = Math.sin(angle) * radius + centerX; this.colorPickerSelector.style.top = newTop - 0.5 * this.colorPickerSelector.clientHeight + 'px'; this.colorPickerSelector.style.left = newLeft - 0.5 * this.colorPickerSelector.clientWidth + 'px'; @@ -564,11 +564,11 @@ class ColorPicker { // set color let h = angle / (2 * Math.PI); h = h < 0 ? h + 1 : h; - let s = radius / this.r; - let hsv = RGBToHSV(this.color.r, this.color.g, this.color.b); + const s = radius / this.r; + const hsv = RGBToHSV(this.color.r, this.color.g, this.color.b); hsv.h = h; hsv.s = s; - let rgba = HSVToRGB(hsv.h, hsv.s, hsv.v); + const rgba = HSVToRGB(hsv.h, hsv.s, hsv.v); rgba['a'] = this.color.a; this.color = rgba; diff --git a/lib/shared/Configurator.js b/lib/shared/Configurator.js index 3a1710e7c5..1c8c083742 100644 --- a/lib/shared/Configurator.js +++ b/lib/shared/Configurator.js @@ -124,11 +124,11 @@ class Configurator { this._clean(); this.changedOptions = []; - let filter = this.options.filter; + const filter = this.options.filter; let counter = 0; let show = false; - for (let option in this.configureOptions) { - if (this.configureOptions.hasOwnProperty(option)) { + for (const option in this.configureOptions) { + if (Object.prototype.hasOwnProperty.call(this.configureOptions, option)) { this.allowCreation = false; show = false; if (typeof filter === 'function') { @@ -169,7 +169,7 @@ class Configurator { this.wrapper = document.createElement('div'); this.wrapper.className = 'vis-configuration-wrapper'; this.container.appendChild(this.wrapper); - for (var i = 0; i < this.domElements.length; i++) { + for (let i = 0; i < this.domElements.length; i++) { this.wrapper.appendChild(this.domElements[i]); } @@ -182,7 +182,7 @@ class Configurator { * @private */ _clean() { - for (var i = 0; i < this.domElements.length; i++) { + for (let i = 0; i < this.domElements.length; i++) { this.wrapper.removeChild(this.domElements[i]); } @@ -226,7 +226,7 @@ class Configurator { */ _makeItem(path, ...domElements) { if (this.allowCreation === true) { - let item = document.createElement('div'); + const item = document.createElement('div'); item.className = 'vis-configuration vis-config-item vis-config-s' + path.length; domElements.forEach((element) => { item.appendChild(element); @@ -244,7 +244,7 @@ class Configurator { * @private */ _makeHeader(name) { - let div = document.createElement('div'); + const div = document.createElement('div'); div.className = 'vis-configuration vis-config-header'; div.innerHTML = name; this._makeItem([],div); @@ -260,7 +260,7 @@ class Configurator { * @private */ _makeLabel(name, path, objectLabel = false) { - let div = document.createElement('div'); + const div = document.createElement('div'); div.className = 'vis-configuration vis-config-label vis-config-s' + path.length; if (objectLabel === true) { div.innerHTML = '' + name + ':'; @@ -280,7 +280,7 @@ class Configurator { * @private */ _makeDropdown(arr, value, path) { - let select = document.createElement('select'); + const select = document.createElement('select'); select.className = 'vis-configuration vis-config-select'; let selectedValue = 0; if (value !== undefined) { @@ -290,7 +290,7 @@ class Configurator { } for (let i = 0; i < arr.length; i++) { - let option = document.createElement('option'); + const option = document.createElement('option'); option.value = arr[i]; if (i === selectedValue) { option.selected = 'selected'; @@ -299,10 +299,10 @@ class Configurator { select.appendChild(option); } - let me = this; + const me = this; select.onchange = function () {me._update(this.value, path);}; - let label = this._makeLabel(path[path.length-1], path); + const label = this._makeLabel(path[path.length-1], path); this._makeItem(path, label, select); } @@ -315,11 +315,11 @@ class Configurator { * @private */ _makeRange(arr, value, path) { - let defaultValue = arr[0]; - let min = arr[1]; - let max = arr[2]; - let step = arr[3]; - let range = document.createElement('input'); + const defaultValue = arr[0]; + const min = arr[1]; + const max = arr[2]; + const step = arr[3]; + const range = document.createElement('input'); range.className = 'vis-configuration vis-config-range'; try { range.type = 'range'; // not supported on IE9 @@ -335,7 +335,7 @@ class Configurator { let popupValue = 0; if (value !== undefined) { - let factor = 1.20; + const factor = 1.20; if (value < 0 && value * factor < min) { range.min = Math.ceil(value * factor); popupValue = range.min; @@ -357,16 +357,16 @@ class Configurator { range.value = defaultValue; } - let input = document.createElement('input'); + const input = document.createElement('input'); input.className = 'vis-configuration vis-config-rangeinput'; input.value = range.value; - var me = this; + const me = this; range.onchange = function () {input.value = this.value; me._update(Number(this.value), path);}; range.oninput = function () {input.value = this.value; }; - let label = this._makeLabel(path[path.length-1], path); - let itemIndex = this._makeItem(path, label, range, input); + const label = this._makeLabel(path[path.length-1], path); + const itemIndex = this._makeItem(path, label, range, input); // if a popup is needed AND it has not been shown for this value, show it. if (popupString !== '' && this.popupHistory[itemIndex] !== popupValue) { @@ -381,7 +381,7 @@ class Configurator { */ _makeButton() { if (this.options.showButton === true) { - let generateButton = document.createElement('div'); + const generateButton = document.createElement('div'); generateButton.className = 'vis-configuration vis-config-button'; generateButton.innerHTML = 'generate options'; generateButton.onclick = () => {this._printOptions();}; @@ -405,7 +405,7 @@ class Configurator { */ _setupPopup(string, index) { if (this.initialized === true && this.allowCreation === true && this.popupCounter < this.popupLimit) { - let div = document.createElement("div"); + const div = document.createElement("div"); div.id = "vis-configuration-popup"; div.className = "vis-configuration-popup"; div.innerHTML = string; @@ -436,8 +436,8 @@ class Configurator { */ _showPopupIfNeeded() { if (this.popupDiv.html !== undefined) { - let correspondingElement = this.domElements[this.popupDiv.index]; - let rect = correspondingElement.getBoundingClientRect(); + const correspondingElement = this.domElements[this.popupDiv.index]; + const rect = correspondingElement.getBoundingClientRect(); this.popupDiv.html.style.left = rect.left + "px"; this.popupDiv.html.style.top = rect.top - 30 + "px"; // 30 is the height; document.body.appendChild(this.popupDiv.html) @@ -458,7 +458,7 @@ class Configurator { * @private */ _makeCheckbox(defaultValue, value, path) { - var checkbox = document.createElement('input'); + const checkbox = document.createElement('input'); checkbox.type = 'checkbox'; checkbox.className = 'vis-configuration vis-config-checkbox'; checkbox.checked = defaultValue; @@ -476,10 +476,10 @@ class Configurator { } } - let me = this; + const me = this; checkbox.onchange = function() {me._update(this.checked, path)}; - let label = this._makeLabel(path[path.length-1], path); + const label = this._makeLabel(path[path.length-1], path); this._makeItem(path, label, checkbox); } @@ -491,7 +491,7 @@ class Configurator { * @private */ _makeTextInput(defaultValue, value, path) { - var checkbox = document.createElement('input'); + const checkbox = document.createElement('input'); checkbox.type = 'text'; checkbox.className = 'vis-configuration vis-config-text'; checkbox.value = value; @@ -499,10 +499,10 @@ class Configurator { this.changedOptions.push({path:path, value:value}); } - let me = this; + const me = this; checkbox.onchange = function() {me._update(this.value, path)}; - let label = this._makeLabel(path[path.length-1], path); + const label = this._makeLabel(path[path.length-1], path); this._makeItem(path, label, checkbox); } @@ -515,8 +515,8 @@ class Configurator { * @private */ _makeColorField(arr, value, path) { - let defaultColor = arr[1]; - let div = document.createElement('div'); + const defaultColor = arr[1]; + const div = document.createElement('div'); value = value === undefined ? defaultColor : value; if (value !== 'none') { @@ -532,7 +532,7 @@ class Configurator { this._showColorPicker(value,div,path); }; - let label = this._makeLabel(path[path.length-1], path); + const label = this._makeLabel(path[path.length-1], path); this._makeItem(path,label, div); } @@ -553,7 +553,7 @@ class Configurator { this.colorPicker.setColor(value); this.colorPicker.setUpdateCallback((color) => { - let colorString = 'rgba(' + color.r + ',' + color.g + ',' + color.b + ',' + color.a + ')'; + const colorString = 'rgba(' + color.r + ',' + color.g + ',' + color.b + ',' + color.a + ')'; div.style.backgroundColor = colorString; this._update(colorString,path); }); @@ -577,13 +577,13 @@ class Configurator { */ _handleObject(obj, path = [], checkOnly = false) { let show = false; - let filter = this.options.filter; + const filter = this.options.filter; let visibleInSet = false; - for (let subObj in obj) { - if (obj.hasOwnProperty(subObj)) { + for (const subObj in obj) { + if (Object.prototype.hasOwnProperty.call(obj, subObj)) { show = true; - let item = obj[subObj]; - let newPath = copyAndExtendArray(path, subObj); + const item = obj[subObj]; + const newPath = copyAndExtendArray(path, subObj); if (typeof filter === 'function') { show = filter(subObj,path); @@ -599,7 +599,7 @@ class Configurator { if (show !== false) { visibleInSet = true; - let value = this._getValue(newPath); + const value = this._getValue(newPath); if (item instanceof Array) { this._handleArray(item, value, newPath); @@ -622,10 +622,10 @@ class Configurator { if (draw === true) { // initially collapse options with an disabled enabled option. if (item.enabled !== undefined) { - let enabledPath = copyAndExtendArray(newPath, 'enabled'); - let enabledValue = this._getValue(enabledPath); + const enabledPath = copyAndExtendArray(newPath, 'enabled'); + const enabledValue = this._getValue(enabledPath); if (enabledValue === true) { - let label = this._makeLabel(subObj, newPath, true); + const label = this._makeLabel(subObj, newPath, true); this._makeItem(newPath, label); visibleInSet = this._handleObject(item, newPath) || visibleInSet; } @@ -634,7 +634,7 @@ class Configurator { } } else { - let label = this._makeLabel(subObj, newPath, true); + const label = this._makeLabel(subObj, newPath, true); this._makeItem(newPath, label); visibleInSet = this._handleObject(item, newPath) || visibleInSet; } @@ -681,7 +681,7 @@ class Configurator { * @private */ _update(value, path) { - let options = this._constructOptions(value,path); + const options = this._constructOptions(value,path); if (this.parent.body && this.parent.body.emitter && this.parent.body.emitter.emit) { this.parent.body.emitter.emit("configChange", options); @@ -726,7 +726,7 @@ class Configurator { * @private */ _printOptions() { - let options = this.getOptions(); + const options = this.getOptions(); this.optionsContainer.innerHTML = '
var options = ' + JSON.stringify(options, null, 2) + '
'; } @@ -735,8 +735,8 @@ class Configurator { * @returns {{}} options */ getOptions() { - let options = {}; - for (var i = 0; i < this.changedOptions.length; i++) { + const options = {}; + for (let i = 0; i < this.changedOptions.length; i++) { this._constructOptions(this.changedOptions[i].value, this.changedOptions[i].path, options) } return options; diff --git a/lib/shared/Popup.js b/lib/shared/Popup.js index 9b0104e000..e5634121cb 100644 --- a/lib/shared/Popup.js +++ b/lib/shared/Popup.js @@ -56,15 +56,15 @@ class Popup { } if (doShow === true) { - var height = this.frame.clientHeight; - var width = this.frame.clientWidth; - var maxHeight = this.frame.parentNode.clientHeight; - var maxWidth = this.frame.parentNode.clientWidth; + const height = this.frame.clientHeight; + const width = this.frame.clientWidth; + const maxHeight = this.frame.parentNode.clientHeight; + const maxWidth = this.frame.parentNode.clientWidth; - var left = 0, top = 0; + let left = 0, top = 0; if (this.overflowMethod == 'flip') { - var isLeft = false, isTop = true; // Where around the position it's located + let isLeft = false, isTop = true; // Where around the position it's located if (this.y - height < this.padding) { isTop = false; diff --git a/lib/shared/Validator.js b/lib/shared/Validator.js index 3f08b0dfe2..a3b413500c 100644 --- a/lib/shared/Validator.js +++ b/lib/shared/Validator.js @@ -2,7 +2,7 @@ import { copyAndExtendArray, copyArray } from 'vis-util/esnext'; let errorFound = false; let allOptions; -let printStyle = 'background: #FFeeee; color: #dd0000'; +const printStyle = 'background: #FFeeee; color: #dd0000'; /** * Used to validate options. */ @@ -41,8 +41,8 @@ class Validator { * @static */ static parse(options, referenceOptions, path) { - for (let option in options) { - if (options.hasOwnProperty(option)) { + for (const option in options) { + if (Object.prototype.hasOwnProperty.call(options, option)) { Validator.check(option, options, referenceOptions, path); } } @@ -103,12 +103,12 @@ class Validator { * @static */ static checkFields(option, options, referenceOptions, referenceOption, refOptionObj, path) { - let log = function(message) { + const log = function(message) { console.log('%c' + message + Validator.printLocation(path, option), printStyle); }; - let optionType = Validator.getType(options[option]); - let refOptionType = refOptionObj[optionType]; + const optionType = Validator.getType(options[option]); + const refOptionType = refOptionObj[optionType]; if (refOptionType !== undefined) { // if the type is correct, we check if it is supposed to be one of a few select values @@ -139,7 +139,7 @@ class Validator { * @static */ static getType(object) { - var type = typeof object; + const type = typeof object; if (type === 'object') { if (object === null) { @@ -190,11 +190,11 @@ class Validator { * @static */ static getSuggestion(option, options, path) { - let localSearch = Validator.findInOptions(option,options,path,false); - let globalSearch = Validator.findInOptions(option,allOptions,[],true); + const localSearch = Validator.findInOptions(option,options,path,false); + const globalSearch = Validator.findInOptions(option,allOptions,[],true); - let localSearchThreshold = 8; - let globalSearchThreshold = 4; + const localSearchThreshold = 8; + const globalSearchThreshold = 4; let msg; if (localSearch.indexMatch !== undefined) { @@ -232,12 +232,12 @@ class Validator { let min = 1e9; let closestMatch = ''; let closestMatchPath = []; - let lowerCaseOption = option.toLowerCase(); + const lowerCaseOption = option.toLowerCase(); let indexMatch = undefined; - for (let op in options) { // eslint-disable-line guard-for-in + for (const op in options) { // eslint-disable-line guard-for-in let distance; if (options[op].__type__ !== undefined && recursive === true) { - let result = Validator.findInOptions(option, options[op], copyAndExtendArray(path,op)); + const result = Validator.findInOptions(option, options[op], copyAndExtendArray(path,op)); if (min > result.distance) { closestMatch = result.closestMatch; closestMatchPath = result.path; @@ -319,16 +319,16 @@ class Validator { if (a.length === 0) return b.length; if (b.length === 0) return a.length; - var matrix = []; + const matrix = []; // increment along the first column of each row - var i; + let i; for (i = 0; i <= b.length; i++) { matrix[i] = [i]; } // increment each column in the first row - var j; + let j; for (j = 0; j <= a.length; j++) { matrix[0][j] = j; } diff --git a/package.json b/package.json index 0aca023ba4..170b24b77a 100644 --- a/package.json +++ b/package.json @@ -68,9 +68,7 @@ "build:watch": "rollup --watch --config rollup.build.js", "prepublishOnly": "npm run build", "generate-examples-index": "generate-examples-index --config generate-examples-index.json", - "lint": "npm run lint:js && npm run lint:ts", - "lint:js": "eslint '{lib,test}/**/*.js'", - "lint:ts": "eslint '{cypress,lib,test}/**/*.ts'", + "lint": "eslint --ext js,json,ts cypress examples lib test", "clean": "rimraf \"declarations\" \"dist\" \"examples/index.html\" \"examples/thumbnails\" \"peer\" \"standalone\" \"styles\" \"vis-network*\" \"cypress/{fixtures,integration,pages,support}/**/*.js{,.map}\" \"cypress/snapshots/{actual,diff}/*\"", "postinstall": "opencollective postinstall || exit 0" }, diff --git a/test/Configurator.test.js b/test/Configurator.test.js index c107118fd4..687c8a9f1c 100644 --- a/test/Configurator.test.js +++ b/test/Configurator.test.js @@ -1,19 +1,18 @@ -var assert = require('assert'); -var jsdom_global = require('jsdom-global'); +const assert = require('assert'); -var canvasMockify = require('./canvas-mock'); -var Configurator = require('../lib/shared/Configurator').default; -var Network = require('../lib/network/Network'); -var { allOptions, configureOptions } = require('../lib/network/options.js'); +const canvasMockify = require('./canvas-mock'); +const Configurator = require('../lib/shared/Configurator').default; +const Network = require('../lib/network/Network'); +const { configureOptions } = require('../lib/network/options.js'); describe('Configurator', function () { beforeEach(function() { - this.jsdom_global = canvasMockify("
"); + this.jsdomGlobalCleanup = canvasMockify("
"); this.container = document.getElementById('mynetwork'); }); afterEach(function() { - this.jsdom_global(); + this.jsdomGlobalCleanup(); this.container.remove(); this.container = undefined; }); @@ -21,7 +20,7 @@ describe('Configurator', function () { describe('constructor', function () { it('sets extends options with default options', function () { - var config = new Configurator(); + const config = new Configurator(); assert.deepEqual(config.options, config.defaultOptions); }); }); @@ -29,34 +28,34 @@ describe('Configurator', function () { describe('setOptions', function () { it('with undefined will not modify defaults', function () { - var config = new Configurator(Network, this.container); + const config = new Configurator(Network, this.container); config.setOptions(); assert.deepEqual(config.options, config.defaultOptions); }); it('with undefined will set enabled to false', function () { - var config = new Configurator(Network, this.container); + const config = new Configurator(Network, this.container); config.options.enabled = false; config.setOptions(); assert.equal(config.options.enabled, false); }); it('with string sets filter and set enabled to true', function () { - var config = new Configurator(Network, this.container); + const config = new Configurator(Network, this.container); config.setOptions('stringFilter!'); assert.equal(config.options.filter, 'stringFilter!'); assert.equal(config.options.enabled, true); }); it('with array sets filter and set enabled to true', function () { - var config = new Configurator(Network, this.container); + const config = new Configurator(Network, this.container); config.setOptions(['array', 'Filter', '!']); assert.equal(config.options.filter, 'array,Filter,!'); assert.equal(config.options.enabled, true); }); it('with object sets filter', function () { - var config = new Configurator(Network, this.container); + const config = new Configurator(Network, this.container); config.setOptions( {container: 'newContainer', filter: 'newFilter', @@ -70,31 +69,31 @@ describe('Configurator', function () { }); it('with object and filter is false enabled will be false', function () { - var config = new Configurator(Network, this.container); + const config = new Configurator(Network, this.container); config.setOptions({filter: false}); assert.equal(config.options.enabled, false); }); it('with boolean true sets filter', function () { - var config = new Configurator(Network, this.container); + const config = new Configurator(Network, this.container); config.setOptions(true); assert.equal(config.options.enabled, true); }); it('with boolean false sets filter', function () { - var config = new Configurator(Network, this.container); + const config = new Configurator(Network, this.container); config.setOptions(false); assert.equal(config.options.enabled, false); }); it('with function sets filter', function () { - var config = new Configurator(Network, this.container); + const config = new Configurator(Network, this.container); config.setOptions(function () {}); assert.equal(config.options.enabled, true); }); it('with null raises exception', function () { - var config = new Configurator(Network, this.container); + const config = new Configurator(Network, this.container); assert.throws(function () {config.setOptions(null)}, TypeError, null); }); @@ -103,13 +102,13 @@ describe('Configurator', function () { describe('setModuleOptions', function () { it('creates no new dom elements if enabled is false', function () { - var config = new Configurator(Network, this.container); + const config = new Configurator(Network, this.container); config.setModuleOptions(); assert.equal(this.container.children.length, 0); }); it('adds div with vis-configuration-wrapper class when enabled', function () { - var config = new Configurator(Network, this.container); + const config = new Configurator(Network, this.container); config.options.enabled = true; config.setModuleOptions(); assert.equal(this.container.children.length, 1); @@ -117,7 +116,7 @@ describe('Configurator', function () { }); it('overwrites config.container with config.options.container', function () { - var config = new Configurator(Network, this.container); + const config = new Configurator(Network, this.container); config.options.enabled = true; config.options.container = document.getElementById('other'); config.setModuleOptions(); @@ -130,8 +129,8 @@ describe('Configurator', function () { describe('getOptions', function () { xit('creates no new dom elements if enabled is false', function () { - var config = new Configurator(Network, this.container, configureOptions); - var options = config.getOptions(); + const config = new Configurator(Network, this.container, configureOptions); + config.getOptions(); }); }); }); diff --git a/test/Label.test.js b/test/Label.test.js index c78176b452..2189b00127 100644 --- a/test/Label.test.js +++ b/test/Label.test.js @@ -1,3 +1,6 @@ +/* eslint require-jsdoc: "off" */ +/* eslint valid-jsdoc: "off" */ + /** * TODO - add tests for: * ==== @@ -51,14 +54,14 @@ describe('Network Label', function() { * NOTE: these are options at the node-level */ function getOptions(options = {}) { - var body = { + const body = { functions: {}, emitter: { on: function() {} } }; - var nodesHandler = new NodesHandler(body, {}, options, new DummyLayoutEngine() ); + const nodesHandler = new NodesHandler(body, {}, options, new DummyLayoutEngine() ); //console.log(JSON.stringify(nodesHandler.options, null, 2)); return nodesHandler.options; @@ -72,7 +75,7 @@ describe('Network Label', function() { * Within blocks, only the text is compared */ function checkBlocks(returned, expected) { - let showBlocks = () => { + const showBlocks = () => { return '\nreturned: ' + JSON.stringify(returned, null, 2) + '\n' + 'expected: ' + JSON.stringify(expected, null, 2); } @@ -80,13 +83,13 @@ describe('Network Label', function() { assert.equal(expected.lines.length, returned.lines.length, 'Number of lines does not match, ' + showBlocks()); for (let i = 0; i < returned.lines.length; ++i) { - let retLine = returned.lines[i]; - let expLine = expected.lines[i]; + const retLine = returned.lines[i]; + const expLine = expected.lines[i]; assert(retLine.blocks.length === expLine.blocks.length, 'Number of blocks does not match, ' + showBlocks()); for (let j = 0; j < retLine.blocks.length; ++j) { - let retBlock = retLine.blocks[j]; - let expBlock = expLine.blocks[j]; + const retBlock = retLine.blocks[j]; + const expBlock = expLine.blocks[j]; assert(retBlock.text === expBlock.text, 'Text does not match, ' + showBlocks()); @@ -104,10 +107,10 @@ describe('Network Label', function() { function checkProcessedLabels(label, text, expected) { - var ctx = new DummyContext(); + const ctx = new DummyContext(); - for (var i in text) { - var ret = label._processLabelText(ctx, false, false, text[i]); + for (const i of Object.keys(text)) { + const ret = label._processLabelText(ctx, false, false, text[i]); //console.log(JSON.stringify(ret, null, 2)); checkBlocks(ret, expected[i]); } @@ -118,7 +121,7 @@ describe('Network Label', function() { * Test data **************************************************************/ - var normal_text = [ + const normal_text = [ "label text", "label\nwith\nnewlines", "OnereallylongwordthatshouldgooverwidthConstraint.maximumifdefined", @@ -126,12 +129,12 @@ describe('Network Label', function() { "Reallyoneenormouslylargelabel withtwobigwordsgoingoverwayovermax" ] - var html_text = [ + const html_text = [ "label with some multi tags", "label with some \n multi tags\n and newlines" // NB spaces around \n's ]; - var markdown_text = [ + const markdown_text = [ "label *with* `some` _multi *tags*_", "label *with* `some` \n _multi *tags*_\n and newlines" // NB spaces around \n's ]; @@ -141,7 +144,7 @@ describe('Network Label', function() { * Expected Results **************************************************************/ - var normal_expected = [{ + const normal_expected = [{ // In first item, width/height kept in for reference width: 120, height: 14, @@ -179,7 +182,7 @@ describe('Network Label', function() { const indexWidthConstrained = 2; // index of first item that will be different with max width set - var normal_widthConstraint_expected = normal_expected.slice(0, indexWidthConstrained); + const normal_widthConstraint_expected = normal_expected.slice(0, indexWidthConstrained); Array.prototype.push.apply(normal_widthConstraint_expected, [{ lines: [{ blocks: [{text: "Onereallylongwordthatshoul"}] @@ -213,7 +216,7 @@ describe('Network Label', function() { }]); - var html_unchanged_expected = [{ + const html_unchanged_expected = [{ lines: [{ blocks: [{text: "label with some multi tags"}] }] @@ -227,7 +230,7 @@ describe('Network Label', function() { }] }]; - var html_widthConstraint_unchanged = [{ + const html_widthConstraint_unchanged = [{ lines: [{ blocks: [{text: "label with"}] }, { @@ -252,7 +255,7 @@ describe('Network Label', function() { }]; - var markdown_unchanged_expected = [{ + const markdown_unchanged_expected = [{ lines: [{ blocks: [{text: "label *with* `some` _multi *tags*_"}] }] @@ -267,7 +270,7 @@ describe('Network Label', function() { }]; - var markdown_widthConstraint_expected= [{ + const markdown_widthConstraint_expected= [{ lines: [{ blocks: [{text: "label *with* `some`"}] }, { @@ -284,7 +287,7 @@ describe('Network Label', function() { }]; - var multi_expected = [{ + const multi_expected = [{ lines: [{ blocks: [ {text: "label "}, @@ -334,7 +337,7 @@ describe('Network Label', function() { it('parses normal text labels', function (done) { - var label = new Label({}, getOptions()); + const label = new Label({}, getOptions()); checkProcessedLabels(label, normal_text , normal_expected); checkProcessedLabels(label, html_text , html_unchanged_expected); // html unchanged @@ -345,10 +348,10 @@ describe('Network Label', function() { it('parses html labels', function (done) { - var options = getOptions(options); + const options = getOptions(); options.font.multi = true; // TODO: also test 'html', also test illegal value here - var label = new Label({}, options); + const label = new Label({}, options); checkProcessedLabels(label, normal_text , normal_expected); // normal as usual checkProcessedLabels(label, html_text , multi_expected); @@ -359,10 +362,10 @@ describe('Network Label', function() { it('parses markdown labels', function (done) { - var options = getOptions(options); + const options = getOptions(); options.font.multi = 'markdown'; // TODO: also test 'md', also test illegal value here - var label = new Label({}, options); + const label = new Label({}, options); checkProcessedLabels(label, normal_text , normal_expected); // normal as usual checkProcessedLabels(label, html_text , html_unchanged_expected); // html unchanged @@ -373,7 +376,7 @@ describe('Network Label', function() { it('handles normal text with widthConstraint.maximum', function (done) { - var options = getOptions(options); + const options = getOptions(); // // What the user would set: @@ -386,7 +389,7 @@ describe('Network Label', function() { // options.font.maxWdt = 300; - var label = new Label({}, options); + let label = new Label({}, options); checkProcessedLabels(label, normal_text , normal_widthConstraint_expected); checkProcessedLabels(label, html_text , html_widthConstraint_unchanged); // html unchanged @@ -402,11 +405,11 @@ describe('Network Label', function() { it('handles html tags with widthConstraint.maximum', function (done) { - var options = getOptions(options); + const options = getOptions(); options.font.multi = true; options.font.maxWdt = 300; - var label = new Label({}, options); + let label = new Label({}, options); checkProcessedLabels(label, normal_text , normal_widthConstraint_expected); checkProcessedLabels(label, html_text , multi_expected); @@ -422,11 +425,11 @@ describe('Network Label', function() { it('handles markdown tags with widthConstraint.maximum', function (done) { - var options = getOptions(options); + const options = getOptions(); options.font.multi = 'markdown'; options.font.maxWdt = 300; - var label = new Label({}, options); + const label = new Label({}, options); checkProcessedLabels(label, normal_text , normal_widthConstraint_expected); checkProcessedLabels(label, html_text , html_widthConstraint_unchanged); @@ -456,7 +459,7 @@ describe('Multi-Fonts', function() { describe('Node Labels', function() { function createNodeNetwork(newOptions) { - var dataNodes = [ + const dataNodes = [ {id: 0, label: '0'}, {id: 1, label: '1'}, {id: 2, label: '2', group: 'group1'}, @@ -473,13 +476,13 @@ describe('Node Labels', function() { ]; // create a network - var container = document.getElementById('mynetwork'); - var data = { + const container = document.getElementById('mynetwork'); + const data = { nodes: new DataSet(dataNodes), edges: [] }; - var options = { + const options = { nodes: { font: { multi: true @@ -499,7 +502,7 @@ describe('Node Labels', function() { util.deepExtend(options, newOptions); } - var network = new Network(container, data, options); + const network = new Network(container, data, options); return [network, data, options]; } @@ -511,8 +514,8 @@ describe('Node Labels', function() { * - using multi-font option 'color' for test, the rest should work analogously */ it('respects the font option precedence', function (done) { - var [network, data, options] = createNodeNetwork(); - var h = new HelperNode(network); + const [network] = createNodeNetwork(); + const h = new HelperNode(network); assert.equal(h.modBold(0).color, '#343434'); // Default value assert.equal(h.modBold(1).color, '#343434'); // Default value @@ -525,8 +528,8 @@ describe('Node Labels', function() { it('handles dynamic data and option updates', function (done) { - var [network, data, options] = createNodeNetwork(); - var h = new HelperNode(network); + const [network, data] = createNodeNetwork(); + const h = new HelperNode(network); // // Change some node values dynamically @@ -597,15 +600,15 @@ describe('Node Labels', function() { it('handles normal font values in default options', function (done) { - var newOptions = { + const newOptions = { nodes: { font: { color: 'purple' // Override the default value } }, }; - var [network, data, options] = createNodeNetwork(newOptions); - var h = new HelperNode(network); + const [network] = createNodeNetwork(newOptions); + const h = new HelperNode(network); assert.equal(h.modBold(0).color, 'purple'); // Nodes value assert.equal(h.modBold(1).color, 'purple'); // Nodes value @@ -618,7 +621,7 @@ describe('Node Labels', function() { it('handles multi-font values in default options/groups', function (done) { - var newOptions = { + const newOptions = { nodes: { font: { color: 'purple' // This set value should be overridden @@ -633,8 +636,8 @@ describe('Node Labels', function() { } }; - var [network, data, options] = createNodeNetwork(newOptions); - var h = new HelperNode(network); + const [network, , options] = createNodeNetwork(newOptions); + const h = new HelperNode(network); assert(options.nodes.font.multi); assert.equal(h.modBold(0).color, 'yellow'); // bold value @@ -652,14 +655,14 @@ describe('Node Labels', function() { describe('Edge Labels', function() { function createEdgeNetwork(newOptions) { - var dataNodes = [ + const dataNodes = [ {id: 1, label: '1'}, {id: 2, label: '2'}, {id: 3, label: '3'}, {id: 4, label: '4'}, ]; - var dataEdges = [ + const dataEdges = [ {id: 1, from: 1, to: 2, label: '1'}, {id: 2, from: 1, to: 4, label: '2', font: { @@ -674,13 +677,13 @@ describe('Edge Labels', function() { ]; // create a network - var container = document.getElementById('mynetwork'); - var data = { + const container = document.getElementById('mynetwork'); + const data = { nodes: new DataSet(dataNodes), edges: new DataSet(dataEdges), }; - var options = { + const options = { edges: { font: { multi: true @@ -692,7 +695,7 @@ describe('Edge Labels', function() { util.deepExtend(options, newOptions); } - var network = new Network(container, data, options); + const network = new Network(container, data, options); return [network, data, options]; } @@ -720,8 +723,8 @@ describe('Edge Labels', function() { * - edges have no groups */ it('respects the font option precedence', function (done) { - var [network, data, options] = createEdgeNetwork(); - var h = new HelperEdge(network); + const [network] = createEdgeNetwork(); + const h = new HelperEdge(network); assert.equal(h.modBold(1).color, '#343434'); // Default value assert.equal(h.modBold(2).color, 'green'); // Local value overrides default @@ -732,8 +735,8 @@ describe('Edge Labels', function() { it('handles dynamic data and option updates', function (done) { - var [network, data, options] = createEdgeNetwork(); - var h = new HelperEdge(network); + const [network, data] = createEdgeNetwork(); + const h = new HelperEdge(network); data.edges.update([ {id: 3, font: { bold: { color: 'orange'}}}, @@ -764,15 +767,15 @@ describe('Edge Labels', function() { it('handles font values in default options', function (done) { - var newOptions = { + const newOptions = { edges: { font: { color: 'purple' // Override the default value } }, }; - var [network, data, options] = createEdgeNetwork(newOptions); - var h = new HelperEdge(network); + const [network] = createEdgeNetwork(newOptions); + const h = new HelperEdge(network); assert.equal(h.modBold(1).color, 'purple'); // Nodes value assert.equal(h.modBold(2).color, 'green'); // Local value overrides all @@ -786,7 +789,7 @@ describe('Edge Labels', function() { describe('Shorthand Font Options', function() { - var testFonts = { + const testFonts = { 'default': {color: '#343434', face: 'arial' , size: 14}, 'monodef': {color: '#343434', face: 'monospace', size: 15}, 'font1' : {color: '#010101', face: 'Font1' , size: 1}, @@ -800,7 +803,7 @@ describe('Shorthand Font Options', function() { function checkFont(opt, expectedLabel) { - var expected = testFonts[expectedLabel]; + const expected = testFonts[expectedLabel]; util.forEach(expected, (item, key) => { assert.equal(opt[key], item); @@ -809,23 +812,23 @@ describe('Shorthand Font Options', function() { function createNetwork() { - var dataNodes = [ + const dataNodes = [ {id: 1, label: '1'}, {id: 2, label: '2', group: 'group1'}, {id: 3, label: '3', group: 'group2'}, {id: 4, label: '4', font: '5px Font5 #050505'}, ]; - var dataEdges = []; + const dataEdges = []; // create a network - var container = document.getElementById('mynetwork'); - var data = { + const container = document.getElementById('mynetwork'); + const data = { nodes: new DataSet(dataNodes), edges: new DataSet(dataEdges), }; - var options = { + const options = { nodes: { font: { multi: true, @@ -845,19 +848,19 @@ describe('Shorthand Font Options', function() { } }; - var network = new Network(container, data, options); + const network = new Network(container, data, options); return [network, data]; } it('handles shorthand options correctly', function (done) { - var [network, data] = createNetwork(); - var h = new HelperNode(network); + const [network] = createNetwork(); + const h = new HelperNode(network); // NOTE: 'mono' has its own global default font and size, which will // trump any other font values set. - var opt = h.fontOption(1); + let opt = h.fontOption(1); checkFont(opt, 'default'); checkFont(opt.bold, 'font1'); checkFont(opt.ital, 'font2'); @@ -920,7 +923,7 @@ describe('Shorthand Font Options', function() { } - function dynamicAdd2(network, data) { + function dynamicAdd2(network) { network.setOptions({ nodes: { font: '7 Font7 #070707' // Note: this kills the font.multi, bold and ital settings! @@ -930,11 +933,11 @@ describe('Shorthand Font Options', function() { it('deals with dynamic data and option updates for shorthand', function (done) { - var [network, data] = createNetwork(); - var h = new HelperNode(network); + const [network, data] = createNetwork(); + const h = new HelperNode(network); dynamicAdd1(network, data); - var opt = h.fontOption(1); + let opt = h.fontOption(1); checkFont(opt, 'font5'); // New base font checkFont(opt.bold, 'font1'); checkFont(opt.ital, 'font4'); // New global node default @@ -968,12 +971,12 @@ describe('Shorthand Font Options', function() { it('deals with dynamic change of global node default', function (done) { - var [network, data] = createNetwork(); - var h = new HelperNode(network); + const [network, data] = createNetwork(); + const h = new HelperNode(network); dynamicAdd1(network, data); // Accumulate data of dynamic add dynamicAdd2(network, data); - var opt = h.fontOption(1); + let opt = h.fontOption(1); checkFont(opt, 'font5'); // Node instance value checkFont(opt.bold, 'font5'); // bold def removed from global default node checkFont(opt.ital, 'font5'); // idem @@ -1010,8 +1013,8 @@ describe('Shorthand Font Options', function() { it('deals with dynamic delete of shorthand options', function (done) { - var [network, data] = createNetwork(); - var h = new HelperNode(network); + const [network, data] = createNetwork(); + const h = new HelperNode(network); dynamicAdd1(network, data); // Accumulate data of previous dynamic steps dynamicAdd2(network, data); // idem @@ -1020,7 +1023,7 @@ describe('Shorthand Font Options', function() { {id: 4, font: { bold: null}}, ]); - var opt; + let opt; /* // Interesting: following flagged as error in options parsing, avoiding it for that reason @@ -1078,8 +1081,8 @@ describe('Shorthand Font Options', function() { /** * Helper function for easily accessing font options in a node */ - var fontOption = (index) => { - var nodes = network.body.nodes; + const fontOption = (index) => { + const nodes = network.body.nodes; return nodes[index].labelModule.fontOptions; }; @@ -1087,12 +1090,12 @@ describe('Shorthand Font Options', function() { /** * Helper function for easily accessing bold options in a node */ - var modBold = (index) => { + const modBold = (index) => { return fontOption(index).bold; }; - var dataNodes = [ + const dataNodes = [ {id: 1, label: '1', group: 'group1'}, { // From example 1 in #3408 @@ -1110,13 +1113,13 @@ describe('Shorthand Font Options', function() { ]; // create a network - var container = document.getElementById('mynetwork'); - var data = { + const container = document.getElementById('mynetwork'); + const data = { nodes: new DataSet(dataNodes), edges: [] }; - var options = { + const options = { groups: { group1: { font: { @@ -1143,7 +1146,7 @@ describe('Shorthand Font Options', function() { }, }; - var network = new Network(container, data, options); + const network = new Network(container, data, options); assert.equal(modBold(1).color, 'red'); // Group value assert(fontOption(1).multi); // Group value @@ -1190,9 +1193,9 @@ describe('Shorthand Font Options', function() { it('compresses spaces for Multi-Font', function (done) { - var options = getOptions(options); + let options = getOptions(); - var text = [ + const text = [ "Too many spaces here!", "one two three four five six .", "This thing:\n - could be\n - a kind\n - of list", // multifont: 2 spaces at start line reduced to 1 @@ -1202,9 +1205,9 @@ describe('Shorthand Font Options', function() { // // multifont disabled: spaces are preserved // - var label = new Label({}, options); + let label = new Label({}, options); - var expected = [{ + const expected = [{ lines: [{ blocks: [{text: "Too many spaces here!"}], }] @@ -1231,9 +1234,9 @@ describe('Shorthand Font Options', function() { // multifont disabled width maxwidth: spaces are preserved // options.font.maxWdt = 300; - var label = new Label({}, options); + label = new Label({}, options); - var expected_maxwidth = [{ + const expected_maxwidth = [{ lines: [{ blocks: [{text: "Too many spaces"}], }, { @@ -1267,9 +1270,9 @@ describe('Shorthand Font Options', function() { // options = getOptions(options); options.font.multi = true; - var label = new Label({}, options); + label = new Label({}, options); - var expected_multifont = [{ + const expected_multifont = [{ lines: [{ blocks: [{text: "Too many spaces here!"}], }] @@ -1296,9 +1299,9 @@ describe('Shorthand Font Options', function() { // multifont enabled with max width: spaces are compressed // options.font.maxWdt = 300; - var label = new Label({}, options); + label = new Label({}, options); - var expected_multifont_maxwidth = [{ + const expected_multifont_maxwidth = [{ lines: [{ blocks: [{text: "Too many spaces"}], }, { @@ -1330,7 +1333,7 @@ describe('Shorthand Font Options', function() { it('parses single huge word on line with preceding whitespace when max width set', function (done) { - var options = getOptions(options); + const options = getOptions(); options.font.maxWdt = 300; assert.equal(options.font.multi, false); @@ -1339,7 +1342,7 @@ describe('Shorthand Font Options', function() { * * Allows negative indexing, counting from back (ruby style) */ - let splitAt = (text, pos, getFirst) => { + const splitAt = (text, pos, getFirst) => { if (pos < 0) pos = text.length + pos; if (getFirst) { @@ -1349,16 +1352,16 @@ describe('Shorthand Font Options', function() { } }; - var label = new Label({}, options); - var longWord = "asd;lkfja;lfkdj;alkjfd;alskfj"; + let label = new Label({}, options); + const longWord = "asd;lkfja;lfkdj;alkjfd;alskfj"; - var text = [ + const text = [ "Mind the space!\n " + longWord, "Mind the empty line!\n\n" + longWord, "Mind the dos empty line!\r\n\r\n" + longWord ]; - var expected = [{ + const expected = [{ lines: [{ blocks: [{text: "Mind the space!"}] }, { @@ -1401,7 +1404,7 @@ describe('Shorthand Font Options', function() { // Multi font enabled. For current case, output should be identical to no multi font // options.font.multi = true; - var label = new Label({}, options); + label = new Label({}, options); checkProcessedLabels(label, text, expected); done(); @@ -1416,7 +1419,7 @@ describe('Shorthand Font Options', function() { * NOTE: boolean shorthand values for widthConstraint and heightConstraint do nothing. */ it('Sets the width/height constraints in the font label options', function (done) { - var nodes = [ + const nodes = [ { id: 100, label: 'node 100'}, { id: 210, group: 'group1', label: 'node 210'}, { id: 211, widthConstraint: { minimum: 120 }, label: 'node 211'}, @@ -1433,19 +1436,19 @@ describe('Shorthand Font Options', function() { { id: 402, heightConstraint: { minimum: 100, valign: 'bottom' }, label: 'node 402'} ]; - var edges = [ + const edges = [ { id: 1, from: 100, to: 210, label: "edge 1"}, { id: 2, widthConstraint: 80, from: 210, to: 211, label: "edge 2"}, { id: 3, heightConstraint: 90, from: 100, to: 220, label: "edge 3"}, { id: 4, from: 401, to: 402, widthConstraint: { maximum: 150 }, label: "edge 12"}, ]; - var container = document.getElementById('mynetwork'); - var data = { + const container = document.getElementById('mynetwork'); + const data = { nodes: nodes, edges: edges }; - var options = { + const options = { edges: { font: { size: 12 @@ -1485,9 +1488,9 @@ describe('Shorthand Font Options', function() { enabled: false } }; - var network = new Network(container, data, options); + const network = new Network(container, data, options); - var nodes_expected = [ + const nodes_expected = [ { nodeId: 100, minWdt: -1, maxWdt: 200, minHgt: -1, valign: 'middle'}, { nodeId: 210, minWdt: -1, maxWdt: 130, minHgt: -1, valign: 'middle'}, { nodeId: 211, minWdt: 120, maxWdt: 200, minHgt: -1, valign: 'middle'}, @@ -1510,7 +1513,7 @@ describe('Shorthand Font Options', function() { // // There is a lot of repetitiveness here. Perhaps using a direct copy of the // example should be let go. - var edges_expected = [ + const edges_expected = [ { id: 1, minWdt: -1, maxWdt: 90, minHgt: -1, valign: 'middle'}, { id: 2, minWdt: 80, maxWdt: 80, minHgt: -1, valign: 'middle'}, { id: 3, minWdt: -1, maxWdt: 90, minHgt: 90, valign: 'middle'}, @@ -1518,7 +1521,7 @@ describe('Shorthand Font Options', function() { ]; - let assertConstraints = (expected, fontOptions, label) => { + const assertConstraints = (expected, fontOptions, label) => { assert.equal(expected.minWdt, fontOptions.minWdt, 'Incorrect min width' + label); assert.equal(expected.maxWdt, fontOptions.maxWdt, 'Incorrect max width' + label); assert.equal(expected.minHgt, fontOptions.minHgt, 'Incorrect min height' + label); @@ -1528,23 +1531,23 @@ describe('Shorthand Font Options', function() { // Check nodes util.forEach(nodes_expected, function(expected) { - let networkNode = network.body.nodes[expected.nodeId]; + const networkNode = network.body.nodes[expected.nodeId]; assert(networkNode !== undefined && networkNode !== null, 'node not found for id: ' + expected.nodeId); - let fontOptions = networkNode.labelModule.fontOptions; + const fontOptions = networkNode.labelModule.fontOptions; - var label = ' for node id: ' + expected.nodeId; + const label = ' for node id: ' + expected.nodeId; assertConstraints(expected, fontOptions, label); }); // Check edges util.forEach(edges_expected, function(expected) { - let networkEdge = network.body.edges[expected.id]; + const networkEdge = network.body.edges[expected.id]; - var label = ' for edge id: ' + expected.id; + const label = ' for edge id: ' + expected.id; assert(networkEdge !== undefined, 'Edge not found' + label); - let fontOptions = networkEdge.labelModule.fontOptions; + const fontOptions = networkEdge.labelModule.fontOptions; assertConstraints(expected, fontOptions, label); }); @@ -1553,21 +1556,21 @@ describe('Shorthand Font Options', function() { it('deals with null labels and other awkward values', function (done) { - var ctx = new DummyContext(); - var options = getOptions({}); + const ctx = new DummyContext(); + let options = getOptions({}); - var checkHandling = (label, index, text) => { + const checkHandling = (label, index, text) => { assert.doesNotThrow(() => {label.getTextSize(ctx, false, false)}, "Unexpected throw for " + text + " " + index); //label.getTextSize(ctx, false, false); // Use this to determine the error thrown // There should not be a label for any of the cases // - let labelVal = label.elementOptions.label; - let validLabel = (typeof labelVal === 'string' && labelVal !== ''); + const labelVal = label.elementOptions.label; + const validLabel = (typeof labelVal === 'string' && labelVal !== ''); assert(!validLabel, "Unexpected label value '" + labelVal+ "' for " + text +" " + index); }; - var nodes = [ + const nodes = [ {id: 1}, {id: 2, label: null}, {id: 3, label: undefined}, @@ -1577,7 +1580,7 @@ describe('Shorthand Font Options', function() { {id: 7, label: 3.419}, ]; - var edges = [ + const edges = [ {from: 1, to: 2, label: null}, {from: 1, to: 3, label: undefined}, {from: 1, to: 4, label: {a: 42}}, @@ -1592,14 +1595,14 @@ describe('Shorthand Font Options', function() { // Node labels for (let i = 0; i < nodes.length; ++i) { - let label = new Label(null, nodes[i], false); + const label = new Label(null, nodes[i], false); checkHandling(label, i, 'node'); } // Edge labels for (let i = 0; i < edges.length; ++i) { - let label = new Label(null, edges[i], true); + const label = new Label(null, edges[i], true); checkHandling(label, i, 'edge'); } @@ -1610,33 +1613,33 @@ describe('Shorthand Font Options', function() { // In the example, only `label:null` was present. The weird thing is that it fails // in the example, but succeeds in the unit tests. // Kept in for regression testing. - var container = document.getElementById('mynetwork'); - var data = { + const container = document.getElementById('mynetwork'); + const data = { nodes: new DataSet(nodes), edges: new DataSet(edges) }; - var options = {}; - var network = new Network(container, data, options); + options = {}; + new Network(container, data, options); done() }) describe('visible function', function() { it('correctly determines label is not visible when label is invalid', function(done) { - var invalidLabel = '' + const invalidLabel = '' assert( !isValidLabel(invalidLabel), 'An empty string should be identified as an invalid label' ) - var body = { + const body = { view: { scale: 1 } } - var options = { + const options = { label: invalidLabel, font: { size: 12 @@ -1648,7 +1651,7 @@ describe('Shorthand Font Options', function() { } } - var label = new Label(body, options) + const label = new Label(body, options) label.size.width = 1 label.size.height = 1 diff --git a/test/Network.test.js b/test/Network.test.js index a80fea0ad7..d14d0cacee 100644 --- a/test/Network.test.js +++ b/test/Network.test.js @@ -1,3 +1,7 @@ +/* eslint-disable require-jsdoc */ +/* eslint-disable valid-jsdoc */ +/* eslint-disable guard-for-in */ + /** * * Useful during debugging @@ -32,8 +36,8 @@ function merge (a, b) { } if (b) { - for (var name in b) { - if (b.hasOwnProperty(name)) { + for (const name in b) { + if (Object.prototype.hasOwnProperty.call(b, name)) { if (typeof b[name] === 'object') { a[name] = merge(a[name], b[name]); } else { @@ -54,9 +58,9 @@ function include(list, context) { list = [list]; } - for (var n in list) { - var path = list[n]; - var arr = [fs.readFileSync(path) + '']; + for (const n in list) { + const path = list[n]; + const arr = [fs.readFileSync(path) + '']; eval.apply(context, arr); } } @@ -71,10 +75,10 @@ function include(list, context) { * For reference, this is the sample network of issue #1218 */ function createSampleNetwork(options) { - var NumInitialNodes = 8; - var NumInitialEdges = 6; + const NumInitialNodes = 8; + const NumInitialEdges = 6; - var nodes = new DataSet([ + const nodes = new DataSet([ {id: 1, label: '1'}, {id: 2, label: '2'}, {id: 3, label: '3'}, @@ -84,7 +88,7 @@ function createSampleNetwork(options) { {id: 13, label: '13'}, {id: 14, label: '14'}, ]); - var edges = new DataSet([ + const edges = new DataSet([ { from: 1, to: 2, label: '1 to 2' }, { from: 2, to: 3, label: '2 to 3' }, { from: 3, to: 4, label: '3 to 4' }, @@ -94,13 +98,13 @@ function createSampleNetwork(options) { ]); // create a network - var container = document.getElementById('mynetwork'); - var data = { + const container = document.getElementById('mynetwork'); + const data = { nodes: nodes, edges: edges }; - var defaultOptions = { + const defaultOptions = { layout: { randomSeed: 8 }, @@ -113,7 +117,7 @@ function createSampleNetwork(options) { options = merge(defaultOptions, options); - var network = new Network(container, data, options); + const network = new Network(container, data, options); assertNumNodes(network, NumInitialNodes); assertNumEdges(network, NumInitialEdges); @@ -131,7 +135,7 @@ function createSampleNetwork(options) { * a cluster is made of two nodes, each from one of the sub-networks. */ function createCluster(network) { - var clusterOptionsByData = { + const clusterOptionsByData = { joinCondition: function(node) { if (node.id == 1 || node.id == 11) return true; return false; @@ -145,6 +149,7 @@ function createCluster(network) { /** * Display node/edge state, useful during debugging */ +// eslint-disable-next-line no-unused-vars function log(network) { console.log(Object.keys(network.body.nodes)); console.log(network.body.nodeIndices); @@ -176,12 +181,12 @@ function assertNumEdges(network, expectedPresent, expectedVisible) { }; function assertEdgeLabels(network, originalEdgesDataSet, assertMessagePrefix) { - let originalIds = originalEdgesDataSet.getIds() + const originalIds = originalEdgesDataSet.getIds() for (let index = 0; index < originalIds.length; index++) { - let id = originalIds[index] - let expectedOriginalEdge = originalEdgesDataSet.get(id) - let currentNetworkEdge = network.body.edges[id] + const id = originalIds[index] + const expectedOriginalEdge = originalEdgesDataSet.get(id) + const currentNetworkEdge = network.body.edges[id] assert.equal( currentNetworkEdge.options.label, @@ -199,7 +204,7 @@ function assertEdgeLabels(network, originalEdgesDataSet, assertMessagePrefix) { * If any assertion fails here, all code in Network handling fonts should be checked. */ function checkFontProperties(fontItem, checkStrict = true) { - var knownProperties = [ + const knownProperties = [ 'color', 'size', 'face', @@ -216,18 +221,18 @@ function checkFontProperties(fontItem, checkStrict = true) { ]; // All properties in fontItem should be known - for (var prop in fontItem) { + for (const prop in fontItem) { if (prop === '__type__') continue; // Skip special field in options definition - if (!fontItem.hasOwnProperty(prop)) continue; + if (!Object.prototype.hasOwnProperty.call(fontItem, prop)) continue; assert(knownProperties.indexOf(prop) !== -1, "Unknown font option '" + prop + "'"); } if (!checkStrict) return; // All known properties should be present - var keys = Object.keys(fontItem); - for (var n in knownProperties) { - var prop = knownProperties[n]; + const keys = Object.keys(fontItem); + for (const n in knownProperties) { + const prop = knownProperties[n]; assert(keys.indexOf(prop) !== -1, "Missing known font option '" + prop + "'"); } } @@ -254,14 +259,15 @@ describe('Network', function () { * Simplify network creation for local tests */ function createNetwork(options) { - var [network, data, numNodes, numEdges] = createSampleNetwork(options); + // eslint-disable-next-line no-unused-vars + const [network] = createSampleNetwork(options); return network; } function firstNode(network) { - for (var id in network.body.nodes) { + for (const id in network.body.nodes) { return network.body.nodes[id]; } @@ -269,7 +275,7 @@ describe('Network', function () { } function firstEdge(network) { - for (var id in network.body.edges) { + for (const id in network.body.edges) { return network.body.edges[id]; } @@ -301,7 +307,7 @@ describe('Network', function () { * Helper function for clustering */ function clusterTo(network, clusterId, nodeList, allowSingle) { - var options = { + const options = { joinCondition: function(node) { return nodeList.indexOf(node.id) !== -1; }, @@ -324,13 +330,13 @@ describe('Network', function () { * The real deterrent is eslint rule 'guard-for-in`. */ it('can deal with added fields in Array.prototype', function (done) { - var canvas = window.document.createElement('canvas'); + window.document.createElement('canvas'); Array.prototype.foo = 1; // Just add anything to the prototype Object.prototype.bar = 2; // Let's screw up hashes as well // The network should just run without throwing errors try { - var [network, data, numNodes, numEdges] = createSampleNetwork({}); + const [network, data] = createSampleNetwork({}); // Do some stuff to trigger more errors clusterTo(network, 'c1', [1,2,3]); @@ -359,20 +365,20 @@ describe('Network', function () { * TODO: extend test for all API calls with options, see #3548 */ it('does not change the options object passed to fit()', function() { - var [network, data, numNodes, numEdges] = createSampleNetwork({}); - var options = {}; + const [network] = createSampleNetwork({}); + const options = {}; network.fit(options); // options should still be empty - for (var prop in options) { - assert(!options.hasOwnProperty(prop), 'No properties should be present in options, detected property: ' + prop); + for (const prop in options) { + assert(!Object.prototype.hasOwnProperty.call(options, prop), 'No properties should be present in options, detected property: ' + prop); } }); it('does not crash when dataChanged is triggered when setting options on first initialization ', function() { // The init should succeed without an error thrown. - var options = { + let options = { nodes: { physics: false // any value here triggered the error } @@ -395,17 +401,17 @@ describe('Network', function () { it('can deal with null data', function() { // While we're at it, try out other silly values as well // All the following are wrong, but none should lead to a crash - var awkwardData = [ + const awkwardData = [ null, [1,2,3], 42, 'meow' ]; - var container = document.getElementById('mynetwork'); + const container = document.getElementById('mynetwork'); - for (var n = 0; n < awkwardData.length; ++n) { - var network = new Network(container, awkwardData[n], {}); // Should not throw + for (let n = 0; n < awkwardData.length; ++n) { + new Network(container, awkwardData[n], {}); // Should not throw } }); @@ -413,7 +419,7 @@ describe('Network', function () { describe('Node', function () { it('has known font options', function () { - var network = createNetwork({}); + const network = createNetwork({}); checkFontProperties(network.nodesHandler.defaultOptions.font); checkFontProperties(allOptions.nodes.font); checkFontProperties(configureOptions.nodes.font, false); @@ -426,8 +432,8 @@ describe('Node', function () { */ it('properly handles choosify input', function () { // check defaults - var options = {}; - var network = createNetwork(options); + let options = {}; + let network = createNetwork(options); checkChooserValues(firstNode(network), true, true); // There's no point in checking invalid values here; these are detected by the options parser @@ -445,13 +451,13 @@ describe('Node', function () { options = {nodes: {chosen: { node:true, - label: function(value, id, selected, hovering) {} + label: function() {} }}}; network = createNetwork(options); checkChooserValues(firstNode(network), true, 'function'); options = {nodes: {chosen: { - node: function(value, id, selected, hovering) {}, + node: function() {}, label:false, }}}; network = createNetwork(options); @@ -463,7 +469,7 @@ describe('Node', function () { describe('Edge', function () { it('has known font options', function () { - var network = createNetwork({}); + const network = createNetwork({}); checkFontProperties(network.edgesHandler.defaultOptions.font); checkFontProperties(allOptions.edges.font); checkFontProperties(configureOptions.edges.font, false); @@ -476,8 +482,8 @@ describe('Edge', function () { */ it('properly handles choosify input', function () { // check defaults - var options = {}; - var network = createNetwork(options); + let options = {}; + let network = createNetwork(options); checkChooserValues(firstEdge(network), true, true); // There's no point in checking invalid values here; these are detected by the options parser @@ -495,13 +501,13 @@ describe('Edge', function () { options = {edges: {chosen: { edge:true, - label: function(value, id, selected, hovering) {} + label: function() {} }}}; network = createNetwork(options); checkChooserValues(firstEdge(network), true, 'function'); options = {edges: {chosen: { - edge: function(value, id, selected, hovering) {}, + edge: function() {}, label:false, }}}; network = createNetwork(options); @@ -513,14 +519,14 @@ describe('Edge', function () { * Support routine for next unit test */ function createDataforColorChange() { - var nodes = new DataSet([ + const nodes = new DataSet([ {id: 1, label: 'Node 1' }, // group:'Group1'}, {id: 2, label: 'Node 2', group:'Group2'}, {id: 3, label: 'Node 3'}, ]); // create an array with edges - var edges = new DataSet([ + const edges = new DataSet([ {id: 1, from: 1, to: 2}, {id: 2, from: 1, to: 3, color: { inherit: 'to'}}, {id: 3, from: 3, to: 3, color: { color: '#00FF00'}}, @@ -528,7 +534,7 @@ describe('Edge', function () { ]); - var data = { + const data = { nodes: nodes, edges: edges }; @@ -544,16 +550,16 @@ describe('Edge', function () { * We test the updates the color options in the general edges options here. */ it('sets inherit color option for edges on call to Network.setOptions()', function () { - var container = document.getElementById('mynetwork'); - var data = createDataforColorChange(); + const container = document.getElementById('mynetwork'); + const data = createDataforColorChange(); - var options = { + const options = { "edges" : { "color" : { "inherit" : "to" } }, }; // Test passing options on init. - var network = new Network(container, data, options); - var edges = network.body.edges; + let network = new Network(container, data, options); + let edges = network.body.edges; assert.equal(edges[1].options.color.inherit, 'to'); // new default assert.equal(edges[2].options.color.inherit, 'to'); // set in edge assert.equal(edges[3].options.color.inherit, false); // has explicit color @@ -597,12 +603,12 @@ describe('Edge', function () { it('sets inherit color option for specific edge', function () { - var container = document.getElementById('mynetwork'); - var data = createDataforColorChange(); + const container = document.getElementById('mynetwork'); + const data = createDataforColorChange(); // Check no options - var network = new Network(container, data, {}); - var edges = network.body.edges; + const network = new Network(container, data, {}); + const edges = network.body.edges; assert.equal(edges[1].options.color.inherit, 'from'); // default assert.equal(edges[2].options.color.inherit, 'to'); // set in edge assert.equal(edges[3].options.color.inherit, false); // has explicit color @@ -621,19 +627,19 @@ describe('Edge', function () { * Perhaps TODO: add unit test for passing string value for color option */ it('sets color value for edges on call to Network.setOptions()', function () { - var container = document.getElementById('mynetwork'); - var data = createDataforColorChange(); + const container = document.getElementById('mynetwork'); + const data = createDataforColorChange(); - var defaultColor = '#848484'; // From defaults - var color = '#FF0000'; + const defaultColor = '#848484'; // From defaults + const color = '#FF0000'; - var options = { + const options = { "edges" : { "color" : { "color" : color } }, }; // Test passing options on init. - var network = new Network(container, data, options); - var edges = network.body.edges; + let network = new Network(container, data, options); + let edges = network.body.edges; assert.equal(edges[1].options.color.color, color); assert.equal(edges[1].options.color.inherit, false); // Explicit color, so no inherit assert.equal(edges[2].options.color.color, color); @@ -674,25 +680,25 @@ describe('Edge', function () { * Checking to make sure edges that become unconnected due to node removal get reconnected */ it.skip('has reconnected edges (problems since mocha 4)', function (done) { - var node1 = {id:1, label:"test1"}; - var node2 = {id:2, label:"test2"}; - var nodes = new DataSet([node1, node2]); + const node1 = {id:1, label:"test1"}; + const node2 = {id:2, label:"test2"}; + const nodes = new DataSet([node1, node2]); - var edge = {id:1, from: 1, to:2}; - var edges = new DataSet([edge]); + const edge = {id:1, from: 1, to:2}; + const edges = new DataSet([edge]); - var data = { + const data = { nodes: nodes, edges: edges }; - var container = document.getElementById('mynetwork'); - var network = new Network(container, data); + const container = document.getElementById('mynetwork'); + const network = new Network(container, data); //remove node causing edge to become disconnected nodes.remove(node2.id); - var foundEdge = network.body.edges[edge.id]; + let foundEdge = network.body.edges[edge.id]; assert.ok(foundEdge===undefined, "edge is still in state cache"); @@ -710,7 +716,9 @@ describe('Edge', function () { describe('Clustering', function () { it('properly handles options allowSingleNodeCluster', function() { - var [network, data, numNodes, numEdges] = createSampleNetwork(); + const sampleNetwork = createSampleNetwork(); + const [network, data] = sampleNetwork; + let [, , numNodes, numEdges] = sampleNetwork; data.edges.update({from: 1, to: 11,}); numEdges += 1; assertNumNodes(network, numNodes); @@ -755,7 +763,9 @@ describe('Clustering', function () { it('removes nested clusters with allowSingleNodeCluster === true', function() { - var [network, data, numNodes, numEdges] = createSampleNetwork(); + const sampleNetwork = createSampleNetwork(); + const [network, data] = sampleNetwork; + let [, , numNodes, numEdges] = sampleNetwork; // Create a chain of nested clusters, three deep clusterTo(network, 'c1', [4], true); clusterTo(network, 'c2', ['c1'], true); @@ -784,7 +794,9 @@ describe('Clustering', function () { * Check on fix for #1218 */ it('connects a new edge to a clustering node instead of the clustered node', function () { - var [network, data, numNodes, numEdges] = createSampleNetwork(); + const sampleNetwork = createSampleNetwork(); + const [network, data] = sampleNetwork; + let [, , numNodes, numEdges] = sampleNetwork; createCluster(network); numNodes += 1; // A clustering node is now hiding two nodes @@ -813,7 +825,9 @@ describe('Clustering', function () { */ it('can uncluster a clustered node when a node is removed that has an edge to that cluster', function () { // NOTE: this block is same as previous test - var [network, data, numNodes, numEdges] = createSampleNetwork(); + const sampleNetwork = createSampleNetwork(); + const [network, data] = sampleNetwork; + let [, , numNodes, numEdges] = sampleNetwork; createCluster(network); numNodes += 1; // A clustering node is now hiding two nodes @@ -851,9 +865,11 @@ describe('Clustering', function () { * Check on fix for #1291 */ it('can remove a node inside a cluster and then open that cluster', function () { - var [network, data, numNodes, numEdges] = createSampleNetwork(); + const sampleNetwork = createSampleNetwork(); + const [network, data] = sampleNetwork; + let [, , numNodes, numEdges] = sampleNetwork; - var clusterOptionsByData = { + const clusterOptionsByData = { joinCondition: function(node) { if (node.id == 1 || node.id == 2 || node.id == 3) return true; return false; @@ -890,7 +906,7 @@ describe('Clustering', function () { */ function createOutlierGraph() { // create an array with nodes - var nodes = new DataSet([ + const nodes = new DataSet([ {id: 1, label: '1', group:'Group1'}, {id: 2, label: '2', group:'Group2'}, {id: 3, label: '3', group:'Group3'}, @@ -899,7 +915,7 @@ describe('Clustering', function () { ]); // create an array with edges - var edges = new DataSet([ + const edges = new DataSet([ {from: 1, to: 3}, {from: 1, to: 2}, {from: 2, to: 4}, @@ -907,12 +923,12 @@ describe('Clustering', function () { ]); // create a network - var container = document.getElementById('mynetwork'); - var data = { + const container = document.getElementById('mynetwork'); + const data = { nodes: nodes, edges: edges }; - var options = { + const options = { "groups" : { "Group1" : { level:1 }, "Group2" : { level:2 }, @@ -921,7 +937,7 @@ describe('Clustering', function () { } }; - var network = new Network (container, data, options); + const network = new Network (container, data, options); return network; } @@ -941,15 +957,15 @@ describe('Clustering', function () { * within nodes.clustering; strictly, speaking, the array and its items * are collections, so order should not matter. */ - var collectClusters = function(network) { - var clusters = []; - for(var n in network.body.nodes) { - var node = network.body.nodes[n]; + const collectClusters = function(network) { + const clusters = []; + for(const n in network.body.nodes) { + const node = network.body.nodes[n]; if (node.containedNodes === undefined) continue; // clusters only // Collect id's of nodes in the cluster - var nodes = []; - for(var m in node.containedNodes) { + const nodes = []; + for(const m in node.containedNodes) { nodes.push(m); } clusters.push(nodes); @@ -971,15 +987,15 @@ describe('Clustering', function () { * This comparison depends on the ordering; better * would be to treat the items and values as collections. */ - var compareClusterInfo = function(recieved, expected) { + const compareClusterInfo = function(recieved, expected) { if (recieved.length !== expected.length) return false; - for (var n = 0; n < recieved.length; ++n) { - var itema = recieved[n]; - var itemb = expected[n]; + for (let n = 0; n < recieved.length; ++n) { + const itema = recieved[n]; + const itemb = expected[n]; if (itema.length !== itemb.length) return false; - for (var m = 0; m < itema.length; ++m) { + for (let m = 0; m < itema.length; ++m) { if (itema[m] != itemb[m]) return false; // != because values can be string or number } } @@ -988,10 +1004,10 @@ describe('Clustering', function () { } - var assertJoinCondition = function(joinCondition, expected) { - var network = createOutlierGraph(); + const assertJoinCondition = function(joinCondition, expected) { + const network = createOutlierGraph(); network.clusterOutliers({joinCondition: joinCondition}); - var recieved = collectClusters(network); + const recieved = collectClusters(network); //console.log(recieved); assert(compareClusterInfo(recieved, expected), @@ -1000,14 +1016,11 @@ describe('Clustering', function () { }; - // Should cluster 3,4,5: - var joinAll_ = function(n) { return true ; } - // Should cluster none: - var joinNone_ = function(n) { return false ; } + const joinNone_ = function() { return false ; } // Should cluster 4 & 5: - var joinLevel_ = function(n) { return n.level > 3 ; } + const joinLevel_ = function(n) { return n.level > 3 ; } assertJoinCondition(undefined , [[1,3],[2,4,5]]); assertJoinCondition(null , [[1,3],[2,4,5]]); @@ -1024,7 +1037,9 @@ describe('Clustering', function () { * Helper function, created nested clusters, three deep */ function createNetwork1() { - var [network, data, numNodes, numEdges] = createSampleNetwork(); + const sampleNetwork = createSampleNetwork(); + const [network, data] = sampleNetwork; + let [, , numNodes, numEdges] = sampleNetwork; clusterTo(network, 'c1', [3,4]); numNodes += 1; // new cluster node @@ -1054,7 +1069,7 @@ describe('Clustering', function () { it('opens clusters automatically when nodes deleted', function () { - var [network, data, numNodes, numEdges] = createSampleNetwork(); + let [network, data, numNodes, numEdges] = createSampleNetwork(); // Simple case: cluster of two nodes, delete one node clusterTo(network, 'c1', [3,4]); @@ -1116,7 +1131,7 @@ describe('Clustering', function () { * This is the 'simple' case. */ it('properly opens 1-level clusters', function () { - var [network, data, numNodes, numEdges] = createSampleNetwork(); + let [network, data, numNodes, numEdges] = createSampleNetwork(); assertEdgeLabels(network, data.edges, "New sample network"); // Pedantic: make a cluster of everything @@ -1201,7 +1216,7 @@ describe('Clustering', function () { * The test uses clustering three levels deep and opens the middle one. */ it('properly opens clustered clusters', function () { - var [network, data, numNodes, numEdges] = createSampleNetwork(); + let [network, data, numNodes, numEdges] = createSampleNetwork(); assertEdgeLabels(network, data.edges, "New sample network"); data.edges.update({ from: 1, to: 11, label: "1 to 11" }) @@ -1229,12 +1244,12 @@ describe('Clustering', function () { numEdges -= 1; assertNumNodes(network, numNodes, numNodes - 5); assertNumEdges(network, numEdges, numEdges - 5); - assertEdgeLabels(network, data.edges, "c2 clustered cluster opened") + assertEdgeLabels(network, data.edges, "c2 clustered cluster opened"); // // Same, with one external connection to cluster // - var [network, data, numNodes, numEdges] = createSampleNetwork(); + ([network, data, numNodes, numEdges] = createSampleNetwork()); data.edges.update({from: 1, to: 11, label: "1 to 11"}); data.edges.update({from: 2, to: 12, label: "2 to 12"}); numEdges += 2; @@ -1313,7 +1328,7 @@ describe('on node.js', function () { assert(this.container !== null, 'Container div not found'); // The following should now just plain succeed - var [network, data] = createSampleNetwork(); + const [network] = createSampleNetwork(); assert.equal(Object.keys(network.body.nodes).length, 8); assert.equal(Object.keys(network.body.edges).length, 6); @@ -1324,27 +1339,30 @@ describe('runs example ', function () { function loadExample(path, noPhysics) { include(path, this); - var container = document.getElementById('mynetwork'); + const container = document.getElementById('mynetwork'); // create a network - var data = { + const data = { + /* eslint-disable no-undef */ nodes: new DataSet(nodes), + /* eslint-disable no-undef */ edges: new DataSet(edges) }; if (noPhysics) { // Avoid excessive processor time due to load. // We're just interested that the load itself is good + /* eslint-disable no-undef */ options.physics = false; } - var network = new Network(container, data, options); + const network = new Network(container, data, options); return network; }; it('basicUsage', function () { - var network = loadExample('./test/network/basicUsage.js'); + const network = loadExample('./test/network/basicUsage.js'); //console.log(Object.keys(network.body.edges)); // Count in following also contains the helper nodes for dynamic edges @@ -1357,7 +1375,7 @@ describe('runs example ', function () { // This is a huge example (which is why it's tested here!), so it takes a long time to load. this.timeout(15000); - var network = loadExample('./examples/network/datasources/WorldCup2014.js', true); + const network = loadExample('./examples/network/datasources/WorldCup2014.js', true); // Count in following also contains the helper nodes for dynamic edges assert.equal(Object.keys(network.body.nodes).length, 9964); @@ -1368,7 +1386,7 @@ describe('runs example ', function () { // This actually failed to load, added for this reason it.skip('disassemblerExample (problems since mocha 4)', function () { - var network = loadExample('./examples/network/exampleApplications/disassemblerExample.js'); + const network = loadExample('./examples/network/exampleApplications/disassemblerExample.js'); // console.log(Object.keys(network.body.nodes)); // console.log(Object.keys(network.body.edges)); diff --git a/test/canvas-mock.js b/test/canvas-mock.js index 5136568ee1..32c3a28ac2 100644 --- a/test/canvas-mock.js +++ b/test/canvas-mock.js @@ -3,12 +3,17 @@ * * Adapted from: https://github.com/Cristy94/canvas-mock */ -var jsdom = require('jsdom'); -var jsdom_global = require('jsdom-global'); +const jsdom = require('jsdom'); +const jsdom_global = require('jsdom-global'); -var canvasMock; // Use one canvas instance for all calls to createElement('canvas'); +let canvasMock; // Use one canvas instance for all calls to createElement('canvas'); +/** + * Replace element's getContext method with a do nothing mock. + * + * @param {HTMLElement} el - The element whose getContext will be mocked. + */ function replaceCanvasContext (el) { el.getContext = function() { return { @@ -68,12 +73,12 @@ function replaceCanvasContext (el) { * @private */ function overrideCreateElement(window) { - var d = window.document; - var f = window.document.createElement; + const d = window.document; + const f = window.document.createElement; // Check if 2D context already present. That happens either when running in a browser, // or this is node.js with 'canvas' installed. - var ctx = d.createElement('canvas').getContext('2d'); + const ctx = d.createElement('canvas').getContext('2d'); if (ctx !== null && ctx !== undefined) { //console.log('2D context is present, no need to override'); return; @@ -102,12 +107,12 @@ function overrideCreateElement(window) { * @private */ function overrideCreateElementNS(window) { - var d = window.document; - var f = window.document.createElementNS; + const d = window.document; + const f = window.document.createElementNS; window.document.createElementNS = function(namespaceURI, qualifiedName) { if (namespaceURI === 'http://www.w3.org/2000/svg') { - var result = f.call(d, namespaceURI, qualifiedName); + const result = f.call(d, namespaceURI, qualifiedName); if (result.style == undefined) { result.style = {}; return result; @@ -127,20 +132,20 @@ function overrideCreateElementNS(window) { */ function mockify(html = '') { // Start of message that we want to suppress. - let msg = 'Error: Not implemented: HTMLCanvasElement.prototype.getContext' + const consoleErrorMessageToSuppress = 'Error: Not implemented: HTMLCanvasElement.prototype.getContext' + ' (without installing the canvas npm package)'; // Override default virtual console of jsdom const virtualConsole = new jsdom.VirtualConsole(); // Set up a simple 'mock' console output. Only 'error' needs to be overridden - let myConsole = { - error: (msg) => { - if (msg.indexOf(msg) === 0) { + const myConsole = { + error: (message) => { + if (message.indexOf(consoleErrorMessageToSuppress) === 0) { //console.error('all is well'); } else { // All other messages pass through - console.error(msg); + console.error(consoleErrorMessageToSuppress); } } }; @@ -148,7 +153,7 @@ function mockify(html = '') { // Using the global catch instead of specific event handler, because I couldn't get them to work virtualConsole.sendTo(myConsole); - let cleanupFunction = jsdom_global( + const cleanupFunction = jsdom_global( html, { skipWindowCheck: true, virtualConsole: virtualConsole} ); diff --git a/test/dotparser.test.js b/test/dotparser.test.js index c9c6412b6e..b48ba22841 100644 --- a/test/dotparser.test.js +++ b/test/dotparser.test.js @@ -1,4 +1,4 @@ -var assert = require('assert'), +const assert = require('assert'), fs = require('fs'), dot = require('../lib/network/dotparser.js'); @@ -8,7 +8,7 @@ describe('dotparser', function () { fs.readFile('test/dot.txt', function (err, data) { data = String(data); - var graph = dot.parseDOT(data); + const graph = dot.parseDOT(data); assert.deepEqual(graph, { "type": "digraph", @@ -188,11 +188,11 @@ describe('dotparser', function () { * DOT-format examples taken from #3015 */ it('properly handles newline escape sequences in strings', function (done) { - var data = 'dinetwork {1 [label="new\\nline"];}'; + let data = 'dinetwork {1 [label="new\\nline"];}'; data = String(data); - var graph = dot.parseDOT(data); + const graph = dot.parseDOT(data); assert.deepEqual(graph, { "id": "dinetwork", @@ -208,7 +208,7 @@ describe('dotparser', function () { // Note the double backslashes - var data2 = 'digraph {' + "\n" + + let data2 = 'digraph {' + "\n" + ' 3 [color="#0d2b7c", label="query:1230:add_q\\n0.005283\\n6.83%\\n(0.0001)\\n(0.13%)\\n17×"];' + "\n" + ' 3 -> 7 [color="#0d2a7b", fontcolor="#0d2a7b", label="0.005128\\n6.63%\\n17×"];' + "\n" + ' 5 [color="#0d1976", label="urlresolvers:537:reverse\\n0.00219\\n2.83%\\n(0.000193)\\n(0.25%)\\n29×"];' + "\n" + @@ -216,7 +216,7 @@ describe('dotparser', function () { data2 = String(data2); - var graph2 = dot.parseDOT(data2); + const graph2 = dot.parseDOT(data2); //console.log(JSON.stringify(graph, null, 2)); assert.deepEqual(graph2, { diff --git a/test/network/basicUsage.js b/test/network/basicUsage.js index 85808210ad..e6701cc712 100644 --- a/test/network/basicUsage.js +++ b/test/network/basicUsage.js @@ -1,3 +1,8 @@ +// These variables will be injected into a function that will use them. +/* eslint no-unused-vars: "off" */ +// Const won't work here, only var. +/* eslint no-var: "off" */ + // Network from `basicUsage` example // create an array with nodes diff --git a/tsconfig.code.json b/tsconfig.code.json index 713b5fc205..4603e2efe6 100644 --- a/tsconfig.code.json +++ b/tsconfig.code.json @@ -3,5 +3,5 @@ "compilerOptions": { "noImplicitAny": false }, - "exclude": ["test"] + "include": ["lib"] } diff --git a/tsconfig.declarations.json b/tsconfig.declarations.json index 79e8a6c772..3728ad158c 100644 --- a/tsconfig.declarations.json +++ b/tsconfig.declarations.json @@ -7,5 +7,5 @@ "emitDeclarationOnly": true, "noImplicitAny": false }, - "exclude": ["cypress", "test"] + "include": ["lib"] } diff --git a/tsconfig.json b/tsconfig.json index 82ced6c357..0f7ceceaac 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -13,6 +13,5 @@ "strict": true, "target": "esnext" }, - "exclude": ["node_modules", "**/__tests__/*"], - "include": ["cypress", "lib", "test"] + "exclude": ["node_modules", "**/__tests__/*"] } diff --git a/tsconfig.lint.json b/tsconfig.lint.json new file mode 100644 index 0000000000..289d9dfa08 --- /dev/null +++ b/tsconfig.lint.json @@ -0,0 +1,4 @@ +{ + "extends": "./tsconfig", + "include": [".*.js", ".*.json", ".*.ts", "**/*.js", "**/*.json", "**/*.ts"] +} diff --git a/tsconfig.types.json b/tsconfig.types.json index 5c82e0795b..f18ad4d07d 100644 --- a/tsconfig.types.json +++ b/tsconfig.types.json @@ -7,5 +7,5 @@ "emitDeclarationOnly": true, "noImplicitAny": false }, - "exclude": ["cypress", "test"] + "include": ["lib"] }