-
Notifications
You must be signed in to change notification settings - Fork 0
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
6 changed files
with
196 additions
and
21 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
// Callback when a user presses the button to update labels in the scatter plot Bokeh figure | ||
|
||
const selectedData = lasso_selection_source.data; | ||
const label = label_select.value; | ||
const labelColumn = label_column_select.value; | ||
|
||
console.log("Will write to these rows:", selectedData.ids); | ||
console.log("Will write this label:", label); | ||
console.log("Will write to this column:", labelColumn); | ||
|
||
const rowIds = selectedData.ids; | ||
|
||
if (typeof window.deeporigin !== "undefined") { | ||
// Reset selections for all the rows in question | ||
const resetChanges = rowIds.map(rowId => ({ | ||
rowId: rowId, | ||
fieldChangeEvents: [{ | ||
columnId: labelColumn, | ||
newValue: { selectedOptions: [] } | ||
}] | ||
})); | ||
|
||
deeporigin.dataHub.primaryDatabase.editRows({ changes: resetChanges }); | ||
|
||
// Write the new value | ||
const updateChanges = rowIds.map(rowId => ({ | ||
rowId: rowId, | ||
fieldChangeEvents: [{ | ||
columnId: labelColumn, | ||
newValue: { selectedOptions: [label] } | ||
}] | ||
})); | ||
|
||
deeporigin.dataHub.primaryDatabase.editRows({ changes: updateChanges }); | ||
} |
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,32 @@ | ||
// callback on lasso selection | ||
|
||
function debounce(func, wait) { | ||
let timeout; | ||
return function (...args) { | ||
const context = this; | ||
clearTimeout(timeout); | ||
timeout = setTimeout(() => func.apply(context, args), wait); | ||
}; | ||
} | ||
|
||
const processSelection = () => { | ||
const selected_indices = scatter_source.selected.indices; | ||
let selected_data = selected_indices.map(i => { | ||
let row = {}; | ||
for (const key in scatter_source.data) { | ||
row[key] = scatter_source.data[key][i]; | ||
} | ||
return row; | ||
}); | ||
|
||
const ids = selected_data.map(item => item.id); | ||
console.log("Lasso selected points data:", ids); | ||
|
||
lasso_selection_source.data.ids = ids; | ||
lasso_selection_source.change.emit(); | ||
|
||
}; | ||
|
||
|
||
const debouncedSelection = debounce(processSelection, 50); | ||
debouncedSelection(); |
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