mirror of
https://github.com/chartjs/Chart.js.git
synced 2025-12-08 20:36:08 +00:00
`controllers.*.js` and `core.datasetController.js` are now importable (no more function export), that's why there is so many changes mainly due to one indentation level removed. Split code for `bar/horizontalBar` and `doughnut/pie` in separate files, added a global controllers import (`src/controllers/index.js`) and add tests to check that all dataset controllers are correctly registered under `chart.controllers.{type}`.
80 lines
1.3 KiB
JavaScript
80 lines
1.3 KiB
JavaScript
|
|
'use strict';
|
|
|
|
var BarController = require('./controller.bar');
|
|
var defaults = require('../core/core.defaults');
|
|
|
|
defaults._set('horizontalBar', {
|
|
hover: {
|
|
mode: 'index',
|
|
axis: 'y'
|
|
},
|
|
|
|
scales: {
|
|
xAxes: [{
|
|
type: 'linear',
|
|
position: 'bottom'
|
|
}],
|
|
|
|
yAxes: [{
|
|
type: 'category',
|
|
position: 'left',
|
|
categoryPercentage: 0.8,
|
|
barPercentage: 0.9,
|
|
offset: true,
|
|
gridLines: {
|
|
offsetGridLines: true
|
|
}
|
|
}]
|
|
},
|
|
|
|
elements: {
|
|
rectangle: {
|
|
borderSkipped: 'left'
|
|
}
|
|
},
|
|
|
|
tooltips: {
|
|
callbacks: {
|
|
title: function(item, data) {
|
|
// Pick first xLabel for now
|
|
var title = '';
|
|
|
|
if (item.length > 0) {
|
|
if (item[0].yLabel) {
|
|
title = item[0].yLabel;
|
|
} else if (data.labels.length > 0 && item[0].index < data.labels.length) {
|
|
title = data.labels[item[0].index];
|
|
}
|
|
}
|
|
|
|
return title;
|
|
},
|
|
|
|
label: function(item, data) {
|
|
var datasetLabel = data.datasets[item.datasetIndex].label || '';
|
|
return datasetLabel + ': ' + item.xLabel;
|
|
}
|
|
},
|
|
mode: 'index',
|
|
axis: 'y'
|
|
}
|
|
});
|
|
|
|
module.exports = BarController.extend({
|
|
/**
|
|
* @private
|
|
*/
|
|
getValueScaleId: function() {
|
|
return this.getMeta().xAxisID;
|
|
},
|
|
|
|
/**
|
|
* @private
|
|
*/
|
|
getIndexScaleId: function() {
|
|
return this.getMeta().yAxisID;
|
|
}
|
|
});
|
|
|