Commit d56a4039 authored by Evgeny's avatar Evgeny

Add colorPattern updater

parent 75082c29
......@@ -6058,7 +6058,6 @@
else {
if (ids.indexOf(id) < 0) { ids.push(id); }
color = pattern[ids.indexOf(id) % pattern.length];
colors[id] = color;
}
return callback instanceof Function ? callback(color, d) : color;
};
......@@ -7646,6 +7645,18 @@
return $$.color(id); // more patterns
};
c3_chart_fn.colorPattern = function(pattern){
var $$ = this.internal;
if(!pattern){
return $$.config.color_pattern;
}
$$.config.color_pattern = pattern;
$$.color = $$.generateColor();
};
c3_chart_fn.x = function (x) {
var $$ = this.internal;
if (arguments.length) {
......
describe("c3 chart", function(){
'use strict';
var chart;
var args = {
data: {
columns: [
['data1', 30, 200, 100, 400, 150, 250],
['data2', 5000, 2000, 1000, 4000, 1500, 2500]
]
}
};
beforeEach(function (done) {
chart = window.initChart(chart, args, done);
});
describe("colorPattern", function(){
it("should update pattern", function(){
chart.colorPattern(['#fff', '#000', '#fff', '#fff']);
expect(chart.color("data1")).toBe("#fff");
expect(chart.color("data2")).toBe("#000");
});
});
});
......@@ -3,3 +3,15 @@ c3_chart_fn.color = function (id) {
var $$ = this.internal;
return $$.color(id); // more patterns
};
c3_chart_fn.colorPattern = function(pattern){
var $$ = this.internal;
if(!pattern){
return $$.config.color_pattern;
}
$$.config.color_pattern = pattern;
$$.color = $$.generateColor();
};
......@@ -20,7 +20,6 @@ c3_chart_internal_fn.generateColor = function () {
else {
if (ids.indexOf(id) < 0) { ids.push(id); }
color = pattern[ids.indexOf(id) % pattern.length];
colors[id] = color;
}
return callback instanceof Function ? callback(color, d) : color;
};
......
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