Skip to content

Commit 8b7b74e

Browse files
3D Scatter (#107)
* 3D Scatter * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent d55b361 commit 8b7b74e

File tree

8 files changed

+94
-2
lines changed

8 files changed

+94
-2
lines changed

gluepyter/glue_session.py

+13
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,19 @@ def _viewer_factory(
267267
pass
268268
except Exception as e:
269269
widget = ErrorWidget(e, __file__)
270+
elif (
271+
view_type == "glue_vispy_viewers.scatter.scatter_viewer.VispyScatterViewer"
272+
):
273+
try:
274+
widget = self.app.scatter3d(data=viewer_data)
275+
for key, value in viewer_state.items():
276+
try:
277+
setattr(widget.state, key, value)
278+
except Exception:
279+
pass
280+
except Exception as e:
281+
widget = ErrorWidget(e, __file__)
282+
270283
return widget
271284

272285
def _read_view_state(

src/commands.ts

+2
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ export namespace CommandIDs {
1010

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

13+
export const new3DScatter = 'glue-control:new-3d-scatter-viewer';
14+
1315
export const newTable = 'glue-control:new-table-viewer';
1416

1517
export const openControlPanel = 'glue-control:open-control-panel';

src/leftPanel/data/datasetsWidget.tsx

+1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ export class DatasetsWidget extends ReactWidget {
3232
viewerSubmenu.title.iconClass = 'fa fa-caret-right';
3333
viewerSubmenu.addItem({ command: CommandIDs.new1DHistogram });
3434
viewerSubmenu.addItem({ command: CommandIDs.new2DScatter });
35+
viewerSubmenu.addItem({ command: CommandIDs.new3DScatter });
3536
viewerSubmenu.addItem({ command: CommandIDs.new2DImage });
3637
viewerSubmenu.addItem({ command: CommandIDs.newTable });
3738
this._menu.addItem({ type: 'submenu', submenu: viewerSubmenu });

src/leftPanel/plugin.ts

+31-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ function addCommands(
5353

5454
commands.addCommand(CommandIDs.new2DScatter, {
5555
label: '2D Scatter',
56-
iconClass: 'fa fa-circle',
56+
iconClass: 'fa fa-chart-line',
5757
execute: (args?: INewViewerArgs) => {
5858
if (!controlModel.sharedModel) {
5959
return;
@@ -81,6 +81,36 @@ function addCommands(
8181
}
8282
});
8383

84+
commands.addCommand(CommandIDs.new3DScatter, {
85+
label: '3D Scatter',
86+
iconClass: 'fa fa-chart-line',
87+
execute: (args?: INewViewerArgs) => {
88+
if (!controlModel.sharedModel) {
89+
return;
90+
}
91+
92+
const tabs = Object.keys(controlModel.sharedModel.tabs);
93+
const focusedTab = controlModel.sharedModel.getSelectedTab() || 1;
94+
const layer = args?.dataset || controlModel.selectedDataset;
95+
96+
if (focusedTab === 0) {
97+
return;
98+
}
99+
100+
controlModel.sharedModel.setTabItem(tabs[focusedTab - 1], UUID.uuid4(), {
101+
_type: 'glue_vispy_viewers.scatter.scatter_viewer.VispyScatterViewer',
102+
pos: args?.position || [0, 0],
103+
session: 'Session',
104+
size: args?.size || [600, 400],
105+
state: {
106+
values: {
107+
layer
108+
}
109+
}
110+
});
111+
}
112+
});
113+
84114
commands.addCommand(CommandIDs.new2DImage, {
85115
label: '2D Image',
86116
iconClass: 'fa fa-image',

src/schemas/glue.schema.json

+4-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,10 @@
5757
"items": {
5858
"anyOf": [
5959
{
60-
"$ref": "./viewers/scatter.schema.json"
60+
"$ref": "./viewers/3dscatter.schema.json"
61+
},
62+
{
63+
"$ref": "./viewers/2dscatter.schema.json"
6164
},
6265
{
6366
"$ref": "./viewers/histogram.schema.json"
+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
{
2+
"type": "object",
3+
"description": "Viewer::Scatter",
4+
"title": "IGlueScatterViewer",
5+
"required": ["_type", "layers", "pos", "session", "size", "state"],
6+
"additionalProperties": false,
7+
"properties": {
8+
"_type": {
9+
"const": "glue_vispy_viewers.scatter.scatter_viewer.VispyScatterViewer"
10+
},
11+
"layers": {
12+
"type": "array",
13+
"items": {
14+
"type": "object"
15+
}
16+
},
17+
"pos": {
18+
"type": "array",
19+
"items": {
20+
"type": "number"
21+
}
22+
},
23+
"session": {
24+
"type": "string"
25+
},
26+
"size": {
27+
"type": "array",
28+
"items": {
29+
"type": "number"
30+
}
31+
},
32+
"state": {
33+
"type": "object",
34+
"additionalProperties": false,
35+
"properties": {
36+
"values": {
37+
"type": "object"
38+
}
39+
}
40+
}
41+
}
42+
}

src/viewPanel/sessionWidget.ts

+1
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ export class SessionWidget extends BoxPanel {
101101
const items: IDict<string> = {
102102
Histogram: CommandIDs.new1DHistogram,
103103
'2D Scatter': CommandIDs.new2DScatter,
104+
'3D Scatter': CommandIDs.new3DScatter,
104105
'2D Image': CommandIDs.new2DImage,
105106
Table: CommandIDs.newTable
106107
};

0 commit comments

Comments
 (0)