Skip to content

Commit

Permalink
planettag/tagcloud almost finished: better implementation of planetta…
Browse files Browse the repository at this point in the history
…g (/tagplanet eliminated, compact design), changed tagcloud to jqcloud (color design still lacking, displaying top 100 tags); since GAE only supports python 2.6 we needed counter.py from outside source, see link in counter.py)
  • Loading branch information
pkra committed May 10, 2011
1 parent 6157af1 commit 1d49054
Show file tree
Hide file tree
Showing 12 changed files with 649 additions and 45 deletions.
36 changes: 36 additions & 0 deletions content/jimpl_cloud.js
@@ -0,0 +1,36 @@
(function($){
$.fn.tagCloud = function(options) {

var defaults = {
separator: ',',
randomize: true
};

var options = $.extend(defaults, options);

var randomize = function(){
return (Math.round(Math.random())-0.5);
};

var trim = function(text){
return text.replace(/^\s\s*/, '').replace(/\s\s*$/, '');
};

return this.each(function() {
var arr = $(this).text().split(options.separator);
if (options.randomize) arr.sort(randomize);
var words_arr = {};
$(arr).each(function(i){
word = trim(this);
words_arr[word] = words_arr[word]? words_arr[word] + 1 : 1;
});
var html = '';
$.each(words_arr, function(k, v) {
v = (v > 9)? 9 : v;
v = (v >= 3)? '2' + '.' + v : v;
html += '<a href="#' + k + '" style="font-size: ' + v + 'em" title="' + k + '"><span>' + k + '</span></a>'
});
$(this).html(html);
});
};
})(jQuery);
104 changes: 104 additions & 0 deletions content/jqcloud-0.1.8.js
@@ -0,0 +1,104 @@
/*!
* jQCloud Plugin for jQuery
*
* Version 0.1.8
*
* Copyright 2011, Luca Ongaro
* Licensed under the MIT license.
*
* Date: Fri Apr 8 10:24:15 +0100 2011
*/

