แก้ coding style ภาค 2

This commit is contained in:
Pitchaya Boonsarngsuk
2018-03-22 16:12:25 +00:00
parent 2256af7448
commit 0cdd927444
12 changed files with 160 additions and 130 deletions

View File

@@ -2,14 +2,40 @@ parserOptions:
sourceType: module sourceType: module
extends: extends:
"eslint:recommended" "standard"
rules: rules:
no-cond-assign: 0 no-cond-assign: 0
no-console: 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: env:
es6: true es6: true
globals: globals:
console: false console: false
/*
plugins:
- import
- node
- promise
*/

View File

@@ -1,17 +1,17 @@
export {default as forceNeighbourSampling} export {default as forceNeighbourSampling}
from "./src/neighbourSampling"; from './src/neighbourSampling';
export { default as forceBarnesHut} export { default as forceBarnesHut}
from "./src/barnesHut"; from './src/barnesHut';
export { default as tSNE} export { default as tSNE}
from "./src/t-sne"; from './src/t-sne';
export { default as forceLinkCompleteGraph} export { default as forceLinkCompleteGraph}
from "./src/link"; from './src/link';
export { default as hybridSimulation} export { default as hybridSimulation}
from "./src/hybridSimulation"; from './src/hybridSimulation';
export { getStress as calculateStress } export { getStress as calculateStress }
from "./src/stress"; from './src/stress';

View File

@@ -19,6 +19,11 @@
}, },
"devDependencies": { "devDependencies": {
"eslint": "4", "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", "rollup": "0.36",
"uglify-js": "git+https://github.com/mishoo/UglifyJS2.git#harmony" "uglify-js": "git+https://github.com/mishoo/UglifyJS2.git#harmony"
}, },

View File

@@ -1,7 +1,7 @@
import constant from "./constant"; import constant from './constant';
import jiggle from "./jiggle"; import jiggle from './jiggle';
import {x, y} from "./xy"; import {x, y} from './xy';
import {quadtree} from "d3-quadtree"; import {quadtree} from 'd3-quadtree';
/** /**
* The refinement of the existing Barnes-Hut implementation in D3 * 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. * @return {boolean} - true if the approximation was applied.
*/ */
function apply (quad, x1, _, x2) { function apply (quad, x1, _, x2) {
var x = quad.data.x + quad.data.vx - node.x - node.vx, var x = quad.data.x + quad.data.vx - node.x - node.vx,
y = quad.data.y + quad.data.vy - node.y - node.vy, y = quad.data.y + quad.data.vy - node.y - node.vy,
w = x2 - x1, w = x2 - x1,
@@ -98,13 +97,15 @@ export default function() {
if (y === 0) y = jiggle(), l += y * y; 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; l = (l - +distance(node, quad.data)) / l * alpha;
x *= l, y *= l; x *= l, y *= l;
quad.data.vx -= x; quad.data.vx -= x;
quad.data.vy -= y; quad.data.vy -= y;
node.vx += x; node.vx += x;
node.vy += y; node.vy += y;
}
} while (quad = quad.next); } while (quad = quad.next);
} }
@@ -137,7 +138,7 @@ export default function() {
}; };
force.distance = 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 (_) { force.theta = function (_) {

View File

@@ -1,5 +1,5 @@
import constant from "./constant"; import constant from './constant';
import jiggle from "./jiggle"; import jiggle from './jiggle';
/** /**
* Modified link force algorithm * Modified link force algorithm
@@ -32,7 +32,8 @@ export default function() {
// Each iteration in a tick // Each iteration in a tick
for (var k = 0, source, target, i, j, x, y, l; k < iterations; ++k) { for (var k = 0, source, target, i, j, x, y, l; k < iterations; ++k) {
// For each link // 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 // jiggle so l won't be zero and divide by zero error after this
source = nodes[i]; source = nodes[i];
target = nodes[j]; target = nodes[j];
@@ -47,6 +48,7 @@ export default function() {
source.vy += y; source.vy += y;
} }
} }
}
// Calculate velocity changes, aka force applied. // Calculate velocity changes, aka force applied.
if (stableVeloHandler !== null && stableVelocity >= 0) { if (stableVeloHandler !== null && stableVelocity >= 0) {
@@ -90,7 +92,7 @@ export default function() {
}; };
force.distance = 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 () { force.latestAccel = function () {

View File

@@ -1,5 +1,5 @@
import constant from "./constant"; import constant from './constant';
import jiggle from "./jiggle"; import jiggle from './jiggle';
/** /**
* An implementation of Chalmers' 1996 Neighbour and Sampling algorithm. * An implementation of Chalmers' 1996 Neighbour and Sampling algorithm.
* It uses random sampling to find the most suited neighbours from the * 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)); return new Map(combined.slice(0, neighbourSize));
} }
// API for initializing the algorithm and setting parameters // API for initializing the algorithm and setting parameters
force.initialize = function (_) { force.initialize = function (_) {
nodes = _; nodes = _;
@@ -186,7 +185,7 @@ export default function () {
}; };
force.distance = 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 () { force.latestAccel = function () {

View File

@@ -5,7 +5,7 @@
* @return {number} - stress of the layout. * @return {number} - stress of the layout.
*/ */
export function getStress (nodes, distance) { export function getStress (nodes, distance) {
let sumDiffSq = 0 let sumDiffSq = 0;
let sumLowDDistSq = 0; let sumLowDDistSq = 0;
for (let j = nodes.length - 1; j >= 1; j--) { for (let j = nodes.length - 1; j >= 1; j--) {
for (let i = 0; i < j; i++) { for (let i = 0; i < j; i++) {

View File

@@ -1,5 +1,5 @@
/* eslint-disable block-scoped-var */ /* eslint-disable block-scoped-var */
import constant from "./constant"; import constant from './constant';
/** /**
* Set the node id accessor to the specified i. * Set the node id accessor to the specified i.
@@ -161,7 +161,6 @@ export default function() {
} else { } else {
beta = (beta + betamax) / 2; beta = (beta + betamax) / 2;
} }
} else { } else {
// Converse case. Make distrubtion less peaky. // Converse case. Make distrubtion less peaky.
betamax = beta; betamax = beta;
@@ -183,7 +182,6 @@ export default function() {
for (j = 0; j < N; j++) { for (j = 0; j < N; j++) {
P1[i * N + j] = prow[j]; P1[i * N + j] = prow[j];
} }
} }
// Symmetrize P and normalize it to sum to 1 over all ij // 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. * @return {object} that contains a cost and a gradient.
*/ */
function costGrad (Y) { function costGrad (Y) {
var pmul = iteration < 100 ? 4 : 1; var pmul = iteration < 100 ? 4 : 1;
// Compute current Q distribution, unnormalized first. // Compute current Q distribution, unnormalized first.
@@ -358,7 +355,7 @@ export default function() {
}; };
force.distance = 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 () { force.stress = function () {