Skip to content

Commit e031443

Browse files
Merge pull request #2103 from plotly/reduce_jlab_bundle_size
Use plotly.min.js in both JS bundles
2 parents 7f6713f + 209daab commit e031443

File tree

8 files changed

+16437
-34267
lines changed

8 files changed

+16437
-34267
lines changed

packages/javascript/jupyterlab-plotly/package-lock.json

+167-115
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/javascript/jupyterlab-plotly/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
"typescript": "~3.1.1"
3232
},
3333
"dependencies": {
34-
"plotly.js": "^1.51.2",
34+
"plotly.js": "^1.52.1",
3535
"@types/plotly.js": "^1.44.9",
3636
"@jupyterlab/rendermime-interfaces": "^1.3.0",
3737
"@phosphor/messaging": "^1.2.3",

packages/javascript/jupyterlab-plotly/src/javascript-renderer-extension.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { Message } from '@phosphor/messaging';
77

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

10-
import Plotly from 'plotly.js/dist/plotly';
10+
import Plotly from 'plotly.js/dist/plotly.min';
1111

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

@@ -226,4 +226,4 @@ const extensions: IRenderMime.IExtension | IRenderMime.IExtension[] = [
226226
}
227227
];
228228

229-
export default extensions;
229+
export default extensions;
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
declare module 'plotly.js/dist/plotly' {
1+
declare module 'plotly.js/dist/plotly.min' {
22
export * from 'plotly.js';
33
export type Frame = { [key: string]: any };
44
export function addFrames(root: Plotly.Root, frames: Frame[]): Promise<void>;
@@ -7,4 +7,4 @@ declare module 'plotly.js/dist/plotly' {
77
export interface PlotlyHTMLElement extends HTMLElement {
88
on(event: 'plotly_webglcontextlost', callback: () => void): void;
99
}
10-
}
10+
}

packages/javascript/plotlywidget/package.json

+1-3
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,8 @@
2222
"style/*.*"
2323
],
2424
"scripts": {
25-
"build": "npm run build:src",
26-
"build:src": "rimraf dist && tsc",
25+
"build": "webpack",
2726
"clean": "rimraf dist/ && rimraf ../../python/plotly/plotlywidget/static'",
28-
"prepublish": "webpack",
2927
"test": "echo \"Error: no test specified\" && exit 1"
3028
},
3129
"devDependencies": {

packages/javascript/plotlywidget/src/Figure.js

+40-4
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ var _ = require("lodash");
33

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

98
// Model
@@ -700,7 +699,7 @@ var FigureView = widgets.DOMWidgetView.extend({
700699

701700
// Set view UID
702701
// ------------
703-
this.viewID = PlotlyIndex.randstr();
702+
this.viewID = randstr();
704703

705704
// Initialize Plotly.js figure
706705
// ---------------------------
@@ -1084,7 +1083,7 @@ var FigureView = widgets.DOMWidgetView.extend({
10841083
handle_plotly_selected: function (data) {
10851084
this._send_points_callback_message(data, "plotly_selected");
10861085
},
1087-
1086+
10881087
/**
10891088
* Handle plotly_deselect events emitted by the Plotly.js library
10901089
* @param data
@@ -1094,7 +1093,7 @@ var FigureView = widgets.DOMWidgetView.extend({
10941093
points : []
10951094
}
10961095
this._send_points_callback_message(data, "plotly_deselect");
1097-
},
1096+
},
10981097

10991098
/**
11001099
* Build and send a points callback message to the Python side
@@ -1812,6 +1811,43 @@ function createDeltaObject(fullObj, removeObj) {
18121811
return res
18131812
}
18141813

1814+
function randstr(existing, bits, base, _recursion) {
1815+
if(!base) base = 16;
1816+
if(bits === undefined) bits = 24;
1817+
if(bits <= 0) return '0';
1818+
1819+
var digits = Math.log(Math.pow(2, bits)) / Math.log(base);
1820+
var res = '';
1821+
var i, b, x;
1822+
1823+
for(i = 2; digits === Infinity; i *= 2) {
1824+
digits = Math.log(Math.pow(2, bits / i)) / Math.log(base) * i;
1825+
}
1826+
1827+
var rem = digits - Math.floor(digits);
1828+
1829+
for(i = 0; i < Math.floor(digits); i++) {
1830+
x = Math.floor(Math.random() * base).toString(base);
1831+
res = x + res;
1832+
}
1833+
1834+
if(rem) {
1835+
b = Math.pow(base, rem);
1836+
x = Math.floor(Math.random() * b).toString(base);
1837+
res = x + res;
1838+
}
1839+
1840+
var parsed = parseInt(res, base);
1841+
if((existing && existing[res]) ||
1842+
(parsed !== Infinity && parsed >= Math.pow(2, bits))) {
1843+
if(_recursion > 10) {
1844+
lib.warn('randstr failed uniqueness');
1845+
return res;
1846+
}
1847+
return randstr(existing, bits, base, (_recursion || 0) + 1);
1848+
} else return res;
1849+
}
1850+
18151851
module.exports = {
18161852
FigureView : FigureView,
18171853
FigureModel: FigureModel

0 commit comments

Comments
 (0)