Skip to content

Commit aefe991

Browse files
Merge pull request #372 from plotly/Adding_pareto_functionality_to_fig2plotly
Adding pareto functionality to fig2plotly
2 parents 9a4a3d9 + e3c4db1 commit aefe991

File tree

6 files changed

+137
-44
lines changed

6 files changed

+137
-44
lines changed

plotly/plotlyfig.m

+21-10
Original file line numberDiff line numberDiff line change
@@ -562,17 +562,21 @@ function validate(obj)
562562
temp_ax = ax; deleted_idx = 0;
563563
for i = 1:length(ax)
564564
for j = i:length(ax)
565-
if ((mean(eq(ax(i).Position, ax(j).Position)) == 1) && (i~=j) && strcmp(ax(i).Children.Type, 'histogram'))
566-
temp_plots = findobj(temp_ax(i),'-not','Type','Text','-not','Type','axes','-depth',1);
567-
if isprop(temp_plots, 'FaceAlpha')
568-
update_opac(i) = true;
569-
else
570-
update_opac(i) = false;
565+
try
566+
if ((mean(eq(ax(i).Position, ax(j).Position)) == 1) && (i~=j) && strcmp(ax(i).Children.Type, 'histogram'))
567+
temp_plots = findobj(temp_ax(i),'-not','Type','Text','-not','Type','axes','-depth',1);
568+
if isprop(temp_plots, 'FaceAlpha')
569+
update_opac(i) = true;
570+
else
571+
update_opac(i) = false;
572+
end
573+
temp_ax(i).YTick = temp_ax(j- deleted_idx).YTick;
574+
temp_ax(i).XTick = temp_ax(j- deleted_idx).XTick;
575+
temp_ax(j - deleted_idx) = [];
576+
deleted_idx = deleted_idx + 1;
571577
end
572-
temp_ax(i).YTick = temp_ax(j- deleted_idx).YTick;
573-
temp_ax(i).XTick = temp_ax(j- deleted_idx).XTick;
574-
temp_ax(j - deleted_idx) = [];
575-
deleted_idx = deleted_idx + 1;
578+
catch
579+
% TODO: error with ax(i).Children.Type. isfield is no enogh
576580
end
577581
end
578582
end
@@ -625,6 +629,13 @@ function validate(obj)
625629
obj.State.Plot(obj.State.Figure.NumPlots).AssociatedAxis = handle(ax(axrev));
626630
obj.State.Plot(obj.State.Figure.NumPlots).Class = getGraphClass(plots(nprev));
627631
end
632+
633+
% this works for pareto
634+
if length(plots) == 0
635+
if obj.State.Figure.NumPlots ~=0
636+
obj.State.Plot(obj.State.Figure.NumPlots).AssociatedAxis = handle(ax(axrev));
637+
end
638+
end
628639

629640
% find text of figure
630641
texts = findobj(ax(axrev),'Type','text','-depth',1);

plotly/plotlyfig_aux/handlegraphics/updateHistogram.m

+8
Original file line numberDiff line numberDiff line change
@@ -191,10 +191,18 @@
191191

192192
%-------------------------------------------------------------------------%
193193

194+
%-marker data-%
194195
obj.data{histIndex}.marker = extractPatchFace(hist_data);
195196

196197
%-------------------------------------------------------------------------%
197198

199+
%-change color when multiple histograms same axes-%
200+
if min([xsource, ysource]) == 1
201+
obj.data{histIndex}.marker = rmfield(obj.data{histIndex}.marker, 'color');
202+
end
203+
204+
%-------------------------------------------------------------------------%
205+
198206
%-hist visible-%
199207
obj.data{histIndex}.visible = strcmp(hist_data.Visible,'on');
200208

plotly/plotlyfig_aux/handlegraphics/updateStem.m

+10-4
Original file line numberDiff line numberDiff line change
@@ -142,13 +142,19 @@
142142
linecolor = cell(3*npoints,1);
143143
hidecolor = 'rgba(0,0,0,0)';
144144

145+
linecolor(1:3:3*npoints) = {hidecolor};
145146
markercolor(1:3:3*npoints) = {hidecolor};
146-
markercolor(2:3:3*npoints) = {stem_data.marker.color};
147-
markercolor(3:3:3*npoints) = {hidecolor};
148147

