mirror of
https://github.com/chartjs/Chart.js.git
synced 2024-10-06 12:19:08 +02:00
Add platform basic implementation (fallback) (#4708)
If `window` or `document` are `undefined`, a minimal platform implementation is used instead, which one only returns a context2d read from the given canvas/context.
This commit is contained in:
parent
e3b70e0420
commit
c7464ebf91
15
src/platforms/platform.basic.js
Normal file
15
src/platforms/platform.basic.js
Normal file
@ -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;
|
||||
}
|
||||
};
|
@ -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}';
|
||||
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user