Skip to content

Commit 9680476

Browse files
fix issue 242
1 parent 5721dc0 commit 9680476

File tree

4 files changed

+254
-40
lines changed

4 files changed

+254
-40
lines changed

plotly/plotlyfig.m

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -237,8 +237,6 @@
237237

238238
% plotly reference
239239
plotlyref = load('plotly_reference.mat');
240-
% rmfield(plotlyref.pr, 'xbins');
241-
% plotlyref.pr.xbins.size
242240

243241
% update the PlotlyRef property
244242
obj.PlotlyReference = plotlyref.pr;
@@ -481,6 +479,9 @@ function validate(obj)
481479

482480
% find axes of figure
483481
ax = findobj(obj.State.Figure.Handle,'Type','axes','-and',{'Tag','','-or','Tag','PlotMatrixBigAx','-or','Tag','PlotMatrixScatterAx', '-or','Tag','PlotMatrixHistAx'});
482+
if isempty(ax)
483+
ax = gca;
484+
end
484485

485486
%---------- checking the overlaping of the graphs ----------%
486487
temp_ax = ax; deleted_idx = 0;
@@ -515,6 +516,7 @@ function validate(obj)
515516
axrev = length(ax) - a + 1;
516517

517518
% set axis handle field
519+
% ax(axrev).XColor
518520
obj.State.Axis(a).Handle = ax(axrev);
519521

520522
% add title
@@ -608,23 +610,29 @@ function validate(obj)
608610

609611
% update axes
610612
for n = 1:obj.State.Figure.NumAxes
611-
updateAxis(obj,n);
613+
try
614+
updateAxis(obj,n);
615+
end
612616
end
613617

614618
% update plots
615619
for n = 1:obj.State.Figure.NumPlots
616620
updateData(obj,n);
617621

618-
if (strcmp(obj.data{1, n}.type, 'bar') && update_opac(length(ax)-n))
619-
obj.data{1, n}.opacity = 0.9;
620-
obj.data{1, n}.marker.color = 'rgb(0,113.985,188.955)';
622+
try
623+
if (strcmp(obj.data{n}.type, 'bar') && update_opac(length(ax)-n))
624+
obj.data{1, n}.opacity = 0.9;
625+
obj.data{1, n}.marker.color = 'rgb(0,113.985,188.955)';
626+
end
621627
end
622628

623629
end
624630

625631
% update annotations
626632
for n = 1:obj.State.Figure.NumTexts
627-
updateAnnotation(obj,n);
633+
try
634+
updateAnnotation(obj,n);
635+
end
628636
end
629637

630638
% update legends
@@ -866,7 +874,7 @@ function delete(obj)
866874
fnmod = fn;
867875

868876
try
869-
for d = 1:length(fn);
877+
for d = 1:length(fn)
870878

871879
% clean up axis keys
872880
if any(strfind(fn{d},'xaxis')) || any(strfind(fn{d},'yaxis'))

plotly/plotlyfig_aux/core/updateData.m

Lines changed: 32 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,11 @@
5151
case 'quivergroup'
5252
updateQuivergroup(obj, dataIndex);
5353
case 'scatter'
54-
updateScatter(obj, dataIndex);
54+
if strcmpi(obj.State.Axis(dataIndex).Handle.Type, 'polaraxes')
55+
updateScatterPolar(obj, dataIndex);
56+
else
57+
updateScatter(obj, dataIndex);
58+
end
5559
case 'scattergroup'
5660
updateScattergroup(obj, dataIndex);
5761
case 'stair'
@@ -84,38 +88,40 @@
8488

8589
%------------------------AXIS/DATA CLEAN UP-------------------------------%
8690

87-
%-AXIS INDEX-%
88-
axIndex = obj.getAxisIndex(obj.State.Plot(dataIndex).AssociatedAxis);
91+
try
92+
%-AXIS INDEX-%
93+
axIndex = obj.getAxisIndex(obj.State.Plot(dataIndex).AssociatedAxis);
8994

