Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Askar's directional button first working implementation #2

Merged
merged 1 commit into from
Aug 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 17 additions & 18 deletions js/Untitled.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -30,22 +30,24 @@
},
{
"cell_type": "code",
"execution_count": 6,
"execution_count": 3,
"id": "94a44328-e9d9-4d23-9de8-0675159e136b",
"metadata": {},
"metadata": {
"scrolled": true
},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "85d59a3e5acb42c2aa45622bcc82ef13",
"model_id": "2a646e36ade645bfb741191ffb4baaaf",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"HBox(children=(VBox(children=(Button(button_style='primary', icon='arrows', layout=Layout(width='36px'), style…"
]
},
"execution_count": 6,
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
Expand Down Expand Up @@ -73,23 +75,12 @@
},
{
"cell_type": "code",
"execution_count": 11,
"execution_count": null,
"id": "653b8122-0ed6-4368-bb3e-4300541c8532",
"metadata": {
"tags": []
},
"outputs": [
{
"data": {
"text/plain": [
"[]"
]
},
"execution_count": 11,
"metadata": {},
"output_type": "execute_result"
}
],
"outputs": [],
"source": [
"p.children[1].children[0].dir_center_positions"
]
Expand All @@ -101,6 +92,14 @@
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"id": "cff4f3fb-bc6c-4f36-b0a1-5171a9adf637",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
Expand All @@ -119,7 +118,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.4"
"version": "3.11.9"
}
},
"nbformat": 4,
Expand Down
5 changes: 3 additions & 2 deletions js/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

57 changes: 54 additions & 3 deletions js/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -277,8 +277,9 @@
});

this.scatterplot = createScatterplot(initialOptions);
// this.scatterplot.setSelectionManager('directional');




