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

Conversation

simonbrunel
Copy link
Member

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.

Relates to #4591

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.
@simonbrunel simonbrunel added this to the Version 2.7 milestone Aug 28, 2017
@simonbrunel simonbrunel mentioned this pull request Aug 28, 2017
4 tasks
@simonbrunel
Copy link
Member Author

@hach-que can you please test this PR and confirm that it works for your use case?

@simonbrunel
Copy link
Member Author

@hach-que ping!

@hach-que
Copy link

hach-que commented Sep 1, 2017

Probably won't get a chance to test this for a while. As long as it avoids calling methods on window or document when they're not available, it should be fine.

@simonbrunel
Copy link
Member Author

I can't test it server side so can't guarantee that it will work as expected. Basically, if window and document are undefined, then we use the default basic implementation which contains no reference to window or document (ie. no responsive resize or chart events).

@hach-que
Copy link

hach-que commented Sep 2, 2017

Found 5 minutes to test this. The following works:

  • yarn init
  • yarn add https://github.com/simonbrunel/Chart.js#platform-basic
  • Write an index.js file like:
var cjs = require('chart.js');

console.log('library loaded successfully under Node.js!');

var c = new cjs();

console.log('made a chart:');
console.log(c);
  • Run node index.js.
  • You'll get the following successful output:
library loaded successfully under Node.js!
Failed to create chart: can't acquire context from the given item
made a chart:
Chart {
  id: 0,
  ctx: null,
  canvas: null,
  ... snipped ... }

@simonbrunel
Copy link
Member Author

Thanks @hach-que

@simonbrunel simonbrunel merged commit c7464eb into chartjs:master Sep 2, 2017
@simonbrunel simonbrunel deleted the platform-basic branch September 2, 2017 09:04
yofreke pushed a commit to yofreke/Chart.js that referenced this pull request Dec 30, 2017
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.
exwm pushed a commit to exwm/Chart.js that referenced this pull request Apr 30, 2021
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants