Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make Chart.layout(Service) importable #5113

Merged
merged 1 commit into from Jan 7, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 10 additions & 1 deletion src/chart.js
Expand Up @@ -12,14 +12,14 @@ Chart.defaults = require('./core/core.defaults');
Chart.Element = require('./core/core.element');
Chart.elements = require('./elements/index');
Chart.Interaction = require('./core/core.interaction');
Chart.layout = require('./core/core.layout');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

actually, I'm just wondering now, do we actually need a Chart.layout variable? shouldn't folks just call require('./core/core.layout') when they need the layout?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The layout (singleton) can be accessed from external plugins/charts, in which case it's not possible to require './core/core.layout'.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@etimberg @benmccann Actually, I don't know why the layout is a singleton instead of an object attached to each chart and accessible via chartInstance.layout. Maybe that something we will like to change in v3.

For the alias, I would suggest another name to be consistent with other "Service" singletons: Chart.layouts (plural since it manages many layouts), as we have Chart.plugins and soon Chart.animations and Chart.scales.

What do you think?

Chart.platform = require('./platforms/platform');
Chart.Ticks = require('./core/core.ticks');

require('./core/core.plugin')(Chart);
require('./core/core.animation')(Chart);
require('./core/core.controller')(Chart);
require('./core/core.datasetController')(Chart);
require('./core/core.layoutService')(Chart);
require('./core/core.scaleService')(Chart);
require('./core/core.scale')(Chart);
require('./core/core.tooltip')(Chart);
Expand Down Expand Up @@ -77,3 +77,12 @@ if (typeof window !== 'undefined') {
* @private
*/
Chart.canvasHelpers = Chart.helpers.canvas;

/**
* Provided for backward compatibility, use Chart.layout instead.
* @namespace Chart.layoutService
* @deprecated since version 2.8.0
* @todo remove at version 3
* @private
*/
Chart.layoutService = Chart.layout;
5 changes: 3 additions & 2 deletions src/core/core.controller.js
Expand Up @@ -3,6 +3,7 @@
var defaults = require('./core.defaults');
var helpers = require('../helpers/index');
var Interaction = require('./core.interaction');
var layout = require('./core.layout');
var platform = require('../platforms/platform');

module.exports = function(Chart) {
Expand Down Expand Up @@ -46,7 +47,7 @@ module.exports = function(Chart) {
var newOptions = chart.options;

helpers.each(chart.scales, function(scale) {
Chart.layoutService.removeBox(chart, scale);
layout.removeBox(chart, scale);
});

newOptions = helpers.configMerge(
Expand Down Expand Up @@ -435,7 +436,7 @@ module.exports = function(Chart) {
return;
}

Chart.layoutService.update(this, this.width, this.height);
layout.update(this, this.width, this.height);

/**
* Provided for backward compatibility, use `afterLayout` instead.
Expand Down