From 647467e97ada02beb0fcd901798655869b0b4b29 Mon Sep 17 00:00:00 2001 From: Devin Howard Date: Mon, 7 Jan 2013 20:34:47 -0500 Subject: [PATCH 1/6] render edge labels with white background --- app/assets/javascripts/Jit/graphsettings.js | 53 ++++++++++++++------- 1 file changed, 37 insertions(+), 16 deletions(-) diff --git a/app/assets/javascripts/Jit/graphsettings.js b/app/assets/javascripts/Jit/graphsettings.js index 9a18d410..66dc36b6 100644 --- a/app/assets/javascripts/Jit/graphsettings.js +++ b/app/assets/javascripts/Jit/graphsettings.js @@ -307,13 +307,6 @@ arrowPoint.y - vect.y); var v1 = intermediatePoint.add(normal); 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.beginPath(); ctx.moveTo(from.x, from.y); @@ -392,13 +385,32 @@ var nodeSettings = { var desc = adj.getData("desc"); var showDesc = adj.getData("showDesc"); if( desc != "" && showDesc ) { - //now adjust the label placement + //now adjust the label placement + var ctx = canvas.getCtx(); var radius = canvas.getSize(); var x = parseInt((pos.x + posChild.x - (desc.length * 5)) /2); var y = parseInt((pos.y + posChild.y) /2); - canvas.getCtx().fillStyle = '#000'; - canvas.getCtx().font = 'bold 14px arial'; - canvas.getCtx().fillText(desc, x, y); + ctx.font = 'bold 14px arial'; + + //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) { var from = adj.nodeFrom.pos.getc(true), @@ -737,11 +749,7 @@ function onCreateLabelHandler(domElement, node) { // add some events to the label $(showCard).find('img.icon').click(function(){ - $('.showcard.topic_' + node.id).fadeOut('fast', function(){ - node.setData('dim', 25, 'current'); - $('.name').css('display','block'); - Mconsole.plot(); - }); + hideCard(node); }); $(showCard).find('.scroll').mCustomScrollbar(); @@ -854,6 +862,19 @@ function onCreateLabelHandler(domElement, node) { }//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 var edgeHover = false; From e481dcd822671cd563d1cb076766e767927533ac Mon Sep 17 00:00:00 2001 From: Devin Howard Date: Mon, 7 Jan 2013 22:04:53 -0500 Subject: [PATCH 2/6] changed maps controller so it accepts synapses as a csv list --- app/controllers/maps_controller.rb | 32 +++++++++++++++++++++--------- 1 file changed, 23 insertions(+), 9 deletions(-) diff --git a/app/controllers/maps_controller.rb b/app/controllers/maps_controller.rb index 829f39fc..5ae51962 100644 --- a/app/controllers/maps_controller.rb +++ b/app/controllers/maps_controller.rb @@ -52,7 +52,7 @@ class MapsController < ApplicationController def create @user = current_user - @map = Map.new() + @map = Map.new() @map.name = params[:map][:name] @map.desc = params[:map][:desc] @map.permission = params[:map][:permission] @@ -61,11 +61,11 @@ class MapsController < ApplicationController @map.save if params[:map][:topicsToMap] - @all = params[:map][:topicsToMap] - @all = @all.split(',') - @all.each do |topic| - topic = topic.split('/') - @mapping = Mapping.new() + @all = params[:map][:topicsToMap] + @all = @all.split(',') + @all.each do |topic| + topic = topic.split('/') + @mapping = Mapping.new() @mapping.category = "Topic" @mapping.user = @user @mapping.map = @map @@ -73,8 +73,22 @@ class MapsController < ApplicationController @mapping.xloc = topic[1] @mapping.yloc = topic[2] @mapping.save - end - @map.arranged = true + end + + if params[:map][:synapsesToMap] + @synAll = params[:map][:synapsesToMap] + @synAll = @synAll.split(',') + @synAll.each do |synapse| + @mapping = Mapping.new() + @mapping.category = "Synapse" + @mapping.user = @user + @mapping.map = @map + @mapping.synapse = Synapse.find(synapse[0]) + @mapping.save + end + end + + @map.arranged = true @map.save respond_to do |format| format.js { respond_with(@map) } @@ -83,7 +97,7 @@ class MapsController < ApplicationController respond_to do |format| format.html { respond_with(@user, location: map_path(@map)) } end - end + end end # GET maps/:id/edit From a7d4debd02f04315d87b5b4a67fa9a3f1433ad0a Mon Sep 17 00:00:00 2001 From: Devin Howard Date: Mon, 7 Jan 2013 22:05:27 -0500 Subject: [PATCH 3/6] added synapsesToMap to maps/_new.html.erb so they can be passed to maps controller --- app/views/maps/_new.html.erb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/views/maps/_new.html.erb b/app/views/maps/_new.html.erb index 25cec3ca..5b30ace2 100644 --- a/app/views/maps/_new.html.erb +++ b/app/views/maps/_new.html.erb @@ -8,8 +8,9 @@ <%= form.select(:permission, options_for_select(['commons', 'public', 'private'])) %> <%= form.hidden_field :topicsToMap, :value => 0 %> + <%= form.hidden_field :synapsesToMap, :value => 0 %> <%= form.submit "Save", class: "add" %>
<% end %> - \ No newline at end of file + From e2c408f983edc2fac94b44a88eeb98bf8a4a0167 Mon Sep 17 00:00:00 2001 From: Devin Howard Date: Mon, 7 Jan 2013 22:05:59 -0500 Subject: [PATCH 4/6] changed savedToMap() function so that it also includes all synapses --- app/assets/javascripts/application.js | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application.js index 42d3ef34..9daf752b 100644 --- a/app/assets/javascripts/application.js +++ b/app/assets/javascripts/application.js @@ -115,16 +115,19 @@ function saveLayout(id) { // this is to save your console to a map function saveToMap() { - var Coor = ""; + var nodes_data = "", syapses_data = ""; 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 + ','; }); - Coor = Coor.slice(0, -1); - $('#map_topicsToMap').val(Coor); + Mconsole.graph.eachAdjacence(function(adj) { + synapses_data += adj.id + ','; + } + nodes_data = nodes_data.slice(0, -1); + $('#map_topicsToMap').val(nodes_data); + $('#map_synapsesToMap').val(synapses_data); $('#new_map').fadeIn('fast'); } - // this is for hiding one topic from your canvas function removeFromCanvas(topic_id) { var node = Mconsole.graph.getNode(topic_id); @@ -168,4 +171,4 @@ function MconsoleReset() { var mY = Mconsole.canvas.scaleOffsetY; Mconsole.canvas.scale((1/mX),(1/mY)); -} \ No newline at end of file +} From 3f1d9ddda5e7a47686948a29a11816eff42ea9b6 Mon Sep 17 00:00:00 2001 From: Devin Howard Date: Mon, 7 Jan 2013 22:06:24 -0500 Subject: [PATCH 5/6] cleaned up synapse editing code - should be bug-free. Famous last words? --- app/assets/javascripts/Jit/graphsettings.js | 35 ++++++++++++--------- 1 file changed, 21 insertions(+), 14 deletions(-) diff --git a/app/assets/javascripts/Jit/graphsettings.js b/app/assets/javascripts/Jit/graphsettings.js index 66dc36b6..1d9f72ed 100644 --- a/app/assets/javascripts/Jit/graphsettings.js +++ b/app/assets/javascripts/Jit/graphsettings.js @@ -421,39 +421,46 @@ var nodeSettings = { } function editEdge(edge, e) { - deselectEdge(edge); //so the label is missing while editing - if (!document.getElementById('edit_synapse')) { - 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 + //reset so we don't interfere with other edges + $('#edit_synapse').remove(); + 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').html(edge.getData("desc")); + $('#edit_synapse').css('position', 'absolute'); $('#edit_synapse').css('left', e.clientX); $('#edit_synapse').css('top', e.clientY); $('#edit_synapse').bind("ajax:success", function() { var desc = $(this).html(); - $('#edit_synapse').hide(); edge.setData("desc", desc); selectEdge(edge); Mconsole.plot(); + $('#edit_synapse').remove(); }); $('#edit_synapse').focusout(function() { - $('#edit_synapse').hide(); + //in case they cancel +// $('#edit_synapse').hide(); }); //css stuff above moves it, this activates it $('#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').show(); } From 1fed4d2f06a0c95553c829f4731de4f01b483b73 Mon Sep 17 00:00:00 2001 From: Devin Howard Date: Mon, 7 Jan 2013 23:03:29 -0500 Subject: [PATCH 6/6] save synapses to map in saveToMap function wasn't working, but it is now --- app/assets/javascripts/application.js | 18 ++++++++++++++---- app/controllers/maps_controller.rb | 4 ++-- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application.js index 9daf752b..84965039 100644 --- a/app/assets/javascripts/application.js +++ b/app/assets/javascripts/application.js @@ -115,14 +115,24 @@ function saveLayout(id) { // this is to save your console to a map function saveToMap() { - var nodes_data = "", syapses_data = ""; + var nodes_data = "", synapses_data = ""; + var synapses_array = new Array(); Mconsole.graph.eachNode(function(n) { nodes_data += n.id + '/' + n.pos.x + '/' + n.pos.y + ','; + n.eachAdjacency(function(adj) { + synapses_array.push(adj.getData("id")); + }); }); - Mconsole.graph.eachAdjacence(function(adj) { - synapses_data += adj.id + ','; - } + + //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'); diff --git a/app/controllers/maps_controller.rb b/app/controllers/maps_controller.rb index 5ae51962..9fe67c24 100644 --- a/app/controllers/maps_controller.rb +++ b/app/controllers/maps_controller.rb @@ -78,12 +78,12 @@ class MapsController < ApplicationController if params[:map][:synapsesToMap] @synAll = params[:map][:synapsesToMap] @synAll = @synAll.split(',') - @synAll.each do |synapse| + @synAll.each do |synapse_id| @mapping = Mapping.new() @mapping.category = "Synapse" @mapping.user = @user @mapping.map = @map - @mapping.synapse = Synapse.find(synapse[0]) + @mapping.synapse = Synapse.find(synapse_id) @mapping.save end end