From 2af77e52c4b509927fce06d5fd8f32219e531496 Mon Sep 17 00:00:00 2001 From: Gilberto Galvis Date: Tue, 10 Aug 2021 18:57:20 -0400 Subject: [PATCH 1/4] fix issue #311 --- plotly/plotlyfig_aux/handlegraphics/updatePatch.m | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/plotly/plotlyfig_aux/handlegraphics/updatePatch.m b/plotly/plotlyfig_aux/handlegraphics/updatePatch.m index b89fffa2..1e942dd2 100644 --- a/plotly/plotlyfig_aux/handlegraphics/updatePatch.m +++ b/plotly/plotlyfig_aux/handlegraphics/updatePatch.m @@ -135,7 +135,7 @@ %---------------------------------------------------------------------% %-patch name-% - if ~isempty(patch_data.DisplayName); + if ~isempty(patch_data.DisplayName) obj.data{patchIndex}.name = patch_data.DisplayName; else obj.data{patchIndex}.name = patch_data.DisplayName; @@ -179,7 +179,7 @@ %-patch fillcolor-% fill = extractPatchFace(patch_data); - if strcmp(obj.data{patchIndex}.type,'scatter'); + if strcmp(obj.data{patchIndex}.type,'scatter') obj.data{patchIndex}.fillcolor = fill.color; else obj.data{patchIndex}.surfacecolor = fill.color; @@ -188,7 +188,7 @@ %---------------------------------------------------------------------% %-surfaceaxis-% - if strcmp(obj.data{patchIndex}.type,'scatter3d'); + if strcmp(obj.data{patchIndex}.type,'scatter3d') minstd = min([std(patch_data.XData) std(patch_data.YData) std(patch_data.ZData)]); ind = find([std(patch_data.XData) std(patch_data.YData) std(patch_data.ZData)] == minstd)-1; obj.data{patchIndex}.surfaceaxis = ind; From 1088c6f8ac18465a73b09b2fddbb593f2e4eeb5e Mon Sep 17 00:00:00 2001 From: Gilberto Galvis Date: Wed, 11 Aug 2021 21:30:10 -0400 Subject: [PATCH 2/4] fix issue #267 --- plotly/plotlyfig_aux/core/updateData.m | 2 + .../updateImplicitFunctionSurface.m | 158 ++++++++++++++++++ 2 files changed, 160 insertions(+) create mode 100644 plotly/plotlyfig_aux/handlegraphics/updateImplicitFunctionSurface.m diff --git a/plotly/plotlyfig_aux/core/updateData.m b/plotly/plotlyfig_aux/core/updateData.m index e828c8ad..7740054d 100644 --- a/plotly/plotlyfig_aux/core/updateData.m +++ b/plotly/plotlyfig_aux/core/updateData.m @@ -34,6 +34,8 @@ updateSurfaceplot(obj,dataIndex); case 'functionsurface' updateFunctionSurface(obj,dataIndex); + case 'implicitfunctionsurface' + updateImplicitFunctionSurface(obj,dataIndex); %-GROUP PLOT OBJECTS-% case 'area' diff --git a/plotly/plotlyfig_aux/handlegraphics/updateImplicitFunctionSurface.m b/plotly/plotlyfig_aux/handlegraphics/updateImplicitFunctionSurface.m new file mode 100644 index 00000000..bfa95034 --- /dev/null +++ b/plotly/plotlyfig_aux/handlegraphics/updateImplicitFunctionSurface.m @@ -0,0 +1,158 @@ +function obj = updateImplicitFunctionSurface(obj, surfaceIndex) + +%-AXIS INDEX-% +axIndex = obj.getAxisIndex(obj.State.Plot(surfaceIndex).AssociatedAxis); + +%-CHECK FOR MULTIPLE AXES-% +[xsource, ysource] = findSourceAxis(obj,axIndex); + +%-SURFACE DATA STRUCTURE- % +image_data = get(obj.State.Plot(surfaceIndex).Handle); +figure_data = get(obj.State.Figure.Handle); + +%-AXIS DATA-% +eval(['xaxis = obj.layout.xaxis' num2str(xsource) ';']); +eval(['yaxis = obj.layout.yaxis' num2str(ysource) ';']); + +%-------------------------------------------------------------------------% + +%-surface xaxis-% +obj.data{surfaceIndex}.xaxis = ['x' num2str(xsource)]; + +%-------------------------------------------------------------------------% + +%-surface yaxis-% +obj.data{surfaceIndex}.yaxis = ['y' num2str(ysource)]; + +%-------------------------------------------------------------------------% + +%-surface type-% +obj.data{surfaceIndex}.type = 'surface'; + +%---------------------------------------------------------------------% + +%-getting x,y,z surface data-% + +strf = func2str(image_data.Function); +ind1 = strfind(strf, '('); ind1 = ind1(1)+1; +ind2 = strfind(strf, ')'); ind2 = ind2(1)-1; +vars = split(strf(ind1:ind2), ','); + +strf = [strf(ind2+2:end) '==0']; +strf = replace(strf, vars{1}, 'Xx'); +strf = replace(strf, vars{2}, 'Yy'); +strf = replace(strf, vars{3}, 'Zz'); + +syms Xx Yy Zz; +f = eval(strf); +s = solve(f, Zz); + +x = image_data.XRange; +y = image_data.YRange; +z = image_data.ZRange; +N = 400; + +[Xx,Yy] = meshgrid(linspace(x(1),x(2),N), linspace(y(1),y(2),N)); +X = []; Y = []; Z = []; + +for n = 1:length(s) + X = [X; Xx]; + Y = [Y; Yy]; + Z = [Z; eval(s(n))]; +end + +clear Xx Yy Zz; +Z(Z < z(1)) = nan; Z(Z > z(2)) = nan; +X(Z < z(1)) = nan; X(Z > z(2)) = nan; +Y(Z < z(1)) = nan; Y(Z > z(2)) = nan; + +%---------------------------------------------------------------------% + +%-surface x-% +obj.data{surfaceIndex}.x = X; + +%---------------------------------------------------------------------% + +%-surface y-% +obj.data{surfaceIndex}.y = Y; + +%---------------------------------------------------------------------% + +%-surface z-% +obj.data{surfaceIndex}.z = Z; + +%---------------------------------------------------------------------% + +%- setting grid mesh by default -% +% x-direction +mden = image_data.MeshDensity; +xsize = (x(2) - x(1)) / mden; +obj.data{surfaceIndex}.contours.x.start = x(1); +obj.data{surfaceIndex}.contours.x.end = x(2); +obj.data{surfaceIndex}.contours.x.size = xsize; +obj.data{surfaceIndex}.contours.x.show = true; +obj.data{surfaceIndex}.contours.x.color = 'black'; +% y-direction +ysize = (y(2) - y(1)) / mden; +obj.data{surfaceIndex}.contours.y.start = y(1); +obj.data{surfaceIndex}.contours.y.end = y(2); +obj.data{surfaceIndex}.contours.y.size = ysize; +obj.data{surfaceIndex}.contours.y.show = true; +obj.data{surfaceIndex}.contours.y.color = 'black'; +% z-direction +zsize = (z(2) - z(1)) / mden; +obj.data{surfaceIndex}.contours.z.start = z(1); +obj.data{surfaceIndex}.contours.z.end = z(2); +obj.data{surfaceIndex}.contours.z.size = zsize; +obj.data{surfaceIndex}.contours.z.show = true; +obj.data{surfaceIndex}.contours.z.color = 'black'; + +%-------------------------------------------------------------------------% + +%-image colorscale-% + +cmap = figure_data.Colormap; +len = length(cmap)-1; + +for c = 1: length(cmap) + col = 255 * cmap(c, :); + obj.data{surfaceIndex}.colorscale{c} = { (c-1)/len , ['rgb(' num2str(col(1)) ',' num2str(col(2)) ',' num2str(col(3)) ')' ] }; +end + +%-------------------------------------------------------------------------% + +%-image surfacescale-% +obj.data{surfaceIndex}.surfacecolor = Z; + +%-------------------------------------------------------------------------% + +%-surface name-% +obj.data{surfaceIndex}.name = image_data.DisplayName; + +%-------------------------------------------------------------------------% + +%-surface showscale-% +obj.data{surfaceIndex}.showscale = false; + +%-------------------------------------------------------------------------% + +%-surface visible-% +obj.data{surfaceIndex}.visible = strcmp(image_data.Visible,'on'); + +%-------------------------------------------------------------------------% + +leg = get(image_data.Annotation); +legInfo = get(leg.LegendInformation); + +switch legInfo.IconDisplayStyle + case 'on' + showleg = true; + case 'off' + showleg = false; +end + +obj.data{surfaceIndex}.showlegend = showleg; + +%-------------------------------------------------------------------------% + +end From 8a9e72189876d7b38d8b67c73554e0a1d7ead4d1 Mon Sep 17 00:00:00 2001 From: Gilberto Galvis Date: Thu, 12 Aug 2021 22:10:52 -0400 Subject: [PATCH 3/4] fix issue #199 --- plotly/plotlyfig.m | 15 + plotly/plotlyfig_aux/core/updateAnnotation.m | 10 +- plotly/plotlyfig_aux/core/updateData.m | 178 +++++----- .../plotlyfig_aux/handlegraphics/updatePie3.m | 326 ++++++++++++++++++ 4 files changed, 443 insertions(+), 86 deletions(-) create mode 100644 plotly/plotlyfig_aux/handlegraphics/updatePie3.m diff --git a/plotly/plotlyfig.m b/plotly/plotlyfig.m index 2bd0769d..28e15768 100644 --- a/plotly/plotlyfig.m +++ b/plotly/plotlyfig.m @@ -60,6 +60,7 @@ obj.PlotOptions.Visible = 'on'; obj.PlotOptions.TriangulatePatch = false; obj.PlotOptions.StripMargins = false; + obj.PlotOptions.TreatAs = '_'; % offline options obj.PlotOptions.Offline = true; @@ -196,6 +197,9 @@ if(strcmpi(varargin{a},'StripMargins')) obj.PlotOptions.StripMargins = varargin{a+1}; end + if(strcmpi(varargin{a},'TreatAs')) + obj.PlotOptions.TreatAs = varargin{a+1}; + end end end @@ -538,6 +542,16 @@ function validate(obj) % find plots of figure plots = findobj(ax(axrev),'-not','Type','Text','-not','Type','axes','-depth',1); + % get number of nbars for pie3 + if strcmpi(obj.PlotOptions.TreatAs, 'pie3') + obj.PlotOptions.nbars = 0; + for i = 1:length(plots) + if strcmpi(getGraphClass(plots(i)), 'surface') + obj.PlotOptions.nbars = obj.PlotOptions.nbars + 1; + end + end + end + % add baseline objects baselines = findobj(ax(axrev),'-property','BaseLine'); @@ -955,6 +969,7 @@ function delete(obj) strcmpi(fieldname,'surface') || strcmpi(fieldname,'scatter3d') ... || strcmpi(fieldname,'mesh3d') || strcmpi(fieldname,'bar') ... || strcmpi(fieldname,'scatterpolar') || strcmpi(fieldname,'barpolar') ... + || strcmpi(fieldname,'scene') ... ) fprintf(['\nWhoops! ' exception.message(1:end-1) ' in ' fieldname '\n\n']); end diff --git a/plotly/plotlyfig_aux/core/updateAnnotation.m b/plotly/plotlyfig_aux/core/updateAnnotation.m index e1e589fa..46e90139 100644 --- a/plotly/plotlyfig_aux/core/updateAnnotation.m +++ b/plotly/plotlyfig_aux/core/updateAnnotation.m @@ -91,9 +91,13 @@ %-------------------------------------------------------------------------% %-text-% -obj.layout.annotations{anIndex}.text = parseString(text_data.String,text_data.Interpreter); -if obj.State.Text(anIndex).Title && isempty(text_data.String) - obj.layout.annotations{anIndex}.text = ''; %empty string annotation +if ~strcmpi(obj.PlotOptions.TreatAs, 'pie3') + obj.layout.annotations{anIndex}.text = parseString(text_data.String,text_data.Interpreter); + if obj.State.Text(anIndex).Title && isempty(text_data.String) + obj.layout.annotations{anIndex}.text = ''; %empty string annotation + end +else + obj.layout.annotations{anIndex}.text = ''; end %-------------------------------------------------------------------------% diff --git a/plotly/plotlyfig_aux/core/updateData.m b/plotly/plotlyfig_aux/core/updateData.m index 7740054d..61eb73af 100644 --- a/plotly/plotlyfig_aux/core/updateData.m +++ b/plotly/plotlyfig_aux/core/updateData.m @@ -2,91 +2,103 @@ function obj = updateData(obj, dataIndex) -%-update plot based on plot call class-% try - switch lower(obj.State.Plot(dataIndex).Class) + + %-update plot based on TreatAs PlotOpts-% + + if ~strcmpi(obj.PlotOptions.TreatAs, '_') + if strcmpi(obj.PlotOptions.TreatAs, 'pie3') + updatePie3(obj, dataIndex); + end + + %-update plot based on plot call class-% + + else - %--CORE PLOT OBJECTS--% - case 'image' - updateImage(obj, dataIndex); - case 'line' - updateLineseries(obj, dataIndex); - case 'categoricalhistogram' - updateCategoricalHistogram(obj, dataIndex); - case 'histogram' - if strcmpi(obj.State.Axis(dataIndex).Handle.Type, 'polaraxes') - updateHistogramPolar(obj, dataIndex); - else - updateHistogram(obj, dataIndex); - end - case 'histogram2' - updateHistogram2(obj, dataIndex); - case 'patch' - % check for histogram - if isHistogram(obj,dataIndex) - updateHistogram(obj,dataIndex); - else - updatePatch(obj, dataIndex); - end - case 'rectangle' - updateRectangle(obj,dataIndex); - case 'surface' - updateSurfaceplot(obj,dataIndex); - case 'functionsurface' - updateFunctionSurface(obj,dataIndex); - case 'implicitfunctionsurface' - updateImplicitFunctionSurface(obj,dataIndex); - - %-GROUP PLOT OBJECTS-% - case 'area' - updateArea(obj, dataIndex); - case 'areaseries' - updateAreaseries(obj, dataIndex); - case 'bar' - updateBar(obj, dataIndex); - case 'barseries' - updateBarseries(obj, dataIndex); - case 'baseline' - updateBaseline(obj, dataIndex); - case {'contourgroup','contour'} - updateContourgroup(obj,dataIndex); - case 'errorbar' - updateErrorbar(obj,dataIndex); - case 'errorbarseries' - updateErrorbarseries(obj,dataIndex); - case 'lineseries' - updateLineseries(obj, dataIndex); - case 'quiver' - updateQuiver(obj, dataIndex); - case 'quivergroup' - updateQuivergroup(obj, dataIndex); - case 'scatter' - if strcmpi(obj.State.Axis(dataIndex).Handle.Type, 'polaraxes') - updateScatterPolar(obj, dataIndex); - else - updateScatter(obj, dataIndex); - end - case 'scattergroup' - updateScattergroup(obj, dataIndex); - case 'stair' - updateStair(obj, dataIndex); - case 'stairseries' - updateStairseries(obj, dataIndex); - case 'stem' - updateStem(obj, dataIndex); - case 'stemseries' - updateStemseries(obj, dataIndex); - case 'surfaceplot' - updateSurfaceplot(obj,dataIndex); - case 'implicitfunctionline' - updateLineseries(obj, dataIndex); - - %--Plotly supported MATLAB group plot objects--% - case {'hggroup','group'} - % check for boxplot - if isBoxplot(obj, dataIndex) - updateBoxplot(obj, dataIndex); - end + switch lower(obj.State.Plot(dataIndex).Class) + + %--CORE PLOT OBJECTS--% + case 'image' + updateImage(obj, dataIndex); + case 'line' + updateLineseries(obj, dataIndex); + case 'categoricalhistogram' + updateCategoricalHistogram(obj, dataIndex); + case 'histogram' + if strcmpi(obj.State.Axis(dataIndex).Handle.Type, 'polaraxes') + updateHistogramPolar(obj, dataIndex); + else + updateHistogram(obj, dataIndex); + end + case 'histogram2' + updateHistogram2(obj, dataIndex); + case 'patch' + % check for histogram + if isHistogram(obj,dataIndex) + updateHistogram(obj,dataIndex); + else + updatePatch(obj, dataIndex); + end + case 'rectangle' + updateRectangle(obj,dataIndex); + case 'surface' + updateSurfaceplot(obj,dataIndex); + case 'functionsurface' + updateFunctionSurface(obj,dataIndex); + case 'implicitfunctionsurface' + updateImplicitFunctionSurface(obj,dataIndex); + + %-GROUP PLOT OBJECTS-% + case 'area' + updateArea(obj, dataIndex); + case 'areaseries' + updateAreaseries(obj, dataIndex); + case 'bar' + updateBar(obj, dataIndex); + case 'barseries' + updateBarseries(obj, dataIndex); + case 'baseline' + updateBaseline(obj, dataIndex); + case {'contourgroup','contour'} + updateContourgroup(obj,dataIndex); + case 'errorbar' + updateErrorbar(obj,dataIndex); + case 'errorbarseries' + updateErrorbarseries(obj,dataIndex); + case 'lineseries' + updateLineseries(obj, dataIndex); + case 'quiver' + updateQuiver(obj, dataIndex); + case 'quivergroup' + updateQuivergroup(obj, dataIndex); + case 'scatter' + if strcmpi(obj.State.Axis(dataIndex).Handle.Type, 'polaraxes') + updateScatterPolar(obj, dataIndex); + else + updateScatter(obj, dataIndex); + end + case 'scattergroup' + updateScattergroup(obj, dataIndex); + case 'stair' + updateStair(obj, dataIndex); + case 'stairseries' + updateStairseries(obj, dataIndex); + case 'stem' + updateStem(obj, dataIndex); + case 'stemseries' + updateStemseries(obj, dataIndex); + case 'surfaceplot' + updateSurfaceplot(obj,dataIndex); + case 'implicitfunctionline' + updateLineseries(obj, dataIndex); + + %--Plotly supported MATLAB group plot objects--% + case {'hggroup','group'} + % check for boxplot + if isBoxplot(obj, dataIndex) + updateBoxplot(obj, dataIndex); + end + end end catch exception diff --git a/plotly/plotlyfig_aux/handlegraphics/updatePie3.m b/plotly/plotlyfig_aux/handlegraphics/updatePie3.m new file mode 100644 index 00000000..60d94f50 --- /dev/null +++ b/plotly/plotlyfig_aux/handlegraphics/updatePie3.m @@ -0,0 +1,326 @@ +function updatePie3(obj,plotIndex) + + %-update according to patch or surface-% + if strcmpi(obj.State.Plot(plotIndex).Class, 'patch') + updatePatchPie3(obj, plotIndex); + else + updateSurfacePie3(obj, plotIndex); + end + + %-hide axis-x-% + obj.layout.scene.xaxis.title = ''; + obj.layout.scene.xaxis.autotick = false; + obj.layout.scene.xaxis.zeroline = false; + obj.layout.scene.xaxis.showline = false; + obj.layout.scene.xaxis.showticklabels = false; + obj.layout.scene.xaxis.showgrid = false; + + %-hide axis-y-% + obj.layout.scene.yaxis.title = ''; + obj.layout.scene.yaxis.autotick = false; + obj.layout.scene.yaxis.zeroline = false; + obj.layout.scene.yaxis.showline = false; + obj.layout.scene.yaxis.showticklabels = false; + obj.layout.scene.yaxis.showgrid = false; + + %-hide axis-z-% + obj.layout.scene.zaxis.title = ''; + obj.layout.scene.zaxis.autotick = false; + obj.layout.scene.zaxis.zeroline = false; + obj.layout.scene.zaxis.showline = false; + obj.layout.scene.zaxis.showticklabels = false; + obj.layout.scene.zaxis.showgrid = false; + + %-put text-% + obj.data{plotIndex}.hoverinfo = 'text'; + obj.data{plotIndex}.hovertext = obj.PlotOptions.perc; + +end + + +%-updatePatchPie3-% + +function obj = updatePatchPie3(obj, patchIndex) + +%-AXIS INDEX-% +axIndex = obj.getAxisIndex(obj.State.Plot(patchIndex).AssociatedAxis); + +%-PATCH DATA STRUCTURE- % +patch_data = get(obj.State.Plot(patchIndex).Handle); + +%-get the percentage-% +if ~any(nonzeros(patch_data.ZData)) + t1 = atan2(patch_data.YData(2), patch_data.XData(2)); + t2 = atan2(patch_data.YData(end-1), patch_data.XData(end-1)); + + a = rad2deg(t2-t1); + if a < 0 + a = a+360; + end + + obj.PlotOptions.perc = sprintf('%d %%', round(100*a/360)); +end + +%-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) ';']); + +%-------------------------------------------------------------------------% + +%-patch xaxis-% +obj.data{patchIndex}.xaxis = ['x' num2str(xsource)]; + +%-------------------------------------------------------------------------% + +%-patch yaxis-% +obj.data{patchIndex}.yaxis = ['y' num2str(ysource)]; + +%-------------------------------------------------------------------------% + +%-patch type-% +obj.data{patchIndex}.type = 'scatter3d'; + +%-------------------------------------------------------------------------% + +%-patch x-% +xdata = patch_data.XData; +if isvector(xdata) + obj.data{patchIndex}.x = [xdata' xdata(1)]; +else + xtemp = reshape(xdata,[],1); + xnew = []; + for n = 1:size(xdata,2) + xnew = [xnew ; xdata(:,n) ; xdata(1,n); NaN]; + end + obj.data{patchIndex}.x = xnew; +end + +%---------------------------------------------------------------------% + +%-patch y-% +ydata = patch_data.YData; +if isvector(ydata) + obj.data{patchIndex}.y = [ydata' ydata(1)]; +else + ytemp = reshape(ydata,[],1); + ynew = []; + for n = 1:size(ydata,2) + ynew = [ynew ; ydata(:,n) ; ydata(1,n); NaN]; + end + obj.data{patchIndex}.y = ynew; +end + +%---------------------------------------------------------------------% + +%-patch z-% +zdata = patch_data.ZData; + +if isvector(ydata) + obj.data{patchIndex}.z = [zdata' zdata(1)]; +else + ztemp = reshape(zdata,[],1); + znew = []; + for n = 1:size(zdata,2) + znew = [znew ; zdata(:,n) ; zdata(1,n); NaN]; + end + obj.data{patchIndex}.z = znew; +end + +%---------------------------------------------------------------------% + +%-patch name-% +if ~isempty(patch_data.DisplayName) + obj.data{patchIndex}.name = patch_data.DisplayName; +else + obj.data{patchIndex}.name = patch_data.DisplayName; +end + +%---------------------------------------------------------------------% + +%-patch visible-% +obj.data{patchIndex}.visible = strcmp(patch_data.Visible,'on'); + +%---------------------------------------------------------------------% + +%-patch fill-% +% obj.data{patchIndex}.fill = 'tozeroy'; + +%-PATCH MODE-% +if ~strcmpi('none', patch_data.Marker) && ~strcmpi('none', patch_data.LineStyle) + mode = 'lines+markers'; +elseif ~strcmpi('none', patch_data.Marker) + mode = 'markers'; +elseif ~strcmpi('none', patch_data.LineStyle) + mode = 'lines'; +else + mode = 'none'; +end + +obj.data{patchIndex}.mode = mode; + +%---------------------------------------------------------------------% + +%-patch marker-% +obj.data{patchIndex}.marker = extractPatchMarker(patch_data); + +%---------------------------------------------------------------------% + +%-patch line-% +obj.data{patchIndex}.line = extractPatchLine(patch_data); + +%---------------------------------------------------------------------% + +%-patch fillcolor-% +fill = extractPatchFace(patch_data); + +if strcmp(obj.data{patchIndex}.type,'scatter') + obj.data{patchIndex}.fillcolor = fill.color; +else + obj.data{patchIndex}.surfacecolor = fill.color; +end + +%---------------------------------------------------------------------% + +%-surfaceaxis-% +if strcmp(obj.data{patchIndex}.type,'scatter3d') + minstd = min([std(patch_data.XData) std(patch_data.YData) std(patch_data.ZData)]); + ind = find([std(patch_data.XData) std(patch_data.YData) std(patch_data.ZData)] == minstd)-1; + obj.data{patchIndex}.surfaceaxis = ind; +end + +%-------------------------------------------------------------------------% + +%-patch showlegend-% +leg = get(patch_data.Annotation); +legInfo = get(leg.LegendInformation); + +switch legInfo.IconDisplayStyle + case 'on' + showleg = true; + case 'off' + showleg = false; +end + +obj.data{patchIndex}.showlegend = showleg; + +%-------------------------------------------------------------------------% +end + + + +function obj = updateSurfacePie3(obj, surfaceIndex) + +%-AXIS INDEX-% +axIndex = obj.getAxisIndex(obj.State.Plot(surfaceIndex).AssociatedAxis); + +%-CHECK FOR MULTIPLE AXES-% +[xsource, ysource] = findSourceAxis(obj,axIndex); + +%-SURFACE DATA STRUCTURE- % +image_data = get(obj.State.Plot(surfaceIndex).Handle); +figure_data = get(obj.State.Figure.Handle); + +%-AXIS DATA-% +eval(['xaxis = obj.layout.xaxis' num2str(xsource) ';']); +eval(['yaxis = obj.layout.yaxis' num2str(ysource) ';']); + +%-------------------------------------------------------------------------% + +%-surface xaxis-% +obj.data{surfaceIndex}.xaxis = ['x' num2str(xsource)]; + +%-------------------------------------------------------------------------% + +%-surface yaxis-% +obj.data{surfaceIndex}.yaxis = ['y' num2str(ysource)]; + +%-------------------------------------------------------------------------% + +% check for 3D +if any(nonzeros(image_data.ZData)) + + %-surface type-% + obj.data{surfaceIndex}.type = 'surface'; + + %---------------------------------------------------------------------% + + %-surface x-% + obj.data{surfaceIndex}.x = image_data.XData; + + %---------------------------------------------------------------------% + + %-surface y-% + obj.data{surfaceIndex}.y = image_data.YData; + + %---------------------------------------------------------------------% + + %-surface z-% + obj.data{surfaceIndex}.z = image_data.ZData; + + %---------------------------------------------------------------------% + +else + + %-surface type-% + obj = updateImage(obj, surfaceIndex); + + %-surface x-% + obj.data{surfaceIndex}.x = image_data.XData(1,:); + + %-surface y-% + obj.data{surfaceIndex}.y = image_data.YData(:,1); +end + +%-------------------------------------------------------------------------% + +%-image colorscale-% + +cmap = figure_data.Colormap; +len = length(cmap)-1; + +for c = 1:length(cmap) + col = 255 * cmap(c, :); + obj.data{surfaceIndex}.colorscale{c} = { (c-1)/len , ['rgb(' num2str(col(1)) ',' num2str(col(2)) ',' num2str(col(3)) ')' ] }; +end + +obj.data{surfaceIndex}.surfacecolor = 255*(image_data.CData-1) / obj.PlotOptions.nbars; +obj.data{surfaceIndex}.cmax = 255; +obj.data{surfaceIndex}.cmin = 0; +obj.layout.scene.aspectmode = 'data'; + +%-------------------------------------------------------------------------% + +%-surface name-% +obj.data{surfaceIndex}.name = image_data.DisplayName; + +%-------------------------------------------------------------------------% + +%-surface showscale-% +obj.data{surfaceIndex}.showscale = false; + +%-------------------------------------------------------------------------% + +%-surface visible-% +obj.data{surfaceIndex}.visible = strcmp(image_data.Visible,'on'); + +%-------------------------------------------------------------------------% + +leg = get(image_data.Annotation); +legInfo = get(leg.LegendInformation); + +switch legInfo.IconDisplayStyle + case 'on' + showleg = true; + case 'off' + showleg = false; +end + +obj.data{surfaceIndex}.showlegend = showleg; + +%-------------------------------------------------------------------------% + +end + From 06237f74c46d641bc50bacb067fbeb3760e82c8f Mon Sep 17 00:00:00 2001 From: Gilberto Galvis Date: Fri, 13 Aug 2021 08:24:01 -0400 Subject: [PATCH 4/4] fix issue #248 --- plotly/plotlyfig_aux/core/updateData.m | 2 + .../handlegraphics/updateFunctionContour.m | 202 ++++++++++++++++++ 2 files changed, 204 insertions(+) create mode 100644 plotly/plotlyfig_aux/handlegraphics/updateFunctionContour.m diff --git a/plotly/plotlyfig_aux/core/updateData.m b/plotly/plotlyfig_aux/core/updateData.m index 61eb73af..d8331ebd 100644 --- a/plotly/plotlyfig_aux/core/updateData.m +++ b/plotly/plotlyfig_aux/core/updateData.m @@ -61,6 +61,8 @@ updateBaseline(obj, dataIndex); case {'contourgroup','contour'} updateContourgroup(obj,dataIndex); + case 'functioncontour' + updateFunctionContour(obj,dataIndex); case 'errorbar' updateErrorbar(obj,dataIndex); case 'errorbarseries' diff --git a/plotly/plotlyfig_aux/handlegraphics/updateFunctionContour.m b/plotly/plotlyfig_aux/handlegraphics/updateFunctionContour.m new file mode 100644 index 00000000..043944de --- /dev/null +++ b/plotly/plotlyfig_aux/handlegraphics/updateFunctionContour.m @@ -0,0 +1,202 @@ +function obj = updateFunctionContour(obj,contourIndex) + +%-FIGURE DATA STRUCTURE-% +figure_data = get(obj.State.Figure.Handle); + +%-AXIS INDEX-% +axIndex = obj.getAxisIndex(obj.State.Plot(contourIndex).AssociatedAxis); + +%-AXIS DATA STRUCTURE-% +axis_data = get(obj.State.Plot(contourIndex).AssociatedAxis); + +%-PLOT DATA STRUCTURE- % +contour_data = get(obj.State.Plot(contourIndex).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) ';']); + +%-------------------------------------------------------------------------% + +%-contour xaxis-% +obj.data{contourIndex}.xaxis = ['x' num2str(xsource)]; + +%-------------------------------------------------------------------------% + +%-contour yaxis-% +obj.data{contourIndex}.yaxis = ['y' num2str(ysource)]; + +%-------------------------------------------------------------------------% + +%-contour name-% +obj.data{contourIndex}.name = contour_data.DisplayName; + +%-------------------------------------------------------------------------% + +%-contour type-% +obj.data{contourIndex}.type = 'contour'; + +%-------------------------------------------------------------------------% + +%-setting the plot-% +xdata = contour_data.XData; +ydata = contour_data.YData; +zdata = contour_data.ZData; + +%-contour x data-% +if ~isvector(xdata) + obj.data{contourIndex}.x = xdata(1,:); +else + obj.data{contourIndex}.x = xdata; +end + +%-contour y data-% +if ~isvector(ydata) + obj.data{contourIndex}.y = ydata(:,1); +else + obj.data{contourIndex}.y = ydata; +end + +%-contour z data-% +obj.data{contourIndex}.z = zdata; + +%-------------------------------------------------------------------------% + +%-contour x type-% + +obj.data{contourIndex}.xtype = 'array'; + +%-------------------------------------------------------------------------% + +%-contour y type-% + +obj.data{contourIndex}.ytype = 'array'; + +%-------------------------------------------------------------------------% + +%-contour visible-% + +obj.data{contourIndex}.visible = strcmp(contour_data.Visible,'on'); + +%-------------------------------------------------------------------------% + +%-contour showscale-% +obj.data{contourIndex}.showscale = false; + +%-------------------------------------------------------------------------% + +%-zauto-% +obj.data{contourIndex}.zauto = false; + +%-------------------------------------------------------------------------% + +%-zmin-% +obj.data{contourIndex}.zmin = axis_data.CLim(1); + +%-------------------------------------------------------------------------% + +%-zmax-% +obj.data{contourIndex}.zmax = axis_data.CLim(2); + +%-------------------------------------------------------------------------% + +%-colorscale (ASSUMES PATCH CDATAMAP IS 'SCALED')-% +colormap = figure_data.Colormap; + +for c = 1:size((colormap),1) + col = 255*(colormap(c,:)); + obj.data{contourIndex}.colorscale{c} = {(c-1)/(size(colormap,1)-1), ['rgb(' num2str(col(1)) ',' num2str(col(2)) ',' num2str(col(3)) ')']}; +end + +%-------------------------------------------------------------------------% + +%-contour reverse scale-% +obj.data{contourIndex}.reversescale = false; + +%-------------------------------------------------------------------------% + +%-autocontour-% +obj.data{contourIndex}.autocontour = false; + +%-------------------------------------------------------------------------% + +%-contour contours-% + +%-coloring-% +switch contour_data.Fill + case 'off' + obj.data{contourIndex}.contours.coloring = 'lines'; + case 'on' + obj.data{contourIndex}.contours.coloring = 'fill'; +end + +%-start-% +obj.data{contourIndex}.contours.start = contour_data.LevelList(1); + +%-end-% +obj.data{contourIndex}.contours.end = contour_data.LevelList(end); + +%-step-% +obj.data{contourIndex}.contours.size = contour_data.LevelStep; + +%-------------------------------------------------------------------------% + +if(~strcmp(contour_data.LineStyle,'none')) + + %-contour line colour-% + if isnumeric(contour_data.LineColor) + col = 255*contour_data.LineColor; + obj.data{contourIndex}.line.color = ['rgb(' num2str(col(1)) ',' num2str(col(2)) ',' num2str(col(3)) ')']; + else + obj.data{contourIndex}.line.color = 'rgba(0,0,0,0)'; + end + + %-contour line width-% + obj.data{contourIndex}.line.width = contour_data.LineWidth; + + %-contour line dash-% + switch contour_data.LineStyle + case '-' + LineStyle = 'solid'; + case '--' + LineStyle = 'dash'; + case ':' + LineStyle = 'dot'; + case '-.' + LineStyle = 'dashdot'; + end + + obj.data{contourIndex}.line.dash = LineStyle; + + %-contour smoothing-% + obj.data{contourIndex}.line.smoothing = 0; + +else + + %-contours showlines-% + obj.data{contourIndex}.contours.showlines = false; + +end + +%-------------------------------------------------------------------------% + +%-contour showlegend-% + +leg = get(contour_data.Annotation); +legInfo = get(leg.LegendInformation); + +switch legInfo.IconDisplayStyle + case 'on' + showleg = true; + case 'off' + showleg = false; +end + +obj.data{contourIndex}.showlegend = showleg; + +%-------------------------------------------------------------------------% + +end