Skip to content

Commit bce5746

Browse files
fixxing issues related to part of issue389, multiplot case and multiple y-axes case
1 parent 9597bfd commit bce5746

File tree

7 files changed

+565
-50
lines changed

7 files changed

+565
-50
lines changed

plotly/plotlyfig.m

+34-9
Original file line numberDiff line numberDiff line change
@@ -568,6 +568,7 @@ function validate(obj)
568568

569569
% find axes of figure
570570
ax = findobj(obj.State.Figure.Handle,'Type','axes','-and',{'Tag','','-or','Tag','PlotMatrixBigAx','-or','Tag','PlotMatrixScatterAx', '-or','Tag','PlotMatrixHistAx'});
571+
571572
if isempty(ax)
572573
ax = gca;
573574
end
@@ -601,7 +602,7 @@ function validate(obj)
601602

602603
% update number of annotations (one title per axis)
603604
obj.State.Figure.NumTexts = length(ax);
604-
605+
605606
% find children of figure axes
606607
for a = 1:length(ax)
607608

@@ -620,18 +621,26 @@ function validate(obj)
620621
plots = findobj(ax(axrev),'-not','Type','Text','-not','Type','axes','-depth',1);
621622

622623
% get number of nbars for pie3
623-
if strcmpi(obj.PlotOptions.TreatAs, 'pie3')
624+
if ismember('pie3', lower(obj.PlotOptions.TreatAs))
624625
obj.PlotOptions.nbars{a} = 0;
625626
for i = 1:length(plots)
626-
if strcmpi(getGraphClass(plots(i)), 'surface')
627+
if ismember('surface', lower(obj.PlotOptions.TreatAs))
627628
obj.PlotOptions.nbars{a} = obj.PlotOptions.nbars{a} + 1;
628629
end
629630
end
630631
end
631632

632633
% add baseline objects
633634
baselines = findobj(ax(axrev),'-property','BaseLine');
634-
635+
636+
% check is current axes have multiple y-axes
637+
try
638+
obj.PlotlyDefaults.isMultipleYAxes(axrev) = length(ax(axrev).YAxis) == 2;
639+
catch
640+
obj.PlotlyDefaults.isMultipleYAxes(axrev) = false;
641+
end
642+
643+
% update structures for each plot in current axes
635644
for np = 1:length(plots)
636645

637646
% reverse plots
@@ -649,9 +658,19 @@ function validate(obj)
649658
end
650659

651660
% this works for pareto
652-
if length(plots) == 0
653-
if obj.State.Figure.NumPlots ~=0
661+
if length(plots) == 0 & obj.State.Figure.NumPlots ~= 0
662+
isPareto = length(ax) >= 2 & obj.State.Figure.NumPlots >= 2;
663+
isBar = strcmpi(lower(obj.State.Plot(obj.State.Figure.NumPlots).Class), 'line');
664+
isLine = strcmpi(lower(obj.State.Plot(obj.State.Figure.NumPlots-1).Class), 'bar');
665+
isPareto = isPareto & isBar & isLine;
666+
667+
if isPareto
654668
obj.State.Plot(obj.State.Figure.NumPlots).AssociatedAxis = handle(ax(axrev));
669+
else
670+
obj.State.Figure.NumPlots = obj.State.Figure.NumPlots + 1;
671+
obj.State.Plot(obj.State.Figure.NumPlots).Handle = {};
672+
obj.State.Plot(obj.State.Figure.NumPlots).AssociatedAxis = handle(ax(axrev));
673+
obj.State.Plot(obj.State.Figure.NumPlots).Class = 'nothing';
655674
end
656675
end
657676

@@ -714,6 +733,7 @@ function validate(obj)
714733

715734
% reset dataget(obj.State.Figure.Handle,'Children')
716735
obj.data = {};
736+
obj.PlotOptions.nPlots = obj.State.Figure.NumPlots;
717737

