Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Load now refreshes x tick format via xtickformat parameter #1365

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,6 @@ d3.min.js
components
build
.sass-cache
.idea
.grunt
_SpecRunner.html
45 changes: 45 additions & 0 deletions spec/api.load-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,4 +118,49 @@ describe('c3 api load', function () {

});

describe('timeseries data', function(){

describe('as column', function(){

it('should update args', function () {
args = {
data: {
x: 'x',
columns: [
['x', '2013-01-01', '2013-01-02', '2013-01-03', '2013-01-04', '2013-01-05', '2013-01-06'],
['data1', 30, 200, 100, 400, 150, 250]
]
},
axis: {
x: {
type: 'timeseries',
tick: {
format: '%Y-%m-%d'
}
}
}
};
expect(true).toBeTruthy();
});

it('should update x axis format', function (done) {
var main = chart.internal.main;
setTimeout(function () {
var target = main.select('.c3-axis.c3-axis-x').select('tspan');
expect(target.text()).toBe('2013-01-01');

chart.load({
xtickformat: '%Y'
});
setTimeout(function () {
var target = main.select('.c3-axis.c3-axis-x').select('tspan');
expect(target.text()).toBe('2013');
done();
}, 500);
}, 500);

});
});
});

});
6 changes: 6 additions & 0 deletions src/api.load.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@ c3_chart_fn.load = function (args) {
config.data_colors[id] = args.colors[id];
});
}

// update x axis tick format if exists
if ('xtickformat' in args) {
config.axis_x_tick_format = args.xtickformat;
}

// use cache if exists
if ('cacheIds' in args && $$.hasCaches(args.cacheIds)) {
$$.load($$.getCaches(args.cacheIds), args.done);
Expand Down
2 changes: 1 addition & 1 deletion src/data.load.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ c3_chart_internal_fn.load = function (targets, args) {
$$.updateTargets($$.data.targets);

// Redraw with new targets
$$.redraw({withUpdateOrgXDomain: true, withUpdateXDomain: true, withLegend: true});
$$.redraw({withUpdateOrgXDomain: true, withUpdateXAxis: true, withLegend: true});

if (args.done) { args.done(); }
};
Expand Down