Skip to content

Fixxing issues related to part of issue389 multiplot case and multiple y axes case #403

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 57 additions & 16 deletions plotly/plotlyfig.m
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
obj.PlotOptions.Visible = 'on';
obj.PlotOptions.TriangulatePatch = false;
obj.PlotOptions.StripMargins = false;
obj.PlotOptions.TreatAs = '_';
obj.PlotOptions.TreatAs = {'_'};
obj.PlotOptions.Image3D = false;
obj.PlotOptions.ContourProjection = false;
obj.PlotOptions.AxisEqual = false;
Expand Down Expand Up @@ -102,6 +102,7 @@
obj.PlotlyDefaults.MinCaptionMargin = 80;
obj.PlotlyDefaults.IsLight = false;
obj.PlotlyDefaults.isGeoaxis = false;
obj.PlotlyDefaults.isTernary = false;

%-State-%
obj.State.Figure = [];
Expand Down Expand Up @@ -235,7 +236,11 @@
obj.PlotOptions.TriangulatePatch = varargin{a+1};
end
if(strcmpi(varargin{a},'TreatAs'))
obj.PlotOptions.TreatAs = varargin{a+1};
if ~iscell(varargin{a+1})
obj.PlotOptions.TreatAs = {varargin{a+1}};
else
obj.PlotOptions.TreatAs = varargin{a+1};
end
end
if(strcmpi(varargin{a},'AxisEqual'))
obj.PlotOptions.AxisEqual = varargin{a+1};
Expand Down Expand Up @@ -563,6 +568,7 @@ function validate(obj)

% find axes of figure
ax = findobj(obj.State.Figure.Handle,'Type','axes','-and',{'Tag','','-or','Tag','PlotMatrixBigAx','-or','Tag','PlotMatrixScatterAx', '-or','Tag','PlotMatrixHistAx'});

if isempty(ax)
ax = gca;
end
Expand Down Expand Up @@ -596,7 +602,7 @@ function validate(obj)

% update number of annotations (one title per axis)
obj.State.Figure.NumTexts = length(ax);

% find children of figure axes
for a = 1:length(ax)

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

% get number of nbars for pie3
if strcmpi(obj.PlotOptions.TreatAs, 'pie3')
if ismember('pie3', lower(obj.PlotOptions.TreatAs))
obj.PlotOptions.nbars{a} = 0;
for i = 1:length(plots)
if strcmpi(getGraphClass(plots(i)), 'surface')
if ismember('surface', lower(obj.PlotOptions.TreatAs))
obj.PlotOptions.nbars{a} = obj.PlotOptions.nbars{a} + 1;
end
end
end

% add baseline objects
baselines = findobj(ax(axrev),'-property','BaseLine');


% check is current axes have multiple y-axes
try
obj.PlotlyDefaults.isMultipleYAxes(axrev) = length(ax(axrev).YAxis) == 2;
catch
obj.PlotlyDefaults.isMultipleYAxes(axrev) = false;
end

% update structures for each plot in current axes
for np = 1:length(plots)

% reverse plots
Expand All @@ -644,9 +658,19 @@ function validate(obj)
end

% this works for pareto
if length(plots) == 0
if obj.State.Figure.NumPlots ~=0
if length(plots) == 0 & obj.State.Figure.NumPlots ~= 0
isPareto = length(ax) >= 2 & obj.State.Figure.NumPlots >= 2;
isBar = strcmpi(lower(obj.State.Plot(obj.State.Figure.NumPlots).Class), 'line');
isLine = strcmpi(lower(obj.State.Plot(obj.State.Figure.NumPlots-1).Class), 'bar');
isPareto = isPareto & isBar & isLine;

if isPareto
obj.State.Plot(obj.State.Figure.NumPlots).AssociatedAxis = handle(ax(axrev));
else
obj.State.Figure.NumPlots = obj.State.Figure.NumPlots + 1;
obj.State.Plot(obj.State.Figure.NumPlots).Handle = {};
obj.State.Plot(obj.State.Figure.NumPlots).AssociatedAxis = handle(ax(axrev));
obj.State.Plot(obj.State.Figure.NumPlots).Class = 'nothing';
end
end

Expand Down Expand Up @@ -709,6 +733,7 @@ function validate(obj)

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

% reset layout
obj.layout = struct();
Expand All @@ -719,16 +744,21 @@ function validate(obj)
% update axes
for n = 1:obj.State.Figure.NumAxes
try
updateAxis(obj,n);
if ~obj.PlotlyDefaults.isMultipleYAxes(n)
updateAxis(obj,n);

else
for yax = 1:2
updateAxisMultipleYAxes(obj,n,yax);
end
end
catch
% TODO to the future
% disp('catch at line 647 in plotlyfig.m file')
end
end

% update plots
obj.PlotOptions.nPlots = obj.State.Figure.NumPlots;

for n = 1:obj.State.Figure.NumPlots
updateData(obj,n);

