move some variables into JIT

This commit is contained in:
Devin Howard 2016-09-22 17:08:53 +08:00
parent 8f100d99cb
commit 9c1543de64
3 changed files with 37 additions and 41 deletions

View file

@ -3,11 +3,6 @@ window.Metamaps = window.Metamaps || {}
// TODO everything in this file should be moved into one of the other modules // TODO everything in this file should be moved into one of the other modules
// Either as a local constant, or as a local constant with a globally available getter/setter // Either as a local constant, or as a local constant with a globally available getter/setter
Metamaps.tempNode = null
Metamaps.tempInit = false
Metamaps.tempNode2 = null
Metamaps.Maps = Metamaps.Maps || {} Metamaps.Maps = Metamaps.Maps || {}
Metamaps.Settings = { Metamaps.Settings = {

View file

@ -3,6 +3,10 @@
let panningInt let panningInt
const JIT = { const JIT = {
tempInit: false,
tempNode: null,
tempNode2: null,
events: { events: {
topicDrag: 'Metamaps:JIT:events:topicDrag', topicDrag: 'Metamaps:JIT:events:topicDrag',
newTopic: 'Metamaps:JIT:events:newTopic', newTopic: 'Metamaps:JIT:events:newTopic',
@ -795,9 +799,9 @@ const JIT = {
} }
// if it's a right click or holding down alt, start synapse creation ->third option is for firefox // if it's a right click or holding down alt, start synapse creation ->third option is for firefox
else if ((e.button == 2 || (e.button == 0 && e.altKey) || e.buttons == 2) && authorized) { else if ((e.button == 2 || (e.button == 0 && e.altKey) || e.buttons == 2) && authorized) {
if (Metamaps.tempInit == false) { if (JIT.tempInit == false) {
Metamaps.tempNode = node JIT.tempNode = node
Metamaps.tempInit = true JIT.tempInit = true
Metamaps.Create.newTopic.hide() Metamaps.Create.newTopic.hide()
Metamaps.Create.newSynapse.hide() Metamaps.Create.newSynapse.hide()
@ -813,8 +817,8 @@ const JIT = {
} }
} else { } else {
Metamaps.Mouse.synapseStartCoordinates = [{ Metamaps.Mouse.synapseStartCoordinates = [{
x: Metamaps.tempNode.pos.getc().x, x: JIT.tempNode.pos.getc().x,
y: Metamaps.tempNode.pos.getc().y y: JIT.tempNode.pos.getc().y
}] }]
} }
Metamaps.Mouse.synapseEndCoordinates = { Metamaps.Mouse.synapseEndCoordinates = {
@ -825,11 +829,11 @@ const JIT = {
// //
let temp = eventInfo.getNode() let temp = eventInfo.getNode()
if (temp != false && temp.id != node.id && Metamaps.Selected.Nodes.indexOf(temp) == -1) { // this means a Node has been returned if (temp != false && temp.id != node.id && Metamaps.Selected.Nodes.indexOf(temp) == -1) { // this means a Node has been returned
Metamaps.tempNode2 = temp JIT.tempNode2 = temp
Metamaps.Mouse.synapseEndCoordinates = { Metamaps.Mouse.synapseEndCoordinates = {
x: Metamaps.tempNode2.pos.getc().x, x: JIT.tempNode2.pos.getc().x,
y: Metamaps.tempNode2.pos.getc().y y: JIT.tempNode2.pos.getc().y
} }
// before making the highlighted one bigger, make sure all the others are regular size // before making the highlighted one bigger, make sure all the others are regular size
@ -839,7 +843,7 @@ const JIT = {
temp.setData('dim', 35, 'current') temp.setData('dim', 35, 'current')
Metamaps.Visualize.mGraph.plot() Metamaps.Visualize.mGraph.plot()
} else if (!temp) { } else if (!temp) {
Metamaps.tempNode2 = null JIT.tempNode2 = null
Metamaps.Visualize.mGraph.graph.eachNode(function (n) { Metamaps.Visualize.mGraph.graph.eachNode(function (n) {
n.setData('dim', 25, 'current') n.setData('dim', 25, 'current')
}) })
@ -867,10 +871,10 @@ const JIT = {
} }
}, // onDragMoveTopicHandler }, // onDragMoveTopicHandler
onDragCancelHandler: function (node, eventInfo, e) { onDragCancelHandler: function (node, eventInfo, e) {
Metamaps.tempNode = null JIT.tempNode = null
if (Metamaps.tempNode2) Metamaps.tempNode2.setData('dim', 25, 'current') if (JIT.tempNode2) JIT.tempNode2.setData('dim', 25, 'current')
Metamaps.tempNode2 = null JIT.tempNode2 = null
Metamaps.tempInit = false JIT.tempInit = false
// reset the draw synapse positions to false // reset the draw synapse positions to false
Metamaps.Mouse.synapseStartCoordinates = [] Metamaps.Mouse.synapseStartCoordinates = []
Metamaps.Mouse.synapseEndCoordinates = null Metamaps.Mouse.synapseEndCoordinates = null
@ -879,27 +883,27 @@ const JIT = {
onDragEndTopicHandler: function (node, eventInfo, e) { onDragEndTopicHandler: function (node, eventInfo, e) {
var midpoint = {}, pixelPos, mapping var midpoint = {}, pixelPos, mapping
if (Metamaps.tempInit && Metamaps.tempNode2 == null) { if (JIT.tempInit && JIT.tempNode2 == null) {
// this means you want to add a new topic, and then a synapse // this means you want to add a new topic, and then a synapse
Metamaps.Create.newTopic.addSynapse = true Metamaps.Create.newTopic.addSynapse = true
Metamaps.Create.newTopic.open() Metamaps.Create.newTopic.open()
} else if (Metamaps.tempInit && Metamaps.tempNode2 != null) { } else if (JIT.tempInit && JIT.tempNode2 != null) {
// this means you want to create a synapse between two existing topics // this means you want to create a synapse between two existing topics
Metamaps.Create.newTopic.addSynapse = false Metamaps.Create.newTopic.addSynapse = false
Metamaps.Create.newSynapse.topic1id = Metamaps.tempNode.getData('topic').id Metamaps.Create.newSynapse.topic1id = JIT.tempNode.getData('topic').id
Metamaps.Create.newSynapse.topic2id = Metamaps.tempNode2.getData('topic').id Metamaps.Create.newSynapse.topic2id = JIT.tempNode2.getData('topic').id
Metamaps.tempNode2.setData('dim', 25, 'current') JIT.tempNode2.setData('dim', 25, 'current')
Metamaps.Visualize.mGraph.plot() Metamaps.Visualize.mGraph.plot()
midpoint.x = Metamaps.tempNode.pos.getc().x + (Metamaps.tempNode2.pos.getc().x - Metamaps.tempNode.pos.getc().x) / 2 midpoint.x = JIT.tempNode.pos.getc().x + (JIT.tempNode2.pos.getc().x - JIT.tempNode.pos.getc().x) / 2
midpoint.y = Metamaps.tempNode.pos.getc().y + (Metamaps.tempNode2.pos.getc().y - Metamaps.tempNode.pos.getc().y) / 2 midpoint.y = JIT.tempNode.pos.getc().y + (JIT.tempNode2.pos.getc().y - JIT.tempNode.pos.getc().y) / 2
pixelPos = Metamaps.Util.coordsToPixels(midpoint) pixelPos = Metamaps.Util.coordsToPixels(midpoint)
$('#new_synapse').css('left', pixelPos.x + 'px') $('#new_synapse').css('left', pixelPos.x + 'px')
$('#new_synapse').css('top', pixelPos.y + 'px') $('#new_synapse').css('top', pixelPos.y + 'px')
Metamaps.Create.newSynapse.open() Metamaps.Create.newSynapse.open()
Metamaps.tempNode = null JIT.tempNode = null
Metamaps.tempNode2 = null JIT.tempNode2 = null
Metamaps.tempInit = false JIT.tempInit = false
} else if (!Metamaps.tempInit && node && !node.nodeFrom) { } else if (!JIT.tempInit && node && !node.nodeFrom) {
// this means you dragged an existing node, autosave that to the database // this means you dragged an existing node, autosave that to the database
// check whether to save mappings // check whether to save mappings
@ -977,9 +981,9 @@ const JIT = {
// reset the draw synapse positions to false // reset the draw synapse positions to false
Metamaps.Mouse.synapseStartCoordinates = [] Metamaps.Mouse.synapseStartCoordinates = []
Metamaps.Mouse.synapseEndCoordinates = null Metamaps.Mouse.synapseEndCoordinates = null
Metamaps.tempInit = false JIT.tempInit = false
Metamaps.tempNode = null JIT.tempNode = null
Metamaps.tempNode2 = null JIT.tempNode2 = null
if (!e.ctrlKey && !e.shiftKey) { if (!e.ctrlKey && !e.shiftKey) {
Metamaps.Control.deselectAllEdges() Metamaps.Control.deselectAllEdges()
Metamaps.Control.deselectAllNodes() Metamaps.Control.deselectAllNodes()

View file

@ -22,9 +22,6 @@
* - Metamaps.Topics * - Metamaps.Topics
* - Metamaps.Util * - Metamaps.Util
* - Metamaps.Visualize * - Metamaps.Visualize
* - Metamaps.tempInit
* - Metamaps.tempNode
* - Metamaps.tempNode2
*/ */
const Topic = { const Topic = {
@ -218,11 +215,11 @@ const Topic = {
nodeOnViz.setPos(new $jit.Complex(mapping.get('xloc'), mapping.get('yloc')), 'end') nodeOnViz.setPos(new $jit.Complex(mapping.get('xloc'), mapping.get('yloc')), 'end')
} }
if (Metamaps.Create.newTopic.addSynapse && permitCreateSynapseAfter) { if (Metamaps.Create.newTopic.addSynapse && permitCreateSynapseAfter) {
Metamaps.Create.newSynapse.topic1id = Metamaps.tempNode.getData('topic').id Metamaps.Create.newSynapse.topic1id = JIT.tempNode.getData('topic').id
// position the form // position the form
midpoint.x = Metamaps.tempNode.pos.getc().x + (nodeOnViz.pos.getc().x - Metamaps.tempNode.pos.getc().x) / 2 midpoint.x = JIT.tempNode.pos.getc().x + (nodeOnViz.pos.getc().x - JIT.tempNode.pos.getc().x) / 2
midpoint.y = Metamaps.tempNode.pos.getc().y + (nodeOnViz.pos.getc().y - Metamaps.tempNode.pos.getc().y) / 2 midpoint.y = JIT.tempNode.pos.getc().y + (nodeOnViz.pos.getc().y - JIT.tempNode.pos.getc().y) / 2
pixelPos = Metamaps.Util.coordsToPixels(midpoint) pixelPos = Metamaps.Util.coordsToPixels(midpoint)
$('#new_synapse').css('left', pixelPos.x + 'px') $('#new_synapse').css('left', pixelPos.x + 'px')
$('#new_synapse').css('top', pixelPos.y + 'px') $('#new_synapse').css('top', pixelPos.y + 'px')
@ -232,9 +229,9 @@ const Topic = {
modes: ['node-property:dim'], modes: ['node-property:dim'],
duration: 500, duration: 500,
onComplete: function () { onComplete: function () {
Metamaps.tempNode = null JIT.tempNode = null
Metamaps.tempNode2 = null JIT.tempNode2 = null
Metamaps.tempInit = false JIT.tempInit = false
} }
}) })
} else { } else {