forked from helgestein/htAx
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplotSpecSliders.m
270 lines (218 loc) · 9.28 KB
/
plotSpecSliders.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
function plotSpecSliders(fig, ...
xAxis, yAxis, composition, scaling, ternHandles, specHandles, ECHandles)
%PLOTSPECSLIDERS plots the spec. data with sliders
fTernDiagram = ternHandles.fTernDiagram;
ternInfoOut = fTernDiagram.UserData;
fSpecPlot = specHandles.fSpecPlot;
specInfo = fSpecPlot.UserData;
figure(fig);
clf;
sliderPlot.fig = fig;
% set up the axes
% setting positions for the graphs
graphHeightFrac = 0.8;
graphVertPosFrac = 0.15;
graphHorPosFrac = 0.07;
graphWidthFrac = 0.8;
sliderWidthFrac = 0.02;
sliderVertWidthFrac = 0.01;
sliderPlot.dataAxes = axes(...
'Units', 'Normalized', ...
'Position', [graphHorPosFrac graphVertPosFrac ...
graphWidthFrac graphHeightFrac], ...
'XTick', [], 'YTick', [], ...
'Box', 'on');
sliderPlot.sliderAxes = axes(...
'Units', 'Normalized', ...
'Position', [graphHorPosFrac (graphVertPosFrac + graphHeightFrac) ...
graphWidthFrac sliderWidthFrac], ...
'XTick', [], 'YTick', [], ...
'YLim', [0 1], ...
'Box', 'on');
sliderPlot.sliderAxesVert = axes(...
'Units', 'Normalized', ...
'Position', [(graphHorPosFrac + graphWidthFrac) graphVertPosFrac ...
sliderVertWidthFrac graphHeightFrac], ...
'XTick', [], 'YTick', [], ...
'XLim', [0 1], ...
'Box', 'on');
Range.X = [min(xAxis) max(xAxis)];
Range.Y = [min(composition) max(composition)];
%maxComp = max(composition);
axes(sliderPlot.dataAxes);
[sComposition, ID] = sort(composition);
[x, y] = meshgrid(xAxis, sComposition);
if scaling == 2
yAxis = sqrt(yAxis);
elseif scaling == 3
yAxis = log10(yAxis);
end
figure(fig);
hold off;
sliderPlot.dataPlots = surf(x, y, yAxis(:, ID).');
shading('interp');
axis('tight');
view(2);
axes(sliderPlot.dataAxes);
xlabel('Angle (2\theta)');
constType = ternInfoOut.constType;
labels = ternInfoOut.labels;
if constType == 0
yCompLabel = labels.B;
elseif constType == 1
yCompLabel = labels.C;
else
yCompLabel = labels.A;
end
yCompLabel = strcat({'Fraction of '}, yCompLabel);
ylabel(yCompLabel);
set(sliderPlot.dataAxes, ...
'XTickMode', 'auto', 'XTickLabelMode', 'auto', ...
'YTickMode', 'auto', 'YTickLabelMode', 'auto');
set(sliderPlot.dataAxes, 'XLim', Range.X);
set(sliderPlot.dataAxes, 'YLim', Range.Y);
set(sliderPlot.fig, 'BusyAction', 'cancel');
setappdata(sliderPlot.fig, 'forcedclose', '0');
% horizontal slider
axes(sliderPlot.sliderAxes);
set(sliderPlot.sliderAxes, 'XLim', Range.X);
hold on;
sliderPlot.sliderLine = plot(Range.X, [.5 .5], '-r');
sliderPlot.sliderMarker = plot(Range.X(1), .5, 'rv', ...
'MarkerFaceColor', 'r', 'MarkerEdgeColor', 'r');
axes(sliderPlot.dataAxes)
hold on;
sliderPlot.angleMarker = ...
plot3([Range.X(1) Range.X(1)], get(sliderPlot.dataAxes, 'YLim'),...
[100000 100000], 'r', 'LineWidth', 2);
% vertical sliders
hold on;
axes(sliderPlot.sliderAxesVert);
set(sliderPlot.sliderAxesVert, 'YLim', Range.Y);
hold on;
sliderPlot.sliderLineVert = plot([.5 .5], Range.Y, '-r');
sliderPlot.sliderMarkerVert = plot(.5, Range.Y(1), '<', ...
'MarkerFaceColor', 'r', 'MarkerEdgeColor', 'r');
specInfo.valSliderVert1 = Range.Y(1);
sliderPlot.sliderMarkerVert2 = plot(.5, Range.Y(2), '<', ...
'MarkerFaceColor', 'r', 'MarkerEdgeColor', 'r');
specInfo.valSliderVert2 = Range.Y(2);
axes(sliderPlot.dataAxes);
sliderPlot.compMarker = ...
plot3(get(sliderPlot.dataAxes, 'XLim'), ...
[Range.Y(1) Range.Y(1)], [100000 100000], 'r', 'LineWidth', 2);
sliderPlot.compMarker2 = ...
plot3(get(sliderPlot.dataAxes, 'XLim'), ...
[Range.Y(2) Range.Y(2)], [100000 100000], 'r', 'LineWidth', 2);
% bring slider axes to the front
uistack(sliderPlot.sliderAxes, 'top');
uistack(sliderPlot.sliderAxesVert, 'top');
set(sliderPlot.sliderAxes, 'ButtonDownFcn', ...
{@sliderHorCallback, sliderPlot.sliderAxes, ternHandles, specHandles, xAxis, ECHandles});
set(sliderPlot.sliderLine, 'ButtonDownFcn', ...
{@sliderHorCallback, sliderPlot.sliderAxes, ternHandles, specHandles, xAxis, ECHandles});
set(sliderPlot.sliderMarker, 'ButtonDownFcn', ...
{@sliderHorCallback, sliderPlot.sliderAxes, ternHandles, specHandles, xAxis, ECHandles});
set(sliderPlot.sliderAxesVert, 'ButtonDownFcn', ...
{@sliderVertCallback, sliderPlot.sliderAxesVert, specHandles});
set(sliderPlot.sliderLineVert, 'ButtonDownFcn', ...
{@sliderVertCallback, sliderPlot.sliderAxesVert, specHandles});
set(sliderPlot.sliderMarkerVert, 'ButtonDownFcn', ...
{@sliderVertCallback, sliderPlot.sliderAxesVert, specHandles});
set(sliderPlot.sliderMarkerVert2, 'ButtonDownFcn', ...
{@sliderVertCallback, sliderPlot.sliderAxesVert, specHandles});
specInfo.sliderPlot = sliderPlot;
fSpecPlot.UserData = specInfo;
%% determine where horizontal slider is and adjust ternary plot
function sliderClickHor(src, evt, ternHandles, specHandles, xAxis, ECHandles)
figTern = ternHandles.fTernDiagram;
ternInfo = figTern.UserData;
figSpec = specHandles.fSpecPlot;
specInfoNest = figSpec.UserData;
sliderPlotNest = specInfoNest.sliderPlot;
selected = get(sliderPlotNest.sliderAxes, 'CurrentPoint');
sliderVal = selected(1, 1);
% find index of closest x value to the slider position
[~, angleIndex] = min(abs(xAxis - sliderVal));
specInfoNest.angleIndex = angleIndex;
% plot ternary diagram
specInfoNest.sliderPlot = sliderPlotNest;
figSpec.UserData = specInfoNest;
plotTernData(ternHandles, specHandles, ECHandles);
figSpec = specHandles.fSpecPlot;
specInfoNest = figSpec.UserData;
sliderPlotNest = specInfoNest.sliderPlot;
set(sliderPlotNest.sliderMarker, 'XData', sliderVal);
set(sliderPlotNest.angleMarker, 'XData', [sliderVal sliderVal]);
if ternInfo.ternPlotType == 0
set(ternInfo.textAngle, ...
'String', strcat({'Angle: '}, ...
num2str(specInfoNest.XRDData(angleIndex, 1))));
elseif ternInfo.ternPlotType == 1
set(ternInfo.textAngle, ...
'String', strcat({'Angle: '}, ...
num2str(specInfoNest.XRDData(angleIndex, 1))));
end
specInfoNest.sliderPlot = sliderPlotNest;
figSpec.UserData = specInfoNest;
end
%% determine where vertical slider is
function sliderClickVert(src, evt, specHandles)
figSpec = specHandles.fSpecPlot;
specInfoNest = figSpec.UserData;
sliderPlotNest = specInfoNest.sliderPlot;
slider1 = specInfoNest.valSliderVert1;
slider2 = specInfoNest.valSliderVert2;
selected = get(sliderPlotNest.sliderAxesVert, 'CurrentPoint');
sliderVal = selected(1, 2);
sliderNum = closerSlider(sliderVal, slider1, slider2);
if sliderNum == 1
set(sliderPlotNest.sliderMarkerVert, 'YData', sliderVal);
set(sliderPlotNest.compMarker, 'YData', [sliderVal sliderVal]);
specInfoNest.valSliderVert1 = sliderVal;
else
set(sliderPlotNest.sliderMarkerVert2, 'YData', sliderVal);
set(sliderPlotNest.compMarker2, 'YData', [sliderVal sliderVal]);
specInfoNest.valSliderVert2 = sliderVal;
end
specInfoNest.sliderPlot = sliderPlotNest;
figSpec.UserData = specInfoNest;
end
%% find which vertical slider is closer
function numCloser = closerSlider(sliderVal, slider1, slider2)
if abs(sliderVal - slider1) < abs(sliderVal - slider2)
numCloser = 1;
else
numCloser = 2;
end
end
%% vertical slider callback
function sliderVertCallback(src, evt, sb, specHandles)
parentfig = get(sb, 'Parent');
if parentfig ~= 0
set(parentfig, ...
'WindowButtonMotionFcn', {@sliderClickVert, specHandles}, ...
'WindowButtonUpFcn', {@buttonUpVert, parentfig});
sliderClickVert(src, evt, specHandles);
end
end
%% horizontal slider callback
function sliderHorCallback(src, evt, sb, ternHandles, specHandles, xAxis, ECHandles)
parentfig = get(sb, 'Parent');
if parentfig ~= 0
set(parentfig, ...
'WindowButtonMotionFcn', {@sliderClickHor, ...
ternHandles, specHandles, xAxis, ECHandles}, ...
'WindowButtonUpFcn', {@buttonUpHor, parentfig});
sliderClickHor(src, evt, ternHandles, specHandles, xAxis, ECHandles);
end
end
%% horizontal slider button up function
function buttonUpHor(src, evt, sb)
set(sb, 'WindowButtonMotionFcn', []);
end
%% vertical slider button up function
function buttonUpVert(src, evt, sb)
set(sb, 'WindowButtonMotionFcn', []);
end
end