array( 'arguments' => array('attributes' => array()), ), ); } /** * Returns HTML for a highcharts container. * * @param $attributes * An associative array containing valid HTML attributes to be applied to the * highchart container: * - id: Required. Must match the 'renderTo' option in the 'Highcharts.Chart' * object. * - style: Default: 'margin 0 auto' is appended to any existing style. * - class: Default: 'highcharts-chart' is appended to any existing class. * * @ingroup themeable * * @return * The chart div, ready for the highchart JS to render to. */ function theme_highcharts_chart($attributes = array()) { if ($attributes['id']) { $attributes['style'] = isset($attributes['style']) ? $attributes['style'] . 'margin: 0 auto' : 'margin: 0 auto'; $attributes['class'] = isset($attributes['class']) ? $attributes['class'] . ' highcharts-chart' : 'highcharts-chart'; $output = '
'; } return $output; } /** * Render a highchart. * * @param object $options * By reference. A highcharts options object. * * Any callbacks are specially handled as Drupal.settings only stores strings. * * Also includes: * - chart_id: added by reference. * * @see the highcharts API http://www.highcharts.com/ref/ */ function highcharts_render(&$options) { // Load common JS only once. static $js_added = false; if (!$js_added) { // Add highcharts library JS. module_load_include('module', 'libraries', 'libraries'); $path = libraries_get_path('highcharts'); if (!empty($path)) { drupal_add_js($path . '/js/highcharts.js'); } // Add highcharts behavior. This allows us to leverage the entire highcharts // API without needing to define each type separately. drupal_add_js(drupal_get_path('module', 'highcharts') . '/js/highcharts.js', 'module', 'footer'); // Flag common JS loaded status. $js_added = TRUE; } // Generate a unique chart ID. $chart_id = 'highcharts_' . uniqid(); // Pass this chart ID by reference to the options object. $options->chart->renderTo = $chart_id; // Add Drupal.settings for this chart. drupal_add_js(array('highcharts' => array($chart_id => $options)), 'setting'); // Add highchart options object methods, which can't be passed through // Drupal.settings. // @todo check for all possible highchart options object callbacks. $formatter = $options->tooltip->formatter; if ($formatter) { drupal_add_js("Drupal.settings.highcharts.{$chart_id}.tooltip.formatter = $formatter", 'inline', 'header', 'FALSE', 'FALSE', FALSE); } }