Skip to content

Commit af0b2b1

Browse files
committed
[feat] add neuroj('gui') to interactively browse neurojson.io
1 parent 9980f9b commit af0b2b1

File tree

2 files changed

+81
-0
lines changed

2 files changed

+81
-0
lines changed

jsonpath.m

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,8 @@
132132
else
133133
if (isKey(input, pathname))
134134
obj = {input(pathname)};
135+
elseif (isKey(input, decodevarname(pathname)))
136+
obj = {input(decodevarname(pathname))};
135137
end
136138
end
137139
if (~exist('obj', 'var') || deepscan)

neuroj.m

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
% regular expression pattern
2727
% - if dataset is a struct, find database using
2828
% the _find API
29+
% 'gui': start a GUI and interactively browse datasets
2930
%
3031
% admin commands (require database admin credentials):
3132
% 'put': create database, create dataset under a dataset, or
@@ -40,6 +41,8 @@
4041
% jsonstring: the JSON raw data from the URL
4142
%
4243
% example:
44+
% neuroj('gui') % start neuroj client in the GUI mode
45+
%
4346
% res = neuroj('list') % list all databases under res.database
4447
% res = neuroj('list', 'cotilab') % list all dataset under res.dataset
4548
% res = neuroj('list', 'cotilab', 'CSF_Neurophotonics_2025') % list all versions
@@ -66,6 +69,80 @@
6669
return
6770
end
6871

72+
function loaddb(src, event)
73+
dbs = neuroj('list');
74+
set(lsDb, 'String', (cellfun(@(x) x.id, dbs.database, 'UniformOutput', false)));
75+
end
76+
77+
function loadds(src, event, keydata)
78+
get(fmMain, 'SelectionType');
79+
if strcmp(get(fmMain, 'SelectionType'), 'open')
80+
idx = get(src, 'value');
81+
dbs = get(src, 'string');
82+
dslist = neuroj('list', dbs{idx});
83+
set(lsDs, 'string', {dslist.dataset.id});
84+
set(lsDb, 'tag', dbs{idx});
85+
end
86+
end
87+
88+
function loaddsdata(src, event, keydata)
89+
get(fmMain, 'SelectionType');
90+
if strcmp(get(fmMain, 'SelectionType'), 'open')
91+
idx = get(src, 'value');
92+
dbs = get(src, 'string');
93+
dbid = get(lsDb, 'tag');
94+
datasets = jdict(neuroj('get', dbid, dbs{idx}));
95+
set(lsJSON, 'string', cellfun(@(x) decodevarname(x), datasets.keys(), 'UniformOutput', false), 'value', 1);
96+
set(lsJSON, 'userdata', datasets);
97+
set(lsJSON, 'tag', '');
98+
end
99+
end
100+
101+
function expandjsontree(src, event, keydata)
102+
if (~isa(get(lsJSON, 'userdata'), 'jdict'))
103+
return
104+
end
105+
get(fmMain, 'SelectionType');
106+
if strcmp(get(fmMain, 'SelectionType'), 'open')
107+
idx = get(src, 'value');
108+
dbs = get(src, 'string');
109+
rootpath = get(lsJSON, 'tag');
110+
datasets = get(lsJSON, 'userdata');
111+
if (isempty(rootpath))
112+
rootpath = '$';
113+
end
114+
if (strcmp(dbs{idx}, '..'))
115+
rootpath = regexprep(rootpath, '\[[^\]]+\]$', '');
116+
else
117+
rootpath = [rootpath '["' dbs{idx} '"]'];
118+
end
119+
120+
datasets = datasets.(rootpath);
121+
try
122+
subitem = cellfun(@(x) decodevarname(x), datasets.keys(), 'UniformOutput', false);
123+
if (~strcmp(rootpath, '$'))
124+
subitem = {'..', subitem{:}};
125+
end
126+
set(lsJSON, 'string', subitem, 'value', 1);
127+
set(lsJSON, 'tag', rootpath);
128+
catch
129+
end
130+
end
131+
end
132+
133+
if (nargin == 1 && strcmp(cmd, 'gui'))
134+
fmMain = figure;
135+
tbTool = uitoolbar(fmMain);
136+
btLoadDb = uipushtool(tbTool, 'ClickedCallback', @loaddb);
137+
if (~isoctavemesh)
138+
btLoadDb.CData = rand(40, 40, 3);
139+
end
140+
lsDb = uicontrol(fmMain, 'tooltipstring', 'Database', 'style', 'listbox', 'units', 'normalized', 'position', [0 0 1 / 5 1], 'Callback', @loadds, 'KeyPressFcn', @loadds);
141+
lsDs = uicontrol(fmMain, 'tooltipstring', 'Dataset', 'style', 'listbox', 'units', 'normalized', 'position', [1 / 5 0 1 / 4 1], 'Callback', @loaddsdata, 'KeyPressFcn', @loaddsdata);
142+
lsJSON = uicontrol(fmMain, 'tooltipstring', 'Data', 'style', 'listbox', 'units', 'normalized', 'position', [9 / 20 0 1 - 9 / 20 1], 'Callback', @expandjsontree, 'KeyPressFcn', @expandjsontree);
143+
return
144+
end
145+
69146
dbname = '';
70147
if (~isempty(varargin))
71148
dbname = varargin{1};
@@ -232,3 +309,5 @@
232309
end
233310
end
234311
end
312+
313+
end

0 commit comments

Comments
 (0)