Skip to content

Commit 717e8d9

Browse files
authored
Make Chart.helpers importable (#4479)
Properly export helpers and remove dependencies to `Chart.helpers`. Helpers can now be accessed from `src/helpers/index.js` (`var helpers = require('path/to/helpers/index')`, instead of `var helpers = Chart.helpers`).
1 parent b03ab1c commit 717e8d9

37 files changed

+638
-623
lines changed

src/chart.js

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,10 @@
33
*/
44
var Chart = require('./core/core')();
55

6-
require('./helpers/helpers.core')(Chart);
7-
require('./helpers/helpers.easing')(Chart);
6+
Chart.helpers = require('./helpers/index');
7+
8+
// @todo dispatch these helpers into appropriated helpers/helpers.* file and write unit tests!
89
require('./core/core.helpers')(Chart);
9-
require('./helpers/helpers.time')(Chart);
10-
require('./helpers/helpers.canvas')(Chart);
1110

1211
require('./platforms/platform')(Chart);
1312
require('./core/core.element')(Chart);
@@ -66,3 +65,14 @@ module.exports = Chart;
6665
if (typeof window !== 'undefined') {
6766
window.Chart = Chart;
6867
}
68+
69+
// DEPRECATIONS
70+
71+
/**
72+
* Provided for backward compatibility, use Chart.helpers.canvas instead.
73+
* @namespace Chart.canvasHelpers
74+
* @deprecated since version 2.6.0
75+
* @todo remove at version 3
76+
* @private
77+
*/
78+
Chart.canvasHelpers = Chart.helpers.canvas;

src/controllers/controller.bar.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
'use strict';
22

3-
module.exports = function(Chart) {
3+
var helpers = require('../helpers/index');
44

5-
var helpers = Chart.helpers;
5+
module.exports = function(Chart) {
66

77
Chart.defaults.bar = {
88
hover: {

src/controllers/controller.bubble.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
'use strict';
22

3-
module.exports = function(Chart) {
3+
var helpers = require('../helpers/index');
44

5-
var helpers = Chart.helpers;
5+
module.exports = function(Chart) {
66

77
Chart.defaults.bubble = {
88
hover: {

src/controllers/controller.doughnut.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
'use strict';
22

3+
var helpers = require('../helpers/index');
4+
35
module.exports = function(Chart) {
46

5-
var helpers = Chart.helpers,
6-
defaults = Chart.defaults;
7+
var defaults = Chart.defaults;
78

89
defaults.doughnut = {
910
animation: {

src/controllers/controller.line.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
'use strict';
22

3-
module.exports = function(Chart) {
3+
var helpers = require('../helpers/index');
44

5-
var helpers = Chart.helpers;
5+
module.exports = function(Chart) {
66

77
Chart.defaults.line = {
88
showLines: true,
@@ -285,13 +285,13 @@ module.exports = function(Chart) {
285285
var ilen = points.length;
286286
var i = 0;
287287

288-
Chart.helpers.canvas.clipArea(chart.ctx, area);
288+
helpers.canvas.clipArea(chart.ctx, area);
289289

290290
if (lineEnabled(me.getDataset(), chart.options)) {
291291
meta.dataset.draw();
292292
}
293293

294-
Chart.helpers.canvas.unclipArea(chart.ctx);
294+
helpers.canvas.unclipArea(chart.ctx);
295295

296296
// Draw the points
297297
for (; i<ilen; ++i) {

src/controllers/controller.polarArea.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
'use strict';
22

3-
module.exports = function(Chart) {
3+
var helpers = require('../helpers/index');
44

5-
var helpers = Chart.helpers;
5+
module.exports = function(Chart) {
66

77
Chart.defaults.polarArea = {
88

src/controllers/controller.radar.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
'use strict';
22

3-
module.exports = function(Chart) {
3+
var helpers = require('../helpers/index');
44

5-
var helpers = Chart.helpers;
5+
module.exports = function(Chart) {
66

77
Chart.defaults.radar = {
88
scale: {

src/core/core.animation.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
/* global window: false */
22
'use strict';
33

4-
module.exports = function(Chart) {
4+
var helpers = require('../helpers/index');
55

6-
var helpers = Chart.helpers;
6+
module.exports = function(Chart) {
77

88
Chart.defaults.global.animation = {
99
duration: 1000,

src/core/core.controller.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
'use strict';
22

3-
module.exports = function(Chart) {
3+
var helpers = require('../helpers/index');
44

5-
var helpers = Chart.helpers;
5+
module.exports = function(Chart) {
66
var plugins = Chart.plugins;
77
var platform = Chart.platform;
88

src/core/core.datasetController.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
'use strict';
22

3-
module.exports = function(Chart) {
3+
var helpers = require('../helpers/index');
44

5-
var helpers = Chart.helpers;
5+
module.exports = function(Chart) {
66

77
var arrayEvents = ['push', 'pop', 'shift', 'splice', 'unshift'];
88

0 commit comments

Comments
 (0)