149-
linecolor(1:3:3*npoints) = {hidecolor};
150-
linecolor(2:3:3*npoints) = {stem_data.marker.line.color};
148+
try
149+
linecolor(2:3:3*npoints) = {stem_data.marker.line.color};
150+
markercolor(2:3:3*npoints) = {stem_data.marker.color};
151+
catch
152+
linecolor(2:3:3*npoints) = {stem_data.marker.color};
153+
markercolor(2:3:3*npoints) = {hidecolor};
154+
end
155+
151156
linecolor(3:3:3*npoints) = {hidecolor};
157+
markercolor(3:3:3*npoints) = {hidecolor};
152158

153159
%-add new marker/line colors-%
154160
stem_data.marker.color = markercolor;

plotly/plotlyfig_aux/helpers/extractAxisData.m

+92-28
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,6 @@
9191
%-------------------------------------------------------------------------%
9292

9393
%-axis type-%
94-
9594
axis.type = eval(['axis_data.' axisName 'Scale']);
9695

9796
%-------------------------------------------------------------------------%
@@ -120,6 +119,9 @@
120119
%---------------------------------------------------------------------%
121120

122121
else
122+
123+
%-get axis limits-%
124+
dataLim = eval( sprintf('axis_data.%sLim', axisName) );
123125

124126
%-axis tick direction-%
125127
switch axis_data.TickDir
@@ -140,24 +142,31 @@
140142

141143
%---------------------------------------------------------------------%
142144

145+
%-LOG TYPE-%
143146
if strcmp(axis.type,'log')
144147

145148
%-axis range-%
146-
axis.range = eval(['log10(axis_data.' axisName 'Lim);']);
149+
axis.range = eval( sprintf('log10(dataLim)') ); %['log10(axis_data.' axisName 'Lim);']);
147150
%-axis autotick-%
148151
axis.autotick = true;
149152
%-axis nticks-%
150153
axis.nticks = eval(['length(axis_data.' axisName 'Tick) + 1;']);
151154

152155
%---------------------------------------------------------------------%
153156

157+
%-LINEAR TYPE-%
154158
elseif strcmp(axis.type,'linear')
159+
160+
%-----------------------------------------------------------------%
161+
162+
%-get tick label mode-%
155163
TickLabelMode = eval(['axis_data.' axisName 'TickLabelMode;']);
164+
165+
%-----------------------------------------------------------------%
166+
167+
%-AUTO MODE-%
156168
if strcmp(TickLabelMode,'auto')
157169

158-
%-axis range-%
159-
dataLim = eval(['axis_data.' axisName 'Lim']);
160-
161170
%-------------------------------------------------------------%
162171

163172
if isnumeric(dataLim)
@@ -192,39 +201,94 @@
192201
axis.autotick = true;
193202
%-axis numticks-%
194203
axis.nticks = eval(['length(axis_data.' axisName 'Tick)+1']);
204+
195205
%-----------------------------------------------------------------%
196206