90-
%-CHECK FOR MULTIPLE AXES-%
91-
[xsource, ysource] = findSourceAxis(obj,axIndex);
95+
%-CHECK FOR MULTIPLE AXES-%
96+
[xsource, ysource] = findSourceAxis(obj,axIndex);
9297

93-
%-AXIS DATA-%
94-
eval(['xaxis = obj.layout.xaxis' num2str(xsource) ';']);
95-
eval(['yaxis = obj.layout.yaxis' num2str(ysource) ';']);
98+
%-AXIS DATA-%
99+
eval(['xaxis = obj.layout.xaxis' num2str(xsource) ';']);
100+
eval(['yaxis = obj.layout.yaxis' num2str(ysource) ';']);
96101

97-
%-------------------------------------------------------------------------%
102+
%---------------------------------------------------------------------%
98103

99-
% check for xaxis dates
100-
if strcmpi(xaxis.type, 'date')
101-
obj.data{dataIndex}.x = convertDate(obj.data{dataIndex}.x);
102-
end
104+
% check for xaxis dates
105+
if strcmpi(xaxis.type, 'date')
106+
obj.data{dataIndex}.x = convertDate(obj.data{dataIndex}.x);
107+
end
103108

104-
% check for xaxis categories
105-
if strcmpi(xaxis.type, 'category') && ...
106-
~strcmp(obj.data{dataIndex}.type,'box')
107-
obj.data{dataIndex}.x = get(obj.State.Plot(dataIndex).AssociatedAxis,'XTickLabel');
108-
end
109+
% check for xaxis categories
110+
if strcmpi(xaxis.type, 'category') && ...
111+
~strcmp(obj.data{dataIndex}.type,'box')
112+
obj.data{dataIndex}.x = get(obj.State.Plot(dataIndex).AssociatedAxis,'XTickLabel');
113+
end
109114

110-
% check for yaxis dates
111-
if strcmpi(yaxis.type, 'date')
112-
obj.data{dataIndex}.y = convertDate(obj.data{dataIndex}.y);
113-
end
115+
% check for yaxis dates
116+
if strcmpi(yaxis.type, 'date')
117+
obj.data{dataIndex}.y = convertDate(obj.data{dataIndex}.y);
118+
end
114119

115-
% check for yaxis categories
116-
if strcmpi(yaxis.type, 'category') && ...
117-
~strcmp(obj.data{dataIndex}.type,'box')
118-
obj.data{dataIndex}.y = get(obj.State.Plot(dataIndex).AssociatedAxis,'YTickLabel');
120+
% check for yaxis categories
121+
if strcmpi(yaxis.type, 'category') && ...
122+
~strcmp(obj.data{dataIndex}.type,'box')
123+
obj.data{dataIndex}.y = get(obj.State.Plot(dataIndex).AssociatedAxis,'YTickLabel');
124+
end
119125
end
120126

