changed the home view
This commit is contained in:
parent
7d45a83776
commit
5784828931
8 changed files with 105 additions and 56 deletions
|
@ -10,22 +10,11 @@ var labelType, useGradients, nativeTextSupport, animate, json;
|
||||||
//I'm setting this based on the fact that ExCanvas provides text support for IE
|
//I'm setting this based on the fact that ExCanvas provides text support for IE
|
||||||
//and that as of today iPhone/iPad current text support is lame
|
//and that as of today iPhone/iPad current text support is lame
|
||||||
labelType = (!nativeCanvasSupport || (textSupport && !iStuff))? 'Native' : 'HTML';
|
labelType = (!nativeCanvasSupport || (textSupport && !iStuff))? 'Native' : 'HTML';
|
||||||
console.log(labelType);
|
|
||||||
nativeTextSupport = labelType == 'Native';
|
nativeTextSupport = labelType == 'Native';
|
||||||
useGradients = nativeCanvasSupport;
|
useGradients = nativeCanvasSupport;
|
||||||
animate = !(iStuff || !nativeCanvasSupport);
|
animate = !(iStuff || !nativeCanvasSupport);
|
||||||
})();
|
})();
|
||||||
|
|
||||||
var Log = {
|
|
||||||
elem: false,
|
|
||||||
write: function(text){
|
|
||||||
if (!this.elem)
|
|
||||||
this.elem = document.getElementById('log');
|
|
||||||
this.elem.innerHTML = text;
|
|
||||||
this.elem.style.left = (500 - this.elem.offsetWidth / 2) + 'px';
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
var imgArray = new Object();
|
var imgArray = new Object();
|
||||||
|
|
||||||
imgArray['Group'] = new Image(); imgArray['Group'].src = '/assets/group.png';
|
imgArray['Group'] = new Image(); imgArray['Group'].src = '/assets/group.png';
|
||||||
|
@ -183,13 +172,13 @@ function init(){
|
||||||
// This is done by traversing the clicked node connections.
|
// This is done by traversing the clicked node connections.
|
||||||
var html = '<div class="item" id="item_' + node.id + '"><p class="type">' + node.getData("itemcatname") + '</p><img alt="' + node.getData("itemcatname") + '" class="icon" height="50" src="' + imgArray[node.getData("itemcatname")].src + '" width="50" /><a href="http://localhost:3000/items/' + node.id + '" class="title">' + node.name + '</a><div class="desc"><p>' + node.getData('desc') + '</p></div><a href="' + node.getData('link') + '" class="link" target="_blank">' + node.getData('link') + '</a></div>';
|
var html = '<div class="item" id="item_' + node.id + '"><p class="type">' + node.getData("itemcatname") + '</p><img alt="' + node.getData("itemcatname") + '" class="icon" height="50" src="' + imgArray[node.getData("itemcatname")].src + '" width="50" /><a href="http://localhost:3000/items/' + node.id + '" class="title">' + node.name + '</a><div class="desc"><p>' + node.getData('desc') + '</p></div><a href="' + node.getData('link') + '" class="link" target="_blank">' + node.getData('link') + '</a></div>';
|
||||||
//append connections information
|
//append connections information
|
||||||
$jit.id('inner-details').innerHTML = html;
|
$jit.id('showcard').innerHTML = html;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
//Number of iterations for the FD algorithm
|
//Number of iterations for the FD algorithm
|
||||||
iterations: 200,
|
iterations: 200,
|
||||||
//Edge length
|
//Edge length
|
||||||
levelDistance: 130,
|
levelDistance: 150,
|
||||||
// Add text to the labels. This method is only triggered
|
// Add text to the labels. This method is only triggered
|
||||||
// on label creation and only for DOM labels (not native canvas ones).
|
// on label creation and only for DOM labels (not native canvas ones).
|
||||||
onCreateLabel: function(domElement, node){
|
onCreateLabel: function(domElement, node){
|
||||||
|
@ -257,7 +246,7 @@ function init(){
|
||||||
// This is done by traversing the clicked node connections.
|
// This is done by traversing the clicked node connections.
|
||||||
var html = '<div class="item" id="item_' + node.id + '"><p class="type">' + node.getData("itemcatname") + '</p><img alt="' + node.getData("itemcatname") + '" class="icon" height="50" src="' + imgArray[node.getData("itemcatname")].src + '" width="50" /><a href="http://localhost:3000/items/' + node.id + '" class="title">' + node.name + '</a><div class="desc"><p>' + node.getData('desc') + '</p></div><a href="' + node.getData('link') + '" class="link" target="_blank">' + node.getData('link') + '</a></div>';
|
var html = '<div class="item" id="item_' + node.id + '"><p class="type">' + node.getData("itemcatname") + '</p><img alt="' + node.getData("itemcatname") + '" class="icon" height="50" src="' + imgArray[node.getData("itemcatname")].src + '" width="50" /><a href="http://localhost:3000/items/' + node.id + '" class="title">' + node.name + '</a><div class="desc"><p>' + node.getData('desc') + '</p></div><a href="' + node.getData('link') + '" class="link" target="_blank">' + node.getData('link') + '</a></div>';
|
||||||
//append connections information
|
//append connections information
|
||||||
$jit.id('inner-details').innerHTML = html;
|
$jit.id('showcard').innerHTML = html;
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
// Change node styles when DOM labels are placed
|
// Change node styles when DOM labels are placed
|
||||||
|
@ -280,10 +269,8 @@ function init(){
|
||||||
iter: 40,
|
iter: 40,
|
||||||
property: 'end',
|
property: 'end',
|
||||||
onStep: function(perc){
|
onStep: function(perc){
|
||||||
Log.write(perc + '% loaded...');
|
|
||||||
},
|
},
|
||||||
onComplete: function(){
|
onComplete: function(){
|
||||||
Log.write('done');
|
|
||||||
fd.animate({
|
fd.animate({
|
||||||
modes: ['linear'],
|
modes: ['linear'],
|
||||||
transition: $jit.Trans.Elastic.easeOut,
|
transition: $jit.Trans.Elastic.easeOut,
|
||||||
|
|
|
@ -1,45 +1,32 @@
|
||||||
#center-container {
|
#center-container {
|
||||||
position:relative;
|
position:relative;
|
||||||
height:500px;
|
height:800px;
|
||||||
width:70%;
|
width:95%;
|
||||||
float:left;
|
|
||||||
/* background-color:#031924; */
|
/* background-color:#031924; */
|
||||||
color:#ccc;
|
color:#ccc;
|
||||||
max-width:900px;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#right-container {
|
#showcard{
|
||||||
height:500px;
|
width:auto;
|
||||||
width:29%;
|
height:auto;
|
||||||
color:#FFF;
|
color:#FFF;
|
||||||
text-align: left;
|
text-align: left;
|
||||||
overflow: auto;
|
overflow: auto;
|
||||||
}
|
position:absolute;
|
||||||
|
top:50%;
|
||||||
#right-container h4{
|
left:10px;
|
||||||
font-size:16px;
|
margin-top:-150px;
|
||||||
line-height:18px;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.text {
|
.text {
|
||||||
margin: 7px;
|
margin: 7px;
|
||||||
}
|
}
|
||||||
|
|
||||||
#inner-details {
|
|
||||||
}
|
|
||||||
|
|
||||||
#log {
|
|
||||||
font-size:1.0em;
|
|
||||||
font-weight:bold;
|
|
||||||
color:#23A4FF;
|
|
||||||
display:none;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
#infovis {
|
#infovis {
|
||||||
position:relative;
|
position:relative;
|
||||||
width:100%;
|
width:100%;
|
||||||
height:500px;
|
height:800px;
|
||||||
margin:0 0 0 50px;
|
margin:0 0 0 50px;
|
||||||
overflow:hidden;
|
overflow:hidden;
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,7 +24,7 @@ class ItemsController < ApplicationController
|
||||||
def show
|
def show
|
||||||
@item = Item.find(params[:id])
|
@item = Item.find(params[:id])
|
||||||
|
|
||||||
@relatives = @item.as_json.html_safe
|
@relatives = @item.map_as_json.html_safe
|
||||||
|
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
format.html { respond_with(@item) }
|
format.html { respond_with(@item) }
|
||||||
|
|
|
@ -6,9 +6,14 @@ class MainController < ApplicationController
|
||||||
def home
|
def home
|
||||||
@current_user = current_user
|
@current_user = current_user
|
||||||
|
|
||||||
@all = Item.all
|
@item = Item.all.first
|
||||||
|
|
||||||
respond_with(@all)
|
@alljson = @item.all_as_json.html_safe
|
||||||
|
|
||||||
|
respond_to do |format|
|
||||||
|
format.html { respond_with(@item) }
|
||||||
|
format.json { respond_with(@alljson) }
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def userobjects
|
def userobjects
|
||||||
|
|
|
@ -1,2 +1,11 @@
|
||||||
module ItemsHelper
|
module ItemsHelper
|
||||||
|
|
||||||
|
def network(node)
|
||||||
|
|
||||||
|
@test = Array.new
|
||||||
|
@test.push(node)
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -17,11 +17,64 @@ has_many :items2, :through => :synapses1, :source => :item2
|
||||||
|
|
||||||
belongs_to :item_category
|
belongs_to :item_category
|
||||||
|
|
||||||
def as_json
|
def self_as_json
|
||||||
Jbuilder.encode do |json|
|
Jbuilder.encode do |json|
|
||||||
@single = Array.new
|
@single = Array.new
|
||||||
@single.push(self)
|
@single.push(self)
|
||||||
#@items = @single + self.relatives
|
|
||||||
|
json.array!(@single) 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
|
||||||
|
@synapsedata['$category'] = synapse.category
|
||||||
|
json.data @synapsedata
|
||||||
|
end
|
||||||
|
|
||||||
|
@itemdata = Hash.new
|
||||||
|
@itemdata['$desc'] = item.desc
|
||||||
|
@itemdata['$link'] = item.link
|
||||||
|
@itemdata['$itemcatname'] = item.item_category.name
|
||||||
|
json.data @itemdata
|
||||||
|
json.id item.id
|
||||||
|
json.name item.name
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def map_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
|
||||||
|
@synapsedata['$category'] = synapse.category
|
||||||
|
json.data @synapsedata
|
||||||
|
end
|
||||||
|
|
||||||
|
@itemdata = Hash.new
|
||||||
|
@itemdata['$desc'] = item.desc
|
||||||
|
@itemdata['$link'] = item.link
|
||||||
|
@itemdata['$itemcatname'] = item.item_category.name
|
||||||
|
json.data @itemdata
|
||||||
|
json.id item.id
|
||||||
|
json.name item.name
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def all_as_json
|
||||||
|
Jbuilder.encode do |json|
|
||||||
|
|
||||||
@items = Item.all
|
@items = Item.all
|
||||||
|
|
||||||
json.array!(@items) do |item|
|
json.array!(@items) do |item|
|
||||||
|
|
|
@ -18,13 +18,10 @@
|
||||||
<div class="clearfloat nodemargin"></div>
|
<div class="clearfloat nodemargin"></div>
|
||||||
|
|
||||||
<div class="relatives" id="container">
|
<div class="relatives" id="container">
|
||||||
<div class="divider"><%= @item.name %> is connected to these items</div>
|
|
||||||
<div id="center-container">
|
<div id="center-container">
|
||||||
<div id="infovis"></div>
|
<div id="infovis"></div>
|
||||||
</div>
|
</div>
|
||||||
<div id="right-container">
|
<div id="showcard">
|
||||||
<div id="log"></div>
|
|
||||||
<div id="inner-details"></div>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="clearfloat"></div>
|
<div class="clearfloat"></div>
|
||||||
|
|
|
@ -1,9 +1,20 @@
|
||||||
<div class="everything" id="everything">
|
<% unless @item.nil? %>
|
||||||
<% @all.each do |object| %>
|
<div class="home" id="home">
|
||||||
<%= render object %>
|
<div id="center-container">
|
||||||
<% end %>
|
<div id="infovis"></div>
|
||||||
<% if @all.empty? %>
|
</div>
|
||||||
<p><br>Shucks, there is nothing in metamaps.<p>
|
<div id="showcard">
|
||||||
<% end %>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="clearfloat"></div>
|
<div class="clearfloat"></div>
|
||||||
|
<script>
|
||||||
|
json = <%= @alljson %>;
|
||||||
|
console.log(json);
|
||||||
|
$(document).ready(function() {
|
||||||
|
init();
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
<% end %>
|
||||||
|
<% if @item.nil? %>
|
||||||
|
<p><br>Shucks, there is nothing in metamaps.<p>
|
||||||
|
<% end %>
|
||||||
|
|
Loading…
Reference in a new issue