getPixelForValue: function(value, index, datasetIndex, includeOffset) {
var pixel;
- var newVal = +this.getRightValue(value);
- var range = helpers.log10(this.end) - helpers.log10(this.start);
+ var newVal = +this.getRightValue(value)
+; var range = helpers.log10(this.end) - helpers.log10(this.start);
if (this.isHorizontal()) {
},
getValueForPixel: function(pixel) {
var offset;
+ var range = helpers.log10(this.end) - helpers.log10(this.start);
+ var value;
- if (this.isHorizontal) {
+ if (this.isHorizontal()) {
var innerWidth = this.width - (this.paddingLeft + this.paddingRight);
+ value = this.start * Math.pow(10, (pixel - this.left - this.paddingLeft) * range / innerWidth);
} else {
var innerHeight = this.height - (this.paddingTop + this.paddingBottom);
+ value = Math.pow(10, (this.bottom - this.paddingBottom - pixel) * range / innerHeight) / this.start;
}
+ return value;
}
});
}
},
getValueForPixel: function(pixel) {
- var offset = pixel - (this.isHorizontal() ? this.left + this.paddingLeft : this.top + this.paddingTop);
+ var innerDimension = this.isHorizontal() ? this.width - (this.paddingLeft + this.paddingRight) : this.height - (this.paddingTop + this.paddingBottom);
+ var offset = (pixel - (this.isHorizontal() ? this.left + this.paddingLeft : this.top + this.paddingTop)) / innerDimension;
offset *= this.scaleSizeInUnits;
return this.firstTick.clone().add(offset, this.tickUnit);
},
};
}
};
+ },
+ toBeCloseToTime: function() {
+ return {
+ compare: function(actual, expected) {
+ var result = false;
+
+ var diff = actual.diff(expected.value, expected.unit, true);
+ result = Math.abs(diff) < 0.25;
+
+ return {
+ pass: result
+ };
+ }
+ }
}
});
});
scale.bottom = 38;
expect(scale.getPixelForValue('', 0, 0)).toBe(81);
- expect(scale.getValueForPixel(81)).toEqual(scale.firstTick);
+ expect(scale.getValueForPixel(81)).toBeCloseToTime({
+ value: moment(mockData.labels[0]),
+ unit: 'hour'
+ });
expect(scale.getPixelForValue('', 6, 0)).toBe(323);
- expect(scale.getValueForPixel(323)).toEqual(scale.lastTick);
+ expect(scale.getValueForPixel(323)).toBeCloseToTime({
+ value: moment(mockData.labels[6]),
+ unit: 'hour'
+ });
var verticalScaleConfig = Chart.helpers.clone(Chart.scaleService.getScaleDefaults('time'));
verticalScaleConfig.position = "left";
verticalScale.bottom = 400;
expect(verticalScale.getPixelForValue('', 0, 0)).toBe(38);
- expect(verticalScale.getValueForPixel(38)).toEqual(verticalScale.firstTick);
+ expect(verticalScale.getValueForPixel(38)).toBeCloseToTime({
+ value: moment(mockData.labels[0]),
+ unit: 'hour'
+ });
expect(verticalScale.getPixelForValue('', 6, 0)).toBe(375);
- expect(verticalScale.getValueForPixel(375)).toEqual(verticalScale.lastTick);
+ expect(verticalScale.getValueForPixel(375)).toBeCloseToTime({
+ value: moment(mockData.labels[6]),
+ unit: 'hour'
+ });
});
it('should get the correct label for a data value', function() {