2015-06-12 22:00:48 +02:00
|
|
|
(function() {
|
2015-08-03 21:06:40 +02:00
|
|
|
"use strict";
|
|
|
|
|
|
|
|
var root = this,
|
|
|
|
Chart = root.Chart,
|
|
|
|
helpers = Chart.helpers;
|
|
|
|
|
|
|
|
// Default config for a category scale
|
|
|
|
var defaultConfig = {
|
|
|
|
position: "bottom",
|
|
|
|
};
|
|
|
|
|
2015-09-23 03:31:26 +02:00
|
|
|
var DatasetScale = Chart.Scale.extend({
|
|
|
|
buildTicks: function(index) {
|
2015-09-24 05:52:31 +02:00
|
|
|
this.ticks = this.data.labels;
|
|
|
|
},
|
2015-08-03 21:06:40 +02:00
|
|
|
|
2015-10-18 22:13:57 +02:00
|
|
|
getLabelForIndex: function(index, datasetIndex) {
|
|
|
|
return this.ticks[index];
|
|
|
|
},
|
|
|
|
|
2015-09-24 05:52:31 +02:00
|
|
|
// Used to get data value locations. Value can either be an index or a numerical value
|
|
|
|
getPixelForValue: function(value, index, datasetIndex, includeOffset) {
|
|
|
|
if (this.isHorizontal()) {
|
|
|
|
var innerWidth = this.width - (this.paddingLeft + this.paddingRight);
|
|
|
|
var valueWidth = innerWidth / Math.max((this.data.labels.length - ((this.options.gridLines.offsetGridLines) ? 0 : 1)), 1);
|
2015-10-21 02:33:51 +02:00
|
|
|
var widthOffset = (valueWidth * index) + this.paddingLeft;
|
2015-09-24 05:52:31 +02:00
|
|
|
|
|
|
|
if (this.options.gridLines.offsetGridLines && includeOffset) {
|
2015-10-21 02:33:51 +02:00
|
|
|
widthOffset += (valueWidth / 2);
|
2015-09-24 05:52:31 +02:00
|
|
|
}
|
|
|
|
|
2015-10-21 02:33:51 +02:00
|
|
|
return this.left + Math.round(widthOffset);
|
2015-08-03 21:06:40 +02:00
|
|
|
} else {
|
2015-09-26 22:52:14 +02:00
|
|
|
var innerHeight = this.height - (this.paddingTop + this.paddingBottom);
|
|
|
|
var valueHeight = innerHeight / Math.max((this.data.labels.length - ((this.options.gridLines.offsetGridLines) ? 0 : 1)), 1);
|
2015-10-21 02:33:51 +02:00
|
|
|
var heightOffset = (valueHeight * index) + this.paddingTop;
|
2015-09-26 22:52:14 +02:00
|
|
|
|
|
|
|
if (this.options.gridLines.offsetGridLines && includeOffset) {
|
2015-10-21 02:33:51 +02:00
|
|
|
heightOffset += (valueHeight / 2);
|
2015-09-26 22:52:14 +02:00
|
|
|
}
|
|
|
|
|
2015-10-21 02:33:51 +02:00
|
|
|
return this.top + Math.round(heightOffset);
|
2015-08-03 21:06:40 +02:00
|
|
|
}
|
|
|
|
},
|
2015-09-23 03:31:26 +02:00
|
|
|
});
|
2015-09-21 01:18:59 +02:00
|
|
|
|
2015-08-03 21:06:40 +02:00
|
|
|
Chart.scaleService.registerScaleType("category", DatasetScale, defaultConfig);
|
2015-09-24 05:52:31 +02:00
|
|
|
|
2015-06-12 22:00:48 +02:00
|
|
|
}).call(this);
|