Browse Source

Fix ticks after hide and show when axis.x.tick.fit = false - #638

pull/681/head
Masayuki Tanaka 10 years ago
parent
commit
c0f5426be1
  1. 9
      c3.js
  2. 2
      c3.min.js
  3. 110
      spec/axis-spec.js
  4. 9
      src/core.js

9
c3.js

@ -463,9 +463,12 @@
if (targetsToShow.length) { if (targetsToShow.length) {
$$.updateXDomain(targetsToShow, withUpdateXDomain, withUpdateOrgXDomain, withTrimXDomain); $$.updateXDomain(targetsToShow, withUpdateXDomain, withUpdateOrgXDomain, withTrimXDomain);
// update axis tick values according to options if (!config.axis_x_tick_values) {
if (!config.axis_x_tick_values && (config.axis_x_tick_fit || config.axis_x_tick_count)) { if (config.axis_x_tick_fit || config.axis_x_tick_count) {
tickValues = $$.generateTickValues($$.mapTargetsToUniqueXs(targetsToShow), config.axis_x_tick_count, $$.isTimeSeries()); tickValues = $$.generateTickValues($$.mapTargetsToUniqueXs(targetsToShow), config.axis_x_tick_count, $$.isTimeSeries());
} else {
tickValues = undefined;
}
$$.xAxis.tickValues(tickValues); $$.xAxis.tickValues(tickValues);
$$.subXAxis.tickValues(tickValues); $$.subXAxis.tickValues(tickValues);
} }

2
c3.min.js vendored

File diff suppressed because one or more lines are too long

110
spec/axis-spec.js

@ -46,7 +46,7 @@ describe('c3 chart axis', function () {
done(); done();
}, 10); }, 10);
}); });
/*
describe('axis.y.tick.count', function () { describe('axis.y.tick.count', function () {
var i = 1; var i = 1;
@ -487,4 +487,112 @@ describe('c3 chart axis', function () {
}); });
*/
describe('axis.x.tick.fit', function () {
describe('axis.x.tick.fit = true', function () {
it('should set args for indexed data', function () {
args = {
data: {
columns: [
['data1', 30, 200, 100, 400, 150, 250],
['data2', 50, 20, 10, 40, 15, 25],
['data3', 150, 120, 110, 140, 115, 125]
]
}
};
expect(true).toBeTruthy();
});
it('should show fitted ticks on indexed data', function () {
var ticks = chart.internal.main.selectAll('.c3-axis-x g.tick');
expect(ticks.size()).toBe(6);
});
it('should set args for x-based data', function () {
args = {
data: {
x: 'x',
columns: [
['x', 10, 20, 100, 110, 200, 1000],
['data1', 30, 200, 100, 400, 150, 250],
['data2', 50, 20, 10, 40, 15, 25],
['data3', 150, 120, 110, 140, 115, 125]
]
}
};
expect(true).toBeTruthy();
});
it('should show fitted ticks on indexed data', function () {
var ticks = chart.internal.main.selectAll('.c3-axis-x g.tick');
expect(ticks.size()).toBe(6);
});
it('should show fitted ticks after hide and show', function () {
chart.hide();
chart.show();
var ticks = chart.internal.main.selectAll('.c3-axis-x g.tick');
expect(ticks.size()).toBe(6);
});
});
describe('axis.x.tick.fit = false', function () {
it('should set args for indexed data', function () {
args = {
data: {
columns: [
['data1', 30, 200, 100, 400, 150, 250],
['data2', 50, 20, 10, 40, 15, 25],
['data3', 150, 120, 110, 140, 115, 125]
]
},
axis: {
x: {
tick: {
fit: false
}
}
}
};
expect(true).toBeTruthy();
});
it('should show fitted ticks on indexed data', function () {
var ticks = chart.internal.main.selectAll('.c3-axis-x g.tick');
expect(ticks.size()).toBe(11);
});
it('should set args for x-based data', function () {
args.data = {
x: 'x',
columns: [
['x', 10, 20, 100, 110, 200, 1000],
['data1', 30, 200, 100, 400, 150, 250],
['data2', 50, 20, 10, 40, 15, 25],
['data3', 150, 120, 110, 140, 115, 125]
]
};
expect(true).toBeTruthy();
});
it('should show fitted ticks on indexed data', function () {
var ticks = chart.internal.main.selectAll('.c3-axis-x g.tick');
expect(ticks.size()).toBe(10);
});
it('should show fitted ticks after hide and show', function () {
chart.hide();
chart.show();
var ticks = chart.internal.main.selectAll('.c3-axis-x g.tick');
expect(ticks.size()).toBe(10);
});
});
});
}); });

9
src/core.js

@ -458,9 +458,12 @@ c3_chart_internal_fn.redraw = function (options, transitions) {
if (targetsToShow.length) { if (targetsToShow.length) {
$$.updateXDomain(targetsToShow, withUpdateXDomain, withUpdateOrgXDomain, withTrimXDomain); $$.updateXDomain(targetsToShow, withUpdateXDomain, withUpdateOrgXDomain, withTrimXDomain);
// update axis tick values according to options if (!config.axis_x_tick_values) {
if (!config.axis_x_tick_values && (config.axis_x_tick_fit || config.axis_x_tick_count)) { if (config.axis_x_tick_fit || config.axis_x_tick_count) {
tickValues = $$.generateTickValues($$.mapTargetsToUniqueXs(targetsToShow), config.axis_x_tick_count, $$.isTimeSeries()); tickValues = $$.generateTickValues($$.mapTargetsToUniqueXs(targetsToShow), config.axis_x_tick_count, $$.isTimeSeries());
} else {
tickValues = undefined;
}
$$.xAxis.tickValues(tickValues); $$.xAxis.tickValues(tickValues);
$$.subXAxis.tickValues(tickValues); $$.subXAxis.tickValues(tickValues);
} }

Loading…
Cancel
Save