121127
%-------------------------------------------------------------------------%
Lines changed: 196 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,196 @@
1+
function updateScatterPolar(obj,scatterIndex)
2+
3+
%check: http://undocumentedmatlab.com/blog/undocumented-scatter-plot-behavior
4+
5+
%----SCATTER FIELDS----%
6+
7+
% x - [DONE]
8+
% y - [DONE]
9+
% r - [HANDLED BY SCATTER]
10+
% t - [HANDLED BY SCATTER]
11+
% mode - [DONE]
12+
% name - [DONE]
13+
% text - [NOT SUPPORTED IN MATLAB]
14+
% error_y - [HANDLED BY ERRORBAR]
15+
% error_x - [NOT SUPPORTED IN MATLAB]
16+
% textfont - [NOT SUPPORTED IN MATLAB]
17+
% textposition - [NOT SUPPORTED IN MATLAB]
18+
% xaxis [DONE]
19+
% yaxis [DONE]
20+
% showlegend [DONE]
21+
% stream - [HANDLED BY PLOTLYSTREAM]
22+
% visible [DONE]
23+
% type [DONE]
24+
% opacity ---[TODO]
25+
26+
% MARKER
27+
% marler.color - [DONE]
28+
% marker.size - [DONE]
29+
% marker.opacity - [NOT SUPPORTED IN MATLAB]
30+
% marker.colorscale - [NOT SUPPORTED IN MATLAB]
31+
% marker.sizemode - [DONE]
32+
% marker.sizeref - [DONE]
33+
% marker.maxdisplayed - [NOT SUPPORTED IN MATLAB]
34+
35+
% MARKER LINE
36+
% marker.line.color - [DONE]
37+
% marker.line.width - [DONE]
38+
% marker.line.dash - [NOT SUPPORTED IN MATLAB]
39+
% marker.line.opacity - [DONE]
40+
% marker.line.smoothing - [NOT SUPPORTED IN MATLAB]
41+
% marker.line.shape - [NOT SUPPORTED IN MATLAB]
42+
43+
% LINE
44+
% line.color - [NA]
45+
% line.width - [NA]
46+
% line.dash - [NA]
47+
% line.opacity [NA]
48+
% line.smoothing - [NOT SUPPORTED IN MATLAB]
49+
% line.shape - [NOT SUPPORTED IN MATLAB]
50+
% connectgaps - [NOT SUPPORTED IN MATLAB]
51+
% fill - [HANDLED BY AREA]
52+
% fillcolor - [HANDLED BY AREA]
53+
54+
%-AXIS INDEX-%
55+
axIndex = obj.getAxisIndex(obj.State.Plot(scatterIndex).AssociatedAxis);
56+
57+
%-SCATTER DATA STRUCTURE- %
58+
scatter_data = get(obj.State.Plot(scatterIndex).Handle);
59+
60+
%-------------------------------------------------------------------------%
61+
62+
%-scatterpolar type-%
63+
obj.data{scatterIndex}.type = 'scatterpolar';
64+
65+
%-------------------------------------------------------------------------%
66+
67+
%-scatter mode-%
68+
obj.data{scatterIndex}.mode = 'markers';
69+
70+
%-------------------------------------------------------------------------%
71+
72+
%-scatter visible-%
73+
obj.data{scatterIndex}.visible = strcmp(scatter_data.Visible,'on');
74+
75+
%-------------------------------------------------------------------------%
76+
77+
%-scatter name-%
78+
obj.data{scatterIndex}.name = scatter_data.DisplayName;
79+
80+
%-------------------------------------------------------------------------%
81+
82+
%-scatter patch data-%
83+
for m = 1:length(scatter_data)
84+
85+
%reverse counter
86+
n = length(scatter_data) - m + 1;
87+
88+
%---------------------------------------------------------------------%
89+
90+
%-scatter r-%
91+
if length(scatter_data) > 1
92+
obj.data{scatterIndex}.r(m) = scatter_data(n).RData;
93+
else
94+
obj.data{scatterIndex}.r = scatter_data.RData;
95+
end
96+
97+
%---------------------------------------------------------------------%
98+
99+
%-scatter theta-%
100+
if length(scatter_data) > 1
101+
obj.data{scatterIndex}.theta(m) = rad2deg(scatter_data(n).ThetaData);
102+
else
103+
obj.data{scatterIndex}.theta = rad2deg(scatter_data.ThetaData);
104+
end
105+
106+
107+
%---------------------------------------------------------------------%
108+
109+
%-scatter showlegend-%
110+
leg = get(scatter_data.Annotation);
111+
legInfo = get(leg.LegendInformation);
112+
113+
switch legInfo.IconDisplayStyle
114+
case 'on'
115+
showleg = true;
116+
case 'off'
117+
showleg = false;
118+
end
119+
120+
if isfield(scatter_data,'ZData')
121+
if isempty(scatter_data.ZData)
122+
obj.data{scatterIndex}.showlegend = showleg;
123+
end
124+
end
125+
126+
%---------------------------------------------------------------------%
127+
128+
%-scatter marker-%
129+
childmarker = extractScatterMarker(scatter_data(n));
130+
131+
%---------------------------------------------------------------------%
132+
133+
%-line color-%
134+
if length(scatter_data) > 1
135+
obj.data{scatterIndex}.marker.line.color{m} = childmarker.line.color{1};
136+
else
137+
if length(childmarker.line.color) > 3
138+
obj.data{scatterIndex}.marker.line.color = childmarker.line.color;
139+
else
140+
obj.data{scatterIndex}.marker.line.color = childmarker.line.color{1};
141+
end
142+
end
143+
144+
%---------------------------------------------------------------------%
145+
146+
%-marker color-%
147+
if length(scatter_data) > 1
148+
obj.data{scatterIndex}.marker.color{m} = childmarker.color{1};
149+
else
150+
obj.data{scatterIndex}.marker.color = childmarker.color;
151+
end
152+
153+
%---------------------------------------------------------------------%
154+
155+
%-sizeref-%
156+
obj.data{scatterIndex}.marker.sizeref = childmarker.sizeref;
157+
158+
%---------------------------------------------------------------------%
159+
160+
%-sizemode-%
161+
obj.data{scatterIndex}.marker.sizemode = childmarker.sizemode;
162+
163+
%---------------------------------------------------------------------%
164+
165+
%-symbol-%
166+
if length(scatter_data) > 1
167+
obj.data{scatterIndex}.marker.symbol{m} = childmarker.symbol;
168+
else
169+
obj.data{scatterIndex}.marker.symbol = childmarker.symbol;
170+
end
171+
172+
%---------------------------------------------------------------------%
173+
174+
%-size-%
175+
if length(scatter_data) > 1
176+
obj.data{scatterIndex}.marker.size = childmarker.size;
177+
else
178+
obj.data{scatterIndex}.marker.size = childmarker.size * 0.15;
179+
end
180+
181+
%---------------------------------------------------------------------%
182+
183+
%-line width-%
184+
185+
if length(scatter_data) > 1 || ischar(childmarker.line.color)
186+
obj.data{scatterIndex}.marker.line.width(m) = childmarker.line.width;
187+
else
188+
obj.data{scatterIndex}.marker.line.width = childmarker.line.width;
189+
% obj.data{scatterIndex}.marker.line.width(1:length(childmarker.line.color)) = childmarker.line.width;
190+
end
191+
192+
%---------------------------------------------------------------------%
193+
194+
end
195+
end
196+

