2016-09-26 13:37:42 +08:00
|
|
|
/* global Metamaps, $, Image, CanvasLoader */
|
2016-09-23 10:37:59 +08:00
|
|
|
|
2016-09-22 23:51:33 +08:00
|
|
|
import _ from 'lodash'
|
2016-10-04 23:38:32 +08:00
|
|
|
import outdent from 'outdent'
|
2016-09-22 23:51:33 +08:00
|
|
|
|
2016-09-23 11:47:40 +08:00
|
|
|
import $jit from '../patched/JIT'
|
|
|
|
|
2016-09-22 18:31:56 +08:00
|
|
|
import Active from './Active'
|
|
|
|
import Control from './Control'
|
|
|
|
import Create from './Create'
|
|
|
|
import Filter from './Filter'
|
|
|
|
import GlobalUI from './GlobalUI'
|
|
|
|
import Map from './Map'
|
|
|
|
import Mouse from './Mouse'
|
|
|
|
import Realtime from './Realtime'
|
|
|
|
import Selected from './Selected'
|
|
|
|
import Settings from './Settings'
|
|
|
|
import Synapse from './Synapse'
|
|
|
|
import SynapseCard from './SynapseCard'
|
|
|
|
import Topic from './Topic'
|
|
|
|
import TopicCard from './TopicCard'
|
|
|
|
import Util from './Util'
|
|
|
|
import Visualize from './Visualize'
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Metamaps.Erb
|
|
|
|
* Metamaps.Mappings
|
|
|
|
* Metamaps.Metacodes
|
|
|
|
* Metamaps.Synapses
|
|
|
|
* Metamaps.Topics
|
|
|
|
*/
|
|
|
|
|
2016-09-22 15:21:59 +08:00
|
|
|
let panningInt
|
|
|
|
|
|
|
|
const JIT = {
|
2016-09-22 17:08:53 +08:00
|
|
|
tempInit: false,
|
|
|
|
tempNode: null,
|
|
|
|
tempNode2: null,
|
|
|
|
|
2016-04-15 08:43:46 +08:00
|
|
|
events: {
|
|
|
|
topicDrag: 'Metamaps:JIT:events:topicDrag',
|
|
|
|
newTopic: 'Metamaps:JIT:events:newTopic',
|
|
|
|
deleteTopic: 'Metamaps:JIT:events:deleteTopic',
|
|
|
|
removeTopic: 'Metamaps:JIT:events:removeTopic',
|
|
|
|
newSynapse: 'Metamaps:JIT:events:newSynapse',
|
|
|
|
deleteSynapse: 'Metamaps:JIT:events:deleteSynapse',
|
|
|
|
removeSynapse: 'Metamaps:JIT:events:removeSynapse',
|
|
|
|
pan: 'Metamaps:JIT:events:pan',
|
|
|
|
zoom: 'Metamaps:JIT:events:zoom',
|
2016-10-05 01:45:21 +08:00
|
|
|
animationDone: 'Metamaps:JIT:events:animationDone'
|
2016-04-15 08:43:46 +08:00
|
|
|
},
|
|
|
|
vizData: [], // contains the visualization-compatible graph
|
|
|
|
/**
|
|
|
|
* This method will bind the event handlers it is interested and initialize the class.
|
|
|
|
*/
|
|
|
|
init: function () {
|
2016-10-05 01:45:21 +08:00
|
|
|
const self = JIT
|
2016-04-15 08:43:46 +08:00
|
|
|
|
|
|
|
$('.zoomIn').click(self.zoomIn)
|
|
|
|
$('.zoomOut').click(self.zoomOut)
|
|
|
|
|
2016-10-05 01:45:21 +08:00
|
|
|
const zoomExtents = function (event) {
|
2016-09-22 18:31:56 +08:00
|
|
|
self.zoomExtents(event, Visualize.mGraph.canvas)
|
2016-04-15 08:43:46 +08:00
|
|
|
}
|
|
|
|
$('.zoomExtents').click(zoomExtents)
|
|
|
|
|
2016-09-22 18:31:56 +08:00
|
|
|
$('.takeScreenshot').click(Map.exportImage)
|
2016-04-15 08:43:46 +08:00
|
|
|
|
|
|
|
self.topicDescImage = new Image()
|
2016-04-24 11:50:35 -04:00
|
|
|
self.topicDescImage.src = Metamaps.Erb['topic_description_signifier.png']
|
2016-04-15 08:43:46 +08:00
|
|
|
|
|
|
|
self.topicLinkImage = new Image()
|
2016-04-24 11:50:35 -04:00
|
|
|
self.topicLinkImage.src = Metamaps.Erb['topic_link_signifier.png']
|
2016-04-15 08:43:46 +08:00
|
|
|
},
|
|
|
|
/**
|
|
|
|
* convert our topic JSON into something JIT can use
|
|
|
|
*/
|
|
|
|
convertModelsToJIT: function (topics, synapses) {
|
2016-10-05 01:45:21 +08:00
|
|
|
const jitReady = []
|
2016-04-15 08:43:46 +08:00
|
|
|
|
2016-10-05 01:45:21 +08:00
|
|
|
const synapsesToRemove = []
|
|
|
|
let mapping
|
|
|
|
let node
|
|
|
|
const nodes = {}
|
|
|
|
let existingEdge
|
|
|
|
let edge
|
|
|
|
const edges = []
|
2016-04-15 08:43:46 +08:00
|
|
|
|
|
|
|
topics.each(function (t) {
|
|
|
|
node = t.createNode()
|
|
|
|
nodes[node.id] = node
|
|
|
|
})
|
|
|
|
synapses.each(function (s) {
|
|
|
|
edge = s.createEdge()
|
|
|
|
|
2016-09-28 10:32:28 +08:00
|
|
|
if (topics.get(s.get('topic1_id')) === undefined || topics.get(s.get('topic2_id')) === undefined) {
|
2016-04-15 08:43:46 +08:00
|
|
|
// this means it's an invalid synapse
|
|
|
|
synapsesToRemove.push(s)
|
2016-10-05 01:45:21 +08:00
|
|
|
} else if (nodes[edge.nodeFrom] && nodes[edge.nodeTo]) {
|
2016-09-23 14:12:27 +08:00
|
|
|
existingEdge = _.find(edges, {
|
2016-04-15 08:43:46 +08:00
|
|
|
nodeFrom: edge.nodeFrom,
|
|
|
|
nodeTo: edge.nodeTo
|
|
|
|
}) ||
|
2016-09-23 14:12:27 +08:00
|
|
|
_.find(edges, {
|
2016-04-15 08:43:46 +08:00
|
|
|
nodeFrom: edge.nodeTo,
|
|
|
|
nodeTo: edge.nodeFrom
|
|
|
|
})
|
|
|
|
|
|
|
|
if (existingEdge) {
|
|
|
|
// for when you're dealing with multiple relationships between the same two topics
|
2016-09-22 18:31:56 +08:00
|
|
|
if (Active.Map) {
|
2016-04-15 08:43:46 +08:00
|
|
|
mapping = s.getMapping()
|
|
|
|
existingEdge.data['$mappingIDs'].push(mapping.id)
|
|
|
|
}
|
|
|
|
existingEdge.data['$synapseIDs'].push(s.id)
|
|
|
|
} else {
|
|
|
|
// for when you're dealing with a topic that has relationships to many different nodes
|
|
|
|
nodes[edge.nodeFrom].adjacencies.push(edge)
|
|
|
|
edges.push(edge)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
2016-02-03 21:38:41 +08:00
|
|
|
|
2016-04-15 08:43:46 +08:00
|
|
|
_.each(nodes, function (node) {
|
|
|
|
jitReady.push(node)
|
|
|
|
})
|
2016-02-03 21:38:41 +08:00
|
|
|
|
2016-04-15 08:43:46 +08:00
|
|
|
return [jitReady, synapsesToRemove]
|
|
|
|
},
|
|
|
|
prepareVizData: function () {
|
2016-10-05 01:45:21 +08:00
|
|
|
const self = JIT
|
|
|
|
let mapping
|
2016-02-03 21:38:41 +08:00
|
|
|
|
2016-04-15 08:43:46 +08:00
|
|
|
// reset/empty vizData
|
|
|
|
self.vizData = []
|
2016-09-22 18:31:56 +08:00
|
|
|
Visualize.loadLater = false
|
2016-02-03 21:38:41 +08:00
|
|
|
|
2016-10-05 01:45:21 +08:00
|
|
|
const results = self.convertModelsToJIT(Metamaps.Topics, Metamaps.Synapses)
|
2016-02-03 21:38:41 +08:00
|
|
|
|
2016-04-15 08:43:46 +08:00
|
|
|
self.vizData = results[0]
|
2016-02-03 21:38:41 +08:00
|
|
|
|
2016-04-15 08:43:46 +08:00
|
|
|
// clean up the synapses array in case of any faulty data
|
|
|
|
_.each(results[1], function (synapse) {
|
|
|
|
mapping = synapse.getMapping()
|
|
|
|
Metamaps.Synapses.remove(synapse)
|
|
|
|
if (Metamaps.Mappings) Metamaps.Mappings.remove(mapping)
|
|
|
|
})
|
2016-02-03 21:38:41 +08:00
|
|
|
|
2016-09-25 22:27:11 +08:00
|
|
|
// set up addTopic instructions in case they delete all the topics
|
|
|
|
// i.e. if there are 0 topics at any time, it should have instructions again
|
|
|
|
$('#instructions div').hide()
|
2016-09-26 14:04:31 +08:00
|
|
|
if (Active.Map && Active.Map.authorizeToEdit(Active.Mapper)) {
|
2016-09-25 22:27:11 +08:00
|
|
|
$('#instructions div.addTopic').show()
|
|
|
|
}
|
|
|
|
|
2016-10-05 01:45:21 +08:00
|
|
|
if (self.vizData.length === 0) {
|
2016-09-22 18:31:56 +08:00
|
|
|
GlobalUI.showDiv('#instructions')
|
|
|
|
Visualize.loadLater = true
|
2016-09-25 20:14:45 +08:00
|
|
|
} else {
|
|
|
|
GlobalUI.hideDiv('#instructions')
|
2016-04-15 08:43:46 +08:00
|
|
|
}
|
|
|
|
|
2016-09-22 18:31:56 +08:00
|
|
|
Visualize.render()
|
2016-04-15 08:43:46 +08:00
|
|
|
}, // prepareVizData
|
|
|
|
edgeRender: function (adj, canvas) {
|
2016-10-05 01:45:21 +08:00
|
|
|
// get nodes cartesian coordinates
|
|
|
|
const pos = adj.nodeFrom.pos.getc(true)
|
|
|
|
const posChild = adj.nodeTo.pos.getc(true)
|
2016-04-15 08:43:46 +08:00
|
|
|
|
2016-10-05 01:45:21 +08:00
|
|
|
let synapse
|
2016-04-15 08:43:46 +08:00
|
|
|
if (adj.getData('displayIndex')) {
|
|
|
|
synapse = adj.getData('synapses')[adj.getData('displayIndex')]
|
|
|
|
if (!synapse) {
|
|
|
|
delete adj.data.$displayIndex
|
|
|
|
synapse = adj.getData('synapses')[0]
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
synapse = adj.getData('synapses')[0]
|
|
|
|
}
|
2016-02-03 21:38:41 +08:00
|
|
|
|
2016-04-15 08:43:46 +08:00
|
|
|
if (!synapse) return // this means there are no corresponding synapses for
|
|
|
|
// this edge, don't render it
|
2016-02-03 21:38:41 +08:00
|
|
|
|
2016-04-15 08:43:46 +08:00
|
|
|
// label placement on edges
|
|
|
|
if (canvas.denySelected) {
|
2016-10-05 01:45:21 +08:00
|
|
|
const color = Settings.colors.synapses.normal
|
2016-04-15 08:43:46 +08:00
|
|
|
canvas.getCtx().fillStyle = canvas.getCtx().strokeStyle = color
|
|
|
|
}
|
2016-09-22 15:21:59 +08:00
|
|
|
JIT.renderEdgeArrows($jit.Graph.Plot.edgeHelper, adj, synapse, canvas)
|
2016-04-15 08:43:46 +08:00
|
|
|
|
2016-10-05 01:45:21 +08:00
|
|
|
// check for edge label in data
|
|
|
|
let desc = synapse.get('desc')
|
2016-04-15 08:43:46 +08:00
|
|
|
|
2016-10-05 01:45:21 +08:00
|
|
|
const showDesc = adj.getData('showDesc')
|
2016-04-15 08:43:46 +08:00
|
|
|
|
2016-10-05 01:45:21 +08:00
|
|
|
const drawSynapseCount = function (context, x, y, count) {
|
2016-04-15 08:43:46 +08:00
|
|
|
/*
|
|
|
|
circle size: 16x16px
|
|
|
|
positioning: overlay and center on top right corner of synapse label - 8px left and 8px down
|
|
|
|
color: #dab539
|
|
|
|
border color: #424242
|
|
|
|
border size: 1.5px
|
|
|
|
font: DIN medium
|
|
|
|
font-size: 14pt
|
|
|
|
font-color: #424242
|
|
|
|
*/
|
|
|
|
context.beginPath()
|
|
|
|
context.arc(x, y, 8, 0, 2 * Math.PI, false)
|
|
|
|
context.fillStyle = '#DAB539'
|
|
|
|
context.strokeStyle = '#424242'
|
|
|
|
context.lineWidth = 1.5
|
|
|
|
context.closePath()
|
|
|
|
context.fill()
|
|
|
|
context.stroke()
|
|
|
|
|
|
|
|
// add the synapse count
|
|
|
|
context.fillStyle = '#424242'
|
|
|
|
context.textAlign = 'center'
|
|
|
|
context.font = '14px din-medium'
|
|
|
|
|
|
|
|
context.fillText(count, x, y + 5)
|
|
|
|
}
|
2016-02-03 21:38:41 +08:00
|
|
|
|
2016-10-05 01:45:21 +08:00
|
|
|
if (!canvas.denySelected && desc !== '' && showDesc) {
|
2016-04-15 08:43:46 +08:00
|
|
|
// '&' to '&'
|
2016-09-22 18:31:56 +08:00
|
|
|
desc = Util.decodeEntities(desc)
|
2016-04-15 08:43:46 +08:00
|
|
|
|
2016-10-05 01:45:21 +08:00
|
|
|
// now adjust the label placement
|
|
|
|
const ctx = canvas.getCtx()
|
2016-04-15 08:43:46 +08:00
|
|
|
ctx.font = 'bold 14px arial'
|
|
|
|
ctx.fillStyle = '#FFF'
|
|
|
|
ctx.textBaseline = 'alphabetic'
|
|
|
|
|
2016-10-05 01:45:21 +08:00
|
|
|
const arrayOfLabelLines = Util.splitLine(desc, 30).split('\n')
|
|
|
|
let lineWidths = []
|
|
|
|
for (let index = 0; index < arrayOfLabelLines.length; ++index) {
|
2016-04-15 08:43:46 +08:00
|
|
|
lineWidths.push(ctx.measureText(arrayOfLabelLines[index]).width)
|
|
|
|
}
|
2016-10-05 01:45:21 +08:00
|
|
|
const width = Math.max.apply(null, lineWidths) + 16
|
|
|
|
const height = (16 * arrayOfLabelLines.length) + 8
|
2016-04-15 08:43:46 +08:00
|
|
|
|
2016-10-05 01:45:21 +08:00
|
|
|
const x = (pos.x + posChild.x - width) / 2
|
|
|
|
const y = ((pos.y + posChild.y) / 2) - height / 2
|
2016-04-15 08:43:46 +08:00
|
|
|
|
2016-10-05 01:45:21 +08:00
|
|
|
const radius = 5
|
2016-04-15 08:43:46 +08:00
|
|
|
|
|
|
|
// render background
|
|
|
|
ctx.beginPath()
|
|
|
|
ctx.moveTo(x + radius, y)
|
|
|
|
ctx.lineTo(x + width - radius, y)
|
|
|
|
ctx.quadraticCurveTo(x + width, y, x + width, y + radius)
|
|
|
|
ctx.lineTo(x + width, y + height - radius)
|
|
|
|
ctx.quadraticCurveTo(x + width, y + height, x + width - radius, y + height)
|
|
|
|
ctx.lineTo(x + radius, y + height)
|
|
|
|
ctx.quadraticCurveTo(x, y + height, x, y + height - radius)
|
|
|
|
ctx.lineTo(x, y + radius)
|
|
|
|
ctx.quadraticCurveTo(x, y, x + radius, y)
|
|
|
|
ctx.closePath()
|
|
|
|
ctx.fill()
|
|
|
|
|
|
|
|
// get number of synapses
|
2016-10-05 01:45:21 +08:00
|
|
|
const synapseNum = adj.getData('synapses').length
|
2016-04-15 08:43:46 +08:00
|
|
|
|
|
|
|
// render text
|
|
|
|
ctx.fillStyle = '#424242'
|
|
|
|
ctx.textAlign = 'center'
|
2016-10-05 01:45:21 +08:00
|
|
|
for (let index = 0; index < arrayOfLabelLines.length; ++index) {
|
2016-04-15 08:43:46 +08:00
|
|
|
ctx.fillText(arrayOfLabelLines[index], x + (width / 2), y + 18 + (16 * index))
|
|
|
|
}
|
|
|
|
|
|
|
|
if (synapseNum > 1) {
|
|
|
|
drawSynapseCount(ctx, x + width, y, synapseNum)
|
|
|
|
}
|
2016-10-05 01:45:21 +08:00
|
|
|
} else if (!canvas.denySelected && showDesc) {
|
2016-04-15 08:43:46 +08:00
|
|
|
// get number of synapses
|
2016-10-05 01:45:21 +08:00
|
|
|
const synapseNum = adj.getData('synapses').length
|
2016-04-15 08:43:46 +08:00
|
|
|
|
|
|
|
if (synapseNum > 1) {
|
2016-10-05 01:45:21 +08:00
|
|
|
const ctx = canvas.getCtx()
|
2016-09-26 13:37:42 +08:00
|
|
|
const x = (pos.x + posChild.x) / 2
|
|
|
|
const y = (pos.y + posChild.y) / 2
|
2016-04-15 08:43:46 +08:00
|
|
|
drawSynapseCount(ctx, x, y, synapseNum)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}, // edgeRender
|
|
|
|
ForceDirected: {
|
|
|
|
animateSavedLayout: {
|
|
|
|
modes: ['linear'],
|
2016-09-23 11:47:40 +08:00
|
|
|
// TODO fix tests so we don't need _.get
|
|
|
|
transition: _.get($jit, 'Trans.Quad.easeInOut'),
|
2016-04-15 08:43:46 +08:00
|
|
|
duration: 800,
|
|
|
|
onComplete: function () {
|
2016-09-22 18:31:56 +08:00
|
|
|
Visualize.mGraph.busy = false
|
2016-09-22 15:21:59 +08:00
|
|
|
$(document).trigger(JIT.events.animationDone)
|
2016-04-15 08:43:46 +08:00
|
|
|
}
|
|
|
|
},
|
|
|
|
animateFDLayout: {
|
|
|
|
modes: ['linear'],
|
2016-09-23 11:47:40 +08:00
|
|
|
// TODO fix tests so we don't need _.get
|
|
|
|
transition: _.get($jit, 'Trans.Elastic.easeOut'),
|
2016-04-15 08:43:46 +08:00
|
|
|
duration: 800,
|
|
|
|
onComplete: function () {
|
2016-09-22 18:31:56 +08:00
|
|
|
Visualize.mGraph.busy = false
|
2016-04-15 08:43:46 +08:00
|
|
|
}
|
|
|
|
},
|
|
|
|
graphSettings: {
|
|
|
|
// id of the visualization container
|
|
|
|
injectInto: 'infovis',
|
|
|
|
// Enable zooming and panning
|
|
|
|
// by scrolling and DnD
|
|
|
|
Navigation: {
|
|
|
|
enable: true,
|
|
|
|
// Enable panning events only if we're dragging the empty
|
|
|
|
// canvas (and not a node).
|
|
|
|
panning: 'avoid nodes',
|
|
|
|
zooming: 28 // zoom speed. higher is more sensible
|
|
|
|
},
|
|
|
|
// background: {
|
|
|
|
// type: 'Metamaps'
|
|
|
|
// },
|
2016-10-05 01:45:21 +08:00
|
|
|
// NodeStyles: {
|
|
|
|
// enable: true,
|
|
|
|
// type: 'Native',
|
|
|
|
// stylesHover: {
|
|
|
|
// dim: 30
|
|
|
|
// },
|
|
|
|
// duration: 300
|
2016-04-15 08:43:46 +08:00
|
|
|
// },
|
|
|
|
// Change node and edge styles such as
|
|
|
|
// color and width.
|
|
|
|
// These properties are also set per node
|
|
|
|
// with dollar prefixed data-properties in the
|
|
|
|
// JSON structure.
|
|
|
|
Node: {
|
|
|
|
overridable: true,
|
|
|
|
color: '#2D6A5D',
|
|
|
|
type: 'customNode',
|
|
|
|
dim: 25
|
|
|
|
},
|
|
|
|
Edge: {
|
|
|
|
overridable: true,
|
2016-09-22 18:31:56 +08:00
|
|
|
color: Settings.colors.synapses.normal,
|
2016-04-15 08:43:46 +08:00
|
|
|
type: 'customEdge',
|
|
|
|
lineWidth: 2,
|
|
|
|
alpha: 1
|
|
|
|
},
|
|
|
|
// Native canvas text styling
|
|
|
|
Label: {
|
|
|
|
type: 'Native', // Native or HTML
|
|
|
|
size: 20,
|
|
|
|
family: 'arial',
|
|
|
|
textBaseline: 'alphabetic',
|
2016-09-22 18:31:56 +08:00
|
|
|
color: Settings.colors.labels.text
|
2016-04-15 08:43:46 +08:00
|
|
|
},
|
|
|
|
// Add Tips
|
|
|
|
Tips: {
|
|
|
|
enable: false,
|
|
|
|
onShow: function (tip, node) {}
|
|
|
|
},
|
|
|
|
// Add node events
|
|
|
|
Events: {
|
|
|
|
enable: true,
|
|
|
|
enableForEdges: true,
|
|
|
|
onMouseMove: function (node, eventInfo, e) {
|
2016-09-22 15:21:59 +08:00
|
|
|
JIT.onMouseMoveHandler(node, eventInfo, e)
|
2016-04-15 08:43:46 +08:00
|
|
|
// console.log('called mouse move handler')
|
|
|
|
},
|
|
|
|
// Update node positions when dragged
|
|
|
|
onDragMove: function (node, eventInfo, e) {
|
2016-09-22 15:21:59 +08:00
|
|
|
JIT.onDragMoveTopicHandler(node, eventInfo, e)
|
2016-04-15 08:43:46 +08:00
|
|
|
// console.log('called drag move handler')
|
|
|
|
},
|
|
|
|
onDragEnd: function (node, eventInfo, e) {
|
2016-09-22 15:21:59 +08:00
|
|
|
JIT.onDragEndTopicHandler(node, eventInfo, e, false)
|
2016-04-15 08:43:46 +08:00
|
|
|
// console.log('called drag end handler')
|
|
|
|
},
|
|
|
|
onDragCancel: function (node, eventInfo, e) {
|
2016-09-22 15:21:59 +08:00
|
|
|
JIT.onDragCancelHandler(node, eventInfo, e, false)
|
2016-04-15 08:43:46 +08:00
|
|
|
},
|
|
|
|
// Implement the same handler for touchscreens
|
2016-08-12 11:07:59 -04:00
|
|
|
onTouchStart: function (node, eventInfo, e) {},
|
2016-04-15 08:43:46 +08:00
|
|
|
// Implement the same handler for touchscreens
|
|
|
|
onTouchMove: function (node, eventInfo, e) {
|
2016-09-22 15:21:59 +08:00
|
|
|
JIT.onDragMoveTopicHandler(node, eventInfo, e)
|
2016-02-03 21:38:41 +08:00
|
|
|
},
|
2016-04-15 08:43:46 +08:00
|
|
|
// Implement the same handler for touchscreens
|
|
|
|
onTouchEnd: function (node, eventInfo, e) {},
|
|
|
|
// Implement the same handler for touchscreens
|
|
|
|
onTouchCancel: function (node, eventInfo, e) {},
|
|
|
|
// Add also a click handler to nodes
|
|
|
|
onClick: function (node, eventInfo, e) {
|
|
|
|
// remove the rightclickmenu
|
|
|
|
$('.rightclickmenu').remove()
|
|
|
|
|
2016-09-22 18:31:56 +08:00
|
|
|
if (Mouse.boxStartCoordinates) {
|
2016-04-15 08:43:46 +08:00
|
|
|
if (e.ctrlKey) {
|
2016-09-22 18:31:56 +08:00
|
|
|
Visualize.mGraph.busy = false
|
|
|
|
Mouse.boxEndCoordinates = eventInfo.getPos()
|
2016-04-15 08:43:46 +08:00
|
|
|
|
2016-10-05 01:45:21 +08:00
|
|
|
const bS = Mouse.boxStartCoordinates
|
|
|
|
const bE = Mouse.boxEndCoordinates
|
2016-04-15 08:43:46 +08:00
|
|
|
if (Math.abs(bS.x - bE.x) > 20 && Math.abs(bS.y - bE.y) > 20) {
|
2016-09-22 15:21:59 +08:00
|
|
|
JIT.zoomToBox(e)
|
2016-04-15 08:43:46 +08:00
|
|
|
return
|
|
|
|
} else {
|
2016-09-22 18:31:56 +08:00
|
|
|
Mouse.boxStartCoordinates = null
|
|
|
|
Mouse.boxEndCoordinates = null
|
2016-04-15 08:43:46 +08:00
|
|
|
}
|
|
|
|
// console.log('called zoom to box')
|
2016-02-03 21:38:41 +08:00
|
|
|
}
|
2016-04-15 08:43:46 +08:00
|
|
|
|
|
|
|
if (e.shiftKey) {
|
2016-09-22 18:31:56 +08:00
|
|
|
Visualize.mGraph.busy = false
|
|
|
|
Mouse.boxEndCoordinates = eventInfo.getPos()
|
2016-09-22 15:21:59 +08:00
|
|
|
JIT.selectWithBox(e)
|
2016-04-15 08:43:46 +08:00
|
|
|
// console.log('called select with box')
|
|
|
|
return
|
2016-02-03 21:38:41 +08:00
|
|
|
}
|
2016-04-15 08:43:46 +08:00
|
|
|
}
|
|
|
|
|
2016-10-05 01:45:21 +08:00
|
|
|
if (e.target.id !== 'infovis-canvas') return false
|
2016-04-15 08:43:46 +08:00
|
|
|
|
|
|
|
// clicking on a edge, node, or clicking on blank part of canvas?
|
|
|
|
if (node.nodeFrom) {
|
2016-09-22 15:21:59 +08:00
|
|
|
JIT.selectEdgeOnClickHandler(node, e)
|
2016-04-15 08:43:46 +08:00
|
|
|
// console.log('called selectEdgeOnClickHandler')
|
|
|
|
} else if (node && !node.nodeFrom) {
|
2016-09-22 15:21:59 +08:00
|
|
|
JIT.selectNodeOnClickHandler(node, e)
|
2016-04-15 08:43:46 +08:00
|
|
|
// console.log('called selectNodeOnClickHandler')
|
|
|
|
} else {
|
2016-09-22 15:21:59 +08:00
|
|
|
JIT.canvasClickHandler(eventInfo.getPos(), e)
|
2016-04-15 08:43:46 +08:00
|
|
|
// console.log('called canvasClickHandler')
|
|
|
|
} // if
|
|
|
|
},
|
|
|
|
// Add also a click handler to nodes
|
|
|
|
onRightClick: function (node, eventInfo, e) {
|
|
|
|
// remove the rightclickmenu
|
|
|
|
$('.rightclickmenu').remove()
|
|
|
|
|
2016-09-22 18:31:56 +08:00
|
|
|
if (Mouse.boxStartCoordinates) {
|
|
|
|
Visualize.mGraph.busy = false
|
|
|
|
Mouse.boxEndCoordinates = eventInfo.getPos()
|
2016-09-22 15:21:59 +08:00
|
|
|
JIT.selectWithBox(e)
|
2016-04-15 08:43:46 +08:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2016-10-05 01:45:21 +08:00
|
|
|
if (e.target.id !== 'infovis-canvas') return false
|
2016-04-15 08:43:46 +08:00
|
|
|
|
|
|
|
// clicking on a edge, node, or clicking on blank part of canvas?
|
|
|
|
if (node.nodeFrom) {
|
2016-09-22 15:21:59 +08:00
|
|
|
JIT.selectEdgeOnRightClickHandler(node, e)
|
2016-04-15 08:43:46 +08:00
|
|
|
} else if (node && !node.nodeFrom) {
|
2016-09-22 15:21:59 +08:00
|
|
|
JIT.selectNodeOnRightClickHandler(node, e)
|
2016-04-15 08:43:46 +08:00
|
|
|
} else {
|
|
|
|
// console.log('right clicked on open space')
|
|
|
|
}
|
2016-02-03 21:38:41 +08:00
|
|
|
}
|
2016-04-15 08:43:46 +08:00
|
|
|
},
|
|
|
|
// Number of iterations for the FD algorithm
|
|
|
|
iterations: 200,
|
|
|
|
// Edge length
|
2016-10-05 01:45:21 +08:00
|
|
|
levelDistance: 200
|
2016-04-15 08:43:46 +08:00
|
|
|
},
|
|
|
|
nodeSettings: {
|
|
|
|
'customNode': {
|
|
|
|
'render': function (node, canvas) {
|
2016-10-05 01:45:21 +08:00
|
|
|
const pos = node.pos.getc(true)
|
|
|
|
const dim = node.getData('dim')
|
|
|
|
const topic = node.getData('topic')
|
|
|
|
const metacode = topic ? topic.getMetacode() : false
|
|
|
|
const ctx = canvas.getCtx()
|
2016-04-15 08:43:46 +08:00
|
|
|
|
|
|
|
// if the topic is selected draw a circle around it
|
|
|
|
if (!canvas.denySelected && node.selected) {
|
|
|
|
ctx.beginPath()
|
|
|
|
ctx.arc(pos.x, pos.y, dim + 3, 0, 2 * Math.PI, false)
|
2016-09-22 18:31:56 +08:00
|
|
|
ctx.strokeStyle = Settings.colors.topics.selected
|
2016-04-15 08:43:46 +08:00
|
|
|
ctx.lineWidth = 2
|
|
|
|
ctx.stroke()
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!metacode ||
|
|
|
|
!metacode.get('image') ||
|
|
|
|
!metacode.get('image').complete ||
|
|
|
|
(typeof metacode.get('image').naturalWidth !== 'undefined' &&
|
|
|
|
metacode.get('image').naturalWidth === 0)) {
|
|
|
|
ctx.beginPath()
|
|
|
|
ctx.arc(pos.x, pos.y, dim, 0, 2 * Math.PI, false)
|
|
|
|
ctx.fillStyle = '#B6B2FD'
|
|
|
|
ctx.fill()
|
|
|
|
} else {
|
|
|
|
ctx.drawImage(metacode.get('image'), pos.x - dim, pos.y - dim, dim * 2, dim * 2)
|
|
|
|
}
|
|
|
|
|
|
|
|
// if the topic has a link, draw a small image to indicate that
|
2016-10-05 01:45:21 +08:00
|
|
|
const hasLink = topic && topic.get('link') !== '' && topic.get('link') !== null
|
|
|
|
const linkImage = JIT.topicLinkImage
|
|
|
|
const linkImageLoaded = linkImage.complete ||
|
2016-04-15 08:43:46 +08:00
|
|
|
(typeof linkImage.naturalWidth !== 'undefined' &&
|
|
|
|
linkImage.naturalWidth !== 0)
|
|
|
|
if (hasLink && linkImageLoaded) {
|
|
|
|
ctx.drawImage(linkImage, pos.x - dim - 8, pos.y - dim - 8, 16, 16)
|
|
|
|
}
|
|
|
|
|
|
|
|
// if the topic has a desc, draw a small image to indicate that
|
2016-10-05 01:45:21 +08:00
|
|
|
const hasDesc = topic && topic.get('desc') !== '' && topic.get('desc') !== null
|
|
|
|
const descImage = JIT.topicDescImage
|
|
|
|
const descImageLoaded = descImage.complete ||
|
2016-04-15 08:43:46 +08:00
|
|
|
(typeof descImage.naturalWidth !== 'undefined' &&
|
|
|
|
descImage.naturalWidth !== 0)
|
|
|
|
if (hasDesc && descImageLoaded) {
|
|
|
|
ctx.drawImage(descImage, pos.x + dim - 8, pos.y - dim - 8, 16, 16)
|
|
|
|
}
|
2016-02-03 21:38:41 +08:00
|
|
|
},
|
2016-04-15 08:43:46 +08:00
|
|
|
'contains': function (node, pos) {
|
2016-10-05 01:45:21 +08:00
|
|
|
const npos = node.pos.getc(true)
|
|
|
|
const dim = node.getData('dim')
|
|
|
|
const arrayOfLabelLines = Util.splitLine(node.name, 30).split('\n')
|
|
|
|
const ctx = Visualize.mGraph.canvas.getCtx()
|
2016-04-15 08:43:46 +08:00
|
|
|
|
2016-10-05 01:45:21 +08:00
|
|
|
const height = 25 * arrayOfLabelLines.length
|
2016-04-15 08:43:46 +08:00
|
|
|
|
2016-10-05 01:45:21 +08:00
|
|
|
let lineWidths = []
|
|
|
|
for (let index = 0; index < arrayOfLabelLines.length; ++index) {
|
2016-04-15 08:43:46 +08:00
|
|
|
lineWidths.push(ctx.measureText(arrayOfLabelLines[index]).width)
|
|
|
|
}
|
2016-10-05 01:45:21 +08:00
|
|
|
const width = Math.max.apply(null, lineWidths) + 8
|
|
|
|
const labely = npos.y + node.getData('height') + 5 + height / 2
|
2016-04-15 08:43:46 +08:00
|
|
|
|
2016-10-05 01:45:21 +08:00
|
|
|
const overLabel = this.nodeHelper.rectangle.contains({
|
2016-04-15 08:43:46 +08:00
|
|
|
x: npos.x,
|
|
|
|
y: labely
|
|
|
|
}, pos, width, height)
|
|
|
|
|
|
|
|
return this.nodeHelper.circle.contains(npos, pos, dim) || overLabel
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
edgeSettings: {
|
|
|
|
'customEdge': {
|
|
|
|
'render': function (adj, canvas) {
|
2016-09-22 15:21:59 +08:00
|
|
|
JIT.edgeRender(adj, canvas)
|
2016-02-03 21:38:41 +08:00
|
|
|
},
|
2016-04-15 08:43:46 +08:00
|
|
|
'contains': function (adj, pos) {
|
2016-10-05 01:45:21 +08:00
|
|
|
const from = adj.nodeFrom.pos.getc()
|
|
|
|
const to = adj.nodeTo.pos.getc()
|
2016-02-03 21:38:41 +08:00
|
|
|
|
2016-04-15 08:43:46 +08:00
|
|
|
// this fixes an issue where when edges are perfectly horizontal or perfectly vertical
|
|
|
|
// it becomes incredibly difficult to hover over them
|
|
|
|
if (-1 < pos.x && pos.x < 1) pos.x = 0
|
|
|
|
if (-1 < pos.y && pos.y < 1) pos.y = 0
|
2016-02-03 21:38:41 +08:00
|
|
|
|
2016-04-15 08:43:46 +08:00
|
|
|
return $jit.Graph.Plot.edgeHelper.line.contains(from, to, pos, adj.Edge.epsilon + 5)
|
2016-02-03 21:38:41 +08:00
|
|
|
}
|
2016-04-15 08:43:46 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}, // ForceDirected
|
|
|
|
ForceDirected3D: {
|
|
|
|
animate: {
|
|
|
|
modes: ['linear'],
|
2016-09-23 11:47:40 +08:00
|
|
|
// TODO fix tests so we don't need _.get
|
|
|
|
transition: _.get($jit, 'Trans.Elastic.easeOut'),
|
2016-04-15 08:43:46 +08:00
|
|
|
duration: 2500,
|
|
|
|
onComplete: function () {
|
2016-09-22 18:31:56 +08:00
|
|
|
Visualize.mGraph.busy = false
|
2016-04-15 08:43:46 +08:00
|
|
|
}
|
|
|
|
},
|
|
|
|
graphSettings: {
|
|
|
|
// id of the visualization container
|
|
|
|
injectInto: 'infovis',
|
|
|
|
type: '3D',
|
|
|
|
Scene: {
|
|
|
|
Lighting: {
|
|
|
|
enable: false,
|
|
|
|
ambient: [0.5, 0.5, 0.5],
|
|
|
|
directional: {
|
|
|
|
direction: {
|
|
|
|
x: 1,
|
|
|
|
y: 0,
|
|
|
|
z: -1
|
|
|
|
},
|
|
|
|
color: [0.9, 0.9, 0.9]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
// Enable zooming and panning
|
|
|
|
// by scrolling and DnD
|
|
|
|
Navigation: {
|
|
|
|
enable: false,
|
|
|
|
// Enable panning events only if we're dragging the empty
|
|
|
|
// canvas (and not a node).
|
|
|
|
panning: 'avoid nodes',
|
|
|
|
zooming: 10 // zoom speed. higher is more sensible
|
|
|
|
},
|
|
|
|
// Change node and edge styles such as
|
|
|
|
// color and width.
|
|
|
|
// These properties are also set per node
|
|
|
|
// with dollar prefixed data-properties in the
|
|
|
|
// JSON structure.
|
|
|
|
Node: {
|
|
|
|
overridable: true,
|
|
|
|
type: 'sphere',
|
|
|
|
dim: 15,
|
|
|
|
color: '#ffffff'
|
|
|
|
},
|
|
|
|
Edge: {
|
|
|
|
overridable: false,
|
|
|
|
type: 'tube',
|
|
|
|
color: '#111',
|
|
|
|
lineWidth: 3
|
|
|
|
},
|
|
|
|
// Native canvas text styling
|
|
|
|
Label: {
|
|
|
|
type: 'HTML', // Native or HTML
|
|
|
|
size: 10,
|
|
|
|
style: 'bold'
|
|
|
|
},
|
|
|
|
// Add node events
|
|
|
|
Events: {
|
|
|
|
enable: true,
|
|
|
|
type: 'Native',
|
|
|
|
i: 0,
|
|
|
|
onMouseMove: function (node, eventInfo, e) {
|
|
|
|
// if(this.i++ % 3) return
|
2016-10-05 01:45:21 +08:00
|
|
|
const pos = eventInfo.getPos()
|
2016-09-22 18:31:56 +08:00
|
|
|
Visualize.cameraPosition.x += (pos.x - Visualize.cameraPosition.x) * 0.5
|
|
|
|
Visualize.cameraPosition.y += (-pos.y - Visualize.cameraPosition.y) * 0.5
|
|
|
|
Visualize.mGraph.plot()
|
2016-02-03 21:38:41 +08:00
|
|
|
},
|
2016-04-15 08:43:46 +08:00
|
|
|
onMouseWheel: function (delta) {
|
2016-09-22 18:31:56 +08:00
|
|
|
Visualize.cameraPosition.z += -delta * 20
|
|
|
|
Visualize.mGraph.plot()
|
2016-02-03 21:38:41 +08:00
|
|
|
},
|
2016-04-15 08:43:46 +08:00
|
|
|
onClick: function () {}
|
|
|
|
},
|
|
|
|
// Number of iterations for the FD algorithm
|
|
|
|
iterations: 200,
|
|
|
|
// Edge length
|
|
|
|
levelDistance: 100
|
2016-02-03 21:38:41 +08:00
|
|
|
},
|
2016-04-15 08:43:46 +08:00
|
|
|
nodeSettings: {
|
2016-02-03 21:38:41 +08:00
|
|
|
|
2016-04-15 08:43:46 +08:00
|
|
|
},
|
|
|
|
edgeSettings: {
|
2016-02-03 21:38:41 +08:00
|
|
|
|
2016-04-15 08:43:46 +08:00
|
|
|
}
|
|
|
|
}, // ForceDirected3D
|
|
|
|
RGraph: {
|
|
|
|
animate: {
|
|
|
|
modes: ['polar'],
|
|
|
|
duration: 800,
|
|
|
|
onComplete: function () {
|
2016-09-22 18:31:56 +08:00
|
|
|
Visualize.mGraph.busy = false
|
2016-04-15 08:43:46 +08:00
|
|
|
}
|
|
|
|
},
|
|
|
|
// this will just be used to patch the ForceDirected graphsettings with the few things which actually differ
|
|
|
|
background: {
|
|
|
|
// type: 'Metamaps',
|
|
|
|
levelDistance: 200,
|
|
|
|
numberOfCircles: 4,
|
|
|
|
CanvasStyles: {
|
|
|
|
strokeStyle: '#333',
|
|
|
|
lineWidth: 1.5
|
|
|
|
}
|
|
|
|
},
|
|
|
|
levelDistance: 200
|
|
|
|
},
|
|
|
|
onMouseEnter: function (edge) {
|
2016-10-05 01:45:21 +08:00
|
|
|
const filtered = edge.getData('alpha') === 0
|
2016-04-15 08:43:46 +08:00
|
|
|
|
|
|
|
// don't do anything if the edge is filtered
|
2016-10-05 01:45:21 +08:00
|
|
|
// or if the canvas is animating
|
2016-09-22 18:31:56 +08:00
|
|
|
if (filtered || Visualize.mGraph.busy) return
|
2016-04-15 08:43:46 +08:00
|
|
|
|
|
|
|
$('canvas').css('cursor', 'pointer')
|
2016-10-05 01:45:21 +08:00
|
|
|
const edgeIsSelected = Selected.Edges.indexOf(edge)
|
2016-04-15 08:43:46 +08:00
|
|
|
// following if statement only executes if the edge being hovered over is not selected
|
2016-10-05 01:45:21 +08:00
|
|
|
if (edgeIsSelected === -1) {
|
2016-04-15 08:43:46 +08:00
|
|
|
edge.setData('showDesc', true, 'current')
|
|
|
|
}
|
2016-02-03 21:38:41 +08:00
|
|
|
|
2016-04-15 08:43:46 +08:00
|
|
|
edge.setDataset('end', {
|
|
|
|
lineWidth: 4
|
|
|
|
})
|
2016-09-22 18:31:56 +08:00
|
|
|
Visualize.mGraph.fx.animate({
|
2016-04-15 08:43:46 +08:00
|
|
|
modes: ['edge-property:lineWidth'],
|
|
|
|
duration: 100
|
|
|
|
})
|
2016-09-22 18:31:56 +08:00
|
|
|
Visualize.mGraph.plot()
|
2016-04-15 08:43:46 +08:00
|
|
|
}, // onMouseEnter
|
|
|
|
onMouseLeave: function (edge) {
|
2016-10-05 01:45:21 +08:00
|
|
|
if (edge.getData('alpha') === 0) return // don't do anything if the edge is filtered
|
2016-04-15 08:43:46 +08:00
|
|
|
$('canvas').css('cursor', 'default')
|
2016-10-05 01:45:21 +08:00
|
|
|
const edgeIsSelected = Selected.Edges.indexOf(edge)
|
2016-04-15 08:43:46 +08:00
|
|
|
// following if statement only executes if the edge being hovered over is not selected
|
2016-10-05 01:45:21 +08:00
|
|
|
if (edgeIsSelected === -1) {
|
2016-04-15 08:43:46 +08:00
|
|
|
edge.setData('showDesc', false, 'current')
|
|
|
|
}
|
2016-02-03 21:38:41 +08:00
|
|
|
|
2016-04-15 08:43:46 +08:00
|
|
|
edge.setDataset('end', {
|
|
|
|
lineWidth: 2
|
|
|
|
})
|
2016-09-22 18:31:56 +08:00
|
|
|
Visualize.mGraph.fx.animate({
|
2016-04-15 08:43:46 +08:00
|
|
|
modes: ['edge-property:lineWidth'],
|
|
|
|
duration: 100
|
|
|
|
})
|
2016-09-22 18:31:56 +08:00
|
|
|
Visualize.mGraph.plot()
|
2016-04-15 08:43:46 +08:00
|
|
|
}, // onMouseLeave
|
2016-10-05 01:45:21 +08:00
|
|
|
onMouseMoveHandler: function (_node, eventInfo, e) {
|
|
|
|
const self = JIT
|
2016-04-15 08:43:46 +08:00
|
|
|
|
2016-09-22 18:31:56 +08:00
|
|
|
if (Visualize.mGraph.busy) return
|
2016-04-15 08:43:46 +08:00
|
|
|
|
2016-10-05 01:45:21 +08:00
|
|
|
const node = eventInfo.getNode()
|
|
|
|
const edge = eventInfo.getEdge()
|
2016-04-15 08:43:46 +08:00
|
|
|
|
|
|
|
// if we're on top of a node object, act like there aren't edges under it
|
2016-10-05 01:45:21 +08:00
|
|
|
if (node !== false) {
|
2016-09-22 18:31:56 +08:00
|
|
|
if (Mouse.edgeHoveringOver) {
|
|
|
|
self.onMouseLeave(Mouse.edgeHoveringOver)
|
2016-04-15 08:43:46 +08:00
|
|
|
}
|
|
|
|
$('canvas').css('cursor', 'pointer')
|
|
|
|
return
|
|
|
|
}
|
2016-02-03 21:38:41 +08:00
|
|
|
|
2016-10-05 01:45:21 +08:00
|
|
|
if (edge === false && Mouse.edgeHoveringOver !== false) {
|
2016-04-15 08:43:46 +08:00
|
|
|
// mouse not on an edge, but we were on an edge previously
|
2016-09-22 18:31:56 +08:00
|
|
|
self.onMouseLeave(Mouse.edgeHoveringOver)
|
2016-10-05 01:45:21 +08:00
|
|
|
} else if (edge !== false && Mouse.edgeHoveringOver === false) {
|
2016-04-15 08:43:46 +08:00
|
|
|
// mouse is on an edge, but there isn't a stored edge
|
|
|
|
self.onMouseEnter(edge)
|
2016-10-05 01:45:21 +08:00
|
|
|
} else if (edge !== false && Mouse.edgeHoveringOver !== edge) {
|
2016-04-15 08:43:46 +08:00
|
|
|
// mouse is on an edge, but a different edge is stored
|
2016-09-22 18:31:56 +08:00
|
|
|
self.onMouseLeave(Mouse.edgeHoveringOver)
|
2016-04-15 08:43:46 +08:00
|
|
|
self.onMouseEnter(edge)
|
|
|
|
}
|
2016-02-03 21:38:41 +08:00
|
|
|
|
2016-04-15 08:43:46 +08:00
|
|
|
// could be false
|
2016-09-22 18:31:56 +08:00
|
|
|
Mouse.edgeHoveringOver = edge
|
2016-02-03 21:38:41 +08:00
|
|
|
|
2016-04-15 08:43:46 +08:00
|
|
|
if (!node && !edge) {
|
|
|
|
$('canvas').css('cursor', 'default')
|
|
|
|
}
|
|
|
|
}, // onMouseMoveHandler
|
|
|
|
enterKeyHandler: function () {
|
2016-10-05 01:45:21 +08:00
|
|
|
const creatingMap = GlobalUI.lightbox
|
2016-04-15 08:43:46 +08:00
|
|
|
if (creatingMap === 'newmap' || creatingMap === 'forkmap') {
|
2016-09-22 18:31:56 +08:00
|
|
|
GlobalUI.CreateMap.submit()
|
2016-10-05 01:45:21 +08:00
|
|
|
} else if (Create.newTopic.beingCreated) {
|
2016-09-22 18:31:56 +08:00
|
|
|
Topic.createTopicLocally()
|
2016-10-05 01:45:21 +08:00
|
|
|
} else if (Create.newSynapse.beingCreated) {
|
2016-09-22 18:31:56 +08:00
|
|
|
Synapse.createSynapseLocally()
|
2016-04-15 08:43:46 +08:00
|
|
|
}
|
|
|
|
}, // enterKeyHandler
|
|
|
|
escKeyHandler: function () {
|
2016-09-22 18:31:56 +08:00
|
|
|
Control.deselectAllEdges()
|
|
|
|
Control.deselectAllNodes()
|
2016-04-15 08:43:46 +08:00
|
|
|
}, // escKeyHandler
|
|
|
|
onDragMoveTopicHandler: function (node, eventInfo, e) {
|
2016-10-05 01:45:21 +08:00
|
|
|
const self = JIT
|
2016-04-15 08:43:46 +08:00
|
|
|
|
2016-10-05 01:45:21 +08:00
|
|
|
// this is used to send nodes that are moving to
|
2016-04-15 08:43:46 +08:00
|
|
|
// other realtime collaborators on the same map
|
2016-10-05 01:45:21 +08:00
|
|
|
const positionsToSend = {}
|
|
|
|
let topic
|
2016-04-15 08:43:46 +08:00
|
|
|
|
2016-10-05 01:45:21 +08:00
|
|
|
const authorized = Active.Map && Active.Map.authorizeToEdit(Active.Mapper)
|
2016-04-15 08:43:46 +08:00
|
|
|
|
|
|
|
if (node && !node.nodeFrom) {
|
2016-10-05 01:45:21 +08:00
|
|
|
const pos = eventInfo.getPos()
|
2016-04-15 08:43:46 +08:00
|
|
|
// if it's a left click, or a touch, move the node
|
2016-10-05 01:45:21 +08:00
|
|
|
if (e.touches || (e.button === 0 && !e.altKey && !e.ctrlKey && !e.shiftKey && (e.buttons === 0 || e.buttons === 1 || e.buttons === undefined))) {
|
2016-04-15 08:43:46 +08:00
|
|
|
// if the node dragged isn't already selected, select it
|
2016-10-05 01:45:21 +08:00
|
|
|
const whatToDo = self.handleSelectionBeforeDragging(node, e)
|
2016-04-15 08:43:46 +08:00
|
|
|
if (node.pos.rho || node.pos.rho === 0) {
|
|
|
|
// this means we're in topic view
|
2016-10-05 01:45:21 +08:00
|
|
|
const rho = Math.sqrt(pos.x * pos.x + pos.y * pos.y)
|
|
|
|
const theta = Math.atan2(pos.y, pos.x)
|
2016-04-15 08:43:46 +08:00
|
|
|
node.pos.setp(theta, rho)
|
2016-10-05 01:45:21 +08:00
|
|
|
} else if (whatToDo === 'only-drag-this-one') {
|
2016-04-15 08:43:46 +08:00
|
|
|
node.pos.setc(pos.x, pos.y)
|
|
|
|
|
2016-09-22 18:31:56 +08:00
|
|
|
if (Active.Map) {
|
2016-04-15 08:43:46 +08:00
|
|
|
topic = node.getData('topic')
|
|
|
|
// we use the topic ID not the node id
|
|
|
|
// because we can't depend on the node id
|
|
|
|
// to be the same as on other collaborators
|
|
|
|
// maps
|
|
|
|
positionsToSend[topic.id] = pos
|
2016-09-22 15:21:59 +08:00
|
|
|
$(document).trigger(JIT.events.topicDrag, [positionsToSend])
|
2016-04-15 08:43:46 +08:00
|
|
|
}
|
|
|
|
} else {
|
2016-10-05 01:45:21 +08:00
|
|
|
const len = Selected.Nodes.length
|
2016-04-15 08:43:46 +08:00
|
|
|
|
|
|
|
// first define offset for each node
|
2016-10-05 01:45:21 +08:00
|
|
|
const xOffset = []
|
|
|
|
const yOffset = []
|
|
|
|
for (let i = 0; i < len; i += 1) {
|
|
|
|
const n = Selected.Nodes[i]
|
2016-04-15 08:43:46 +08:00
|
|
|
xOffset[i] = n.pos.x - node.pos.x
|
|
|
|
yOffset[i] = n.pos.y - node.pos.y
|
|
|
|
} // for
|
|
|
|
|
2016-10-05 01:45:21 +08:00
|
|
|
for (let i = 0; i < len; i += 1) {
|
|
|
|
const n = Selected.Nodes[i]
|
|
|
|
const x = pos.x + xOffset[i]
|
|
|
|
const y = pos.y + yOffset[i]
|
2016-04-15 08:43:46 +08:00
|
|
|
n.pos.setc(x, y)
|
|
|
|
|
2016-09-22 18:31:56 +08:00
|
|
|
if (Active.Map) {
|
2016-04-15 08:43:46 +08:00
|
|
|
topic = n.getData('topic')
|
|
|
|
// we use the topic ID not the node id
|
|
|
|
// because we can't depend on the node id
|
|
|
|
// to be the same as on other collaborators
|
|
|
|
// maps
|
|
|
|
positionsToSend[topic.id] = n.pos
|
2016-02-03 21:38:41 +08:00
|
|
|
}
|
2016-04-15 08:43:46 +08:00
|
|
|
} // for
|
2016-02-03 21:38:41 +08:00
|
|
|
|
2016-09-22 18:31:56 +08:00
|
|
|
if (Active.Map) {
|
2016-09-22 15:21:59 +08:00
|
|
|
$(document).trigger(JIT.events.topicDrag, [positionsToSend])
|
2016-04-15 08:43:46 +08:00
|
|
|
}
|
|
|
|
} // if
|
2016-02-03 21:38:41 +08:00
|
|
|
|
2016-10-05 01:45:21 +08:00
|
|
|
if (whatToDo === 'deselect') {
|
2016-09-22 18:31:56 +08:00
|
|
|
Control.deselectNode(node)
|
2016-02-03 21:38:41 +08:00
|
|
|
}
|
2016-09-22 18:31:56 +08:00
|
|
|
Visualize.mGraph.plot()
|
2016-10-05 01:45:21 +08:00
|
|
|
} else if ((e.button === 2 || (e.button === 0 && e.altKey) || e.buttons === 2) && authorized) {
|
|
|
|
// if it's a right click or holding down alt, start synapse creation ->third option is for firefox
|
|
|
|
if (JIT.tempInit === false) {
|
2016-09-22 17:08:53 +08:00
|
|
|
JIT.tempNode = node
|
|
|
|
JIT.tempInit = true
|
2016-04-15 08:43:46 +08:00
|
|
|
|
2016-09-22 18:31:56 +08:00
|
|
|
Create.newTopic.hide()
|
|
|
|
Create.newSynapse.hide()
|
2016-04-15 08:43:46 +08:00
|
|
|
// set the draw synapse start positions
|
2016-10-05 01:45:21 +08:00
|
|
|
const l = Selected.Nodes.length
|
2016-04-15 08:43:46 +08:00
|
|
|
if (l > 0) {
|
2016-09-26 13:37:42 +08:00
|
|
|
for (let i = l - 1; i >= 0; i -= 1) {
|
|
|
|
const n = Selected.Nodes[i]
|
2016-09-22 18:31:56 +08:00
|
|
|
Mouse.synapseStartCoordinates.push({
|
2016-04-15 08:43:46 +08:00
|
|
|
x: n.pos.getc().x,
|
|
|
|
y: n.pos.getc().y
|
|
|
|
})
|
2016-02-03 21:38:41 +08:00
|
|
|
}
|
2016-04-15 08:43:46 +08:00
|
|
|
} else {
|
2016-09-22 18:31:56 +08:00
|
|
|
Mouse.synapseStartCoordinates = [{
|
2016-09-22 17:08:53 +08:00
|
|
|
x: JIT.tempNode.pos.getc().x,
|
|
|
|
y: JIT.tempNode.pos.getc().y
|
2016-04-15 08:43:46 +08:00
|
|
|
}]
|
|
|
|
}
|
2016-09-22 18:31:56 +08:00
|
|
|
Mouse.synapseEndCoordinates = {
|
2016-04-15 08:43:46 +08:00
|
|
|
x: pos.x,
|
|
|
|
y: pos.y
|
|
|
|
}
|
2016-02-03 21:38:41 +08:00
|
|
|
}
|
2016-04-15 08:43:46 +08:00
|
|
|
//
|
2016-09-22 14:25:49 +08:00
|
|
|
let temp = eventInfo.getNode()
|
2016-10-05 01:45:21 +08:00
|
|
|
if (temp !== false && temp.id !== node.id && Selected.Nodes.indexOf(temp) === -1) { // this means a Node has been returned
|
2016-09-22 17:08:53 +08:00
|
|
|
JIT.tempNode2 = temp
|
2016-04-15 08:43:46 +08:00
|
|
|
|
2016-09-22 18:31:56 +08:00
|
|
|
Mouse.synapseEndCoordinates = {
|
2016-09-22 17:08:53 +08:00
|
|
|
x: JIT.tempNode2.pos.getc().x,
|
|
|
|
y: JIT.tempNode2.pos.getc().y
|
2016-04-15 08:43:46 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// before making the highlighted one bigger, make sure all the others are regular size
|
2016-09-22 18:31:56 +08:00
|
|
|
Visualize.mGraph.graph.eachNode(function (n) {
|
2016-04-15 08:43:46 +08:00
|
|
|
n.setData('dim', 25, 'current')
|
|
|
|
})
|
|
|
|
temp.setData('dim', 35, 'current')
|
2016-09-22 18:31:56 +08:00
|
|
|
Visualize.mGraph.plot()
|
2016-04-15 08:43:46 +08:00
|
|
|
} else if (!temp) {
|
2016-09-22 17:08:53 +08:00
|
|
|
JIT.tempNode2 = null
|
2016-09-22 18:31:56 +08:00
|
|
|
Visualize.mGraph.graph.eachNode(function (n) {
|
2016-04-15 08:43:46 +08:00
|
|
|
n.setData('dim', 25, 'current')
|
|
|
|
})
|
|
|
|
// pop up node creation :)
|
2016-10-05 01:45:21 +08:00
|
|
|
const myX = e.clientX - 110
|
|
|
|
const myY = e.clientY - 30
|
2016-04-15 08:43:46 +08:00
|
|
|
$('#new_topic').css('left', myX + 'px')
|
|
|
|
$('#new_topic').css('top', myY + 'px')
|
2016-09-22 18:31:56 +08:00
|
|
|
Create.newTopic.x = eventInfo.getPos().x
|
|
|
|
Create.newTopic.y = eventInfo.getPos().y
|
|
|
|
Visualize.mGraph.plot()
|
2016-04-15 08:43:46 +08:00
|
|
|
|
2016-09-22 18:31:56 +08:00
|
|
|
Mouse.synapseEndCoordinates = {
|
2016-04-15 08:43:46 +08:00
|
|
|
x: pos.x,
|
|
|
|
y: pos.y
|
|
|
|
}
|
2016-02-03 21:38:41 +08:00
|
|
|
}
|
2016-10-05 01:45:21 +08:00
|
|
|
} else if ((e.button === 2 || (e.button === 0 && e.altKey) || e.buttons === 2) && Active.Topic) {
|
2016-09-22 18:31:56 +08:00
|
|
|
GlobalUI.notifyUser('Cannot create in Topic view.')
|
2016-10-05 01:45:21 +08:00
|
|
|
} else if ((e.button === 2 || (e.button === 0 && e.altKey) || e.buttons === 2) && !authorized) {
|
2016-09-22 18:31:56 +08:00
|
|
|
GlobalUI.notifyUser('Cannot edit Public map.')
|
2016-04-15 08:43:46 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}, // onDragMoveTopicHandler
|
|
|
|
onDragCancelHandler: function (node, eventInfo, e) {
|
2016-09-22 17:08:53 +08:00
|
|
|
JIT.tempNode = null
|
|
|
|
if (JIT.tempNode2) JIT.tempNode2.setData('dim', 25, 'current')
|
|
|
|
JIT.tempNode2 = null
|
|
|
|
JIT.tempInit = false
|
2016-04-15 08:43:46 +08:00
|
|
|
// reset the draw synapse positions to false
|
2016-09-22 18:31:56 +08:00
|
|
|
Mouse.synapseStartCoordinates = []
|
|
|
|
Mouse.synapseEndCoordinates = null
|
|
|
|
Visualize.mGraph.plot()
|
2016-04-15 08:43:46 +08:00
|
|
|
}, // onDragCancelHandler
|
|
|
|
onDragEndTopicHandler: function (node, eventInfo, e) {
|
2016-10-05 01:45:21 +08:00
|
|
|
let midpoint = {}
|
|
|
|
let pixelPos
|
|
|
|
let mapping
|
2016-04-15 08:43:46 +08:00
|
|
|
|
2016-09-22 17:08:53 +08:00
|
|
|
if (JIT.tempInit && JIT.tempNode2 == null) {
|
2016-04-15 08:43:46 +08:00
|
|
|
// this means you want to add a new topic, and then a synapse
|
2016-09-22 18:31:56 +08:00
|
|
|
Create.newTopic.addSynapse = true
|
|
|
|
Create.newTopic.open()
|
2016-09-22 17:08:53 +08:00
|
|
|
} else if (JIT.tempInit && JIT.tempNode2 != null) {
|
2016-04-15 08:43:46 +08:00
|
|
|
// this means you want to create a synapse between two existing topics
|
2016-09-22 18:31:56 +08:00
|
|
|
Create.newTopic.addSynapse = false
|
|
|
|
Create.newSynapse.topic1id = JIT.tempNode.getData('topic').id
|
|
|
|
Create.newSynapse.topic2id = JIT.tempNode2.getData('topic').id
|
2016-09-22 17:08:53 +08:00
|
|
|
JIT.tempNode2.setData('dim', 25, 'current')
|
2016-09-22 18:31:56 +08:00
|
|
|
Visualize.mGraph.plot()
|
2016-09-22 17:08:53 +08:00
|
|
|
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
|
2016-09-22 18:31:56 +08:00
|
|
|
pixelPos = Util.coordsToPixels(midpoint)
|
2016-04-15 08:43:46 +08:00
|
|
|
$('#new_synapse').css('left', pixelPos.x + 'px')
|
|
|
|
$('#new_synapse').css('top', pixelPos.y + 'px')
|
2016-09-22 18:31:56 +08:00
|
|
|
Create.newSynapse.open()
|
2016-09-22 17:08:53 +08:00
|
|
|
JIT.tempNode = null
|
|
|
|
JIT.tempNode2 = null
|
|
|
|
JIT.tempInit = false
|
|
|
|
} else if (!JIT.tempInit && node && !node.nodeFrom) {
|
2016-04-15 08:43:46 +08:00
|
|
|
// this means you dragged an existing node, autosave that to the database
|
|
|
|
|
|
|
|
// check whether to save mappings
|
2016-10-05 01:45:21 +08:00
|
|
|
const checkWhetherToSave = function () {
|
|
|
|
const map = Active.Map
|
2016-04-15 08:43:46 +08:00
|
|
|
if (!map) return false
|
2016-10-17 22:27:15 -04:00
|
|
|
return map.authorizeToEdit(Active.Mapper)
|
2016-04-15 08:43:46 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (checkWhetherToSave()) {
|
|
|
|
mapping = node.getData('mapping')
|
|
|
|
mapping.save({
|
|
|
|
xloc: node.getPos().x,
|
|
|
|
yloc: node.getPos().y
|
|
|
|
})
|
|
|
|
// also save any other selected nodes that also got dragged along
|
2016-10-05 01:45:21 +08:00
|
|
|
const l = Selected.Nodes.length
|
2016-04-15 08:43:46 +08:00
|
|
|
for (var i = l - 1; i >= 0; i -= 1) {
|
2016-10-05 01:45:21 +08:00
|
|
|
const n = Selected.Nodes[i]
|
2016-04-15 08:43:46 +08:00
|
|
|
if (n !== node) {
|
|
|
|
mapping = n.getData('mapping')
|
|
|
|
mapping.save({
|
|
|
|
xloc: n.getPos().x,
|
|
|
|
yloc: n.getPos().y
|
|
|
|
})
|
|
|
|
}
|
2016-02-03 21:38:41 +08:00
|
|
|
}
|
2016-04-15 08:43:46 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}, // onDragEndTopicHandler
|
|
|
|
canvasClickHandler: function (canvasLoc, e) {
|
2016-10-05 01:45:21 +08:00
|
|
|
// grab the location and timestamp of the click
|
|
|
|
const storedTime = Mouse.lastCanvasClick
|
|
|
|
const now = Date.now() // not compatible with IE8 FYI
|
2016-09-22 18:31:56 +08:00
|
|
|
Mouse.lastCanvasClick = now
|
2016-04-15 08:43:46 +08:00
|
|
|
|
2016-10-05 01:45:21 +08:00
|
|
|
const authorized = Active.Map && Active.Map.authorizeToEdit(Active.Mapper)
|
2016-04-15 08:43:46 +08:00
|
|
|
|
2016-09-22 18:31:56 +08:00
|
|
|
if (now - storedTime < Mouse.DOUBLE_CLICK_TOLERANCE && !Mouse.didPan) {
|
|
|
|
if (Active.Map && !authorized) {
|
|
|
|
GlobalUI.notifyUser('Cannot edit Public map.')
|
2016-04-15 08:43:46 +08:00
|
|
|
return
|
2016-10-05 01:45:21 +08:00
|
|
|
} else if (Active.Topic) {
|
2016-09-22 18:31:56 +08:00
|
|
|
GlobalUI.notifyUser('Cannot create in Topic view.')
|
2016-04-15 08:43:46 +08:00
|
|
|
return
|
|
|
|
}
|
|
|
|
// DOUBLE CLICK
|
2016-10-05 01:45:21 +08:00
|
|
|
// pop up node creation :)
|
2016-09-22 18:31:56 +08:00
|
|
|
Create.newTopic.addSynapse = false
|
|
|
|
Create.newTopic.x = canvasLoc.x
|
|
|
|
Create.newTopic.y = canvasLoc.y
|
2016-04-15 08:43:46 +08:00
|
|
|
$('#new_topic').css('left', e.clientX + 'px')
|
|
|
|
$('#new_topic').css('top', e.clientY + 'px')
|
2016-09-22 18:31:56 +08:00
|
|
|
Create.newTopic.open()
|
|
|
|
} else if (!Mouse.didPan) {
|
2016-04-15 08:43:46 +08:00
|
|
|
// SINGLE CLICK, no pan
|
2016-09-22 18:31:56 +08:00
|
|
|
Filter.close()
|
|
|
|
TopicCard.hideCard()
|
|
|
|
SynapseCard.hideCard()
|
|
|
|
Create.newTopic.hide()
|
2016-04-15 08:43:46 +08:00
|
|
|
$('.rightclickmenu').remove()
|
|
|
|
// reset the draw synapse positions to false
|
2016-09-22 18:31:56 +08:00
|
|
|
Mouse.synapseStartCoordinates = []
|
|
|
|
Mouse.synapseEndCoordinates = null
|
2016-09-22 17:08:53 +08:00
|
|
|
JIT.tempInit = false
|
|
|
|
JIT.tempNode = null
|
|
|
|
JIT.tempNode2 = null
|
2016-04-15 08:43:46 +08:00
|
|
|
if (!e.ctrlKey && !e.shiftKey) {
|
2016-09-22 18:31:56 +08:00
|
|
|
Control.deselectAllEdges()
|
|
|
|
Control.deselectAllNodes()
|
2016-04-15 08:43:46 +08:00
|
|
|
}
|
|
|
|
}
|
2016-10-05 01:45:21 +08:00
|
|
|
}, // canvasClickHandler
|
2016-04-15 08:43:46 +08:00
|
|
|
nodeDoubleClickHandler: function (node, e) {
|
2016-09-22 18:31:56 +08:00
|
|
|
TopicCard.showCard(node)
|
2016-04-15 08:43:46 +08:00
|
|
|
}, // nodeDoubleClickHandler
|
|
|
|
edgeDoubleClickHandler: function (adj, e) {
|
2016-09-22 18:31:56 +08:00
|
|
|
SynapseCard.showCard(adj, e)
|
2016-04-15 08:43:46 +08:00
|
|
|
}, // nodeDoubleClickHandler
|
|
|
|
nodeWasDoubleClicked: function () {
|
2016-10-05 01:45:21 +08:00
|
|
|
// grab the timestamp of the click
|
|
|
|
const storedTime = Mouse.lastNodeClick
|
|
|
|
const now = Date.now() // not compatible with IE8 FYI
|
2016-09-22 18:31:56 +08:00
|
|
|
Mouse.lastNodeClick = now
|
2016-04-15 08:43:46 +08:00
|
|
|
|
2016-09-22 18:31:56 +08:00
|
|
|
if (now - storedTime < Mouse.DOUBLE_CLICK_TOLERANCE) {
|
2016-04-15 08:43:46 +08:00
|
|
|
return true
|
|
|
|
} else {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
}, // nodeWasDoubleClicked
|
|
|
|
handleSelectionBeforeDragging: function (node, e) {
|
|
|
|
// four cases:
|
|
|
|
// 1 nothing is selected, so pretend you aren't selecting
|
|
|
|
// 2 others are selected only and shift, so additionally select this one
|
|
|
|
// 3 others are selected only, no shift: drag only this one
|
|
|
|
// 4 this node and others were selected, so drag them (just return false)
|
|
|
|
// return value: deselect node again after?
|
2016-10-05 01:45:21 +08:00
|
|
|
if (Selected.Nodes.length === 0) {
|
2016-04-15 08:43:46 +08:00
|
|
|
return 'only-drag-this-one'
|
|
|
|
}
|
2016-10-05 01:45:21 +08:00
|
|
|
if (Selected.Nodes.indexOf(node) === -1) {
|
2016-04-15 08:43:46 +08:00
|
|
|
if (e.shiftKey) {
|
2016-09-22 18:31:56 +08:00
|
|
|
Control.selectNode(node, e)
|
2016-04-15 08:43:46 +08:00
|
|
|
return 'nothing'
|
|
|
|
} else {
|
|
|
|
return 'only-drag-this-one'
|
|
|
|
}
|
|
|
|
}
|
2016-10-05 01:45:21 +08:00
|
|
|
return 'nothing' // case 4?
|
2016-04-15 08:43:46 +08:00
|
|
|
}, // handleSelectionBeforeDragging
|
2016-10-05 01:45:21 +08:00
|
|
|
getNodeXY: function (node) {
|
|
|
|
if (typeof node.pos.x === 'number' && typeof node.pos.y === 'number') {
|
2016-08-07 13:17:25 +08:00
|
|
|
return node.pos
|
2016-10-05 01:45:21 +08:00
|
|
|
} else if (typeof node.pos.theta === 'number' && typeof node.pos.rho === 'number') {
|
2016-08-07 13:17:25 +08:00
|
|
|
return new $jit.Polar(node.pos.theta, node.pos.rho).getc(true)
|
|
|
|
} else {
|
|
|
|
console.error('getNodeXY: unrecognized node pos format')
|
|
|
|
return {}
|
|
|
|
}
|
|
|
|
},
|
2016-04-15 08:43:46 +08:00
|
|
|
selectWithBox: function (e) {
|
2016-10-05 01:45:21 +08:00
|
|
|
const self = this
|
|
|
|
let sX = Mouse.boxStartCoordinates.x
|
|
|
|
let sY = Mouse.boxStartCoordinates.y
|
|
|
|
let eX = Mouse.boxEndCoordinates.x
|
|
|
|
let eY = Mouse.boxEndCoordinates.y
|
2016-04-15 08:43:46 +08:00
|
|
|
|
|
|
|
if (!e.shiftKey) {
|
2016-09-22 18:31:56 +08:00
|
|
|
Control.deselectAllNodes()
|
|
|
|
Control.deselectAllEdges()
|
2016-04-15 08:43:46 +08:00
|
|
|
}
|
2016-02-03 21:38:41 +08:00
|
|
|
|
2016-04-15 08:43:46 +08:00
|
|
|
// select all nodes that are within the box
|
2016-10-05 01:45:21 +08:00
|
|
|
Visualize.mGraph.graph.eachNode(function (n) {
|
|
|
|
const pos = self.getNodeXY(n)
|
|
|
|
const x = pos.x
|
|
|
|
const y = pos.y
|
2016-08-07 13:17:25 +08:00
|
|
|
|
|
|
|
// depending on which way the person dragged the box, check that
|
|
|
|
// x and y are between the start and end values of the box
|
|
|
|
if ((sX < x && x < eX && sY < y && y < eY) ||
|
2016-10-05 01:45:21 +08:00
|
|
|
(sX > x && x > eX && sY > y && y > eY) ||
|
|
|
|
(sX > x && x > eX && sY < y && y < eY) ||
|
|
|
|
(sX < x && x < eX && sY > y && y > eY)) {
|
2016-04-15 08:43:46 +08:00
|
|
|
if (e.shiftKey) {
|
|
|
|
if (n.selected) {
|
2016-09-22 18:31:56 +08:00
|
|
|
Control.deselectNode(n)
|
2016-04-15 08:43:46 +08:00
|
|
|
} else {
|
2016-09-22 18:31:56 +08:00
|
|
|
Control.selectNode(n, e)
|
2016-04-15 08:43:46 +08:00
|
|
|
}
|
2016-02-03 21:38:41 +08:00
|
|
|
} else {
|
2016-09-22 18:31:56 +08:00
|
|
|
Control.selectNode(n, e)
|
2016-02-03 21:38:41 +08:00
|
|
|
}
|
2016-04-15 08:43:46 +08:00
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
// Convert selection box coordinates to traditional coordinates (+,+) in upper right
|
|
|
|
sY = -1 * sY
|
|
|
|
eY = -1 * eY
|
|
|
|
|
2016-10-05 01:45:21 +08:00
|
|
|
const edgesToToggle = []
|
2016-04-15 08:43:46 +08:00
|
|
|
Metamaps.Synapses.each(function (synapse) {
|
2016-10-05 01:45:21 +08:00
|
|
|
const e = synapse.get('edge')
|
2016-04-15 08:43:46 +08:00
|
|
|
if (edgesToToggle.indexOf(e) === -1) {
|
|
|
|
edgesToToggle.push(e)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
edgesToToggle.forEach(function (edge) {
|
2016-10-05 01:45:21 +08:00
|
|
|
const fromNodePos = self.getNodeXY(edge.nodeFrom)
|
|
|
|
const fromNodeX = fromNodePos.x
|
|
|
|
const fromNodeY = -1 * fromNodePos.y
|
|
|
|
const toNodePos = self.getNodeXY(edge.nodeTo)
|
|
|
|
const toNodeX = toNodePos.x
|
|
|
|
const toNodeY = -1 * toNodePos.y
|
|
|
|
|
|
|
|
let maxX = fromNodeX
|
|
|
|
let maxY = fromNodeY
|
|
|
|
let minX = fromNodeX
|
|
|
|
let minY = fromNodeY
|
2016-04-15 08:43:46 +08:00
|
|
|
|
|
|
|
// Correct maxX, MaxY values
|
|
|
|
;(toNodeX > maxX) ? (maxX = toNodeX) : (minX = toNodeX)
|
|
|
|
;(toNodeY > maxY) ? (maxY = toNodeY) : (minY = toNodeY)
|
|
|
|
|
2016-10-05 01:45:21 +08:00
|
|
|
let maxBoxX = sX
|
|
|
|
let maxBoxY = sY
|
|
|
|
let minBoxX = sX
|
|
|
|
let minBoxY = sY
|
2016-04-15 08:43:46 +08:00
|
|
|
|
|
|
|
// Correct maxBoxX, maxBoxY values
|
|
|
|
;(eX > maxBoxX) ? (maxBoxX = eX) : (minBoxX = eX)
|
|
|
|
;(eY > maxBoxY) ? (maxBoxY = eY) : (minBoxY = eY)
|
|
|
|
|
|
|
|
// Find the slopes from the synapse fromNode to the 4 corners of the selection box
|
2016-10-05 01:45:21 +08:00
|
|
|
const slopes = []
|
2016-04-15 08:43:46 +08:00
|
|
|
slopes.push((sY - fromNodeY) / (sX - fromNodeX))
|
|
|
|
slopes.push((sY - fromNodeY) / (eX - fromNodeX))
|
|
|
|
slopes.push((eY - fromNodeY) / (eX - fromNodeX))
|
|
|
|
slopes.push((eY - fromNodeY) / (sX - fromNodeX))
|
|
|
|
|
2016-10-05 01:45:21 +08:00
|
|
|
let minSlope = slopes[0]
|
|
|
|
let maxSlope = slopes[0]
|
2016-04-15 08:43:46 +08:00
|
|
|
slopes.forEach(function (entry) {
|
|
|
|
if (entry > maxSlope) maxSlope = entry
|
|
|
|
if (entry < minSlope) minSlope = entry
|
|
|
|
})
|
|
|
|
|
|
|
|
// Find synapse-in-question's slope
|
2016-10-05 01:45:21 +08:00
|
|
|
const synSlope = (toNodeY - fromNodeY) / (toNodeX - fromNodeX)
|
|
|
|
const b = fromNodeY - synSlope * fromNodeX
|
2016-04-15 08:43:46 +08:00
|
|
|
|
|
|
|
// Use the selection box edges as test cases for synapse intersection
|
2016-10-05 01:45:21 +08:00
|
|
|
let testX = sX
|
|
|
|
let testY = synSlope * testX + b
|
2016-04-15 08:43:46 +08:00
|
|
|
|
2016-10-05 01:45:21 +08:00
|
|
|
let selectTest
|
2016-04-15 08:43:46 +08:00
|
|
|
|
|
|
|
if (testX >= minX && testX <= maxX && testY >= minY && testY <= maxY && testY >= minBoxY && testY <= maxBoxY) {
|
|
|
|
selectTest = true
|
|
|
|
}
|
|
|
|
|
|
|
|
testX = eX
|
|
|
|
testY = synSlope * testX + b
|
|
|
|
|
|
|
|
if (testX >= minX && testX <= maxX && testY >= minY && testY <= maxY && testY >= minBoxY && testY <= maxBoxY) {
|
|
|
|
selectTest = true
|
|
|
|
}
|
|
|
|
|
|
|
|
testY = sY
|
|
|
|
testX = (testY - b) / synSlope
|
|
|
|
|
|
|
|
if (testX >= minX && testX <= maxX && testY >= minY && testY <= maxY && testX >= minBoxX && testX <= maxBoxX) {
|
|
|
|
selectTest = true
|
|
|
|
}
|
|
|
|
|
|
|
|
testY = eY
|
|
|
|
testX = (testY - b) / synSlope
|
|
|
|
|
|
|
|
if (testX >= minX && testX <= maxX && testY >= minY && testY <= maxY && testX >= minBoxX && testX <= maxBoxX) {
|
|
|
|
selectTest = true
|
|
|
|
}
|
|
|
|
|
|
|
|
// Case where the synapse is wholly enclosed in the seldction box
|
|
|
|
if (fromNodeX >= minBoxX && fromNodeX <= maxBoxX && fromNodeY >= minBoxY && fromNodeY <= maxBoxY && toNodeX >= minBoxX && toNodeX <= maxBoxX && toNodeY >= minBoxY && toNodeY <= maxBoxY) {
|
|
|
|
selectTest = true
|
|
|
|
}
|
|
|
|
|
|
|
|
// The test synapse was selected!
|
|
|
|
|
|
|
|
if (selectTest) {
|
2016-10-05 01:45:21 +08:00
|
|
|
// shiftKey = toggleSelect, otherwise
|
2016-04-15 08:43:46 +08:00
|
|
|
if (e.shiftKey) {
|
2016-10-05 01:45:21 +08:00
|
|
|
if (Selected.Edges.indexOf(edge) !== -1) {
|
2016-09-22 18:31:56 +08:00
|
|
|
Control.deselectEdge(edge)
|
2016-04-15 08:43:46 +08:00
|
|
|
} else {
|
2016-09-22 18:31:56 +08:00
|
|
|
Control.selectEdge(edge)
|
2016-04-15 08:43:46 +08:00
|
|
|
}
|
|
|
|
} else {
|
2016-09-22 18:31:56 +08:00
|
|
|
Control.selectEdge(edge)
|
2016-02-03 21:38:41 +08:00
|
|
|
}
|
2016-04-15 08:43:46 +08:00
|
|
|
}
|
|
|
|
})
|
2016-09-22 18:31:56 +08:00
|
|
|
Mouse.boxStartCoordinates = false
|
|
|
|
Mouse.boxEndCoordinates = false
|
|
|
|
Visualize.mGraph.plot()
|
2016-04-15 08:43:46 +08:00
|
|
|
}, // selectWithBox
|
|
|
|
drawSelectBox: function (eventInfo, e) {
|
2016-10-05 01:45:21 +08:00
|
|
|
const ctx = Visualize.mGraph.canvas.getCtx()
|
2016-04-15 08:43:46 +08:00
|
|
|
|
2016-10-05 01:45:21 +08:00
|
|
|
const startX = Mouse.boxStartCoordinates.x
|
|
|
|
const startY = Mouse.boxStartCoordinates.y
|
|
|
|
const currX = eventInfo.getPos().x
|
|
|
|
const currY = eventInfo.getPos().y
|
2016-04-15 08:43:46 +08:00
|
|
|
|
2016-09-22 18:31:56 +08:00
|
|
|
Visualize.mGraph.canvas.clear()
|
|
|
|
Visualize.mGraph.plot()
|
2016-04-15 08:43:46 +08:00
|
|
|
|
|
|
|
ctx.beginPath()
|
|
|
|
ctx.moveTo(startX, startY)
|
|
|
|
ctx.lineTo(startX, currY)
|
|
|
|
ctx.lineTo(currX, currY)
|
|
|
|
ctx.lineTo(currX, startY)
|
|
|
|
ctx.lineTo(startX, startY)
|
|
|
|
ctx.strokeStyle = 'black'
|
|
|
|
ctx.stroke()
|
|
|
|
}, // drawSelectBox
|
|
|
|
selectNodeOnClickHandler: function (node, e) {
|
2016-09-22 18:31:56 +08:00
|
|
|
if (Visualize.mGraph.busy) return
|
2016-04-15 08:43:46 +08:00
|
|
|
|
2016-10-05 01:45:21 +08:00
|
|
|
const self = JIT
|
2016-04-15 08:43:46 +08:00
|
|
|
|
|
|
|
// catch right click on mac, which is often like ctrl+click
|
2016-10-05 01:45:21 +08:00
|
|
|
if (navigator.platform.indexOf('Mac') !== -1 && e.ctrlKey) {
|
2016-04-15 08:43:46 +08:00
|
|
|
self.selectNodeOnRightClickHandler(node, e)
|
|
|
|
return
|
|
|
|
}
|
2016-02-03 21:38:41 +08:00
|
|
|
|
2016-04-15 08:43:46 +08:00
|
|
|
// if on a topic page, let alt+click center you on a new topic
|
2016-09-22 18:31:56 +08:00
|
|
|
if (Active.Topic && e.altKey) {
|
|
|
|
JIT.RGraph.centerOn(node.id)
|
2016-04-15 08:43:46 +08:00
|
|
|
return
|
|
|
|
}
|
2016-02-03 21:38:41 +08:00
|
|
|
|
2016-10-05 01:45:21 +08:00
|
|
|
const check = self.nodeWasDoubleClicked()
|
2016-04-15 08:43:46 +08:00
|
|
|
if (check) {
|
|
|
|
self.nodeDoubleClickHandler(node, e)
|
|
|
|
return
|
|
|
|
} else {
|
|
|
|
// wait a certain length of time, then check again, then run this code
|
|
|
|
setTimeout(function () {
|
2016-09-22 15:21:59 +08:00
|
|
|
if (!JIT.nodeWasDoubleClicked()) {
|
2016-10-05 01:45:21 +08:00
|
|
|
const nodeAlreadySelected = node.selected
|
2016-04-15 08:43:46 +08:00
|
|
|
|
|
|
|
if (!e.shiftKey) {
|
2016-09-22 18:31:56 +08:00
|
|
|
Control.deselectAllNodes()
|
|
|
|
Control.deselectAllEdges()
|
2016-04-15 08:43:46 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (nodeAlreadySelected) {
|
2016-09-22 18:31:56 +08:00
|
|
|
Control.deselectNode(node)
|
2016-04-15 08:43:46 +08:00
|
|
|
} else {
|
2016-09-22 18:31:56 +08:00
|
|
|
Control.selectNode(node, e)
|
2016-04-15 08:43:46 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// trigger animation to final styles
|
2016-09-22 18:31:56 +08:00
|
|
|
Visualize.mGraph.fx.animate({
|
2016-04-15 08:43:46 +08:00
|
|
|
modes: ['edge-property:lineWidth:color:alpha'],
|
|
|
|
duration: 500
|
|
|
|
})
|
2016-09-22 18:31:56 +08:00
|
|
|
Visualize.mGraph.plot()
|
2016-02-03 21:38:41 +08:00
|
|
|
}
|
2016-09-22 18:31:56 +08:00
|
|
|
}, Mouse.DOUBLE_CLICK_TOLERANCE)
|
2016-04-15 08:43:46 +08:00
|
|
|
}
|
|
|
|
}, // selectNodeOnClickHandler
|
|
|
|
selectNodeOnRightClickHandler: function (node, e) {
|
|
|
|
// the 'node' variable is a JIT node, the one that was clicked on
|
|
|
|
// the 'e' variable is the click event
|
2016-02-03 21:38:41 +08:00
|
|
|
|
2016-04-15 08:43:46 +08:00
|
|
|
e.preventDefault()
|
|
|
|
e.stopPropagation()
|
2016-02-03 21:38:41 +08:00
|
|
|
|
2016-09-22 18:31:56 +08:00
|
|
|
if (Visualize.mGraph.busy) return
|
2016-02-03 21:38:41 +08:00
|
|
|
|
2016-04-15 08:43:46 +08:00
|
|
|
// select the node
|
2016-09-22 18:31:56 +08:00
|
|
|
Control.selectNode(node, e)
|
2016-02-03 21:38:41 +08:00
|
|
|
|
2016-04-15 08:43:46 +08:00
|
|
|
// delete old right click menu
|
|
|
|
$('.rightclickmenu').remove()
|
|
|
|
// create new menu for clicked on node
|
2016-10-05 01:45:21 +08:00
|
|
|
const rightclickmenu = document.createElement('div')
|
2016-04-15 08:43:46 +08:00
|
|
|
rightclickmenu.className = 'rightclickmenu'
|
2016-10-05 01:45:21 +08:00
|
|
|
// prevent the custom context menu from immediately opening the default context menu as well
|
|
|
|
rightclickmenu.setAttribute('oncontextmenu', 'return false')
|
|
|
|
|
2016-04-15 08:43:46 +08:00
|
|
|
// add the proper options to the menu
|
2016-10-05 01:45:21 +08:00
|
|
|
let menustring = '<ul>'
|
2016-02-03 21:38:41 +08:00
|
|
|
|
2016-10-05 01:45:21 +08:00
|
|
|
const authorized = Active.Map && Active.Map.authorizeToEdit(Active.Mapper)
|
2016-02-03 21:38:41 +08:00
|
|
|
|
2016-10-05 01:45:21 +08:00
|
|
|
const disabled = authorized ? '' : 'disabled'
|
2016-02-03 21:38:41 +08:00
|
|
|
|
2016-09-22 18:31:56 +08:00
|
|
|
if (Active.Map) menustring += '<li class="rc-hide"><div class="rc-icon"></div>Hide until refresh<div class="rc-keyboard">Ctrl+H</div></li>'
|
|
|
|
if (Active.Map && Active.Mapper) menustring += '<li class="rc-remove ' + disabled + '"><div class="rc-icon"></div>Remove from map<div class="rc-keyboard">Ctrl+M</div></li>'
|
|
|
|
if (Active.Topic) menustring += '<li class="rc-remove"><div class="rc-icon"></div>Remove from view<div class="rc-keyboard">Ctrl+M</div></li>'
|
|
|
|
if (Active.Map && Active.Mapper) menustring += '<li class="rc-delete ' + disabled + '"><div class="rc-icon"></div>Delete<div class="rc-keyboard">Ctrl+D</div></li>'
|
2016-02-03 21:38:41 +08:00
|
|
|
|
2016-09-22 18:31:56 +08:00
|
|
|
if (Active.Topic) {
|
2016-08-09 23:53:50 +08:00
|
|
|
menustring += '<li class="rc-center"><div class="rc-icon"></div>Center this topic<div class="rc-keyboard">Alt+E</div></li>'
|
2016-04-15 08:43:46 +08:00
|
|
|
}
|
2016-10-04 23:38:32 +08:00
|
|
|
|
2016-04-15 08:43:46 +08:00
|
|
|
menustring += '<li class="rc-popout"><div class="rc-icon"></div>Open in new tab</li>'
|
2016-10-04 23:38:32 +08:00
|
|
|
|
2016-09-22 18:31:56 +08:00
|
|
|
if (Active.Mapper) {
|
2016-10-05 01:45:21 +08:00
|
|
|
const options = outdent`
|
2016-10-04 23:38:32 +08:00
|
|
|
<ul>
|
|
|
|
<li class="changeP toCommons"><div class="rc-perm-icon"></div>commons</li>
|
|
|
|
<li class="changeP toPublic"><div class="rc-perm-icon"></div>public</li>
|
|
|
|
<li class="changeP toPrivate"><div class="rc-perm-icon"></div>private</li>
|
|
|
|
</ul>`
|
2016-02-03 21:38:41 +08:00
|
|
|
|
2016-04-15 08:43:46 +08:00
|
|
|
menustring += '<li class="rc-spacer"></li>'
|
2016-02-03 21:38:41 +08:00
|
|
|
|
2016-10-04 23:38:32 +08:00
|
|
|
menustring += outdent`
|
|
|
|
<li class="rc-permission">
|
|
|
|
<div class="rc-icon"></div>
|
|
|
|
Change permissions
|
|
|
|
${options}
|
|
|
|
<div class="expandLi"></div>
|
|
|
|
</li>`
|
2016-02-03 21:38:41 +08:00
|
|
|
|
2016-10-05 01:45:21 +08:00
|
|
|
const metacodeOptions = $('#metacodeOptions').html()
|
2016-02-03 21:38:41 +08:00
|
|
|
|
2016-04-15 08:43:46 +08:00
|
|
|
menustring += '<li class="rc-metacode"><div class="rc-icon"></div>Change metacode' + metacodeOptions + '<div class="expandLi"></div></li>'
|
|
|
|
}
|
2016-09-22 18:31:56 +08:00
|
|
|
if (Active.Topic) {
|
|
|
|
if (!Active.Mapper) {
|
2016-04-15 08:43:46 +08:00
|
|
|
menustring += '<li class="rc-spacer"></li>'
|
|
|
|
}
|
|
|
|
|
|
|
|
// set up the get sibling menu as a "lazy load"
|
|
|
|
// only fill in the submenu when they hover over the get siblings list item
|
2016-10-05 01:45:21 +08:00
|
|
|
const siblingMenu = outdent`
|
2016-10-04 23:38:32 +08:00
|
|
|
<ul id="fetchSiblingList">
|
|
|
|
<li class="fetchAll">All<div class="rc-keyboard">Alt+R</div></li>
|
|
|
|
<li id="loadingSiblings"></li>
|
|
|
|
</ul>`
|
2016-08-08 21:46:05 +08:00
|
|
|
menustring += '<li class="rc-siblings"><div class="rc-icon"></div>Reveal siblings' + siblingMenu + '<div class="expandLi"></div></li>'
|
2016-04-15 08:43:46 +08:00
|
|
|
}
|
2016-02-03 21:38:41 +08:00
|
|
|
|
2016-04-15 08:43:46 +08:00
|
|
|
menustring += '</ul>'
|
|
|
|
rightclickmenu.innerHTML = menustring
|
|
|
|
|
|
|
|
// position the menu where the click happened
|
2016-10-05 01:45:21 +08:00
|
|
|
const position = {}
|
|
|
|
const RIGHTCLICK_WIDTH = 300
|
|
|
|
const RIGHTCLICK_HEIGHT = 144 // this does vary somewhat, but we can use static
|
|
|
|
const SUBMENUS_WIDTH = 256
|
|
|
|
const MAX_SUBMENU_HEIGHT = 270
|
|
|
|
const windowWidth = $(window).width()
|
|
|
|
const windowHeight = $(window).height()
|
2016-04-15 08:43:46 +08:00
|
|
|
|
|
|
|
if (windowWidth - e.clientX < SUBMENUS_WIDTH) {
|
|
|
|
position.right = windowWidth - e.clientX
|
|
|
|
$(rightclickmenu).addClass('moveMenusToLeft')
|
2016-10-05 01:45:21 +08:00
|
|
|
} else if (windowWidth - e.clientX < RIGHTCLICK_WIDTH) {
|
2016-04-15 08:43:46 +08:00
|
|
|
position.right = windowWidth - e.clientX
|
2016-10-05 01:45:21 +08:00
|
|
|
} else if (windowWidth - e.clientX < RIGHTCLICK_WIDTH + SUBMENUS_WIDTH) {
|
2016-04-15 08:43:46 +08:00
|
|
|
position.left = e.clientX
|
|
|
|
$(rightclickmenu).addClass('moveMenusToLeft')
|
2016-10-05 01:45:21 +08:00
|
|
|
} else {
|
|
|
|
position.left = e.clientX
|
2016-04-15 08:43:46 +08:00
|
|
|
}
|
2016-02-03 21:38:41 +08:00
|
|
|
|
2016-04-15 08:43:46 +08:00
|
|
|
if (windowHeight - e.clientY < MAX_SUBMENU_HEIGHT) {
|
|
|
|
position.bottom = windowHeight - e.clientY
|
|
|
|
$(rightclickmenu).addClass('moveMenusUp')
|
2016-10-05 01:45:21 +08:00
|
|
|
} else if (windowHeight - e.clientY < RIGHTCLICK_HEIGHT + MAX_SUBMENU_HEIGHT) {
|
2016-04-15 08:43:46 +08:00
|
|
|
position.top = e.clientY
|
|
|
|
$(rightclickmenu).addClass('moveMenusUp')
|
2016-10-05 01:45:21 +08:00
|
|
|
} else {
|
|
|
|
position.top = e.clientY
|
2016-04-15 08:43:46 +08:00
|
|
|
}
|
2016-02-03 21:38:41 +08:00
|
|
|
|
2016-04-15 08:43:46 +08:00
|
|
|
$(rightclickmenu).css(position)
|
|
|
|
// add the menu to the page
|
|
|
|
$('#wrapper').append(rightclickmenu)
|
2016-02-03 21:38:41 +08:00
|
|
|
|
2016-04-15 08:43:46 +08:00
|
|
|
// attach events to clicks on the list items
|
2016-02-03 21:38:41 +08:00
|
|
|
|
2016-04-15 08:43:46 +08:00
|
|
|
// delete the selected things from the database
|
|
|
|
if (authorized) {
|
|
|
|
$('.rc-delete').click(function () {
|
|
|
|
$('.rightclickmenu').remove()
|
2016-09-22 18:31:56 +08:00
|
|
|
Control.deleteSelected()
|
2016-04-15 08:43:46 +08:00
|
|
|
})
|
|
|
|
}
|
2016-02-03 21:38:41 +08:00
|
|
|
|
2016-04-15 08:43:46 +08:00
|
|
|
// remove the selected things from the map
|
2016-09-22 18:31:56 +08:00
|
|
|
if (Active.Topic || authorized) {
|
2016-04-15 08:43:46 +08:00
|
|
|
$('.rc-remove').click(function () {
|
|
|
|
$('.rightclickmenu').remove()
|
2016-09-22 18:31:56 +08:00
|
|
|
Control.removeSelectedEdges()
|
|
|
|
Control.removeSelectedNodes()
|
2016-04-15 08:43:46 +08:00
|
|
|
})
|
|
|
|
}
|
2016-02-03 21:38:41 +08:00
|
|
|
|
2016-04-15 08:43:46 +08:00
|
|
|
// hide selected nodes and synapses until refresh
|
|
|
|
$('.rc-hide').click(function () {
|
|
|
|
$('.rightclickmenu').remove()
|
2016-09-22 18:31:56 +08:00
|
|
|
Control.hideSelectedEdges()
|
|
|
|
Control.hideSelectedNodes()
|
2016-04-15 08:43:46 +08:00
|
|
|
})
|
|
|
|
|
|
|
|
// when in radial, center on the topic you picked
|
|
|
|
$('.rc-center').click(function () {
|
|
|
|
$('.rightclickmenu').remove()
|
2016-09-22 18:31:56 +08:00
|
|
|
Topic.centerOn(node.id)
|
2016-04-15 08:43:46 +08:00
|
|
|
})
|
|
|
|
|
|
|
|
// open the entity in a new tab
|
|
|
|
$('.rc-popout').click(function () {
|
|
|
|
$('.rightclickmenu').remove()
|
2016-10-05 01:45:21 +08:00
|
|
|
const win = window.open('/topics/' + node.id, '_blank')
|
2016-04-15 08:43:46 +08:00
|
|
|
win.focus()
|
|
|
|
})
|
|
|
|
|
|
|
|
// change the permission of all the selected nodes and synapses that you were the originator of
|
|
|
|
$('.rc-permission li').click(function () {
|
|
|
|
$('.rightclickmenu').remove()
|
|
|
|
// $(this).text() will be 'commons' 'public' or 'private'
|
2016-09-22 18:31:56 +08:00
|
|
|
Control.updateSelectedPermissions($(this).text())
|
2016-04-15 08:43:46 +08:00
|
|
|
})
|
|
|
|
|
|
|
|
// change the metacode of all the selected nodes that you have edit permission for
|
|
|
|
$('.rc-metacode li li').click(function () {
|
|
|
|
$('.rightclickmenu').remove()
|
|
|
|
//
|
2016-09-22 18:31:56 +08:00
|
|
|
Control.updateSelectedMetacodes($(this).attr('data-id'))
|
2016-04-15 08:43:46 +08:00
|
|
|
})
|
|
|
|
|
|
|
|
// fetch relatives
|
2016-10-05 01:45:21 +08:00
|
|
|
let fetchSent = false
|
2016-04-15 08:43:46 +08:00
|
|
|
$('.rc-siblings').hover(function () {
|
2016-10-05 01:45:21 +08:00
|
|
|
if (!fetchSent) {
|
2016-09-22 15:21:59 +08:00
|
|
|
JIT.populateRightClickSiblings(node)
|
2016-10-05 01:45:21 +08:00
|
|
|
fetchSent = true
|
2016-04-15 08:43:46 +08:00
|
|
|
}
|
|
|
|
})
|
|
|
|
$('.rc-siblings .fetchAll').click(function () {
|
|
|
|
$('.rightclickmenu').remove()
|
|
|
|
// data-id is a metacode id
|
2016-09-22 18:31:56 +08:00
|
|
|
Topic.fetchRelatives(node)
|
2016-04-15 08:43:46 +08:00
|
|
|
})
|
|
|
|
}, // selectNodeOnRightClickHandler,
|
|
|
|
populateRightClickSiblings: function (node) {
|
|
|
|
// depending on how many topics are selected, do different things
|
2016-10-05 01:45:21 +08:00
|
|
|
const topic = node.getData('topic')
|
2016-04-15 08:43:46 +08:00
|
|
|
|
|
|
|
// add a loading icon for now
|
2016-10-05 01:45:21 +08:00
|
|
|
const loader = new CanvasLoader('loadingSiblings')
|
|
|
|
loader.setColor('#4FC059') // default is '#000000'
|
2016-04-15 08:43:46 +08:00
|
|
|
loader.setDiameter(15) // default is 40
|
|
|
|
loader.setDensity(41) // default is 40
|
2016-10-05 01:45:21 +08:00
|
|
|
loader.setRange(0.9) // default is 1.3
|
2016-04-15 08:43:46 +08:00
|
|
|
loader.show() // Hidden by default
|
|
|
|
|
2016-10-05 01:45:21 +08:00
|
|
|
const topics = Metamaps.Topics.map(function (t) { return t.id })
|
|
|
|
const topicsString = topics.join()
|
2016-04-15 08:43:46 +08:00
|
|
|
|
2016-10-05 01:45:21 +08:00
|
|
|
const successCallback = function (data) {
|
2016-04-15 08:43:46 +08:00
|
|
|
$('#loadingSiblings').remove()
|
|
|
|
|
|
|
|
for (var key in data) {
|
2016-10-05 01:45:21 +08:00
|
|
|
const string = Metamaps.Metacodes.get(key).get('name') + ' (' + data[key] + ')'
|
2016-04-15 08:43:46 +08:00
|
|
|
$('#fetchSiblingList').append('<li class="getSiblings" data-id="' + key + '">' + string + '</li>')
|
|
|
|
}
|
|
|
|
|
|
|
|
$('.rc-siblings .getSiblings').click(function () {
|
|
|
|
$('.rightclickmenu').remove()
|
|
|
|
// data-id is a metacode id
|
2016-09-22 18:31:56 +08:00
|
|
|
Topic.fetchRelatives(node, $(this).attr('data-id'))
|
2016-04-15 08:43:46 +08:00
|
|
|
})
|
|
|
|
}
|
2016-02-03 21:38:41 +08:00
|
|
|
|
2016-04-15 08:43:46 +08:00
|
|
|
$.ajax({
|
2016-08-07 15:34:30 +08:00
|
|
|
type: 'GET',
|
2016-10-05 01:45:21 +08:00
|
|
|
url: '/topics/' + topic.id + '/relative_numbers.json?network=' + topicsString,
|
2016-04-15 08:43:46 +08:00
|
|
|
success: successCallback,
|
|
|
|
error: function () {}
|
|
|
|
})
|
|
|
|
},
|
|
|
|
selectEdgeOnClickHandler: function (adj, e) {
|
2016-09-22 18:31:56 +08:00
|
|
|
if (Visualize.mGraph.busy) return
|
2016-04-15 08:43:46 +08:00
|
|
|
|
2016-10-05 01:45:21 +08:00
|
|
|
const self = JIT
|
2016-04-15 08:43:46 +08:00
|
|
|
|
|
|
|
// catch right click on mac, which is often like ctrl+click
|
2016-10-05 01:45:21 +08:00
|
|
|
if (navigator.platform.indexOf('Mac') !== -1 && e.ctrlKey) {
|
2016-04-15 08:43:46 +08:00
|
|
|
self.selectEdgeOnRightClickHandler(adj, e)
|
|
|
|
return
|
|
|
|
}
|
2016-02-03 21:38:41 +08:00
|
|
|
|
2016-10-05 01:45:21 +08:00
|
|
|
const check = self.nodeWasDoubleClicked()
|
2016-04-15 08:43:46 +08:00
|
|
|
if (check) {
|
|
|
|
self.edgeDoubleClickHandler(adj, e)
|
|
|
|
return
|
|
|
|
} else {
|
|
|
|
// wait a certain length of time, then check again, then run this code
|
|
|
|
setTimeout(function () {
|
2016-09-22 15:21:59 +08:00
|
|
|
if (!JIT.nodeWasDoubleClicked()) {
|
2016-10-05 01:45:21 +08:00
|
|
|
const edgeAlreadySelected = Selected.Edges.indexOf(adj) !== -1
|
2016-04-15 08:43:46 +08:00
|
|
|
|
|
|
|
if (!e.shiftKey) {
|
2016-09-22 18:31:56 +08:00
|
|
|
Control.deselectAllNodes()
|
|
|
|
Control.deselectAllEdges()
|
2016-04-15 08:43:46 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (edgeAlreadySelected) {
|
2016-09-22 18:31:56 +08:00
|
|
|
Control.deselectEdge(adj)
|
2016-04-15 08:43:46 +08:00
|
|
|
} else {
|
2016-09-22 18:31:56 +08:00
|
|
|
Control.selectEdge(adj)
|
2016-04-15 08:43:46 +08:00
|
|
|
}
|
|
|
|
|
2016-09-22 18:31:56 +08:00
|
|
|
Visualize.mGraph.plot()
|
2016-02-03 21:38:41 +08:00
|
|
|
}
|
2016-09-22 18:31:56 +08:00
|
|
|
}, Mouse.DOUBLE_CLICK_TOLERANCE)
|
2016-04-15 08:43:46 +08:00
|
|
|
}
|
|
|
|
}, // selectEdgeOnClickHandler
|
|
|
|
selectEdgeOnRightClickHandler: function (adj, e) {
|
|
|
|
// the 'node' variable is a JIT node, the one that was clicked on
|
|
|
|
// the 'e' variable is the click event
|
2016-02-03 21:38:41 +08:00
|
|
|
|
2016-10-05 01:45:21 +08:00
|
|
|
if (adj.getData('alpha') === 0) return // don't do anything if the edge is filtered
|
2016-02-03 21:38:41 +08:00
|
|
|
|
2016-04-15 08:43:46 +08:00
|
|
|
e.preventDefault()
|
|
|
|
e.stopPropagation()
|
2016-02-03 21:38:41 +08:00
|
|
|
|
2016-09-22 18:31:56 +08:00
|
|
|
if (Visualize.mGraph.busy) return
|
2016-02-03 21:38:41 +08:00
|
|
|
|
2016-09-22 18:31:56 +08:00
|
|
|
Control.selectEdge(adj)
|
2016-02-03 21:38:41 +08:00
|
|
|
|
2016-04-15 08:43:46 +08:00
|
|
|
// delete old right click menu
|
|
|
|
$('.rightclickmenu').remove()
|
|
|
|
// create new menu for clicked on node
|
2016-10-05 01:45:21 +08:00
|
|
|
const rightclickmenu = document.createElement('div')
|
2016-04-15 08:43:46 +08:00
|
|
|
rightclickmenu.className = 'rightclickmenu'
|
2016-10-05 01:45:21 +08:00
|
|
|
// prevent the custom context menu from immediately opening the default context menu as well
|
|
|
|
rightclickmenu.setAttribute('oncontextmenu', 'return false')
|
2016-02-03 21:38:41 +08:00
|
|
|
|
2016-04-15 08:43:46 +08:00
|
|
|
// add the proper options to the menu
|
2016-10-05 01:45:21 +08:00
|
|
|
let menustring = '<ul>'
|
2016-02-03 21:38:41 +08:00
|
|
|
|
2016-10-05 01:45:21 +08:00
|
|
|
const authorized = Active.Map && Active.Map.authorizeToEdit(Active.Mapper)
|
2016-02-03 21:38:41 +08:00
|
|
|
|
2016-10-05 01:45:21 +08:00
|
|
|
const disabled = authorized ? '' : 'disabled'
|
2016-02-03 21:38:41 +08:00
|
|
|
|
2016-09-22 18:31:56 +08:00
|
|
|
if (Active.Map) menustring += '<li class="rc-hide"><div class="rc-icon"></div>Hide until refresh<div class="rc-keyboard">Ctrl+H</div></li>'
|
|
|
|
if (Active.Map && Active.Mapper) menustring += '<li class="rc-remove ' + disabled + '"><div class="rc-icon"></div>Remove from map<div class="rc-keyboard">Ctrl+M</div></li>'
|
|
|
|
if (Active.Topic) menustring += '<li class="rc-remove"><div class="rc-icon"></div>Remove from view<div class="rc-keyboard">Ctrl+M</div></li>'
|
|
|
|
if (Active.Map && Active.Mapper) menustring += '<li class="rc-delete ' + disabled + '"><div class="rc-icon"></div>Delete<div class="rc-keyboard">Ctrl+D</div></li>'
|
2016-02-03 21:38:41 +08:00
|
|
|
|
2016-09-22 18:31:56 +08:00
|
|
|
if (Active.Map && Active.Mapper) menustring += '<li class="rc-spacer"></li>'
|
2016-02-03 21:38:41 +08:00
|
|
|
|
2016-09-22 18:31:56 +08:00
|
|
|
if (Active.Mapper) {
|
2016-10-05 01:45:21 +08:00
|
|
|
const permOptions = outdent`
|
2016-10-04 23:38:32 +08:00
|
|
|
<ul>
|
|
|
|
<li class="changeP toCommons"><div class="rc-perm-icon"></div>commons</li>
|
2016-10-05 01:45:21 +08:00
|
|
|
<li class="changeP toPublic"><div class="rc-perm-icon"></div>public</li> <li class="changeP toPrivate"><div class="rc-perm-icon"></div>private</li> </ul>`
|
2016-02-03 21:38:41 +08:00
|
|
|
|
2016-04-15 08:43:46 +08:00
|
|
|
menustring += '<li class="rc-permission"><div class="rc-icon"></div>Change permissions' + permOptions + '<div class="expandLi"></div></li>'
|
|
|
|
}
|
2016-02-03 21:38:41 +08:00
|
|
|
|
2016-04-15 08:43:46 +08:00
|
|
|
menustring += '</ul>'
|
|
|
|
rightclickmenu.innerHTML = menustring
|
|
|
|
|
|
|
|
// position the menu where the click happened
|
2016-10-05 01:45:21 +08:00
|
|
|
const position = {}
|
|
|
|
const RIGHTCLICK_WIDTH = 300
|
|
|
|
const RIGHTCLICK_HEIGHT = 144 // this does vary somewhat, but we can use static
|
|
|
|
const SUBMENUS_WIDTH = 256
|
|
|
|
const MAX_SUBMENU_HEIGHT = 270
|
|
|
|
const windowWidth = $(window).width()
|
|
|
|
const windowHeight = $(window).height()
|
2016-04-15 08:43:46 +08:00
|
|
|
|
|
|
|
if (windowWidth - e.clientX < SUBMENUS_WIDTH) {
|
|
|
|
position.right = windowWidth - e.clientX
|
|
|
|
$(rightclickmenu).addClass('moveMenusToLeft')
|
2016-10-05 01:45:21 +08:00
|
|
|
} else if (windowWidth - e.clientX < RIGHTCLICK_WIDTH) {
|
2016-04-15 08:43:46 +08:00
|
|
|
position.right = windowWidth - e.clientX
|
2016-10-05 01:45:21 +08:00
|
|
|
} else position.left = e.clientX
|
2016-02-03 21:38:41 +08:00
|
|
|
|
2016-04-15 08:43:46 +08:00
|
|
|
if (windowHeight - e.clientY < MAX_SUBMENU_HEIGHT) {
|
|
|
|
position.bottom = windowHeight - e.clientY
|
|
|
|
$(rightclickmenu).addClass('moveMenusUp')
|
2016-10-05 01:45:21 +08:00
|
|
|
} else if (windowHeight - e.clientY < RIGHTCLICK_HEIGHT + MAX_SUBMENU_HEIGHT) {
|
2016-04-15 08:43:46 +08:00
|
|
|
position.top = e.clientY
|
|
|
|
$(rightclickmenu).addClass('moveMenusUp')
|
2016-10-05 01:45:21 +08:00
|
|
|
} else position.top = e.clientY
|
2016-02-03 21:38:41 +08:00
|
|
|
|
2016-04-15 08:43:46 +08:00
|
|
|
$(rightclickmenu).css(position)
|
2016-02-03 21:38:41 +08:00
|
|
|
|
2016-04-15 08:43:46 +08:00
|
|
|
// add the menu to the page
|
|
|
|
$('#wrapper').append(rightclickmenu)
|
2016-02-03 21:38:41 +08:00
|
|
|
|
2016-04-15 08:43:46 +08:00
|
|
|
// attach events to clicks on the list items
|
2016-02-03 21:38:41 +08:00
|
|
|
|
2016-04-15 08:43:46 +08:00
|
|
|
// delete the selected things from the database
|
|
|
|
if (authorized) {
|
|
|
|
$('.rc-delete').click(function () {
|
|
|
|
$('.rightclickmenu').remove()
|
2016-09-22 18:31:56 +08:00
|
|
|
Control.deleteSelected()
|
2016-04-15 08:43:46 +08:00
|
|
|
})
|
|
|
|
}
|
2016-02-03 21:38:41 +08:00
|
|
|
|
2016-04-15 08:43:46 +08:00
|
|
|
// remove the selected things from the map
|
|
|
|
if (authorized) {
|
|
|
|
$('.rc-remove').click(function () {
|
|
|
|
$('.rightclickmenu').remove()
|
2016-09-22 18:31:56 +08:00
|
|
|
Control.removeSelectedEdges()
|
|
|
|
Control.removeSelectedNodes()
|
2016-04-15 08:43:46 +08:00
|
|
|
})
|
|
|
|
}
|
2016-02-03 21:38:41 +08:00
|
|
|
|
2016-04-15 08:43:46 +08:00
|
|
|
// hide selected nodes and synapses until refresh
|
|
|
|
$('.rc-hide').click(function () {
|
|
|
|
$('.rightclickmenu').remove()
|
2016-09-22 18:31:56 +08:00
|
|
|
Control.hideSelectedEdges()
|
|
|
|
Control.hideSelectedNodes()
|
2016-04-15 08:43:46 +08:00
|
|
|
})
|
|
|
|
|
|
|
|
// change the permission of all the selected nodes and synapses that you were the originator of
|
|
|
|
$('.rc-permission li').click(function () {
|
|
|
|
$('.rightclickmenu').remove()
|
|
|
|
// $(this).text() will be 'commons' 'public' or 'private'
|
2016-09-22 18:31:56 +08:00
|
|
|
Control.updateSelectedPermissions($(this).text())
|
2016-04-15 08:43:46 +08:00
|
|
|
})
|
|
|
|
}, // selectEdgeOnRightClickHandler
|
|
|
|
SmoothPanning: function () {
|
2016-10-05 01:45:21 +08:00
|
|
|
const sx = Visualize.mGraph.canvas.scaleOffsetX
|
|
|
|
const sy = Visualize.mGraph.canvas.scaleOffsetY
|
|
|
|
const yVelocity = Mouse.changeInY // initial y velocity
|
|
|
|
const xVelocity = Mouse.changeInX // initial x velocity
|
|
|
|
let easing = 1 // frictional value
|
2016-04-15 08:43:46 +08:00
|
|
|
|
2016-09-22 15:21:59 +08:00
|
|
|
window.clearInterval(panningInt)
|
|
|
|
panningInt = setInterval(function () {
|
2016-04-15 08:43:46 +08:00
|
|
|
myTimer()
|
|
|
|
}, 1)
|
|
|
|
|
|
|
|
function myTimer () {
|
2016-10-05 01:45:21 +08:00
|
|
|
Visualize.mGraph.canvas.translate(xVelocity * easing * 1 / sx, yVelocity * easing * 1 / sy)
|
2016-09-22 15:21:59 +08:00
|
|
|
$(document).trigger(JIT.events.pan)
|
2016-04-15 08:43:46 +08:00
|
|
|
easing = easing * 0.75
|
|
|
|
|
2016-09-22 15:21:59 +08:00
|
|
|
if (easing < 0.1) window.clearInterval(panningInt)
|
2016-04-15 08:43:46 +08:00
|
|
|
}
|
|
|
|
}, // SmoothPanning
|
|
|
|
renderMidArrow: function (from, to, dim, swap, canvas, placement, newSynapse) {
|
2016-10-05 01:45:21 +08:00
|
|
|
const ctx = canvas.getCtx()
|
|
|
|
// invert edge direction
|
2016-04-15 08:43:46 +08:00
|
|
|
if (swap) {
|
2016-10-05 01:45:21 +08:00
|
|
|
const tmp = from
|
2016-04-15 08:43:46 +08:00
|
|
|
from = to
|
|
|
|
to = tmp
|
|
|
|
}
|
2016-10-05 01:45:21 +08:00
|
|
|
// vect represents a line from tip to tail of the arrow
|
|
|
|
const vect = new $jit.Complex(to.x - from.x, to.y - from.y)
|
|
|
|
// scale it
|
2016-04-15 08:43:46 +08:00
|
|
|
vect.$scale(dim / vect.norm())
|
2016-10-05 01:45:21 +08:00
|
|
|
// compute the midpoint of the edge line
|
|
|
|
const newX = (to.x - from.x) * placement + from.x
|
|
|
|
const newY = (to.y - from.y) * placement + from.y
|
|
|
|
const midPoint = new $jit.Complex(newX, newY)
|
|
|
|
|
|
|
|
// move midpoint by half the "length" of the arrow so the arrow is centered on the midpoint
|
|
|
|
const arrowPoint = new $jit.Complex((vect.x / 0.7) + midPoint.x, (vect.y / 0.7) + midPoint.y)
|
|
|
|
// compute the tail intersection point with the edge line
|
|
|
|
const intermediatePoint = new $jit.Complex(arrowPoint.x - vect.x, arrowPoint.y - vect.y)
|
|
|
|
// vector perpendicular to vect
|
|
|
|
const normal = new $jit.Complex(-vect.y / 2, vect.x / 2)
|
|
|
|
const v1 = intermediatePoint.add(normal)
|
|
|
|
const v2 = intermediatePoint.$add(normal.$scale(-1))
|
2016-04-15 08:43:46 +08:00
|
|
|
|
|
|
|
if (newSynapse) {
|
|
|
|
ctx.strokeStyle = '#4fc059'
|
|
|
|
ctx.lineWidth = 2
|
|
|
|
ctx.globalAlpha = 1
|
|
|
|
}
|
|
|
|
ctx.beginPath()
|
|
|
|
ctx.moveTo(from.x, from.y)
|
|
|
|
ctx.lineTo(to.x, to.y)
|
|
|
|
ctx.stroke()
|
|
|
|
ctx.beginPath()
|
|
|
|
ctx.moveTo(v1.x, v1.y)
|
|
|
|
ctx.lineTo(arrowPoint.x, arrowPoint.y)
|
|
|
|
ctx.lineTo(v2.x, v2.y)
|
|
|
|
ctx.stroke()
|
|
|
|
}, // renderMidArrow
|
|
|
|
renderEdgeArrows: function (edgeHelper, adj, synapse, canvas) {
|
2016-10-05 01:45:21 +08:00
|
|
|
const self = JIT
|
2016-04-15 08:43:46 +08:00
|
|
|
|
2016-10-05 01:45:21 +08:00
|
|
|
const directionCat = synapse.get('category')
|
|
|
|
const direction = synapse.getDirection()
|
2016-04-15 08:43:46 +08:00
|
|
|
|
2016-10-05 01:45:21 +08:00
|
|
|
const pos = adj.nodeFrom.pos.getc(true)
|
|
|
|
const posChild = adj.nodeTo.pos.getc(true)
|
2016-04-15 08:43:46 +08:00
|
|
|
|
2016-10-05 01:45:21 +08:00
|
|
|
// plot arrow edge
|
2016-04-15 08:43:46 +08:00
|
|
|
if (!direction) {
|
|
|
|
// render nothing for this arrow if the direction couldn't be retrieved
|
2016-10-05 01:45:21 +08:00
|
|
|
} else if (directionCat === 'none') {
|
2016-04-15 08:43:46 +08:00
|
|
|
edgeHelper.line.render({
|
|
|
|
x: pos.x,
|
|
|
|
y: pos.y
|
|
|
|
}, {
|
|
|
|
x: posChild.x,
|
|
|
|
y: posChild.y
|
|
|
|
}, canvas)
|
2016-10-05 01:45:21 +08:00
|
|
|
} else if (directionCat === 'both') {
|
2016-04-15 08:43:46 +08:00
|
|
|
self.renderMidArrow({
|
|
|
|
x: pos.x,
|
|
|
|
y: pos.y
|
|
|
|
}, {
|
|
|
|
x: posChild.x,
|
|
|
|
y: posChild.y
|
|
|
|
}, 13, true, canvas, 0.7)
|
|
|
|
self.renderMidArrow({
|
|
|
|
x: pos.x,
|
|
|
|
y: pos.y
|
|
|
|
}, {
|
|
|
|
x: posChild.x,
|
|
|
|
y: posChild.y
|
|
|
|
}, 13, false, canvas, 0.7)
|
2016-10-05 01:45:21 +08:00
|
|
|
} else if (directionCat === 'from-to') {
|
|
|
|
const inv = (direction[0] !== adj.nodeFrom.id)
|
2016-04-15 08:43:46 +08:00
|
|
|
self.renderMidArrow({
|
|
|
|
x: pos.x,
|
|
|
|
y: pos.y
|
|
|
|
}, {
|
|
|
|
x: posChild.x,
|
|
|
|
y: posChild.y
|
|
|
|
}, 13, inv, canvas, 0.7)
|
|
|
|
self.renderMidArrow({
|
|
|
|
x: pos.x,
|
|
|
|
y: pos.y
|
|
|
|
}, {
|
|
|
|
x: posChild.x,
|
|
|
|
y: posChild.y
|
|
|
|
}, 13, inv, canvas, 0.3)
|
|
|
|
}
|
|
|
|
}, // renderEdgeArrows
|
|
|
|
zoomIn: function (event) {
|
2016-09-22 18:31:56 +08:00
|
|
|
Visualize.mGraph.canvas.scale(1.25, 1.25)
|
2016-09-22 15:21:59 +08:00
|
|
|
$(document).trigger(JIT.events.zoom, [event])
|
2016-04-15 08:43:46 +08:00
|
|
|
},
|
|
|
|
zoomOut: function (event) {
|
2016-09-22 18:31:56 +08:00
|
|
|
Visualize.mGraph.canvas.scale(0.8, 0.8)
|
2016-09-22 15:21:59 +08:00
|
|
|
$(document).trigger(JIT.events.zoom, [event])
|
2016-04-15 08:43:46 +08:00
|
|
|
},
|
|
|
|
centerMap: function (canvas) {
|
2016-10-05 01:45:21 +08:00
|
|
|
const offsetScale = canvas.scaleOffsetX
|
2016-04-15 08:43:46 +08:00
|
|
|
|
|
|
|
canvas.scale(1 / offsetScale, 1 / offsetScale)
|
|
|
|
|
2016-10-05 01:45:21 +08:00
|
|
|
const offsetX = canvas.translateOffsetX
|
|
|
|
const offsetY = canvas.translateOffsetY
|
2016-04-15 08:43:46 +08:00
|
|
|
|
|
|
|
canvas.translate(-1 * offsetX, -1 * offsetY)
|
|
|
|
},
|
|
|
|
zoomToBox: function (event) {
|
2016-10-05 01:45:21 +08:00
|
|
|
const sX = Mouse.boxStartCoordinates.x
|
|
|
|
const sY = Mouse.boxStartCoordinates.y
|
|
|
|
const eX = Mouse.boxEndCoordinates.x
|
|
|
|
const eY = Mouse.boxEndCoordinates.y
|
2016-04-15 08:43:46 +08:00
|
|
|
|
2016-10-05 01:45:21 +08:00
|
|
|
let canvas = Visualize.mGraph.canvas
|
2016-09-22 15:21:59 +08:00
|
|
|
JIT.centerMap(canvas)
|
2016-04-15 08:43:46 +08:00
|
|
|
|
2016-10-05 01:45:21 +08:00
|
|
|
let height = $(document).height()
|
|
|
|
let width = $(document).width()
|
2016-04-15 08:43:46 +08:00
|
|
|
|
2016-10-05 01:45:21 +08:00
|
|
|
let spanX = Math.abs(sX - eX)
|
|
|
|
let spanY = Math.abs(sY - eY)
|
|
|
|
let ratioX = width / spanX
|
|
|
|
let ratioY = height / spanY
|
2016-04-15 08:43:46 +08:00
|
|
|
|
2016-10-05 01:45:21 +08:00
|
|
|
let newRatio = Math.min(ratioX, ratioY)
|
2016-04-15 08:43:46 +08:00
|
|
|
|
|
|
|
if (canvas.scaleOffsetX * newRatio <= 5 && canvas.scaleOffsetX * newRatio >= 0.2) {
|
|
|
|
canvas.scale(newRatio, newRatio)
|
2016-10-05 01:45:21 +08:00
|
|
|
} else if (canvas.scaleOffsetX * newRatio > 5) {
|
2016-04-15 08:43:46 +08:00
|
|
|
newRatio = 5 / canvas.scaleOffsetX
|
|
|
|
canvas.scale(newRatio, newRatio)
|
|
|
|
} else {
|
|
|
|
newRatio = 0.2 / canvas.scaleOffsetX
|
|
|
|
canvas.scale(newRatio, newRatio)
|
|
|
|
}
|
2016-02-03 21:38:41 +08:00
|
|
|
|
2016-10-05 01:45:21 +08:00
|
|
|
const cogX = (sX + eX) / 2
|
|
|
|
const cogY = (sY + eY) / 2
|
2016-04-15 08:43:46 +08:00
|
|
|
|
|
|
|
canvas.translate(-1 * cogX, -1 * cogY)
|
2016-09-22 15:21:59 +08:00
|
|
|
$(document).trigger(JIT.events.zoom, [event])
|
2016-04-15 08:43:46 +08:00
|
|
|
|
2016-09-22 18:31:56 +08:00
|
|
|
Mouse.boxStartCoordinates = false
|
|
|
|
Mouse.boxEndCoordinates = false
|
|
|
|
Visualize.mGraph.plot()
|
2016-04-15 08:43:46 +08:00
|
|
|
},
|
|
|
|
zoomExtents: function (event, canvas, denySelected) {
|
2016-09-22 15:21:59 +08:00
|
|
|
JIT.centerMap(canvas)
|
2016-10-05 01:45:21 +08:00
|
|
|
let height = canvas.getSize().height
|
|
|
|
let width = canvas.getSize().width
|
|
|
|
let maxX
|
|
|
|
let maxY
|
|
|
|
let minX
|
|
|
|
let minY
|
|
|
|
let counter = 0
|
2016-04-15 08:43:46 +08:00
|
|
|
|
2016-09-26 13:37:42 +08:00
|
|
|
let nodes
|
2016-09-22 18:31:56 +08:00
|
|
|
if (!denySelected && Selected.Nodes.length > 0) {
|
2016-09-26 13:37:42 +08:00
|
|
|
nodes = Selected.Nodes
|
2016-04-15 08:43:46 +08:00
|
|
|
} else {
|
2016-09-26 13:37:42 +08:00
|
|
|
nodes = _.values(Visualize.mGraph.graph.nodes)
|
2016-04-15 08:43:46 +08:00
|
|
|
}
|
2016-02-03 21:38:41 +08:00
|
|
|
|
2016-04-15 08:43:46 +08:00
|
|
|
if (nodes.length > 1) {
|
|
|
|
nodes.forEach(function (n) {
|
2016-10-05 01:45:21 +08:00
|
|
|
let x = n.pos.x
|
|
|
|
let y = n.pos.y
|
2016-02-03 21:38:41 +08:00
|
|
|
|
2016-10-05 01:45:21 +08:00
|
|
|
if (counter === 0 && n.getData('alpha') === 1) {
|
2016-04-15 08:43:46 +08:00
|
|
|
maxX = x
|
|
|
|
minX = x
|
|
|
|
maxY = y
|
|
|
|
minY = y
|
2016-02-03 21:38:41 +08:00
|
|
|
}
|
|
|
|
|
2016-10-05 01:45:21 +08:00
|
|
|
let arrayOfLabelLines = Util.splitLine(n.name, 30).split('\n')
|
|
|
|
let dim = n.getData('dim')
|
|
|
|
let ctx = canvas.getCtx()
|
2016-02-03 21:38:41 +08:00
|
|
|
|
2016-10-05 01:45:21 +08:00
|
|
|
let height = 25 * arrayOfLabelLines.length
|
2016-02-03 21:38:41 +08:00
|
|
|
|
2016-10-05 01:45:21 +08:00
|
|
|
let lineWidths = []
|
|
|
|
for (let index = 0; index < arrayOfLabelLines.length; ++index) {
|
2016-04-15 08:43:46 +08:00
|
|
|
lineWidths.push(ctx.measureText(arrayOfLabelLines[index]).width)
|
2016-02-03 21:38:41 +08:00
|
|
|
}
|
2016-10-05 01:45:21 +08:00
|
|
|
let width = Math.max.apply(null, lineWidths) + 8
|
2016-02-03 21:38:41 +08:00
|
|
|
|
2016-04-15 08:43:46 +08:00
|
|
|
// only adjust these values if the node is not filtered
|
2016-10-05 01:45:21 +08:00
|
|
|
if (n.getData('alpha') === 1) {
|
2016-04-15 08:43:46 +08:00
|
|
|
maxX = Math.max(x + width / 2, maxX)
|
|
|
|
maxY = Math.max(y + n.getData('height') + 5 + height, maxY)
|
|
|
|
minX = Math.min(x - width / 2, minX)
|
|
|
|
minY = Math.min(y - dim, minY)
|
2016-02-03 21:38:41 +08:00
|
|
|
|
2016-04-15 08:43:46 +08:00
|
|
|
counter++
|
|
|
|
}
|
|
|
|
})
|
2016-02-03 21:38:41 +08:00
|
|
|
|
2016-10-05 01:45:21 +08:00
|
|
|
let spanX = maxX - minX
|
|
|
|
let spanY = maxY - minY
|
|
|
|
let ratioX = spanX / width
|
|
|
|
let ratioY = spanY / height
|
2016-02-03 21:38:41 +08:00
|
|
|
|
2016-10-05 01:45:21 +08:00
|
|
|
let cogX = (maxX + minX) / 2
|
|
|
|
let cogY = (maxY + minY) / 2
|
2016-02-03 21:38:41 +08:00
|
|
|
|
2016-04-15 08:43:46 +08:00
|
|
|
canvas.translate(-1 * cogX, -1 * cogY)
|
2016-02-03 21:38:41 +08:00
|
|
|
|
2016-10-05 01:45:21 +08:00
|
|
|
let newRatio = Math.max(ratioX, ratioY)
|
|
|
|
let scaleMultiplier = 1 / newRatio * 0.9
|
2016-02-03 21:38:41 +08:00
|
|
|
|
2016-04-15 08:43:46 +08:00
|
|
|
if (canvas.scaleOffsetX * scaleMultiplier <= 3 && canvas.scaleOffsetX * scaleMultiplier >= 0.2) {
|
|
|
|
canvas.scale(scaleMultiplier, scaleMultiplier)
|
2016-10-05 01:45:21 +08:00
|
|
|
} else if (canvas.scaleOffsetX * scaleMultiplier > 3) {
|
2016-04-15 08:43:46 +08:00
|
|
|
scaleMultiplier = 3 / canvas.scaleOffsetX
|
|
|
|
canvas.scale(scaleMultiplier, scaleMultiplier)
|
|
|
|
} else {
|
|
|
|
scaleMultiplier = 0.2 / canvas.scaleOffsetX
|
|
|
|
canvas.scale(scaleMultiplier, scaleMultiplier)
|
|
|
|
}
|
2016-02-03 21:38:41 +08:00
|
|
|
|
2016-09-22 15:21:59 +08:00
|
|
|
$(document).trigger(JIT.events.zoom, [event])
|
2016-10-05 01:45:21 +08:00
|
|
|
} else if (nodes.length === 1) {
|
2016-04-15 08:43:46 +08:00
|
|
|
nodes.forEach(function (n) {
|
2016-10-05 01:45:21 +08:00
|
|
|
const x = n.pos.x
|
|
|
|
const y = n.pos.y
|
2016-04-15 08:43:46 +08:00
|
|
|
|
|
|
|
canvas.translate(-1 * x, -1 * y)
|
2016-09-22 15:21:59 +08:00
|
|
|
$(document).trigger(JIT.events.zoom, [event])
|
2016-04-15 08:43:46 +08:00
|
|
|
})
|
2016-02-03 21:38:41 +08:00
|
|
|
}
|
2016-04-15 08:43:46 +08:00
|
|
|
}
|
|
|
|
}
|
2016-09-22 15:21:59 +08:00
|
|
|
|
|
|
|
export default JIT
|