How to control the levels of the tags in the cloud like li.views-cloud-size-1

momper - June 3, 2009 - 12:43
Project:Views Cloud
Version:6.x-1.0
Component:Miscellaneous
Category:support request
Priority:normal
Assigned:Unassigned
Status:closed
Description

hello

how can i control the levels of the tags in the cloud "like li.views-cloud-size-1"?
i have a lot with size-1, a few with size-3 and one with size-7.
but this is not comprehensible for me - the steps are very huge ...
how to control the point of change to the next level or how to control the maximum number of sizes?

thanks and greetings momper

#1

momper - June 10, 2009 - 08:35

@eaton - maybe a short tip for me?

#2

momper - June 27, 2009 - 12:39

we hacked a little bit - hardcoded style - maybe it's interesting for somebody (we filter out "Deutschland" - delete this):

<?php
// $Id: views_cloud.module,v 1.3 2008/09/17 16:02:42 eaton Exp $

/**
* @file
* Provide a tag cloud style for views data.
*/

/**
* Implementation of hook_views_api.
* Notifies the Views module that we're compatible with a particular API revision.
*/
function views_cloud_views_api() {
  return array('api' => 2);
}

/**
* Display a view as a cloud.
*/
function template_preprocess_views_cloud_style(&$vars) {
  drupal_add_css(drupal_get_path('module', 'views_cloud') . '/views_cloud.css');

  $view = $vars['view'];

  $result   = $vars['rows'];
  $vars['rows'] = array();

  $handler  = $view->style_plugin;
  $weight_field = $view->style_plugin->options['weight_field'];
  $hide = $view->style_plugin->options['hide_weight_field'];
  $fields   = &$view->field;
  $weight_field_alias = $fields[$weight_field]->field_alias;


  $min = 1000;
  $max = -1000; 
  foreach ($result as $row) {
    $cur = intval($row->{$weight_field_alias});
    if ($min > $cur) {
      $min = $cur;
    }
    if ($max < $cur) {
      $max = $cur;
    }
  }

  foreach ($fields as $field => $column) {
    foreach ($result as $num => $row) {
      if ((!$hide || ($field != $weight_field)) &&
          !empty($fields[$field]) && empty($fields[$field]->options['exclude'])) {
        $field_output = $fields[$field]->theme($row);
        $vars['rows'][$num]['output'] .= $field_output;
      }
    }
  }
 
  foreach ($vars['rows'] as $num => $row) {
    $vars['rows'][$num]['cloud_size'] = _views_cloud_size_helper($result[$num]->{$weight_field_alias}, $min, $max);
    $vars['rows'][$num] = (object)$vars['rows'][$num];
  }

  if (!empty($view->style_plugin->options['randomize'])) {
    shuffle($vars['rows']);
  }
}


/**
* Display a summary view as a cloud.
*/
function template_preprocess_views_cloud_summary_style(&$vars) {
  drupal_add_css(drupal_get_path('module', 'views_cloud') . '/views_cloud.css');

  $view     = $vars['view'];
  $argument = $view->argument[$view->build_info['summary_level']];

  $url_options = array();

  if (!empty($view->exposed_raw_input)) {
    $url_options['query'] = $view->exposed_raw_input;
  }

//print tt_dump($vars['rows']);
 
  // First we take a quick pass through to find the ceiling and floor
  $min = 1000;
  $max = -1000;
  foreach ($vars['rows'] as $id => $row) {
    $vars['rows'][$id]->link = $argument->summary_name($row);
    $vars['rows'][$id]->url = url($view->get_url($view->args), $url_options);
    $vars['rows'][$id]->count = intval($row->{$argument->count_alias});
   
    if (empty($vars['rows'][$id]->link) || $vars['rows'][$id]->link == 'Deutschland') {
      unset($vars['rows'][$id]);
      continue;
    }
 
    $cur = intval($row->{$argument->count_alias});
    if ($min > $cur)
      $min = $cur;
    if ($max < $cur)
      $max = $cur;
  }

  foreach ($vars['rows'] as $id => $row)
  {
      $vars['rows'][$id]->cloud_size = _views_cloud_size_helper($vars['rows'][$id]->count, $min, $max);
  }
}


function _views_cloud_size_helper($value, $min, $max, $sizes = 7) {

  // --- kiezblogs ---
  if ($value <= 1)   return 1;
  if ($value <= 2)   return 2; 
  if ($value <= 4)   return 3; 
  if ($value <= 10)  return 4;   
  if ($value <= 20)  return 5;     
  if ($value <= 40)  return 6;       
  return 7;
  // -----------------
 
/** 
  if ($min == $max) return 1;
  $range = ($sizes - 1) / ($max - $min);
  $value = ($value - $min) * $range ;
  return (intval($value + 1));
**/ 
}

#3

quicksketch - November 17, 2009 - 22:33
Status:active» fixed

This was caused by the same bug as #321038: Always "views-cloud-size-7". Items are now forced to be distributed between 1 and 7, as opposed to all sticking around the same number.

#4

System Message - December 1, 2009 - 22:40
Status:fixed» closed

Automatically closed -- issue fixed for 2 weeks with no activity.

 
 

Drupal is a registered trademark of Dries Buytaert.