plotly/plotlyfig_aux/helpers/extractScatterMarker.m

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,6 @@
129129

130130
end
131131

132-
133132
%-------------------------------------------------------------------------%
134133

135134
%-MARKER LINE COLOR-%
@@ -146,7 +145,7 @@
146145
switch MarkerLineColor
147146

148147
case 'none'
149-
148+
150149
markerlinecolor = 'rgba(0,0,0,0)';
151150

152151
case 'auto'
@@ -168,7 +167,6 @@
168167

169168
for n = 1:length(patch_data.CData)
170169

171-
172170
capCD = max(min(patch_data.CData(n),axis_data.CLim(2)),axis_data.CLim(1));
173171
scalefactor = (capCD - axis_data.CLim(1))/diff(axis_data.CLim);
174172
col = 255*(colormap(1 + floor(scalefactor*(length(colormap)-1)),:));
@@ -184,9 +182,15 @@
184182

185183
for n = 1:length(patch_data.CData)
186184

187-
capCD = max(min(patch_data.CData(n),axis_data.CLim(2)),axis_data.CLim(1));
188-
scalefactor = (capCD - axis_data.CLim(1))/diff(axis_data.CLim);
189-
col = 255*(colormap(1+floor(scalefactor*(length(colormap)-1)),:));
185+
try
186+
capCD = max(min(patch_data.CData(n),axis_data.CLim(2)),axis_data.CLim(1));
187+
scalefactor = (capCD - axis_data.CLim(1))/diff(axis_data.CLim);
188+
col = 255*(colormap(1+floor(scalefactor*(length(colormap)-1)),:));
189+
catch
190+
capCD = patch_data.CData(n);
191+
scalefactor = capCD;
192+
col = 255*(colormap(1+floor(scalefactor*(length(colormap)-1)),:));
193+
end
190194

191195
markerlinecolor{n} = ['rgb(' num2str(col(1)) ',' num2str(col(2)) ',' num2str(col(3)) ')'];
192196

0 commit comments

Comments
 (0)