-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
1,007 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,3 +16,4 @@ node_modules/ | |
_build/ | ||
generated/ | ||
gallery/ | ||
gosling/static/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
{ | ||
"lock": false, | ||
"nodeModulesDir": "auto", | ||
"tasks": { | ||
"dev": "deno run -A --node-modules-dir npm:esbuild --bundle --minify --loader:.css=text --format=esm --outfile=gosling/static/widget.js frontend/widget.ts --sourcemap=inline --watch", | ||
"build": "deno run -A --node-modules-dir npm:esbuild --bundle --minify --loader:.css=text --format=esm --outfile=gosling/static/widget.js frontend/widget.ts" | ||
}, | ||
"imports": { | ||
"@anywidget/types": "npm:@anywidget/types@^0.2.0", | ||
"gosling.js": "npm:gosling.js@^0.17.0" | ||
}, | ||
"fmt": { | ||
"useTabs": true | ||
}, | ||
"lint": { | ||
"rules": { | ||
"exclude": ["prefer-const"] | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import * as gosling from "gosling.js"; | ||
|
||
interface Model { | ||
_viewconf: string; | ||
} | ||
|
||
export default { | ||
async render({ model, el }: import("@anywidget/types").RenderProps<Model>) { | ||
const viewconf = JSON.parse(model.get("_viewconf")); | ||
const api = await gosling.embed(el, viewconf, { padding: 0 }); | ||
model.on("msg:custom", (msg) => { | ||
msg = JSON.parse(msg); | ||
console.log(msg); | ||
try { | ||
const [fn, ...args] = msg; | ||
// @ts-expect-error - This is a dynamic call | ||
api[fn](...args); | ||
} catch (e) { | ||
console.error(e); | ||
} | ||
}); | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import json | ||
import pathlib | ||
from typing import Any, Dict | ||
|
||
import anywidget | ||
import traitlets as t | ||
|
||
|
||
class GoslingWidget(anywidget.AnyWidget): | ||
_esm = pathlib.Path(__file__).parent / "static" / "widget.js" | ||
_viewconf = t.Unicode("null").tag(sync=True) | ||
|
||
location = t.List(t.Union([t.Float(), t.Tuple()]), read_only=True).tag(sync=True) | ||
|
||
def __init__(self, viewconf: Dict[str, Any], **kwargs): | ||
super().__init__(_viewconf=json.dumps(viewconf), **kwargs) | ||
|
||
def zoom_to(self, view_id: str, pos: str, padding: float = 0, duration: int = 1000): | ||
msg = json.dumps(["zoomTo", view_id, pos, padding, duration]) | ||
self.send(msg) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
"""A Hatchling plugin to build the gosling-widget frontend.""" | ||
|
||
import os | ||
import pathlib | ||
import subprocess | ||
|
||
from hatchling.builders.hooks.plugin.interface import BuildHookInterface | ||
|
||
ROOT = pathlib.Path(__file__).parent / ".." | ||
|
||
|
||
class QuakBuildHook(BuildHookInterface): | ||
"""Hatchling plugin to build the quak frontend.""" | ||
|
||
PLUGIN_NAME = "gosling-widget" | ||
|
||
def initialize(self, version: str, build_data: dict) -> None: | ||
"""Initialize the plugin.""" | ||
if os.getenv("SKIP_DENO_BUILD", "0") == "1": | ||
# Skip the build if the environment variable is set | ||
# Useful in CI/CD pipelines | ||
return | ||
|
||
if not (ROOT / "gosling/static/widget.js").exists(): | ||
subprocess.check_call(["deno", "task", "build"], cwd=ROOT) |