function chart_unique_color in Google Chart Tools: Image Charts 5
Same name and namespace in other branches
- 6 chart.module \chart_unique_color()
- 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
1 call to chart_unique_color()
- system_charts_build in contrib/
system_charts/ system_charts.module - Gather data and build a chart API structure.
File
- ./
chart.module, line 1081 - Google Charting API. Developed by Tj Holowaychuk
Code
function chart_unique_color($content_id, $scheme = 'default') {
static $colors_used;
$colors = _chart_color_schemes();
if (count($colors[$scheme])) {
$colors['default'];
}
// Associative color is available
if (isset($colors[$scheme][$content_id])) {
return $colors[$scheme][$content_id];
}
elseif ($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';
}