From bb013787b6eb65298bc466674f0c9dd6df07442e Mon Sep 17 00:00:00 2001 From: Devin Howard Date: Sat, 1 Oct 2016 13:34:52 +0800 Subject: [PATCH] make AutoLayout skip over coordinates if there is a mapping at that exact position --- frontend/src/Metamaps/AutoLayout.js | 23 +++++++++++++++++++---- frontend/src/Metamaps/Import.js | 4 ++-- 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/frontend/src/Metamaps/AutoLayout.js b/frontend/src/Metamaps/AutoLayout.js index ee9dc33c..e0835473 100644 --- a/frontend/src/Metamaps/AutoLayout.js +++ b/frontend/src/Metamaps/AutoLayout.js @@ -1,3 +1,5 @@ +import Active from './Active' + const AutoLayout = { nextX: 0, nextY: 0, @@ -7,7 +9,7 @@ const AutoLayout = { nextYshift: 0, timeToTurn: 0, - getNextCoord: function () { + getNextCoord: function (opts = {}) { var self = AutoLayout var nextX = self.nextX var nextY = self.nextY @@ -49,9 +51,22 @@ const AutoLayout = { } } - return { - x: nextX, - y: nextY + if (opts.map && self.coordsTaken(nextX, nextY, opts.map)) { + // check if the coordinate is already taken on the current map + return self.getNextCoord(opts) + } else { + return { + x: nextX, + y: nextY + } + } + }, + coordsTaken: function(x, y, map) { + const mappings = map.getMappings() + if (mappings.findWhere({ xloc: x, yloc: y })) { + return true + } else { + return false } }, resetSpiral: function () { diff --git a/frontend/src/Metamaps/Import.js b/frontend/src/Metamaps/Import.js index 2de7ca02..5d5f91a7 100644 --- a/frontend/src/Metamaps/Import.js +++ b/frontend/src/Metamaps/Import.js @@ -227,7 +227,7 @@ const Import = { parsedTopics.forEach(function (topic) { let coords = { x: topic.x, y: topic.y } if (!coords.x || !coords.y) { - coords = AutoLayout.getNextCoord() + coords = AutoLayout.getNextCoord({ map: Active.Map }) } if (!topic.name && topic.link || @@ -349,7 +349,7 @@ const Import = { handleURL: function (url, opts = {}) { let coords = opts.coords if (!coords || coords.x === undefined || coords.y === undefined) { - coords = AutoLayout.getNextCoord() + coords = AutoLayout.getNextCoord({ map: Active.Map }) } const name = opts.name || 'Link'