718738
% reset layout
719739
obj.layout = struct();
@@ -724,16 +744,21 @@ function validate(obj)
724744
% update axes
725745
for n = 1:obj.State.Figure.NumAxes
726746
try
727-
updateAxis(obj,n);
747+
if ~obj.PlotlyDefaults.isMultipleYAxes(n)
748+
updateAxis(obj,n);
749+
750+
else
751+
for yax = 1:2
752+
updateAxisMultipleYAxes(obj,n,yax);
753+
end
754+
end
728755
catch
729756
% TODO to the future
730757
% disp('catch at line 647 in plotlyfig.m file')
731758
end
732759
end
733760

734761
% update plots
735-
obj.PlotOptions.nPlots = obj.State.Figure.NumPlots;
736-
737762
for n = 1:obj.State.Figure.NumPlots
738763
updateData(obj,n);
739764

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
%----UPDATE AXIS DATA/LAYOUT----%
2+
3+
function obj = updateAxisMultipleYAxes(obj,axIndex,yaxIndex)
4+
5+
%-STANDARDIZE UNITS-%
6+
axisUnits = get(obj.State.Axis(axIndex).Handle,'Units');
7+
set(obj.State.Axis(axIndex).Handle,'Units','normalized')
8+
9+
try
10+
fontUnits = get(obj.State.Axis(axIndex).Handle,'FontUnits');
11+
set(obj.State.Axis(axIndex).Handle,'FontUnits','points')
12+
catch
13+
% TODO
14+
end
15+
16+
%-AXIS DATA STRUCTURE-%
17+
axisData = get(obj.State.Axis(axIndex).Handle);
18+
19+
%-------------------------------------------------------------------------%
20+
21+
%-xaxis-%
22+
xaxis = extractAxisData(obj,axisData, 'X');
23+
24+
%-------------------------------------------------------------------------%
25+
26+
%-yaxis-%
27+
[yaxis, yAxisLim] = extractAxisDataMultipleYAxes(obj, axisData, yaxIndex);
28+
29+
%-------------------------------------------------------------------------%
30+
31+
%-getting and setting postion data-%
32+
33+
xo = axisData.Position(1);
34+
yo = axisData.Position(2);
35+
w = axisData.Position(3);
36+
h = axisData.Position(4);
37+
38+
if obj.PlotOptions.AxisEqual
39+
wh = min(axisData.Position(3:4));
40+
w = wh;
41+
h = wh;
42+
end
43+
44+
%-------------------------------------------------------------------------%
45+
46+
%-xaxis domain-%
47+
xaxis.domain = min([xo xo + w],1);
48+
scene.domain.x = min([xo xo + w],1);
49+
50+
%-------------------------------------------------------------------------%
51+
52+
%-yaxis domain-%
53+
yaxis.domain = min([yo yo + h],1);
54+
scene.domain.y = min([yo yo + h],1);
55+
56+
%-------------------------------------------------------------------------%
57+
58+
[xsource, ysource, xoverlay, yoverlay] = findSourceAxis(obj, axIndex, yaxIndex);
59+
60+
%-------------------------------------------------------------------------%
61+
62+
%-xaxis anchor-%
63+
xaxis.anchor = ['y' num2str(ysource)];
64+
65+
%-------------------------------------------------------------------------%
66+
67+
%-yaxis anchor-%
68+
yaxis.anchor = ['x' num2str(xsource)];
69+
70+
%-------------------------------------------------------------------------%
71+
72+
%-xaxis overlaying-%
73+
if xoverlay
74+
xaxis.overlaying = ['x' num2str(xoverlay)];
75+
end
76+
77+
%-------------------------------------------------------------------------%
78+
79+
%-yaxis overlaying-%
80+
if yoverlay
81+
yaxis.overlaying = ['y' num2str(yoverlay)];
82+
end
83+
84+
%-------------------------------------------------------------------------%
85+
86+
% update the layout field (do not overwrite source)
87+
if xsource == axIndex
88+
obj.layout = setfield(obj.layout,['xaxis' num2str(xsource)],xaxis);
89+
end
90+
91+
%-------------------------------------------------------------------------%
92+
93+
% update the layout field (do not overwrite source)
94+
obj.layout = setfield(obj.layout,['yaxis' num2str(ysource)],yaxis);
95+
96+
%-------------------------------------------------------------------------%
97+
98+
%-REVERT UNITS-%
99+
set(obj.State.Axis(axIndex).Handle,'Units',axisUnits);
100+
101+
try
102+
set(obj.State.Axis(axIndex).Handle,'FontUnits',fontUnits);
103+
catch
104+
% TODO
105+
end
106+
107+
%-------------------------------------------------------------------------%
108+
109+
%-do y-axes visibles-%
110+
obj.PlotOptions.nPlots = obj.PlotOptions.nPlots + 1;
111+
plotIndex = obj.PlotOptions.nPlots;
112+
113+
obj.data{plotIndex}.type = 'scatter';
114+
obj.data{plotIndex}.xaxis = ['x' num2str(xsource)];
115+
obj.data{plotIndex}.yaxis = ['y' num2str(ysource)];
116+
117+
%-------------------------------------------------------------------------%
118+
end

