Skip to content

Commit

Permalink
Send initial selections to Python in JupyterChart (#3172)
Browse files Browse the repository at this point in the history
  • Loading branch information
jonmmease authored Aug 28, 2023
1 parent 85c4cc4 commit 9b2b0d1
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions altair/jupyter/js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,17 +36,21 @@ export async function render({ model, el }) {

const initialSelections = {};
for (const selectionName of Object.keys(model.get("_vl_selections"))) {
const storeName = `${selectionName}_store`;
const selectionHandler = (_, value) => {
const newSelections = JSON.parse(JSON.stringify(model.get("_vl_selections"))) || {};
const store = JSON.parse(JSON.stringify(api.view.data(`${selectionName}_store`)));
const newSelections = cleanJson(model.get("_vl_selections") ?? {});
const store = cleanJson(api.view.data(storeName) ?? []);

newSelections[selectionName] = {value, store};
model.set("_vl_selections", newSelections);
model.save_changes();
};
api.view.addSignalListener(selectionName, debounce(selectionHandler, wait, {maxWait}));

initialSelections[selectionName] = {value: {}, store: []}
initialSelections[selectionName] = {
value: cleanJson(api.view.signal(selectionName) ?? {}),
store: cleanJson(api.view.data(storeName) ?? [])
}
}
model.set("_vl_selections", initialSelections);

Expand Down Expand Up @@ -78,3 +82,7 @@ export async function render({ model, el }) {
model.on('change:debounce_wait', reembed);
await reembed();
}

function cleanJson(data) {
return JSON.parse(JSON.stringify(data))
}

0 comments on commit 9b2b0d1

Please sign in to comment.