Index: views_cloud.module =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/views_cloud/views_cloud.module,v retrieving revision 1.3 diff -u -p -r1.3 views_cloud.module --- views_cloud.module 17 Sep 2008 16:02:42 -0000 1.3 +++ views_cloud.module 1 Jul 2009 16:57:01 -0000 @@ -53,9 +53,12 @@ function template_preprocess_views_cloud } } } - + + // Get selected algorithm + $algofunc = '_views_cloud_size_helper'; + $algofunc .= ($view->style_plugin->options['algorithm'] == 'linear' ? '_lin' : '_log' ); 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]['cloud_size'] = $algofunc($result[$num]->{$weight_field_alias}, $min, $max); $vars['rows'][$num] = (object)$vars['rows'][$num]; } @@ -105,8 +108,11 @@ function template_preprocess_views_cloud } } + // Get selected algorithm + $algofunc = '_views_cloud_size_helper'; + $algofunc .= ($view->style_plugin->options['algorithm'] == 'linear' ? '_lin' : '_log' ); foreach ($vars['rows'] as $id => $row) { - $vars['rows'][$id]->cloud_size = _views_cloud_size_helper($vars['rows'][$id]->count, $min, $max); + $vars['rows'][$id]->cloud_size = $algofunc($vars['rows'][$id]->count, $min, $max); } if (!empty($view->style_plugin->options['randomize'])) { @@ -114,10 +120,38 @@ function template_preprocess_views_cloud } } +/** + * Algorithm for calculating relative size that is logarithmic. + * + * @param $value + * @param $min + * @param $max + * @param $sizes + * @return + */ +function _views_cloud_size_helper_lin($value, $min, $max, $sizes = 7) { + if ($min == $max) return 1; + $range = ($sizes - 1) / ($max - $min); + $value = ($value - $min) * $range; + return (intval($value + 1)); +} -function _views_cloud_size_helper($value, $min, $max, $sizes = 7) { +/** + * Algorithm for calculating relative size that is logarithmic. + * + * @param $value + * @param $min + * @param $max + * @param $sizes + * @return + */ +function _views_cloud_size_helper_log($value, $min, $max, $sizes = 7) { if ($min == $max) return 1; + $value = log($value == 0 ? ++$value : $value); + $min = log($min == 0 ? ++$min : $min); + $max = log($max); $range = ($sizes - 1) / ($max - $min); $value = ($value - $min) * $range; return (intval($value + 1)); } + Index: views_cloud_plugin_style_cloud.inc =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/views_cloud/views_cloud_plugin_style_cloud.inc,v retrieving revision 1.2.2.1 diff -u -p -r1.2.2.1 views_cloud_plugin_style_cloud.inc --- views_cloud_plugin_style_cloud.inc 28 May 2009 16:37:05 -0000 1.2.2.1 +++ views_cloud_plugin_style_cloud.inc 1 Jul 2009 16:57:01 -0000 @@ -7,6 +7,7 @@ class views_cloud_plugin_style_cloud ext function option_definition() { $options = parent::option_definition(); $options['randomize'] = array('default' => TRUE); + $options['algorithm'] = array('default' => TRUE); $options['weight_field'] = array('default' => NULL); $options['hide_weight_field'] = array('default' => TRUE); return $options; @@ -49,6 +52,14 @@ class views_cloud_plugin_style_cloud ext '#description' => t("This setting respects the View's sort order when limiting large paged lists, but shuffles each list of items when displayed on the page."), '#default_value' => $this->options['randomize'], ); - + + $form['algorithm'] = array( + '#type' => 'select', + '#title' => t('Weight to size algorithm'), + '#description' => t("Select the item weight sizing algorithm, linear or logarithmic. Logarithmic emphasizes the relative weight of items."), + '#options' => array('linear' => t('Linear'), 'logarithmic' => t('Logarithmic')), + '#default_value' => $this->options['algorithm'], + ); + } } Index: views_cloud_plugin_summary_style_cloud.inc =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/views_cloud/views_cloud_plugin_summary_style_cloud.inc,v retrieving revision 1.1 diff -u -p -r1.1 views_cloud_plugin_summary_style_cloud.inc --- views_cloud_plugin_summary_style_cloud.inc 17 Sep 2008 16:02:42 -0000 1.1 +++ views_cloud_plugin_summary_style_cloud.inc 1 Jul 2009 16:57:01 -0000 @@ -18,7 +18,15 @@ class views_cloud_plugin_summary_style_c '#title' => t('Randomize the order of items'), '#description' => t("This setting respects the View's sort order when limiting large paged lists, but shuffles each list of items when displayed on the page."), '#default_value' => $this->options['randomize'], - ); + ); + + $form['algorithm'] = array( + '#type' => 'select', + '#title' => t('Weight to size algorithm'), + '#description' => t("Select the item weight sizing algorithm, linear or logarithmic. Logarithmic emphasizes the relative weight of items."), + '#options' => array('linear' => t('Linear'), 'logarithmic' => t('Logarithmic')), + '#default_value' => $this->options['algorithm'], + ); } }