Skip to content

Commit

Permalink
Minor cleanup (#6362)
Browse files Browse the repository at this point in the history
  • Loading branch information
benmccann authored and etimberg committed Aug 13, 2019
1 parent 053729a commit 4093483
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 18 deletions.
12 changes: 4 additions & 8 deletions src/controllers/controller.bar.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,13 @@ defaults._set('bar', {
*/
function computeMinSampleSize(scale, pixels) {
var min = scale._length;
var ticks = scale.getTicks();
var prev, curr, i, ilen;

for (i = 1, ilen = pixels.length; i < ilen; ++i) {
min = Math.min(min, Math.abs(pixels[i] - pixels[i - 1]));
}

for (i = 0, ilen = ticks.length; i < ilen; ++i) {
for (i = 0, ilen = scale.getTicks().length; i < ilen; ++i) {
curr = scale.getPixelForTick(i);
min = i > 0 ? Math.min(min, Math.abs(curr - prev)) : min;
prev = curr;
Expand Down Expand Up @@ -260,13 +259,11 @@ module.exports = DatasetController.extend({
getRuler: function() {
var me = this;
var scale = me._getIndexScale();
var stackCount = me.getStackCount();
var datasetIndex = me.index;
var pixels = [];
var i, ilen, min;

for (i = 0, ilen = me.getMeta().data.length; i < ilen; ++i) {
pixels.push(scale.getPixelForValue(null, i, datasetIndex));
pixels.push(scale.getPixelForValue(null, i, me.index));
}

min = helpers.isNullOrUndef(scale.options.barThickness)
Expand All @@ -278,7 +275,7 @@ module.exports = DatasetController.extend({
pixels: pixels,
start: scale._startPixel,
end: scale._endPixel,
stackCount: stackCount,
stackCount: me.getStackCount(),
scale: scale
};
},
Expand All @@ -290,14 +287,13 @@ module.exports = DatasetController.extend({
calculateBarValuePixels: function(datasetIndex, index) {
var me = this;
var chart = me.chart;
var meta = me.getMeta();
var scale = me._getValueScale();
var isHorizontal = scale.isHorizontal();
var datasets = chart.data.datasets;
var value = scale._parseValue(datasets[datasetIndex].data[index]);
var minBarLength = scale.options.minBarLength;
var stacked = scale.options.stacked;
var stack = meta.stack;
var stack = me.getMeta().stack;
var start = value.start === undefined ? 0 : value.max >= 0 && value.min >= 0 ? value.min : value.max;
var length = value.start === undefined ? value.end : value.max >= 0 && value.min >= 0 ? value.max - value.min : value.min - value.max;
var i, imeta, ivalue, base, head, size, stackLength;
Expand Down
17 changes: 8 additions & 9 deletions src/core/core.scale.js
Original file line number Diff line number Diff line change
Expand Up @@ -456,13 +456,13 @@ var Scale = Element.extend({
var me = this;
var options = me.options;
var tickOpts = options.ticks;
var ticks = me.getTicks();
var numTicks = me.getTicks().length;
var minRotation = tickOpts.minRotation || 0;
var maxRotation = tickOpts.maxRotation;
var labelRotation = minRotation;
var labelSizes, maxLabelWidth, maxLabelHeight, maxWidth, tickWidth, maxHeight, maxLabelDiagonal;

if (!me._isVisible() || !tickOpts.display || minRotation >= maxRotation || ticks.length <= 1 || !me.isHorizontal()) {
if (!me._isVisible() || !tickOpts.display || minRotation >= maxRotation || numTicks <= 1 || !me.isHorizontal()) {
me.labelRotation = minRotation;
return;
}
Expand All @@ -474,11 +474,11 @@ var Scale = Element.extend({
// Estimate the width of each grid based on the canvas width, the maximum
// label width and the number of tick intervals
maxWidth = Math.min(me.maxWidth, me.chart.width - maxLabelWidth);
tickWidth = options.offset ? me.maxWidth / ticks.length : maxWidth / (ticks.length - 1);
tickWidth = options.offset ? me.maxWidth / numTicks : maxWidth / (numTicks - 1);

// Allow 3 pixels x2 padding either side for label readability
if (maxLabelWidth + 6 > tickWidth) {
tickWidth = maxWidth / (ticks.length - (options.offset ? 0.5 : 1));
tickWidth = maxWidth / (numTicks - (options.offset ? 0.5 : 1));
maxHeight = me.maxHeight - getTickMarkLength(options.gridLines)
- tickOpts.padding - getScaleLabelHeight(options.scaleLabel);
maxLabelDiagonal = Math.sqrt(maxLabelWidth * maxLabelWidth + maxLabelHeight * maxLabelHeight);
Expand Down Expand Up @@ -508,13 +508,12 @@ var Scale = Element.extend({
height: 0
};

var ticks = me.getTicks();
var opts = me.options;
var tickOpts = opts.ticks;
var scaleLabelOpts = opts.scaleLabel;
var gridLineOpts = opts.gridLines;
var display = me._isVisible();
var position = opts.position;
var isBottom = opts.position === 'bottom';
var isHorizontal = me.isHorizontal();

// Width
Expand Down Expand Up @@ -556,16 +555,16 @@ var Scale = Element.extend({
minSize.height = Math.min(me.maxHeight, minSize.height + labelHeight + tickPadding);

var offsetLeft = me.getPixelForTick(0) - me.left;
var offsetRight = me.right - me.getPixelForTick(ticks.length - 1);
var offsetRight = me.right - me.getPixelForTick(me.getTicks().length - 1);
var paddingLeft, paddingRight;

// Ensure that our ticks are always inside the canvas. When rotated, ticks are right aligned
// which means that the right padding is dominated by the font height
if (isRotated) {
paddingLeft = position === 'bottom' ?
paddingLeft = isBottom ?
cosRotation * firstLabelSize.width + sinRotation * firstLabelSize.offset :
sinRotation * (firstLabelSize.height - firstLabelSize.offset);
paddingRight = position === 'bottom' ?
paddingRight = isBottom ?
sinRotation * (lastLabelSize.height - lastLabelSize.offset) :
cosRotation * lastLabelSize.width + sinRotation * lastLabelSize.offset;
} else {
Expand Down
2 changes: 1 addition & 1 deletion src/scales/scale.category.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ module.exports = Scale.extend({
return me.getRightValue(chart.data.datasets[datasetIndex].data[index]);
}

return me.ticks[index - me.minIndex];
return me._getLabels()[index];
},

_configure: function() {
Expand Down

0 comments on commit 4093483

Please sign in to comment.