From 9bd2dc051b50352d4bc33c8925dfddc05d965867 Mon Sep 17 00:00:00 2001 From: Matthew Turk Date: Sat, 6 Feb 2021 11:48:08 -0600 Subject: [PATCH 01/18] Apply automatic conversion to jupyterlab 3.0 --- .eslintignore | 5 +++ .eslintrc.js | 39 +++++++++++++++++ .github/workflows/build.yml | 58 +++++++++++++++++++++++++ .gitignore | 43 ++++++++---------- .prettierignore | 5 +++ .prettierrc | 5 +++ LICENSE | 3 +- MANIFEST.in | 6 ++- install.json | 5 +++ jupyter-config/widgyts.json | 6 +-- package.json | 61 +++++++++++++++----------- setup.py | 87 +++++++++++++++++++------------------ src/handler.ts | 46 ++++++++++++++++++++ style/base.css | 0 style/index.css | 1 + style/index.js | 1 + tsconfig.json | 3 +- widgyts/__init__.py | 57 ++++++++++++------------ widgyts/_version.py | 19 ++++++++ widgyts/handlers.py | 24 ++++++++++ 20 files changed, 345 insertions(+), 129 deletions(-) create mode 100644 .eslintignore create mode 100644 .eslintrc.js create mode 100644 .github/workflows/build.yml create mode 100644 .prettierignore create mode 100644 .prettierrc create mode 100644 install.json create mode 100644 src/handler.ts create mode 100644 style/base.css create mode 100644 style/index.js create mode 100644 widgyts/_version.py create mode 100644 widgyts/handlers.py diff --git a/.eslintignore b/.eslintignore new file mode 100644 index 0000000..5c99ba7 --- /dev/null +++ b/.eslintignore @@ -0,0 +1,5 @@ +node_modules +dist +coverage +**/*.d.ts +tests diff --git a/.eslintrc.js b/.eslintrc.js new file mode 100644 index 0000000..d66148c --- /dev/null +++ b/.eslintrc.js @@ -0,0 +1,39 @@ +module.exports = { + extends: [ + 'eslint:recommended', + 'plugin:@typescript-eslint/eslint-recommended', + 'plugin:@typescript-eslint/recommended', + 'plugin:prettier/recommended' + ], + parser: '@typescript-eslint/parser', + parserOptions: { + project: 'tsconfig.json', + sourceType: 'module' + }, + plugins: ['@typescript-eslint'], + rules: { + '@typescript-eslint/naming-convention': [ + 'error', + { + 'selector': 'interface', + 'format': ['PascalCase'], + 'custom': { + 'regex': '^I[A-Z]', + 'match': true + } + } + ], + '@typescript-eslint/no-unused-vars': ['warn', { args: 'none' }], + '@typescript-eslint/no-explicit-any': 'off', + '@typescript-eslint/no-namespace': 'off', + '@typescript-eslint/no-use-before-define': 'off', + '@typescript-eslint/quotes': [ + 'error', + 'single', + { avoidEscape: true, allowTemplateLiterals: false } + ], + curly: ['error', 'all'], + eqeqeq: 'error', + 'prefer-arrow-callback': 'error' + } +}; diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 0000000..8446012 --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,58 @@ +name: Build + +on: + push: + branches: main + pull_request: + branches: '*' + +jobs: + build: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v2 + - name: Install node + uses: actions/setup-node@v1 + with: + node-version: '12.x' + - name: Install Python + uses: actions/setup-python@v2 + with: + python-version: '3.7' + architecture: 'x64' + + + - name: Setup pip cache + uses: actions/cache@v2 + with: + path: ~/.cache/pip + key: pip-3.7-${{ hashFiles('package.json') }} + restore-keys: | + pip-3.7- + pip- + + - name: Get yarn cache directory path + id: yarn-cache-dir-path + run: echo "::set-output name=dir::$(yarn cache dir)" + - name: Setup yarn cache + uses: actions/cache@v2 + id: yarn-cache # use this to check for `cache-hit` (`steps.yarn-cache.outputs.cache-hit != 'true'`) + with: + path: ${{ steps.yarn-cache-dir-path.outputs.dir }} + key: yarn-${{ hashFiles('**/yarn.lock') }} + restore-keys: | + yarn- + + - name: Install dependencies + run: python -m pip install -U jupyterlab~=3.0 jupyter_packaging~=0.7.9 + - name: Build the extension + run: | + jlpm + jlpm run eslint:check + python -m pip install . + + jupyter server extension list 2>&1 | grep -ie "widgyts.*OK" + + jupyter labextension list 2>&1 | grep -ie "@yt-project/yt-widgets.*OK" + python -m jupyterlab.browser_check diff --git a/.gitignore b/.gitignore index 8d135f4..f48aa49 100644 --- a/.gitignore +++ b/.gitignore @@ -4,8 +4,8 @@ node_modules/ *.egg-info/ .ipynb_checkpoints *.tsbuildinfo +widgyts/labextension -*/labextension/*.tgz # Created by https://www.gitignore.io/api/python # Edit at https://www.gitignore.io/?templates=python @@ -36,10 +36,7 @@ pip-wheel-metadata/ share/python-wheels/ .installed.cfg *.egg -node_modules/ -widgyts/static/ -js/package-lock.json -js/yarn.lock +MANIFEST # PyInstaller # Usually these files are written by a python script from a template @@ -54,6 +51,7 @@ pip-delete-this-directory.txt # Unit test / coverage reports htmlcov/ .tox/ +.nox/ .coverage .coverage.* .cache @@ -67,14 +65,6 @@ coverage.xml *.mo *.pot -# Django stuff: -*.log -local_settings.py - -# Flask stuff: -instance/ -.webassets-cache - # Scrapy stuff: .scrapy @@ -84,9 +74,6 @@ docs/_build/ # PyBuilder target/ -# Jupyter Notebook -.ipynb_checkpoints - # pyenv .python-version @@ -96,14 +83,6 @@ celerybeat-schedule # SageMath parsed files *.sage.py -# dotenv -.env - -# virtualenv -.venv -venv/ -ENV/ - # Spyder project settings .spyderproject .spyproject @@ -111,9 +90,23 @@ ENV/ # Rope project settings .ropeproject +# Mr Developer +.mr.developer.cfg +.project +.pydevproject + # mkdocs documentation /site # mypy .mypy_cache/ -.vscode/settings.json +.dmypy.json +dmypy.json + +# Pyre type checker +.pyre/ + +# End of https://www.gitignore.io/api/python + +# OSX files +.DS_Store diff --git a/.prettierignore b/.prettierignore new file mode 100644 index 0000000..58e7054 --- /dev/null +++ b/.prettierignore @@ -0,0 +1,5 @@ +node_modules +**/node_modules +**/lib +**/package.json +widgyts diff --git a/.prettierrc b/.prettierrc new file mode 100644 index 0000000..b0a179d --- /dev/null +++ b/.prettierrc @@ -0,0 +1,5 @@ +{ + "singleQuote": true, + "trailingComma": "none", + "arrowParens": "avoid" +} diff --git a/LICENSE b/LICENSE index ffa7ce0..a05e2a4 100644 --- a/LICENSE +++ b/LICENSE @@ -1,7 +1,6 @@ BSD 3-Clause License -Copyright (c) 2018, Data Exploration Lab -All rights reserved. +Copyright (c) 2020, Data Exploration Lab All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: diff --git a/MANIFEST.in b/MANIFEST.in index c3942dd..b3d188b 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -1,12 +1,14 @@ include LICENSE include README.md include pyproject.toml - include jupyter-config/widgyts.json include package.json +include install.json include ts*.json -include widgyts/labextension/*.tgz +include yarn.lock + +graft widgyts/labextension # Javascript files graft src diff --git a/install.json b/install.json new file mode 100644 index 0000000..4259140 --- /dev/null +++ b/install.json @@ -0,0 +1,5 @@ +{ + "packageManager": "python", + "packageName": "widgyts", + "uninstallInstructions": "Use your Python package manager (pip, conda, etc.) to uninstall the package widgyts" +} diff --git a/jupyter-config/widgyts.json b/jupyter-config/widgyts.json index 825ebfb..8e89f9b 100644 --- a/jupyter-config/widgyts.json +++ b/jupyter-config/widgyts.json @@ -1,7 +1,7 @@ { - "NotebookApp": { - "nbserver_extensions": { - "widgytsts": true + "ServerApp": { + "jpserver_extensions": { + "widgyts": true } } } diff --git a/package.json b/package.json index 6eef5da..d96feb3 100644 --- a/package.json +++ b/package.json @@ -29,7 +29,8 @@ "license": "BSD-3-Clause", "files": [ "lib/**/*.{d.ts,eot,gif,html,jpg,js,js.map,json,png,svg,woff2,ttf,wasm}", - "style/**/*.{css,eot,gif,html,jpg,json,png,svg,woff2,ttf}" + "style/**/*.{css,eot,gif,html,jpg,json,png,svg,woff2,ttf}", + "style/index.js" ], "main": "lib/index.js", "types": "lib/index.d.ts", @@ -39,42 +40,50 @@ "url": "https://github.com/yt-project/widgyts.git" }, "scripts": { - "build": "jlpm run build:lib", - "build:labextension": "cd widgyts && rimraf labextension && mkdirp labextension && cd labextension && npm pack ../..", - "build:lib": "tsc", + "build": "jlpm run build:lib && jlpm run build:labextension:dev", "build:all": "jlpm run build:labextension", + "build:labextension": "jupyter labextension build .", + "build:labextension:dev": "jupyter labextension build --development True .", + "build:lib": "tsc", + "build:prod": "jlpm run build:lib && jlpm run build:labextension", "clean": "jlpm run clean:lib", - "clean:lib": "rimraf lib tsconfig.tsbuildinfo", - "clean:labextension": "rimraf widgyts/labextension", "clean:all": "jlpm run clean:lib && jlpm run clean:labextension", + "clean:labextension": "rimraf widgyts/labextension", + "clean:lib": "rimraf lib tsconfig.tsbuildinfo", "eslint": "eslint . --ext .ts,.tsx --fix", "eslint:check": "eslint . --ext .ts,.tsx", - "prepare": "jlpm run clean && jlpm run build", - "watch": "tsc -w" + "install:extension": "jupyter labextension develop --overwrite .", + "prepare": "jlpm run clean && jlpm run build:prod", + "watch": "run-p watch:src watch:labextension", + "watch:labextension": "jupyter labextension watch .", + "watch:src": "tsc -w" }, "dependencies": { "@data-exp-lab/yt-tools": "^0.3.0", - "@jupyterlab/application": "^2.0.0", - "@jupyterlab/coreutils": "^4.0.0", - "@jupyterlab/mainmenu": "^2.1.1", - "@jupyterlab/services": "^5.0.0", - "@lumino/widgets": "^1.13.0", + "@jupyterlab/application": "^3.0.4", + "@jupyterlab/coreutils": "^5.0.2", + "@jupyterlab/mainmenu": "^3.0.3", + "@jupyterlab/services": "^6.0.3", + "@lumino/widgets": "^1.16.1", "@types/node": "^14.0.5", "ipycanvas": "^0.4.7" }, "devDependencies": { - "@typescript-eslint/eslint-plugin": "^2.25.0", - "@typescript-eslint/parser": "^2.25.0", - "eslint": "^6.8.0", - "eslint-config-prettier": "^6.10.1", - "eslint-plugin-prettier": "^3.1.2", + "@jupyterlab/builder": "^3.0.0", + "@typescript-eslint/eslint-plugin": "^4.8.1", + "@typescript-eslint/parser": "^4.8.1", + "eslint": "^7.14.0", + "eslint-config-prettier": "^6.15.0", + "eslint-plugin-prettier": "^3.1.4", "mkdirp": "^1.0.3", - "prettier": "1.16.4", - "rimraf": "^2.6.1", - "typescript": "^3.9.3" + "npm-run-all": "^4.1.5", + "prettier": "^2.1.1", + "rimraf": "^3.0.2", + "typescript": "~4.1.3" }, "sideEffects": [ - "style/*.css" + "style/*.css", + "style/index.js" ], "jupyterlab": { "discovery": { @@ -87,6 +96,8 @@ } } }, - "extension": "lib/plugin" - } -} + "extension": "lib/plugin", + "outputDir": "widgyts/labextension" + }, + "styleModule": "style/index.js" +} \ No newline at end of file diff --git a/setup.py b/setup.py index b3f8d15..33f97ba 100644 --- a/setup.py +++ b/setup.py @@ -1,90 +1,91 @@ """ -Setup Module to setup Python Handlers for the widgyts extension. +widgyts setup """ -import os +import json +from pathlib import Path -import setuptools from jupyter_packaging import ( - combine_commands, create_cmdclass, - ensure_python, - ensure_targets, install_npm, + ensure_targets, + combine_commands, + skip_if_exists ) +import setuptools -HERE = os.path.abspath(os.path.dirname(__file__)) +HERE = Path(__file__).parent.resolve() # The name of the project name = "widgyts" -# Ensure a valid python version -ensure_python(">=3.5") - -# Get our version -version = "0.4.0dev0" - -lab_path = os.path.join(HERE, name, "labextension") +lab_path = (HERE / name / "labextension") # Representative files that should exist after a successful build jstargets = [ - os.path.join(HERE, "lib", "widgyts.js"), + str(lab_path / "package.json"), ] -package_data_spec = {name: ["*"]} +package_data_spec = { + name: ["*"], +} + +labext_name = "@yt-project/yt-widgets" data_files_spec = [ - ("share/jupyter/lab/extensions", lab_path, "*.tgz"), - ("etc/jupyter/jupyter_notebook_config.d", "jupyter-config", "widgyts.json"), + ("share/jupyter/labextensions/%s" % labext_name, str(lab_path), "**"), + ("share/jupyter/labextensions/%s" % labext_name, str(HERE), "install.json"),("etc/jupyter/jupyter_server_config.d", + "jupyter-config", "widgyts.json"), + ] -cmdclass = create_cmdclass( - "jsdeps", package_data_spec=package_data_spec, data_files_spec=data_files_spec +cmdclass = create_cmdclass("jsdeps", + package_data_spec=package_data_spec, + data_files_spec=data_files_spec ) -cmdclass["jsdeps"] = combine_commands( - install_npm(HERE, build_cmd="build:all", npm=["jlpm"]), ensure_targets(jstargets), +js_command = combine_commands( + install_npm(HERE, build_cmd="build:prod", npm=["jlpm"]), + ensure_targets(jstargets), ) -with open("README.md", "r") as fh: - long_description = fh.read() +is_repo = (HERE / ".git").exists() +if is_repo: + cmdclass["jsdeps"] = js_command +else: + cmdclass["jsdeps"] = skip_if_exists(jstargets, js_command) + +long_description = (HERE / "README.md").read_text() + +# Get the package info from package.json +pkg_json = json.loads((HERE / "package.json").read_bytes()) setup_args = dict( name=name, - version=version, - url="https://github.com/yt-project/widgyts", - author="Data Exploration Lab", - author_email="mmunk2@illinois.edu", - description="A Custom Jupyter Widget Library for yt", + version=pkg_json["version"], + url=pkg_json["homepage"], + author=pkg_json["author"], + description=pkg_json["description"], + license=pkg_json["license"], long_description=long_description, long_description_content_type="text/markdown", cmdclass=cmdclass, packages=setuptools.find_packages(), install_requires=[ - "jupyterlab~=2.0", - "ipycanvas>=0.4.7", - "ipywidgets>=7.5.1", - "numpy>=1.14", - "traitlets>=4.3.3", - "yt>=3.5.1", - "pythreejs>=2.2.0", + "jupyterlab~=3.0", ], zip_safe=False, include_package_data=True, - license="BSD-3-Clause", + python_requires=">=3.6", platforms="Linux, Mac OS X, Windows", - keywords=["Jupyter", "JupyterLab"], + keywords=["Jupyter", "JupyterLab", "JupyterLab3"], classifiers=[ "License :: OSI Approved :: BSD License", - "Development Status :: 4 - Beta", - "Framework :: IPython", - "Intended Audience :: Developers", - "Intended Audience :: Science/Research", - "Topic :: Multimedia :: Graphics", "Programming Language :: Python", "Programming Language :: Python :: 3", "Programming Language :: Python :: 3.6", "Programming Language :: Python :: 3.7", "Programming Language :: Python :: 3.8", + "Programming Language :: Python :: 3.9", "Framework :: Jupyter", ], ) diff --git a/src/handler.ts b/src/handler.ts new file mode 100644 index 0000000..02b154c --- /dev/null +++ b/src/handler.ts @@ -0,0 +1,46 @@ +import { URLExt } from '@jupyterlab/coreutils'; + +import { ServerConnection } from '@jupyterlab/services'; + +/** + * Call the API extension + * + * @param endPoint API REST end point for the extension + * @param init Initial values for the request + * @returns The response body interpreted as JSON + */ +export async function requestAPI( + endPoint = '', + init: RequestInit = {} +): Promise { + // Make request to Jupyter API + const settings = ServerConnection.makeSettings(); + const requestUrl = URLExt.join( + settings.baseUrl, + 'widgyts', // API Namespace + endPoint + ); + + let response: Response; + try { + response = await ServerConnection.makeRequest(requestUrl, init, settings); + } catch (error) { + throw new ServerConnection.NetworkError(error); + } + + let data: any = await response.text(); + + if (data.length > 0) { + try { + data = JSON.parse(data); + } catch (error) { + console.log('Not a JSON response body.', response); + } + } + + if (!response.ok) { + throw new ServerConnection.ResponseError(response, data.message || data); + } + + return data; +} diff --git a/style/base.css b/style/base.css new file mode 100644 index 0000000..e69de29 diff --git a/style/index.css b/style/index.css index e69de29..8a7ea29 100644 --- a/style/index.css +++ b/style/index.css @@ -0,0 +1 @@ +@import url('base.css'); diff --git a/style/index.js b/style/index.js new file mode 100644 index 0000000..a028a76 --- /dev/null +++ b/style/index.js @@ -0,0 +1 @@ +import './base.css'; diff --git a/tsconfig.json b/tsconfig.json index 7459fa7..81139f5 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -18,8 +18,7 @@ "strict": true, "strictNullChecks": false, "target": "es2017", - "types": ["node"], - "skipLibCheck": true + "types": [] }, "include": ["src/*"] } diff --git a/widgyts/__init__.py b/widgyts/__init__.py index 4287876..8ad3295 100644 --- a/widgyts/__init__.py +++ b/widgyts/__init__.py @@ -1,36 +1,39 @@ -__version__ = "0.4.0dev0" -EXTENSION_VERSION = "~" + __version__ -from .dataset_viewer import ( - AMRDomainViewer, - DatasetViewer, - FieldDefinitionViewer, - ParametersViewer, -) -from .image_canvas import * +import json +from pathlib import Path +from ._version import __version__ -def _jupyter_nbextension_paths(): - # Not sure we need this anymore - return [ - { - "section": "notebook", - "src": "static", - "dest": "yt-widgets", - "require": "yt-widgets/extension", - } - ] +HERE = Path(__file__).parent.resolve() +with (HERE / "labextension" / "package.json").open() as fid: + data = json.load(fid) -def _jupyter_server_extension_paths(): - return [{"module": "widgyts"}] +def _jupyter_labextension_paths(): + return [{ + "src": "labextension", + "dest": data["name"] + }] -def load_jupyter_server_extension(lab_app): - """ - Just add to mimetypes. + +from .handlers import setup_handlers + + +def _jupyter_server_extension_points(): + return [{ + "module": "widgyts" + }] + + +def _load_jupyter_server_extension(server_app): + """Registers the API handler to receive HTTP requests from the frontend extension. + + Parameters + ---------- + server_app: jupyterlab.labapp.LabApp + JupyterLab application instance """ - import mimetypes + setup_handlers(server_app.web_app) + server_app.log.info("Registered HelloWorld extension at URL path /widgyts") - mimetypes.add_type("application/wasm", ".wasm") - lab_app.log.info("Registered application/wasm MIME type") diff --git a/widgyts/_version.py b/widgyts/_version.py new file mode 100644 index 0000000..b96d38b --- /dev/null +++ b/widgyts/_version.py @@ -0,0 +1,19 @@ +import json +from pathlib import Path + +__all__ = ["__version__"] + +def _fetchVersion(): + HERE = Path(__file__).parent.resolve() + + for settings in HERE.rglob("package.json"): + try: + with settings.open() as f: + return json.load(f)["version"] + except FileNotFoundError: + pass + + raise FileNotFoundError(f"Could not find package.json under dir {HERE!s}") + +__version__ = _fetchVersion() + diff --git a/widgyts/handlers.py b/widgyts/handlers.py new file mode 100644 index 0000000..0227d30 --- /dev/null +++ b/widgyts/handlers.py @@ -0,0 +1,24 @@ +import json + +from jupyter_server.base.handlers import APIHandler +from jupyter_server.utils import url_path_join +import tornado + +class RouteHandler(APIHandler): + # The following decorator should be present on all verb methods (head, get, post, + # patch, put, delete, options) to ensure only authorized user can request the + # Jupyter server + @tornado.web.authenticated + def get(self): + self.finish(json.dumps({ + "data": "This is /widgyts/get_example endpoint!" + })) + + +def setup_handlers(web_app): + host_pattern = ".*$" + + base_url = web_app.settings["base_url"] + route_pattern = url_path_join(base_url, "widgyts", "get_example") + handlers = [(route_pattern, RouteHandler)] + web_app.add_handlers(host_pattern, handlers) From c907f5c4a7da8de5f2a6343aaa269796a3555127 Mon Sep 17 00:00:00 2001 From: Matthew Turk Date: Sat, 6 Feb 2021 14:20:52 -0600 Subject: [PATCH 02/18] Adding node types --- tsconfig.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tsconfig.json b/tsconfig.json index 81139f5..df6cda3 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -18,7 +18,7 @@ "strict": true, "strictNullChecks": false, "target": "es2017", - "types": [] + "types": ["node"] }, "include": ["src/*"] } From 11811c6a9617e79a181d3f85de78c4561e49a5c3 Mon Sep 17 00:00:00 2001 From: Matthew Turk Date: Sat, 6 Feb 2021 14:31:39 -0600 Subject: [PATCH 03/18] Redoing server extensions --- src/handler.ts | 46 --------------------------------------------- widgyts/__init__.py | 26 ++++++++++++++----------- widgyts/handlers.py | 24 ----------------------- 3 files changed, 15 insertions(+), 81 deletions(-) delete mode 100644 src/handler.ts delete mode 100644 widgyts/handlers.py diff --git a/src/handler.ts b/src/handler.ts deleted file mode 100644 index 02b154c..0000000 --- a/src/handler.ts +++ /dev/null @@ -1,46 +0,0 @@ -import { URLExt } from '@jupyterlab/coreutils'; - -import { ServerConnection } from '@jupyterlab/services'; - -/** - * Call the API extension - * - * @param endPoint API REST end point for the extension - * @param init Initial values for the request - * @returns The response body interpreted as JSON - */ -export async function requestAPI( - endPoint = '', - init: RequestInit = {} -): Promise { - // Make request to Jupyter API - const settings = ServerConnection.makeSettings(); - const requestUrl = URLExt.join( - settings.baseUrl, - 'widgyts', // API Namespace - endPoint - ); - - let response: Response; - try { - response = await ServerConnection.makeRequest(requestUrl, init, settings); - } catch (error) { - throw new ServerConnection.NetworkError(error); - } - - let data: any = await response.text(); - - if (data.length > 0) { - try { - data = JSON.parse(data); - } catch (error) { - console.log('Not a JSON response body.', response); - } - } - - if (!response.ok) { - throw new ServerConnection.ResponseError(response, data.message || data); - } - - return data; -} diff --git a/widgyts/__init__.py b/widgyts/__init__.py index 8ad3295..46e5e53 100644 --- a/widgyts/__init__.py +++ b/widgyts/__init__.py @@ -3,6 +3,16 @@ from pathlib import Path from ._version import __version__ +EXTENSION_VERSION = "~" + __version__ + +from .dataset_viewer import ( + AMRDomainViewer, + DatasetViewer, + FieldDefinitionViewer, + ParametersViewer, +) +from .image_canvas import * + HERE = Path(__file__).parent.resolve() @@ -17,9 +27,6 @@ def _jupyter_labextension_paths(): -from .handlers import setup_handlers - - def _jupyter_server_extension_points(): return [{ "module": "widgyts" @@ -27,13 +34,10 @@ def _jupyter_server_extension_points(): def _load_jupyter_server_extension(server_app): - """Registers the API handler to receive HTTP requests from the frontend extension. - - Parameters - ---------- - server_app: jupyterlab.labapp.LabApp - JupyterLab application instance """ - setup_handlers(server_app.web_app) - server_app.log.info("Registered HelloWorld extension at URL path /widgyts") + Just add to mimetypes. + """ + import mimetypes + mimetypes.add_type("application/wasm", ".wasm") + lab_app.log.info("Registered application/wasm MIME type") diff --git a/widgyts/handlers.py b/widgyts/handlers.py deleted file mode 100644 index 0227d30..0000000 --- a/widgyts/handlers.py +++ /dev/null @@ -1,24 +0,0 @@ -import json - -from jupyter_server.base.handlers import APIHandler -from jupyter_server.utils import url_path_join -import tornado - -class RouteHandler(APIHandler): - # The following decorator should be present on all verb methods (head, get, post, - # patch, put, delete, options) to ensure only authorized user can request the - # Jupyter server - @tornado.web.authenticated - def get(self): - self.finish(json.dumps({ - "data": "This is /widgyts/get_example endpoint!" - })) - - -def setup_handlers(web_app): - host_pattern = ".*$" - - base_url = web_app.settings["base_url"] - route_pattern = url_path_join(base_url, "widgyts", "get_example") - handlers = [(route_pattern, RouteHandler)] - web_app.add_handlers(host_pattern, handlers) From e881c3adadb02cd25cb146372833e3e757b3f655 Mon Sep 17 00:00:00 2001 From: Matthew Turk Date: Sat, 6 Feb 2021 14:34:04 -0600 Subject: [PATCH 04/18] Skip the lib check --- tsconfig.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tsconfig.json b/tsconfig.json index df6cda3..7459fa7 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -18,7 +18,8 @@ "strict": true, "strictNullChecks": false, "target": "es2017", - "types": ["node"] + "types": ["node"], + "skipLibCheck": true }, "include": ["src/*"] } From 1f9683a1154d7988f22ba622e936d51956672ee0 Mon Sep 17 00:00:00 2001 From: Matthew Turk Date: Sat, 6 Feb 2021 14:42:17 -0600 Subject: [PATCH 05/18] Updating pyproject.toml --- package.json | 5 +++-- pyproject.toml | 2 +- webpack.config.js | 6 ++++++ 3 files changed, 10 insertions(+), 3 deletions(-) create mode 100644 webpack.config.js diff --git a/package.json b/package.json index d96feb3..0370d02 100644 --- a/package.json +++ b/package.json @@ -97,7 +97,8 @@ } }, "extension": "lib/plugin", - "outputDir": "widgyts/labextension" + "outputDir": "widgyts/labextension", + "webpackConfig": "./webpack.config.js" }, "styleModule": "style/index.js" -} \ No newline at end of file +} diff --git a/pyproject.toml b/pyproject.toml index 5cf16d6..35c6456 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,5 +1,5 @@ [build-system] -requires = ["jupyter_packaging~=0.4.0", "jupyterlab~=2.0", "setuptools>=40.8.0", "wheel"] +requires = ["jupyter_packaging~=0.7.9", "jupyterlab~=3.0", "setuptools>=40.8.0", "wheel"] build-backend = "setuptools.build_meta" [tool.black] diff --git a/webpack.config.js b/webpack.config.js new file mode 100644 index 0000000..7f6473e --- /dev/null +++ b/webpack.config.js @@ -0,0 +1,6 @@ +module.exports = { + experiments: { + topLevelAwait: true, + asyncWebAssembly: true, + } +}; From 1efd3976a7cf08b5bf28da55875f6d8c3cfdcf63 Mon Sep 17 00:00:00 2001 From: Matthew Turk Date: Sat, 6 Feb 2021 14:47:41 -0600 Subject: [PATCH 06/18] First pass at eslintify --- src/index.ts | 2 +- src/plugin.ts | 52 +++++------ src/version.ts | 2 +- src/widgyts.ts | 242 ++++++++++++++++++++++++++++++------------------- 4 files changed, 173 insertions(+), 125 deletions(-) diff --git a/src/index.ts b/src/index.ts index 6de4005..5d7aae4 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1 +1 @@ -export * from './widgyts'; \ No newline at end of file +export * from './widgyts'; diff --git a/src/plugin.ts b/src/plugin.ts index 7f5b745..d89fbdf 100644 --- a/src/plugin.ts +++ b/src/plugin.ts @@ -1,38 +1,32 @@ -import { - Application, IPlugin -} from '@lumino/application'; +import { Application, IPlugin } from '@lumino/application'; -import { - Widget -} from '@lumino/widgets'; +import { Widget } from '@lumino/widgets'; -import { - IJupyterWidgetRegistry -} from '@jupyter-widgets/base'; +import { IJupyterWidgetRegistry } from '@jupyter-widgets/base'; import * as widgytsExports from './widgyts'; -import { - MODULE_NAME, - MODULE_VERSION -} from './version'; -const EXTENSION_ID = MODULE_NAME + ":plugin"; -console.log("widgyts version " + MODULE_VERSION); -console.log("widgyts module " + MODULE_NAME); +import { MODULE_NAME, MODULE_VERSION } from './version'; +const EXTENSION_ID = MODULE_NAME + ':plugin'; +console.log('widgyts version ' + MODULE_VERSION); +console.log('widgyts module ' + MODULE_NAME); -const widgytsPlugin: IPlugin, void> = { - id: EXTENSION_ID, - requires: [IJupyterWidgetRegistry], - activate: activateWidgetExtension, - autoStart: true -} as unknown as IPlugin, void>; +const widgytsPlugin: IPlugin, void> = ({ + id: EXTENSION_ID, + requires: [IJupyterWidgetRegistry], + activate: activateWidgetExtension, + autoStart: true +} as unknown) as IPlugin, void>; export default widgytsPlugin; -function activateWidgetExtension(app: Application, registry: IJupyterWidgetRegistry): void { - registry.registerWidget({ - name: MODULE_NAME, - version: MODULE_VERSION, - exports: widgytsExports, - }); -} \ No newline at end of file +function activateWidgetExtension( + app: Application, + registry: IJupyterWidgetRegistry +): void { + registry.registerWidget({ + name: MODULE_NAME, + version: MODULE_VERSION, + exports: widgytsExports + }); +} diff --git a/src/version.ts b/src/version.ts index 8b74c74..fea7d54 100644 --- a/src/version.ts +++ b/src/version.ts @@ -4,4 +4,4 @@ const data = require('../package.json'); export const MODULE_VERSION = data.version; -export const MODULE_NAME = data.name; \ No newline at end of file +export const MODULE_NAME = data.name; diff --git a/src/widgyts.ts b/src/widgyts.ts index b02b3bb..acee382 100644 --- a/src/widgyts.ts +++ b/src/widgyts.ts @@ -1,6 +1,15 @@ -import { DOMWidgetModel, ISerializers, WidgetModel, unpack_models } from '@jupyter-widgets/base'; +import { + DOMWidgetModel, + ISerializers, + WidgetModel, + unpack_models +} from '@jupyter-widgets/base'; import { CanvasView, CanvasModel } from 'ipycanvas'; -import type { FixedResolutionBuffer, ColormapCollection, VariableMesh } from '@data-exp-lab/yt-tools'; +import type { + FixedResolutionBuffer, + ColormapCollection, + VariableMesh +} from '@data-exp-lab/yt-tools'; import { MODULE_NAME, MODULE_VERSION } from './version'; const _yt_tools = import('@data-exp-lab/yt-tools'); @@ -16,7 +25,7 @@ function deserializeArray(dataview: DataView | null) { return new Float64Array(dataview.buffer); } -/* +/* * We have this as we can potentially have more than one FRB for a variable mesh * */ @@ -46,7 +55,7 @@ export class VariableMeshModel extends DOMWidgetModel { this.get('pdy'), this.get('val') ); - }) + }); } static serializers: ISerializers = { @@ -55,9 +64,8 @@ export class VariableMeshModel extends DOMWidgetModel { pdx: { serialize: serializeArray, deserialize: deserializeArray }, py: { serialize: serializeArray, deserialize: deserializeArray }, pdy: { serialize: serializeArray, deserialize: deserializeArray }, - val: { serialize: serializeArray, deserialize: deserializeArray }, - - } + val: { serialize: serializeArray, deserialize: deserializeArray } + }; px: Float64Array; pdx: Float64Array; @@ -66,20 +74,19 @@ export class VariableMeshModel extends DOMWidgetModel { val: Float64Array; variable_mesh: VariableMesh; - static model_name = "VariableMeshModel"; + static model_name = 'VariableMeshModel'; static model_module = MODULE_NAME; static model_module_version = MODULE_VERSION; } interface FRBViewBounds { - x_low: number, - x_high: number, - y_low: number, - y_high: number + x_low: number; + x_high: number; + y_low: number; + y_high: number; } export class FRBModel extends DOMWidgetModel { - defaults() { return { ...super.defaults(), @@ -104,8 +111,7 @@ export class FRBModel extends DOMWidgetModel { static serializers: ISerializers = { ...DOMWidgetModel.serializers, variable_mesh_model: { deserialize: unpack_models } - } - + }; sizeChanged() { this.width = this.get('width'); @@ -116,26 +122,31 @@ export class FRBModel extends DOMWidgetModel { calculateViewBounds(): FRBViewBounds { this.view_width = this.get('view_width'); this.view_center = this.get('view_center'); - let hwidths: [number, number] = [ - this.view_width[0] / 2, this.view_width[1] / 2]; - let bounds = - { - x_low: this.view_center[0] - hwidths[0], - x_high: this.view_center[0] + hwidths[0], - y_low: this.view_center[1] - hwidths[1], - y_high: this.view_center[1] + hwidths[1] - }; + const hwidths: [number, number] = [ + this.view_width[0] / 2, + this.view_width[1] / 2 + ]; + const bounds = { + x_low: this.view_center[0] - hwidths[0], + x_high: this.view_center[0] + hwidths[0], + y_low: this.view_center[1] - hwidths[1], + y_high: this.view_center[1] + hwidths[1] + }; return bounds; } async depositDataBuffer(variable_mesh_model: VariableMeshModel) { - let bounds: FRBViewBounds = this.calculateViewBounds(); - let yt_tools = await _yt_tools; + const bounds: FRBViewBounds = this.calculateViewBounds(); + const yt_tools = await _yt_tools; this.frb = new yt_tools.FixedResolutionBuffer( - this.width, this.height, - bounds.x_low, bounds.x_high, bounds.y_low, bounds.y_high); - this.frb.deposit(variable_mesh_model.variable_mesh, - this.data_buffer); + this.width, + this.height, + bounds.x_low, + bounds.x_high, + bounds.y_low, + bounds.y_high + ); + this.frb.deposit(variable_mesh_model.variable_mesh, this.data_buffer); return this.data_buffer; } @@ -147,7 +158,7 @@ export class FRBModel extends DOMWidgetModel { view_center: [number, number]; view_width: [number, number]; - static model_name = "FRBModel" + static model_name = 'FRBModel'; static model_module = MODULE_NAME; static model_module_version = MODULE_VERSION; } @@ -165,7 +176,7 @@ export class WidgytsCanvasModel extends CanvasModel { min_val: undefined, max_val: undefined, is_log: true, - colormap_name: "viridis", + colormap_name: 'viridis', colormaps: null, frb_model: null, variable_mesh_model: null, @@ -173,11 +184,11 @@ export class WidgytsCanvasModel extends CanvasModel { image_data: undefined, _dirty_frb: false, _dirty_bitmap: false - } + }; } initialize(attributes: any, options: any) { - super.initialize(attributes, options) + super.initialize(attributes, options); this.frb_model = this.get('frb_model'); this.variable_mesh_model = this.get('variable_mesh_model'); this.colormaps = this.get('colormaps'); @@ -188,7 +199,7 @@ export class WidgytsCanvasModel extends CanvasModel { frb_model: { deserialize: unpack_models }, variable_mesh_model: { deserialize: unpack_models }, colormaps: { deserialize: unpack_models } - } + }; min_val: number; max_val: number; @@ -200,10 +211,10 @@ export class WidgytsCanvasModel extends CanvasModel { _dirty_frb: boolean; _dirty_bitmap: boolean; - static view_name = "WidgytsCanvasView"; + static view_name = 'WidgytsCanvasView'; static view_module = MODULE_NAME; static view_module_version = MODULE_VERSION; - static model_name = "WidgytsCanvasModel"; + static model_name = 'WidgytsCanvasModel'; static model_module = MODULE_NAME; static model_module_version = MODULE_VERSION; } @@ -234,24 +245,36 @@ export class WidgytsCanvasView extends CanvasView { frbWidth: [number, number]; setupEventListeners() { - this.model.frb_model.on_some_change(['width', 'height'], - this.resizeFromFRB, this); - this.model.frb_model.on_some_change(['view_center', 'view_width'], - this.dirtyFRB, this); - this.model.on_some_change(['_dirty_frb', '_dirty_bitmap'], - this.updateBitmap, this); - this.model.on_some_change(['min_val', 'max_val', 'colormap_name', - 'is_log'], this.dirtyBitmap, this); - this.canvas.addEventListener("wheel", this.conductZoom.bind(this)); - this.canvas.addEventListener("mousedown", this.startDrag.bind(this)); - this.canvas.addEventListener("mousemove", this.conductDrag.bind(this)); - window.addEventListener("mouseup", this.endDrag.bind(this)); + this.model.frb_model.on_some_change( + ['width', 'height'], + this.resizeFromFRB, + this + ); + this.model.frb_model.on_some_change( + ['view_center', 'view_width'], + this.dirtyFRB, + this + ); + this.model.on_some_change( + ['_dirty_frb', '_dirty_bitmap'], + this.updateBitmap, + this + ); + this.model.on_some_change( + ['min_val', 'max_val', 'colormap_name', 'is_log'], + this.dirtyBitmap, + this + ); + this.canvas.addEventListener('wheel', this.conductZoom.bind(this)); + this.canvas.addEventListener('mousedown', this.startDrag.bind(this)); + this.canvas.addEventListener('mousemove', this.conductDrag.bind(this)); + window.addEventListener('mouseup', this.endDrag.bind(this)); } conductZoom(event: WheelEvent) { event.preventDefault(); - let view_width: [number, number] = this.model.frb_model.get("view_width"); - let n_units: number = 0; + const view_width: [number, number] = this.model.frb_model.get('view_width'); + let n_units = 0; if (event.deltaMode == event.DOM_DELTA_PIXEL) { // let's say we have 10 units per image n_units = event.deltaY / (this.frbWidth[1] / 10); @@ -262,32 +285,44 @@ export class WidgytsCanvasView extends CanvasView { // yeah i don't know return; } - let zoomFactor: number = 1.1 ** n_units; - let new_view_width: [number, number] = [view_width[0] * zoomFactor, view_width[1] * zoomFactor]; - this.model.frb_model.set("view_width", new_view_width); + const zoomFactor: number = 1.1 ** n_units; + const new_view_width: [number, number] = [ + view_width[0] * zoomFactor, + view_width[1] * zoomFactor + ]; + this.model.frb_model.set('view_width', new_view_width); this.model.frb_model.save_changes(); } startDrag(event: MouseEvent) { this.drag = true; this.dragStart = [event.offsetX, event.offsetY]; - this.dragStartCenter = this.model.frb_model.get("view_center"); + this.dragStartCenter = this.model.frb_model.get('view_center'); } conductDrag(event: MouseEvent) { - if (!this.drag) return; - let shiftValue: [number, number] = [event.offsetX - this.dragStart[0], event.offsetY - this.dragStart[1]]; + if (!this.drag) { + return; + } + const shiftValue: [number, number] = [ + event.offsetX - this.dragStart[0], + event.offsetY - this.dragStart[1] + ]; // Now we shift the actual center - let view_width: [number, number] = this.model.frb_model.get("view_width"); - let dx = view_width[0] / this.frbWidth[0]; // note these are FRB dims, which are *pixel* dims, not display dims - let dy = view_width[1] / this.frbWidth[1] * -1; // origin is upper left, so flip dy - let new_view_center: [number, number] = [this.dragStartCenter[0] - dx * shiftValue[0], - this.dragStartCenter[1] - dy * shiftValue[1]]; - this.model.frb_model.set("view_center", new_view_center); + const view_width: [number, number] = this.model.frb_model.get('view_width'); + const dx = view_width[0] / this.frbWidth[0]; // note these are FRB dims, which are *pixel* dims, not display dims + const dy = (view_width[1] / this.frbWidth[1]) * -1; // origin is upper left, so flip dy + const new_view_center: [number, number] = [ + this.dragStartCenter[0] - dx * shiftValue[0], + this.dragStartCenter[1] - dy * shiftValue[1] + ]; + this.model.frb_model.set('view_center', new_view_center); } endDrag(event: MouseEvent) { - if (!this.drag) return; + if (!this.drag) { + return; + } this.drag = false; this.model.frb_model.save_changes(); } @@ -301,18 +336,18 @@ export class WidgytsCanvasView extends CanvasView { } async initializeArrays() { - this.regenerateBuffer(); // This will stick stuff into the FRB's data buffer - this.resizeFromFRB(); // This will create image_buffer and image_data + this.regenerateBuffer(); // This will stick stuff into the FRB's data buffer + this.resizeFromFRB(); // This will create image_buffer and image_data await this.createBitmap(); // This creates a bitmap array and normalizes } updateCanvas() { - /* + /* * We don't call super.updateCanvas here, and we just re-do what it does. * This means we'll have to update it when the base class changes, but it * also means greater control. */ - this.clear() + this.clear(); if (this.image_bitmap !== undefined) { //console.log("Drawing this.image_bitmap"); this.ctx.drawImage(this.image_bitmap, 0, 0); @@ -324,7 +359,9 @@ export class WidgytsCanvasView extends CanvasView { } async updateBitmap() { - if (this.locked) return; + if (this.locked) { + return; + } //console.log("Locking."); this.locked = true; //console.log("Update bitmap"); @@ -345,13 +382,13 @@ export class WidgytsCanvasView extends CanvasView { //console.log("resizeFromFRB"); if (this.model.frb_model !== null && this.ctx !== null) { //console.log("frb initialized; creating new clamped array and image"); - let width = this.model.frb_model.get('width'); - let height = this.model.frb_model.get('height'); + const width = this.model.frb_model.get('width'); + const height = this.model.frb_model.get('height'); this.frbWidth = [width, height]; - let npix = width * height; + const npix = width * height; // Times four so that we have one for *each* channel :) this.image_buffer = new Uint8ClampedArray(npix * 4); - this.image_data = this.ctx.createImageData(width, height) + this.image_data = this.ctx.createImageData(width, height); } } @@ -363,19 +400,23 @@ export class WidgytsCanvasView extends CanvasView { } async createBitmap() { - /* + /* * This needs to make sure our deposition is up to date, * normalize it, and then re-set our image data - */ + */ /* Need to normalize here somehow */ //console.log("Creating bitmap."); - await this.model.colormaps.normalize(this.model.get('colormap_name'), - this.model.frb_model.data_buffer, this.image_buffer, - this.model.get('min_val'), this.model.get('max_val'), - this.model.get('is_log')); + await this.model.colormaps.normalize( + this.model.get('colormap_name'), + this.model.frb_model.data_buffer, + this.image_buffer, + this.model.get('min_val'), + this.model.get('max_val'), + this.model.get('is_log') + ); this.image_data.data.set(this.image_buffer); - let nx = this.model.frb_model.get('width'); - let ny = this.model.frb_model.get('height'); + const nx = this.model.frb_model.get('width'); + const ny = this.model.frb_model.get('height'); /* This has to be called every time image_data changes */ this.image_bitmap = await createImageBitmap(this.image_data, 0, 0, nx, ny); this.model.set('_dirty_bitmap', false); @@ -391,8 +432,8 @@ export class ColormapContainerModel extends WidgetModel { _initialized: false, _model_name: ColormapContainerModel.model_name, _model_module: ColormapContainerModel.model_module, - _model_module_version: ColormapContainerModel.model_module_version, - } + _model_module_version: ColormapContainerModel.model_module_version + }; } initialize(attributes: any, options: any) { @@ -400,23 +441,36 @@ export class ColormapContainerModel extends WidgetModel { this.colormap_values = this.get('colormap_values'); } - async normalize(colormap_name: string, data_array: Float64Array, - output_array: Uint8ClampedArray, min_val: number, max_val: number, - take_log: boolean) { + async normalize( + colormap_name: string, + data_array: Float64Array, + output_array: Uint8ClampedArray, + min_val: number, + max_val: number, + take_log: boolean + ) { if (!this._initialized) { await this.setupColormaps(); } - let unclamped: Uint8Array = new Uint8Array(output_array.buffer); - this.colormaps.normalize(colormap_name, data_array, - unclamped, min_val, max_val, take_log); + const unclamped: Uint8Array = new Uint8Array(output_array.buffer); + this.colormaps.normalize( + colormap_name, + data_array, + unclamped, + min_val, + max_val, + take_log + ); } private async setupColormaps() { - if (this._initialized) return; - let yt_tools = await _yt_tools; + if (this._initialized) { + return; + } + const yt_tools = await _yt_tools; this.colormaps = new yt_tools.ColormapCollection(); - for (let [name, values] of Object.entries(this.colormap_values)) { - let arr_values: Uint8Array = Uint8Array.from(values); + for (const [name, values] of Object.entries(this.colormap_values)) { + const arr_values: Uint8Array = Uint8Array.from(values); this.colormaps.add_colormap(name, arr_values); } this._initialized = true; @@ -425,7 +479,7 @@ export class ColormapContainerModel extends WidgetModel { colormap_values: Object; colormaps: ColormapCollection; _initialized: boolean; - static model_name = "ColormapContainerModel"; + static model_name = 'ColormapContainerModel'; static model_module = MODULE_NAME; static model_module_version = MODULE_VERSION; } From f095080fcb4f23dac066ba82a8bfeb72dabd70a5 Mon Sep 17 00:00:00 2001 From: Matthew Turk Date: Sat, 6 Feb 2021 15:15:58 -0600 Subject: [PATCH 07/18] Updating eslint --- src/version.ts | 2 +- src/widgyts.ts | 74 ++++++++++++++++++++++++++------------------------ 2 files changed, 39 insertions(+), 37 deletions(-) diff --git a/src/version.ts b/src/version.ts index fea7d54..781ad51 100644 --- a/src/version.ts +++ b/src/version.ts @@ -1,4 +1,4 @@ -const data = require('../package.json'); +const data = import('../package.json'); /* As seen in the ipycanvas repository */ diff --git a/src/widgyts.ts b/src/widgyts.ts index acee382..173629e 100644 --- a/src/widgyts.ts +++ b/src/widgyts.ts @@ -13,11 +13,11 @@ import type { import { MODULE_NAME, MODULE_VERSION } from './version'; const _yt_tools = import('@data-exp-lab/yt-tools'); -function serializeArray(array: Float64Array) { +function serializeArray(array: Float64Array): DataView { return new DataView(array.buffer.slice(0)); } -function deserializeArray(dataview: DataView | null) { +function deserializeArray(dataview: DataView | null): Float64Array | null { if (dataview === null) { return null; } @@ -30,7 +30,7 @@ function deserializeArray(dataview: DataView | null) { * */ export class VariableMeshModel extends DOMWidgetModel { - defaults() { + defaults(): any { return { ...super.defaults(), _model_name: VariableMeshModel.model_name, @@ -45,7 +45,7 @@ export class VariableMeshModel extends DOMWidgetModel { }; } - initialize(attributes: any, options: any) { + initialize(attributes: any, options: any): void { super.initialize(attributes, options); _yt_tools.then(yt_tools => { this.variable_mesh = new yt_tools.VariableMesh( @@ -79,7 +79,7 @@ export class VariableMeshModel extends DOMWidgetModel { static model_module_version = MODULE_VERSION; } -interface FRBViewBounds { +interface IFRBViewBounds { x_low: number; x_high: number; y_low: number; @@ -87,7 +87,7 @@ interface FRBViewBounds { } export class FRBModel extends DOMWidgetModel { - defaults() { + defaults(): any { return { ...super.defaults(), _model_name: FRBModel.model_name, @@ -103,7 +103,7 @@ export class FRBModel extends DOMWidgetModel { }; } - initialize(attributes: any, options: any) { + initialize(attributes: any, options: any): void { super.initialize(attributes, options); this.on_some_change(['width', 'height'], this.sizeChanged, this); this.sizeChanged(); @@ -113,20 +113,20 @@ export class FRBModel extends DOMWidgetModel { variable_mesh_model: { deserialize: unpack_models } }; - sizeChanged() { + sizeChanged(): void { this.width = this.get('width'); this.height = this.get('height'); this.data_buffer = new Float64Array(this.width * this.height); } - calculateViewBounds(): FRBViewBounds { + calculateViewBounds(): IFRBViewBounds { this.view_width = this.get('view_width'); this.view_center = this.get('view_center'); const hwidths: [number, number] = [ this.view_width[0] / 2, this.view_width[1] / 2 ]; - const bounds = { + const bounds = { x_low: this.view_center[0] - hwidths[0], x_high: this.view_center[0] + hwidths[0], y_low: this.view_center[1] - hwidths[1], @@ -135,8 +135,10 @@ export class FRBModel extends DOMWidgetModel { return bounds; } - async depositDataBuffer(variable_mesh_model: VariableMeshModel) { - const bounds: FRBViewBounds = this.calculateViewBounds(); + async depositDataBuffer( + variable_mesh_model: VariableMeshModel + ): Float64Array { + const bounds: IFRBViewBounds = this.calculateViewBounds(); const yt_tools = await _yt_tools; this.frb = new yt_tools.FixedResolutionBuffer( this.width, @@ -164,7 +166,7 @@ export class FRBModel extends DOMWidgetModel { } export class WidgytsCanvasModel extends CanvasModel { - defaults() { + defaults(): any { return { ...super.defaults(), _model_name: WidgytsCanvasModel.model_name, @@ -187,7 +189,7 @@ export class WidgytsCanvasModel extends CanvasModel { }; } - initialize(attributes: any, options: any) { + initialize(attributes: any, options: any): void { super.initialize(attributes, options); this.frb_model = this.get('frb_model'); this.variable_mesh_model = this.get('variable_mesh_model'); @@ -220,7 +222,7 @@ export class WidgytsCanvasModel extends CanvasModel { } export class WidgytsCanvasView extends CanvasView { - render() { + render(): void { /* This is where we update stuff! * Render in the base class will set up the ctx, but also calls * updateCanvas, so we need to check before calling anything in there. @@ -244,7 +246,7 @@ export class WidgytsCanvasView extends CanvasView { dragStartCenter: [number, number]; frbWidth: [number, number]; - setupEventListeners() { + setupEventListeners(): void { this.model.frb_model.on_some_change( ['width', 'height'], this.resizeFromFRB, @@ -271,17 +273,17 @@ export class WidgytsCanvasView extends CanvasView { window.addEventListener('mouseup', this.endDrag.bind(this)); } - conductZoom(event: WheelEvent) { + conductZoom(event: WheelEvent): void { event.preventDefault(); const view_width: [number, number] = this.model.frb_model.get('view_width'); let n_units = 0; - if (event.deltaMode == event.DOM_DELTA_PIXEL) { + if (event.deltaMode === event.DOM_DELTA_PIXEL) { // let's say we have 10 units per image n_units = event.deltaY / (this.frbWidth[1] / 10); - } else if (event.deltaMode == event.DOM_DELTA_LINE) { + } else if (event.deltaMode === event.DOM_DELTA_LINE) { // two lines per unit let's say n_units = event.deltaY / 2; - } else if (event.deltaMode == event.DOM_DELTA_PAGE) { + } else if (event.deltaMode === event.DOM_DELTA_PAGE) { // yeah i don't know return; } @@ -294,13 +296,13 @@ export class WidgytsCanvasView extends CanvasView { this.model.frb_model.save_changes(); } - startDrag(event: MouseEvent) { + startDrag(event: MouseEvent): void { this.drag = true; this.dragStart = [event.offsetX, event.offsetY]; this.dragStartCenter = this.model.frb_model.get('view_center'); } - conductDrag(event: MouseEvent) { + conductDrag(event: MouseEvent): void { if (!this.drag) { return; } @@ -319,7 +321,7 @@ export class WidgytsCanvasView extends CanvasView { this.model.frb_model.set('view_center', new_view_center); } - endDrag(event: MouseEvent) { + endDrag(event: MouseEvent): void { if (!this.drag) { return; } @@ -327,21 +329,21 @@ export class WidgytsCanvasView extends CanvasView { this.model.frb_model.save_changes(); } - dirtyBitmap() { + dirtyBitmap(): void { this.model.set('_dirty_bitmap', true); } - dirtyFRB() { + dirtyFRB(): void { this.model.set('_dirty_frb', true); } - async initializeArrays() { + async initializeArrays(): Promise { this.regenerateBuffer(); // This will stick stuff into the FRB's data buffer this.resizeFromFRB(); // This will create image_buffer and image_data await this.createBitmap(); // This creates a bitmap array and normalizes } - updateCanvas() { + updateCanvas(): void { /* * We don't call super.updateCanvas here, and we just re-do what it does. * This means we'll have to update it when the base class changes, but it @@ -358,7 +360,7 @@ export class WidgytsCanvasView extends CanvasView { } } - async updateBitmap() { + async updateBitmap(): Promise { if (this.locked) { return; } @@ -378,7 +380,7 @@ export class WidgytsCanvasView extends CanvasView { this.locked = false; } - resizeFromFRB() { + resizeFromFRB(): void { //console.log("resizeFromFRB"); if (this.model.frb_model !== null && this.ctx !== null) { //console.log("frb initialized; creating new clamped array and image"); @@ -392,14 +394,14 @@ export class WidgytsCanvasView extends CanvasView { } } - regenerateBuffer() { + regenerateBuffer(): void { //console.log("regenerateBuffer"); this.model.frb_model.depositDataBuffer(this.model.variable_mesh_model); this.model.set('_dirty_frb', false); this.model.set('_dirty_bitmap', true); } - async createBitmap() { + async createBitmap(): Promise { /* * This needs to make sure our deposition is up to date, * normalize it, and then re-set our image data @@ -425,7 +427,7 @@ export class WidgytsCanvasView extends CanvasView { } export class ColormapContainerModel extends WidgetModel { - defaults() { + defaults(): any { return { ...super.defaults(), colormap_values: {}, @@ -436,7 +438,7 @@ export class ColormapContainerModel extends WidgetModel { }; } - initialize(attributes: any, options: any) { + initialize(attributes: any, options: any): void { super.initialize(attributes, options); this.colormap_values = this.get('colormap_values'); } @@ -448,7 +450,7 @@ export class ColormapContainerModel extends WidgetModel { min_val: number, max_val: number, take_log: boolean - ) { + ): Promise { if (!this._initialized) { await this.setupColormaps(); } @@ -463,7 +465,7 @@ export class ColormapContainerModel extends WidgetModel { ); } - private async setupColormaps() { + private async setupColormaps(): Promise { if (this._initialized) { return; } @@ -476,7 +478,7 @@ export class ColormapContainerModel extends WidgetModel { this._initialized = true; } - colormap_values: Object; + colormap_values: unknown; colormaps: ColormapCollection; _initialized: boolean; static model_name = 'ColormapContainerModel'; From 41c7e81f021b6a7183d599f55ff4c845a8a35fa2 Mon Sep 17 00:00:00 2001 From: Matthew Turk Date: Sat, 6 Feb 2021 15:25:20 -0600 Subject: [PATCH 08/18] More eslint --- src/version.ts | 3 ++- src/widgyts.ts | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/version.ts b/src/version.ts index 781ad51..25f78d8 100644 --- a/src/version.ts +++ b/src/version.ts @@ -1,4 +1,5 @@ -const data = import('../package.json'); +// eslint-disable-next-line @typescript-eslint/no-var-requires +const data = require('../package.json'); /* As seen in the ipycanvas repository */ diff --git a/src/widgyts.ts b/src/widgyts.ts index 173629e..de7415d 100644 --- a/src/widgyts.ts +++ b/src/widgyts.ts @@ -1,3 +1,4 @@ +/* eslint-disable @typescript-eslint/explicit-module-boundary-types */ import { DOMWidgetModel, ISerializers, @@ -137,7 +138,7 @@ export class FRBModel extends DOMWidgetModel { async depositDataBuffer( variable_mesh_model: VariableMeshModel - ): Float64Array { + ): Promise { const bounds: IFRBViewBounds = this.calculateViewBounds(); const yt_tools = await _yt_tools; this.frb = new yt_tools.FixedResolutionBuffer( From 090d0206a04b284bbfc6d2558f61ff993eda7fc2 Mon Sep 17 00:00:00 2001 From: Matthew Turk Date: Sat, 6 Feb 2021 15:29:24 -0600 Subject: [PATCH 09/18] Fixing flake and black --- widgyts/_version.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/widgyts/_version.py b/widgyts/_version.py index b96d38b..d0bfd88 100644 --- a/widgyts/_version.py +++ b/widgyts/_version.py @@ -3,10 +3,11 @@ __all__ = ["__version__"] + def _fetchVersion(): HERE = Path(__file__).parent.resolve() - for settings in HERE.rglob("package.json"): + for settings in HERE.rglob("package.json"): try: with settings.open() as f: return json.load(f)["version"] @@ -15,5 +16,5 @@ def _fetchVersion(): raise FileNotFoundError(f"Could not find package.json under dir {HERE!s}") -__version__ = _fetchVersion() +__version__ = _fetchVersion() From b5972b88e5f89ed9ce5920b99baf8582713894cf Mon Sep 17 00:00:00 2001 From: Matthew Turk Date: Sat, 6 Feb 2021 15:32:58 -0600 Subject: [PATCH 10/18] Re-doing black --- widgyts/__init__.py | 14 ++++---------- widgyts/dataset_viewer.py | 2 +- 2 files changed, 5 insertions(+), 11 deletions(-) diff --git a/widgyts/__init__.py b/widgyts/__init__.py index 46e5e53..36f3b17 100644 --- a/widgyts/__init__.py +++ b/widgyts/__init__.py @@ -1,8 +1,8 @@ - import json from pathlib import Path from ._version import __version__ + EXTENSION_VERSION = "~" + __version__ from .dataset_viewer import ( @@ -13,24 +13,18 @@ ) from .image_canvas import * - HERE = Path(__file__).parent.resolve() with (HERE / "labextension" / "package.json").open() as fid: data = json.load(fid) -def _jupyter_labextension_paths(): - return [{ - "src": "labextension", - "dest": data["name"] - }] +def _jupyter_labextension_paths(): + return [{"src": "labextension", "dest": data["name"]}] def _jupyter_server_extension_points(): - return [{ - "module": "widgyts" - }] + return [{"module": "widgyts"}] def _load_jupyter_server_extension(server_app): diff --git a/widgyts/dataset_viewer.py b/widgyts/dataset_viewer.py index d51a23b..586df79 100644 --- a/widgyts/dataset_viewer.py +++ b/widgyts/dataset_viewer.py @@ -129,7 +129,7 @@ def _r2_falloff_default(self): def _colormap_texture_default(self): viridis = mcm.get_cmap("viridis") values = (viridis(np.mgrid[0.0:1.0:256j]) * 255).astype("u1") - values = np.stack([values[:, :],] * 256, axis=1).copy(order="C") + values = np.stack([values[:, :],] * 256, axis=1,).copy(order="C") colormap_texture = pythreejs.BaseDataTexture(data=values) return colormap_texture From 68dedaecc9cc2e2604012a43ea2b84b7613051bd Mon Sep 17 00:00:00 2001 From: Matthew Turk Date: Sat, 6 Feb 2021 15:39:16 -0600 Subject: [PATCH 11/18] Fixing dependencies --- setup.py | 31 +++++++++++++++++-------------- widgyts/__init__.py | 2 +- 2 files changed, 18 insertions(+), 15 deletions(-) diff --git a/setup.py b/setup.py index 33f97ba..daca780 100644 --- a/setup.py +++ b/setup.py @@ -4,21 +4,21 @@ import json from pathlib import Path +import setuptools from jupyter_packaging import ( + combine_commands, create_cmdclass, - install_npm, ensure_targets, - combine_commands, - skip_if_exists + install_npm, + skip_if_exists, ) -import setuptools HERE = Path(__file__).parent.resolve() # The name of the project name = "widgyts" -lab_path = (HERE / name / "labextension") +lab_path = HERE / name / "labextension" # Representative files that should exist after a successful build jstargets = [ @@ -32,20 +32,17 @@ labext_name = "@yt-project/yt-widgets" data_files_spec = [ - ("share/jupyter/labextensions/%s" % labext_name, str(lab_path), "**"), - ("share/jupyter/labextensions/%s" % labext_name, str(HERE), "install.json"),("etc/jupyter/jupyter_server_config.d", - "jupyter-config", "widgyts.json"), - + (f"share/jupyter/labextensions/{labext_name}", str(lab_path), "**"), + (f"share/jupyter/labextensions/{labext_name}", str(HERE), "install.json"), + ("etc/jupyter/jupyter_server_config.d", "jupyter-config", "widgyts.json"), ] -cmdclass = create_cmdclass("jsdeps", - package_data_spec=package_data_spec, - data_files_spec=data_files_spec +cmdclass = create_cmdclass( + "jsdeps", package_data_spec=package_data_spec, data_files_spec=data_files_spec ) js_command = combine_commands( - install_npm(HERE, build_cmd="build:prod", npm=["jlpm"]), - ensure_targets(jstargets), + install_npm(HERE, build_cmd="build:prod", npm=["jlpm"]), ensure_targets(jstargets), ) is_repo = (HERE / ".git").exists() @@ -72,6 +69,12 @@ packages=setuptools.find_packages(), install_requires=[ "jupyterlab~=3.0", + "ipycanvas>=0.4.7", + "ipywidgets>=7.5.1", + "numpy>=1.14", + "traitlets>=4.3.3", + "yt>=3.5.1", + "pythreejs>=2.2.0", ], zip_safe=False, include_package_data=True, diff --git a/widgyts/__init__.py b/widgyts/__init__.py index 36f3b17..5406249 100644 --- a/widgyts/__init__.py +++ b/widgyts/__init__.py @@ -34,4 +34,4 @@ def _load_jupyter_server_extension(server_app): import mimetypes mimetypes.add_type("application/wasm", ".wasm") - lab_app.log.info("Registered application/wasm MIME type") + server_app.log.info("Registered application/wasm MIME type") From 9f7bd790def024ae256b1a9cebf7869c45562cdb Mon Sep 17 00:00:00 2001 From: Matthew Turk Date: Sat, 6 Feb 2021 15:46:57 -0600 Subject: [PATCH 12/18] Use egg link for yt 4 --- setup.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/setup.py b/setup.py index daca780..76a18cb 100644 --- a/setup.py +++ b/setup.py @@ -73,9 +73,10 @@ "ipywidgets>=7.5.1", "numpy>=1.14", "traitlets>=4.3.3", - "yt>=3.5.1", + "yt>=4.0.dev0", "pythreejs>=2.2.0", ], + dependency_links=["https://github.com/yt-project/yt/tarball/main#egg=yt-4.0.dev0",], zip_safe=False, include_package_data=True, python_requires=">=3.6", From 8529748737e92c249f9df9b751945e6363875a3f Mon Sep 17 00:00:00 2001 From: Matthew Turk Date: Sat, 6 Feb 2021 15:52:30 -0600 Subject: [PATCH 13/18] Manually install in build.yml --- .github/workflows/build.yml | 1 + setup.py | 1 - 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 8446012..3844c8b 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -50,6 +50,7 @@ jobs: run: | jlpm jlpm run eslint:check + python -m pip install https://github.com/yt-project/yt.git python -m pip install . jupyter server extension list 2>&1 | grep -ie "widgyts.*OK" diff --git a/setup.py b/setup.py index 76a18cb..441bb38 100644 --- a/setup.py +++ b/setup.py @@ -76,7 +76,6 @@ "yt>=4.0.dev0", "pythreejs>=2.2.0", ], - dependency_links=["https://github.com/yt-project/yt/tarball/main#egg=yt-4.0.dev0",], zip_safe=False, include_package_data=True, python_requires=">=3.6", From e832292b9c10ee8477f8647fcf2335a65858d7ad Mon Sep 17 00:00:00 2001 From: Matthew Turk Date: Sat, 6 Feb 2021 15:54:55 -0600 Subject: [PATCH 14/18] Argh, copy paste. --- .github/workflows/build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 3844c8b..52e87d9 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -50,7 +50,7 @@ jobs: run: | jlpm jlpm run eslint:check - python -m pip install https://github.com/yt-project/yt.git + python -m pip install git+https://github.com/yt-project/yt.git python -m pip install . jupyter server extension list 2>&1 | grep -ie "widgyts.*OK" From c128b24596b3427da93645dfd7822dc05de1e08d Mon Sep 17 00:00:00 2001 From: Matthew Turk Date: Sun, 7 Feb 2021 08:53:22 -0600 Subject: [PATCH 15/18] Changes to dependencies --- package.json | 46 ++++++++++++++++++++++++++++++++++++---------- 1 file changed, 36 insertions(+), 10 deletions(-) diff --git a/package.json b/package.json index 0370d02..7c30bfe 100644 --- a/package.json +++ b/package.json @@ -65,21 +65,47 @@ "@jupyterlab/mainmenu": "^3.0.3", "@jupyterlab/services": "^6.0.3", "@lumino/widgets": "^1.16.1", - "@types/node": "^14.0.5", + "@jupyter-widgets/base": "^1.1.10 || ^2 || ^3", + "@jupyter-widgets/widgets": "^1.1.10 || ^2 || ^3", + "@types/node": "^10.11.6", "ipycanvas": "^0.4.7" }, "devDependencies": { "@jupyterlab/builder": "^3.0.0", - "@typescript-eslint/eslint-plugin": "^4.8.1", - "@typescript-eslint/parser": "^4.8.1", - "eslint": "^7.14.0", - "eslint-config-prettier": "^6.15.0", + "@phosphor/application": "^1.6.0", + "@phosphor/widgets": "^1.6.0", + "@types/expect.js": "^0.3.29", + "@types/mocha": "^5.2.5", + "@types/node": "^10.11.6", + "@types/webpack-env": "^1.13.6", + "@typescript-eslint/eslint-plugin": "^3.6.0", + "@typescript-eslint/parser": "^3.6.0", + "acorn": "^7.2.0", + "css-loader": "^3.2.0", + "eslint": "^7.4.0", + "eslint-config-prettier": "^6.11.0", "eslint-plugin-prettier": "^3.1.4", - "mkdirp": "^1.0.3", - "npm-run-all": "^4.1.5", - "prettier": "^2.1.1", - "rimraf": "^3.0.2", - "typescript": "~4.1.3" + "expect.js": "^0.3.1", + "fs-extra": "^7.0.0", + "karma": "^3.1.0", + "karma-chrome-launcher": "^2.2.0", + "karma-firefox-launcher": "^1.1.0", + "karma-ie-launcher": "^1.0.0", + "karma-mocha": "^1.3.0", + "karma-mocha-reporter": "^2.2.5", + "karma-typescript": "^5.0.3", + "karma-typescript-es6-transform": "^5.0.3", + "mkdirp": "^0.5.1", + "mocha": "^5.2.0", + "npm-run-all": "^4.1.3", + "prettier": "^2.0.5", + "rimraf": "^2.6.2", + "source-map-loader": "^0.2.4", + "style-loader": "^1.0.0", + "ts-loader": "^5.2.1", + "typescript": "^4.1.3", + "webpack": "^4.20.2", + "webpack-cli": "^3.1.2" }, "sideEffects": [ "style/*.css", From ea487726710845cab6dd69dc282043c391434847 Mon Sep 17 00:00:00 2001 From: Matthew Turk Date: Sun, 7 Feb 2021 08:58:03 -0600 Subject: [PATCH 16/18] Removing non-existent dependencies --- package.json | 2 -- 1 file changed, 2 deletions(-) diff --git a/package.json b/package.json index 7c30bfe..fc69193 100644 --- a/package.json +++ b/package.json @@ -65,8 +65,6 @@ "@jupyterlab/mainmenu": "^3.0.3", "@jupyterlab/services": "^6.0.3", "@lumino/widgets": "^1.16.1", - "@jupyter-widgets/base": "^1.1.10 || ^2 || ^3", - "@jupyter-widgets/widgets": "^1.1.10 || ^2 || ^3", "@types/node": "^10.11.6", "ipycanvas": "^0.4.7" }, From 1d3270de158a3618d65aa9374726272bea63ba9a Mon Sep 17 00:00:00 2001 From: Matthew Turk Date: Sun, 7 Feb 2021 10:35:23 -0600 Subject: [PATCH 17/18] Now it works for me, just fine. --- examples/galaxy_display.ipynb | 10 ++++------ package.json | 14 ++++++++++---- src/plugin.ts | 27 ++++++++++----------------- src/widgyts.ts | 8 ++++---- 4 files changed, 28 insertions(+), 31 deletions(-) diff --git a/examples/galaxy_display.ipynb b/examples/galaxy_display.ipynb index c83f5f0..51c5fc7 100644 --- a/examples/galaxy_display.ipynb +++ b/examples/galaxy_display.ipynb @@ -33,12 +33,10 @@ { "cell_type": "code", "execution_count": null, - "metadata": { - "scrolled": false - }, + "metadata": {}, "outputs": [], "source": [ - "ds = yt.load(\"IsolatedGalaxy/galaxy0030/galaxy0030\")\n", + "ds = yt.load_sample(\"IsolatedGalaxy\")\n", "s = ds.r[:,:,0.5]\n", "ss = s.display(\"density\")\n", "ss" @@ -61,9 +59,9 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.6.5" + "version": "3.9.1" } }, "nbformat": 4, - "nbformat_minor": 2 + "nbformat_minor": 4 } diff --git a/package.json b/package.json index fc69193..8f99a49 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@yt-project/yt-widgets", - "version": "0.4.0dev0", + "version": "0.4.0", "description": "A Custom Jupyter Widget Library for Interactive Visualization with yt", "author": "Data Exploration Lab", "contributors": [ @@ -64,9 +64,9 @@ "@jupyterlab/coreutils": "^5.0.2", "@jupyterlab/mainmenu": "^3.0.3", "@jupyterlab/services": "^6.0.3", - "@lumino/widgets": "^1.16.1", + "@jupyter-widgets/base": "^1.1.10 || ^2 || ^3 || ^4", "@types/node": "^10.11.6", - "ipycanvas": "^0.4.7" + "ipycanvas": "^0.8.2" }, "devDependencies": { "@jupyterlab/builder": "^3.0.0", @@ -122,7 +122,13 @@ }, "extension": "lib/plugin", "outputDir": "widgyts/labextension", - "webpackConfig": "./webpack.config.js" + "webpackConfig": "./webpack.config.js", + "sharedPackages": { + "@jupyter-widgets/base": { + "bundled": false, + "singleton": true + } + } }, "styleModule": "style/index.js" } diff --git a/src/plugin.ts b/src/plugin.ts index d89fbdf..a7d0057 100644 --- a/src/plugin.ts +++ b/src/plugin.ts @@ -1,6 +1,4 @@ -import { Application, IPlugin } from '@lumino/application'; - -import { Widget } from '@lumino/widgets'; +import { JupyterFrontEndPlugin, JupyterFrontEnd } from '@jupyterlab/application'; import { IJupyterWidgetRegistry } from '@jupyter-widgets/base'; @@ -11,22 +9,17 @@ const EXTENSION_ID = MODULE_NAME + ':plugin'; console.log('widgyts version ' + MODULE_VERSION); console.log('widgyts module ' + MODULE_NAME); -const widgytsPlugin: IPlugin, void> = ({ +const widgytsPlugin: JupyterFrontEndPlugin = { id: EXTENSION_ID, requires: [IJupyterWidgetRegistry], - activate: activateWidgetExtension, + activate: (app: JupyterFrontEnd, registry: IJupyterWidgetRegistry): void => { + registry.registerWidget({ + name: MODULE_NAME, + version: MODULE_VERSION, + exports: widgytsExports + }); + }, autoStart: true -} as unknown) as IPlugin, void>; +}; export default widgytsPlugin; - -function activateWidgetExtension( - app: Application, - registry: IJupyterWidgetRegistry -): void { - registry.registerWidget({ - name: MODULE_NAME, - version: MODULE_VERSION, - exports: widgytsExports - }); -} diff --git a/src/widgyts.ts b/src/widgyts.ts index de7415d..ea8f232 100644 --- a/src/widgyts.ts +++ b/src/widgyts.ts @@ -198,7 +198,7 @@ export class WidgytsCanvasModel extends CanvasModel { } static serializers: ISerializers = { - ...DOMWidgetModel.serializers, + ...CanvasModel.serializers, frb_model: { deserialize: unpack_models }, variable_mesh_model: { deserialize: unpack_models }, colormaps: { deserialize: unpack_models } @@ -268,9 +268,9 @@ export class WidgytsCanvasView extends CanvasView { this.dirtyBitmap, this ); - this.canvas.addEventListener('wheel', this.conductZoom.bind(this)); - this.canvas.addEventListener('mousedown', this.startDrag.bind(this)); - this.canvas.addEventListener('mousemove', this.conductDrag.bind(this)); + this.el.addEventListener('wheel', this.conductZoom.bind(this)); + this.el.addEventListener('mousedown', this.startDrag.bind(this)); + this.el.addEventListener('mousemove', this.conductDrag.bind(this)); window.addEventListener('mouseup', this.endDrag.bind(this)); } From 8c782c43e974f402a6649112f298f394d369f131 Mon Sep 17 00:00:00 2001 From: Matthew Turk Date: Sun, 7 Feb 2021 10:37:52 -0600 Subject: [PATCH 18/18] Prettify --- src/plugin.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/plugin.ts b/src/plugin.ts index a7d0057..390ca5a 100644 --- a/src/plugin.ts +++ b/src/plugin.ts @@ -1,4 +1,7 @@ -import { JupyterFrontEndPlugin, JupyterFrontEnd } from '@jupyterlab/application'; +import { + JupyterFrontEndPlugin, + JupyterFrontEnd +} from '@jupyterlab/application'; import { IJupyterWidgetRegistry } from '@jupyter-widgets/base';