Skip to content

Improve support for 'area' plots #495

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
merged 1 commit into from
Aug 4, 2024
Merged
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
283 changes: 137 additions & 146 deletions plotly/plotlyfig_aux/handlegraphics/updateArea.m
Original file line number Diff line number Diff line change
@@ -1,163 +1,154 @@
function updateArea(obj,areaIndex)

% x: ...[DONE]
% y: ...[DONE]
% r: ...[NOT SUPPORTED IN MATLAB]
% t: ...[NOT SUPPORTED IN MATLAB]
% mode: ...[DONE]
% name: ...[DONE]
% text: ...[NOT SUPPORTED IN MATLAB]
% error_y: ...[HANDLED BY ERRORBAR]
% error_x: ...[HANDLED BY ERRORBAR]

%----marker----%

% color: ...[NA]
% size: ...[NA]
% symbol: ...[NA]
% opacity: ...[NA]
% sizeref: ...[NA]
% sizemode: ...[NA]
% colorscale: ...[NA]
% cauto: ...[NA]
% cmin: ...[NA]
% cmax: ...[NA]
% outliercolor: ...[NA]
% maxdisplayed: ...[NA]

%----marker line----%

% color: ...[NA]
% width: ...[NA]
% dash: ...[NA]
% opacity: ...[NA]
% shape: ...[NA]
% smoothing: ...[NA]
% outliercolor: ...[NA]
% outlierwidth: ...[NA]

%----line----%
% color: .........[TODO]
% width: .........[TODO]
% dash: .........[TODO]
% opacity: .........[TODO]
% shape: ...[NA]
% smoothing: ...[NA]
% outliercolor: ...[NA]
% outlierwidth: ...[NA]

% textposition: ...[NOT SUPPORTED IN MATLAB]
% textfont: ...[NOT SUPPORTED IN MATLAB]
% connectgaps: ...[NOT SUPPORTED IN MATLAB]
% fill: ...[DONE]
% fillcolor: ..........[TODO]
% opacity: ..........[TODO]
% xaxis: ...[DONE]
% yaxis: ....[DONE]
% showlegend: ...[DONE]
% stream: ...[HANDLED BY PLOTLYSTREAM]
% visible: ...[DONE]
% type: ...[DONE]

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

%-store original area handle-%
area_data = obj.State.Plot(areaIndex).Handle;

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

%-get "children" using new HG2 approach-%
area_child = area_data.java.firstDown;

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

%-AXIS INDEX-%
axIndex = obj.getAxisIndex(obj.State.Plot(areaIndex).AssociatedAxis);

%-CHECK FOR MULTIPLE AXES-%
[xsource, ysource] = findSourceAxis(obj,axIndex);

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

%-area xaxis-%
obj.data{areaIndex}.xaxis = ['x' num2str(xsource)];

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

%-area yaxis-%
obj.data{areaIndex}.yaxis = ['y' num2str(ysource)];

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

%-area type-%
obj.data{areaIndex}.type = 'scatter';

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

%-area x-%
obj.data{areaIndex}.x = area_data.XData;

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

%-area y-%
if areaIndex>1
obj.data{areaIndex}.y = obj.data{areaIndex-1}.y + area_data.YData;
else
obj.data{areaIndex}.y = area_data.YData;
end

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

%-area name-%
if ~isempty(area_data.DisplayName);
obj.data{areaIndex}.name = area_data.DisplayName;
else
% x: ...[DONE]
% y: ...[DONE]
% r: ...[NOT SUPPORTED IN MATLAB]
% t: ...[NOT SUPPORTED IN MATLAB]
% mode: ...[DONE]
% name: ...[DONE]
% text: ...[NOT SUPPORTED IN MATLAB]
% error_y: ...[HANDLED BY ERRORBAR]
% error_x: ...[HANDLED BY ERRORBAR]

%----marker----%
% color: ...[NA]
% size: ...[NA]
% symbol: ...[NA]
% opacity: ...[NA]
% sizeref: ...[NA]
% sizemode: ...[NA]
% colorscale: ...[NA]
% cauto: ...[NA]
% cmin: ...[NA]
% cmax: ...[NA]
% outliercolor: ...[NA]
% maxdisplayed: ...[NA]

