Skip to content

Adding pareto functionality to fig2plotly #372

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
Sep 10, 2021
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
31 changes: 21 additions & 10 deletions plotly/plotlyfig.m
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand Down
8 changes: 8 additions & 0 deletions plotly/plotlyfig_aux/handlegraphics/updateHistogram.m
Original file line number Diff line number Diff line change
Expand Up @@ -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');

Expand Down
14 changes: 10 additions & 4 deletions plotly/plotlyfig_aux/handlegraphics/updateStem.m
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
120 changes: 92 additions & 28 deletions plotly/plotlyfig_aux/helpers/extractAxisData.m
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@
%-------------------------------------------------------------------------%

%-axis type-%

axis.type = eval(['axis_data.' axisName 'Scale']);

%-------------------------------------------------------------------------%
Expand Down Expand Up @@ -120,6 +119,9 @@
%---------------------------------------------------------------------%

else

%-get axis limits-%
dataLim = eval( sprintf('axis_data.%sLim', axisName) );

%-axis tick direction-%
switch axis_data.TickDir
Expand All @@ -140,24 +142,31 @@

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

%-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-%
axis.nticks = eval(['length(axis_data.' axisName 'Tick) + 1;']);

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

%-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)
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion plotly/plotlyfig_aux/helpers/extractLineMarker.m
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
%-------------------------------------------------------------------------%

filledMarkerSet = {'o','square','s','diamond','d',...
'v','^', '<','>','hexagram','pentagram', '*', '+'};
'v','^', '<','>','hexagram','pentagram'};

filledMarker = ismember(line_data.Marker,filledMarkerSet);

Expand Down
6 changes: 5 additions & 1 deletion plotly/plotlyfig_aux/helpers/extractPatchFace.m
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down