plotly/plotlyfig_aux/core/updateData.m

+1-1
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@
135135
case 'quivergroup'
136136
updateQuivergroup(obj, dataIndex);
137137
case 'scatter'
138-
if strcmpi(obj.State.Axis(dataIndex).Handle.Type, 'polaraxes')
138+
if ismember('polaraxes', lower(obj.PlotOptions.TreatAs))
139139
updateScatterPolar(obj, dataIndex);
140140
elseif obj.PlotlyDefaults.isGeoaxis
141141
updateGeoScatter(obj, dataIndex);

plotly/plotlyfig_aux/handlegraphics/updateLineseries.m

+29-19
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,20 @@ function updateLineseries(obj,plotIndex)
5454
axIndex = obj.getAxisIndex(obj.State.Plot(plotIndex).AssociatedAxis);
5555

5656
%-PLOT DATA STRUCTURE- %
57-
plot_data = get(obj.State.Plot(plotIndex).Handle);
57+
plotData = get(obj.State.Plot(plotIndex).Handle);
5858

5959
%-CHECK FOR MULTIPLE AXES-%
60-
[xsource, ysource] = findSourceAxis(obj,axIndex);
60+
try
61+
for yax = 1:2
62+
yaxIndex(yax) = sum(plotData.Parent.YAxis(yax).Color == plotData.Color);
63+
end
64+
65+
[~, yaxIndex] = max(yaxIndex);
66+
[xsource, ysource] = findSourceAxis(obj, axIndex, yaxIndex);
67+
68+
catch
69+
[xsource, ysource] = findSourceAxis(obj,axIndex);
70+
end
6171

6272
%-AXIS DATA-%
6373
eval(['xaxis = obj.layout.xaxis' num2str(xsource) ';']);
@@ -67,13 +77,13 @@ function updateLineseries(obj,plotIndex)
6777

6878
%-if polar plot or not-%
6979
treatas = obj.PlotOptions.TreatAs;
70-
ispolar = strcmpi(treatas, 'compass') || strcmpi(treatas, 'ezpolar');
80+
ispolar = ismember('compass', lower(treatas)) || ismember('ezpolar', lower(treatas));
7181

7282
%-------------------------------------------------------------------------%
7383

7484
%-getting data-%
75-
x = plot_data.XData;
76-
y = plot_data.YData;
85+
x = plotData.XData;
86+
y = plotData.YData;
7787

7888
%-------------------------------------------------------------------------%
7989

@@ -97,7 +107,7 @@ function updateLineseries(obj,plotIndex)
97107
%-------------------------------------------------------------------------%
98108

99109
%-scatter visible-%
100-
obj.data{plotIndex}.visible = strcmp(plot_data.Visible,'on');
110+
obj.data{plotIndex}.visible = strcmp(plotData.Visible,'on');
101111

102112
%-------------------------------------------------------------------------%
103113