Expand All @@ -752,7 +782,9 @@ function validate(obj)
elseif obj.PlotlyDefaults.isGeoaxis
% TODO
else
updateAnnotation(obj,n);
if ~obj.PlotlyDefaults.isTernary
updateAnnotation(obj,n);
end
end
catch
% TODO to the future
Expand All @@ -761,15 +793,23 @@ function validate(obj)
end

% update legends
for n = 1:obj.State.Figure.NumLegends
if ~strcmpi(obj.PlotOptions.TreatAs, 'pie3')
updateLegend(obj,n);
if obj.State.Figure.NumLegends < 2
for n = 1:obj.State.Figure.NumLegends
if ~strcmpi(obj.PlotOptions.TreatAs, 'pie3')
updateLegend(obj,n);
end
end
else
updateLegendMultipleAxes(obj,1);
end

% update colorbars
for n = 1:obj.State.Figure.NumColorbars
updateColorbar(obj,n);
if ~obj.PlotlyDefaults.isTernary
updateColorbar(obj,n);
else
updateTernaryColorbar(obj,n);
end
end

end
Expand Down Expand Up @@ -1068,6 +1108,7 @@ function delete(obj)
|| strcmpi(fieldname,'legend') || strcmpi(fieldname,'histogram')...
|| strcmpi(fieldname,'scatter') || strcmpi(fieldname,'line')...
|| strcmpi(fieldname,'scattergeo') || strcmpi(fieldname,'scattermapbox')...
|| strcmpi(fieldname,'scatterternary')...
)
fprintf(['\nWhoops! ' exception.message(1:end-1) ' in ' fieldname '\n\n']);
end
Expand Down
118 changes: 118 additions & 0 deletions plotly/plotlyfig_aux/core/updateAxisMultipleYAxes.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
%----UPDATE AXIS DATA/LAYOUT----%

function obj = updateAxisMultipleYAxes(obj,axIndex,yaxIndex)

%-STANDARDIZE UNITS-%
axisUnits = get(obj.State.Axis(axIndex).Handle,'Units');
set(obj.State.Axis(axIndex).Handle,'Units','normalized')

try
fontUnits = get(obj.State.Axis(axIndex).Handle,'FontUnits');
set(obj.State.Axis(axIndex).Handle,'FontUnits','points')
catch
% TODO
end

%-AXIS DATA STRUCTURE-%
axisData = get(obj.State.Axis(axIndex).Handle);

%-------------------------------------------------------------------------%

%-xaxis-%
xaxis = extractAxisData(obj,axisData, 'X');

%-------------------------------------------------------------------------%

%-yaxis-%
[yaxis, yAxisLim] = extractAxisDataMultipleYAxes(obj, axisData, yaxIndex);

%-------------------------------------------------------------------------%

%-getting and setting postion data-%

xo = axisData.Position(1);
yo = axisData.Position(2);
w = axisData.Position(3);
h = axisData.Position(4);

if obj.PlotOptions.AxisEqual
wh = min(axisData.Position(3:4));
w = wh;
h = wh;
end

%-------------------------------------------------------------------------%

%-xaxis domain-%
xaxis.domain = min([xo xo + w],1);
scene.domain.x = min([xo xo + w],1);

%-------------------------------------------------------------------------%

%-yaxis domain-%
yaxis.domain = min([yo yo + h],1);
scene.domain.y = min([yo yo + h],1);

%-------------------------------------------------------------------------%

[xsource, ysource, xoverlay, yoverlay] = findSourceAxis(obj, axIndex, yaxIndex);

%-------------------------------------------------------------------------%

%-xaxis anchor-%
xaxis.anchor = ['y' num2str(ysource)];

%-------------------------------------------------------------------------%

%-yaxis anchor-%
yaxis.anchor = ['x' num2str(xsource)];

%-------------------------------------------------------------------------%

%-xaxis overlaying-%
if xoverlay
xaxis.overlaying = ['x' num2str(xoverlay)];
end

%-------------------------------------------------------------------------%

%-yaxis overlaying-%
if yoverlay
yaxis.overlaying = ['y' num2str(yoverlay)];
end

%-------------------------------------------------------------------------%

% update the layout field (do not overwrite source)
if xsource == axIndex
obj.layout = setfield(obj.layout,['xaxis' num2str(xsource)],xaxis);
end

%-------------------------------------------------------------------------%

% update the layout field (do not overwrite source)
obj.layout = setfield(obj.layout,['yaxis' num2str(ysource)],yaxis);

%-------------------------------------------------------------------------%

%-REVERT UNITS-%
set(obj.State.Axis(axIndex).Handle,'Units',axisUnits);

try
set(obj.State.Axis(axIndex).Handle,'FontUnits',fontUnits);
catch
% TODO
end

%-------------------------------------------------------------------------%

%-do y-axes visibles-%
obj.PlotOptions.nPlots = obj.PlotOptions.nPlots + 1;
plotIndex = obj.PlotOptions.nPlots;

obj.data{plotIndex}.type = 'scatter';
obj.data{plotIndex}.xaxis = ['x' num2str(xsource)];
obj.data{plotIndex}.yaxis = ['y' num2str(ysource)];

%-------------------------------------------------------------------------%
end
Loading