Merge branch 'master' of github.com:Connoropolous/metamaps_gen002
This commit is contained in:
commit
f48659288c
4 changed files with 102 additions and 46 deletions
|
@ -307,13 +307,6 @@ arrowPoint.y - vect.y);
|
||||||
var v1 = intermediatePoint.add(normal);
|
var v1 = intermediatePoint.add(normal);
|
||||||
var v2 = intermediatePoint.$add(normal.$scale(-1));
|
var v2 = intermediatePoint.$add(normal.$scale(-1));
|
||||||
|
|
||||||
//draw circle
|
|
||||||
//ctx.strokeStyle = "rgb(150,0,0)";
|
|
||||||
//ctx.beginPath();
|
|
||||||
//ctx.arc(midPoint.x, midPoint.y, 8, 0, (Math.PI/180)*360, true);
|
|
||||||
//ctx.stroke();
|
|
||||||
//ctx.closePath();
|
|
||||||
|
|
||||||
//ctx.strokeStyle = "#222222";
|
//ctx.strokeStyle = "#222222";
|
||||||
ctx.beginPath();
|
ctx.beginPath();
|
||||||
ctx.moveTo(from.x, from.y);
|
ctx.moveTo(from.x, from.y);
|
||||||
|
@ -392,13 +385,32 @@ var nodeSettings = {
|
||||||
var desc = adj.getData("desc");
|
var desc = adj.getData("desc");
|
||||||
var showDesc = adj.getData("showDesc");
|
var showDesc = adj.getData("showDesc");
|
||||||
if( desc != "" && showDesc ) {
|
if( desc != "" && showDesc ) {
|
||||||
//now adjust the label placement
|
//now adjust the label placement
|
||||||
|
var ctx = canvas.getCtx();
|
||||||
var radius = canvas.getSize();
|
var radius = canvas.getSize();
|
||||||
var x = parseInt((pos.x + posChild.x - (desc.length * 5)) /2);
|
var x = parseInt((pos.x + posChild.x - (desc.length * 5)) /2);
|
||||||
var y = parseInt((pos.y + posChild.y) /2);
|
var y = parseInt((pos.y + posChild.y) /2);
|
||||||
canvas.getCtx().fillStyle = '#000';
|
ctx.font = 'bold 14px arial';
|
||||||
canvas.getCtx().font = 'bold 14px arial';
|
|
||||||
canvas.getCtx().fillText(desc, x, y);
|
//render background
|
||||||
|
ctx.fillStyle = '#FFF';
|
||||||
|
var margin = 5;
|
||||||
|
var height = 14 + margin; //font size + margin
|
||||||
|
var CURVE = height / 2; //offset for curvy corners
|
||||||
|
var width = ctx.measureText(desc).width + 2 * margin - 2 * CURVE
|
||||||
|
var labelX = x - margin + CURVE;
|
||||||
|
var labelY = y - height + margin;
|
||||||
|
ctx.fillRect(labelX, labelY, width, height);
|
||||||
|
|
||||||
|
//curvy corners woo - circles in place of last CURVE pixels of rect
|
||||||
|
ctx.beginPath();
|
||||||
|
ctx.arc(labelX, labelY + CURVE, CURVE, 0, 2 * Math.PI, false);
|
||||||
|
ctx.arc(labelX + width, labelY + CURVE, CURVE, 0, 2 * Math.PI, false);
|
||||||
|
ctx.fill();
|
||||||
|
|
||||||
|
//render text
|
||||||
|
ctx.fillStyle = '#000';
|
||||||
|
ctx.fillText(desc, x, y);
|
||||||
}
|
}
|
||||||
}, 'contains' : function(adj, pos) {
|
}, 'contains' : function(adj, pos) {
|
||||||
var from = adj.nodeFrom.pos.getc(true),
|
var from = adj.nodeFrom.pos.getc(true),
|
||||||
|
@ -409,39 +421,46 @@ var nodeSettings = {
|
||||||
}
|
}
|
||||||
|
|
||||||
function editEdge(edge, e) {
|
function editEdge(edge, e) {
|
||||||
deselectEdge(edge); //so the label is missing while editing
|
//reset so we don't interfere with other edges
|
||||||
if (!document.getElementById('edit_synapse')) {
|
$('#edit_synapse').remove();
|
||||||
var edit_div = document.createElement('div');
|
|
||||||
edit_div.setAttribute('id', 'edit_synapse');
|
|
||||||
edit_div.setAttribute('class', 'best_in_place best_in_place_desc');
|
|
||||||
edit_div.setAttribute('data-object', 'synapse');
|
|
||||||
edit_div.setAttribute('data-attribute', 'desc');
|
|
||||||
edit_div.setAttribute('data-type', 'input');
|
|
||||||
//TODO how to get blank data-nil
|
|
||||||
edit_div.setAttribute('data-nil', ' ');
|
|
||||||
$('.main .wrapper').append(edit_div);
|
|
||||||
}//if
|
|
||||||
|
|
||||||
|
deselectEdge(edge); //so the label is missing while editing
|
||||||
|
var edit_div = document.createElement('div');
|
||||||
|
edit_div.setAttribute('id', 'edit_synapse');
|
||||||
|
$('.main .wrapper').append(edit_div);
|
||||||
|
$('#edit_synapse').attr('class', 'best_in_place best_in_place_desc');
|
||||||
|
$('#edit_synapse').attr('data-object', 'synapse');
|
||||||
|
$('#edit_synapse').attr('data-attribute', 'desc');
|
||||||
|
$('#edit_synapse').attr('data-type', 'input');
|
||||||
|
//TODO how to get blank data-nil
|
||||||
|
$('#edit_synapse').attr('data-nil', ' ');
|
||||||
$('#edit_synapse').attr('data-url', '/synapses/' + edge.getData("id"));
|
$('#edit_synapse').attr('data-url', '/synapses/' + edge.getData("id"));
|
||||||
$('#edit_synapse').html(edge.getData("desc"));
|
$('#edit_synapse').html(edge.getData("desc"));
|
||||||
|
|
||||||
$('#edit_synapse').css('position', 'absolute');
|
$('#edit_synapse').css('position', 'absolute');
|
||||||
$('#edit_synapse').css('left', e.clientX);
|
$('#edit_synapse').css('left', e.clientX);
|
||||||
$('#edit_synapse').css('top', e.clientY);
|
$('#edit_synapse').css('top', e.clientY);
|
||||||
|
|
||||||
$('#edit_synapse').bind("ajax:success", function() {
|
$('#edit_synapse').bind("ajax:success", function() {
|
||||||
var desc = $(this).html();
|
var desc = $(this).html();
|
||||||
$('#edit_synapse').hide();
|
|
||||||
edge.setData("desc", desc);
|
edge.setData("desc", desc);
|
||||||
selectEdge(edge);
|
selectEdge(edge);
|
||||||
Mconsole.plot();
|
Mconsole.plot();
|
||||||
|
$('#edit_synapse').remove();
|
||||||
});
|
});
|
||||||
|
|
||||||
$('#edit_synapse').focusout(function() {
|
$('#edit_synapse').focusout(function() {
|
||||||
$('#edit_synapse').hide();
|
//in case they cancel
|
||||||
|
// $('#edit_synapse').hide();
|
||||||
});
|
});
|
||||||
|
|
||||||
//css stuff above moves it, this activates it
|
//css stuff above moves it, this activates it
|
||||||
$('#edit_synapse').click();
|
$('#edit_synapse').click();
|
||||||
|
$('#edit_synapse form').submit(function() {
|
||||||
|
//hide it once form submits.
|
||||||
|
//If you don't do this, and data is unchanged, it'll show up on canvas
|
||||||
|
$('#edit_synapse').hide();
|
||||||
|
});
|
||||||
$('#edit_synapse input').focus();
|
$('#edit_synapse input').focus();
|
||||||
$('#edit_synapse').show();
|
$('#edit_synapse').show();
|
||||||
}
|
}
|
||||||
|
@ -737,11 +756,7 @@ function onCreateLabelHandler(domElement, node) {
|
||||||
|
|
||||||
// add some events to the label
|
// add some events to the label
|
||||||
$(showCard).find('img.icon').click(function(){
|
$(showCard).find('img.icon').click(function(){
|
||||||
$('.showcard.topic_' + node.id).fadeOut('fast', function(){
|
hideCard(node);
|
||||||
node.setData('dim', 25, 'current');
|
|
||||||
$('.name').css('display','block');
|
|
||||||
Mconsole.plot();
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
$(showCard).find('.scroll').mCustomScrollbar();
|
$(showCard).find('.scroll').mCustomScrollbar();
|
||||||
|
@ -854,6 +869,19 @@ function onCreateLabelHandler(domElement, node) {
|
||||||
|
|
||||||
}//onCreateLabelHandler
|
}//onCreateLabelHandler
|
||||||
|
|
||||||
|
function hideCard(node) {
|
||||||
|
var card = '.showcard';
|
||||||
|
if (node != null) {
|
||||||
|
card += '.topic_' + node.id;
|
||||||
|
}
|
||||||
|
|
||||||
|
$(card).fadeOut('fast', function(){
|
||||||
|
node.setData('dim', 25, 'current');
|
||||||
|
$('.name').show();
|
||||||
|
Mconsole.plot();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
//edge that the mouse is currently hovering over
|
//edge that the mouse is currently hovering over
|
||||||
var edgeHover = false;
|
var edgeHover = false;
|
||||||
|
|
||||||
|
|
|
@ -115,16 +115,29 @@ function saveLayout(id) {
|
||||||
|
|
||||||
// this is to save your console to a map
|
// this is to save your console to a map
|
||||||
function saveToMap() {
|
function saveToMap() {
|
||||||
var Coor = "";
|
var nodes_data = "", synapses_data = "";
|
||||||
|
var synapses_array = new Array();
|
||||||
Mconsole.graph.eachNode(function(n) {
|
Mconsole.graph.eachNode(function(n) {
|
||||||
Coor = Coor + n.id + '/' + n.pos.x + '/' + n.pos.y + ',';
|
nodes_data += n.id + '/' + n.pos.x + '/' + n.pos.y + ',';
|
||||||
|
n.eachAdjacency(function(adj) {
|
||||||
|
synapses_array.push(adj.getData("id"));
|
||||||
|
});
|
||||||
});
|
});
|
||||||
Coor = Coor.slice(0, -1);
|
|
||||||
$('#map_topicsToMap').val(Coor);
|
//get unique values only
|
||||||
|
synapses_array = $.grep(synapses_array, function(value, key){
|
||||||
|
return $.inArray(value, synapses_array) === key;
|
||||||
|
});
|
||||||
|
|
||||||
|
synapses_data = synapses_array.join();
|
||||||
|
console.log(synapses_data);
|
||||||
|
nodes_data = nodes_data.slice(0, -1);
|
||||||
|
|
||||||
|
$('#map_topicsToMap').val(nodes_data);
|
||||||
|
$('#map_synapsesToMap').val(synapses_data);
|
||||||
$('#new_map').fadeIn('fast');
|
$('#new_map').fadeIn('fast');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// this is for hiding one topic from your canvas
|
// this is for hiding one topic from your canvas
|
||||||
function removeFromCanvas(topic_id) {
|
function removeFromCanvas(topic_id) {
|
||||||
var node = Mconsole.graph.getNode(topic_id);
|
var node = Mconsole.graph.getNode(topic_id);
|
||||||
|
@ -168,4 +181,4 @@ function MconsoleReset() {
|
||||||
var mY = Mconsole.canvas.scaleOffsetY;
|
var mY = Mconsole.canvas.scaleOffsetY;
|
||||||
Mconsole.canvas.scale((1/mX),(1/mY));
|
Mconsole.canvas.scale((1/mX),(1/mY));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -52,7 +52,7 @@ class MapsController < ApplicationController
|
||||||
def create
|
def create
|
||||||
|
|
||||||
@user = current_user
|
@user = current_user
|
||||||
@map = Map.new()
|
@map = Map.new()
|
||||||
@map.name = params[:map][:name]
|
@map.name = params[:map][:name]
|
||||||
@map.desc = params[:map][:desc]
|
@map.desc = params[:map][:desc]
|
||||||
@map.permission = params[:map][:permission]
|
@map.permission = params[:map][:permission]
|
||||||
|
@ -61,11 +61,11 @@ class MapsController < ApplicationController
|
||||||
@map.save
|
@map.save
|
||||||
|
|
||||||
if params[:map][:topicsToMap]
|
if params[:map][:topicsToMap]
|
||||||
@all = params[:map][:topicsToMap]
|
@all = params[:map][:topicsToMap]
|
||||||
@all = @all.split(',')
|
@all = @all.split(',')
|
||||||
@all.each do |topic|
|
@all.each do |topic|
|
||||||
topic = topic.split('/')
|
topic = topic.split('/')
|
||||||
@mapping = Mapping.new()
|
@mapping = Mapping.new()
|
||||||
@mapping.category = "Topic"
|
@mapping.category = "Topic"
|
||||||
@mapping.user = @user
|
@mapping.user = @user
|
||||||
@mapping.map = @map
|
@mapping.map = @map
|
||||||
|
@ -73,8 +73,22 @@ class MapsController < ApplicationController
|
||||||
@mapping.xloc = topic[1]
|
@mapping.xloc = topic[1]
|
||||||
@mapping.yloc = topic[2]
|
@mapping.yloc = topic[2]
|
||||||
@mapping.save
|
@mapping.save
|
||||||
end
|
end
|
||||||
@map.arranged = true
|
|
||||||
|
if params[:map][:synapsesToMap]
|
||||||
|
@synAll = params[:map][:synapsesToMap]
|
||||||
|
@synAll = @synAll.split(',')
|
||||||
|
@synAll.each do |synapse_id|
|
||||||
|
@mapping = Mapping.new()
|
||||||
|
@mapping.category = "Synapse"
|
||||||
|
@mapping.user = @user
|
||||||
|
@mapping.map = @map
|
||||||
|
@mapping.synapse = Synapse.find(synapse_id)
|
||||||
|
@mapping.save
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
@map.arranged = true
|
||||||
@map.save
|
@map.save
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
format.js { respond_with(@map) }
|
format.js { respond_with(@map) }
|
||||||
|
@ -83,7 +97,7 @@ class MapsController < ApplicationController
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
format.html { respond_with(@user, location: map_path(@map)) }
|
format.html { respond_with(@user, location: map_path(@map)) }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# GET maps/:id/edit
|
# GET maps/:id/edit
|
||||||
|
|
|
@ -8,8 +8,9 @@
|
||||||
<label for="map_permission">Permission</label>
|
<label for="map_permission">Permission</label>
|
||||||
<%= form.select(:permission, options_for_select(['commons', 'public', 'private'])) %>
|
<%= form.select(:permission, options_for_select(['commons', 'public', 'private'])) %>
|
||||||
<%= form.hidden_field :topicsToMap, :value => 0 %>
|
<%= form.hidden_field :topicsToMap, :value => 0 %>
|
||||||
|
<%= form.hidden_field :synapsesToMap, :value => 0 %>
|
||||||
<%= form.submit "Save", class: "add" %>
|
<%= form.submit "Save", class: "add" %>
|
||||||
<button onclick="$('#new_map').fadeOut('fast'); event.preventDefault();">Cancel</button>
|
<button onclick="$('#new_map').fadeOut('fast'); event.preventDefault();">Cancel</button>
|
||||||
<div class="clearfloat"></div>
|
<div class="clearfloat"></div>
|
||||||
<% end %>
|
<% end %>
|
||||||
</div>
|
</div>
|
||||||
|
|
Loading…
Reference in a new issue