Skip to content

Commit

Permalink
Add API for showing and hidding axis. Fixes c3js#1520
Browse files Browse the repository at this point in the history
  • Loading branch information
missingdays committed Jul 8, 2016
1 parent f7f99e0 commit f0971db
Show file tree
Hide file tree
Showing 3 changed files with 133 additions and 1 deletion.
102 changes: 102 additions & 0 deletions spec/api.axis-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,106 @@ describe('c3 api axis', function () {
});

});

describe('isShown', function(){
it('should get value', function(){
args = {
data: {
columns: [
['data1', 30, 200, 100],
['data2', 50, 20, 10]
],
},
axis: {
x: {
show: true
},
y: {
show: true,
}
}
};

chart = window.initChart(chart, args);

expect(chart.axis.isXShown()).toBe(true);
expect(chart.axis.isYShown()).toBe(true);

args.axis.x.show = false;
args.axis.y.show = false;

chart = window.initChart(chart, args);

expect(chart.axis.isXShown()).toBe(false);
expect(chart.axis.isYShown()).toBe(false);

});

it('should set value', function(){
chart.axis.isXShown(true);

expect(chart.axis.isXShown()).toBe(true);
expect(chart.axis.isYShown()).toBe(false);

chart.axis.isYShown(true);

expect(chart.axis.isXShown()).toBe(true);
expect(chart.axis.isYShown()).toBe(true);

chart.axis.isXShown(false);

expect(chart.axis.isXShown()).toBe(false);
expect(chart.axis.isYShown()).toBe(true);

chart.axis.isYShown(false);

expect(chart.axis.isXShown()).toBe(false);
expect(chart.axis.isYShown()).toBe(false);
});

it('should actualy show and hide axis', function(){
function check(axis, prop){
expect(d3.select('.c3-axis-' + axis).style('visibility')).toBe(prop);
}

args = {
data: {
columns: [
['data1', 30, 200, 100],
['data2', 50, 20, 10]
],
},
axis: {
x: {
show: true
},
y: {
show: true,
}
}
};

chart = window.initChart(chart, args);

chart.axis.isXShown(false);

check('x', 'hidden');
check('y', 'visible');

chart.axis.isYShown(false);

check('x', 'hidden');
check('y', 'hidden');

chart.axis.isXShown(true);

check('x', 'visible');
check('y', 'hidden');

chart.axis.isYShown(true);

check('x', 'visible');
check('y', 'visible');
});
});
});
4 changes: 3 additions & 1 deletion spec/c3-helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ function initChart(chart, args, done) {
}

window.setTimeout(function () {
done();
if(done){
done();
}
}, 10);

return chart;
Expand Down
28 changes: 28 additions & 0 deletions src/api.axis.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,31 @@ c3_chart_fn.axis.range = function (range) {
};
}
};

c3_chart_fn.axis.isXShown = function(value){
var $$ = this.internal;

if(value === undefined){
return $$.config.axis_x_show;
}

$$.config.axis_x_show = !!value;
$$.axes.x.style("visibility", $$.config.axis_x_show ? 'visible' : 'hidden');

$$.redraw();
};

c3_chart_fn.axis.isYShown = function(value){
var $$ = this.internal;

if(value === undefined){
return $$.config.axis_y_show;
}

$$.config.axis_y_show = !!value;
$$.axes.y.style("visibility", $$.config.axis_y_show ? 'visible' : 'hidden');

$$.redraw();
};


0 comments on commit f0971db

Please sign in to comment.