@@ -117,21 +127,21 @@ function updateLineseries(obj,plotIndex)
117127
theta = atan2(x,y);
118128
obj.data{plotIndex}.theta = -(rad2deg(theta) - 90);
119129
else
120-
obj.data{plotIndex}.y = plot_data.YData;
130+
obj.data{plotIndex}.y = plotData.YData;
121131
end
122132

123133
%-------------------------------------------------------------------------%
124134

125135
%-Fro 3D plots-%
126136
obj.PlotOptions.is3d = false; % by default
127137

128-
if isfield(plot_data,'ZData')
138+
if isfield(plotData,'ZData')
129139

130-
numbset = unique(plot_data.ZData);
140+
numbset = unique(plotData.ZData);
131141

132-
if any(plot_data.ZData) && length(numbset)>1
142+
if any(plotData.ZData) && length(numbset)>1
133143
%-scatter z-%
134-
obj.data{plotIndex}.z = plot_data.ZData;
144+
obj.data{plotIndex}.z = plotData.ZData;
135145

136146
%-overwrite type-%
137147
obj.data{plotIndex}.type = 'scatter3d';
@@ -144,17 +154,17 @@ function updateLineseries(obj,plotIndex)
144154
%-------------------------------------------------------------------------%
145155

146156
%-scatter name-%
147-
obj.data{plotIndex}.name = plot_data.DisplayName;
157+
obj.data{plotIndex}.name = plotData.DisplayName;
148158

149159
%-------------------------------------------------------------------------%
150160

151161
%-scatter mode-%
152-
if ~strcmpi('none', plot_data.Marker) ...
153-
&& ~strcmpi('none', plot_data.LineStyle)
162+
if ~strcmpi('none', plotData.Marker) ...
163+
&& ~strcmpi('none', plotData.LineStyle)
154164
mode = 'lines+markers';
155-
elseif ~strcmpi('none', plot_data.Marker)
165+
elseif ~strcmpi('none', plotData.Marker)
156166
mode = 'markers';
157-
elseif ~strcmpi('none', plot_data.LineStyle)
167+
elseif ~strcmpi('none', plotData.LineStyle)
158168
mode = 'lines';
159169
else
160170
mode = 'none';
@@ -165,17 +175,17 @@ function updateLineseries(obj,plotIndex)
165175
%-------------------------------------------------------------------------%
166176

167177
%-scatter line-%
168-
obj.data{plotIndex}.line = extractLineLine(plot_data);
178+
obj.data{plotIndex}.line = extractLineLine(plotData);
169179

170180
%-------------------------------------------------------------------------%
171181

172182
%-scatter marker-%
173-
obj.data{plotIndex}.marker = extractLineMarker(plot_data);
183+
obj.data{plotIndex}.marker = extractLineMarker(plotData);
174184

175185
%-------------------------------------------------------------------------%
176186

177187
%-scatter showlegend-%
178-
leg = get(plot_data.Annotation);
188+
leg = get(plotData.Annotation);
179189
legInfo = get(leg.LegendInformation);
180190

181191
switch legInfo.IconDisplayStyle

plotly/plotlyfig_aux/helpers/extractAxisData.m

+7-1
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,13 @@
5353
axis.tickcolor = axiscol;
5454
%-axis tickfont-%
5555
axis.tickfont.color = axiscol;
56+
5657
%-axis grid color-%
57-
axis.gridcolor = axiscol;
58+
try
59+
axis.gridcolor = sprintf('rgba(%f,,%f,%f,%f)', 255*axis_data.GridColor, axis_data.GridAlpha);
60+
catch
61+
axis.gridcolor = axiscol;
62+
end
5863

5964
%-------------------------------------------------------------------------%
6065

@@ -170,6 +175,7 @@
170175
%-------------------------------------------------------------%
171176

172177
if isnumeric(dataLim)
178+
% axis.title = 'axis';
173179
axis.range = dataLim;
174180

175181
%-------------------------------------------------------------%

0 commit comments

Comments
 (0)