Chart.js/src/scales/scale.category.js

40 lines
1.3 KiB
JavaScript
Raw Normal View History

2015-06-12 22:00:48 +02:00
(function() {
"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) {
this.ticks = this.data.labels;
},
// 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);
var valueOffset = (valueWidth * index) + this.paddingLeft;
if (this.options.gridLines.offsetGridLines && includeOffset) {
valueOffset += (valueWidth / 2);
}
return this.left + Math.round(valueOffset);
} else {
return this.top + (index * (this.height / this.labels.length));
}
},
2015-09-23 03:31:26 +02:00
});
2015-09-21 01:18:59 +02:00
Chart.scaleService.registerScaleType("category", DatasetScale, defaultConfig);
2015-06-12 22:00:48 +02:00
}).call(this);