-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: Trevor Manz <trevor.j.manz@gmail.com>
- Loading branch information
1 parent
b1292cd
commit a74443f
Showing
6 changed files
with
90 additions
and
6 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
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,37 @@ | ||
from __future__ import annotations | ||
|
||
import json | ||
import pathlib | ||
|
||
import anywidget | ||
import traitlets as t | ||
|
||
|
||
class HiGlassWidget(anywidget.AnyWidget): | ||
_esm = pathlib.Path(__file__).parent / "widget.js" | ||
_css = "https://esm.sh/higlass@1.12/dist/hglib.css" | ||
|
||
_viewconf = t.Dict(allow_none=False).tag(sync=True) | ||
_options = t.Dict().tag(sync=True) | ||
|
||
# readonly properties | ||
location = t.List(t.Union([t.Float(), t.Tuple()]), read_only=True).tag(sync=True) | ||
|
||
def __init__(self, viewconf: dict, **viewer_options): | ||
super().__init__(_viewconf=viewconf, _options=viewer_options) | ||
|
||
def reload(self, *items): | ||
msg = json.dumps(["reload", items]) | ||
self.send(msg) | ||
|
||
def zoom_to( | ||
self, | ||
view_id: str, | ||
start1: int, | ||
end1: int, | ||
start2: int | None = None, | ||
end2: int | None = None, | ||
animate_time: int = 500, | ||
): | ||
msg = json.dumps(["zoomTo", view_id, start1, end1, start2, end2, animate_time]) | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import hglib from "https://esm.sh/higlass@1.12?deps=react@17,react-dom@17,pixi.js@6"; | ||
|
||
/** | ||
* @param {{ | ||
* xDomain: [number, number], | ||
* yDomain: [number, number], | ||
* }} location | ||
*/ | ||
function toPts({ xDomain, yDomain }) { | ||
let [x, xe] = xDomain; | ||
let [y, ye] = yDomain; | ||
return [x, xe, y, ye]; | ||
} | ||
|
||
export async function render({ model, el }) { | ||
let viewconf = model.get("_viewconf"); | ||
let options = model.get("_options") ?? {}; | ||
let api = await hglib.viewer(el, viewconf, options); | ||
|
||
model.on("msg:custom", (msg) => { | ||
msg = JSON.parse(msg); | ||
let [fn, ...args] = msg; | ||
api[fn](...args); | ||
}); | ||
|
||
if (viewconf.views.length === 1) { | ||
api.on("location", (loc) => { | ||
model.set("location", toPts(loc)); | ||
model.save_changes(); | ||
}, viewconf.views[0].uid); | ||
} else { | ||
viewconf.views.forEach((view, idx) => { | ||
api.on("location", (loc) => { | ||
let copy = model.get("location").slice(); | ||
copy[idx] = toPts(loc); | ||
model.set("location", copy); | ||
model.save_changes(); | ||
}, view.uid); | ||
}); | ||
} | ||
} |