(function( $ ){
$.fn.jQCloud = function(word_array, callback_function) {
// Reference to the container element
var $this = this;
// Reference to the ID of the container element
var container_id = $this.attr('id');

// Add the "jqcloud" class to the container for easy CSS styling
$this.addClass("jqcloud");

var drawWordCloud = function() {
// Helper function to test if an element overlaps others
var hitTest = function(elem, other_elems){
// Pairwise overlap detection
var overlapping = function(a, b){
if (Math.abs(2.0*a.offsetLeft + a.offsetWidth - 2.0*b.offsetLeft - b.offsetWidth) < a.offsetWidth + b.offsetWidth) {
if (Math.abs(2.0*a.offsetTop + a.offsetHeight - 2.0*b.offsetTop - b.offsetHeight) < a.offsetHeight + b.offsetHeight) {
return true;
}
}
return false;
};
var i = 0;
// Check elements for overlap one by one, stop and return false as soon as an overlap is found
for(i = 0; i < other_elems.length; i++) {
if (overlapping(elem, other_elems[i])) {
return true;
}
}
return false;
};

// Make sure every weight is a number before sorting
for (i = 0; i < word_array.length; i++) {
word_array[i].weight = parseFloat(word_array[i].weight, 10);
}

// Sort word_array from the word with the highest weight to the one with the lowest
word_array.sort(function(a, b) { if (a.weight < b.weight) {return 1;} else if (a.weight > b.weight) {return -1;} else {return 0;} });

var step = 2.0;
var already_placed_words = [];
var aspect_ratio = $this.width() / $this.height();
var origin_x = $this.width() / 2.0;
var origin_y = $this.height() / 2.0;

// Move each word in spiral until it finds a suitable empty place
$.each(word_array, function(index, word) {

// Define the ID attribute of the span that will wrap the word, and the associated jQuery selector string
var word_id = container_id + "_word_" + index;
var word_selector = "#" + word_id;

var angle = 6.28 * Math.random();
var radius = 0.0;

// Linearly map the original weight to a discrete scale from 1 to 10
var weight = Math.round((word.weight - word_array[word_array.length - 1].weight)/(word_array[0].weight - word_array[word_array.length - 1].weight) * 9.0) + 1;

var inner_html = word.url !== undefined ? "<a href='" + encodeURI(word.url).replace(/'/g, "%27") + "'>" + word.text + "</a>" : word.text;
$this.append("<span id='" + word_id + "' class='w" + weight + "' title='" + (word.title || "") + "'>" + inner_html + "</span>");

var width = $(word_selector).width();
var height = $(word_selector).height();
var left = origin_x - width / 2.0;
var top = origin_y - height / 2.0;
$(word_selector).css("position", "absolute");
$(word_selector).css("left", left + "px");
$(word_selector).css("top", top + "px");

while(hitTest(document.getElementById(word_id), already_placed_words)) {
radius += step;
angle += (index % 2 === 0 ? 1 : -1)*step;

left = origin_x - (width / 2.0) + (radius*Math.cos(angle)) * aspect_ratio;
top = origin_y + radius*Math.sin(angle) - (height / 2.0);

$(word_selector).css('left', left + "px");
$(word_selector).css('top', top + "px");
}
already_placed_words.push(document.getElementById(word_id));
});

if (typeof callback_function === 'function') {
callback_function.call(this);
}
};

// Delay execution so that the browser can render the page before the computatively intensive word cloud drawing
setTimeout(function(){drawWordCloud();}, 100);
return this;
};
})(jQuery);
11 changes: 11 additions & 0 deletions content/jqcloud-0.1.8.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 20 additions & 0 deletions content/jqcloud-LICENSE.txt
@@ -0,0 +1,20 @@
Copyright (c) 2011 Luca Ongaro

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
59 changes: 59 additions & 0 deletions content/jqcloud.css
@@ -0,0 +1,59 @@
div.jqcloud {
font-family: "Helvetica", "Arial", sans-serif;
color: #09f;
overflow: hidden;
position: relative;
}
div.jqcloud a {
color: inherit;
text-decoration: none;
}
div.jqcloud a:hover {
color: #0df;
}
div.jqcloud a:hover {
color: #0cf;
}
div.jqcloud span {
padding: 0;
}
div.jqcloud span.w10 {
font-size: 54px;
color: #0cf;
}
div.jqcloud span.w9 {
font-size: 50px;
color: #0cf;
}
div.jqcloud span.w8 {
font-size: 44px;
color: #0cf;
}
div.jqcloud span.w7 {
font-size: 40px;
color: #39d;
}
div.jqcloud span.w6 {
font-size: 34px;
color: #90c5f0;
}
div.jqcloud span.w5 {
font-size: 30px;
color: #90a0dd;
}
div.jqcloud span.w4 {
font-size: 24px;
color: #90c5f0;
}
div.jqcloud span.w3 {
font-size: 20px;
color: #a0ddff;
}
div.jqcloud span.w2 {
font-size: 14px;
color: #99ccee;
}
div.jqcloud span.w1 {
font-size: 10px;
color: #aab5f0;
}
16 changes: 16 additions & 0 deletions content/jquery-1.5.2.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion content/site.css
Expand Up @@ -395,4 +395,4 @@ background-color:black;

.planetbody h3 {
font-size: 110%;
}
}
88 changes: 85 additions & 3 deletions content/site.css~
Expand Up @@ -41,7 +41,7 @@ h1 {

h2 {
font-style: italic;
font-family: "Palatino Linotype","Palatino","URW Palladio L",Palladio,"Bitstream Vera Serif",sans-serif;
font-family: "Palatino Linotype","Palatino","URW Palladio L",Palladio,"Bitstream Vera Serif",serif;
border-bottom: 3px solid gray;
color: black;
padding-bottom: 3px;
Expand Down Expand Up @@ -288,7 +288,6 @@ background-color:black;
border: 1px solid black;
box-shadow: 4px 4px 8px black;
-webkit-box-shadow: 4px 4px 8px black;
float: left;
}

#postsbydate td {
Expand Down Expand Up @@ -326,4 +325,87 @@ background-color:black;
color: black;
}

/* ------------ End Date View Table --------------- */
/* ------------ End Date View Table --------------- */

/* ------------ Twitter ---------------- */

.twitter {
margin: auto;
padding: 20pt;
}

.twtr-widget {
margin: auto;
width: 400px;
}

.twtr-doc {
box-shadow: 2px 2px 4px #000000;
}

/* ------------- By ranking ---------------- */

.rankingcolumn {
float: left;
margin: 1ex !important;
}

.rankingcolumn .datecolumn{
width: 3ex !important;
}

/* -------------- Planet -------------------- */

.planetbox {
box-shadow: 4px 4px 7px black;
-webkit-box-shadow: 4px 4px 7px black;
border: 1px solid gray;
padding: 18px 18px 18px 18px;
margin: 10px 10px 50px 10px;
}

.planetbody, .planetbody h1, .planetbody h2, .planetbody h3, .planetbody h4 {
font-family: "Helvetica", "Bitstream Vera Sans", sans-serif, sans !important;
border: 0;
font-style: normal;
text-decoration: none;
}

.planethead h2 {
font-size: 150%;
margin-top: 0px;
}

.planetsubtitle {
font-size: 120%;
font-weight: bold;
}

.planethead h2 a {
text-decoration: none;
}

.planetbody h1 {
font-size: 125%;
}

.planetbody h2 {
font-size: 115%;
}

.planetbody h3 {
font-size: 110%;
}

/* -------------- Planet -------------------- */
.tagcloud {
width: 800px; margin-left: 40px; border: 1px dashed

}
.tagcloud a{
text-decoration:none; border-bottom:1px dotted ; padding-bottom:1px; margin: 4px;

}
.tagcloud a:hover {
text-decoration:none; border-bottom:2px solid ;
}

0 comments on commit 1d49054

Please sign in to comment.