Skip to content

Commit

Permalink
review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
kurkle committed Jun 19, 2019
1 parent 97f819d commit 41d9be3
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 15 deletions.
14 changes: 6 additions & 8 deletions src/core/core.scale.js
Expand Up @@ -70,9 +70,7 @@ function getPixelForGridLine(scale, index, offsetGridLines) {

if (offsetGridLines) {
if (scale.getTicks().length === 1) {
lineValue -= scale.isHorizontal() ?
Math.max(lineValue - scale.left, scale.right - lineValue) :
Math.max(lineValue - scale.top, scale.bottom - lineValue);
lineValue -= Math.max(lineValue - scale._start, scale._end - lineValue);
} else if (index === 0) {
lineValue -= (scale.getPixelForTick(1) - lineValue) / 2;
} else {
Expand Down Expand Up @@ -454,7 +452,7 @@ var Scale = Element.extend({

// 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 / (ticks.length - (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 @@ -700,8 +698,8 @@ var Scale = Element.extend({
getPixelForTick: function(index) {
var me = this;
var offset = me.options.offset;
var tickWidth = 1 / Math.max((me._ticks.length - offset ? 0 : 1), 1);
var decimal = index * tickWidth + offset ? tickWidth / 2 : 0;
var tickWidth = 1 / Math.max(me._ticks.length - (offset ? 0 : 1), 1);
var decimal = index * tickWidth + (offset ? tickWidth / 2 : 0);
return me.getPixelForDecimal(decimal);
},

Expand Down Expand Up @@ -1134,7 +1132,7 @@ var Scale = Element.extend({
var scaleLabelX, scaleLabelY;

if (me.isHorizontal()) {
scaleLabelX = me.left + ((me.right - me.left) / 2); // midpoint of the width
scaleLabelX = me.left + me.width / 2; // midpoint of the width
scaleLabelY = position === 'bottom'
? me.bottom - halfLineHeight - scaleLabelPadding.bottom
: me.top + halfLineHeight + scaleLabelPadding.top;
Expand All @@ -1143,7 +1141,7 @@ var Scale = Element.extend({
scaleLabelX = isLeft
? me.left + halfLineHeight + scaleLabelPadding.top
: me.right - halfLineHeight - scaleLabelPadding.top;
scaleLabelY = me.top + ((me.bottom - me.top) / 2);
scaleLabelY = me.top + me.height / 2;
rotation = isLeft ? -0.5 * Math.PI : 0.5 * Math.PI;
}

Expand Down
12 changes: 5 additions & 7 deletions src/scales/scale.category.js
Expand Up @@ -67,12 +67,9 @@ module.exports = Scale.extend({
var me = this;
var offset = me.options.offset;

// 1 is added because we need the length but we have the indexes
var range = Math.max(me.maxIndex + 1 - me.minIndex - (offset ? 0 : 1), 1);
var start = me.minIndex - (offset ? 0.5 : 0);
return {
start: start,
range: range
start: me.minIndex - (offset ? 0.5 : 0),
range: Math.max(me.ticks.length - (offset ? 0 : 1), 1)
};
},

Expand All @@ -88,7 +85,7 @@ module.exports = Scale.extend({

// If value is a data object, then index is the index in the data array,
// not the index of the scale. We need to change that.
if (!helpers.isNullOrUndef(value)) {
if (!isNullOrUndef(value)) {
valueCategory = me.isHorizontal() ? value.x : value.y;
}
if (valueCategory !== undefined || (value !== undefined && isNaN(index))) {
Expand All @@ -114,7 +111,8 @@ module.exports = Scale.extend({
getValueForPixel: function(pixel) {
var me = this;
var params = me._getParams();
return Math.round(params.start + me.getDecimalForPixel(pixel) * params.range);
var value = Math.round(params.start + me.getDecimalForPixel(pixel) * params.range);
return Math.min(Math.max(value, 0), me.ticks.length - 1);
},

getBasePixel: function() {
Expand Down

0 comments on commit 41d9be3

Please sign in to comment.