eslint and use AutoLayout

This commit is contained in:
Devin Howard 2016-10-01 12:43:02 +08:00
parent fdf03ac83a
commit 4949f0dbd6
2 changed files with 8 additions and 19 deletions

View file

@ -4,6 +4,7 @@ import parse from 'csv-parse'
import _ from 'lodash' import _ from 'lodash'
import Active from './Active' import Active from './Active'
import AutoLayout from './AutoLayout'
import GlobalUI from './GlobalUI' import GlobalUI from './GlobalUI'
import Map from './Map' import Map from './Map'
import Synapse from './Synapse' import Synapse from './Synapse'
@ -40,9 +41,9 @@ const Import = {
const topicsRegex = /("?Topics"?)([\s\S]*)/mi const topicsRegex = /("?Topics"?)([\s\S]*)/mi
const synapsesRegex = /("?Synapses"?)([\s\S]*)/mi const synapsesRegex = /("?Synapses"?)([\s\S]*)/mi
let topicsText = text.match(topicsRegex) || "" let topicsText = text.match(topicsRegex) || ''
if (topicsText) topicsText = topicsText[2].replace(synapsesRegex, '') if (topicsText) topicsText = topicsText[2].replace(synapsesRegex, '')
let synapsesText = text.match(synapsesRegex) || "" let synapsesText = text.match(synapsesRegex) || ''
if (synapsesText) synapsesText = synapsesText[2].replace(topicsRegex, '') if (synapsesText) synapsesText = synapsesText[2].replace(topicsRegex, '')
// merge default options and extra options passed in parserOpts argument // merge default options and extra options passed in parserOpts argument
@ -223,31 +224,19 @@ const Import = {
importTopics: function (parsedTopics) { importTopics: function (parsedTopics) {
var self = Import var self = Import
// up to 25 topics: scale 100
// up to 81 topics: scale 200
// up to 169 topics: scale 300
var scale = Math.floor((Math.sqrt(parsedTopics.length) - 1) / 4) * 100
if (scale < 100) scale = 100
var autoX = -scale
var autoY = -scale
parsedTopics.forEach(function (topic) { parsedTopics.forEach(function (topic) {
var x, y var x, y
if (topic.x && topic.y) { if (topic.x && topic.y) {
x = topic.x x = topic.x
y = topic.y y = topic.y
} else { } else {
x = autoX const coords = AutoLayout.getNextCoord()
y = autoY x = coords.x
autoX += 50 y = coords.y
if (autoX > scale) {
autoY += 50
autoX = -scale
}
} }
if (topic.name && topic.link && !topic.metacode) { if (topic.name && topic.link && !topic.metacode) {
topic.metacode = "Reference" topic.metacode = 'Reference'
} }
self.createTopicWithParameters( self.createTopicWithParameters(

View file

@ -26,7 +26,7 @@ const config = module.exports = {
test: /\.(js|jsx)?$/, test: /\.(js|jsx)?$/,
exclude: /node_modules/, exclude: /node_modules/,
loaders: [ loaders: [
"babel-loader?cacheDirectory&retainLines=true" 'babel-loader?cacheDirectory&retainLines=true'
] ]
} }
] ]