From 4f7d5799b17bfc8b47c5db0ebfccabf6f1912dc5 Mon Sep 17 00:00:00 2001 From: robertoffmoura Date: Sun, 4 Aug 2024 12:25:10 +0100 Subject: [PATCH] Improve support for 'area' plots --- .../plotlyfig_aux/handlegraphics/updateArea.m | 283 +++++++++--------- 1 file changed, 137 insertions(+), 146 deletions(-) diff --git a/plotly/plotlyfig_aux/handlegraphics/updateArea.m b/plotly/plotlyfig_aux/handlegraphics/updateArea.m index 6b561d8e..f8ca60c2 100644 --- a/plotly/plotlyfig_aux/handlegraphics/updateArea.m +++ b/plotly/plotlyfig_aux/handlegraphics/updateArea.m @@ -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 - -