Skip to content

Commit c6f4233

Browse files
authored
Add 1D profile support (#108)
1 parent 8b7b74e commit c6f4233

File tree

8 files changed

+90
-4
lines changed

8 files changed

+90
-4
lines changed

gluepyter/glue_session.py

+10
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,16 @@ def _viewer_factory(
279279
pass
280280
except Exception as e:
281281
widget = ErrorWidget(e, __file__)
282+
elif view_type == "glue.viewers.profile.state.ProfileLayerState":
283+
try:
284+
widget = self.app.profile1d(data=viewer_data)
285+
for key, value in viewer_state.items():
286+
try:
287+
setattr(widget.state, key, value)
288+
except Exception:
289+
pass
290+
except Exception as e:
291+
widget = ErrorWidget(e, __file__)
282292

283293
return widget
284294

src/commands.ts

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

77
export const new1DHistogram = 'glue-control:new-1d-histogram-viewer';
88

9+
export const new1DProfile = 'glue-control:new-1d-profile-viewer';
10+
911
export const new2DImage = 'glue-control:new-2d-image-viewer';
1012

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

src/leftPanel/data/datasetsWidget.tsx

+1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ export class DatasetsWidget extends ReactWidget {
3131
viewerSubmenu.title.label = 'New Viewer';
3232
viewerSubmenu.title.iconClass = 'fa fa-caret-right';
3333
viewerSubmenu.addItem({ command: CommandIDs.new1DHistogram });
34+
viewerSubmenu.addItem({ command: CommandIDs.new1DProfile });
3435
viewerSubmenu.addItem({ command: CommandIDs.new2DScatter });
3536
viewerSubmenu.addItem({ command: CommandIDs.new3DScatter });
3637
viewerSubmenu.addItem({ command: CommandIDs.new2DImage });

src/leftPanel/plugin.ts

+30
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,36 @@ function addCommands(
5151
}
5252
});
5353

54+
commands.addCommand(CommandIDs.new1DProfile, {
55+
label: '1D Profile',
56+
iconClass: 'fa fa-chart-line',
57+
execute: (args?: INewViewerArgs) => {
58+
if (!controlModel.sharedModel) {
59+
return;
60+
}
61+
62+
const tabs = Object.keys(controlModel.sharedModel.tabs);
63+
const focusedTab = controlModel.sharedModel.getSelectedTab() || 1;
64+
const layer = args?.dataset || controlModel.selectedDataset;
65+
66+
if (focusedTab === 0) {
67+
return;
68+
}
69+
70+
controlModel.sharedModel.setTabItem(tabs[focusedTab - 1], UUID.uuid4(), {
71+
_type: 'glue.viewers.profile.state.ProfileLayerState',
72+
pos: args?.position || [0, 0],
73+
session: 'Session',
74+
size: args?.size || [600, 400],
75+
state: {
76+
values: {
77+
layer
78+
}
79+
}
80+
});
81+
}
82+
});
83+
5484
commands.addCommand(CommandIDs.new2DScatter, {
5585
label: '2D Scatter',
5686
iconClass: 'fa fa-chart-line',
+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
{
2+
"type": "object",
3+
"description": "Viewer::Profile",
4+
"title": "IGlueProfileViewer",
5+
"required": ["_type", "layers", "pos", "session", "size", "state"],
6+
"additionalProperties": false,
7+
"properties": {
8+
"_type": {
9+
"const": "glue.viewers.profile.state.ProfileLayerState"
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/schemas/viewers/2dscatter.schema.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"type": "object",
3-
"description": "Viewer::Scatter",
4-
"title": "IGlueScatterViewer",
3+
"description": "Viewer::2DScatter",
4+
"title": "IGlue2DScatterViewer",
55
"required": ["_type", "layers", "pos", "session", "size", "state"],
66
"additionalProperties": false,
77
"properties": {

src/schemas/viewers/3dscatter.schema.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"type": "object",
3-
"description": "Viewer::Scatter",
4-
"title": "IGlueScatterViewer",
3+
"description": "Viewer::3DScatter",
4+
"title": "IGlue3DScatterViewer",
55
"required": ["_type", "layers", "pos", "session", "size", "state"],
66
"additionalProperties": false,
77
"properties": {

src/viewPanel/sessionWidget.ts

+1
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ export class SessionWidget extends BoxPanel {
100100

101101
const items: IDict<string> = {
102102
Histogram: CommandIDs.new1DHistogram,
103+
'1D Profile': CommandIDs.new1DProfile,
103104
'2D Scatter': CommandIDs.new2DScatter,
104105
'3D Scatter': CommandIDs.new3DScatter,
105106
'2D Image': CommandIDs.new2DImage,

0 commit comments

Comments
 (0)