Commit 5365a741 authored by Evgeny's avatar Evgeny

Add axis.xFormat axis.yFormat API

parent 11275488
......@@ -7930,6 +7930,31 @@
};
}
};
c3_chart_fn.axis.xFormat = function(value){
var $$ = this.internal, config = $$.config;
if(value === undefined){
return config.axis_x_tick_format;
}
config.axis_x_tick_format = value;
$$.redraw();
};
c3_chart_fn.axis.yFormat = function(value){
var $$ = this.internal, config = $$.config;
if(value === undefined){
return config.axis_y_tick_format;
}
config.axis_y_tick_format = value;
$$.redraw();
};
c3_chart_fn.axisX = function (value){
var $$ = this.internal;
......@@ -8325,7 +8350,7 @@
text.style('display', function(d, i){
return shouldDrawTickText(i - indexOfZero) ? 'block' : 'none';
});
tspan = text.selectAll('tspan')
.data(function (d, i) {
var splitted = params.tickMultiline ? splitTickText(d, params.tickWidth) : [].concat(textFormatted(d));
......
This source diff could not be displayed because it is too large. You can view the blob instead.
......@@ -736,4 +736,54 @@ describe('c3 chart axis', function () {
});
describe('chart.axis.xFormat', function(){
it('should update args', function(){
args = {
data: {
columns: [
['data1', 0, 1, 2, 3]
]
},
axis: {
x: {
show: true
},
y: {
show: true
}
}
};
expect(true).toBeTruthy();
});
it('should update x format function', function(){
function format(x){
return x+10;
}
chart.axis.xFormat(format);
var tickSpans = chart.internal.main.selectAll('.c3-axis-x g.tick text tspan')[0];
for(var i = 0; i < tickSpans.length; i++){
expect(tickSpans[i].textContent).toBe('' + (i+10));
}
});
it('should update y format function', function(){
function format(x){
return x-10;
}
chart.axis.yFormat(format);
var tickSpans = chart.internal.main.selectAll('.c3-axis-y g.tick text tspan')[0];
var expected = ['-10', '-9.5', '-9', '-8.5', '-8', '-7.5', '-7'];
for(var i = 0; i < tickSpans.length; i++){
expect(tickSpans[i].textContent).toBe(expected[i]);
}
});
});
});
......@@ -58,6 +58,31 @@ c3_chart_fn.axis.range = function (range) {
};
}
};
c3_chart_fn.axis.xFormat = function(value){
var $$ = this.internal, config = $$.config;
if(value === undefined){
return config.axis_x_tick_format;
}
config.axis_x_tick_format = value;
$$.redraw();
};
c3_chart_fn.axis.yFormat = function(value){
var $$ = this.internal, config = $$.config;
if(value === undefined){
return config.axis_y_tick_format;
}
config.axis_y_tick_format = value;
$$.redraw();
};
c3_chart_fn.axisX = function (value){
var $$ = this.internal;
......
......@@ -220,7 +220,7 @@ function c3_axis(d3, params, $$) {
text.style('display', function(d, i){
return shouldDrawTickText(i - indexOfZero) ? 'block' : 'none';
});
tspan = text.selectAll('tspan')
.data(function (d, i) {
var splitted = params.tickMultiline ? splitTickText(d, params.tickWidth) : [].concat(textFormatted(d));
......
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