2011-01-24 18:24:24 +00:00
|
|
|
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
|
|
|
|
|
|
|
|
var browseClassGroups = {
|
|
|
|
// Initial page setup
|
|
|
|
onLoad: function() {
|
|
|
|
this.mergeFromTemplate();
|
|
|
|
this.initObjects();
|
2011-01-28 18:21:17 +00:00
|
|
|
this.bindEventListeners();
|
2011-01-24 18:24:24 +00:00
|
|
|
},
|
|
|
|
|
2011-01-28 18:21:17 +00:00
|
|
|
// Add variables from browse template
|
2011-01-24 18:24:24 +00:00
|
|
|
mergeFromTemplate: function() {
|
|
|
|
$.extend(this, browseData);
|
|
|
|
},
|
|
|
|
|
|
|
|
// Create references to frequently used elements for convenience
|
|
|
|
initObjects: function() {
|
2011-01-28 18:21:17 +00:00
|
|
|
this.vClassesInClassGroup = $('ul#classes-in-classgroup');
|
2011-01-24 18:24:24 +00:00
|
|
|
this.browseClassGroupLinks = $('#browse-classgroups li a');
|
2011-02-02 16:10:58 +00:00
|
|
|
this.browseClasses = $('#browse-classes');
|
2011-01-24 18:24:24 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
// Event listeners. Called on page load
|
|
|
|
bindEventListeners: function() {
|
|
|
|
// Listener for classGroup switching
|
|
|
|
this.browseClassGroupLinks.click(function() {
|
|
|
|
uri = $(this).attr("data-uri");
|
2011-02-02 16:10:58 +00:00
|
|
|
individualCount = $(this).attr("data-count");
|
|
|
|
browseClassGroups.getVClasses(uri, individualCount);
|
2011-01-24 18:24:24 +00:00
|
|
|
return false;
|
2011-01-28 18:21:17 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
// Call the bar chart highlighter listener
|
|
|
|
this.chartHighlighterListener();
|
|
|
|
},
|
|
|
|
|
|
|
|
// Listener for bar chart highlighting -- separate from the rest because it needs to be callable
|
|
|
|
chartHighlighterListener: function() {
|
|
|
|
// This essentially replicates the native Raphael hover behavior (see chart.hover below)
|
|
|
|
// but allows us to trigger it via jQuery from the list of classes adjacent to the chart
|
|
|
|
$('ul#classes-in-classgroup li a').hover(function() {
|
|
|
|
var classIndex = $('ul#classes-in-classgroup li a').index(this);
|
|
|
|
$('#visual-graph svg path').eq(classIndex).attr('fill', '#ccc');
|
|
|
|
return false;
|
|
|
|
}, function() {
|
|
|
|
var classIndex = $('ul#classes-in-classgroup li a').index(this);
|
|
|
|
$('#visual-graph svg path').eq(classIndex).attr('fill', '#999');
|
2011-01-24 18:24:24 +00:00
|
|
|
})
|
|
|
|
},
|
|
|
|
|
|
|
|
// Load classes and chart for default class group as defined by template
|
|
|
|
defaultClassGroup: function() {
|
|
|
|
if ( this.defaultBrowseClassGroupURI != "false" ) {
|
2011-02-02 16:10:58 +00:00
|
|
|
this.getVClasses(this.defaultBrowseClassGroupUri, this.defaultBrowseClassGroupCount);
|
2011-01-24 18:24:24 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2011-01-28 18:21:17 +00:00
|
|
|
// Where all the magic happens -- gonna fetch me some classes
|
2011-02-02 16:10:58 +00:00
|
|
|
getVClasses: function(classgroupUri, classGroupIndivCount) {
|
2011-01-24 18:24:24 +00:00
|
|
|
url = this.dataServiceUrl + encodeURIComponent(classgroupUri);
|
2011-02-02 16:10:58 +00:00
|
|
|
|
|
|
|
// First wipe currently displayed classes, browse all link, and bar chart
|
2011-01-24 18:24:24 +00:00
|
|
|
this.vClassesInClassGroup.empty();
|
2011-02-02 16:10:58 +00:00
|
|
|
$('a.browse-superclass').remove();
|
|
|
|
$('#visual-graph').empty();
|
2011-01-24 18:24:24 +00:00
|
|
|
|
2011-01-28 18:21:17 +00:00
|
|
|
var values = [],
|
|
|
|
labels = [],
|
2011-02-02 16:10:58 +00:00
|
|
|
uris = [],
|
|
|
|
classList = [],
|
|
|
|
populatedClasses = 0;
|
|
|
|
potentialSuperClasses = [];
|
2011-01-28 18:21:17 +00:00
|
|
|
|
2011-01-24 18:24:24 +00:00
|
|
|
$.getJSON(url, function(results) {
|
2011-02-02 16:10:58 +00:00
|
|
|
|
2011-01-28 18:21:17 +00:00
|
|
|
$.each(results.classes, function(i, item) {
|
|
|
|
name = results.classes[i].name;
|
|
|
|
uri = results.classes[i].URI;
|
|
|
|
indivCount = results.classes[i].entityCount;
|
2011-02-02 16:10:58 +00:00
|
|
|
indexUrl = browseClassGroups.baseUrl +'/individuallist?vclassId='+ encodeURIComponent(uri);
|
2011-01-28 18:21:17 +00:00
|
|
|
// Only add to the arrays and render classes when they aren't empty
|
|
|
|
if ( indivCount > 0 ) {
|
2011-02-02 16:10:58 +00:00
|
|
|
// if the class individual count is equal to the class group individual count, this could be a super class
|
|
|
|
if ( indivCount == classGroupIndivCount ) {
|
|
|
|
potentialSuperClasses.push(populatedClasses);
|
|
|
|
}
|
|
|
|
|
2011-01-28 18:21:17 +00:00
|
|
|
values.push(parseInt(indivCount, 10));
|
2011-02-02 16:10:58 +00:00
|
|
|
labels.push(name);
|
2011-01-28 18:21:17 +00:00
|
|
|
uris.push(uri);
|
|
|
|
|
|
|
|
// Build the content of each list item, piecing together each component
|
|
|
|
listItem = '<li role="listitem">';
|
2011-02-08 13:29:09 +00:00
|
|
|
listItem += '<a href="'+ indexUrl +'" title="Browse all '+ name +' content">'+ name +'</a>';
|
2011-01-28 18:21:17 +00:00
|
|
|
listItem += '</li>';
|
2011-02-02 16:10:58 +00:00
|
|
|
|
|
|
|
// Add the list item to the array of classes
|
|
|
|
classList.push(listItem);
|
|
|
|
|
|
|
|
populatedClasses++;
|
2011-01-28 18:21:17 +00:00
|
|
|
}
|
2011-01-24 18:24:24 +00:00
|
|
|
})
|
2011-02-02 16:10:58 +00:00
|
|
|
|
|
|
|
// Test for number of potential super classes. If only 1, then remove it from all arrays
|
|
|
|
// But only do so if there are at least 2 classes in the list to begin with
|
|
|
|
if ( classList.length > 1 && potentialSuperClasses.length == 1 ){
|
|
|
|
// Grab the URI of the super class before splicing
|
|
|
|
superClassUri = uris[potentialSuperClasses];
|
|
|
|
|
|
|
|
values.splice(potentialSuperClasses, 1);
|
|
|
|
labels.splice(potentialSuperClasses, 1);
|
|
|
|
uris.splice(potentialSuperClasses, 1);
|
|
|
|
classList.splice(potentialSuperClasses, 1);
|
|
|
|
|
|
|
|
browseAllUrl = browseClassGroups.baseUrl +'/individuallist?vclassId='+ encodeURIComponent(superClassUri);
|
|
|
|
browseAllLink = '<a class="browse-superclass" href="'+ browseAllUrl +'" title="Browse all '+ results.classGroupName +'">Browse all »</a>';
|
|
|
|
browseClassGroups.browseClasses.prepend(browseAllLink);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Add the classes to the DOM
|
|
|
|
$.each(classList, function(i, listItem) {
|
|
|
|
browseClassGroups.vClassesInClassGroup.append(listItem);
|
|
|
|
})
|
|
|
|
|
2011-01-28 18:21:17 +00:00
|
|
|
// Set selected class group
|
|
|
|
browseClassGroups.selectedClassGroup(results.classGroupUri);
|
|
|
|
|
|
|
|
// Update the graph
|
|
|
|
graphClassGroups.barchart(values, labels, uris);
|
|
|
|
|
|
|
|
// Call the bar highlighter listener
|
|
|
|
browseClassGroups.chartHighlighterListener();
|
2011-01-24 18:24:24 +00:00
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2011-01-28 18:21:17 +00:00
|
|
|
// Toggle the active class group so it's clear which is selected
|
|
|
|
selectedClassGroup: function(classGroupUri) {
|
2011-01-24 18:24:24 +00:00
|
|
|
// Remove active class on all vClasses
|
2011-01-28 18:21:17 +00:00
|
|
|
$('#browse-classgroups li a.selected').removeClass('selected');
|
2011-01-24 18:24:24 +00:00
|
|
|
|
|
|
|
// Add active class for requested vClass
|
2011-01-28 18:21:17 +00:00
|
|
|
$('#browse-classgroups li a[data-uri="'+ classGroupUri +'"]').addClass('selected');
|
2011-01-24 18:24:24 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
var graphClassGroups = {
|
2011-01-28 18:21:17 +00:00
|
|
|
// Build the bar chart using gRaphael
|
|
|
|
barchart: function(values, labels, uris) {
|
2011-01-24 18:24:24 +00:00
|
|
|
var height = values.length * 37;
|
|
|
|
|
|
|
|
// Create the canvas
|
2011-05-13 18:03:20 +00:00
|
|
|
var r = Raphael("visual-graph", 225, height + 10);
|
2011-01-24 18:24:24 +00:00
|
|
|
|
2011-05-13 18:03:20 +00:00
|
|
|
var chart = r.g.hbarchart(0, 16, 225, height, [values], {type:"soft", singleColor:"#999"});
|
2011-01-24 18:24:24 +00:00
|
|
|
|
|
|
|
// Was unable to append <a> within <svg> -- was always hidden and couldn't get it to display
|
2011-01-28 18:21:17 +00:00
|
|
|
// so using jQuery click to add links
|
2011-01-24 18:24:24 +00:00
|
|
|
$('rect').click(function() {
|
|
|
|
var index = $('rect').index(this);
|
|
|
|
var uri = uris[index];
|
|
|
|
var link = browseClassGroups.baseUrl + '/individuallist?vclassId=' + encodeURIComponent(uri);
|
|
|
|
window.location = link;
|
2011-01-28 18:21:17 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
// Add title attributes to each <rect> in the bar chart
|
|
|
|
$('rect').each(function() {
|
|
|
|
var index = $('rect').index(this);
|
|
|
|
var label = labels[index];
|
2011-02-02 16:10:58 +00:00
|
|
|
var title = 'Browse all '+ label +' content';
|
2011-01-28 18:21:17 +00:00
|
|
|
|
|
|
|
// Add a title attribute
|
|
|
|
$(this).attr('title', title);
|
|
|
|
});
|
2011-01-24 18:24:24 +00:00
|
|
|
|
|
|
|
// On hover
|
|
|
|
// 1. Change bar color
|
2011-02-08 13:29:09 +00:00
|
|
|
// 2. Highlight class name in main list
|
2011-01-24 18:24:24 +00:00
|
|
|
chart.hover(function() {
|
|
|
|
this.bar.attr({fill: "#ccc"});
|
|
|
|
$('rect').hover(function() {
|
|
|
|
var index = $('rect').index(this);
|
2011-01-28 18:21:17 +00:00
|
|
|
$('#classes-in-classgroup li a').eq(index).addClass('selected');
|
2011-01-24 18:24:24 +00:00
|
|
|
})
|
|
|
|
}, function() {
|
|
|
|
this.bar.attr({fill: "#999"});
|
|
|
|
$('rect').hover(function() {
|
|
|
|
var index = $('rect').index(this);
|
2011-01-28 18:21:17 +00:00
|
|
|
$('#classes-in-classgroup li a').eq(index).removeClass('selected');
|
2011-01-24 18:24:24 +00:00
|
|
|
})
|
|
|
|
});
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
$(document).ready(function() {
|
|
|
|
browseClassGroups.onLoad();
|
2011-01-28 18:21:17 +00:00
|
|
|
browseClassGroups.defaultClassGroup();
|
2011-01-24 18:24:24 +00:00
|
|
|
});
|