From e3c4db145da8e4c0b5443e82564de37cdc4e960f Mon Sep 17 00:00:00 2001 From: Gilberto Galvis Date: Wed, 8 Sep 2021 20:59:51 -0400 Subject: [PATCH] Adding pareto functionality to fig2plotly --- plotly/plotlyfig.m | 31 +++-- .../handlegraphics/updateHistogram.m | 8 ++ .../plotlyfig_aux/handlegraphics/updateStem.m | 14 +- .../plotlyfig_aux/helpers/extractAxisData.m | 120 ++++++++++++++---- .../plotlyfig_aux/helpers/extractLineMarker.m | 2 +- .../plotlyfig_aux/helpers/extractPatchFace.m | 6 +- 6 files changed, 137 insertions(+), 44 deletions(-) diff --git a/plotly/plotlyfig.m b/plotly/plotlyfig.m index 38b7ff87..03e47f27 100644 --- a/plotly/plotlyfig.m +++ b/plotly/plotlyfig.m @@ -562,17 +562,21 @@ function validate(obj) temp_ax = ax; deleted_idx = 0; for i = 1:length(ax) for j = i:length(ax) - if ((mean(eq(ax(i).Position, ax(j).Position)) == 1) && (i~=j) && strcmp(ax(i).Children.Type, 'histogram')) - temp_plots = findobj(temp_ax(i),'-not','Type','Text','-not','Type','axes','-depth',1); - if isprop(temp_plots, 'FaceAlpha') - update_opac(i) = true; - else - update_opac(i) = false; + try + if ((mean(eq(ax(i).Position, ax(j).Position)) == 1) && (i~=j) && strcmp(ax(i).Children.Type, 'histogram')) + temp_plots = findobj(temp_ax(i),'-not','Type','Text','-not','Type','axes','-depth',1); + if isprop(temp_plots, 'FaceAlpha') + update_opac(i) = true; + else + update_opac(i) = false; + end + temp_ax(i).YTick = temp_ax(j- deleted_idx).YTick; + temp_ax(i).XTick = temp_ax(j- deleted_idx).XTick; + temp_ax(j - deleted_idx) = []; + deleted_idx = deleted_idx + 1; end - temp_ax(i).YTick = temp_ax(j- deleted_idx).YTick; - temp_ax(i).XTick = temp_ax(j- deleted_idx).XTick; - temp_ax(j - deleted_idx) = []; - deleted_idx = deleted_idx + 1; + catch + % TODO: error with ax(i).Children.Type. isfield is no enogh end end end @@ -625,6 +629,13 @@ function validate(obj) obj.State.Plot(obj.State.Figure.NumPlots).AssociatedAxis = handle(ax(axrev)); obj.State.Plot(obj.State.Figure.NumPlots).Class = getGraphClass(plots(nprev)); end + + % this works for pareto + if length(plots) == 0 + if obj.State.Figure.NumPlots ~=0 + obj.State.Plot(obj.State.Figure.NumPlots).AssociatedAxis = handle(ax(axrev)); + end + end % find text of figure texts = findobj(ax(axrev),'Type','text','-depth',1); diff --git a/plotly/plotlyfig_aux/handlegraphics/updateHistogram.m b/plotly/plotlyfig_aux/handlegraphics/updateHistogram.m index 91b636b1..d2626d0c 100644 --- a/plotly/plotlyfig_aux/handlegraphics/updateHistogram.m +++ b/plotly/plotlyfig_aux/handlegraphics/updateHistogram.m @@ -191,10 +191,18 @@ %-------------------------------------------------------------------------% +%-marker data-% obj.data{histIndex}.marker = extractPatchFace(hist_data); %-------------------------------------------------------------------------% +%-change color when multiple histograms same axes-% +if min([xsource, ysource]) == 1 + obj.data{histIndex}.marker = rmfield(obj.data{histIndex}.marker, 'color'); +end + +%-------------------------------------------------------------------------% + %-hist visible-% obj.data{histIndex}.visible = strcmp(hist_data.Visible,'on'); diff --git a/plotly/plotlyfig_aux/handlegraphics/updateStem.m b/plotly/plotlyfig_aux/handlegraphics/updateStem.m index 76b0c83c..eb510e5c 100644 --- a/plotly/plotlyfig_aux/handlegraphics/updateStem.m +++ b/plotly/plotlyfig_aux/handlegraphics/updateStem.m @@ -142,13 +142,19 @@ linecolor = cell(3*npoints,1); hidecolor = 'rgba(0,0,0,0)'; + linecolor(1:3:3*npoints) = {hidecolor}; markercolor(1:3:3*npoints) = {hidecolor}; - markercolor(2:3:3*npoints) = {stem_data.marker.color}; - markercolor(3:3:3*npoints) = {hidecolor}; - linecolor(1:3:3*npoints) = {hidecolor}; - linecolor(2:3:3*npoints) = {stem_data.marker.line.color}; + try + linecolor(2:3:3*npoints) = {stem_data.marker.line.color}; + markercolor(2:3:3*npoints) = {stem_data.marker.color}; + catch + linecolor(2:3:3*npoints) = {stem_data.marker.color}; + markercolor(2:3:3*npoints) = {hidecolor}; + end + linecolor(3:3:3*npoints) = {hidecolor}; + markercolor(3:3:3*npoints) = {hidecolor}; %-add new marker/line colors-% stem_data.marker.color = markercolor; diff --git a/plotly/plotlyfig_aux/helpers/extractAxisData.m b/plotly/plotlyfig_aux/helpers/extractAxisData.m index 201d883f..a87d8b61 100644 --- a/plotly/plotlyfig_aux/helpers/extractAxisData.m +++ b/plotly/plotlyfig_aux/helpers/extractAxisData.m @@ -91,7 +91,6 @@ %-------------------------------------------------------------------------% %-axis type-% - axis.type = eval(['axis_data.' axisName 'Scale']); %-------------------------------------------------------------------------% @@ -120,6 +119,9 @@ %---------------------------------------------------------------------% else + + %-get axis limits-% + dataLim = eval( sprintf('axis_data.%sLim', axisName) ); %-axis tick direction-% switch axis_data.TickDir @@ -140,10 +142,11 @@ %---------------------------------------------------------------------% + %-LOG TYPE-% if strcmp(axis.type,'log') %-axis range-% - axis.range = eval(['log10(axis_data.' axisName 'Lim);']); + axis.range = eval( sprintf('log10(dataLim)') ); %['log10(axis_data.' axisName 'Lim);']); %-axis autotick-% axis.autotick = true; %-axis nticks-% @@ -151,13 +154,19 @@ %---------------------------------------------------------------------% + %-LINEAR TYPE-% elseif strcmp(axis.type,'linear') + + %-----------------------------------------------------------------% + + %-get tick label mode-% TickLabelMode = eval(['axis_data.' axisName 'TickLabelMode;']); + + %-----------------------------------------------------------------% + + %-AUTO MODE-% if strcmp(TickLabelMode,'auto') - %-axis range-% - dataLim = eval(['axis_data.' axisName 'Lim']); - %-------------------------------------------------------------% if isnumeric(dataLim) @@ -192,39 +201,94 @@ axis.autotick = true; %-axis numticks-% axis.nticks = eval(['length(axis_data.' axisName 'Tick)+1']); + %-----------------------------------------------------------------% + %-CUSTOM MODE-% else - %-axis show tick labels-% - Tick = eval(['axis_data.' axisName 'TickLabel;']); - if isempty(Tick) + + %-------------------------------------------------------------% + + %-get tick labels-% + tickLabels = eval(['axis_data.' axisName 'TickLabel;']); + + %-------------------------------------------------------------% + + %-hide tick labels as lichkLabels field is empty-% + if isempty(tickLabels) + + %-------------------------------------------------------------% + %-hide tick labels-% axis.showticklabels = false; + + %-------------------------------------------------------------% + %-axis autorange-% axis.autorange = true; + + %-------------------------------------------------------------% + + %-axis show tick labels as tickLabels matlab field-% else - %-axis labels - labels = str2double(axis_data.YTickLabel); - try - %find numbers in labels - labelnums = find(~isnan(labels)); - %-axis type linear-% - axis.type = 'linear'; - %-range (overwrite)-% - delta = (labels(labelnums(2)) - labels(labelnums(1)))/(labelnums(2)-labelnums(1)); - axis.range = [labels(labelnums(1))-delta*(labelnums(1)-1) labels(labelnums(1)) + (length(labels)-labelnums(1))*delta]; - %-axis autotick-% - axis.autotick = true; - %-axis numticks-% - axis.nticks = eval(['length(axis_data.' axisName 'Tick) + 1;']); - catch - %-axis type category-% - axis.type = 'category'; - %-range (overwrite)-% + + %-------------------------------------------------------------% + + axis.showticklabels = true; + axis.type = 'linear'; + + %-------------------------------------------------------------% + + if isnumeric(dataLim) + axis.range = eval(['axis_data.' axisName 'Lim;']); + else axis.autorange = true; - %-axis autotick-% - % axis.autotick = true; end + + %-------------------------------------------------------------% + + axis.tickvals = tick; + axis.ticktext = tickLabels; + + %-------------------------------------------------------------% + + %+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++% + % NOTE: + % The next piece of code was replaced by the previous one. + % I think that the new piece of code is better, optimal and + % extends to all cases. However, I will leave this piece of + % code commented in case there is a problem in the future. + % + % If there is a problem with the new piece of code, please + % comment and uncomment the next piece of code. + % + % If everything goes well with the new gripping piece, at + % the end of the development we will be able to remove the + % commented lines + %+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++% + + %-axis labels + % labels = str2double(tickLabels); + % try + % %find numbers in labels + % labelnums = find(~isnan(labels)); + % %-axis type linear-% + % axis.type = 'linear'; + % %-range (overwrite)-% + % delta = (labels(labelnums(2)) - labels(labelnums(1)))/(labelnums(2)-labelnums(1)); + % axis.range = [labels(labelnums(1))-delta*(labelnums(1)-1) labels(labelnums(1)) + (length(labels)-labelnums(1))*delta]; + % %-axis autotick-% + % axis.autotick = true; + % %-axis numticks-% + % axis.nticks = eval(['length(axis_data.' axisName 'Tick) + 1;']); + % catch + % %-axis type category-% + % axis.type = 'category'; + % %-range (overwrite)-% + % axis.autorange = true; + % %-axis autotick-% + % % axis.autotick = true; + % end end end end diff --git a/plotly/plotlyfig_aux/helpers/extractLineMarker.m b/plotly/plotlyfig_aux/helpers/extractLineMarker.m index eb0a9672..c2c758bb 100644 --- a/plotly/plotlyfig_aux/helpers/extractLineMarker.m +++ b/plotly/plotlyfig_aux/helpers/extractLineMarker.m @@ -69,7 +69,7 @@ %-------------------------------------------------------------------------% filledMarkerSet = {'o','square','s','diamond','d',... - 'v','^', '<','>','hexagram','pentagram', '*', '+'}; + 'v','^', '<','>','hexagram','pentagram'}; filledMarker = ismember(line_data.Marker,filledMarkerSet); diff --git a/plotly/plotlyfig_aux/helpers/extractPatchFace.m b/plotly/plotlyfig_aux/helpers/extractPatchFace.m index d4b7ef54..6fa84201 100644 --- a/plotly/plotlyfig_aux/helpers/extractPatchFace.m +++ b/plotly/plotlyfig_aux/helpers/extractPatchFace.m @@ -44,12 +44,16 @@ capCD = max(min(patch_data.FaceVertexCData(1,1),axis_data.CLim(2)),axis_data.CLim(1)); scalefactor = (capCD -axis_data.CLim(1))/diff(axis_data.CLim); col = 255*(colormap(1+ floor(scalefactor*(length(colormap)-1)),:)); - case {'direct', 'auto'} + case 'direct' + patch_data.FaceVertexCData col = 255*(colormap(patch_data.FaceVertexCData(1,1),:)); end marker.color = ['rgb(' num2str(col(1)) ',' num2str(col(2)) ',' num2str(col(3)) ')']; + + case 'auto' + marker.color = 'rgb(0,113.985,188.955)'; end end