From 1c95daff7265fa44ab485ac735f2f652593551db Mon Sep 17 00:00:00 2001 From: Gilberto Galvis Date: Wed, 13 Oct 2021 11:11:46 -0400 Subject: [PATCH] fix issue related to bar functionality --- .../plotlyfig_aux/handlegraphics/updateBar.m | 280 ++++++++---------- .../plotlyfig_aux/helpers/extractAxisData.m | 209 ++++++------- 2 files changed, 230 insertions(+), 259 deletions(-) diff --git a/plotly/plotlyfig_aux/handlegraphics/updateBar.m b/plotly/plotlyfig_aux/handlegraphics/updateBar.m index 3626e1fb..cb899620 100644 --- a/plotly/plotlyfig_aux/handlegraphics/updateBar.m +++ b/plotly/plotlyfig_aux/handlegraphics/updateBar.m @@ -1,163 +1,129 @@ function obj = updateBar(obj,barIndex) -% x: ...[DONE] -% y: ...[DONE] -% name: ...[DONE] -% orientation: ...[DONE] -% text: ...[NOT SUPPORTED IN MATLAB] -% error_y: ...[HANDLED BY ERRORBAR] -% error_x: ...[HANDLED BY ERRORBAR] -% opacity: ...[DONE] -% xaxis: ...[DONE] -% yaxis: ...[DONE] -% showlegend: ...[DONE] -% stream: ...[HANDLED BY PLOTLY STREAM] -% visible: ...[DONE] -% type: ...[DONE] -% r: ...[NA] -% t: ...[NA] -% textfont: ...[NA] - -% MARKER: -% color: ...DONE] -% 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: ...[DONE] -% width: ...[DONE] -% dash: ...[NA] -% opacity: ---[TODO] -% shape: ...[NA] -% smoothing: ...[NA] -% outliercolor: ...[NA] -% outlierwidth: ...[NA] - -%-------------------------------------------------------------------------% - -%-AXIS INDEX-% -axIndex = obj.getAxisIndex(obj.State.Plot(barIndex).AssociatedAxis); - -%-BAR DATA STRUCTURE- % -bar_data = obj.State.Plot(barIndex).Handle; - -%-CHECK FOR MULTIPLE AXES-% -[xsource, ysource] = findSourceAxis(obj, axIndex); - -%-AXIS DATA-% -eval(['xaxis = obj.layout.xaxis' num2str(xsource) ';']); -eval(['yaxis = obj.layout.yaxis' num2str(ysource) ';']); - -%-------------------------------------------------------------------------% - -%-bar xaxis-% -obj.data{barIndex}.xaxis = ['x' num2str(xsource)]; - -%-------------------------------------------------------------------------% - -%-bar yaxis-% -obj.data{barIndex}.yaxis = ['y' num2str(ysource)]; - -%-------------------------------------------------------------------------% - -%-bar visible-% -obj.data{barIndex}.visible = strcmp(bar_data.Visible,'on'); - -%-------------------------------------------------------------------------% - -%-bar type-% -obj.data{barIndex}.type = 'bar'; - -%-------------------------------------------------------------------------% - -%-bar name-% -obj.data{barIndex}.name = bar_data.DisplayName; - -%-------------------------------------------------------------------------% - -%-layout barmode-% -switch bar_data.BarLayout - case 'grouped' - obj.layout.barmode = 'group'; - case 'stacked' - obj.layout.barmode = 'relative'; -end - -%-------------------------------------------------------------------------% - -%-layout bargroupgap-% -obj.layout.bargroupgap = 1-bar_data.BarWidth; - -%---------------------------------------------------------------------% - -%-layout bargap-% -obj.layout.bargap = obj.PlotlyDefaults.Bargap; - -%-------------------------------------------------------------------------% - -%-bar orientation-% -switch bar_data.Horizontal - - case 'off' - - %-bar orientation-% - obj.data{barIndex}.orientation = 'v'; - - %-bar x data-% - obj.data{barIndex}.x = bar_data.XData; - - %-bar y data-% - obj.data{barIndex}.y = bar_data.YData; - - - case 'on' - - %-bar orientation-% - obj.data{barIndex}.orientation = 'h'; + % x: ...[DONE] + % y: ...[DONE] + % name: ...[DONE] + % orientation: ...[DONE] + % text: ...[NOT SUPPORTED IN MATLAB] + % error_y: ...[HANDLED BY ERRORBAR] + % error_x: ...[HANDLED BY ERRORBAR] + % opacity: ...[DONE] + % xaxis: ...[DONE] + % yaxis: ...[DONE] + % showlegend: ...[DONE] + % stream: ...[HANDLED BY PLOTLY STREAM] + % visible: ...[DONE] + % type: ...[DONE] + % r: ...[NA] + % t: ...[NA] + % textfont: ...[NA] + + % MARKER: + % color: ...DONE] + % 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: ...[DONE] + % width: ...[DONE] + % dash: ...[NA] + % opacity: ---[TODO] + % shape: ...[NA] + % smoothing: ...[NA] + % outliercolor: ...[NA] + % outlierwidth: ...[NA] + + %-------------------------------------------------------------------------% + + %-AXIS INDEX-% + axIndex = obj.getAxisIndex(obj.State.Plot(barIndex).AssociatedAxis); + + %-BAR DATA STRUCTURE- % + barData = obj.State.Plot(barIndex).Handle; + + %-CHECK FOR MULTIPLE AXES-% + [xSource, ySource] = findSourceAxis(obj, axIndex); + + %-------------------------------------------------------------------------% + + %-associate axis-% + obj.data{barIndex}.xaxis = sprintf('x%d', xSource); + obj.data{barIndex}.yaxis = sprintf('y%d', ySource); + + %-------------------------------------------------------------------------% + + %-set trace-% + obj.data{barIndex}.type = 'bar'; + obj.data{barIndex}.name = barData.DisplayName; + obj.data{barIndex}.visible = strcmp(barData.Visible,'on'); + + %-------------------------------------------------------------------------% + + %-set plot data-% + switch barData.Horizontal - %-bar x data-% - obj.data{barIndex}.x = bar_data.YData; - - %-bar y data-% - obj.data{barIndex}.y = bar_data.XData; -end - -%---------------------------------------------------------------------% - -%-bar showlegend-% -leg = get(bar_data.Annotation); -legInfo = get(leg.LegendInformation); - -switch legInfo.IconDisplayStyle - case 'on' - showleg = true; - case 'off' - showleg = false; -end - -obj.data{barIndex}.showlegend = showleg; - -%-------------------------------------------------------------------------% - -%-bar marker-% -obj.data{barIndex}.marker = extractAreaFace(bar_data); - -%-------------------------------------------------------------------------% - -%-bar marker line-% -markerline = extractAreaLine(bar_data); -obj.data{barIndex}.marker.line = markerline; - -%-------------------------------------------------------------------------% + case 'off' + obj.data{barIndex}.orientation = 'v'; + obj.data{barIndex}.x = barData.XData; + obj.data{barIndex}.y = barData.YData; + + case 'on' + obj.data{barIndex}.orientation = 'h'; + obj.data{barIndex}.x = barData.YData; + obj.data{barIndex}.y = barData.XData; + end + + %-------------------------------------------------------------------------% + + %-trace settings-% + markerline = extractAreaLine(barData); + + obj.data{barIndex}.marker = extractAreaFace(barData); + obj.data{barIndex}.marker.line = markerline; + + %-------------------------------------------------------------------------% + + %-layout settings-% + obj.layout.bargroupgap = 1-barData.BarWidth; + + try + obj.layout.bargap = obj.layout.bargap + 0.0625; + catch + obj.layout.bargap = 0.0625; + end + + switch barData.BarLayout + case 'grouped' + obj.layout.barmode = 'group'; + case 'stacked' + obj.layout.barmode = 'relative'; + end + + %-------------------------------------------------------------------------% + + %-bar showlegend-% + leg = get(barData.Annotation); + legInfo = get(leg.LegendInformation); + + switch legInfo.IconDisplayStyle + case 'on' + showleg = true; + case 'off' + showleg = false; + end + + obj.data{barIndex}.showlegend = showleg; + + %-------------------------------------------------------------------------% end diff --git a/plotly/plotlyfig_aux/helpers/extractAxisData.m b/plotly/plotlyfig_aux/helpers/extractAxisData.m index 4161d1e9..e7f042f9 100644 --- a/plotly/plotlyfig_aux/helpers/extractAxisData.m +++ b/plotly/plotlyfig_aux/helpers/extractAxisData.m @@ -13,7 +13,12 @@ axisColor = 255 * eval(sprintf('axisData.%sColor', axisName)); axisColor = sprintf('rgb(%f,%f,%f)', axisColor); lineWidth = max(1,axisData.LineWidth*obj.PlotlyDefaults.AxisLineIncreaseFactor); - exponentFormat = eval(sprintf('axisData.%sAxis.Exponent', axisName)); + + try + exponentFormat = eval(sprintf('axisData.%sAxis.Exponent', axisName)); + catch + exponentFormat = 0; + end axis.side = eval(sprintf('axisData.%sAxisLocation', axisName)); axis.zeroline = false; @@ -49,7 +54,6 @@ %-------------------------------------------------------------------------% %-set axis grid-% - isGrid = sprintf('axisData.%sGrid', axisName); isMinorGrid = sprintf('axisData.%sMinorGrid', axisName); @@ -90,7 +94,7 @@ %-------------------------------------------------------------------------% %-there is not tick label case-% - if isempty(tickValues) && isempty(tickLabels) + if isempty(tickValues) axis.ticks = ''; axis.showticklabels = false; @@ -105,22 +109,20 @@ %-------------------------------------------------------------------------% - %-there is tick labels-% + %-there is tick labels case-% else - %---------------------------------------------------------------------% - - %-some tick label settings-% - axisLim = eval( sprintf('axisData.%sLim', axisName) ); - if isduration(axisLim), axisLim = datenum(axisLim); end + %-set tick values-% + axis.showticklabels = true; + axis.tickmode = 'array'; - switch axisData.Box - case 'on' - axis.mirror = 'ticks'; - case 'off' - axis.mirror = false; + if ~iscategorical(tickValues) + axis.tickvals = tickValues; end + %-set axis limits-% + axisLim = eval( sprintf('axisData.%sLim', axisName) ); + if isnumeric(axisLim) if strcmp(axis.type, 'linear') axis.range = axisLim; @@ -128,104 +130,107 @@ axis.range = log10(axisLim); end + elseif isduration(axisLim) + axis.range = datenum(axisLim); + + elseif iscategorical(axisLim) + axis.autorange = true; + axis.type = 'category'; + else axis.autorange = true; end - axis.showticklabels = true; - - %---------------------------------------------------------------------% + %-box setting-% + switch axisData.Box + case 'on' + axis.mirror = 'ticks'; + case 'off' + axis.mirror = false; + end - %-set tick labels by using tick values and tick texts-% - if ~isempty(tickValues) && ~isempty(tickLabels) - axis.tickmode = 'array'; - axis.tickvals = tickValues; + %-set tick labels by using tick texts-% + if ~isempty(tickLabels) axis.ticktext = tickLabels; + end + end - %---------------------------------------------------------------------% + %---------------------------------------------------------------------% - %-set tick labels by using only tick values-% - elseif ~isempty(tickValues) && isempty(tickLabels) - axis.tickmode = 'array'; - axis.tickvals = tickValues; + %+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++% + % + % TODO: determine if following code piece is necessary. For this we need + % to test fig2plotly with more examples + % + %+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++% - %+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++% - % - % TODO: determine if following code piece is necessary. For this we need - % to test fig2plotly with more examples - % - %+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++% - - % %-LOG TYPE-% - % if strcmp(axis.type,'log') - - % axis.range = log10(axisLim); - % axis.autotick = true; - % axis.nticks = eval(['length(axisData.' axisName 'Tick) + 1;']); - - % %---------------------------------------------------------------------% - - % %-LINEAR TYPE-% - % elseif strcmp(axis.type,'linear') - - % %-----------------------------------------------------------------% - - % % %-get tick label mode-% - % % tickLabelMode = eval(['axisData.' axisName 'TickLabelMode;']); - - % % %-----------------------------------------------------------------% - - % % %-AUTO MODE-% - % % if strcmp(tickLabelMode,'auto') - - % %-------------------------------------------------------------% - - % if isnumeric(axisLim) - % %-axis range-% - % axis.range = axisLim; - % %-axis tickvals-% - % axis.tickvals = tick; - - % %-------------------------------------------------------------% - - % elseif isduration(axisLim) - % [temp,type] = convertDuration(axisLim); - - % if (~isduration(temp)) - % axis.range = temp; - % axis.type = 'duration'; - % axis.title = type; - % else - % nticks = eval(['length(axisData.' axisName 'Tick)-1;']); - % delta = 0.1; - % axis.range = [-delta nticks+delta]; - % axis.type = 'duration - specified format'; - % end - - % %-------------------------------------------------------------% - - % elseif isdatetime(axisLim) - % axis.range = convertDate(axisLim); - % axis.type = 'date'; - % else - % % data is a category type other then duration and datetime - % end - - % %-------------------------------------------------------------% - - % if ~isnumeric(axisLim) - % %-axis autotick-% - % axis.autotick = true; - % %-axis numticks-% - % axis.nticks = eval(['length(axisData.' axisName 'Tick)+1']); - % end - % end - % end - - %+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++% + % %-LOG TYPE-% + % if strcmp(axis.type,'log') - end - end + % axis.range = log10(axisLim); + % axis.autotick = true; + % axis.nticks = eval(['length(axisData.' axisName 'Tick) + 1;']); + + % %---------------------------------------------------------------------% + + % %-LINEAR TYPE-% + % elseif strcmp(axis.type,'linear') + + % %-----------------------------------------------------------------% + + % % %-get tick label mode-% + % % tickLabelMode = eval(['axisData.' axisName 'TickLabelMode;']); + + % % %-----------------------------------------------------------------% + + % % %-AUTO MODE-% + % % if strcmp(tickLabelMode,'auto') + + % %-------------------------------------------------------------% + + % if isnumeric(axisLim) + % %-axis range-% + % axis.range = axisLim; + % %-axis tickvals-% + % axis.tickvals = tick; + + % %-------------------------------------------------------------% + + % elseif isduration(axisLim) + % [temp,type] = convertDuration(axisLim); + + % if (~isduration(temp)) + % axis.range = temp; + % axis.type = 'duration'; + % axis.title = type; + % else + % nticks = eval(['length(axisData.' axisName 'Tick)-1;']); + % delta = 0.1; + % axis.range = [-delta nticks+delta]; + % axis.type = 'duration - specified format'; + % end + + % %-------------------------------------------------------------% + + % elseif isdatetime(axisLim) + % axis.range = convertDate(axisLim); + % axis.type = 'date'; + % else + % % data is a category type other then duration and datetime + % end + + % %-------------------------------------------------------------% + + % if ~isnumeric(axisLim) + % %-axis autotick-% + % axis.autotick = true; + % %-axis numticks-% + % axis.nticks = eval(['length(axisData.' axisName 'Tick)+1']); + % end + % end + % end + + %+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++% %-------------------------------------------------------------------------%