function chart_unique_color in Google Chart Tools: Image Charts 7
Same name and namespace in other branches
- 5 chart.module \chart_unique_color()
- 6 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/
views/ chart_views_plugin_style_chart.inc - Render the display in this style.
- system_charts_build in system_charts/
system_charts.module - Gather data and build a chart API structure.
File
- ./
chart.module, line 1302 - Provides primary Drupal hook implementations.
Code
function chart_unique_color($content_id, $scheme = 'default') {
$colors_used =& drupal_static(__FUNCTION__);
$colors = chart_color_schemes();
// Revert to default color schema if $scheme has not been registered.
if (!isset($colors[$scheme])) {
$scheme = 'default';
}
// This content_id has already been color-mapped
if (isset($colors_used[$scheme][$content_id])) {
return $colors_used[$scheme][$content_id];
}
// Specific associative color is available
if (isset($colors[$scheme][$content_id])) {
return $colors_used[$scheme][$content_id] = $colors[$scheme][$content_id];
}
// Map first unused color from color scheme
if (isset($colors_used[$scheme])) {
$available_colors = array_diff($colors[$scheme], $colors_used[$scheme]);
return $colors_used[$scheme][$content_id] = array_shift($available_colors);
}
else {
return $colors_used[$scheme][$content_id] = array_shift($colors[$scheme]);
}
return '000000';
}