Browse Source

Add API for showing and hidding axis. Fixes #1520

pull/1760/head
Evgeny Bovykin 9 years ago
parent
commit
f0971dbe46
  1. 102
      spec/api.axis-spec.js
  2. 4
      spec/c3-helper.js
  3. 28
      src/api.axis.js

102
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');
});
});
});

4
spec/c3-helper.js

@ -39,7 +39,9 @@ function initChart(chart, args, done) {
}
window.setTimeout(function () {
done();
if(done){
done();
}
}, 10);
return chart;

28
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();
};

Loading…
Cancel
Save