Skip to content
This repository has been archived by the owner on Feb 28, 2024. It is now read-only.

Commit

Permalink
Pass in auth token
Browse files Browse the repository at this point in the history
  • Loading branch information
pkerpedjiev committed Aug 21, 2023
1 parent 81b5c3a commit b8c4e3e
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 28 deletions.
62 changes: 36 additions & 26 deletions higlass_widget/widget.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import hglib from "https://esm.sh/higlass@1.12?deps=react@17,react-dom@17,pixi.js@6"
import hglib from "https://esm.sh/higlass@1.12?deps=react@17,react-dom@17,pixi.js@6";

/**
* @param {{
Expand All @@ -7,34 +7,44 @@ import hglib from "https://esm.sh/higlass@1.12?deps=react@17,react-dom@17,pixi.j
* }} location
*/
function toPts({ xDomain, yDomain }) {
let [x, xe] = xDomain;
let [y, ye] = yDomain;
return [x, xe, y, ye];
let [x, xe] = xDomain;
let [y, ye] = yDomain;
return [x, xe, y, ye];
}

export async function render({ model, el }) {
let viewconf = JSON.parse(model.get("_viewconf"));
let api = await hglib.viewer(el, viewconf);
let viewconf = JSON.parse(model.get("_viewconf"));
let auth_token = model.get("_auth_token");

model.on("msg:custom", (msg) => {
msg = JSON.parse(msg);
let [fn, ...args] = msg;
api[fn](...args);
});
let api = await hglib.viewer(el, viewconf, { authToken: auth_token });

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);
});
}
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
);
});
}
}
8 changes: 6 additions & 2 deletions higlass_widget/widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,15 @@ class HiGlassWidget(anywidget.AnyWidget):
_css = "https://esm.sh/higlass@1.12/dist/hglib.css"
_viewconf = t.Unicode("null").tag(sync=True)

_auth_token = t.Unicode().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, **kwargs):
super().__init__(_viewconf=json.dumps(viewconf), **kwargs)
def __init__(self, viewconf: dict, auth_token=None, **kwargs):
super().__init__(
_viewconf=json.dumps(viewconf), _auth_token=auth_token, **kwargs
)

def reload(self, *items):
msg = json.dumps(["reload", items])
Expand Down

0 comments on commit b8c4e3e

Please sign in to comment.