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
// JSON structure.
Node: {
overridable: true
overridable: true,
color: '#2D6A5D',
type: 'circle',
dim: 11
},
Edge: {
overridable: true,
color: '#23A4FF',
lineWidth: 0.4
lineWidth: 0.5
},
//Native canvas text styling
Label: {
type: labelType, //Native or HTML
size: 10,
size: 12,
style: 'bold'
},
//Add Tips
@ -117,7 +120,7 @@ function init(){
onCreateLabel: function(domElement, node){
domElement.innerHTML = node.name;
var style = domElement.style;
style.fontSize = "0.8em";
style.fontSize = "0.9em";
style.color = "#ddd";
},
// 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; }
.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
belongs_to :user
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 :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 :groups1, :through => :synapses2, :source => :group1
has_many :groups2, :through => :synapses1, :source => :group2
def synapses
synapses1 + synapses2
end
def relatives
groups1 + groups2
end
has_many :grouppeople
has_many :groupitems
has_many :child_groups, :through => :groupgroup_c, :source => :group
has_many :parent_groups, :through => :groupgroup_p, :source => :parent_group
has_many :people, :through => :grouppeople
has_many :items, :through => :groupitems
def as_json
Jbuilder.encode do |json|
@data1 = {'$color'=> '#909291'}
@data2 = {'$color'=> '#70A35E', '$type'=> 'triangle', '$dim'=> 11 }
@single = Array.new
@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.nodeTo synapse.node1_id
json.nodeFrom synapse.node2_id
json.data @data1
end
json.data @data2
json.id group.id
json.name group.name
end
end
end
end
class Group < ActiveRecord::Base
belongs_to :user
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 :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 :groups1, :through => :synapses2, :source => :group1
has_many :groups2, :through => :synapses1, :source => :group2
def synapses
synapses1 + synapses2
end
def relatives
groups1 + groups2
end
has_many :grouppeople
has_many :groupitems
has_many :child_groups, :through => :groupgroup_c, :source => :group
has_many :parent_groups, :through => :groupgroup_p, :source => :parent_group
has_many :people, :through => :grouppeople
has_many :items, :through => :groupitems
def as_json
Jbuilder.encode do |json|
@single = Array.new
@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.nodeTo synapse.node1_id
json.nodeFrom synapse.node2_id
@synapsedata = Hash.new
@synapsedata['desc'] = synapse.desc
json.data @synapsedata
end
@groupdata = Hash.new
@groupdata['desc'] = group.desc
@groupdata['link'] = group.link
json.data @groupdata
json.id group.id
json.name group.name
end
end
end
end

View file

@ -1,54 +1,58 @@
class Item < ActiveRecord::Base
belongs_to :user
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 :groupitems
has_many :personitems
has_many :groups, :through => :groupitems
has_many :people, :through => :personitems
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 :items1, :through => :synapses2, :source => :item1
has_many :items2, :through => :synapses1, :source => :item2
def synapses
synapses1 + synapses2
end
def relatives
items1 + items2
end
belongs_to :item_category
has_many :child_items, :through => :itemitem_c, :source => :item
has_many :parent_items, :through => :itemitem_p, :source => :parent_item
def as_json
Jbuilder.encode do |json|
@data1 = {'$color'=> '#909291'}
@data2 = {'$color'=> '#70A35E', '$type'=> 'triangle', '$dim'=> 11 }
@single = Array.new
@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.nodeTo synapse.node1_id
json.nodeFrom synapse.node2_id
json.data @data1
end
json.data @data2
json.id item.id
json.name item.name
end
end
end
end
class Item < ActiveRecord::Base
belongs_to :user
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 :groupitems
has_many :personitems
has_many :groups, :through => :groupitems
has_many :people, :through => :personitems
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 :items1, :through => :synapses2, :source => :item1
has_many :items2, :through => :synapses1, :source => :item2
def synapses
synapses1 + synapses2
end
def relatives
items1 + items2
end
belongs_to :item_category
has_many :child_items, :through => :itemitem_c, :source => :item
has_many :parent_items, :through => :itemitem_p, :source => :parent_item
def as_json
Jbuilder.encode do |json|
@single = Array.new
@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.nodeTo synapse.node1_id
json.nodeFrom synapse.node2_id
@synapsedata = Hash.new
@synapsedata['desc'] = synapse.desc
json.data @synapsedata
end
@itemdata = Hash.new
@itemdata['desc'] = item.desc
@itemdata['link'] = item.link
json.data @itemdata
json.id item.id
json.name item.name
end
end
end
end

View file

@ -1,46 +1,50 @@
class Person < ActiveRecord::Base
belongs_to :user
has_many :grouppeople
has_many :personitems
has_many :groups, :through => :grouppeople
has_many :items, :through => :personitems
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 :people1, :through => :synapses2, :source => :person1
has_many :people2, :through => :synapses1, :source => :person2
def synapses
synapses1 + synapses2
end
def relatives
people1 + people2
end
def as_json
Jbuilder.encode do |json|
@data1 = {'$color'=> '#909291'}
@data2 = {'$color'=> '#70A35E', '$type'=> 'triangle', '$dim'=> 11 }
@single = Array.new
@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.nodeTo synapse.node1_id
json.nodeFrom synapse.node2_id
json.data @data1
end
json.data @data2
json.id person.id
json.name person.name
end
end
end
end
class Person < ActiveRecord::Base
belongs_to :user
has_many :grouppeople
has_many :personitems
has_many :groups, :through => :grouppeople
has_many :items, :through => :personitems
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 :people1, :through => :synapses2, :source => :person1
has_many :people2, :through => :synapses1, :source => :person2
def synapses
synapses1 + synapses2
end
def relatives
people1 + people2
end
def as_json
Jbuilder.encode do |json|
@single = Array.new
@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.nodeTo synapse.node1_id
json.nodeFrom synapse.node2_id
@synapsedata = Hash.new
@synapsedata['desc'] = synapse.desc
json.data @synapsedata
end
@persondata = Hash.new
@persondata['desc'] = person.desc
@persondata['link'] = person.link
json.data @persondata
json.id person.id
json.name person.name
end
end
end
end

View file

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

View file

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