mirror of
https://github.com/chartjs/Chart.js.git
synced 2025-12-08 20:36:08 +00:00
Apply offset regardless of min/max time scale options (#6264)
This commit is contained in:
parent
89f2e04ff0
commit
1686ce0aa7
@ -387,21 +387,17 @@ function computeOffsets(table, ticks, min, max, options) {
|
||||
var first, last;
|
||||
|
||||
if (options.offset && ticks.length) {
|
||||
if (!getMin(options)) {
|
||||
first = interpolate(table, 'time', ticks[0], 'pos');
|
||||
if (ticks.length === 1) {
|
||||
start = 1 - first;
|
||||
} else {
|
||||
start = (interpolate(table, 'time', ticks[1], 'pos') - first) / 2;
|
||||
}
|
||||
first = interpolate(table, 'time', ticks[0], 'pos');
|
||||
if (ticks.length === 1) {
|
||||
start = 1 - first;
|
||||
} else {
|
||||
start = (interpolate(table, 'time', ticks[1], 'pos') - first) / 2;
|
||||
}
|
||||
if (!getMax(options)) {
|
||||
last = interpolate(table, 'time', ticks[ticks.length - 1], 'pos');
|
||||
if (ticks.length === 1) {
|
||||
end = last;
|
||||
} else {
|
||||
end = (last - interpolate(table, 'time', ticks[ticks.length - 2], 'pos')) / 2;
|
||||
}
|
||||
last = interpolate(table, 'time', ticks[ticks.length - 1], 'pos');
|
||||
if (ticks.length === 1) {
|
||||
end = last;
|
||||
} else {
|
||||
end = (last - interpolate(table, 'time', ticks[ticks.length - 2], 'pos')) / 2;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -1456,7 +1456,7 @@ describe('Time scale tests', function() {
|
||||
expect(scale.getPixelForValue('2051')).toBeCloseToPixel(scale.left + scale.width);
|
||||
});
|
||||
|
||||
it ('should not add offset if min and max extend the labels range and offset is true', function() {
|
||||
it ('should add offset if min and max extend the labels range and offset is true', function() {
|
||||
var chart = this.chart;
|
||||
var scale = chart.scales.x;
|
||||
var options = chart.options.scales.xAxes[0];
|
||||
@ -1466,8 +1466,11 @@ describe('Time scale tests', function() {
|
||||
options.offset = true;
|
||||
chart.update();
|
||||
|
||||
expect(scale.getPixelForValue('2012')).toBeCloseToPixel(scale.left);
|
||||
expect(scale.getPixelForValue('2051')).toBeCloseToPixel(scale.left + scale.width);
|
||||
var numTicks = scale.ticks.length;
|
||||
var firstTickInterval = scale.getPixelForTick(1) - scale.getPixelForTick(0);
|
||||
var lastTickInterval = scale.getPixelForTick(numTicks - 1) - scale.getPixelForTick(numTicks - 2);
|
||||
expect(scale.getPixelForValue('2012')).toBeCloseToPixel(scale.left + firstTickInterval / 2);
|
||||
expect(scale.getPixelForValue('2051')).toBeCloseToPixel(scale.left + scale.width - lastTickInterval / 2);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user