Skip to content

Commit

Permalink
Merge with border-time-axis-ticks branch.
Browse files Browse the repository at this point in the history
  • Loading branch information
andrew.hurskiy committed May 22, 2017
2 parents 7647661 + 76a3d19 commit 0e0c643
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 14 deletions.
20 changes: 7 additions & 13 deletions src/scales/scale.time.js
Expand Up @@ -184,10 +184,7 @@ module.exports = function(Chart) {
var startFraction = startRange % (interval[options.unit].size * stepSize);
var alignedTick = startTick;
ticks.push(startTick);
if (startTick !== alignedTick + startFraction &&
options.majorUnit &&
!options.timeOpts.round &&
!options.timeOpts.isoWeekday) {
if (startTick !== alignedTick + startFraction && options.majorUnit && !options.timeOpts.round && !options.timeOpts.isoWeekday) {
alignedTick += startFraction;
ticks.push(alignedTick);
}
Expand All @@ -212,7 +209,7 @@ module.exports = function(Chart) {
Chart.Ticks.generators.time = function(options, dataRange) {
var niceMin;
var niceMax;
var isoWeekday = options.isoWeekday;
var isoWeekday = options.timeOpts.isoWeekday;
if (options.unit === 'week' && isoWeekday !== false) {
niceMin = moment(dataRange.min).startOf('isoWeek').isoWeekday(isoWeekday).valueOf();
niceMax = moment(dataRange.max).startOf('isoWeek').isoWeekday(isoWeekday);
Expand Down Expand Up @@ -338,7 +335,7 @@ module.exports = function(Chart) {
}

me.displayFormat = timeOpts.displayFormats[unit];
me.seniorDisplayFormat = timeOpts.displayFormats[majorUnit];
me.majorDisplayFormat = timeOpts.displayFormats[majorUnit];
me.unit = unit;
me.majorUnit = majorUnit;

Expand All @@ -351,8 +348,7 @@ module.exports = function(Chart) {
stepSize: stepSize,
majorUnit: majorUnit,
unit: unit,
timeOpts: timeOpts,
isoWeekday: timeOpts.isoWeekday
timeOpts: timeOpts
}, {
min: dataMin,
max: dataMax
Expand Down Expand Up @@ -384,11 +380,9 @@ module.exports = function(Chart) {
tickFormatFunction: function(tick, index, ticks) {
var formattedTick;
var tickClone = tick.clone();
if (this.majorUnit &&
this.seniorDisplayFormat &&
tick.valueOf() === tickClone.startOf(this.majorUnit).valueOf()) {
// format as senior unit
formattedTick = tick.format(this.seniorDisplayFormat);
if (this.majorUnit && this.majorDisplayFormat && tick.valueOf() === tickClone.startOf(this.majorUnit).valueOf()) {
// format as major unit
formattedTick = tick.format(this.majorDisplayFormat);
} else {
// format as base unit
formattedTick = tick.format(this.displayFormat);
Expand Down
2 changes: 1 addition & 1 deletion test/specs/scale.time.tests.js
Expand Up @@ -232,6 +232,7 @@ describe('Time scale tests', function() {

var scale = createScale(mockData, config);
scale.update(2500, 200);

expect(scale.ticks).toEqual(['8PM', '9PM', '10PM', '11PM', 'Jan 2', '1AM', '2AM', '3AM', '4AM', '5AM', '6AM', '7AM', '8AM', '9AM', '10AM', '11AM', '12PM', '1PM', '2PM', '3PM', '4PM', '5PM', '6PM', '7PM', '8PM', '9PM']);
});

Expand Down Expand Up @@ -467,7 +468,6 @@ describe('Time scale tests', function() {
var pixel = xScale.getPixelForValue('', 0, 0);

expect(xScale.getValueForPixel(pixel).valueOf()).toEqual(moment(chart.data.labels[0]).valueOf());

});

it('does not create a negative width chart when hidden', function() {
Expand Down

0 comments on commit 0e0c643

Please sign in to comment.