%----marker line----%
% color: ...[NA]
% width: ...[NA]
% dash: ...[NA]
% opacity: ...[NA]
% shape: ...[NA]
% smoothing: ...[NA]
% outliercolor: ...[NA]
% outlierwidth: ...[NA]

%----line----%
% color: .........[TODO]
% width: .........[TODO]
% dash: .........[TODO]
% opacity: .........[TODO]
% shape: ...[NA]
% smoothing: ...[NA]
% outliercolor: ...[NA]
% outlierwidth: ...[NA]

% textposition: ...[NOT SUPPORTED IN MATLAB]
% textfont: ...[NOT SUPPORTED IN MATLAB]
% connectgaps: ...[NOT SUPPORTED IN MATLAB]
% fill: ...[DONE]
% fillcolor: ..........[TODO]
% opacity: ..........[TODO]
% xaxis: ...[DONE]
% yaxis: ....[DONE]
% showlegend: ...[DONE]
% stream: ...[HANDLED BY PLOTLYSTREAM]
% visible: ...[DONE]
% type: ...[DONE]

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

%-store original area handle-%
area_data = obj.State.Plot(areaIndex).Handle;

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

%-AXIS INDEX-%
axIndex = obj.getAxisIndex(obj.State.Plot(areaIndex).AssociatedAxis);

%-CHECK FOR MULTIPLE AXES-%
[xsource, ysource] = findSourceAxis(obj,axIndex);

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

%-area axis-%
obj.data{areaIndex}.xaxis = "x" + xsource;
obj.data{areaIndex}.yaxis = "y" + ysource;

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

%-area type-%
obj.data{areaIndex}.type = "scatter";

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

%-area x-%
obj.data{areaIndex}.x = area_data.XData;

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

%-area y-%
prevAreaIndex = find(cellfun(@(x) isfield(x,"fill") ...
&& isequal({x.xaxis x.yaxis},{obj.data{areaIndex}.xaxis ...
obj.data{areaIndex}.yaxis}),obj.data(1:areaIndex-1)),1,"last");
if ~isempty(prevAreaIndex)
obj.data{areaIndex}.y = obj.data{prevAreaIndex}.y + area_data.YData;
else
obj.data{areaIndex}.y = area_data.YData;
end

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

%-area name-%
obj.data{areaIndex}.name = area_data.DisplayName;
end

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

%-area visible-%
obj.data{areaIndex}.visible = strcmp(area_data.Visible,'on');
%-area visible-%
obj.data{areaIndex}.visible = strcmp(area_data.Visible, "on");

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

%-area fill-%
obj.data{areaIndex}.fill = 'tonexty';
%-area fill-%
if ~isempty(prevAreaIndex)
obj.data{areaIndex}.fill = "tonexty";
else % first area plot
obj.data{areaIndex}.fill = "tozeroy";
end

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

%-AREA MODE-%
obj.data{areaIndex}.mode = 'lines';
%-AREA MODE-%
if isprop(area_data, "LineStyle") ...
&& isequal(area_data.LineStyle, "none")
obj.data{areaIndex}.mode = "none";
else
obj.data{areaIndex}.mode = "lines";
end

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

%-area line-%
obj.data{areaIndex}.line = extractAreaLine(area_data);
%-area line-%
obj.data{areaIndex}.line = extractAreaLine(area_data);

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

%-area fillcolor-%
fill = extractAreaFace(area_data);
obj.data{areaIndex}.fillcolor = fill.color;
%-area fillcolor-%
fill = extractAreaFace(area_data);
obj.data{areaIndex}.fillcolor = fill.color;

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

%-area showlegend-%
leg = area_data.Annotation;
legInfo = leg.LegendInformation;
%-area showlegend-%
leg = area_data.Annotation;
legInfo = leg.LegendInformation;

switch legInfo.IconDisplayStyle
case 'on'
showleg = true;
case 'off'
showleg = false;
end

obj.data{areaIndex}.showlegend = showleg;

%-------------------------------------------------------------------------%
switch legInfo.IconDisplayStyle
case "on"
showleg = true;
case "off"
showleg = false;
end

obj.data{areaIndex}.showlegend = showleg;
end