Skip to content

Commit

Permalink
AutoSkip in update
Browse files Browse the repository at this point in the history
  • Loading branch information
benmccann committed Jun 24, 2019
1 parent 1c85700 commit 90b7a47
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 12 deletions.
36 changes: 26 additions & 10 deletions src/core/core.scale.js
Expand Up @@ -240,8 +240,17 @@ var Scale = Element.extend({
helpers.callback(this.options.beforeUpdate, [this]);
},

/**
* @param {number} maxWidth - the max width in pixels
* @param {number} maxHeight - the max height in pixels
* @param {object} margins - the space between the edge of the scale and edge of the chart
* This space comes from two sources:
* - padding - space that's required to show the labels at the edges of the scale
* - thickness of scales or legends in another orientation
*/
update: function(maxWidth, maxHeight, margins) {
var me = this;
var optionTicks = me.options.ticks;
var i, ilen, labels, label, ticks, tick;

// Update Lifecycle - Probably don't want to ever extend or overwrite this function ;)
Expand Down Expand Up @@ -325,9 +334,12 @@ var Scale = Element.extend({
me.beforeFit();
me.fit();
me.afterFit();
//
// Auto-skip
me._ticks = optionTicks.display && optionTicks.autoSkip ? me._autoSkip(me.getTicks()) : me.getTicks();

me.afterUpdate();

// TODO: remove minSize as a public property and return value from all layout boxes. It is unused
return me.minSize;

},
Expand Down Expand Up @@ -465,6 +477,7 @@ var Scale = Element.extend({
height: 0
};

var chart = me.chart;
var ticks = me.getTicks();
var opts = me.options;
var tickOpts = opts.ticks;
Expand Down Expand Up @@ -553,8 +566,13 @@ var Scale = Element.extend({

me.handleMargins();

me.width = minSize.width;
me.height = minSize.height;
if (isHorizontal) {
me.width = chart.width - me.margins.left - me.margins.right;
me.height = minSize.height;
} else {
me.width = minSize.width;
me.height = chart.height - me.margins.top - me.margins.bottom;
}
},

/**
Expand All @@ -563,12 +581,10 @@ var Scale = Element.extend({
*/
handleMargins: function() {
var me = this;
if (me.margins) {
me.margins.left = Math.max(me.paddingLeft, me.margins.left);
me.margins.top = Math.max(me.paddingTop, me.margins.top);
me.margins.right = Math.max(me.paddingRight, me.margins.right);
me.margins.bottom = Math.max(me.paddingBottom, me.margins.bottom);
}
me.margins.left = Math.max(me.paddingLeft, me.margins.left);
me.margins.top = Math.max(me.paddingTop, me.margins.top);
me.margins.right = Math.max(me.paddingRight, me.margins.right);
me.margins.bottom = Math.max(me.paddingBottom, me.margins.bottom);
},

afterFit: function() {
Expand Down Expand Up @@ -834,7 +850,7 @@ var Scale = Element.extend({
var isMirrored = optionTicks.mirror;
var isHorizontal = me.isHorizontal();

var ticks = optionTicks.display && optionTicks.autoSkip ? me._autoSkip(me.getTicks()) : me.getTicks();
var ticks = me.getTicks();
var tickFonts = parseTickFontOptions(optionTicks);
var tickPadding = optionTicks.padding;
var labelOffset = optionTicks.labelOffset;
Expand Down
3 changes: 1 addition & 2 deletions test/specs/scale.time.tests.js
Expand Up @@ -600,10 +600,9 @@ describe('Time scale tests', function() {
}],
}
}
});
}, {canvas: {width: 800, height: 200}});

this.scale = this.chart.scales.xScale0;
this.scale.update(800, 200);
});

it('should be bounded by nearest step\'s year start and end', function() {
Expand Down

0 comments on commit 90b7a47

Please sign in to comment.