You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
We'll remove the es6-promise polyfill entirely from plotly.js in v2.0.0 (see complete list of planned modifications here).
That said, perhaps we could already (in the v1.x series) distribute a plotly.js bundle w/o the es6-promise polyfill? I'd vote 👍 on that if this issue gets more backers.
Reacted by Roland Groza, Victor Berchet, Miško Hevery, John Soklaski, Frederik Aalund, Caleb Kiage, Alain Scialoja, ivanko2000, Antoine Chabert, Maksim Kolchin and 8 more
Thanks for the quick response, looks like a lot of work on the next version. It may make sense to have a patch with the promise polyfill removed already.
Promises are widely supported (IE not) and it always makes sense to let the user decide on which polyfill to use.
I prefer using npm to mange my dependencies, so rolling a build of my own is not something I would do. For now, I just include before angular deps, which still allows me to be up to date with the newer versions.
I think that a simple doc on including the promise polyfill for those that use browsers which don't support it yet, should be enough. I'm not sure though how much work would be required in order to remove the polyfill, but if it's just a line, I think it's worth doing it.
Including it from the CDN in index.html and using declare var Plotly: any; in the controller is pretty hacky, but works fine for me in a few angular-cli apps.
Reacted by sn0wcat, Roland Groza, Alex Mann and DJCrabhat
With npm plotly.js (includes polyfill)
With plotly.js configured as a global script declare var Plotly: any; ng server builds fine, but my app fails to load. I don't see any errors at all in the console.
If I try to import * as Plotly from 'plotly.js'; I get this error:
@arlowhite I have been down the same road. Projects built using Angular CLI don't offer any method to use custom loader which is required by glslify to work. Check out this issue on angular-cli repo for more details. If you are using basic charts and don't require GLSL, then you can go for plotly-basic.js which can be found in node_modules/plotly.js/dist.
@prateek0103 Ok, thanks. dist/plotly.js does load and renders the getting started plot. You think it will break if I use a plotly.js API that requires GLSL?
I haven't fully tested the use of dist/plotly.js it may break if GLSL plots are used, you can also use dist/plotly-basic.js, which should have no problems.
You can then utilize fully typed Plotly in your components:
Edit: I had forgot to show the addition of plotly.js to the types definition in tsconfig.app.json. I've updated the snippet above. I'm not sure if this is necessary, however the angular-cli documentation says to add it.
Edit: To further optimize your imports you can do the following since the webpack tree-shaking does not work on plotly.js. Rather than importing a single dist file, only import the source files you need for your plots.
Just a heads up: using plotly.js/dist/plotly-basic.js rather than plotly.js/dist/plotly.js in the solutions above will get one a much smaller bundle. Of course, this limits the support to basic graphs only.
(Despite --an attempt of?-- tree shaking using Angular CLI's --prod flag, this still adds about 700 KB to my application, but the full one would add 2.32 MB for me.)
The following worked without any update to the tsconfig after importing plotly.js and types. Passing the nativeElement from the ViewChild reference allows me to mark-up multiple instances of the component on a single view.
I'm using Angular 6 at the moment and I have problem with @type files (i.e. index.d.ts). The project complies fine and and everything is working but my IDE, which is Intellij WebStorm is not fully functioning.
I did what @szechyjs said but WebStorm is only suggesting the name of the functions and not providing any details. For example, for newPlot() function it only shows: newPlot(tsconfig$roots) . . . . main.newPlot
in the popup menu.
In addition, I checked and I can not simply "ctrl + click" on the name of function or other imports like "Data" or "Layout" to go to the index.d.ts file.
What I did was to play with tsconfig.app.jason file and I changed the "paths" variable from: "paths": { "plotly.js": [ "../node_modules/plotly.js/dist/plotly.js" ] }
to "paths": { "Plotly": [ "../node_modules/plotly.js/dist/plotly.js" ] }
and suddenly WebStorm started to work! However, as you can guess, the project couldn't be compiled successfully anymore :(
Any suggestion to make Angular 6 to work with the new typing files?
Activity
etpinard commentedon Sep 20, 2016
We'll remove the
es6-promisepolyfill entirely from plotly.js inv2.0.0(see complete list of planned modifications here).That said, perhaps we could already (in the
v1.xseries) distribute a plotly.js bundle w/o thees6-promisepolyfill? I'd vote 👍 on that if this issue gets more backers.In the meantime, I'd recommend:
npm i,npm run buildanddist/plotly.jsbundle.I hope this helps.
rolandjitsu commentedon Sep 20, 2016
Thanks for the quick response, looks like a lot of work on the next version. It may make sense to have a patch with the promise polyfill removed already.
Promises are widely supported (IE not) and it always makes sense to let the user decide on which polyfill to use.
I prefer using npm to mange my dependencies, so rolling a build of my own is not something I would do. For now, I just include before angular deps, which still allows me to be up to date with the newer versions.
I think that a simple doc on including the promise polyfill for those that use browsers which don't support it yet, should be enough. I'm not sure though how much work would be required in order to remove the polyfill, but if it's just a line, I think it's worth doing it.
Thanks again 👍
brian428 commentedon Jan 13, 2017
Was this ever addressed? Trying to add plotly to an Angular 2 project and it is hanging the browser, probably because of the Promise conflict.
amellnik commentedon Jan 13, 2017
Including it from the CDN in
index.htmland usingdeclare var Plotly: any;in the controller is pretty hacky, but works fine for me in a few angular-cli apps.sn0wcat commentedon Feb 12, 2017
it seems to still be broken in angular/cli apps. The hack from amellnik works though.
damienbod commentedon Feb 12, 2017
I have a working example here:
https://damienbod.com/2016/04/21/creating-an-angular-2-component-for-plotly/
Greetings Damien
prateek0103 commentedon Mar 17, 2017
@damienbod It would be helpful to publish the angular2 component to npm, open source community could then pick it up. Thanks for the tutorial.
arlowhite commentedon Mar 30, 2017
With npm plotly.js (includes polyfill)
With plotly.js configured as a global script
declare var Plotly: any;ng serverbuilds fine, but my app fails to load. I don't see any errors at all in the console.If I try to
import * as Plotly from 'plotly.js';I get this error:Re-build without polyfill
@alexcjohnson re-build without polyfill trick worked.
(with Plotly configured as a global script in angular-cli.json)
If you just want to use my build, add this to package.json
"plotly.js": "git+https://github.com/arlowhite/plotly.js#no-polyfill",No matter what I've tried,
import * as Plotly from 'plotly.js';results in an error.FYI, for angular-cli users:
(see the dist directory for alternate builds: plotly.js, plotly-basic.js, etc)
Also, there are type definitions:
npm install @types/plotly.js --save-devYes, a build without the polyfill would be nice. Or maybe all builds shouldn't have it and just document how to add the polyfill to your app?
etpinard commentedon Mar 30, 2017
@arlowhite what tool are you using to bundle your app? plotly.js works best with browserify. Here's how to make it work with webpack.
arlowhite commentedon Mar 30, 2017
@etpinard Thanks, but unfortunately, angular-cli hides webpack.config.json from you.
I updated my previous comment to describe how I got plotly.js working with angular-cli.
EDIT: Just FYI, angular-cli does not plan to allow access to webpack config but maybe will create some addon system.
prateek0103 commentedon Mar 30, 2017
@arlowhite I have been down the same road. Projects built using Angular CLI don't offer any method to use custom loader which is required by
glslifyto work. Check out this issue on angular-cli repo for more details. If you are using basic charts and don't require GLSL, then you can go forplotly-basic.jswhich can be found innode_modules/plotly.js/dist.arlowhite commentedon Mar 30, 2017
@prateek0103 Ok, thanks.
dist/plotly.jsdoes load and renders the getting started plot. You think it will break if I use a plotly.js API that requires GLSL?Fix Jasmine tests
Fix Jasmine tests
Fix Jasmine tests
yugi03 commentedon Sep 20, 2017
@arlowhite : In response to your reply to @etpinard, now angular is exposing webpack.config.json. You can see it here
szechyjs commentedon Oct 11, 2017
The following worked for me with angular-cli.
Add the following to
src/tsconfig.app.json:{ "compilerOptions": { ... "paths": { "plotly.js": [ "../node_modules/plotly.js/dist/plotly.js" ] }, "types": [ "plotly.js" ], ... }I haven't fully tested the use of
dist/plotly.jsit may break if GLSL plots are used, you can also usedist/plotly-basic.js, which should have no problems.You can then utilize fully typed Plotly in your components:
Edit: I had forgot to show the addition of
plotly.jsto thetypesdefinition intsconfig.app.json. I've updated the snippet above. I'm not sure if this is necessary, however the angular-cli documentation says to add it.Edit: To further optimize your imports you can do the following since the webpack tree-shaking does not work on plotly.js. Rather than importing a single dist file, only import the source files you need for your plots.
{ "compilerOptions": { ... "paths": { "plotly.js": [ "../node_modules/plotly.js/lib/core.js", "../node_modules/plotly.js/lib/scatter.js" ] }, ... }rolandjitsu commentedon Oct 15, 2017
One addition to @szechyjs 's comment: do not use
{ ... "strict": true ... }compiler option as it will not work.avbentem commentedon Jan 3, 2018
Just a heads up: using
plotly.js/dist/plotly-basic.jsrather thanplotly.js/dist/plotly.jsin the solutions above will get one a much smaller bundle. Of course, this limits the support to basic graphs only.(Despite --an attempt of?-- tree shaking using Angular CLI's
--prodflag, this still adds about 700 KB to my application, but the full one would add 2.32 MB for me.)cicinelli commentedon Mar 5, 2018
The following worked without any update to the tsconfig after importing plotly.js and types. Passing the nativeElement from the ViewChild reference allows me to mark-up multiple instances of the component on a single view.
saaniaki commentedon Jun 24, 2018
I'm using Angular 6 at the moment and I have problem with @type files (i.e. index.d.ts). The project complies fine and and everything is working but my IDE, which is Intellij WebStorm is not fully functioning.
I did what @szechyjs said but WebStorm is only suggesting the name of the functions and not providing any details. For example, for newPlot() function it only shows:
newPlot(tsconfig$roots) . . . . main.newPlotin the popup menu.
In addition, I checked and I can not simply "ctrl + click" on the name of function or other imports like "Data" or "Layout" to go to the index.d.ts file.
What I did was to play with tsconfig.app.jason file and I changed the "paths" variable from:
"paths": { "plotly.js": [ "../node_modules/plotly.js/dist/plotly.js" ] }to
"paths": { "Plotly": [ "../node_modules/plotly.js/dist/plotly.js" ] }and suddenly WebStorm started to work! However, as you can guess, the project couldn't be compiled successfully anymore :(
Any suggestion to make Angular 6 to work with the new typing files?
etpinard commentedon Jun 26, 2018
@saaniaki have you seen https://github.com/plotly/angular-plotly.js ?
amellnik commentedon Dec 20, 2018
I think this can be closed.