mirror of
https://github.com/chartjs/Chart.js.git
synced 2026-03-11 02:36:52 +01:00
Make the main controller importable (#5969)
Merge `core/core.js` in `core/core.controller.js`, split default options next to their associated code and deprecate `Chart.types` (not sure what it was for).
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
/**
|
||||
* @namespace Chart
|
||||
*/
|
||||
var Chart = require('./core/core')();
|
||||
var Chart = require('./core/core.controller');
|
||||
|
||||
Chart.helpers = require('./helpers/index');
|
||||
|
||||
@@ -24,8 +24,6 @@ Chart.scaleService = require('./core/core.scaleService');
|
||||
Chart.Ticks = require('./core/core.ticks');
|
||||
Chart.Tooltip = require('./core/core.tooltip');
|
||||
|
||||
require('./core/core.controller')(Chart);
|
||||
|
||||
// Register built-in scales
|
||||
var scales = require('./scales');
|
||||
Chart.helpers.each(scales, function(scale, type) {
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -2,7 +2,7 @@
|
||||
|
||||
var helpers = require('../helpers/helpers.core');
|
||||
|
||||
module.exports = {
|
||||
var defaults = {
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
@@ -10,3 +10,15 @@ module.exports = {
|
||||
return helpers.merge(this[scope] || (this[scope] = {}), values);
|
||||
}
|
||||
};
|
||||
|
||||
defaults._set('global', {
|
||||
defaultColor: 'rgba(0,0,0,0.1)',
|
||||
defaultFontColor: '#666',
|
||||
defaultFontFamily: "'Helvetica Neue', 'Helvetica', 'Arial', sans-serif",
|
||||
defaultFontSize: 12,
|
||||
defaultFontStyle: 'normal',
|
||||
defaultLineHeight: 1.2,
|
||||
showLines: true
|
||||
});
|
||||
|
||||
module.exports = defaults;
|
||||
|
||||
@@ -1,50 +0,0 @@
|
||||
'use strict';
|
||||
|
||||
var defaults = require('./core.defaults');
|
||||
|
||||
defaults._set('global', {
|
||||
responsive: true,
|
||||
responsiveAnimationDuration: 0,
|
||||
maintainAspectRatio: true,
|
||||
events: ['mousemove', 'mouseout', 'click', 'touchstart', 'touchmove'],
|
||||
hover: {
|
||||
onHover: null,
|
||||
mode: 'nearest',
|
||||
intersect: true,
|
||||
animationDuration: 400
|
||||
},
|
||||
onClick: null,
|
||||
defaultColor: 'rgba(0,0,0,0.1)',
|
||||
defaultFontColor: '#666',
|
||||
defaultFontFamily: "'Helvetica Neue', 'Helvetica', 'Arial', sans-serif",
|
||||
defaultFontSize: 12,
|
||||
defaultFontStyle: 'normal',
|
||||
defaultLineHeight: 1.2,
|
||||
showLines: true,
|
||||
|
||||
// Element defaults defined in element extensions
|
||||
elements: {},
|
||||
|
||||
// Layout options such as padding
|
||||
layout: {
|
||||
padding: {
|
||||
top: 0,
|
||||
right: 0,
|
||||
bottom: 0,
|
||||
left: 0
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
module.exports = function() {
|
||||
|
||||
// Occupy the global variable of Chart, and create a simple base class
|
||||
var Chart = function(item, config) {
|
||||
this.construct(item, config);
|
||||
return this;
|
||||
};
|
||||
|
||||
Chart.Chart = Chart;
|
||||
|
||||
return Chart;
|
||||
};
|
||||
@@ -1,5 +1,6 @@
|
||||
'use strict';
|
||||
|
||||
var defaults = require('./core.defaults');
|
||||
var helpers = require('../helpers/index');
|
||||
|
||||
function filterByPosition(array, position) {
|
||||
@@ -25,6 +26,17 @@ function sortByWeight(array, reverse) {
|
||||
});
|
||||
}
|
||||
|
||||
defaults._set('global', {
|
||||
layout: {
|
||||
padding: {
|
||||
top: 0,
|
||||
right: 0,
|
||||
bottom: 0,
|
||||
left: 0
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* @interface ILayoutItem
|
||||
* @prop {String} position - The position of the item in the chart layout. Possible values are
|
||||
|
||||
@@ -14,7 +14,6 @@ describe('Deprecations', function() {
|
||||
|
||||
describe('Chart.' + klass, function() {
|
||||
it('should be defined as a function', function() {
|
||||
expect(Chart[klass]).toBeDefined();
|
||||
expect(typeof Chart[klass]).toBe('function');
|
||||
});
|
||||
it('should create a chart of type "' + type + '"', function() {
|
||||
@@ -26,19 +25,23 @@ describe('Deprecations', function() {
|
||||
});
|
||||
|
||||
describe('Chart.helpers.aliasPixel', function() {
|
||||
it('should be defined and a function', function() {
|
||||
expect(Chart.helpers.aliasPixel).toBeDefined();
|
||||
it('should be defined as a function', function() {
|
||||
expect(typeof Chart.helpers.aliasPixel).toBe('function');
|
||||
});
|
||||
});
|
||||
|
||||
describe('Chart.LinearScaleBase', function() {
|
||||
it('should be defined and inherit from Chart.Scale', function() {
|
||||
expect(Chart.LinearScaleBase).toBeDefined();
|
||||
expect(typeof Chart.LinearScaleBase).toBe('function');
|
||||
expect(Chart.LinearScaleBase.prototype instanceof Chart.Scale).toBeTruthy();
|
||||
});
|
||||
});
|
||||
|
||||
describe('Chart.types', function() {
|
||||
it('should be defined as an empty object', function() {
|
||||
expect(Chart.types).toEqual({});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('Version 2.7.3', function() {
|
||||
@@ -103,7 +106,6 @@ describe('Deprecations', function() {
|
||||
|
||||
describe('Chart.helpers.indexOf', function() {
|
||||
it('should be defined and a function', function() {
|
||||
expect(Chart.helpers.indexOf).toBeDefined();
|
||||
expect(typeof Chart.helpers.indexOf).toBe('function');
|
||||
});
|
||||
it('should returns the correct index', function() {
|
||||
@@ -144,7 +146,6 @@ describe('Deprecations', function() {
|
||||
|
||||
describe('Chart.helpers.drawRoundedRectangle', function() {
|
||||
it('should be defined and a function', function() {
|
||||
expect(Chart.helpers.drawRoundedRectangle).toBeDefined();
|
||||
expect(typeof Chart.helpers.drawRoundedRectangle).toBe('function');
|
||||
});
|
||||
it('should call Chart.helpers.canvas.roundedRect', function() {
|
||||
@@ -161,7 +162,6 @@ describe('Deprecations', function() {
|
||||
|
||||
describe('Chart.helpers.addEvent', function() {
|
||||
it('should be defined and a function', function() {
|
||||
expect(Chart.helpers.addEvent).toBeDefined();
|
||||
expect(typeof Chart.helpers.addEvent).toBe('function');
|
||||
});
|
||||
it('should correctly add event listener', function() {
|
||||
@@ -174,7 +174,6 @@ describe('Deprecations', function() {
|
||||
|
||||
describe('Chart.helpers.removeEvent', function() {
|
||||
it('should be defined and a function', function() {
|
||||
expect(Chart.helpers.removeEvent).toBeDefined();
|
||||
expect(typeof Chart.helpers.removeEvent).toBe('function');
|
||||
});
|
||||
it('should correctly remove event listener', function() {
|
||||
|
||||
Reference in New Issue
Block a user