แก้ coding style ภาค 2
This commit is contained in:
32
.eslintrc
32
.eslintrc
@@ -2,14 +2,40 @@ parserOptions:
|
||||
sourceType: module
|
||||
|
||||
extends:
|
||||
"eslint:recommended"
|
||||
|
||||
"standard"
|
||||
rules:
|
||||
no-cond-assign: 0
|
||||
no-console: 0
|
||||
|
||||
semi:
|
||||
- error
|
||||
- always
|
||||
/*
|
||||
no-extra-parens: 1
|
||||
curly: 0
|
||||
block-scoped-var: 1
|
||||
no-tabs: 1
|
||||
no-negated-condition: 1
|
||||
block-spacing: 1
|
||||
brace-style: 1
|
||||
comma-spacing: 1
|
||||
comma-style: 1
|
||||
eol-last: 1
|
||||
func-call-spacing: 1
|
||||
indent:
|
||||
- error
|
||||
- 2
|
||||
key-spacing: 1
|
||||
linebreak-style: 1
|
||||
no-lonely-if: 1
|
||||
*/
|
||||
env:
|
||||
es6: true
|
||||
|
||||
globals:
|
||||
console: false
|
||||
/*
|
||||
plugins:
|
||||
- import
|
||||
- node
|
||||
- promise
|
||||
*/
|
||||
|
||||
12
index.js
12
index.js
@@ -1,17 +1,17 @@
|
||||
export {default as forceNeighbourSampling}
|
||||
from "./src/neighbourSampling";
|
||||
from './src/neighbourSampling';
|
||||
|
||||
export { default as forceBarnesHut}
|
||||
from "./src/barnesHut";
|
||||
from './src/barnesHut';
|
||||
|
||||
export { default as tSNE}
|
||||
from "./src/t-sne";
|
||||
from './src/t-sne';
|
||||
|
||||
export { default as forceLinkCompleteGraph}
|
||||
from "./src/link";
|
||||
from './src/link';
|
||||
|
||||
export { default as hybridSimulation}
|
||||
from "./src/hybridSimulation";
|
||||
from './src/hybridSimulation';
|
||||
|
||||
export { getStress as calculateStress }
|
||||
from "./src/stress";
|
||||
from './src/stress';
|
||||
|
||||
@@ -19,6 +19,11 @@
|
||||
},
|
||||
"devDependencies": {
|
||||
"eslint": "4",
|
||||
"eslint-config-standard": "^11.0.0",
|
||||
"eslint-plugin-import": "^2.9.0",
|
||||
"eslint-plugin-node": "^6.0.1",
|
||||
"eslint-plugin-promise": "^3.7.0",
|
||||
"eslint-plugin-standard": "^3.0.1",
|
||||
"rollup": "0.36",
|
||||
"uglify-js": "git+https://github.com/mishoo/UglifyJS2.git#harmony"
|
||||
},
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import constant from "./constant";
|
||||
import jiggle from "./jiggle";
|
||||
import {x, y} from "./xy";
|
||||
import {quadtree} from "d3-quadtree";
|
||||
import constant from './constant';
|
||||
import jiggle from './jiggle';
|
||||
import {x, y} from './xy';
|
||||
import {quadtree} from 'd3-quadtree';
|
||||
|
||||
/**
|
||||
* The refinement of the existing Barnes-Hut implementation in D3
|
||||
@@ -70,7 +70,6 @@ export default function() {
|
||||
* @return {boolean} - true if the approximation was applied.
|
||||
*/
|
||||
function apply (quad, x1, _, x2) {
|
||||
|
||||
var x = quad.data.x + quad.data.vx - node.x - node.vx,
|
||||
y = quad.data.y + quad.data.vy - node.y - node.vy,
|
||||
w = x2 - x1,
|
||||
@@ -98,13 +97,15 @@ export default function() {
|
||||
if (y === 0) y = jiggle(), l += y * y;
|
||||
}
|
||||
|
||||
do if (quad.data !== node) {
|
||||
do {
|
||||
if (quad.data !== node) {
|
||||
l = (l - +distance(node, quad.data)) / l * alpha;
|
||||
x *= l, y *= l;
|
||||
quad.data.vx -= x;
|
||||
quad.data.vy -= y;
|
||||
node.vx += x;
|
||||
node.vy += y;
|
||||
}
|
||||
} while (quad = quad.next);
|
||||
}
|
||||
|
||||
@@ -137,7 +138,7 @@ export default function() {
|
||||
};
|
||||
|
||||
force.distance = function (_) {
|
||||
return arguments.length ? (distance = typeof _ === "function" ? _ : constant(+_), force) : distance;
|
||||
return arguments.length ? (distance = typeof _ === 'function' ? _ : constant(+_), force) : distance;
|
||||
};
|
||||
|
||||
force.theta = function (_) {
|
||||
|
||||
10
src/link.js
10
src/link.js
@@ -1,5 +1,5 @@
|
||||
import constant from "./constant";
|
||||
import jiggle from "./jiggle";
|
||||
import constant from './constant';
|
||||
import jiggle from './jiggle';
|
||||
|
||||
/**
|
||||
* Modified link force algorithm
|
||||
@@ -32,7 +32,8 @@ export default function() {
|
||||
// Each iteration in a tick
|
||||
for (var k = 0, source, target, i, j, x, y, l; k < iterations; ++k) {
|
||||
// For each link
|
||||
for (i = 1; i < n; i++) for (j = 0; j < i; j++) {
|
||||
for (i = 1; i < n; i++) {
|
||||
for (j = 0; j < i; j++) {
|
||||
// jiggle so l won't be zero and divide by zero error after this
|
||||
source = nodes[i];
|
||||
target = nodes[j];
|
||||
@@ -47,6 +48,7 @@ export default function() {
|
||||
source.vy += y;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Calculate velocity changes, aka force applied.
|
||||
if (stableVeloHandler !== null && stableVelocity >= 0) {
|
||||
@@ -90,7 +92,7 @@ export default function() {
|
||||
};
|
||||
|
||||
force.distance = function (_) {
|
||||
return arguments.length ? (distance = typeof _ === "function" ? _ : constant(+_), initializeDistance(), force) : distance;
|
||||
return arguments.length ? (distance = typeof _ === 'function' ? _ : constant(+_), initializeDistance(), force) : distance;
|
||||
};
|
||||
|
||||
force.latestAccel = function () {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import constant from "./constant";
|
||||
import jiggle from "./jiggle";
|
||||
import constant from './constant';
|
||||
import jiggle from './jiggle';
|
||||
/**
|
||||
* An implementation of Chalmers' 1996 Neighbour and Sampling algorithm.
|
||||
* It uses random sampling to find the most suited neighbours from the
|
||||
@@ -166,7 +166,6 @@ export default function () {
|
||||
return new Map(combined.slice(0, neighbourSize));
|
||||
}
|
||||
|
||||
|
||||
// API for initializing the algorithm and setting parameters
|
||||
force.initialize = function (_) {
|
||||
nodes = _;
|
||||
@@ -186,7 +185,7 @@ export default function () {
|
||||
};
|
||||
|
||||
force.distance = function (_) {
|
||||
return arguments.length ? (distance = typeof _ === "function" ? _ : constant(+_), force) : distance;
|
||||
return arguments.length ? (distance = typeof _ === 'function' ? _ : constant(+_), force) : distance;
|
||||
};
|
||||
|
||||
force.latestAccel = function () {
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
* @return {number} - stress of the layout.
|
||||
*/
|
||||
export function getStress (nodes, distance) {
|
||||
let sumDiffSq = 0
|
||||
let sumDiffSq = 0;
|
||||
let sumLowDDistSq = 0;
|
||||
for (let j = nodes.length - 1; j >= 1; j--) {
|
||||
for (let i = 0; i < j; i++) {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/* eslint-disable block-scoped-var */
|
||||
import constant from "./constant";
|
||||
import constant from './constant';
|
||||
|
||||
/**
|
||||
* Set the node id accessor to the specified i.
|
||||
@@ -161,7 +161,6 @@ export default function() {
|
||||
} else {
|
||||
beta = (beta + betamax) / 2;
|
||||
}
|
||||
|
||||
} else {
|
||||
// Converse case. Make distrubtion less peaky.
|
||||
betamax = beta;
|
||||
@@ -183,7 +182,6 @@ export default function() {
|
||||
for (j = 0; j < N; j++) {
|
||||
P1[i * N + j] = prow[j];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// Symmetrize P and normalize it to sum to 1 over all ij
|
||||
@@ -270,7 +268,6 @@ export default function() {
|
||||
* @return {object} that contains a cost and a gradient.
|
||||
*/
|
||||
function costGrad (Y) {
|
||||
|
||||
var pmul = iteration < 100 ? 4 : 1;
|
||||
|
||||
// Compute current Q distribution, unnormalized first.
|
||||
@@ -358,7 +355,7 @@ export default function() {
|
||||
};
|
||||
|
||||
force.distance = function (_) {
|
||||
return arguments.length ? (distance = typeof _ === "function" ? _ : constant(+_), force) : distance;
|
||||
return arguments.length ? (distance = typeof _ === 'function' ? _ : constant(+_), force) : distance;
|
||||
};
|
||||
|
||||
force.stress = function () {
|
||||
|
||||
Reference in New Issue
Block a user