metamaps--metamaps/app/views/main/search.js.erb

95 lines
3.2 KiB
Text

/*
* @file
* This javascript code is run when you execute a search query.
* From the "Find"/"Seek" tab on the console.
*/
$('.getTopicsInput').attr('value','');
var h = Mconsole.canvas.element.clientHeight / 2;
var w = Mconsole.canvas.element.clientWidth / 2;
var myX = -w + 400;
var myY = -h + 100;
var even = true;
<% @topics.each do |topic| %>
if ($.isEmptyObject(Mconsole.graph.nodes)) {
json = <%= topic.self_as_json.html_safe %>;
Mconsole.loadJSON(json);
var temp = Mconsole.graph.getNode('<%= topic.id %>');
temp.setData('dim', 1, 'start');
temp.setData('dim', 25, 'end');
temp.setData('greenCircle',true);
temp.setData('whiteCircle',false);
temp.setPos(new $jit.Complex(myX, myY), 'current');
temp.setPos(new $jit.Complex(myX, myY), 'start');
temp.setPos(new $jit.Complex(myX, myY), 'end');
Mconsole.fx.plotNode(temp, Mconsole.canvas);
Mconsole.labels.plotLabel(Mconsole.canvas, temp, Mconsole.config);
myX += 100;
even = !even;
} else {
var temp = Mconsole.graph.getNode('<%= topic.id %>');
if (temp == undefined) {
var newnode = <%= topic.self_as_json.html_safe %>;
Mconsole.graph.addNode(newnode);
var temp = Mconsole.graph.getNode('<%= topic.id %>');
temp.setData('dim', 1, 'start');
temp.setData('dim', 25, 'end');
temp.setData('greenCircle',true);
temp.setData('whiteCircle',false);
if (myX > (w-100)) {
myX = -w + 400;
myY += 200;
even = true;
}
if (even) {
temp.setPos(new $jit.Complex(myX, myY), 'current');
temp.setPos(new $jit.Complex(myX, myY), 'start');
temp.setPos(new $jit.Complex(myX, myY), 'end');
}
else if (!even) {
temp.setPos(new $jit.Complex(myX, myY+100), 'current');
temp.setPos(new $jit.Complex(myX, myY+100), 'start');
temp.setPos(new $jit.Complex(myX, myY+100), 'end');
}
Mconsole.fx.plotNode(temp, Mconsole.canvas);
Mconsole.labels.plotLabel(Mconsole.canvas, temp, Mconsole.config);
myX += 100;
even = !even;
}
}
<% end %>
<% @synapses.each do |synapse| %>
var temp1 = null, temp2 = null;
temp1 = Mconsole.graph.getNode(<%= synapse.topic1.id %>);
temp2 = Mconsole.graph.getNode(<%= synapse.topic2.id %>);
if (temp1 != undefined && temp2 != undefined) {
Mconsole.graph.addAdjacence(temp1, temp2, {});
temp = Mconsole.graph.getAdjacence(temp1.id, temp2.id);
temp.setDataset('start', {
lineWidth: 0.4
});
temp.setDataset('end', {
lineWidth: 2
});
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 %>',
id: '<%= synapse.id %>',
userid: '<%= synapse.user.id %>',
username: '<%= synapse.user.name %>',
permission: '<%= synapse.permission %>'
});
temp.setData('direction', d);
Mconsole.fx.plotLine(temp, Mconsole.canvas);
}
<% end %>
Mconsole.fx.animate({
modes: ['node-property:dim','edge-property:lineWidth'],
duration: 500
});