diff --git a/README.md b/README.md index b5f9274e471..d2aa3e817e5 100644 --- a/README.md +++ b/README.md @@ -24,6 +24,40 @@ +--- + +## NOTE + +__**This is a fork of Plotly modified for use in Mode's native Python notebook environment.**__ + +To test work on Mode's fork of Plotly you will need to do the following: + +1. ensure these Mode services are running: + + * Jiffypop: https://github.com/mode/go-mono/tree/master/jiffypop + * Python 3 runtime: https://github.com/mode/runtime-images/tree/master/runtime-python3 + * The following services in the JVM mono repo: https://github.com/mode/jvm-mono + * DirectConnect + * Credguard + * Flamingo + * Zookeeper + +2. After saving changes to the Plotly repo, if your local Python3 Docker container is running stop and restart it: + * Restart the container with `./runtime-python3/bin/run-runtime-python3-image-0` in the `runtime-images` directory + +3. Execute this command within the `plotly.py` directory to apply your changes to the Python runtime: +`docker cp ./packages/python/plotly/. $(docker container ps --filter name=runtime-python3 -q):/opt/conda/envs/python3/lib/python3.6/site-packages/` + +4. Click "Restart" in the web application notebook. + +5. Verify you're running your local version of Plotly by executing this code in the notebook, which should print out `'0+unknown'`: +``` +import plotly +plotly.__version__ +``` + +--- + ## Quickstart `pip install plotly "notebook>=5.3" "ipywidgets>=7.2"` @@ -102,7 +136,7 @@ conda install "notebook>=5.3" "ipywidgets=7.5" ### JupyterLab Support (Python 3.5+) For use in JupyterLab, install the `jupyterlab` and `ipywidgets` -packages using pip... +packages using pip... ``` pip install jupyterlab==1.0 "ipywidgets==7.5" diff --git a/packages/javascript/plotlywidget/package-lock.json b/packages/javascript/plotlywidget/package-lock.json index 18893e6d22f..47eb8559757 100644 --- a/packages/javascript/plotlywidget/package-lock.json +++ b/packages/javascript/plotlywidget/package-lock.json @@ -2188,7 +2188,8 @@ "ansi-regex": { "version": "2.1.1", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "aproba": { "version": "1.1.1", @@ -2239,7 +2240,8 @@ "balanced-match": { "version": "0.4.2", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "bcrypt-pbkdf": { "version": "1.0.1", @@ -2254,6 +2256,7 @@ "version": "0.0.9", "bundled": true, "dev": true, + "optional": true, "requires": { "inherits": "~2.0.0" } @@ -2262,6 +2265,7 @@ "version": "2.10.1", "bundled": true, "dev": true, + "optional": true, "requires": { "hoek": "2.x.x" } @@ -2270,6 +2274,7 @@ "version": "1.1.7", "bundled": true, "dev": true, + "optional": true, "requires": { "balanced-match": "^0.4.1", "concat-map": "0.0.1" @@ -2278,7 +2283,8 @@ "buffer-shims": { "version": "1.0.0", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "caseless": { "version": "0.12.0", @@ -2295,12 +2301,14 @@ "code-point-at": { "version": "1.1.0", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "combined-stream": { "version": "1.0.5", "bundled": true, "dev": true, + "optional": true, "requires": { "delayed-stream": "~1.0.0" } @@ -2308,22 +2316,26 @@ "concat-map": { "version": "0.0.1", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "console-control-strings": { "version": "1.1.0", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "core-util-is": { "version": "1.0.2", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "cryptiles": { "version": "2.0.5", "bundled": true, "dev": true, + "optional": true, "requires": { "boom": "2.x.x" } @@ -2363,7 +2375,8 @@ "delayed-stream": { "version": "1.0.0", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "delegates": { "version": "1.0.0", @@ -2395,7 +2408,8 @@ "extsprintf": { "version": "1.0.2", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "forever-agent": { "version": "0.6.1", @@ -2417,12 +2431,14 @@ "fs.realpath": { "version": "1.0.0", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "fstream": { "version": "1.0.11", "bundled": true, "dev": true, + "optional": true, "requires": { "graceful-fs": "^4.1.2", "inherits": "~2.0.0", @@ -2478,6 +2494,7 @@ "version": "7.1.2", "bundled": true, "dev": true, + "optional": true, "requires": { "fs.realpath": "^1.0.0", "inflight": "^1.0.4", @@ -2490,7 +2507,8 @@ "graceful-fs": { "version": "4.1.11", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "har-schema": { "version": "1.0.5", @@ -2518,6 +2536,7 @@ "version": "3.1.3", "bundled": true, "dev": true, + "optional": true, "requires": { "boom": "2.x.x", "cryptiles": "2.x.x", @@ -2528,7 +2547,8 @@ "hoek": { "version": "2.16.3", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "http-signature": { "version": "1.1.1", @@ -2545,6 +2565,7 @@ "version": "1.0.6", "bundled": true, "dev": true, + "optional": true, "requires": { "once": "^1.3.0", "wrappy": "1" @@ -2553,7 +2574,8 @@ "inherits": { "version": "2.0.3", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "ini": { "version": "1.3.4", @@ -2565,6 +2587,7 @@ "version": "1.0.0", "bundled": true, "dev": true, + "optional": true, "requires": { "number-is-nan": "^1.0.0" } @@ -2578,7 +2601,8 @@ "isarray": { "version": "1.0.0", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "isstream": { "version": "0.1.2", @@ -2651,12 +2675,14 @@ "mime-db": { "version": "1.27.0", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "mime-types": { "version": "2.1.15", "bundled": true, "dev": true, + "optional": true, "requires": { "mime-db": "~1.27.0" } @@ -2665,6 +2691,7 @@ "version": "3.0.4", "bundled": true, "dev": true, + "optional": true, "requires": { "brace-expansion": "^1.1.7" } @@ -2672,12 +2699,14 @@ "minimist": { "version": "0.0.8", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "mkdirp": { "version": "0.5.1", "bundled": true, "dev": true, + "optional": true, "requires": { "minimist": "0.0.8" } @@ -2732,7 +2761,8 @@ "number-is-nan": { "version": "1.0.1", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "oauth-sign": { "version": "0.8.2", @@ -2750,6 +2780,7 @@ "version": "1.4.0", "bundled": true, "dev": true, + "optional": true, "requires": { "wrappy": "1" } @@ -2779,7 +2810,8 @@ "path-is-absolute": { "version": "1.0.1", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "performance-now": { "version": "0.2.0", @@ -2790,7 +2822,8 @@ "process-nextick-args": { "version": "1.0.7", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "punycode": { "version": "1.4.1", @@ -2828,6 +2861,7 @@ "version": "2.2.9", "bundled": true, "dev": true, + "optional": true, "requires": { "buffer-shims": "~1.0.0", "core-util-is": "~1.0.0", @@ -2872,6 +2906,7 @@ "version": "2.6.1", "bundled": true, "dev": true, + "optional": true, "requires": { "glob": "^7.0.5" } @@ -2879,7 +2914,8 @@ "safe-buffer": { "version": "5.0.1", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "semver": { "version": "5.3.0", @@ -2903,6 +2939,7 @@ "version": "1.0.9", "bundled": true, "dev": true, + "optional": true, "requires": { "hoek": "2.x.x" } @@ -2936,6 +2973,7 @@ "version": "1.0.2", "bundled": true, "dev": true, + "optional": true, "requires": { "code-point-at": "^1.0.0", "is-fullwidth-code-point": "^1.0.0", @@ -2946,6 +2984,7 @@ "version": "1.0.1", "bundled": true, "dev": true, + "optional": true, "requires": { "safe-buffer": "^5.0.1" } @@ -2960,6 +2999,7 @@ "version": "3.0.1", "bundled": true, "dev": true, + "optional": true, "requires": { "ansi-regex": "^2.0.0" } @@ -2974,6 +3014,7 @@ "version": "2.2.1", "bundled": true, "dev": true, + "optional": true, "requires": { "block-stream": "*", "fstream": "^1.0.2", @@ -3029,7 +3070,8 @@ "util-deprecate": { "version": "1.0.2", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "uuid": { "version": "3.0.1", @@ -3058,7 +3100,8 @@ "wrappy": { "version": "1.0.2", "bundled": true, - "dev": true + "dev": true, + "optional": true } } }, diff --git a/packages/python/chart-studio/chart_studio/tools.py b/packages/python/chart-studio/chart_studio/tools.py index 87b23546b33..5cc32dfed8d 100644 --- a/packages/python/chart-studio/chart_studio/tools.py +++ b/packages/python/chart-studio/chart_studio/tools.py @@ -65,16 +65,19 @@ def ensure_local_plotly_files(): if contents_orig.keys() != contents.keys(): utils.save_json_dict(fn, contents) - else: - warnings.warn( - "Looks like you don't have 'read-write' permission to " - "your 'home' ('~') directory or to our '~/.plotly' " - "directory. That means plotly's python api can't setup " - "local configuration files. No problem though! You'll " - "just have to sign-in using 'plotly.plotly.sign_in()'. " - "For help with that: 'help(plotly.plotly.sign_in)'." - "\nQuestions? Visit https://support.plot.ly" - ) + # MODE MODIFIED # + # unless or until we support online plotly there's no reason to nag the user about + # something they can't affect anyway + # else: + # warnings.warn( + # "Looks like you don't have 'read-write' permission to " + # "your 'home' ('~') directory or to our '~/.plotly' " + # "directory. That means plotly's python api can't setup " + # "local configuration files. No problem though! You'll " + # "just have to sign-in using 'plotly.plotly.sign_in()'. " + # "For help with that: 'help(plotly.plotly.sign_in)'." + # "\nQuestions? Visit https://support.plot.ly" + # ) ### credentials tools ### diff --git a/packages/python/plotly/plotly/io/_html.py b/packages/python/plotly/plotly/io/_html.py index f2f4aba0ef1..fb5e953952b 100644 --- a/packages/python/plotly/plotly/io/_html.py +++ b/packages/python/plotly/plotly/io/_html.py @@ -211,7 +211,7 @@ def to_html( then_animate = "" if jframes: then_addframes = """.then(function(){{ - Plotly.addFrames('{id}', {frames}); + window.Plotly && Plotly.addFrames('{id}', {frames}); }})""".format( id=plotdivid, frames=jframes ) @@ -230,14 +230,28 @@ def to_html( # Serialize config dict to JSON jconfig = json.dumps(config) + # MODE ADDITION # + after_script = """ + .then(function() {{ + if (window["MODE_PYTHON_EMBED"]) {{ + window["mode"] && window["mode"].resize && window["mode"].resize(); + }} else {{ + window.onresize = function() {{ + window.Plotly && Plotly.Plots.resize(document.getElementById("{id}")); + }}; + }} + }}); + """.format(id=plotdivid) + + # MODE MODIFIED # script = """ if (document.getElementById("{id}")) {{ - Plotly.newPlot( + window.Plotly && Plotly.newPlot( '{id}', {data}, {layout}, {config} - ){then_addframes}{then_animate}{then_post_script} + ){then_addframes}{then_animate}{then_post_script}{after_script} }}""".format( id=plotdivid, data=jdata, @@ -246,6 +260,7 @@ def to_html( then_addframes=then_addframes, then_animate=then_animate, then_post_script=then_post_script, + after_script=after_script ) # ## Handle loading/initializing plotly.js ## @@ -263,8 +278,9 @@ def to_html( # Init plotlyjs. This block needs to run before plotly.js is loaded in # order for MathJax configuration to work properly if include_plotlyjs == "require": - require_start = 'require(["plotly"], function(Plotly) {' - require_end = "});" + # MODE MODIFIED # + require_start = '' + require_end = '' elif include_plotlyjs == "cdn": load_plotlyjs = """\ @@ -333,13 +349,23 @@ def to_html( Invalid value of type {typ} received as the include_mathjax argument Received value: {val} -include_mathjax may be specified as False, 'cdn', or a string ending with '.js' +include_mathjax may be specified as False, 'cdn', or a string ending with '.js' """.format( typ=type(include_mathjax), val=repr(include_mathjax) ) ) + # MODE ADDITION # + before_script = """ + if (!window["MODE_PYTHON_EMBED"]) {{ + document.getElementById("{id}").style.height = "336px"; + }} + """.format(id=plotdivid) + + # MODE MODIFIED # plotly_html_div = """\ +\ +\
{mathjax_script} {load_plotlyjs} @@ -348,7 +374,7 @@ def to_html(
""".format( @@ -361,6 +387,7 @@ def to_html( require_start=require_start, script=script, require_end=require_end, + before_script=before_script, ) if full_html: diff --git a/packages/python/plotly/plotly/offline/offline.py b/packages/python/plotly/plotly/offline/offline.py index c7d458b1452..ca33f02f05d 100644 --- a/packages/python/plotly/plotly/offline/offline.py +++ b/packages/python/plotly/plotly/offline/offline.py @@ -161,6 +161,12 @@ def _get_jconfig(config=None): ) clean_config = config + + # MODE ADDITION # + clean_config['showLink'] = False + clean_config['displaylogo'] = False + clean_config['modeBarButtonsToRemove'] = ['sendDataToCloud'] + else: clean_config = {} diff --git a/packages/python/plotly/plotlywidget/static/index.js b/packages/python/plotly/plotlywidget/static/index.js index ceea30dfc82..1532476b37d 100644 --- a/packages/python/plotly/plotlywidget/static/index.js +++ b/packages/python/plotly/plotlywidget/static/index.js @@ -10495,27 +10495,27 @@ module.exports = function(opts) { /* 10 */ /***/ (function(module, exports) { -var g; - -// This works in non-strict mode -g = (function() { - return this; -})(); - -try { - // This works if eval is allowed (see CSP) - g = g || Function("return this")() || (1,eval)("this"); -} catch(e) { - // This works if the window reference is available - if(typeof window === "object") - g = window; -} - -// g can still be undefined, but nothing to do about it... -// We return undefined, instead of nothing here, so it's -// easier to handle this case. if(!global) { ...} - -module.exports = g; +var g; + +// This works in non-strict mode +g = (function() { + return this; +})(); + +try { + // This works if eval is allowed (see CSP) + g = g || Function("return this")() || (1,eval)("this"); +} catch(e) { + // This works if the window reference is available + if(typeof window === "object") + g = window; +} + +// g can still be undefined, but nothing to do about it... +// We return undefined, instead of nothing here, so it's +// easier to handle this case. if(!global) { ...} + +module.exports = g; /***/ }), @@ -31519,28 +31519,28 @@ module.exports = __WEBPACK_EXTERNAL_MODULE_22__; /* 24 */ /***/ (function(module, exports) { -module.exports = function(module) { - if(!module.webpackPolyfill) { - module.deprecate = function() {}; - module.paths = []; - // module.parent = undefined by default - if(!module.children) module.children = []; - Object.defineProperty(module, "loaded", { - enumerable: true, - get: function() { - return module.l; - } - }); - Object.defineProperty(module, "id", { - enumerable: true, - get: function() { - return module.i; - } - }); - module.webpackPolyfill = 1; - } - return module; -}; +module.exports = function(module) { + if(!module.webpackPolyfill) { + module.deprecate = function() {}; + module.paths = []; + // module.parent = undefined by default + if(!module.children) module.children = []; + Object.defineProperty(module, "loaded", { + enumerable: true, + get: function() { + return module.l; + } + }); + Object.defineProperty(module, "id", { + enumerable: true, + get: function() { + return module.i; + } + }); + module.webpackPolyfill = 1; + } + return module; +}; /***/ }), @@ -32720,41 +32720,41 @@ lib.isHidden = function(gd) { /***/ (function(module, exports, __webpack_require__) { "use strict"; - - -/** - * Is this string all whitespace? - * This solution kind of makes my brain hurt, but it's significantly faster - * than !str.trim() or any other solution I could find. - * - * whitespace codes from: http://en.wikipedia.org/wiki/Whitespace_character - * and verified with: - * - * for(var i = 0; i < 65536; i++) { - * var s = String.fromCharCode(i); - * if(+s===0 && !s.trim()) console.log(i, s); - * } - * - * which counts a couple of these as *not* whitespace, but finds nothing else - * that *is* whitespace. Note that charCodeAt stops at 16 bits, but it appears - * that there are no whitespace characters above this, and code points above - * this do not map onto white space characters. - */ - -module.exports = function(str){ - var l = str.length, - a; - for(var i = 0; i < l; i++) { - a = str.charCodeAt(i); - if((a < 9 || a > 13) && (a !== 32) && (a !== 133) && (a !== 160) && - (a !== 5760) && (a !== 6158) && (a < 8192 || a > 8205) && - (a !== 8232) && (a !== 8233) && (a !== 8239) && (a !== 8287) && - (a !== 8288) && (a !== 12288) && (a !== 65279)) { - return false; - } - } - return true; -} + + +/** + * Is this string all whitespace? + * This solution kind of makes my brain hurt, but it's significantly faster + * than !str.trim() or any other solution I could find. + * + * whitespace codes from: http://en.wikipedia.org/wiki/Whitespace_character + * and verified with: + * + * for(var i = 0; i < 65536; i++) { + * var s = String.fromCharCode(i); + * if(+s===0 && !s.trim()) console.log(i, s); + * } + * + * which counts a couple of these as *not* whitespace, but finds nothing else + * that *is* whitespace. Note that charCodeAt stops at 16 bits, but it appears + * that there are no whitespace characters above this, and code points above + * this do not map onto white space characters. + */ + +module.exports = function(str){ + var l = str.length, + a; + for(var i = 0; i < l; i++) { + a = str.charCodeAt(i); + if((a < 9 || a > 13) && (a !== 32) && (a !== 133) && (a !== 160) && + (a !== 5760) && (a !== 6158) && (a < 8192 || a > 8205) && + (a !== 8232) && (a !== 8233) && (a !== 8239) && (a !== 8287) && + (a !== 8288) && (a !== 12288) && (a !== 65279)) { + return false; + } + } + return true; +} /***/ }), diff --git a/packages/python/plotly/setup.py b/packages/python/plotly/setup.py index d2e9832c171..ec03afac6fd 100644 --- a/packages/python/plotly/setup.py +++ b/packages/python/plotly/setup.py @@ -432,13 +432,13 @@ def run(self): versioneer_cmds = versioneer.get_cmdclass() setup( - name="plotly", + name="mode-plotly", version=versioneer.get_version(), use_2to3=False, author="Chris P", author_email="chris@plot.ly", - maintainer="Jon Mease", - maintainer_email="jon@plot.ly", + maintainer="Mode Analytics", + maintainer_email="support@modeanalytics.com", url="https://plot.ly/python/", project_urls={"Github": "https://github.com/plotly/plotly.py"}, description="An open-source, interactive graphing library for Python",