| 1 |
<?php |
<?php |
| 2 |
|
// $Id$ |
|
/** |
|
|
* @file |
|
|
* Google Charting API |
|
|
* @author Tj Holowaychuk <http://www.350designs.com/> |
|
|
* @package Chart |
|
|
*/ |
|
|
|
|
| 3 |
/** |
/** |
| 4 |
* Misc |
* @file |
| 5 |
*/ |
* Provides Google chart API integration. |
| 6 |
|
* |
| 7 |
|
* @author Tj Holowaychuk <http://www.350designs.com/> |
| 8 |
|
* @author Jimmy Berry ("boombatower", http://drupal.org/user/214218) |
| 9 |
|
* @package Chart |
| 10 |
|
*/ |
| 11 |
|
|
| 12 |
|
/* |
| 13 |
|
* Misc |
| 14 |
|
*/ |
| 15 |
define('CHART_URI', 'http://chart.apis.google.com/chart'); |
define('CHART_URI', 'http://chart.apis.google.com/chart'); |
| 16 |
|
|
| 17 |
/** |
/* |
| 18 |
* Chart types |
* Chart types. |
| 19 |
*/ |
*/ |
| 20 |
define('CHART_TYPE_LINE', 'lc'); |
define('CHART_TYPE_LINE', 'lc'); |
| 21 |
define('CHART_TYPE_LINE_XY', 'lxy'); |
define('CHART_TYPE_LINE_XY', 'lxy'); |
| 22 |
define('CHART_TYPE_BAR_H', 'bhs'); |
define('CHART_TYPE_BAR_H', 'bhs'); |
| 30 |
define('CHART_TYPE_MAP', 't'); |
define('CHART_TYPE_MAP', 't'); |
| 31 |
define('CHART_TYPE_GMETER', 'gom'); |
define('CHART_TYPE_GMETER', 'gom'); |
| 32 |
|
|
| 33 |
/** |
/* |
| 34 |
* Marker types |
* Marker types. |
| 35 |
*/ |
*/ |
| 36 |
define('CHART_MARKER_ARROW', 'a'); |
define('CHART_MARKER_ARROW', 'a'); |
| 37 |
define('CHART_MARKER_CROSS', 'c'); |
define('CHART_MARKER_CROSS', 'c'); |
| 38 |
define('CHART_MARKER_DIAMOND', 'd'); |
define('CHART_MARKER_DIAMOND', 'd'); |
| 43 |
define('CHART_MARKER_HORIZONTAL_LINE', 'h'); |
define('CHART_MARKER_HORIZONTAL_LINE', 'h'); |
| 44 |
define('CHART_MARKER_X', 'x'); |
define('CHART_MARKER_X', 'x'); |
| 45 |
|
|
| 46 |
/** |
/* |
| 47 |
* Axis |
* Axis. |
| 48 |
*/ |
*/ |
| 49 |
define('CHART_AXIS_X_BOTTOM', 'x'); |
define('CHART_AXIS_X_BOTTOM', 'x'); |
| 50 |
define('CHART_AXIS_X_TOP', 't'); |
define('CHART_AXIS_X_TOP', 't'); |
| 51 |
define('CHART_AXIS_Y_LEFT', 'y'); |
define('CHART_AXIS_Y_LEFT', 'y'); |
| 52 |
define('CHART_AXIS_Y_RIGHT', 'r'); |
define('CHART_AXIS_Y_RIGHT', 'r'); |
| 53 |
|
|
| 54 |
/** |
/** |
| 55 |
* Alignment |
* Alignment. |
| 56 |
*/ |
*/ |
| 57 |
define('CHART_ALIGN_LEFT', -1); |
define('CHART_ALIGN_LEFT', -1); |
| 58 |
define('CHART_ALIGN_CENTER', 0); |
define('CHART_ALIGN_CENTER', 0); |
| 59 |
define('CHART_ALIGN_RIGHT', 1); |
define('CHART_ALIGN_RIGHT', 1); |
| 60 |
|
|
| 61 |
/* ----------------------------------------------------------------- |
/*----------------------------------------------------------------- |
| 62 |
|
* Hook Implementations |
| 63 |
Hook Implementations |
*------------------------------------------------------------------*/ |
|
|
|
|
------------------------------------------------------------------ */ |
|
| 64 |
|
|
| 65 |
/** |
/** |
| 66 |
* Implementation of hook_perm(); |
* Implementation of hook_perm(); |
| 67 |
*/ |
*/ |
| 68 |
function chart_perm() { |
function chart_perm() { |
| 69 |
return array('administer chart'); |
return array('administer chart'); |
| 70 |
} |
} |
| 71 |
|
|
| 72 |
/** |
/** |
| 73 |
* Implementation of hook_init(). |
* Implementation of hook_init(). |
| 74 |
*/ |
*/ |
| 75 |
function chart_init() { |
function chart_init() { |
| 76 |
_chart_color_schemes(TRUE); |
_chart_color_schemes(TRUE); |
| 77 |
} |
} |
| 78 |
|
|
| 79 |
/** |
/** |
| 80 |
* Implementation of hook_menu(). |
* Implementation of hook_menu(). |
| 81 |
*/ |
*/ |
| 82 |
function chart_menu() { |
function chart_menu() { |
| 83 |
$items = array(); |
$items = array(); |
| 84 |
|
|
| 92 |
return $items; |
return $items; |
| 93 |
} |
} |
| 94 |
|
|
| 95 |
/* ----------------------------------------------------------------- |
/*----------------------------------------------------------------- |
| 96 |
|
* Public API |
| 97 |
Public API |
*------------------------------------------------------------------*/ |
| 98 |
|
|
| 99 |
------------------------------------------------------------------ */ |
/** |
| 100 |
|
* Renders a chart structure. |
| 101 |
/** |
* |
| 102 |
* Renders a chart structure. |
* @param array $chart |
| 103 |
* |
* |
| 104 |
* @param array $chart |
* @param array $attributes |
| 105 |
* |
* (optional) Assoc array of attributes parsed by drupal_attributes(); |
| 106 |
* @param array $attributes |
* |
| 107 |
* (optional) Assoc array of attributes parsed by drupal_attributes(); |
* @return mixed |
| 108 |
* |
* - Success: Chart image markup |
| 109 |
* @return mixed |
* - Failure: FALSE |
| 110 |
* - Success: Chart image markup |
*/ |
|
* - Failure: FALSE |
|
|
*/ |
|
| 111 |
function chart_render($chart, $attributes = array()) { |
function chart_render($chart, $attributes = array()) { |
| 112 |
if ($chart_query_string = chart_build($chart)){ |
if ($chart_query_string = chart_build($chart)){ |
| 113 |
$attributes['id'] = 'chart-' . $chart['#chart_id']; |
$attributes['id'] = 'chart-' . $chart['#chart_id']; |
| 125 |
} |
} |
| 126 |
|
|
| 127 |
/** |
/** |
| 128 |
* Returns the chart URL. |
* Returns the chart URL. |
| 129 |
* |
* |
| 130 |
* @param array $chart |
* @param array $chart |
| 131 |
* |
* |
| 132 |
* @return mixed |
* @return mixed |
| 133 |
* - Success: Chart image markup |
* - Success: Chart image markup |
| 134 |
* - Failure: FALSE |
* - Failure: FALSE |
| 135 |
*/ |
*/ |
| 136 |
function chart_url($chart) { |
function chart_url($chart) { |
| 137 |
if ($chart_query_string = chart_build($chart)){ |
if ($chart_query_string = chart_build($chart)){ |
| 138 |
return CHART_URI . '?' . $chart_query_string; |
return CHART_URI . '?' . $chart_query_string; |
| 144 |
|
|
| 145 |
|
|
| 146 |
/** |
/** |
| 147 |
* Copies rendered chart image. |
* Copies rendered chart image. |
| 148 |
* |
* |
| 149 |
* @param array $chart |
* @param array $chart |
| 150 |
* Chart API structure |
* Chart API structure |
| 151 |
* |
* |
| 152 |
* @param string $name |
* @param string $name |
| 153 |
* (optional) Filename WITHOUT extension. |
* (optional) Filename WITHOUT extension. |
| 154 |
* when NULL #chart_id is used. |
* when NULL #chart_id is used. |
| 155 |
* |
* |
| 156 |
* @param string $dest |
* @param string $dest |
| 157 |
* (optional) A string containing the path to verify. If this value is |
* (optional) A string containing the path to verify. If this value is |
| 158 |
* omitted, Drupal's 'files/charts' directory will be used. |
* omitted, Drupal's 'files/charts' directory will be used. |
| 159 |
* |
* |
| 160 |
* @param string $replace |
* @param string $replace |
| 161 |
* (optional) Replace behavior when the destination file already exists. |
* (optional) Replace behavior when the destination file already exists. |
| 162 |
* - FILE_EXISTS_REPLACE: Replace the existing file |
* - FILE_EXISTS_REPLACE: Replace the existing file |
| 163 |
* - FILE_EXISTS_RENAME: Appends _{incrementing number} until the filename is unique |
* - FILE_EXISTS_RENAME: Appends _{incrementing number} until the filename is unique |
| 164 |
* - FILE_EXISTS_ERROR: Do nothing and return FALSE. |
* - FILE_EXISTS_ERROR: Do nothing and return FALSE. |
| 165 |
* |
* |
| 166 |
* @return bool |
* @return bool |
| 167 |
*/ |
*/ |
| 168 |
function chart_copy($chart, $name = NULL, $dest = 'charts', $replace = FILE_EXISTS_REPLACE) { |
function chart_copy($chart, $name = NULL, $dest = 'charts', $replace = FILE_EXISTS_REPLACE) { |
| 169 |
if (!$chart_query_string = chart_build($chart)){ |
if (!$chart_query_string = chart_build($chart)){ |
| 170 |
return FALSE; |
return FALSE; |
| 197 |
} |
} |
| 198 |
|
|
| 199 |
/** |
/** |
| 200 |
* Build chart query string. |
* Build chart query string. |
| 201 |
* |
* |
| 202 |
* @param array $chart |
* @param array $chart |
| 203 |
* |
* |
| 204 |
* REQUIRED |
* REQUIRED |
| 205 |
* #chart_id |
* #chart_id |
| 206 |
* #type |
* #type |
| 207 |
* #data |
* #data |
| 208 |
* |
* |
| 209 |
* OPTIONAL |
* OPTIONAL |
| 210 |
* #title |
* #title |
| 211 |
* #size |
* #size |
| 212 |
* #legends |
* #legends |
| 213 |
* #labels |
* #labels |
| 214 |
* #adjust_resolution |
* #adjust_resolution |
| 215 |
* #line_styles |
* #line_styles |
| 216 |
* #grid_lines |
* #grid_lines |
| 217 |
* #shape_markers |
* #shape_markers |
| 218 |
* #data_colors |
* #data_colors |
| 219 |
* #chart_fill |
* #chart_fill |
| 220 |
* #mixed_axis_labels |
* #mixed_axis_labels |
| 221 |
* #mixed_axis_label_styles |
* #mixed_axis_label_styles |
| 222 |
* #bar_size |
* #bar_size |
| 223 |
* #countries |
* #countries |
| 224 |
* #georange |
* #georange |
| 225 |
* |
* |
| 226 |
* @return mixed |
* @return mixed |
| 227 |
* Query string or FALSE on failure. |
* Query string or FALSE on failure. |
| 228 |
*/ |
*/ |
| 229 |
function chart_build($chart) { |
function chart_build($chart) { |
| 230 |
static $charts; |
static $charts; |
| 231 |
|
|
| 305 |
return $charts[$chart['#chart_id']]; |
return $charts[$chart['#chart_id']]; |
| 306 |
} |
} |
| 307 |
|
|
| 308 |
/* ----------------------------------------------------------------- |
/*----------------------------------------------------------------- |
| 309 |
|
* Page Callbacks |
| 310 |
Page Callbacks |
*------------------------------------------------------------------*/ |
|
|
|
|
------------------------------------------------------------------ */ |
|
| 311 |
|
|
| 312 |
/** |
/** |
| 313 |
* Settings form page callback handler. |
* Settings form page callback handler. |
| 314 |
*/ |
*/ |
| 315 |
function chart_settings() { |
function chart_settings() { |
| 316 |
$form = array(); |
$form = array(); |
| 317 |
|
|
| 346 |
|
|
| 347 |
|
|
| 348 |
/** |
/** |
| 349 |
* Implementation of hook_validate(); |
* Implementation of hook_validate(); |
| 350 |
*/ |
*/ |
| 351 |
function chart_settings_validate($form, &$form_state) { |
function chart_settings_validate($form, &$form_state) { |
| 352 |
if (!empty($form_state['values']['chart_global_bg']) && !preg_match('/[a-fA-F0-9]{6}/is', $form_state['values']['chart_global_bg'])){ |
if (!empty($form_state['values']['chart_global_bg']) && !preg_match('/[a-fA-F0-9]{6}/is', $form_state['values']['chart_global_bg'])){ |
| 353 |
form_set_error('chart_global_bg', t('Invalid color. Formatted as RRGGBB with no pound sign.')); |
form_set_error('chart_global_bg', t('Invalid color. Formatted as RRGGBB with no pound sign.')); |
| 360 |
} |
} |
| 361 |
} |
} |
| 362 |
|
|
| 363 |
/* ----------------------------------------------------------------- |
/*----------------------------------------------------------------- |
| 364 |
|
* Helpers |
| 365 |
Helpers |
*------------------------------------------------------------------*/ |
|
|
|
|
------------------------------------------------------------------ */ |
|
| 366 |
|
|
| 367 |
/** |
/** |
| 368 |
* Encode an array of data. |
* Encode an array of data. |
| 369 |
* |
* |
| 370 |
* Missing data placeholder 'NULL' is replaced |
* Missing data placeholder 'NULL' is replaced |
| 371 |
* the appropriate placeholder. |
* the appropriate placeholder. |
| 372 |
* |
* |
| 373 |
* @return string |
* @return string |
| 374 |
*/ |
*/ |
| 375 |
function _chart_encode_data($data) { |
function _chart_encode_data($data) { |
| 376 |
$output = ''; |
$output = ''; |
| 377 |
if (count($data)){ |
if (count($data)){ |
| 395 |
} |
} |
| 396 |
|
|
| 397 |
/** |
/** |
| 398 |
* Adjusts chart data transforming values so that they may |
* Adjusts chart data transforming values so that they may |
| 399 |
* be represented properly within the given resolution |
* be represented properly within the given resolution |
| 400 |
* for the selected encoding type. |
* for the selected encoding type. |
| 401 |
*/ |
*/ |
| 402 |
function _chart_adjust_resolution($chart_id, &$data, $max_value = NULL) { |
function _chart_adjust_resolution($chart_id, &$data, $max_value = NULL) { |
| 403 |
static $max; |
static $max; |
| 404 |
|
|
| 449 |
} |
} |
| 450 |
|
|
| 451 |
/** |
/** |
| 452 |
* When the value passed is valid append a chart API |
* When the value passed is valid append a chart API |
| 453 |
* attribute and parsed values to $data. |
* attribute and parsed values to $data. |
| 454 |
*/ |
*/ |
| 455 |
function _chart_append($attr, $value, &$data) { |
function _chart_append($attr, $value, &$data) { |
| 456 |
// Size and fill contain defaults, all other attributes must be set |
// Size and fill contain defaults, all other attributes must be set |
| 457 |
if (!$value && $attr != 'chs' && $attr != 'chf'){ |
if (!$value && $attr != 'chs' && $attr != 'chf'){ |
| 678 |
} |
} |
| 679 |
|
|
| 680 |
/** |
/** |
| 681 |
* Return the max value of a single level array. |
* Return the max value of a single level array. |
| 682 |
*/ |
*/ |
| 683 |
function _chart_get_max($array) { |
function _chart_get_max($array) { |
| 684 |
rsort($array, SORT_NUMERIC); |
rsort($array, SORT_NUMERIC); |
| 685 |
$max = is_array($array[0]) ? 1 : $array[0]; |
$max = is_array($array[0]) ? 1 : $array[0]; |
| 699 |
} |
} |
| 700 |
|
|
| 701 |
/** |
/** |
| 702 |
* Override the default chart aspect ratio. |
* Override the default chart aspect ratio. |
| 703 |
*/ |
*/ |
| 704 |
function _chart_override_aspect(&$width, &$height) { |
function _chart_override_aspect(&$width, &$height) { |
| 705 |
$decrement = 20; |
$decrement = 20; |
| 706 |
$max_width = variable_get('chart_max_width', FALSE); |
$max_width = variable_get('chart_max_width', FALSE); |
| 727 |
} |
} |
| 728 |
|
|
| 729 |
/** |
/** |
| 730 |
* Admin error. |
* Admin error. |
| 731 |
*/ |
*/ |
| 732 |
function _chart_error($message, $admin = TRUE) { |
function _chart_error($message, $admin = TRUE) { |
| 733 |
if ($admin){ |
if ($admin){ |
| 734 |
if (user_access('administer chart')){ |
if (user_access('administer chart')){ |
| 741 |
} |
} |
| 742 |
|
|
| 743 |
/** |
/** |
| 744 |
* Check if chart data is below size limit. |
* Check if chart data is below size limit. |
| 745 |
*/ |
*/ |
| 746 |
function _chart_is_valid_size($size) { |
function _chart_is_valid_size($size) { |
| 747 |
if (!is_numeric($size['#width']) && !is_numeric($size['#height'])){ |
if (!is_numeric($size['#width']) && !is_numeric($size['#height'])){ |
| 748 |
return FALSE; |
return FALSE; |
| 756 |
} |
} |
| 757 |
|
|
| 758 |
/** |
/** |
| 759 |
* Invoke chart_color_schemes(); hook to gather available schemes. |
* Invoke chart_color_schemes(); hook to gather available schemes. |
| 760 |
* When $init is FALSE the color schemes gathered are returned. |
* When $init is FALSE the color schemes gathered are returned. |
| 761 |
*/ |
*/ |
| 762 |
function _chart_color_schemes($init = FALSE) { |
function _chart_color_schemes($init = FALSE) { |
| 763 |
static $colors; |
static $colors; |
| 764 |
|
|
| 801 |
} |
} |
| 802 |
} |
} |
| 803 |
|
|
| 804 |
/* ----------------------------------------------------------------- |
/*----------------------------------------------------------------- |
| 805 |
|
* Label Utils |
| 806 |
Label Utils |
*------------------------------------------------------------------*/ |
|
|
|
|
------------------------------------------------------------------ */ |
|
| 807 |
|
|
| 808 |
/** |
/** |
| 809 |
* Title |
* Title |
| 810 |
* |
* |
| 811 |
* @param string $title |
* @param string $title |
| 812 |
* |
* |
| 813 |
* @param string $color |
* @param string $color |
| 814 |
* |
* |
| 815 |
* @param int $size |
* @param int $size |
| 816 |
* |
* |
| 817 |
* @return array |
* @return array |
| 818 |
*/ |
*/ |
| 819 |
function chart_title($title, $color = '000000', $size = 14) { |
function chart_title($title, $color = '000000', $size = 14) { |
| 820 |
return array( |
return array( |
| 821 |
'#title' => $title, |
'#title' => $title, |
| 825 |
} |
} |
| 826 |
|
|
| 827 |
/** |
/** |
| 828 |
* Create a mixed axis label. |
* Create a mixed axis label. |
| 829 |
* |
* |
| 830 |
* Labels must be nested by axis and index: |
* Labels must be nested by axis and index: |
| 831 |
* @code |
* @code |
| 832 |
* $chart['#mixed_axis_labels'][CHART_AXIS_X_BOTTOM][0][] = chart_mixed_axis_label(t('Monday')); |
* $chart['#mixed_axis_labels'][CHART_AXIS_X_BOTTOM][0][] = chart_mixed_axis_label(t('Monday')); |
| 833 |
* $chart['#mixed_axis_labels'][CHART_AXIS_X_BOTTOM][0][] = chart_mixed_axis_label(t('Tuesday')); |
* $chart['#mixed_axis_labels'][CHART_AXIS_X_BOTTOM][0][] = chart_mixed_axis_label(t('Tuesday')); |
| 834 |
* $chart['#mixed_axis_labels'][CHART_AXIS_X_BOTTOM][0][] = chart_mixed_axis_label(t('Wednesday')); |
* $chart['#mixed_axis_labels'][CHART_AXIS_X_BOTTOM][0][] = chart_mixed_axis_label(t('Wednesday')); |
| 835 |
* $chart['#mixed_axis_labels'][CHART_AXIS_Y_LEFT][1][] = chart_mixed_axis_range_label(0, 50); |
* $chart['#mixed_axis_labels'][CHART_AXIS_Y_LEFT][1][] = chart_mixed_axis_range_label(0, 50); |
| 836 |
* $chart['#mixed_axis_labels'][CHART_AXIS_Y_LEFT][2][] = chart_mixed_axis_label(t('Min')); |
* $chart['#mixed_axis_labels'][CHART_AXIS_Y_LEFT][2][] = chart_mixed_axis_label(t('Min')); |
| 837 |
* $chart['#mixed_axis_labels'][CHART_AXIS_Y_LEFT][2][] = chart_mixed_axis_label(t('Max')); |
* $chart['#mixed_axis_labels'][CHART_AXIS_Y_LEFT][2][] = chart_mixed_axis_label(t('Max')); |
| 838 |
* @endcode |
* @endcode |
| 839 |
* |
* |
| 840 |
* @param mixed $label |
* @param mixed $label |
| 841 |
* - string: A single label |
* - string: A single label |
| 842 |
* - array: An array of label strings, or an assoc array containing #label and #position |
* - array: An array of label strings, or an assoc array containing #label and #position |
| 843 |
* |
* |
| 844 |
* @param int $position |
* @param int $position |
| 845 |
* (optional) An integer between 0 - 100 representing where the label should appear along the axis. |
* (optional) An integer between 0 - 100 representing where the label should appear along the axis. |
| 846 |
* 0 representing bottom and left, 100 representing top and right. When one label within a given set |
* 0 representing bottom and left, 100 representing top and right. When one label within a given set |
| 847 |
* is given a position, the remaining labels in the set must have a position. |
* is given a position, the remaining labels in the set must have a position. |
| 848 |
* |
* |
| 849 |
* @return array |
* @return array |
| 850 |
*/ |
*/ |
| 851 |
function chart_mixed_axis_label($label, $position = NULL) { |
function chart_mixed_axis_label($label, $position = NULL) { |
| 852 |
return array( |
return array( |
| 853 |
'#label' => $label, |
'#label' => $label, |
| 856 |
} |
} |
| 857 |
|
|
| 858 |
/** |
/** |
| 859 |
* Create a mixed axis range label. |
* Create a mixed axis range label. |
| 860 |
* |
* |
| 861 |
* Labels must be nested by axis and index: |
* Labels must be nested by axis and index: |
| 862 |
* @code |
* @code |
| 863 |
* $chart['#mixed_axis_labels'][CHART_AXIS_X_BOTTOM][0][] = chart_mixed_axis_label(t('Monday')); |
* $chart['#mixed_axis_labels'][CHART_AXIS_X_BOTTOM][0][] = chart_mixed_axis_label(t('Monday')); |
| 864 |
* $chart['#mixed_axis_labels'][CHART_AXIS_X_BOTTOM][0][] = chart_mixed_axis_label(t('Tuesday')); |
* $chart['#mixed_axis_labels'][CHART_AXIS_X_BOTTOM][0][] = chart_mixed_axis_label(t('Tuesday')); |
| 865 |
* $chart['#mixed_axis_labels'][CHART_AXIS_X_BOTTOM][0][] = chart_mixed_axis_label(t('Wednesday')); |
* $chart['#mixed_axis_labels'][CHART_AXIS_X_BOTTOM][0][] = chart_mixed_axis_label(t('Wednesday')); |
| 866 |
* $chart['#mixed_axis_labels'][CHART_AXIS_Y_LEFT][1][] = chart_mixed_axis_range_label(0, 50); |
* $chart['#mixed_axis_labels'][CHART_AXIS_Y_LEFT][1][] = chart_mixed_axis_range_label(0, 50); |
| 867 |
* $chart['#mixed_axis_labels'][CHART_AXIS_Y_LEFT][2][] = chart_mixed_axis_label(t('Min')); |
* $chart['#mixed_axis_labels'][CHART_AXIS_Y_LEFT][2][] = chart_mixed_axis_label(t('Min')); |
| 868 |
* $chart['#mixed_axis_labels'][CHART_AXIS_Y_LEFT][2][] = chart_mixed_axis_label(t('Max')); |
* $chart['#mixed_axis_labels'][CHART_AXIS_Y_LEFT][2][] = chart_mixed_axis_label(t('Max')); |
| 869 |
* @endcode |
* @endcode |
| 870 |
* |
* |
| 871 |
* @param string $start |
* @param string $start |
| 872 |
* |
* |
| 873 |
* @param string $end |
* @param string $end |
| 874 |
* |
* |
| 875 |
* @return array |
* @return array |
| 876 |
*/ |
*/ |
| 877 |
function chart_mixed_axis_range_label($start, $end) { |
function chart_mixed_axis_range_label($start, $end) { |
| 878 |
return array( |
return array( |
| 879 |
'#start' => $start, |
'#start' => $start, |
| 882 |
} |
} |
| 883 |
|
|
| 884 |
/** |
/** |
| 885 |
* Create a mixed axis for a corresponding label set index. |
* Create a mixed axis for a corresponding label set index. |
| 886 |
* |
* |
| 887 |
* @param int $index |
* @param int $index |
| 888 |
* |
* |
| 889 |
* @param string $color |
* @param string $color |
| 890 |
* |
* |
| 891 |
* @param int $font_size |
* @param int $font_size |
| 892 |
* |
* |
| 893 |
* @param int $alignment |
* @param int $alignment |
| 894 |
* - CHART_ALIGN_LEFT |
* - CHART_ALIGN_LEFT |
| 895 |
* - CHART_ALIGN_CENTER |
* - CHART_ALIGN_CENTER |
| 896 |
* - CHART_ALIGN_RIGHT |
* - CHART_ALIGN_RIGHT |
| 897 |
* |
* |
| 898 |
* @return array |
* @return array |
| 899 |
*/ |
*/ |
| 900 |
function chart_mixed_axis_label_style($index, $color, $font_size = 12, $alignment = CHART_ALIGN_CENTER) { |
function chart_mixed_axis_label_style($index, $color, $font_size = 12, $alignment = CHART_ALIGN_CENTER) { |
| 901 |
return array( |
return array( |
| 902 |
'#index' => $index, |
'#index' => $index, |
| 906 |
); |
); |
| 907 |
} |
} |
| 908 |
|
|
| 909 |
/* ----------------------------------------------------------------- |
/*----------------------------------------------------------------- |
| 910 |
|
* Style Utils |
| 911 |
Style Utils |
*------------------------------------------------------------------*/ |
|
|
|
|
------------------------------------------------------------------ */ |
|
| 912 |
|
|
| 913 |
/** |
/** |
| 914 |
* Chart size |
* Chart size |
| 915 |
* |
* |
| 916 |
* @return array |
* @return array |
| 917 |
*/ |
*/ |
| 918 |
function chart_size($width, $height) { |
function chart_size($width, $height) { |
| 919 |
return array( |
return array( |
| 920 |
'#width' => $width, |
'#width' => $width, |
| 923 |
} |
} |
| 924 |
|
|
| 925 |
/** |
/** |
| 926 |
* Data Colors |
* Data Colors |
| 927 |
* |
* |
| 928 |
* @param array $colors |
* @param array $colors |
| 929 |
* |
* |
| 930 |
* @return array |
* @return array |
| 931 |
*/ |
*/ |
| 932 |
function chart_data_colors($colors) { |
function chart_data_colors($colors) { |
| 933 |
return $colors; |
return $colors; |
| 934 |
} |
} |
| 935 |
|
|
| 936 |
/** |
/** |
| 937 |
* Line Style |
* Line Style |
| 938 |
* |
* |
| 939 |
* @param int $line_thickness |
* @param int $line_thickness |
| 940 |
* |
* |
| 941 |
* @param int $segment_length |
* @param int $segment_length |
| 942 |
* |
* |
| 943 |
* @param int $blank_segment_length |
* @param int $blank_segment_length |
| 944 |
* |
* |
| 945 |
* @return array |
* @return array |
| 946 |
*/ |
*/ |
| 947 |
function chart_line_style($line_thickness = 1, $segment_length = 1, $blank_segment_length = 0) { |
function chart_line_style($line_thickness = 1, $segment_length = 1, $blank_segment_length = 0) { |
| 948 |
return array( |
return array( |
| 949 |
'#line_thickness' => $line_thickness, |
'#line_thickness' => $line_thickness, |
| 953 |
} |
} |
| 954 |
|
|
| 955 |
/** |
/** |
| 956 |
* Grid Lines |
* Grid Lines |
| 957 |
* |
* |
| 958 |
* @param int $x_step |
* @param int $x_step |
| 959 |
* Space in pixels in which to step the horizontal lines. |
* Space in pixels in which to step the horizontal lines. |
| 960 |
* |
* |
| 961 |
* @param int $y_step |
* @param int $y_step |
| 962 |
* Space in pixels in which to step the virtical lines. |
* Space in pixels in which to step the virtical lines. |
| 963 |
* |
* |
| 964 |
* @param int $segment_length |
* @param int $segment_length |
| 965 |
* (optional) Visibile segment length in pixels. |
* (optional) Visibile segment length in pixels. |
| 966 |
* |
* |
| 967 |
* @param int $blank_segment_length |
* @param int $blank_segment_length |
| 968 |
* (optional) Blank segment length in pixels. |
* (optional) Blank segment length in pixels. |
| 969 |
* |
* |
| 970 |
* @return array |
* @return array |
| 971 |
*/ |
*/ |
| 972 |
function chart_grid_lines($x_step, $y_step, $segment_length = 1, $blank_segment_length = 3) { |
function chart_grid_lines($x_step, $y_step, $segment_length = 1, $blank_segment_length = 3) { |
| 973 |
return array( |
return array( |
| 974 |
'#x_step' => $x_step, |
'#x_step' => $x_step, |
| 979 |
} |
} |
| 980 |
|
|
| 981 |
/** |
/** |
| 982 |
* Shape Marker |
* Shape Marker |
| 983 |
* |
* |
| 984 |
* @param int $index |
* @param int $index |
| 985 |
* (optional) The index of the line on which to draw the marker. |
* (optional) The index of the line on which to draw the marker. |
| 986 |
* |
* |
| 987 |
* @param float $point |
* @param float $point |
| 988 |
* (optional) Floating point value that specifies on which data point |
* (optional) Floating point value that specifies on which data point |
| 989 |
* the marker will be drawn. |
* the marker will be drawn. |
| 990 |
* |
* |
| 991 |
* @param string $type |
* @param string $type |
| 992 |
* - CHART_MARKER_ARROW |
* - CHART_MARKER_ARROW |
| 993 |
* - CHART_MARKER_CROSS |
* - CHART_MARKER_CROSS |
| 994 |
* - CHART_MARKER_DIAMOND |
* - CHART_MARKER_DIAMOND |
| 995 |
* - CHART_MARKER_CIRCLE |
* - CHART_MARKER_CIRCLE |
| 996 |
* - CHART_MARKER_SQUARE |
* - CHART_MARKER_SQUARE |
| 997 |
* - CHART_MARKER_VIRTICAL_LINE_X |
* - CHART_MARKER_VIRTICAL_LINE_X |
| 998 |
* - CHART_MARKER_VIRTICAL_LINE_TOP |
* - CHART_MARKER_VIRTICAL_LINE_TOP |
| 999 |
* - CHART_MARKER_HORIZONTAL_LINE |
* - CHART_MARKER_HORIZONTAL_LINE |
| 1000 |
* - CHART_MARKER_X |
* - CHART_MARKER_X |
| 1001 |
* |
* |
| 1002 |
* @param int $size |
* @param int $size |
| 1003 |
* (optional) Marker size in pixels. |
* (optional) Marker size in pixels. |
| 1004 |
* |
* |
| 1005 |
* @param string $color |
* @param string $color |
| 1006 |
* |
* |
| 1007 |
* @return array |
* @return array |
| 1008 |
*/ |
*/ |
| 1009 |
function chart_shape_marker($index = 0, $point = 0, $type = 'o', $size = 20, $color = '000000') { |
function chart_shape_marker($index = 0, $point = 0, $type = 'o', $size = 20, $color = '000000') { |
| 1010 |
return array( |
return array( |
| 1011 |
'#type' => $type, |
'#type' => $type, |
| 1017 |
} |
} |
| 1018 |
|
|
| 1019 |
/** |
/** |
| 1020 |
* Range Marker |
* Range Marker |
| 1021 |
* |
* |
| 1022 |
* @param int $start |
* @param int $start |
| 1023 |
* |
* |
| 1024 |
* @param int $end |
* @param int $end |
| 1025 |
* |
* |
| 1026 |
* @param bool $virtical |
* @param bool $virtical |
| 1027 |
* |
* |
| 1028 |
* @param string $color |
* @param string $color |
| 1029 |
* |
* |
| 1030 |
* @return array |
* @return array |
| 1031 |
*/ |
*/ |
| 1032 |
function chart_range_marker($start, $end, $virtical = TRUE, $color = '000000') { |
function chart_range_marker($start, $end, $virtical = TRUE, $color = '000000') { |
| 1033 |
return array( |
return array( |
| 1034 |
'#start' => $start, |
'#start' => $start, |
| 1039 |
} |
} |
| 1040 |
|
|
| 1041 |
/** |
/** |
| 1042 |
* Bar chart bar sizing. |
* Bar chart bar sizing. |
| 1043 |
* |
* |
| 1044 |
* @param int $size |
* @param int $size |
| 1045 |
* (optional) Height or width of the bar. |
* (optional) Height or width of the bar. |
| 1046 |
* |
* |
| 1047 |
* @param int $spacing |
* @param int $spacing |
| 1048 |
* (optional) Pixel spacing between bars. |
* (optional) Pixel spacing between bars. |
| 1049 |
* |
* |
| 1050 |
* @return array |
* @return array |
| 1051 |
*/ |
*/ |
| 1052 |
function chart_bar_size($size = 40, $spacing = 20) { |
function chart_bar_size($size = 40, $spacing = 20) { |
| 1053 |
return array( |
return array( |
| 1054 |
'#size' => $size, |
'#size' => $size, |
| 1057 |
} |
} |
| 1058 |
|
|
| 1059 |
/** |
/** |
| 1060 |
* Solid Fill |
* Solid Fill |
| 1061 |
* |
* |
| 1062 |
* @param int $type |
* @param int $type |
| 1063 |
* (optional) 'bg' or 'c' |
* (optional) 'bg' or 'c' |
| 1064 |
* |
* |
| 1065 |
* @param string $color |
* @param string $color |
| 1066 |
* |
* |
| 1067 |
* @return array |
* @return array |
| 1068 |
*/ |
*/ |
| 1069 |
function chart_fill($type = 'c', $color = '000000') { |
function chart_fill($type = 'c', $color = '000000') { |
| 1070 |
return array( |
return array( |
| 1071 |
'#type' => $type, |
'#type' => $type, |
| 1075 |
} |
} |
| 1076 |
|
|
| 1077 |
/** |
/** |
| 1078 |
* Linear Gradient |
* Linear Gradient |
| 1079 |
* |
* |
| 1080 |
* @param int $type |
* @param int $type |
| 1081 |
* (optional) 'bg' or 'c' |
* (optional) 'bg' or 'c' |
| 1082 |
* |
* |
| 1083 |
* @param int $color |
* @param int $color |
| 1084 |
* |
* |
| 1085 |
* @param int $offset |
* @param int $offset |
| 1086 |
* (optional) Cpecify at what point the color is pure where: 0 specifies the right-most |
* (optional) Cpecify at what point the color is pure where: 0 specifies the right-most |
| 1087 |
* chart position and 1 the left-most. |
* chart position and 1 the left-most. |
| 1088 |
* |
* |
| 1089 |
* @return array |
* @return array |
| 1090 |
*/ |
*/ |
| 1091 |
function chart_linear_gradient($type = 'c', $color = '000000', $offset = 0) { |
function chart_linear_gradient($type = 'c', $color = '000000', $offset = 0) { |
| 1092 |
return array( |
return array( |
| 1093 |
'#type' => $type, |
'#type' => $type, |
| 1097 |
} |
} |
| 1098 |
|
|
| 1099 |
/** |
/** |
| 1100 |
* Linear Stripes |
* Linear Stripes |
| 1101 |
* |
* |
| 1102 |
* @param int $type |
* @param int $type |
| 1103 |
* (optional) 'bg' or 'c' |
* (optional) 'bg' or 'c' |
| 1104 |
* |
* |
| 1105 |
* @param int $color |
* @param int $color |
| 1106 |
* |
* |
| 1107 |
* @param int $angle |
* @param int $angle |
| 1108 |
* (optional) Specifies the angle of the gradient between 0 (horizontal) and 90 (vertical). |
* (optional) Specifies the angle of the gradient between 0 (horizontal) and 90 (vertical). |
| 1109 |
* |
* |
| 1110 |
* @param float $width |
* @param float $width |
| 1111 |
* (optional) Must be between 0 and 1 where 1 is the full width of the chart. Stripes are |
* (optional) Must be between 0 and 1 where 1 is the full width of the chart. Stripes are |
| 1112 |
* repeated until the chart is filled. |
* repeated until the chart is filled. |
| 1113 |
* |
* |
| 1114 |
* @return array |
* @return array |
| 1115 |
*/ |
*/ |
| 1116 |
function chart_linear_stripes($type = 'c', $color = '000000', $angle = 0, $width = 0.25) { |
function chart_linear_stripes($type = 'c', $color = '000000', $angle = 0, $width = 0.25) { |
| 1117 |
return array( |
return array( |
| 1118 |
'#type' => $type, |
'#type' => $type, |
| 1123 |
); |
); |
| 1124 |
} |
} |
| 1125 |
|
|
| 1126 |
/* ----------------------------------------------------------------- |
/*----------------------------------------------------------------- |
| 1127 |
|
* Color Schemes |
| 1128 |
Color Schemes |
*------------------------------------------------------------------*/ |
| 1129 |
|
|
| 1130 |
------------------------------------------------------------------ */ |
/** |
| 1131 |
|
* Supplies a unique color. |
| 1132 |
/** |
* |
| 1133 |
* Supplies a unique color. |
* When an assoc array color scheme is provided |
| 1134 |
* |
* $content_id can be used to sync the color to |
| 1135 |
* When an assoc array color scheme is provided |
* the data rendered. Otherwise the next available |
| 1136 |
* $content_id can be used to sync the color to |
* color in the stack is assigned to $content_id |
| 1137 |
* the data rendered. Otherwise the next available |
* |
| 1138 |
* color in the stack is assigned to $content_id |
* @param string $content_id |
| 1139 |
* |
* |
| 1140 |
* @param string $content_id |
* @param string $scheme |
| 1141 |
* |
* (optional) Color scheme. |
| 1142 |
* @param string $scheme |
* |
| 1143 |
* (optional) Color scheme. |
* @return string |
| 1144 |
* |
* hex RGB value |
| 1145 |
* @return string |
*/ |
|
* hex RGB value |
|
|
*/ |
|
| 1146 |
function chart_unique_color($content_id, $scheme = 'default') { |
function chart_unique_color($content_id, $scheme = 'default') { |
| 1147 |
static $colors_used; |
static $colors_used; |
| 1148 |
$colors = _chart_color_schemes(); |
$colors = _chart_color_schemes(); |