forked from mathblogging/mathblogging
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
planettag/tagcloud almost finished: better implementation of planetta…
…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
Showing
12 changed files
with
649 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -395,4 +395,4 @@ background-color:black; | |
|
||
.planetbody h3 { | ||
font-size: 110%; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.