Commit 9bc8e185 authored by Masayuki Tanaka's avatar Masayuki Tanaka

Add data.color option - #127

parent 0008bae7
...@@ -129,6 +129,7 @@ ...@@ -129,6 +129,7 @@
__data_labels = getConfig(['data', 'labels'], {}), __data_labels = getConfig(['data', 'labels'], {}),
__data_order = getConfig(['data', 'order']), __data_order = getConfig(['data', 'order']),
__data_regions = getConfig(['data', 'regions'], {}), __data_regions = getConfig(['data', 'regions'], {}),
__data_color = getConfig(['data', 'color']),
__data_colors = getConfig(['data', 'colors'], {}), __data_colors = getConfig(['data', 'colors'], {}),
__data_selection_enabled = getConfig(['data', 'selection', 'enabled'], false), __data_selection_enabled = getConfig(['data', 'selection', 'enabled'], false),
__data_selection_grouped = getConfig(['data', 'selection', 'grouped'], false), __data_selection_grouped = getConfig(['data', 'selection', 'grouped'], false),
...@@ -273,7 +274,8 @@ ...@@ -273,7 +274,8 @@
var dragStart = null, dragging = false, cancelClick = false, mouseover = false; var dragStart = null, dragging = false, cancelClick = false, mouseover = false;
var color = generateColor(__data_colors, __color_pattern); var defaultColorPattern = ['#1f77b4', '#ff7f0e', '#2ca02c', '#d62728', '#9467bd', '#8c564b', '#e377c2', '#7f7f7f', '#bcbd22', '#17becf'], //same as d3.scale.category10()
color = generateColor(__data_colors, notEmpty(__color_pattern) ? __color_pattern : defaultColorPattern, __data_color);
var defaultTimeFormat = (function () { var defaultTimeFormat = (function () {
var formats = [ var formats = [
...@@ -1920,25 +1922,26 @@ ...@@ -1920,25 +1922,26 @@
//-- Color --// //-- Color --//
function generateColor(_colors, _pattern) { function generateColor(colors, pattern, callback) {
var ids = [], var ids = [];
colors = _colors,
pattern = notEmpty(_pattern) ? _pattern : ['#1f77b4', '#ff7f0e', '#2ca02c', '#d62728', '#9467bd', '#8c564b', '#e377c2', '#7f7f7f', '#bcbd22', '#17becf']; //same as d3.scale.category10()
return function (d) { return function (d) {
var id = d.id || d; var id = d.id || d, color;
// if callback function is provided // if callback function is provided
if (colors[id] instanceof Function) { return colors[id](d); } if (colors[id] instanceof Function) {
color = colors[id](d);
}
// if specified, choose that color // if specified, choose that color
if (id in colors) { return colors[id]; } else if (id in colors) {
color = colors[id];
}
// if not specified, choose from pattern // if not specified, choose from pattern
if (ids.indexOf(id) === -1) { else {
ids.push(id); if (ids.indexOf(id) < 0) { ids.push(id); }
color = pattern[ids.indexOf(id) % pattern.length];
} }
return pattern[ids.indexOf(id) % pattern.length]; return callback instanceof Function ? callback(color, d) : color;
}; };
} }
......
This source diff could not be displayed because it is too large. You can view the blob instead.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment