metamaps--metamaps/app/views/synapses/create.js.erb

88 lines
3.2 KiB
Text
Raw Normal View History

$('#new_synapse').fadeOut('fast');
$('#new_synapse')[0].reset();
// if there's a map, add the synapse to that
map1 = document.getElementById('container');
if (map1 != null) {
2012-12-14 18:31:39 +00:00
var newnode, temp1, temp2, temp;
if ( Mconsole != null) {
temp1 = Mconsole.graph.getNode(<%= @synapse.item1.id %>);
if (temp1 == null) {
newnode = <%= @synapse.item1.self_as_json.html_safe %>;
Mconsole.graph.addNode(newnode);
temp = Mconsole.graph.getNode('<%= @synapse.item1.id %>');
temp.setData('dim', 1, 'start');
temp.setData('dim', 40, 'end');
2012-12-14 18:31:39 +00:00
if (gType == "arranged" || gType == "chaotic") {
temp.setData('xloc',0);
temp.setData('yloc',0);
temp.setData('mappingid', '<%= @mapping1.id %>');
temp.setPos(new $jit.Complex(0, 0), 'current');
temp.setPos(new $jit.Complex(0, 0), 'start');
temp.setPos(new $jit.Complex(0, 0), 'end');
}
2012-12-14 18:31:39 +00:00
else if (gType == "centered") {
temp.setPos(new $jit.Polar(5.54, 347.6), 'current');
temp.setPos(new $jit.Polar(5.54, 347.6), 'start');
temp.setPos(new $jit.Polar(5.54, 347.6), 'end');
}
Mconsole.fx.plotNode(temp, Mconsole.canvas);
temp1 = Mconsole.graph.getNode(<%= @synapse.item1.id %>);
}
temp2 = Mconsole.graph.getNode(<%= @synapse.item2.id %>);
if (temp2 == null) {
newnode = <%= @synapse.item2.self_as_json.html_safe %>;
Mconsole.graph.addNode(newnode);
temp = Mconsole.graph.getNode('<%= @synapse.item2.id %>');
temp.setData('dim', 1, 'start');
temp.setData('dim', 40, 'end');
2012-12-14 18:31:39 +00:00
if (gType == "arranged" || gType == "chaotic") {
temp.setData('xloc',0);
temp.setData('yloc',0);
temp.setData('mappingid', '<%= @mapping2.id %>');
temp.setPos(new $jit.Complex(0, 0), 'current');
temp.setPos(new $jit.Complex(0, 0), 'start');
temp.setPos(new $jit.Complex(0, 0), 'end');
}
2012-12-14 18:31:39 +00:00
else if (gType == "centered") {
temp.setPos(new $jit.Polar(5.54, 347.6), 'current');
temp.setPos(new $jit.Polar(5.54, 347.6), 'start');
temp.setPos(new $jit.Polar(5.54, 347.6), 'end');
}
Mconsole.fx.plotNode(temp, Mconsole.canvas);
temp2 = Mconsole.graph.getNode(<%= @synapse.item2.id %>);
}
Mconsole.graph.addAdjacence(temp1, temp2, {});
temp = Mconsole.graph.getAdjacence(temp1.id, temp2.id);
temp.setDataset('start', {
lineWidth: 0.4,
color: '#d1d1d1'
});
temp.setDataset('end', {
lineWidth: 3,
color: '#36acfb'
});
var d = new Array(<%= @synapse.node1_id.to_s() %>, <%= @synapse.node2_id.to_s() %>);
temp.setDataset('current', {
desc: '<%= @synapse.desc %>',
showDesc: false,
category: '<%= @synapse.category %>',
2012-12-14 18:31:39 +00:00
id: '<%= @synapse.id %>',
userid: '<%= @synapse.user.id %>',
username: '<%= @synapse.user.name %>'
});
temp.data.$direction = d;
Mconsole.fx.plotLine(temp, Mconsole.canvas);
Mconsole.fx.animate({
modes: ['node-property:dim','edge-property:lineWidth:color'],
duration: 400
});
}
else {
json = <%= @synapse.selfplusnodes_as_json.html_safe %>
2012-12-14 18:31:39 +00:00
initialize("chaotic");
}
}