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

Use plotly.min.js in both JS bundles #2103

Merged
merged 4 commits into from
Jan 22, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
282 changes: 167 additions & 115 deletions packages/javascript/jupyterlab-plotly/package-lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion packages/javascript/jupyterlab-plotly/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
"typescript": "~3.1.1"
},
"dependencies": {
"plotly.js": "^1.51.2",
"plotly.js": "^1.52.1",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you intend to downgrade plotly.js here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That’s an upgrade actually ;)

"@types/plotly.js": "^1.44.9",
"@jupyterlab/rendermime-interfaces": "^1.3.0",
"@phosphor/messaging": "^1.2.3",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { Message } from '@phosphor/messaging';

import { IRenderMime } from '@jupyterlab/rendermime-interfaces';

import Plotly from 'plotly.js/dist/plotly';
import Plotly from 'plotly.js/dist/plotly.min';

import '../style/index.css';

Expand Down Expand Up @@ -226,4 +226,4 @@ const extensions: IRenderMime.IExtension | IRenderMime.IExtension[] = [
}
];

export default extensions;
export default extensions;
4 changes: 2 additions & 2 deletions packages/javascript/jupyterlab-plotly/src/lib.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
declare module 'plotly.js/dist/plotly' {
declare module 'plotly.js/dist/plotly.min' {
export * from 'plotly.js';
export type Frame = { [key: string]: any };
export function addFrames(root: Plotly.Root, frames: Frame[]): Promise<void>;
Expand All @@ -7,4 +7,4 @@ declare module 'plotly.js/dist/plotly' {
export interface PlotlyHTMLElement extends HTMLElement {
on(event: 'plotly_webglcontextlost', callback: () => void): void;
}
}
}
4 changes: 1 addition & 3 deletions packages/javascript/plotlywidget/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,8 @@
"style/*.*"
],
"scripts": {
"build": "npm run build:src",
"build:src": "rimraf dist && tsc",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this isn't a TypeScript module so this doesn't seem to do much

"build": "webpack",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The build for this package is, in fact webpack, and running npm run build does use the installed webpack in node_modules. So now we have to run npm install && npm run build and there are no deprecation warnings :)

"clean": "rimraf dist/ && rimraf ../../python/plotly/plotlywidget/static'",
"prepublish": "webpack",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this prepublish thing is deprecated. It seems like NPM tries to run it when doing npm install and fails unless you have webpack installed globally for some reason.

"test": "echo \"Error: no test specified\" && exit 1"
},
"devDependencies": {
Expand Down
44 changes: 40 additions & 4 deletions packages/javascript/plotlywidget/src/Figure.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ var _ = require("lodash");

window.PlotlyConfig = {MathJaxConfig: 'local'};
var Plotly = require("plotly.js/dist/plotly.min");
var PlotlyIndex = require("plotly.js/src/lib/index");
var semver_range = "^" + require("../package.json").version;

// Model
Expand Down Expand Up @@ -700,7 +699,7 @@ var FigureView = widgets.DOMWidgetView.extend({

// Set view UID
// ------------
this.viewID = PlotlyIndex.randstr();
this.viewID = randstr();

// Initialize Plotly.js figure
// ---------------------------
Expand Down Expand Up @@ -1084,7 +1083,7 @@ var FigureView = widgets.DOMWidgetView.extend({
handle_plotly_selected: function (data) {
this._send_points_callback_message(data, "plotly_selected");
},

/**
* Handle plotly_deselect events emitted by the Plotly.js library
* @param data
Expand All @@ -1094,7 +1093,7 @@ var FigureView = widgets.DOMWidgetView.extend({
points : []
}
this._send_points_callback_message(data, "plotly_deselect");
},
},

/**
* Build and send a points callback message to the Python side
Expand Down Expand Up @@ -1812,6 +1811,43 @@ function createDeltaObject(fullObj, removeObj) {
return res
}

function randstr(existing, bits, base, _recursion) {
if(!base) base = 16;
if(bits === undefined) bits = 24;
if(bits <= 0) return '0';

var digits = Math.log(Math.pow(2, bits)) / Math.log(base);
var res = '';
var i, b, x;

for(i = 2; digits === Infinity; i *= 2) {
digits = Math.log(Math.pow(2, bits / i)) / Math.log(base) * i;
}

var rem = digits - Math.floor(digits);

for(i = 0; i < Math.floor(digits); i++) {
x = Math.floor(Math.random() * base).toString(base);
res = x + res;
}

if(rem) {
b = Math.pow(base, rem);
x = Math.floor(Math.random() * b).toString(base);
res = x + res;
}

var parsed = parseInt(res, base);
if((existing && existing[res]) ||
(parsed !== Infinity && parsed >= Math.pow(2, bits))) {
if(_recursion > 10) {
lib.warn('randstr failed uniqueness');
return res;
}
return randstr(existing, bits, base, (_recursion || 0) + 1);
} else return res;
}

module.exports = {
FigureView : FigureView,
FigureModel: FigureModel
Expand Down
Loading