diff --git a/spec/api.axis-spec.js b/spec/api.axis-spec.js index 5764f7383..858f8d9ae 100644 --- a/spec/api.axis-spec.js +++ b/spec/api.axis-spec.js @@ -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'); + }); + }); }); diff --git a/spec/c3-helper.js b/spec/c3-helper.js index 970cd1b7c..6f84a346c 100644 --- a/spec/c3-helper.js +++ b/spec/c3-helper.js @@ -39,7 +39,9 @@ function initChart(chart, args, done) { } window.setTimeout(function () { - done(); + if(done){ + done(); + } }, 10); return chart; diff --git a/src/api.axis.js b/src/api.axis.js index 281a7bb1e..7c7d68679 100644 --- a/src/api.axis.js +++ b/src/api.axis.js @@ -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(); +}; + +