You are here

function chart_unique_color in Google Chart Tools: Image Charts 6

Same name and namespace in other branches
  1. 5 chart.module \chart_unique_color()
  2. 7 chart.module \chart_unique_color()

Supplies a unique color.

When an assoc array color scheme is provided $content_id can be used to sync the color to the data rendered. Otherwise the next available color in the stack is assigned to $content_id

Parameters

string $content_id:

string $scheme: (optional) Color scheme.

Return value

string hex RGB value

2 calls to chart_unique_color()
chart_views_plugin_style_chart::render in chart_views/includes/views/chart_views_plugin_style_chart.inc
Define and display a chart from the grouped values.
system_charts_build in contrib/system_charts/system_charts.module
Gather data and build a chart API structure.

File

./chart.module, line 1252
Provides Google chart API integration.

Code

function chart_unique_color($content_id, $scheme = 'default') {
  static $colors_used;
  $colors = _chart_color_schemes();

  // Revert to default color schema if $schema has not been registered.
  if (!isset($colors[$scheme])) {
    $scheme = 'default';
  }

  // Associative color is available
  if (isset($colors[$scheme][$content_id])) {
    return $colors[$scheme][$content_id];
  }
  elseif (isset($colors_used[$scheme][$content_id])) {
    return $colors_used[$scheme][$content_id];
  }
  else {

    // No used colors yet use the first one in the scheme
    // and map it to the content id
    if (!is_array($colors_used)) {
      $colors_used[$scheme][$content_id] = array_shift($colors[$scheme]);
      return $colors_used[$scheme][$content_id];
    }
    else {
      $available_colors = array_diff($colors[$scheme], (array) $colors_used[$scheme]);
      $colors_used[$scheme][$content_id] = array_shift($available_colors);
      return $colors_used[$scheme][$content_id];
    }
  }
  return '000000';
}