Simple Yii Framework Tag Cloud Extension.
Requirements ¶
Yii 1.1 or above
Installation ¶
- Extract 'YiiTagCloud' folder to protected/extensions/YiiTagCloud.
Usage ¶
$this->widget('application.extensions.YiiTagCloud.YiiTagCloud',
array(
'beginColor' => '00089A',
'endColor' => 'A3AEFF',
'minFontSize' => 8,
'maxFontSize' => 20,
'arrTags' => array (
'MVC' => array('weight'=> 2),
'PHP' => array('weight'=> 9, 'url' => 'http://php.net'),
'MySQL' => array('weight'=> 8, 'url' => 'http://mysql.com'),
'jQuery' => array('weight'=> 6, 'url' => 'http://jquery.com'),
'SQL' => array('weight'=> 9),
'C#' => array('weight'=> 2),
),
)
);
User Contributed Notes 9
Good work
Good work!
Nice
Nice
AJAX Update?
Really nice extension. I am planning on using this on a dashboard interface. I already have setup some charts, gauges, etc that use AJAX to update their contents every minute or so. A really neat feature would be add a way to update the tags dynamically.
I suppose you could use jquery to create and ajax request to a render partial but thats a bit inelegant :(
AJAX Update
Well I setup an AJAX request that renders a Partial view and it works rather well :D
For my purposes i did have to make some changes to the YiiTagCloud.php as when I was populating the tag array it was possible for all my qeights to be 0 which was causing an illeagal division by zero error. Changes as below
public function calcFontSize($weight) { if ($this->maxWeight - $this->minWeight == 0) { return round(($weight - $this->minWeight) + $this->minFontSize); } else { return round(((($weight - $this->minWeight) * ($this->maxFontSize - $this->minFontSize)) / ($this->maxWeight - $this->minWeight)) + $this->minFontSize); } }When this happened The tags were all showing as the beginColor which wasn't what I required so I changed the generate colors method with
if ($this->minWeight == 0 && $this->maxWeight == 0) { $beginColor = hexdec($this->endColor); $endColor = hexdec($this->endColor); }after
$endColor = hexdec($this->endColor);Might be an idea to add a class option for display color if all weights are the same?
Thanks
Thanks guys!!
@David Walker I'll think in a way of implement your suggestions
Adding some CSS class
Adding a CSS class in options for flexible styling will be nice!
good one
useful extension
Division by zero exception
When minWeight == maxWeight (if only one tag is given), division by zero excwption fires in this line
return round(((($weight - $this->minWeight) * ($this->maxFontSize - $this->minFontSize)) / ($this->maxWeight - $this->minWeight)) + $this->minFontSize); }to fix it changed it to
return round(((($weight - $this->minWeight) * ($this->maxFontSize - $this->minFontSize)) / (($this->maxWeight - $this->minWeight) || 1)) + $this->minFontSize); }using arrays
how to user array in to create tagcloud like this type of array.
Array ( [toy] => 2 [not-possible ] => 1 [peace] => 1 [nedds] => 1 [fullfilment] => 1 [pakistan] => 1 [no-terrorism] => 1 [message-for-muslims] => 1 [a] => 1 [just ] => 1 [for-showoff] => 1 [a-dream] => 1 [peace-hen] => 1 [reality] => 1 )
here apply cloud on keys and frequency is their values.
thanks in advance
Leave a comment
If you have any questions, please ask in the forum instead.
Join the conversation to share a note.