Skip to content

Commit b1f0c42

Browse files
committed
Add dynmaic import for plotly lib
1 parent b75cc01 commit b1f0c42

4 files changed

Lines changed: 13 additions & 9 deletions

File tree

src/danfojs-base/plotting/index.ts

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,12 @@ import Series from "../core/series";
2626
import DataFrame from "../core/frame";
2727
import { PlotConfigObject, IPlotlyLib } from "../shared/types"
2828

29-
import Plotly from "plotly.js-dist-min"
29+
let Plotly: IPlotlyLib;
3030

31+
if (typeof window !== "undefined") {
32+
//check if in browser environment and require "plotly.js-dist-min" module
33+
Plotly = require("plotly.js-dist-min") as IPlotlyLib;
3134

32-
try {
33-
// @ts-ignore
34-
const version = Plotly.version;
35-
console.info(`Using Plotly version ${version}`);
36-
} catch (error) {
37-
console.info(`Plotly CDN not found. If you need to make Plots, then add the Plotly CDN to your script`);
3835
}
3936

4037
class PlotlyLib implements IPlotlyLib {

src/danfojs-node/package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,9 @@
2727
"seedrandom": "^2.4.3",
2828
"stream-json": "^1.7.3",
2929
"table": "6.7.1",
30-
"xlsx": "^0.17.2"
30+
"xlsx": "^0.17.2",
31+
"plotly.js-dist-min": "^2.8.0"
32+
3133
},
3234
"scripts": {
3335
"test": "nyc mocha --require ts-node/register test/**/*.test.ts",

src/danfojs-node/tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"compilerOptions": {
33
"target": "es5", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019', 'ES2020', or 'ESNEXT'. */
44
"module": "commonjs", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', 'es2020', or 'ESNext'. */
5-
"lib": ["es6"], /* Specify library files to be included in the compilation. */
5+
"lib": ["es6", "DOM"], /* Specify library files to be included in the compilation. */
66
"allowJs": true, /* Allow javascript files to be compiled. */
77
"outDir": "./dist", /* Redirect output structure to the directory. */
88
"strict": true, /* Enable all strict type-checking options. */

src/danfojs-node/yarn.lock

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4214,6 +4214,11 @@ pkg-dir@^4.1.0:
42144214
dependencies:
42154215
find-up "^4.0.0"
42164216

4217+
plotly.js-dist-min@^2.8.0:
4218+
version "2.8.3"
4219+
resolved "https://registry.yarnpkg.com/plotly.js-dist-min/-/plotly.js-dist-min-2.8.3.tgz#0ffa317de10dd48f0c32d15c83c41f60230f50b3"
4220+
integrity sha512-TjovBrqIbedUfjGWNMMs++az3lF4hsIAB8EjqM/mC0cPrO7Wg86lBkHAsRbMra5aWyXA+M52yiQUUKBfThqwzg==
4221+
42174222
posix-character-classes@^0.1.0:
42184223
version "0.1.1"
42194224
resolved "https://registry.yarnpkg.com/posix-character-classes/-/posix-character-classes-0.1.1.tgz#01eac0fe3b5af71a2a6c02feabb8c1fef7e00eab"

0 commit comments

Comments
 (0)