Skip to content

Commit

Permalink
Remove check for label values for offset calculation
Browse files Browse the repository at this point in the history
  • Loading branch information
nagix committed Aug 29, 2017
1 parent 7eabbf0 commit afa314e
Showing 1 changed file with 7 additions and 16 deletions.
23 changes: 7 additions & 16 deletions src/scales/scale.time.js
Original file line number Diff line number Diff line change
Expand Up @@ -334,28 +334,19 @@ function generate(min, max, minor, major, capacity, options) {
* Returns the right and left offsets from edges in the form of {left, right}.
* Offsets are added when the `offset` option is true.
*/
function computeOffsets(table, ts, min, max, options) {
function computeOffsets(table, data, min, max, options) {
var left = 0;
var right = 0;
var timestamps = [];
var i, ilen, timestamp, length, upper, lower, divisor;

if (options.offset) {
// First, it processes `ts.labels` to pick up timestamps of labels, which are
// primarily used for offset calculation because bars are usually on labels.
// But if there are no labels, it should add offsets based on `ts.data` because
// we support bars with {x, y} data points as well. That is the second path.
[ts.labels, ts.data].forEach(function(data) {
if (!timestamps.length) {
// Remove timestamps outside the min/max range
for (i = 0, ilen = data.length; i < ilen; ++i) {
timestamp = data[i];
if (timestamp >= min && timestamp <= max) {
timestamps.push(timestamp);
}
}
for (i = 0, ilen = data.length; i < ilen; ++i) {
timestamp = data[i];
if (timestamp >= min && timestamp <= max) {
timestamps.push(timestamp);
}
});
}

length = timestamps.length;
if (length) {
Expand Down Expand Up @@ -608,7 +599,7 @@ module.exports = function(Chart) {
me._minorFormat = formats[unit];
me._majorFormat = formats[majorUnit];
me._table = buildLookupTable(me._timestamps.data, min, max, options.distribution);
me._offsets = computeOffsets(me._table, me._timestamps, min, max, options);
me._offsets = computeOffsets(me._table, me._timestamps.data, min, max, options);

return ticksFromTimestamps(ticks, majorUnit);
},
Expand Down

0 comments on commit afa314e

Please sign in to comment.