PATCH: Data scaling

jwinstanley - July 31, 2009 - 10:43
Project:Chart API
Version:6.x-1.x-dev
Component:Code
Category:task
Priority:normal
Assigned:Unassigned
Status:needs review
Description

Data is scaled from 0 to 100 by default. if adjust_resolution is TRUE, the data values are altered to fit in with a 0- 100 data range. This does not acheive the results I need, e.g. where the theoretical maximum value is 10 but the highest value is 7, I can either have a very tiny lines at the bottom, or lines reaching the top, neither of which portray the real situation: what I want in this case is that the hightest line should reach 70% of the way up.

I have added a few lines of code (shown below) to my local version of chart.module to allow the data scaling parameters of the google API to be accessed. I've not commited my version back to CVS as I'm not sure how helpful it will be for other people. If it is useful, please feel free to make the change or assign the issue to me and I'll commit it. Hope this helps

Line 220, insert:

<?php
*     #data_scale
?>

Line 277, insert:

<?php
  _chart_append
('chds', $chart['#data_scale'],              $data);
?>

Line 554, insert:

<?php
   
// Bar chart data scaling
   
case 'chds':
     
$data[$attr] .= implode(',', array($value['#min'], $value['#max']));
      break;
?>

Line 1042, insert:

<?php
/**
* Bar chart data scaling
*
* @param int $min
*   (optional) minimum value for data scale.
*
* @param int $max
*   (optional) maximum value for data scale.
*
* @return array
*/
function chart_data_scale($min = 1, $max = 100) {
  return array(      
     
'#min'    => $min
     
'#max' => $max
    );
}
?>

#1

SirClickALot - August 28, 2009 - 07:54

This sounds like exactly what I need and what many users would also need - I'm puzzled as to why it wasn't in place anyway surely any user will need what you describe before long?

Anyway, I have made all the additions to my local version of the chart module as per your instructions but can't get it working. Here's the details.

What I want is for my line chart (comprising two data sets) to scale its actual data values (which range from between roughly 80 and 100) so that they 'fill' the whole of the vertical available space.

In order to achieve this, am I correct in thinking that the following will do the job...

I set up an array which I called data_scalers to hold the min and max values for the two series.

/* Data scaling */
$data_scalers = array();
$data_scalers[] = 80;
$data_scalers[] = 100;
$data_scalers[] = 80;
$data_scalers[] = 100;

So that the data_scalers array is filled {80,100,80,100} to accomodate both data sets.

I then followed this with ...

'#data_scale' => $data_scalers

... as the last line of the '$chart = array(.....) bit inside the brackets of course.

The only reference 'chds' that I can see in the output URI is as follows...

...&chxt=y%2Cy%2Cx&chds=%2Cchd=t%3A87.912777500%2C...

Any guidance?

Thanks

Nick

#2

bouton - October 8, 2009 - 13:14
Version:6.x-1.2» 6.x-1.x-dev
Category:support request» feature request

Just what I needed. Ineeded scaling.
The above code works for me when used in the following manner

<?php
$chart
= array(
     
'#chart_id' => 'test_chart',
     
'#title' => t('My test'),
     
'#type' => CHART_TYPE_GMETER,
    );
$chart['#data_scale'] = array(
   
'#min'=>-54,
       
'#max'=>54);
$chart['#data']['test'] = 0;
$chart['#labels'][] = t('Test Label');

  echo
chart_render($chart);
?>

#3

bouton - October 8, 2009 - 13:16
Status:active» needs review

This should be looked at and properly patched.

#4

bouton - October 29, 2009 - 12:39
Category:feature request» task

Since the code above works fine for me when I use the google-o-meter (gom) chart type (only one tested), I decided to try my hand at a patch using the code submitted by jwinstanley above.

So, please find attached a patch. Hope this is what a patch should be.

AttachmentSize
chart.module.patch 1.84 KB

#5

bouton - October 29, 2009 - 12:39
Title:Data scaling» PATCH: Data scaling

Just changed the title.

 
 

Drupal is a registered trademark of Dries Buytaert.