diff --git a/plotly/plotlyfig.m b/plotly/plotlyfig.m index 6797bb4b..15a77540 100644 --- a/plotly/plotlyfig.m +++ b/plotly/plotlyfig.m @@ -450,7 +450,11 @@ function validate(obj) % handle title (for feed) if obj.PlotOptions.CleanFeedTitle - cleanFeedTitle(obj); + try + cleanFeedTitle(obj); + catch + % TODO to the future + end end %get args @@ -642,7 +646,7 @@ function validate(obj) updateAxis(obj,n); catch % TODO to the future - disp('warning: error in updateAxis') + % disp('catch at line 647 in plotlyfig.m file') end end @@ -657,7 +661,7 @@ function validate(obj) end catch % TODO to the future - disp('warning: error using update_opac') + % disp('catch at line 664 in plotlyfig.m file') end end @@ -665,10 +669,14 @@ function validate(obj) % update annotations for n = 1:obj.State.Figure.NumTexts try - updateAnnotation(obj,n); + if ~strcmpi(obj.State.Plot(dataIndex).Class, 'heatmap') + updateAnnotation(obj,n); + else + obj.PlotOptions.CleanFeedTitle = false; + end catch % TODO to the future - disp('warning: error in updateAnnotation') + % disp('catch at line 679 in plotlyfig.m file') end end @@ -972,7 +980,8 @@ function delete(obj) strcmpi(fieldname,'surface') || strcmpi(fieldname,'scatter3d') ... || strcmpi(fieldname,'mesh3d') || strcmpi(fieldname,'bar') ... || strcmpi(fieldname,'scatterpolar') || strcmpi(fieldname,'barpolar') ... - || strcmpi(fieldname,'scene') ... + || strcmpi(fieldname,'scene') || strcmpi(fieldname,'layout') ... + || strcmpi(fieldname,'heatmap') ... ) fprintf(['\nWhoops! ' exception.message(1:end-1) ' in ' fieldname '\n\n']); end diff --git a/plotly/plotlyfig_aux/core/updateData.m b/plotly/plotlyfig_aux/core/updateData.m index d8331ebd..da579f05 100644 --- a/plotly/plotlyfig_aux/core/updateData.m +++ b/plotly/plotlyfig_aux/core/updateData.m @@ -9,6 +9,10 @@ if ~strcmpi(obj.PlotOptions.TreatAs, '_') if strcmpi(obj.PlotOptions.TreatAs, 'pie3') updatePie3(obj, dataIndex); + elseif strcmpi(obj.PlotOptions.TreatAs, 'pcolor') + updatePColor(obj, dataIndex); + elseif strcmpi(obj.PlotOptions.TreatAs, 'polarplot') + updatePolarplot(obj, dataIndex); end %-update plot based on plot call class-% @@ -18,6 +22,8 @@ switch lower(obj.State.Plot(dataIndex).Class) %--CORE PLOT OBJECTS--% + case 'heatmap' + updateHeatmap(obj, dataIndex); case 'image' updateImage(obj, dataIndex); case 'line' @@ -148,7 +154,7 @@ end catch % TODO to the future - disp('waring: error in updateData at AXIS/DATA CLEAN UP section') + % disp('catch at line 157 in updateData.m file') end %-------------------------------------------------------------------------% diff --git a/plotly/plotlyfig_aux/handlegraphics/updateHeatmap.m b/plotly/plotlyfig_aux/handlegraphics/updateHeatmap.m new file mode 100644 index 00000000..9fad55fd --- /dev/null +++ b/plotly/plotlyfig_aux/handlegraphics/updateHeatmap.m @@ -0,0 +1,52 @@ +function obj = updateHeatmap(obj,heatIndex) + +%-------------------------------------------------------------------------% + +%-HEATMAP DATA STRUCTURE- % +heat_data = get(obj.State.Plot(heatIndex).Handle); +%-------------------------------------------------------------------------% + +%-heatmap type-% +obj.data{heatIndex}.type = 'heatmap'; + +%-------------------------------------------------------------------------% + +%-format data-% +obj.data{heatIndex}.x = heat_data.XData; +obj.data{heatIndex}.y = heat_data.YData; +obj.data{heatIndex}.z = heat_data.ColorData(end:-1:1, :); + +%-------------------------------------------------------------------------% + +%-heatmap colorscale-% +cmap = heat_data.Colormap; +len = length(cmap)-1; + +for c = 1: length(cmap) + col = 255 * cmap(c, :); + obj.data{heatIndex}.colorscale{c} = { (c-1)/len , ['rgb(' num2str(col(1)) ',' num2str(col(2)) ',' num2str(col(3)) ')' ] }; +end + +%-------------------------------------------------------------------------% + +%-setting plot-% +obj.data{heatIndex}.hoverinfo = 'text'; +obj.data{heatIndex}.text = heat_data.ColorData(end:-1:1, :); +obj.data{heatIndex}.hoverlabel.bgcolor = 'white'; + +%-------------------------------------------------------------------------% + +%-show colorbar-% +obj.data{heatIndex}.showscale = false; +if strcmpi(heat_data.ColorbarVisible, 'on') + obj.data{heatIndex}.showscale = true; +end + +%-------------------------------------------------------------------------% + +%-hist visible-% +obj.data{heatIndex}.visible = strcmp(heat_data.Visible,'on'); + +%-------------------------------------------------------------------------% + +end diff --git a/plotly/plotlyfig_aux/handlegraphics/updateLineseries.m b/plotly/plotlyfig_aux/handlegraphics/updateLineseries.m index e20bac47..28b35352 100644 --- a/plotly/plotlyfig_aux/handlegraphics/updateLineseries.m +++ b/plotly/plotlyfig_aux/handlegraphics/updateLineseries.m @@ -131,6 +131,9 @@ function updateLineseries(obj,plotIndex) %-------------------------------------------------------------------------% +%-Fro 3D plots-% +obj.PlotOptions.is3d = false; % by default + if isfield(plot_data,'ZData') numbset = unique(plot_data.ZData); @@ -139,8 +142,11 @@ function updateLineseries(obj,plotIndex) %-scatter z-% obj.data{plotIndex}.z = plot_data.ZData; - %overwrite type + %-overwrite type-% obj.data{plotIndex}.type = 'scatter3d'; + + %-flag to manage 3d plots-% + obj.PlotOptions.is3d = true; end end diff --git a/plotly/plotlyfig_aux/handlegraphics/updatePColor.m b/plotly/plotlyfig_aux/handlegraphics/updatePColor.m new file mode 100644 index 00000000..359a6ab0 --- /dev/null +++ b/plotly/plotlyfig_aux/handlegraphics/updatePColor.m @@ -0,0 +1,178 @@ +function obj = updatePColor(obj, patchIndex) + +%-AXIS INDEX-% +axIndex = obj.getAxisIndex(obj.State.Plot(patchIndex).AssociatedAxis); + +%-PCOLOR DATA STRUCTURE- % +pcolor_data = get(obj.State.Plot(patchIndex).Handle); +figure_data = get(obj.State.Figure.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) ';']); + +%-------------------------------------------------------------------------% + +%-pcolor xaxis-% +obj.data{patchIndex}.xaxis = ['x' num2str(xsource)]; + +%-------------------------------------------------------------------------% + +%-pcolor yaxis-% +obj.data{patchIndex}.yaxis = ['y' num2str(ysource)]; + +%-------------------------------------------------------------------------% + +%-plot type: surface-% +obj.data{patchIndex}.type = 'surface'; + +%-------------------------------------------------------------------------% + +%-format data-% +XData = pcolor_data.XData; +YData = pcolor_data.YData; +ZData = pcolor_data.ZData; +CData = pcolor_data.CData; +usegrid = false; + +if isvector(XData) + usegrid = true; + [XData, YData] = meshgrid(XData, YData); +end + +sizes = [(size(XData, 1)-1)*2, (size(XData, 2)-1)*2]; +xdata = zeros(sizes); +ydata = zeros(sizes); +zdata = zeros(sizes); +cdata = zeros(sizes); + +for n = 1:size(XData, 2)-1 + for m = 1:size(XData, 1)-1 + + % get indices + n1 = 2*(n-1)+1; m1 = 2*(m-1)+1; + + % get surface mesh + xdata(m1:m1+1,n1:n1+1) = XData(m:m+1, n:n+1); + ydata(m1:m1+1,n1:n1+1) = YData(m:m+1, n:n+1); + zdata(m1:m1+1,n1:n1+1) = ZData(m:m+1, n:n+1); + cdata(m1:m1+1,n1:n1+1) = ones(2,2)*CData(m, n); + end +end + +%-------------------------------------------------------------------------% + +%-x-data-% +obj.data{patchIndex}.x = xdata; + +%-------------------------------------------------------------------------% + +%-y-data-% +obj.data{patchIndex}.y = ydata; + +%-------------------------------------------------------------------------% + +%-z-data-% +obj.data{patchIndex}.z = zdata; + +%-------------------------------------------------------------------------% + +%-coloring-% +cmap = figure_data.Colormap; +len = length(cmap)-1; + +for c = 1: length(cmap) + col = 255 * cmap(c, :); + obj.data{patchIndex}.colorscale{c} = { (c-1)/len , ['rgb(' num2str(col(1)) ',' num2str(col(2)) ',' num2str(col(3)) ')' ] }; +end + +obj.data{patchIndex}.surfacecolor = cdata; +obj.data{patchIndex}.showscale = false; +obj.data{patchIndex}.cmin = min(CData(:)); +obj.data{patchIndex}.cmax = max(CData(:)); + +%-------------------------------------------------------------------------% + +%-setting grid mesh-% +if usegrid + % x-direction + xmin = min(XData(:)); + xmax = max(XData(:)); + xsize = (xmax - xmin) / (size(XData, 2) - 1); + obj.data{patchIndex}.contours.x.start = xmin; + obj.data{patchIndex}.contours.x.end = xmax; + obj.data{patchIndex}.contours.x.size = xsize; + obj.data{patchIndex}.contours.x.show = true; + obj.data{patchIndex}.contours.x.color = 'black'; + % y-direction + ymin = min(YData(:)); + ymax = max(YData(:)); + ysize = (ymax - ymin) / (size(YData, 2)-1); + obj.data{patchIndex}.contours.y.start = ymin; + obj.data{patchIndex}.contours.y.end = ymax; + obj.data{patchIndex}.contours.y.size = ysize; + obj.data{patchIndex}.contours.y.show = true; + obj.data{patchIndex}.contours.y.color = 'black'; +end + +%-------------------------------------------------------------------------% + +%-aspectratio-% +obj.layout.scene.aspectratio.x = 12; +obj.layout.scene.aspectratio.y = 10; +obj.layout.scene.aspectratio.z = 0.0001; + +%-------------------------------------------------------------------------% + +%-camera.eye-% +obj.layout.scene.camera.eye.x = 0; +obj.layout.scene.camera.eye.y = -0.5; +obj.layout.scene.camera.eye.z = 14; + +%-------------------------------------------------------------------------% + +%-hide axis-x-% +obj.layout.scene.xaxis.showticklabels = true; +obj.layout.scene.xaxis.zeroline = false; +obj.layout.scene.xaxis.showgrid = false; +obj.layout.scene.xaxis.title = ''; + +%-------------------------------------------------------------------------% + +%-hide axis-y-% +obj.layout.scene.yaxis.zeroline = false; +obj.layout.scene.yaxis.showgrid = false; +obj.layout.scene.yaxis.showticklabels = true; +obj.layout.scene.yaxis.title = ''; + +%-------------------------------------------------------------------------% + +%-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; + +%-------------------------------------------------------------------------% + +%-patch showlegend-% +leg = get(pcolor_data.Annotation); +legInfo = get(leg.LegendInformation); + +switch legInfo.IconDisplayStyle + case 'on' + showleg = true; + case 'off' + showleg = false; +end + +obj.data{patchIndex}.showlegend = showleg; + +%-------------------------------------------------------------------------% + +end diff --git a/plotly/plotlyfig_aux/handlegraphics/updatePolarplot.m b/plotly/plotlyfig_aux/handlegraphics/updatePolarplot.m new file mode 100644 index 00000000..4d3df342 --- /dev/null +++ b/plotly/plotlyfig_aux/handlegraphics/updatePolarplot.m @@ -0,0 +1,135 @@ +function updatePolarplot(obj,plotIndex) + +%-------------------------------------------------------------------------% + +%-Get plot class-% +plotclass = obj.State.Plot(plotIndex).Class; + +%-------------------------------------------------------------------------% + +%-run the correct plot class-% +if strcmpi(plotclass, 'line') + updatePolarline(obj,plotIndex) +elseif strcmpi(plotclass, 'polaraxes') + updatePolaraxes(obj,plotIndex) +end + +%-------------------------------------------------------------------------% + +end + + +%-------------------------------------------------------------------------% +%-HELPERS FUNCTIONS-% +%-------------------------------------------------------------------------% + +function updatePolaraxes(obj,plotIndex) + +%-------------------------------------------------------------------------% + +%-PLOT DATA STRUCTURE-% +plot_data = get(obj.State.Plot(plotIndex).Handle); + +%-------------------------------------------------------------------------% + +%-setting polar axes-% +gridcolor = 'rgb(235,235,235)'; +linecolor = 'rgb(210,210,210)'; + +%-R-axis-% +obj.layout.polar.angularaxis.tickmode = 'array'; +obj.layout.polar.angularaxis.tickvals = plot_data.ThetaTick(1:end-1); +obj.layout.polar.angularaxis.gridcolor = gridcolor; +obj.layout.polar.angularaxis.linecolor = linecolor; +obj.layout.polar.angularaxis.ticks = ''; + +%-Theta-axis-% +obj.layout.polar.radialaxis.angle = plot_data.RAxisLocation; +obj.layout.polar.radialaxis.tickmode = 'array'; +obj.layout.polar.radialaxis.tickvals = plot_data.RTick; +obj.layout.polar.radialaxis.gridcolor = gridcolor; +obj.layout.polar.radialaxis.showline = false; +obj.layout.polar.radialaxis.tickangle = 90; +obj.layout.polar.radialaxis.ticks = ''; + +%-------------------------------------------------------------------------% + +end + +function updatePolarline(obj,plotIndex) + +%-------------------------------------------------------------------------% + +%-PLOT DATA STRUCTURE- % +plot_data = get(obj.State.Plot(plotIndex).Handle); + +%-------------------------------------------------------------------------% + +%-scatterpolar type-% +obj.data{plotIndex}.type = 'scatterpolar'; + +%-------------------------------------------------------------------------% + +%-scatter visible-% +obj.data{plotIndex}.visible = strcmp(plot_data.Visible,'on'); + +%-------------------------------------------------------------------------% + +%-scatter r-data-% +obj.data{plotIndex}.r = abs(plot_data.RData); + +%-------------------------------------------------------------------------% + +%-scatter theta-data-% +obj.data{plotIndex}.theta = rad2deg(plot_data.ThetaData); + +%-------------------------------------------------------------------------% + +%-scatterpolar name-% +obj.data{plotIndex}.name = plot_data.DisplayName; + +%-------------------------------------------------------------------------% + +%-scatterpolar mode-% +if ~strcmpi('none', plot_data.Marker) ... + && ~strcmpi('none', plot_data.LineStyle) + mode = 'lines+markers'; +elseif ~strcmpi('none', plot_data.Marker) + mode = 'markers'; +elseif ~strcmpi('none', plot_data.LineStyle) + mode = 'lines'; +else + mode = 'none'; +end + +obj.data{plotIndex}.mode = mode; + +%-------------------------------------------------------------------------% + +%-scatter line-% +obj.data{plotIndex}.line = extractLineLine(plot_data); +obj.data{plotIndex}.line.width = 2 * obj.data{plotIndex}.line.width; + +%-------------------------------------------------------------------------% + +%-scatter marker-% +obj.data{plotIndex}.marker = extractLineMarker(plot_data); + +%-------------------------------------------------------------------------% + +%-scatter showlegend-% +leg = get(plot_data.Annotation); +legInfo = get(leg.LegendInformation); + +switch legInfo.IconDisplayStyle + case 'on' + showleg = true; + case 'off' + showleg = false; +end + +obj.data{plotIndex}.showlegend = showleg; + +%-------------------------------------------------------------------------% + +end \ No newline at end of file diff --git a/plotly/plotlyfig_aux/handlegraphics/updateStem.m b/plotly/plotlyfig_aux/handlegraphics/updateStem.m index a75fea4a..7b86279f 100644 --- a/plotly/plotlyfig_aux/handlegraphics/updateStem.m +++ b/plotly/plotlyfig_aux/handlegraphics/updateStem.m @@ -5,6 +5,7 @@ %-update line-% updateLineseries(obj,dataIndex); stem_temp_data = obj.data{dataIndex}; +isstem3d = obj.PlotOptions.is3d; %------------------------------------------------------------------------% @@ -17,6 +18,10 @@ xdata_extended = zeros(1,3*length(stem_temp_data.x)); ydata_extended = zeros(1,3*length(stem_temp_data.y)); +if isstem3d + zdata_extended = zeros(1,3*length(stem_temp_data.z)); +end + %-format x data-% m = 1; for n = 1:length(stem_temp_data.x) @@ -29,12 +34,28 @@ %-format y data-% m = 1; for n = 1:length(stem_temp_data.y) - ydata_extended(m) = 0; + ydata_extended(m) = 0; + + if isstem3d + ydata_extended(m) = stem_temp_data.y(n); + end + ydata_extended(m+1) = stem_temp_data.y(n); ydata_extended(m+2) = nan; m = m + 3; end +%-format z data-% +if isstem3d + m = 1; + for n = 1:length(stem_temp_data.z) + zdata_extended(m) = 0; + zdata_extended(m+1) = stem_temp_data.z(n); + zdata_extended(m+2) = nan; + m = m + 3; + end +end + %-hide every other marker-% color_temp = cell(1,3*length(stem_temp_data.y)); line_color_temp = cell(1,3*length(stem_temp_data.y)); @@ -57,6 +78,10 @@ stem_temp_data.x = xdata_extended; stem_temp_data.y = ydata_extended; +if isstem3d + stem_temp_data.z = zdata_extended; +end + %------------------------------------------------------------------------% obj.data{dataIndex} = stem_temp_data; diff --git a/plotly/plotlyfig_aux/helpers/parseString.m b/plotly/plotlyfig_aux/helpers/parseString.m index 3179b183..56875eb9 100644 --- a/plotly/plotlyfig_aux/helpers/parseString.m +++ b/plotly/plotlyfig_aux/helpers/parseString.m @@ -247,6 +247,8 @@ end end end +else + formatStr = 'untitled'; end