CSS weight in jQCloud, a jQuery plugin

51 Views Asked by At

I need to create a tag cloud from a JSON file, which is made as follows:

{
   "data": "2023/02/14",
   "titolo": "San Valentino e un gatto a tre zampe",
   "anno_1": 1952,
   "anno_2": 1921,
   "anno_3": "",
   "luogo_1": "Italia",
   "luogo_2": "",
   "luogo_3": "",
   "persona_1": "Federico Seneca",
   "persona_2": "Luigi Broggini",
   "persona_3": "Luisa Spagnoli",
   "persona_4": "",
   "parola_1": "Perugina",
   "parola_2": "packaging",
   "parola_3": "ENI",
   "parola_4": "AGIP",
   "parola_5": "Futurismo"
 },

I extract "persona_1", "persona_2", "persona_3", "persona_4" from each entry using PHP and append all of them in an array:

$puntate = "docs/centra.json";
$html = file_get_contents($puntate);
$result = json_decode($html, true);
foreach($result as $key => $row) {
    $persona_1 = $row['persona_1'];
    $persona_2 = $row['persona_2'];
    $persona_3 = $row['persona_3'];
    $persona_4 = $row['persona_4'];
    array_push($persone,$persona_1,$persona_2,$persona_3,$persona_4);
}

Then I use jQCloud (a jQuery plugin) to build the tag cloud:

<script type="text/javascript">
var persone_array = [
<?php
foreach($persone as $personee => $freqpersone){
    echo '{text: "';
    echo $personee;
    echo '", weight: ';
    echo $freqpersone;
    echo '},';
}
?>
];
$(function() {
    $("#cloudpersone").jQCloud(persone_array);
    autoResize: true
});
</script>

The result can be seen here. All tags in the cloud are given a "weight: 1", although in the array $persone some words occur more often. Below is an extract from the array:

Array ( [] => 78 
[Albe Steiner] => 4 [Achille Castiglioni] => 4 [Bruno Munari] => 4 
[Marco Zanuso] => 2 [Richard Sapper] => 2 
[Andy Warhol] => 1 [Italo Lupi] => 1

I guess that the most frequent occurences should be shown with a higher weight. Is anything wrong? The "weight" in the plugin is described as "the relative importance of the word - the range is arbitrary and will be linearly mapped to a discrete scale".

0

There are 0 best solutions below