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

Add platform fallback implementation #4708

Merged
merged 1 commit into from Sep 2, 2017
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
15 changes: 15 additions & 0 deletions src/platforms/platform.basic.js
@@ -0,0 +1,15 @@
/**
* Platform fallback implementation (minimal).
* @see https://github.com/chartjs/Chart.js/pull/4591#issuecomment-319575939
*/

module.exports = {
acquireContext: function(item) {
if (item && item.canvas) {
// Support for any object associated to a canvas (including a context2d)
item = item.canvas;
}

return item && item.getContext('2d') || null;
}
};
7 changes: 7 additions & 0 deletions src/platforms/platform.dom.js
Expand Up @@ -305,6 +305,13 @@ function injectCSS(platform, css) {
}

module.exports = {
/**
* This property holds whether this platform is enabled for the current environment.
* Currently used by platform.js to select the proper implementation.
* @private
*/
_enabled: typeof window !== 'undefined' && typeof document !== 'undefined',

initialize: function() {
var keyframes = 'from{opacity:0.99}to{opacity:1}';

Expand Down
5 changes: 3 additions & 2 deletions src/platforms/platform.js
@@ -1,10 +1,11 @@
'use strict';

var helpers = require('../helpers/index');
var basic = require('./platform.basic');
var dom = require('./platform.dom');

// By default, select the browser (DOM) platform.
// @TODO Make possible to select another platform at build time.
var implementation = require('./platform.dom');
var implementation = dom._enabled ? dom : basic;

/**
* @namespace Chart.platform
Expand Down