Commit 319626fb authored by Evgeny's avatar Evgeny

Add width and height functions

parent 82ec630c
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("width", function(){
it("should get width when no arguments given", function(done){
// Just some unusual number
chart.resize({ width: 1087, height: 1087 });
wait(function(){
expect(chart.width()).toBe(1087);
done();
});
});
it("should set width", function(done){
chart.width(1087);
wait(function(){
expect(chart.width()).toBe(1087);
done();
});
});
});
describe("height", function(){
it("should get height when no arguments given", function(done){
// Just some unusual number
chart.resize({ width: 1087, height: 1087 });
wait(function(){
expect(chart.height()).toBe(1087);
done();
});
});
it("should set height", function(done){
chart.height(1087);
wait(function(){
expect(chart.height()).toBe(1087);
done();
});
});
});
});
......@@ -45,3 +45,9 @@ function initChart(chart, args, done) {
return chart;
}
typeof initChart !== 'undefined';
function wait(f){
setTimeout(f, 500);
}
typeof wait !== 'undefined';
......@@ -5,6 +5,24 @@ c3_chart_fn.resize = function (size) {
this.flush();
};
c3_chart_fn.width = function(width){
var $$ = this.internal;
if(isUndefined(width)){
return $$.getCurrentWidth();
}
$$.config.size_width = width;
this.flush();
};
c3_chart_fn.height = function(height){
var $$ = this.internal;
if(isUndefined(height)){
return $$.getCurrentHeight();
}
$$.config.size_height = height;
this.flush();
};
c3_chart_fn.flush = function () {
var $$ = this.internal;
$$.updateAndRedraw({withLegend: true, withTransition: false, withTransitionForTransform: false});
......
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