207+
%-CUSTOM MODE-%
197208
else
198-
%-axis show tick labels-%
199-
Tick = eval(['axis_data.' axisName 'TickLabel;']);
200-
if isempty(Tick)
209+
210+
%-------------------------------------------------------------%
211+
212+
%-get tick labels-%
213+
tickLabels = eval(['axis_data.' axisName 'TickLabel;']);
214+
215+
%-------------------------------------------------------------%
216+
217+
%-hide tick labels as lichkLabels field is empty-%
218+
if isempty(tickLabels)
219+
220+
%-------------------------------------------------------------%
221+
201222
%-hide tick labels-%
202223
axis.showticklabels = false;
224+
225+
%-------------------------------------------------------------%
226+
203227
%-axis autorange-%
204228
axis.autorange = true;
229+
230+
%-------------------------------------------------------------%
231+
232+
%-axis show tick labels as tickLabels matlab field-%
205233
else
206-
%-axis labels
207-
labels = str2double(axis_data.YTickLabel);
208-
try
209-
%find numbers in labels
210-
labelnums = find(~isnan(labels));
211-
%-axis type linear-%
212-
axis.type = 'linear';
213-
%-range (overwrite)-%
214-
delta = (labels(labelnums(2)) - labels(labelnums(1)))/(labelnums(2)-labelnums(1));
215-
axis.range = [labels(labelnums(1))-delta*(labelnums(1)-1) labels(labelnums(1)) + (length(labels)-labelnums(1))*delta];
216-
%-axis autotick-%
217-
axis.autotick = true;
218-
%-axis numticks-%
219-
axis.nticks = eval(['length(axis_data.' axisName 'Tick) + 1;']);
220-
catch
221-
%-axis type category-%
222-
axis.type = 'category';
223-
%-range (overwrite)-%
234+
235+
%-------------------------------------------------------------%
236+
237+
axis.showticklabels = true;
238+
axis.type = 'linear';
239+
240+
%-------------------------------------------------------------%
241+
242+
if isnumeric(dataLim)
243+
axis.range = eval(['axis_data.' axisName 'Lim;']);
244+
else
224245
axis.autorange = true;
225-
%-axis autotick-%
226-
% axis.autotick = true;
227246
end
247+
248+
%-------------------------------------------------------------%
249+
250+
axis.tickvals = tick;
251+
axis.ticktext = tickLabels;
252+
253+
%-------------------------------------------------------------%
254+
255+
%+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++%
256+
% NOTE:
257+
% The next piece of code was replaced by the previous one.
258+
% I think that the new piece of code is better, optimal and
259+
% extends to all cases. However, I will leave this piece of
260+
% code commented in case there is a problem in the future.
261+
%
262+
% If there is a problem with the new piece of code, please
263+
% comment and uncomment the next piece of code.
264+
%
265+
% If everything goes well with the new gripping piece, at
266+
% the end of the development we will be able to remove the
267+
% commented lines
268+
%+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++%
269+
270+
%-axis labels
271+
% labels = str2double(tickLabels);
272+
% try
273+
% %find numbers in labels
274+
% labelnums = find(~isnan(labels));
275+
% %-axis type linear-%
276+
% axis.type = 'linear';
277+
% %-range (overwrite)-%
278+
% delta = (labels(labelnums(2)) - labels(labelnums(1)))/(labelnums(2)-labelnums(1));
279+
% axis.range = [labels(labelnums(1))-delta*(labelnums(1)-1) labels(labelnums(1)) + (length(labels)-labelnums(1))*delta];
280+
% %-axis autotick-%
281+
% axis.autotick = true;
282+
% %-axis numticks-%
283+
% axis.nticks = eval(['length(axis_data.' axisName 'Tick) + 1;']);
284+
% catch
285+
% %-axis type category-%
286+
% axis.type = 'category';
287+
% %-range (overwrite)-%
288+
% axis.autorange = true;
289+
% %-axis autotick-%
290+
% % axis.autotick = true;
291+
% end
228292
end
229293
end
230294
end

plotly/plotlyfig_aux/helpers/extractLineMarker.m

+1-1
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@
6969
%-------------------------------------------------------------------------%
7070

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

7474
filledMarker = ismember(line_data.Marker,filledMarkerSet);
7575

plotly/plotlyfig_aux/helpers/extractPatchFace.m

+5-1
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,16 @@
4444
capCD = max(min(patch_data.FaceVertexCData(1,1),axis_data.CLim(2)),axis_data.CLim(1));
4545
scalefactor = (capCD -axis_data.CLim(1))/diff(axis_data.CLim);
4646
col = 255*(colormap(1+ floor(scalefactor*(length(colormap)-1)),:));
47-
case {'direct', 'auto'}
47+
case 'direct'
48+
patch_data.FaceVertexCData
4849
col = 255*(colormap(patch_data.FaceVertexCData(1,1),:));
4950

5051
end
5152

5253
marker.color = ['rgb(' num2str(col(1)) ',' num2str(col(2)) ',' num2str(col(3)) ')'];
54+
55+
case 'auto'
56+
marker.color = 'rgb(0,113.985,188.955)';
5357
end
5458
end
5559

0 commit comments

Comments
 (0)