got directionality working on the RGraph type
Before Width: | Height: | Size: 7.8 KiB After Width: | Height: | Size: 9.4 KiB |
Before Width: | Height: | Size: 8.4 KiB After Width: | Height: | Size: 10 KiB |
Before Width: | Height: | Size: 8.4 KiB After Width: | Height: | Size: 10 KiB |
Before Width: | Height: | Size: 8.1 KiB After Width: | Height: | Size: 9.8 KiB |
Before Width: | Height: | Size: 8.4 KiB After Width: | Height: | Size: 10 KiB |
Before Width: | Height: | Size: 8.5 KiB After Width: | Height: | Size: 10 KiB |
Before Width: | Height: | Size: 8.5 KiB After Width: | Height: | Size: 10 KiB |
Before Width: | Height: | Size: 8 KiB After Width: | Height: | Size: 9.8 KiB |
Before Width: | Height: | Size: 8.1 KiB After Width: | Height: | Size: 7.6 KiB |
Before Width: | Height: | Size: 8.2 KiB After Width: | Height: | Size: 10 KiB |
Before Width: | Height: | Size: 9.6 KiB After Width: | Height: | Size: 12 KiB |
Before Width: | Height: | Size: 7.7 KiB After Width: | Height: | Size: 9.7 KiB |
Before Width: | Height: | Size: 8.3 KiB After Width: | Height: | Size: 9.9 KiB |
Before Width: | Height: | Size: 8.3 KiB After Width: | Height: | Size: 10 KiB |
Before Width: | Height: | Size: 8.6 KiB After Width: | Height: | Size: 10 KiB |
Before Width: | Height: | Size: 7.1 KiB After Width: | Height: | Size: 8.7 KiB |
Before Width: | Height: | Size: 8.1 KiB After Width: | Height: | Size: 9.9 KiB |
Before Width: | Height: | Size: 8.6 KiB After Width: | Height: | Size: 10 KiB |
Before Width: | Height: | Size: 7.8 KiB After Width: | Height: | Size: 9.5 KiB |
Before Width: | Height: | Size: 7.9 KiB After Width: | Height: | Size: 9.6 KiB |
Before Width: | Height: | Size: 8 KiB After Width: | Height: | Size: 9.7 KiB |
Before Width: | Height: | Size: 6.8 KiB After Width: | Height: | Size: 8.5 KiB |
Before Width: | Height: | Size: 8.2 KiB After Width: | Height: | Size: 6.9 KiB |
|
@ -65,6 +65,46 @@ function initRG(){
|
|||
}
|
||||
}
|
||||
});
|
||||
//implement an edge type
|
||||
$jit.RGraph.Plot.EdgeTypes.implement({
|
||||
'customEdge': {
|
||||
'render': function(adj, canvas) {
|
||||
//get nodes cartesian coordinates
|
||||
var pos = adj.nodeFrom.pos.getc(true);
|
||||
var posChild = adj.nodeTo.pos.getc(true);
|
||||
|
||||
var direction = adj.getData("category");
|
||||
//label placement on edges
|
||||
//plot arrow edge
|
||||
if (direction == "none") {
|
||||
this.edgeHelper.line.render({ x: pos.x, y: pos.y }, { x: posChild.x, y: posChild.y }, canvas);
|
||||
}
|
||||
else if (direction == "both") {
|
||||
this.edgeHelper.arrow.render({ x: pos.x, y: pos.y }, { x: posChild.x, y: posChild.y }, 40, false, canvas);
|
||||
this.edgeHelper.arrow.render({ x: pos.x, y: pos.y }, { x: posChild.x, y: posChild.y }, 40, true, canvas);
|
||||
}
|
||||
else if (direction == "from-to") {
|
||||
this.edgeHelper.arrow.render({ x: pos.x, y: pos.y }, { x: posChild.x, y: posChild.y }, 40, false, canvas);
|
||||
}
|
||||
else if (direction == "to-from") {
|
||||
this.edgeHelper.arrow.render({ x: pos.x, y: pos.y }, { x: posChild.x, y: posChild.y }, 40, true, canvas);
|
||||
}
|
||||
|
||||
//check for edge label in data
|
||||
var desc = adj.getData("desc");
|
||||
var showDesc = adj.getData("showDesc");
|
||||
if( desc != "" && showDesc ) {
|
||||
//now adjust the label placement
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
// end
|
||||
// init RGraph
|
||||
rg = new $jit.RGraph({
|
||||
|
@ -101,7 +141,8 @@ function initRG(){
|
|||
Edge: {
|
||||
overridable: true,
|
||||
color: '#222222',
|
||||
lineWidth: 0.5
|
||||
type: 'customEdge',
|
||||
lineWidth: 1
|
||||
},
|
||||
//Native canvas text styling
|
||||
Label: {
|
||||
|
@ -152,9 +193,10 @@ function initRG(){
|
|||
n.setData('dim', 25, 'end');
|
||||
n.eachAdjacency(function(adj) {
|
||||
adj.setDataset('end', {
|
||||
lineWidth: 0.5,
|
||||
color: '#222222'
|
||||
});
|
||||
lineWidth: 1,
|
||||
color: '#222222'
|
||||
});
|
||||
adj.setData('showDesc', false, 'current');
|
||||
});
|
||||
});
|
||||
if(!node.selected) {
|
||||
|
@ -164,7 +206,8 @@ function initRG(){
|
|||
adj.setDataset('end', {
|
||||
lineWidth: 3,
|
||||
color: '#FFF'
|
||||
});
|
||||
});
|
||||
adj.setData('showDesc', true, 'current');
|
||||
});
|
||||
} else {
|
||||
delete node.selected;
|
||||
|
|
|
@ -54,7 +54,7 @@ class SynapsesController < ApplicationController
|
|||
@user = current_user
|
||||
@synapse = Synapse.new()
|
||||
@synapse.desc = params[:synapse][:desc]
|
||||
@synapse.category = params[:category]
|
||||
@synapse.category = params[:synapse][:category]
|
||||
@synapse.item1 = Item.find(params[:node1_id])
|
||||
@synapse.item2 = Item.find(params[:node2_id])
|
||||
@synapse.permission = params[:synapse][:permission]
|
||||
|
@ -102,7 +102,7 @@ class SynapsesController < ApplicationController
|
|||
@synapse = @user.synapses.find(params[:id]).authorize_to_edit(@current)
|
||||
|
||||
if @synapse
|
||||
@items = Item.visibleToUser(@current)
|
||||
@items = Item.visibleToUser(@current, nil)
|
||||
elsif not @synapse
|
||||
redirect_to root_url and return
|
||||
end
|
||||
|
@ -118,6 +118,7 @@ class SynapsesController < ApplicationController
|
|||
|
||||
if @synapse
|
||||
@synapse.desc = params[:synapse][:desc]
|
||||
@synapse.category = params[:synapse][:category]
|
||||
@synapse.item1 = Item.find(params[:node1_id][:node1])
|
||||
@synapse.item2 = Item.find(params[:node2_id][:node2])
|
||||
@synapse.permission = params[:synapse][:permission]
|
||||
|
|
|
@ -62,6 +62,7 @@ belongs_to :item_category
|
|||
|
||||
@synapsedata = Hash.new
|
||||
@synapsedata['$desc'] = synapse.desc
|
||||
@synapsedata['$showDesc'] = false
|
||||
@synapsedata['$category'] = synapse.category
|
||||
@synapsedata['$userid'] = synapse.user.id
|
||||
@synapsedata['$username'] = synapse.user.name
|
||||
|
|
|
@ -30,6 +30,7 @@ end
|
|||
|
||||
@synapsedata = Hash.new
|
||||
@synapsedata['$desc'] = synapse.desc
|
||||
@synapsedata['$showDesc'] = false
|
||||
@synapsedata['$category'] = synapse.category
|
||||
@synapsedata['$userid'] = synapse.user.id
|
||||
@synapsedata['$username'] = synapse.user.name
|
||||
|
|
|
@ -14,6 +14,7 @@ has_many :maps, :through => :mappings
|
|||
Jbuilder.encode do |json|
|
||||
@synapsedata = Hash.new
|
||||
@synapsedata['$desc'] = self.desc
|
||||
@synapsedata['$showDesc'] = false
|
||||
@synapsedata['$category'] = self.category
|
||||
@synapsedata['$userid'] = synapse.user.id
|
||||
@synapsedata['$username'] = synapse.user.name
|
||||
|
@ -34,6 +35,7 @@ has_many :maps, :through => :mappings
|
|||
|
||||
@synapsedata = Hash.new
|
||||
@synapsedata['$desc'] = synapse.desc
|
||||
@synapsedata['$showDesc'] = false
|
||||
@synapsedata['$category'] = synapse.category
|
||||
@synapsedata['$userid'] = synapse.user.id
|
||||
@synapsedata['$username'] = synapse.user.name
|
||||
|
|
|
@ -2,15 +2,16 @@
|
|||
<%= form_for Synapse.new, url: user_synapses_url(user), remote: true do |form| %>
|
||||
<button id="closenewsynapse" onclick="$('#new_synapse').fadeOut('fast'); $('#new_synapse')[0].reset(); return false;">close</button>
|
||||
<h3>Add Synapse Between Topics</h3>
|
||||
<%= hidden_field_tag(:category, "Item") %>
|
||||
<% if Item.visibleToUser(user, nil).count > 0 %>
|
||||
<label for="node1_id">Choose First Item</label>
|
||||
<label for="node1_id">Choose First Topic</label>
|
||||
<%= select_tag :node1_id, options_from_collection_for_select(Item.order("name ASC").visibleToUser(user, nil), "id", "name") %>
|
||||
<% end %>
|
||||
<label for="item_category">Directionality of the Connection</label>
|
||||
<%= form.select :category, options_for_select(['none', 'both', 'from-to', 'to-from']) %>
|
||||
<label for="item_desc">Describe The Connection</label>
|
||||
<%= form.text_field :desc, class: "description" %>
|
||||
<% if Item.visibleToUser(user, nil).count > 0 %>
|
||||
<label for="node2_id">Choose Second Item</label>
|
||||
<label for="node2_id">Choose Second Topic</label>
|
||||
<%= select_tag :node2_id, options_from_collection_for_select(Item.order("name ASC").visibleToUser(user, nil), "id", "name") %>
|
||||
<% end %>
|
||||
<label for="synapse_permission">Permission</label>
|
||||
|
|
|
@ -2,15 +2,16 @@
|
|||
<%= form_for Synapse.new, url: user_synapses_url(user), remote: true do |form| %>
|
||||
<button id="closenewsynapse" onclick="$('#new_synapse').fadeOut('fast'); $('#new_synapse')[0].reset(); return false;">close</button>
|
||||
<h3>Add Synapse Between Topics</h3>
|
||||
<%= hidden_field_tag(:category, "Item") %>
|
||||
<% if Item.visibleToUser(user, nil).count > 0 %>
|
||||
<label for="node1_id">Choose First Item</label>
|
||||
<label for="node1_id">Choose First Topic</label>
|
||||
<%= select_tag :node1_id, options_from_collection_for_select(Item.order("name ASC").visibleToUser(user, nil), "id", "name") %>
|
||||
<% end %>
|
||||
<label for="item_category">Directionality of the Connection</label>
|
||||
<%= form.select :category, options_for_select(['none', 'both', 'from-to', 'to-from']) %>
|
||||
<label for="item_desc">Describe The Connection</label>
|
||||
<%= form.text_field :desc, class: "description" %>
|
||||
<% if Item.visibleToUser(user, nil).count > 0 %>
|
||||
<label for="node2_id">Choose Second Item</label>
|
||||
<label for="node2_id">Choose Second Topic</label>
|
||||
<%= select_tag :node2_id, options_from_collection_for_select(Item.order("name ASC").visibleToUser(user, nil), "id", "name") %>
|
||||
<% end %>
|
||||
<label for="synapse_permission">Permission</label>
|
||||
|
|
|
@ -1,14 +1,16 @@
|
|||
<%= form_for @synapse, url: user_synapse_url do |form| %>
|
||||
<h3>Edit Synapse</h3>
|
||||
<% if @collection.count > 0 %>
|
||||
<% if Item.visibleToUser(user, nil).count > 0 %>
|
||||
<label for="node1_id">Choose First <%= @synapse.category %></label>
|
||||
<%= select "node1_id", "node1", @collection.order("name ASC").map {|p| [ p.name, p.id ] }, { :selected => @synapse.node1_id } %>
|
||||
<%= select "node1_id", "node1", Item.order("name ASC").visibleToUser(user, nil).map {|p| [ p.name, p.id ] }, { :selected => @synapse.node1_id } %>
|
||||
<% end %>
|
||||
<label for="item_category">Directionality of the Connection</label>
|
||||
<%= form.select :category, options_for_select(['none', 'both', 'from-to', 'to-from'], @synapse.category) %>
|
||||
<label for="item_desc">Describe The Connection</label>
|
||||
<%= form.text_field :desc, class: "description" %>
|
||||
<% if @collection.count > 0 %>
|
||||
<% if Item.visibleToUser(user, nil).count > 0 %>
|
||||
<label for="node2_id">Choose Second <%= @synapse.category %></label>
|
||||
<%= select "node2_id", "node2", @collection.order("name ASC").map {|p| [ p.name, p.id ] }, { :selected => @synapse.node2_id } %>
|
||||
<%= select "node2_id", "node2", Item.order("name ASC").visibleToUser(user, nil).map {|p| [ p.name, p.id ] }, { :selected => @synapse.node2_id } %>
|
||||
<% end %>
|
||||
<label for="synapse_permission">Permission</label>
|
||||
<%= form.select :permission, options_for_select(['commons', 'public', 'private'], @synapse.permission) %>
|
||||
|
|
|
@ -1,15 +1,16 @@
|
|||
<div class="newsynapses">
|
||||
<%= form_for @synapse, url: user_synapses_url do |form| %>
|
||||
<h3>Add Synapse Between Topics</h3>
|
||||
<%= hidden_field_tag(:category, "Item") %>
|
||||
<% if Item.visibleToUser(user, nil).count > 0 %>
|
||||
<label for="node1_id">Choose First Item</label>
|
||||
<label for="node1_id">Choose First Topic</label>
|
||||
<%= select_tag :node1_id, options_from_collection_for_select(Item.order("name ASC").visibleToUser(user, nil), "id", "name") %>
|
||||
<% end %>
|
||||
<label for="item_category">Directionality of the Connection</label>
|
||||
<%= form.select :category, options_for_select(['none', 'both', 'from-to', 'to-from']) %>
|
||||
<label for="item_desc">Describe The Connection</label>
|
||||
<%= form.text_field :desc, class: "description" %>
|
||||
<% if Item.visibleToUser(user, nil).count > 0 %>
|
||||
<label for="node2_id">Choose Second Item</label>
|
||||
<label for="node2_id">Choose Second Topic</label>
|
||||
<%= select_tag :node2_id, options_from_collection_for_select(Item.order("name ASC").visibleToUser(user, nil), "id", "name") %>
|
||||
<% end %>
|
||||
<label for="synapse_permission">Permission</label>
|
||||
|
|
16
db/schema.rb
|
@ -11,7 +11,7 @@
|
|||
#
|
||||
# It's strongly recommended to check this file into your version control system.
|
||||
|
||||
ActiveRecord::Schema.define(:version => 20121029164735) do
|
||||
ActiveRecord::Schema.define(:version => 20121026000731) do
|
||||
|
||||
create_table "item_categories", :force => true do |t|
|
||||
t.text "name"
|
||||
|
@ -24,11 +24,11 @@ ActiveRecord::Schema.define(:version => 20121029164735) do
|
|||
t.text "name"
|
||||
t.text "desc"
|
||||
t.text "link"
|
||||
t.text "permission"
|
||||
t.integer "user_id"
|
||||
t.integer "item_category_id"
|
||||
t.datetime "created_at", :null => false
|
||||
t.datetime "updated_at", :null => false
|
||||
t.text "permission"
|
||||
end
|
||||
|
||||
create_table "mappings", :force => true do |t|
|
||||
|
@ -44,37 +44,37 @@ ActiveRecord::Schema.define(:version => 20121029164735) do
|
|||
end
|
||||
|
||||
create_table "maps", :force => true do |t|
|
||||
t.datetime "created_at", :null => false
|
||||
t.datetime "updated_at", :null => false
|
||||
t.text "name"
|
||||
t.text "desc"
|
||||
t.text "permission"
|
||||
t.integer "user_id"
|
||||
t.datetime "created_at", :null => false
|
||||
t.datetime "updated_at", :null => false
|
||||
end
|
||||
|
||||
create_table "synapses", :force => true do |t|
|
||||
t.text "desc"
|
||||
t.text "category"
|
||||
t.text "weight"
|
||||
t.text "permission"
|
||||
t.integer "node1_id"
|
||||
t.integer "node2_id"
|
||||
t.integer "user_id"
|
||||
t.datetime "created_at", :null => false
|
||||
t.datetime "updated_at", :null => false
|
||||
t.text "permission"
|
||||
t.text "weight"
|
||||
end
|
||||
|
||||
create_table "users", :force => true do |t|
|
||||
t.string "name"
|
||||
t.string "email"
|
||||
t.string "code", :limit => 8
|
||||
t.string "joinedwithcode", :limit => 8
|
||||
t.string "crypted_password"
|
||||
t.string "password_salt"
|
||||
t.string "persistence_token"
|
||||
t.string "perishable_token"
|
||||
t.datetime "created_at", :null => false
|
||||
t.datetime "updated_at", :null => false
|
||||
t.string "code", :limit => 8
|
||||
t.string "joinedwithcode", :limit => 8
|
||||
end
|
||||
|
||||
end
|
||||
|
|