Skip to content

Commit

Permalink
Merge pull request #2103 from plotly/reduce_jlab_bundle_size
Browse files Browse the repository at this point in the history
Use plotly.min.js in both JS bundles
  • Loading branch information
nicolaskruchten authored Jan 22, 2020
2 parents 7f6713f + 209daab commit e031443
Show file tree
Hide file tree
Showing 8 changed files with 16,437 additions and 34,267 deletions.
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",
"@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",
"build": "webpack",
"clean": "rimraf dist/ && rimraf ../../python/plotly/plotlywidget/static'",
"prepublish": "webpack",
"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

0 comments on commit e031443

Please sign in to comment.