Skip to content

Commit

Permalink
3D Scatter
Browse files Browse the repository at this point in the history
  • Loading branch information
martinRenou committed Jul 3, 2023
1 parent 23d1db5 commit b7a38d7
Show file tree
Hide file tree
Showing 8 changed files with 93 additions and 3 deletions.
11 changes: 11 additions & 0 deletions gluepyter/glue_session.py
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,17 @@ def _viewer_factory(
pass
except Exception as e:
widget = ErrorWidget(e, __file__)
elif view_type == "glue_vispy_viewers.scatter.scatter_viewer.VispyScatterViewer":
try:
widget = self.app.scatter3d(data=viewer_data)
for key, value in viewer_state.items():
try:
setattr(widget.state, key, value)
except Exception:
pass
except Exception as e:
widget = ErrorWidget(e, __file__)

return widget

def _read_view_state(
Expand Down
2 changes: 2 additions & 0 deletions src/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ export namespace CommandIDs {

export const new2DScatter = 'glue-control:new-2d-scatter-viewer';

export const new3DScatter = 'glue-control:new-3d-scatter-viewer';

export const newTable = 'glue-control:new-table-viewer';

export const openControlPanel = 'glue-control:open-control-panel';
Expand Down
1 change: 1 addition & 0 deletions src/leftPanel/data/datasetsWidget.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export class DatasetsWidget extends ReactWidget {
viewerSubmenu.title.iconClass = 'fa fa-caret-right';
viewerSubmenu.addItem({ command: CommandIDs.new1DHistogram });
viewerSubmenu.addItem({ command: CommandIDs.new2DScatter });
viewerSubmenu.addItem({ command: CommandIDs.new3DScatter });
viewerSubmenu.addItem({ command: CommandIDs.new2DImage });
viewerSubmenu.addItem({ command: CommandIDs.newTable });
this._menu.addItem({ type: 'submenu', submenu: viewerSubmenu });
Expand Down
34 changes: 32 additions & 2 deletions src/leftPanel/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ function addCommands(
): void {
commands.addCommand(CommandIDs.new1DHistogram, {
label: '1D Histogram',
iconClass: 'fa fa-chart-bar',
iconClass: 'fa fa-chart-column',
execute: (args?: INewViewerArgs) => {
if (!controlModel.sharedModel) {
return;
Expand Down Expand Up @@ -53,7 +53,7 @@ function addCommands(

commands.addCommand(CommandIDs.new2DScatter, {
label: '2D Scatter',
iconClass: 'fa fa-circle',
iconClass: 'fa fa-chart-line',
execute: (args?: INewViewerArgs) => {
if (!controlModel.sharedModel) {
return;
Expand Down Expand Up @@ -81,6 +81,36 @@ function addCommands(
}
});

commands.addCommand(CommandIDs.new3DScatter, {
label: '3D Scatter',
iconClass: 'fa fa-chart-line',
execute: (args?: INewViewerArgs) => {
if (!controlModel.sharedModel) {
return;
}

const tabs = Object.keys(controlModel.sharedModel.tabs);
const focusedTab = controlModel.sharedModel.getSelectedTab() || 1;
const layer = args?.dataset || controlModel.selectedDataset;

if (focusedTab === 0) {
return;
}

controlModel.sharedModel.setTabItem(tabs[focusedTab - 1], UUID.uuid4(), {
_type: 'glue_vispy_viewers.scatter.scatter_viewer.VispyScatterViewer',
pos: args?.position || [0, 0],
session: 'Session',
size: args?.size || [600, 400],
state: {
values: {
layer
}
}
});
}
});

commands.addCommand(CommandIDs.new2DImage, {
label: '2D Image',
iconClass: 'fa fa-image',
Expand Down
5 changes: 4 additions & 1 deletion src/schemas/glue.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,10 @@
"items": {
"anyOf": [
{
"$ref": "./viewers/scatter.schema.json"
"$ref": "./viewers/3dscatter.schema.json"
},
{
"$ref": "./viewers/2dscatter.schema.json"
},
{
"$ref": "./viewers/histogram.schema.json"
Expand Down
File renamed without changes.
42 changes: 42 additions & 0 deletions src/schemas/viewers/3dscatter.schema.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
{
"type": "object",
"description": "Viewer::Scatter",
"title": "IGlueScatterViewer",
"required": ["_type", "layers", "pos", "session", "size", "state"],
"additionalProperties": false,
"properties": {
"_type": {
"const": "glue_vispy_viewers.scatter.scatter_viewer.VispyScatterViewer"
},
"layers": {
"type": "array",
"items": {
"type": "object"
}
},
"pos": {
"type": "array",
"items": {
"type": "number"
}
},
"session": {
"type": "string"
},
"size": {
"type": "array",
"items": {
"type": "number"
}
},
"state": {
"type": "object",
"additionalProperties": false,
"properties": {
"values": {
"type": "object"
}
}
}
}
}
1 change: 1 addition & 0 deletions src/viewPanel/sessionWidget.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ export class SessionWidget extends BoxPanel {
const items: IDict<string> = {
Histogram: CommandIDs.new1DHistogram,
'2D Scatter': CommandIDs.new2DScatter,
'3D Scatter': CommandIDs.new3DScatter,
'2D Image': CommandIDs.new2DImage,
Table: CommandIDs.newTable
};
Expand Down

0 comments on commit b7a38d7

Please sign in to comment.