if (!window.jupyterScatter.versionLog) {
// eslint-disable-next-line
console.log(
Expand All @@ -303,6 +304,8 @@
this.externalViewChangeHandlerBound = this.externalViewChangeHandler.bind(this);
this.viewChangeHandlerBound = this.viewChangeHandler.bind(this);
this.resizeHandlerBound = this.resizeHandler.bind(this);
//This is Askar's code added on Aug 22 to try out
//if (this.model.get(mouse))
this.scatterplot.subscribe('lassoEnd', ({ centerPositions }) => {
// eslint-disable-next-line
console.log("lassoEnd")
Expand Down Expand Up @@ -351,7 +354,29 @@
this.model.on('msg:custom', (event) => {
this.customEventHandler.call(this, event);
}, this);


// this.model.on("msg:custom", (msg) => {
// if (msg?.type === "setdirectional") this.scatterplot.setSelectionManager('directional');
//});

//BS Code I added for now - Askar
// this.model.on('change:mouse_mode', () => {
// const newMouseMode = this.model.get('mouse_mode');

// //Check if the new mouse mode is 'directional'
// if (newMouseMode === 'directional') {
// console.log('Directional Mode Activated');
// this.scatterplot.setSelectionManager('directional');

// //Subscribe to the 'dirEnd' event
// this.scatterplot.subscribe('dirEnd', ({ dircenterPositions }) => {
// console.log("dirEnd");
// console.log({ dircenterPositions});
// this.model.set("dir_center_positions", dircenterPositions);
// this.model.save_changes();
// })
// }});

this.colorCanvas();

this.getOuterDimensions();
Expand Down Expand Up @@ -394,11 +419,37 @@
}

customEventHandler(event) {
console.log("Event received: ", event.type);

Check failure on line 422 in js/src/index.js

View workflow job for this annotation

GitHub Actions / Test (3.8)

Unexpected console statement

Check failure on line 422 in js/src/index.js

View workflow job for this annotation

GitHub Actions / Test (3.9)

Unexpected console statement

Check failure on line 422 in js/src/index.js

View workflow job for this annotation

GitHub Actions / Test (3.10)

Unexpected console statement

Check failure on line 422 in js/src/index.js

View workflow job for this annotation

GitHub Actions / Test (3.11)

Unexpected console statement

Check failure on line 422 in js/src/index.js

View workflow job for this annotation

GitHub Actions / Test (3.12)

Unexpected console statement
if (event.type === this.eventTypes.TOOLTIP) {
if (event.index !== this.tooltipPointIdx && event.show !== true) return;
this.tooltipDataHandlers(event)
if (event.show) this.showTooltip(event.index);
}
//Handle directional mode - added by askar and andres
if (event.type === 'setdirectional') {
console.log("switching to directional mode");

Check failure on line 430 in js/src/index.js

View workflow job for this annotation

GitHub Actions / Test (3.8)

Unexpected console statement

Check failure on line 430 in js/src/index.js

View workflow job for this annotation

GitHub Actions / Test (3.9)

Unexpected console statement

Check failure on line 430 in js/src/index.js

View workflow job for this annotation

GitHub Actions / Test (3.10)

Unexpected console statement

Check failure on line 430 in js/src/index.js

View workflow job for this annotation

GitHub Actions / Test (3.11)

Unexpected console statement

Check failure on line 430 in js/src/index.js

View workflow job for this annotation

GitHub Actions / Test (3.12)

Unexpected console statement
if (!this.scatterplot) return;
this.scatterplot.setSelectionManager('directional');
}
//Handle lasso mode - added by askar
if (event.type === 'setlasso') {
console.log("switching to lasso mode");

Check failure on line 436 in js/src/index.js

View workflow job for this annotation

GitHub Actions / Test (3.8)

Unexpected console statement

Check failure on line 436 in js/src/index.js

View workflow job for this annotation

GitHub Actions / Test (3.9)

Unexpected console statement

Check failure on line 436 in js/src/index.js

View workflow job for this annotation

GitHub Actions / Test (3.10)

Unexpected console statement

Check failure on line 436 in js/src/index.js

View workflow job for this annotation

GitHub Actions / Test (3.11)

Unexpected console statement

Check failure on line 436 in js/src/index.js

View workflow job for this annotation

GitHub Actions / Test (3.12)

Unexpected console statement
if (!this.scatterplot) return;
this.scatterplot.setSelectionManager('lasso');
}
//Handle pan zoom mode - added by askar
if (event.type === 'setpanzoom') {
console.log("switching to pan zoom mode");

Check failure on line 442 in js/src/index.js

View workflow job for this annotation

GitHub Actions / Test (3.8)

Unexpected console statement

Check failure on line 442 in js/src/index.js

View workflow job for this annotation

GitHub Actions / Test (3.9)

Unexpected console statement

Check failure on line 442 in js/src/index.js

View workflow job for this annotation

GitHub Actions / Test (3.10)

Unexpected console statement

Check failure on line 442 in js/src/index.js

View workflow job for this annotation

GitHub Actions / Test (3.11)

Unexpected console statement

Check failure on line 442 in js/src/index.js

View workflow job for this annotation

GitHub Actions / Test (3.12)

Unexpected console statement
if (!this.scatterplot) return;
this.scatterplot.setSelectionManager('panzoom');
}
//Handle rotate mode - added by askar
// if (event.type === 'setrotate') {
// console.log("switching to rotate mode");
// if (!this.scatterplot) return;
// this.scatterplot.setSelectionManager('rotate');
// }
//
if (event.type === this.eventTypes.VIEW_RESET) {
if (!this.scatterplot) return;
if (event.area) {
Expand Down
1 change: 1 addition & 0 deletions jscatter/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ class MouseModes(Enum):
PAN_ZOOM = 'panZoom'
LASSO = 'lasso'
ROTATE = 'rotate'
DIRECTIONAL = 'directional'

class Auto(Enum):
AUTO = 'auto'
Expand Down
17 changes: 15 additions & 2 deletions jscatter/widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -340,9 +340,22 @@ def click_handler(b):
if mouse_mode == 'lasso':
# Change selection manager in js code to lasso
print("use lasso")
self.send({ "type": "setlasso"})
elif mouse_mode == 'directional':
# Change selection manager in js code to lasso
# Change selection manager in js code to directional
print("use directional")
self.send({ "type": "setdirectional"})
#added by askar Aug 23,2024 -not sure if necessary to be honest because it might interfere with normal functionality
elif mouse_mode == 'panZoom':
# Change selection manager in js code to panZoom
print("use panZoom")
self.send({ "type": "setpanZoom"})
# elif mouse_mode == 'rotate':
# # Change selection manager in js code to rotate
# print("use rotate")
# self.send({ "type": "setrotate"})
else:
print(mouse_mode)

def change_handler(change):
button.button_style = 'primary' if change['new'] == mouse_mode else ''
Expand All @@ -367,7 +380,7 @@ def show(self):
),
self.create_mouse_mode_toggle_button(
mouse_mode='directional',
icon='crosshairs',
icon='bullseye',
tooltip='Activate directional selection',
),
self.create_mouse_mode_toggle_button(
Expand Down
Loading