updated graph styling and json generate code. updated add synapses page to not have all three forms in the same place.

This commit is contained in:
Connor Turland 2012-10-10 11:52:50 -04:00
parent 4d09fb6fc8
commit 606b59b644
7 changed files with 283 additions and 255 deletions

View file

@ -48,17 +48,20 @@ function init(){
// with dollar prefixed data-properties in the // with dollar prefixed data-properties in the
// JSON structure. // JSON structure.
Node: { Node: {
overridable: true overridable: true,
color: '#2D6A5D',
type: 'circle',
dim: 11
}, },
Edge: { Edge: {
overridable: true, overridable: true,
color: '#23A4FF', color: '#23A4FF',
lineWidth: 0.4 lineWidth: 0.5
}, },
//Native canvas text styling //Native canvas text styling
Label: { Label: {
type: labelType, //Native or HTML type: labelType, //Native or HTML
size: 10, size: 12,
style: 'bold' style: 'bold'
}, },
//Add Tips //Add Tips
@ -117,7 +120,7 @@ function init(){
onCreateLabel: function(domElement, node){ onCreateLabel: function(domElement, node){
domElement.innerHTML = node.name; domElement.innerHTML = node.name;
var style = domElement.style; var style = domElement.style;
style.fontSize = "0.8em"; style.fontSize = "0.9em";
style.color = "#ddd"; style.color = "#ddd";
}, },
// Change node styles when DOM labels are placed // Change node styles when DOM labels are placed

View file

@ -68,4 +68,10 @@ input[type="submit"] { margin-top:5px; }
.focus .link { padding:0 0 0 10px; display:block; width:90%; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; } .focus .link { padding:0 0 0 10px; display:block; width:90%; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.divider { margin: 20px 50px 20px 50px; border-bottom:2px solid #FFF; } .divider { margin: 20px 50px 20px 50px; border-bottom:2px solid #FFF; }
.empty { margin-left:50px; } .empty { margin-left:50px; }
.selecttype { display:block; margin:100px auto 0; width:500px; }
.selecttype button { display:inline-block; width:150px; height:50px; background: #2D6A5D; color: white; border-radius: 15px; cursor: pointer; }
.selecttype button:hover { border-width:4px; border-color:#CCC; }
.selecttype .middle { margin:0 20px; }
.newsynapses form {display:none; }

View file

@ -1,52 +1,56 @@
class Group < ActiveRecord::Base class Group < ActiveRecord::Base
belongs_to :user belongs_to :user
has_many :groupgroup_c, :foreign_key => 'parent_group_id', :class_name => 'Groupgroup' has_many :groupgroup_c, :foreign_key => 'parent_group_id', :class_name => 'Groupgroup'
has_many :groupgroup_p, :foreign_key => 'group_id', :class_name => 'Groupgroup' has_many :groupgroup_p, :foreign_key => 'group_id', :class_name => 'Groupgroup'
has_many :synapses1, :class_name => 'Synapse', :foreign_key => 'node1_id', :conditions => {:category => 'Group'} has_many :synapses1, :class_name => 'Synapse', :foreign_key => 'node1_id', :conditions => {:category => 'Group'}
has_many :synapses2, :class_name => 'Synapse', :foreign_key => 'node2_id', :conditions => {:category => 'Group'} has_many :synapses2, :class_name => 'Synapse', :foreign_key => 'node2_id', :conditions => {:category => 'Group'}
has_many :groups1, :through => :synapses2, :source => :group1 has_many :groups1, :through => :synapses2, :source => :group1
has_many :groups2, :through => :synapses1, :source => :group2 has_many :groups2, :through => :synapses1, :source => :group2
def synapses def synapses
synapses1 + synapses2 synapses1 + synapses2
end end
def relatives def relatives
groups1 + groups2 groups1 + groups2
end end
has_many :grouppeople has_many :grouppeople
has_many :groupitems has_many :groupitems
has_many :child_groups, :through => :groupgroup_c, :source => :group has_many :child_groups, :through => :groupgroup_c, :source => :group
has_many :parent_groups, :through => :groupgroup_p, :source => :parent_group has_many :parent_groups, :through => :groupgroup_p, :source => :parent_group
has_many :people, :through => :grouppeople has_many :people, :through => :grouppeople
has_many :items, :through => :groupitems has_many :items, :through => :groupitems
def as_json def as_json
Jbuilder.encode do |json| Jbuilder.encode do |json|
@data1 = {'$color'=> '#909291'} @single = Array.new
@data2 = {'$color'=> '#70A35E', '$type'=> 'triangle', '$dim'=> 11 } @single.push(self)
@single = Array.new @groups = @single + self.relatives
@single.push(self)
@groups = @single + self.relatives json.array!(@groups) do |group|
json.adjacencies group.synapses2.delete_if{|synapse| not @groups.include?(Group.find_by_id(synapse.node1_id))} do |json, synapse|
json.array!(@groups) do |group| json.nodeTo synapse.node1_id
json.adjacencies group.synapses2.delete_if{|synapse| not @groups.include?(Group.find_by_id(synapse.node1_id))} do |json, synapse| json.nodeFrom synapse.node2_id
json.nodeTo synapse.node1_id
json.nodeFrom synapse.node2_id @synapsedata = Hash.new
json.data @data1 @synapsedata['desc'] = synapse.desc
end json.data @synapsedata
end
json.data @data2
json.id group.id @groupdata = Hash.new
json.name group.name @groupdata['desc'] = group.desc
end @groupdata['link'] = group.link
end json.data @groupdata
end json.id group.id
json.name group.name
end end
end
end
end

View file

@ -1,54 +1,58 @@
class Item < ActiveRecord::Base class Item < ActiveRecord::Base
belongs_to :user belongs_to :user
has_many :itemitem_c, :foreign_key => 'parent_item_id', :class_name => 'Itemitem' has_many :itemitem_c, :foreign_key => 'parent_item_id', :class_name => 'Itemitem'
has_many :itemitem_p, :foreign_key => 'item_id', :class_name => 'Itemitem' has_many :itemitem_p, :foreign_key => 'item_id', :class_name => 'Itemitem'
has_many :groupitems has_many :groupitems
has_many :personitems has_many :personitems
has_many :groups, :through => :groupitems has_many :groups, :through => :groupitems
has_many :people, :through => :personitems has_many :people, :through => :personitems
has_many :synapses1, :class_name => 'Synapse', :foreign_key => 'node1_id', :conditions => {:category => 'Item'} has_many :synapses1, :class_name => 'Synapse', :foreign_key => 'node1_id', :conditions => {:category => 'Item'}
has_many :synapses2, :class_name => 'Synapse', :foreign_key => 'node2_id', :conditions => {:category => 'Item'} has_many :synapses2, :class_name => 'Synapse', :foreign_key => 'node2_id', :conditions => {:category => 'Item'}
has_many :items1, :through => :synapses2, :source => :item1 has_many :items1, :through => :synapses2, :source => :item1
has_many :items2, :through => :synapses1, :source => :item2 has_many :items2, :through => :synapses1, :source => :item2
def synapses def synapses
synapses1 + synapses2 synapses1 + synapses2
end end
def relatives def relatives
items1 + items2 items1 + items2
end end
belongs_to :item_category belongs_to :item_category
has_many :child_items, :through => :itemitem_c, :source => :item has_many :child_items, :through => :itemitem_c, :source => :item
has_many :parent_items, :through => :itemitem_p, :source => :parent_item has_many :parent_items, :through => :itemitem_p, :source => :parent_item
def as_json def as_json
Jbuilder.encode do |json| Jbuilder.encode do |json|
@data1 = {'$color'=> '#909291'} @single = Array.new
@data2 = {'$color'=> '#70A35E', '$type'=> 'triangle', '$dim'=> 11 } @single.push(self)
@single = Array.new @items = @single + self.relatives
@single.push(self)
@items = @single + self.relatives json.array!(@items) do |item|
json.adjacencies item.synapses2.delete_if{|synapse| not @items.include?(Item.find_by_id(synapse.node1_id))} do |json, synapse|
json.array!(@items) do |item| json.nodeTo synapse.node1_id
json.adjacencies item.synapses2.delete_if{|synapse| not @items.include?(Item.find_by_id(synapse.node1_id))} do |json, synapse| json.nodeFrom synapse.node2_id
json.nodeTo synapse.node1_id
json.nodeFrom synapse.node2_id @synapsedata = Hash.new
json.data @data1 @synapsedata['desc'] = synapse.desc
end json.data @synapsedata
end
json.data @data2
json.id item.id @itemdata = Hash.new
json.name item.name @itemdata['desc'] = item.desc
end @itemdata['link'] = item.link
end json.data @itemdata
end json.id item.id
json.name item.name
end end
end
end
end

View file

@ -1,46 +1,50 @@
class Person < ActiveRecord::Base class Person < ActiveRecord::Base
belongs_to :user belongs_to :user
has_many :grouppeople has_many :grouppeople
has_many :personitems has_many :personitems
has_many :groups, :through => :grouppeople has_many :groups, :through => :grouppeople
has_many :items, :through => :personitems has_many :items, :through => :personitems
has_many :synapses1, :class_name => 'Synapse', :foreign_key => 'node1_id', :conditions => {:category => 'Person'} has_many :synapses1, :class_name => 'Synapse', :foreign_key => 'node1_id', :conditions => {:category => 'Person'}
has_many :synapses2, :class_name => 'Synapse', :foreign_key => 'node2_id', :conditions => {:category => 'Person'} has_many :synapses2, :class_name => 'Synapse', :foreign_key => 'node2_id', :conditions => {:category => 'Person'}
has_many :people1, :through => :synapses2, :source => :person1 has_many :people1, :through => :synapses2, :source => :person1
has_many :people2, :through => :synapses1, :source => :person2 has_many :people2, :through => :synapses1, :source => :person2
def synapses def synapses
synapses1 + synapses2 synapses1 + synapses2
end end
def relatives def relatives
people1 + people2 people1 + people2
end end
def as_json def as_json
Jbuilder.encode do |json| Jbuilder.encode do |json|
@data1 = {'$color'=> '#909291'} @single = Array.new
@data2 = {'$color'=> '#70A35E', '$type'=> 'triangle', '$dim'=> 11 } @single.push(self)
@single = Array.new @people = @single + self.relatives
@single.push(self)
@people = @single + self.relatives json.array!(@people) do |person|
json.adjacencies person.synapses2.delete_if{|synapse| not @people.include?(Person.find_by_id(synapse.node1_id))} do |json, synapse|
json.array!(@people) do |person| json.nodeTo synapse.node1_id
json.adjacencies person.synapses2.delete_if{|synapse| not @people.include?(Person.find_by_id(synapse.node1_id))} do |json, synapse| json.nodeFrom synapse.node2_id
json.nodeTo synapse.node1_id
json.nodeFrom synapse.node2_id @synapsedata = Hash.new
json.data @data1 @synapsedata['desc'] = synapse.desc
end json.data @synapsedata
end
json.data @data2
json.id person.id @persondata = Hash.new
json.name person.name @persondata['desc'] = person.desc
end @persondata['link'] = person.link
end json.data @persondata
end json.id person.id
json.name person.name
end end
end
end
end

View file

@ -1,53 +1,53 @@
<!DOCTYPE html> <!DOCTYPE html>
<html> <html>
<head> <head>
<title>Metamap</title> <title>Metamaps</title>
<%= stylesheet_link_tag "application", :media => "all" %> <%= stylesheet_link_tag "application", :media => "all" %>
<%= javascript_include_tag "application" %> <%= javascript_include_tag "application" %>
<%= csrf_meta_tags %> <%= csrf_meta_tags %>
</head> </head>
<body> <body>
<%= content_tag :div, class: authenticated? ? "main authenticated" : "main unauthenticated" do %> <%= content_tag :div, class: authenticated? ? "main authenticated" : "main unauthenticated" do %>
<div class="headertop"> <div class="headertop">
<h1 id="mainTitle"><%= link_to "metamap", root_path %></h1>&nbsp;beta <h1 id="mainTitle"><%= link_to "metamaps", root_path %></h1>&nbsp;beta
<% unless authenticated? %> <% unless authenticated? %>
<ul> <ul>
<li><%= link_to "Login", new_session_path, id: "Login" %></li> <li><%= link_to "Login", new_session_path, id: "Login" %></li>
<li>|</li> <li>|</li>
<li><%= link_to "Items", items_path %></li> <li><%= link_to "Items", items_path %></li>
<li><%= link_to "People", people_path %></li> <li><%= link_to "People", people_path %></li>
<li><%= link_to "Groups", groups_path %></li> <li><%= link_to "Groups", groups_path %></li>
</ul> </ul>
<% end %> <% end %>
<% if authenticated? %> <% if authenticated? %>
<ul> <ul>
<li><%= link_to "Logout", session_path, method: 'delete', id: "Login" %></li> <li><%= link_to "Logout", session_path, method: 'delete', id: "Login" %></li>
<li><%= link_to "My Cards", userobjects_path %></li> <li><%= link_to "My Cards", userobjects_path %></li>
<li>|</li> <li>|</li>
<li><%= link_to "Add Synapse", new_synapse_path %></li> <li><%= link_to "Add Synapse", new_synapse_path %></li>
<li>|</li> <li>|</li>
<li><%= link_to "Add Item", new_item_path %></li> <li><%= link_to "Add Item", new_item_path %></li>
<li><%= link_to "Add Person", new_person_path %></li> <li><%= link_to "Add Person", new_person_path %></li>
<li><%= link_to "Add Group", new_group_path %></li> <li><%= link_to "Add Group", new_group_path %></li>
<li>|</li> <li>|</li>
<li><%= link_to "Items", items_path %></li> <li><%= link_to "Items", items_path %></li>
<li><%= link_to "People", people_path %></li> <li><%= link_to "People", people_path %></li>
<li><%= link_to "Groups", groups_path %></li> <li><%= link_to "Groups", groups_path %></li>
</ul> </ul>
<% end %> <% end %>
</div> </div>
<div class="clearfloat"></div> <div class="clearfloat"></div>
<div class="wrapper" id="wrapper"> <div class="wrapper" id="wrapper">
<%= yield %> <%= yield %>
</div> </div>
<div class="footer"> <div class="footer">
<div class="wrap"> <div class="wrap">
<div class="copy"> <div class="copy">
</div> </div>
</div> </div>
<% end %> <% end %>
</body> </body>

View file

@ -1,45 +1,52 @@
<%= form_for @synapse1, url: synapses_url do |form| %> <div class="selecttype">
<h3>Add Synapse Between Groups</h3> <button onclick="$('.selecttype').fadeOut('fast', function(){$('.newsynapses form:eq(0)').fadeIn('fast')});">Group to Group</button>
<%= hidden_field_tag(:category, "Group") %> <button class="middle" onclick="$('.selecttype').fadeOut('fast', function(){$('.newsynapses form:eq(1)').fadeIn('fast')});">Person to Person</button>
<% if @allgroups.count > 0 %> <button onclick="$('.selecttype').fadeOut('fast', function(){$('.newsynapses form:eq(2)').fadeIn('fast')});">Item to Item</button>
<label for="node1_id">Choose First Group</label> </div>
<%= select_tag :node1_id, options_from_collection_for_select(@allgroups, "id", "name") %> <div class="newsynapses">
<% end %> <%= form_for @synapse1, url: synapses_url do |form| %>
<label for="item_desc">Describe The Connection</label> <h3>Add Synapse Between Groups</h3>
<%= form.text_field :desc, class: "description" %> <%= hidden_field_tag(:category, "Group") %>
<% if @allgroups.count > 0 %> <% if @allgroups.count > 0 %>
<label for="node2_id">Choose Second Group</label> <label for="node1_id">Choose First Group</label>
<%= select_tag :node2_id, options_from_collection_for_select(@allgroups, "id", "name") %> <%= select_tag :node1_id, options_from_collection_for_select(@allgroups, "id", "name") %>
<% end %> <% end %>
<%= form.submit "Add Synapse", class: "add" %> <label for="item_desc">Describe The Connection</label>
<% end %> <%= form.text_field :desc, class: "description" %>
<%= form_for @synapse2, url: synapses_url do |form| %> <% if @allgroups.count > 0 %>
<h3>Add Synapse Between People</h3> <label for="node2_id">Choose Second Group</label>
<%= hidden_field_tag(:category, "Person") %> <%= select_tag :node2_id, options_from_collection_for_select(@allgroups, "id", "name") %>
<% if @allpeople.count > 0 %> <% end %>
<label for="node1_id">Choose First Person</label> <%= form.submit "Add Synapse", class: "add" %>
<%= select_tag :node1_id, options_from_collection_for_select(@allpeople, "id", "name") %> <% end %>
<% end %> <%= form_for @synapse2, url: synapses_url do |form| %>
<label for="item_desc">Describe The Connection</label> <h3>Add Synapse Between People</h3>
<%= form.text_field :desc, class: "description" %> <%= hidden_field_tag(:category, "Person") %>
<% if @allpeople.count > 0 %> <% if @allpeople.count > 0 %>
<label for="node2_id">Choose Second Person</label> <label for="node1_id">Choose First Person</label>
<%= select_tag :node2_id, options_from_collection_for_select(@allpeople, "id", "name") %> <%= select_tag :node1_id, options_from_collection_for_select(@allpeople, "id", "name") %>
<% end %> <% end %>
<%= form.submit "Add Synapse", class: "add" %> <label for="item_desc">Describe The Connection</label>
<% end %> <%= form.text_field :desc, class: "description" %>
<%= form_for @synapse3, url: synapses_url do |form| %> <% if @allpeople.count > 0 %>
<h3>Add Synapse Between Items</h3> <label for="node2_id">Choose Second Person</label>
<%= hidden_field_tag(:category, "Item") %> <%= select_tag :node2_id, options_from_collection_for_select(@allpeople, "id", "name") %>
<% if @allitems.count > 0 %> <% end %>
<label for="node1_id">Choose First Item</label> <%= form.submit "Add Synapse", class: "add" %>
<%= select_tag :node1_id, options_from_collection_for_select(@allitems, "id", "name") %> <% end %>
<% end %> <%= form_for @synapse3, url: synapses_url do |form| %>
<label for="item_desc">Describe The Connection</label> <h3>Add Synapse Between Items</h3>
<%= form.text_field :desc, class: "description" %> <%= hidden_field_tag(:category, "Item") %>
<% if @allitems.count > 0 %> <% if @allitems.count > 0 %>
<label for="node2_id">Choose Second Item</label> <label for="node1_id">Choose First Item</label>
<%= select_tag :node2_id, options_from_collection_for_select(@allitems, "id", "name") %> <%= select_tag :node1_id, options_from_collection_for_select(@allitems, "id", "name") %>
<% end %> <% end %>
<%= form.submit "Add Synapse", class: "add" %> <label for="item_desc">Describe The Connection</label>
<% end %> <%= form.text_field :desc, class: "description" %>
<% if @allitems.count > 0 %>
<label for="node2_id">Choose Second Item</label>
<%= select_tag :node2_id, options_from_collection_for_select(@allitems, "id", "name") %>
<% end %>
<%= form.submit "Add Synapse", class: "add" %>
<% end %>
</div>