decouple Util from other Metamaps modules
This commit is contained in:
parent
98e2de68da
commit
58fe65a4af
5 changed files with 20 additions and 14 deletions
|
@ -990,7 +990,7 @@ const JIT = {
|
||||||
Visualize.mGraph.plot()
|
Visualize.mGraph.plot()
|
||||||
midpoint.x = JIT.tempNode.pos.getc().x + (JIT.tempNode2.pos.getc().x - JIT.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 = JIT.tempNode.pos.getc().y + (JIT.tempNode2.pos.getc().y - JIT.tempNode.pos.getc().y) / 2
|
midpoint.y = JIT.tempNode.pos.getc().y + (JIT.tempNode2.pos.getc().y - JIT.tempNode.pos.getc().y) / 2
|
||||||
pixelPos = Util.coordsToPixels(midpoint)
|
pixelPos = Util.coordsToPixels(Visualize.mGraph, 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')
|
||||||
Create.newSynapse.open()
|
Create.newSynapse.open()
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
import Import from './Import'
|
import Import from './Import'
|
||||||
import Util from './Util'
|
import Util from './Util'
|
||||||
|
import Visualize from './Visualize'
|
||||||
|
|
||||||
const PasteInput = {
|
const PasteInput = {
|
||||||
// thanks to https://github.com/kevva/url-regex
|
// thanks to https://github.com/kevva/url-regex
|
||||||
|
@ -19,7 +20,7 @@ const PasteInput = {
|
||||||
window.addEventListener("drop", function(e) {
|
window.addEventListener("drop", function(e) {
|
||||||
e = e || window.event;
|
e = e || window.event;
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
var coords = Util.pixelsToCoords({ x: e.clientX, y: e.clientY })
|
var coords = Util.pixelsToCoords(Visualize.mGraph, { x: e.clientX, y: e.clientY })
|
||||||
if (e.dataTransfer.files.length > 0) {
|
if (e.dataTransfer.files.length > 0) {
|
||||||
self.handleFile(e.dataTransfer.files[0], coords)
|
self.handleFile(e.dataTransfer.files[0], coords)
|
||||||
}
|
}
|
||||||
|
|
|
@ -278,7 +278,7 @@ let Realtime = {
|
||||||
x: event.pageX,
|
x: event.pageX,
|
||||||
y: event.pageY
|
y: event.pageY
|
||||||
}
|
}
|
||||||
var coords = Util.pixelsToCoords(pixels)
|
var coords = Util.pixelsToCoords(Visualize.mGraph, pixels)
|
||||||
self.sendCoords(coords)
|
self.sendCoords(coords)
|
||||||
}
|
}
|
||||||
$(document).on('mousemove.map', sendCoords)
|
$(document).on('mousemove.map', sendCoords)
|
||||||
|
@ -289,7 +289,7 @@ let Realtime = {
|
||||||
x: e.pageX,
|
x: e.pageX,
|
||||||
y: e.pageY
|
y: e.pageY
|
||||||
}
|
}
|
||||||
var coords = Util.pixelsToCoords(pixels)
|
var coords = Util.pixelsToCoords(Visualize.mGraph, pixels)
|
||||||
self.sendCoords(coords)
|
self.sendCoords(coords)
|
||||||
}
|
}
|
||||||
self.positionPeerIcons()
|
self.positionPeerIcons()
|
||||||
|
@ -448,7 +448,7 @@ let Realtime = {
|
||||||
var compassDiameter = 56
|
var compassDiameter = 56
|
||||||
var compassArrowSize = 24
|
var compassArrowSize = 24
|
||||||
|
|
||||||
var origPixels = Util.coordsToPixels(mapper.coords)
|
var origPixels = Util.coordsToPixels(Visualize.mGraph, mapper.coords)
|
||||||
var pixels = self.limitPixelsToScreen(origPixels)
|
var pixels = self.limitPixelsToScreen(origPixels)
|
||||||
$('#compass' + id).css({
|
$('#compass' + id).css({
|
||||||
left: pixels.x + 'px',
|
left: pixels.x + 'px',
|
||||||
|
|
|
@ -211,7 +211,7 @@ const Topic = {
|
||||||
// position the form
|
// position the form
|
||||||
midpoint.x = JIT.tempNode.pos.getc().x + (nodeOnViz.pos.getc().x - JIT.tempNode.pos.getc().x) / 2
|
midpoint.x = JIT.tempNode.pos.getc().x + (nodeOnViz.pos.getc().x - JIT.tempNode.pos.getc().x) / 2
|
||||||
midpoint.y = JIT.tempNode.pos.getc().y + (nodeOnViz.pos.getc().y - JIT.tempNode.pos.getc().y) / 2
|
midpoint.y = JIT.tempNode.pos.getc().y + (nodeOnViz.pos.getc().y - JIT.tempNode.pos.getc().y) / 2
|
||||||
pixelPos = Util.coordsToPixels(midpoint)
|
pixelPos = Util.coordsToPixels(Visualize.mGraph, 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')
|
||||||
// show the form
|
// show the form
|
||||||
|
|
|
@ -2,8 +2,6 @@
|
||||||
|
|
||||||
import { Parser, HtmlRenderer } from 'commonmark'
|
import { Parser, HtmlRenderer } from 'commonmark'
|
||||||
|
|
||||||
import Visualize from './Visualize'
|
|
||||||
|
|
||||||
const Util = {
|
const Util = {
|
||||||
// helper function to determine how many lines are needed
|
// helper function to determine how many lines are needed
|
||||||
// Line Splitter Function
|
// Line Splitter Function
|
||||||
|
@ -23,6 +21,7 @@ const Util = {
|
||||||
}
|
}
|
||||||
return b + s
|
return b + s
|
||||||
},
|
},
|
||||||
|
|
||||||
nowDateFormatted: function () {
|
nowDateFormatted: function () {
|
||||||
var date = new Date(Date.now())
|
var date = new Date(Date.now())
|
||||||
var month = (date.getMonth() + 1) < 10 ? '0' + (date.getMonth() + 1) : (date.getMonth() + 1)
|
var month = (date.getMonth() + 1) < 10 ? '0' + (date.getMonth() + 1) : (date.getMonth() + 1)
|
||||||
|
@ -31,6 +30,7 @@ const Util = {
|
||||||
|
|
||||||
return month + '/' + day + '/' + year
|
return month + '/' + day + '/' + year
|
||||||
},
|
},
|
||||||
|
|
||||||
decodeEntities: function (desc) {
|
decodeEntities: function (desc) {
|
||||||
var str, temp = document.createElement('p')
|
var str, temp = document.createElement('p')
|
||||||
temp.innerHTML = desc // browser handles the topics
|
temp.innerHTML = desc // browser handles the topics
|
||||||
|
@ -38,12 +38,15 @@ const Util = {
|
||||||
temp = null // delete the element
|
temp = null // delete the element
|
||||||
return str
|
return str
|
||||||
}, // decodeEntities
|
}, // decodeEntities
|
||||||
|
|
||||||
getDistance: function (p1, p2) {
|
getDistance: function (p1, p2) {
|
||||||
return Math.sqrt(Math.pow((p2.x - p1.x), 2) + Math.pow((p2.y - p1.y), 2))
|
return Math.sqrt(Math.pow((p2.x - p1.x), 2) + Math.pow((p2.y - p1.y), 2))
|
||||||
},
|
},
|
||||||
coordsToPixels: function (coords) {
|
|
||||||
if (Visualize.mGraph) {
|
// Try using Visualize.mGraph
|
||||||
var canvas = Visualize.mGraph.canvas,
|
coordsToPixels: function (mGraph, coords) {
|
||||||
|
if (mGraph) {
|
||||||
|
var canvas = mGraph.canvas,
|
||||||
s = canvas.getSize(),
|
s = canvas.getSize(),
|
||||||
p = canvas.getPos(),
|
p = canvas.getPos(),
|
||||||
ox = canvas.translateOffsetX,
|
ox = canvas.translateOffsetX,
|
||||||
|
@ -62,10 +65,12 @@ const Util = {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
pixelsToCoords: function (pixels) {
|
|
||||||
|
// Try using Visualize.mGraph
|
||||||
|
pixelsToCoords: function (mGraph, pixels) {
|
||||||
var coords
|
var coords
|
||||||
if (Visualize.mGraph) {
|
if (mGraph) {
|
||||||
var canvas = Visualize.mGraph.canvas,
|
var canvas = mGraph.canvas,
|
||||||
s = canvas.getSize(),
|
s = canvas.getSize(),
|
||||||
p = canvas.getPos(),
|
p = canvas.getPos(),
|
||||||
ox = canvas.translateOffsetX,
|
ox = canvas.translateOffsetX,
|
||||||
|
|
Loading…
Add table
Reference in a new issue