-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
incompatible with Angular 2 #955
Comments
We'll remove the That said, perhaps we could already (in the In the meantime, I'd recommend:
I hope this helps. |
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 👍 |
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. |
Including it from the CDN in |
it seems to still be broken in angular/cli apps. The hack from amellnik works though. |
I have a working example here: |
@damienbod It would be helpful to publish the angular2 component to npm, open source community could then pick it up. Thanks for the tutorial. |
With npm plotly.js (includes polyfill) If I try to
Re-build without polyfill If you just want to use my build, add this to package.json No matter what I've tried, FYI, for angular-cli users:
(see the dist directory for alternate builds: plotly.js, plotly-basic.js, etc) Also, there are type definitions:
Yes, 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? |
@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. |
@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. |
@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 |
@prateek0103 Ok, thanks. |
Adds modified version of Plotly package. Old one redefined polyfills and there were problems with Zone.js. Current build has modified es6 include as described here: plotly/plotly.js#955 Plotly component has to be further bind to data, but now it has just sample ones.
Adds modified version of Plotly package. Old one redefined polyfills and there were problems with Zone.js. Current build has modified es6 include as described here: plotly/plotly.js#955 Plotly component has to be further bind to data, but now it has just sample ones.
Adds modified version of Plotly package. Old one redefined polyfills and there were problems with Zone.js. Current build has modified es6 include as described here: plotly/plotly.js#955 Plotly component has to be further bind to data, but now it has just sample ones.
@arlowhite : In response to your reply to @etpinard, now angular is exposing webpack.config.json. You can see it here |
The following worked for me with angular-cli. yarn add plotly.js
yarn add @types/plotly.js --dev Add the following to {
"compilerOptions": {
...
"paths": {
"plotly.js": [
"../node_modules/plotly.js/dist/plotly.js"
]
},
"types": [
"plotly.js"
],
...
} I haven't fully tested the use of You can then utilize fully typed Plotly in your components: import * as Plotly from 'plotly.js';
import {Config, Data, Layout} from 'plotly.js'; Edit: I had forgot to show the addition of 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"
]
},
...
} |
One addition to @szechyjs 's comment: do not use |
Just a heads up: using (Despite --an attempt of?-- tree shaking using Angular CLI's |
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. import { Component, Input, OnInit, ViewChild } from "@angular/core";
import * as Plotly from "plotly.js/dist/plotly-basic.js";
import { Config, Data, Layout } from "plotly.js/dist/plotly-basic.js";
@Component({
selector: "plotly-chart",
template: `
<div #plotly></div>
`,
styleUrls: ["./plotly-chart.component.scss"]
})
export class PlotlyChartComponent implements OnInit {
@Input() data: any;
@Input() layout: any;
@Input() options: any;
@ViewChild("plotly") plotly;
constructor() {}
ngOnInit() {
Plotly.newPlot(
this.plotly.nativeElement,
this.data,
this.layout,
this.options
);
}
} |
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: 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: Any suggestion to make Angular 6 to work with the new typing files? |
@saaniaki have you seen https://github.com/plotly/angular-plotly.js ? |
I think this can be closed. |
There seems to be some kind of conflict when using Angular 2 and Plotly. The same issue is somewhat described in #7218.
For now, the only fix is including plotly before angular's zone.js dependency.
Could there be something done from within this lib?
The text was updated successfully, but these errors were encountered: