diff --git a/plotly/plotlyfig.m b/plotly/plotlyfig.m index 92e5e512..4da33848 100644 --- a/plotly/plotlyfig.m +++ b/plotly/plotlyfig.m @@ -570,7 +570,11 @@ function validate(obj) ax = findobj(obj.State.Figure.Handle,'Type','axes','-and',{'Tag','','-or','Tag','PlotMatrixBigAx','-or','Tag','PlotMatrixScatterAx', '-or','Tag','PlotMatrixHistAx'}); if isempty(ax) - ax = gca; + try + ax = get(obj.State.Figure.Handle,'Children'); + catch + ax = gca; + end end %---------- checking the overlaping of the graphs ----------% @@ -647,7 +651,9 @@ function validate(obj) nprev = length(plots) - np + 1; % update the plot fields - if ~strcmpi(getGraphClass(plots(nprev)), 'light') + plotClass = lower(getGraphClass(plots(nprev))); + + if ~ismember(plotClass, {'light', 'polaraxes'}) obj.State.Figure.NumPlots = obj.State.Figure.NumPlots + 1; obj.State.Plot(obj.State.Figure.NumPlots).Handle = handle(plots(nprev)); obj.State.Plot(obj.State.Figure.NumPlots).AssociatedAxis = handle(ax(axrev)); @@ -658,11 +664,16 @@ function validate(obj) end % this works for pareto - if length(plots) == 0 & obj.State.Figure.NumPlots ~= 0 - isPareto = length(ax) >= 2 & obj.State.Figure.NumPlots >= 2; - isBar = strcmpi(lower(obj.State.Plot(obj.State.Figure.NumPlots).Class), 'line'); - isLine = strcmpi(lower(obj.State.Plot(obj.State.Figure.NumPlots-1).Class), 'bar'); - isPareto = isPareto & isBar & isLine; + if length(plots) == 0 + + try + isPareto = length(ax) >= 2 & obj.State.Figure.NumPlots >= 2; + isBar = strcmpi(lower(obj.State.Plot(obj.State.Figure.NumPlots).Class), 'line'); + isLine = strcmpi(lower(obj.State.Plot(obj.State.Figure.NumPlots-1).Class), 'bar'); + isPareto = isPareto & isBar & isLine; + catch + isPareto = false; + end if isPareto obj.State.Plot(obj.State.Figure.NumPlots).AssociatedAxis = handle(ax(axrev)); @@ -784,6 +795,9 @@ function validate(obj) else if ~obj.PlotlyDefaults.isTernary updateAnnotation(obj,n); + if obj.State.Figure.NumAxes == 1 + obj.PlotOptions.CleanFeedTitle = false; + end end end catch diff --git a/plotly/plotlyfig_aux/core/updateData.m b/plotly/plotlyfig_aux/core/updateData.m index 82e641f8..9c46872f 100644 --- a/plotly/plotlyfig_aux/core/updateData.m +++ b/plotly/plotlyfig_aux/core/updateData.m @@ -10,8 +10,6 @@ updatePie3(obj, dataIndex); elseif ismember('pcolor', lower(obj.PlotOptions.TreatAs)) updatePColor(obj, dataIndex); - elseif ismember('polarplot', lower(obj.PlotOptions.TreatAs)) - updatePolarplot(obj, dataIndex); elseif ismember('contour3', lower(obj.PlotOptions.TreatAs)) updateContour3(obj, dataIndex); elseif ismember('compass', lower(obj.PlotOptions.TreatAs)) @@ -50,6 +48,10 @@ case 'geoaxes' UpdateGeoAxes(obj, dataIndex); + %-EMULATE AXES-% + case 'nothing' + updateOnlyAxes(obj, dataIndex); + %--CORE PLOT OBJECTS--% case 'geobubble' updateGeobubble(obj, dataIndex); @@ -68,6 +70,8 @@ case 'line' if obj.PlotlyDefaults.isGeoaxis updateGeoPlot(obj, dataIndex); + elseif ismember('polarplot', lower(obj.PlotOptions.TreatAs)) + updatePolarplot(obj, dataIndex); elseif ismember('ternplot', lower(obj.PlotOptions.TreatAs)) updateTernaryPlot(obj, dataIndex); else @@ -137,7 +141,7 @@ case 'quivergroup' updateQuivergroup(obj, dataIndex); case 'scatter' - if ismember('polaraxes', lower(obj.PlotOptions.TreatAs)) + if ismember('scatterpolar', lower(obj.PlotOptions.TreatAs)) updateScatterPolar(obj, dataIndex); elseif obj.PlotlyDefaults.isGeoaxis updateGeoScatter(obj, dataIndex); diff --git a/plotly/plotlyfig_aux/handlegraphics/updateLineseries.m b/plotly/plotlyfig_aux/handlegraphics/updateLineseries.m index 8146d264..b6892769 100644 --- a/plotly/plotlyfig_aux/handlegraphics/updateLineseries.m +++ b/plotly/plotlyfig_aux/handlegraphics/updateLineseries.m @@ -1,205 +1,209 @@ -function updateLineseries(obj,plotIndex) - -%----SCATTER FIELDS----% - -% x - [DONE] -% y - [DONE] -% r - [HANDLED BY SCATTER] -% t - [HANDLED BY SCATTER] -% mode - [DONE] -% name - [NOT SUPPORTED IN MATLAB] -% text - [DONE] -% error_y - [HANDLED BY ERRORBAR] -% error_x - [NOT SUPPORTED IN MATLAB] -% connectgaps - [NOT SUPPORTED IN MATLAB] -% fill - [HANDLED BY AREA] -% fillcolor - [HANDLED BY AREA] -% opacity --- [TODO] -% textfont - [NOT SUPPORTED IN MATLAB] -% textposition - [NOT SUPPORTED IN MATLAB] -% xaxis [DONE] -% yaxis [DONE] -% showlegend [DONE] -% stream - [HANDLED BY PLOTLYSTREAM] -% visible [DONE] -% type [DONE] - -% MARKER -% marler.color - [DONE] -% marker.size - [DONE] -% marker.line.color - [DONE] -% marker.line.width - [DONE] -% marker.line.dash - [NOT SUPPORTED IN MATLAB] -% marker.line.opacity - [NOT SUPPORTED IN MATLAB] -% marker.line.smoothing - [NOT SUPPORTED IN MATLAB] -% marker.line.shape - [NOT SUPPORTED IN MATLAB] -% marker.opacity --- [TODO] -% marker.colorscale - [NOT SUPPORTED IN MATLAB] -% marker.sizemode - [NOT SUPPORTED IN MATLAB] -% marker.sizeref - [NOT SUPPORTED IN MATLAB] -% marker.maxdisplayed - [NOT SUPPORTED IN MATLAB] - -% LINE - -% line.color - [DONE] -% line.width - [DONE] -% line.dash - [DONE] -% line.opacity --- [TODO] -% line.smoothing - [NOT SUPPORTED IN MATLAB] -% line.shape - [NOT SUPPORTED IN MATLAB] - -%-------------------------------------------------------------------------% - -%-AXIS INDEX-% -axIndex = obj.getAxisIndex(obj.State.Plot(plotIndex).AssociatedAxis); - -%-PLOT DATA STRUCTURE- % -plotData = get(obj.State.Plot(plotIndex).Handle); - -%-CHECK FOR MULTIPLE AXES-% -try - for yax = 1:2 - yaxIndex(yax) = sum(plotData.Parent.YAxis(yax).Color == plotData.Color); +function updateLineseries(obj, plotIndex) + + %----SCATTER FIELDS----% + + % x - [DONE] + % y - [DONE] + % r - [HANDLED BY SCATTER] + % t - [HANDLED BY SCATTER] + % mode - [DONE] + % name - [NOT SUPPORTED IN MATLAB] + % text - [DONE] + % error_y - [HANDLED BY ERRORBAR] + % error_x - [NOT SUPPORTED IN MATLAB] + % connectgaps - [NOT SUPPORTED IN MATLAB] + % fill - [HANDLED BY AREA] + % fillcolor - [HANDLED BY AREA] + % opacity --- [TODO] + % textfont - [NOT SUPPORTED IN MATLAB] + % textposition - [NOT SUPPORTED IN MATLAB] + % xaxis [DONE] + % yaxis [DONE] + % showlegend [DONE] + % stream - [HANDLED BY PLOTLYSTREAM] + % visible [DONE] + % type [DONE] + + % MARKER + % marler.color - [DONE] + % marker.size - [DONE] + % marker.line.color - [DONE] + % marker.line.width - [DONE] + % marker.line.dash - [NOT SUPPORTED IN MATLAB] + % marker.line.opacity - [NOT SUPPORTED IN MATLAB] + % marker.line.smoothing - [NOT SUPPORTED IN MATLAB] + % marker.line.shape - [NOT SUPPORTED IN MATLAB] + % marker.opacity --- [TODO] + % marker.colorscale - [NOT SUPPORTED IN MATLAB] + % marker.sizemode - [NOT SUPPORTED IN MATLAB] + % marker.sizeref - [NOT SUPPORTED IN MATLAB] + % marker.maxdisplayed - [NOT SUPPORTED IN MATLAB] + + % LINE + + % line.color - [DONE] + % line.width - [DONE] + % line.dash - [DONE] + % line.opacity --- [TODO] + % line.smoothing - [NOT SUPPORTED IN MATLAB] + % line.shape - [NOT SUPPORTED IN MATLAB] + + %-------------------------------------------------------------------------% + + %-AXIS INDEX-% + axIndex = obj.getAxisIndex(obj.State.Plot(plotIndex).AssociatedAxis); + + %-PLOT DATA STRUCTURE- % + plotData = get(obj.State.Plot(plotIndex).Handle); + + %-CHECK FOR MULTIPLE AXES-% + try + for yax = 1:2 + yaxIndex(yax) = sum(plotData.Parent.YAxis(yax).Color == plotData.Color); + end + + [~, yaxIndex] = max(yaxIndex); + [xsource, ysource] = findSourceAxis(obj, axIndex, yaxIndex); + + catch + [xsource, ysource] = findSourceAxis(obj,axIndex); end - [~, yaxIndex] = max(yaxIndex); - [xsource, ysource] = findSourceAxis(obj, axIndex, yaxIndex); + %-AXIS DATA-% + eval(['xaxis = obj.layout.xaxis' num2str(xsource) ';']); + eval(['yaxis = obj.layout.yaxis' num2str(ysource) ';']); -catch - [xsource, ysource] = findSourceAxis(obj,axIndex); -end + %-------------------------------------------------------------------------% -%-AXIS DATA-% -eval(['xaxis = obj.layout.xaxis' num2str(xsource) ';']); -eval(['yaxis = obj.layout.yaxis' num2str(ysource) ';']); + %-if polar plot or not-% + treatAs = obj.PlotOptions.TreatAs; + isPolar = ismember('compass', lower(treatAs)) || ismember('ezpolar', lower(treatAs)); -%-------------------------------------------------------------------------% + %-------------------------------------------------------------------------% -%-if polar plot or not-% -treatAs = obj.PlotOptions.TreatAs; -ispolar = ismember('compass', lower(treatAs)) || ismember('ezpolar', lower(treatAs)); + %-getting data-% + xData = plotData.XData; + yData = plotData.YData; -%-------------------------------------------------------------------------% + if isduration(xData), xData = datenum(xData); end + if isduration(yData), yData = datenum(yData); end -%-getting data-% -xData = plotData.XData; -yData = plotData.YData; + %-------------------------------------------------------------------------% -if isduration(xData), xData = datenum(xData); end -if isduration(yData), yData = datenum(yData); end + %-scatter xaxis-% + obj.data{plotIndex}.xaxis = ['x' num2str(xsource)]; -%-------------------------------------------------------------------------% + %-------------------------------------------------------------------------% -%-scatter xaxis-% -obj.data{plotIndex}.xaxis = ['x' num2str(xsource)]; + %-scatter yaxis-% + obj.data{plotIndex}.yaxis = ['y' num2str(ysource)]; -%-------------------------------------------------------------------------% + %-------------------------------------------------------------------------% -%-scatter yaxis-% -obj.data{plotIndex}.yaxis = ['y' num2str(ysource)]; + %-scatter type-% + obj.data{plotIndex}.type = 'scatter'; -%-------------------------------------------------------------------------% - -%-scatter type-% -obj.data{plotIndex}.type = 'scatter'; - -if ispolar - obj.data{plotIndex}.type = 'scatterpolar'; -end + if isPolar + obj.data{plotIndex}.type = 'scatterpolar'; + end -%-------------------------------------------------------------------------% + %-------------------------------------------------------------------------% -%-scatter visible-% -obj.data{plotIndex}.visible = strcmp(plotData.Visible,'on'); + %-scatter visible-% + obj.data{plotIndex}.visible = strcmp(plotData.Visible,'on'); -%-------------------------------------------------------------------------% + %-------------------------------------------------------------------------% -%-scatter x-% + %-scatter x-% -if ispolar - rData = sqrt(x.^2 + y.^2); - obj.data{plotIndex}.r = rData; -else - obj.data{plotIndex}.x = xData; -end + if isPolar + rData = sqrt(x.^2 + y.^2); + obj.data{plotIndex}.r = rData; + else + obj.data{plotIndex}.x = xData; + end -%-------------------------------------------------------------------------% + %-------------------------------------------------------------------------% -%-scatter y-% -if ispolar - thetaData = atan2(xData,yData); - obj.data{plotIndex}.theta = -(rad2deg(thetaData) - 90); -else - obj.data{plotIndex}.y = yData; -end + %-scatter y-% + if isPolar + thetaData = atan2(xData,yData); + obj.data{plotIndex}.theta = -(rad2deg(thetaData) - 90); + else + obj.data{plotIndex}.y = yData; + end -%-------------------------------------------------------------------------% + %-------------------------------------------------------------------------% -%-Fro 3D plots-% -obj.PlotOptions.is3d = false; % by default + %-Fro 3D plots-% + obj.PlotOptions.is3d = false; % by default -if isfield(plotData,'ZData') - - numbset = unique(plotData.ZData); - - if any(plotData.ZData) && length(numbset)>1 - %-scatter z-% - obj.data{plotIndex}.z = plotData.ZData; + if isfield(plotData,'ZData') - %-overwrite type-% - obj.data{plotIndex}.type = 'scatter3d'; + numbset = unique(plotData.ZData); - %-flag to manage 3d plots-% - obj.PlotOptions.is3d = true; + if any(plotData.ZData) && length(numbset)>1 + %-scatter z-% + obj.data{plotIndex}.z = plotData.ZData; + + %-overwrite type-% + obj.data{plotIndex}.type = 'scatter3d'; + + %-flag to manage 3d plots-% + obj.PlotOptions.is3d = true; + end end -end -%-------------------------------------------------------------------------% + %-------------------------------------------------------------------------% -%-scatter name-% -obj.data{plotIndex}.name = plotData.DisplayName; + %-scatter name-% + obj.data{plotIndex}.name = plotData.DisplayName; -%-------------------------------------------------------------------------% + %-------------------------------------------------------------------------% -%-scatter mode-% -if ~strcmpi('none', plotData.Marker) ... - && ~strcmpi('none', plotData.LineStyle) - mode = 'lines+markers'; -elseif ~strcmpi('none', plotData.Marker) - mode = 'markers'; -elseif ~strcmpi('none', plotData.LineStyle) - mode = 'lines'; -else - mode = 'none'; -end + %-scatter mode-% + if ~strcmpi('none', plotData.Marker) ... + && ~strcmpi('none', plotData.LineStyle) + mode = 'lines+markers'; + elseif ~strcmpi('none', plotData.Marker) + mode = 'markers'; + elseif ~strcmpi('none', plotData.LineStyle) + mode = 'lines'; + else + mode = 'none'; + end + + obj.data{plotIndex}.mode = mode; -obj.data{plotIndex}.mode = mode; + %-------------------------------------------------------------------------% -%-------------------------------------------------------------------------% + %-scatter line-% + obj.data{plotIndex}.line = extractLineLine(plotData); -%-scatter line-% -obj.data{plotIndex}.line = extractLineLine(plotData); + %-------------------------------------------------------------------------% -%-------------------------------------------------------------------------% + %-scatter marker-% + obj.data{plotIndex}.marker = extractLineMarker(plotData); -%-scatter marker-% -obj.data{plotIndex}.marker = extractLineMarker(plotData); + %-------------------------------------------------------------------------% -%-------------------------------------------------------------------------% + %-scatter showlegend-% + leg = get(plotData.Annotation); + legInfo = get(leg.LegendInformation); -%-scatter showlegend-% -leg = get(plotData.Annotation); -legInfo = get(leg.LegendInformation); + switch legInfo.IconDisplayStyle + case 'on' + showLeg = true; + case 'off' + showLeg = false; + end -switch legInfo.IconDisplayStyle - case 'on' - showLeg = true; - case 'off' - showLeg = false; -end + obj.data{plotIndex}.showlegend = showLeg; -obj.data{plotIndex}.showlegend = showLeg; + if isempty(obj.data{plotIndex}.name) + obj.data{plotIndex}.showlegend = false; + end -%-------------------------------------------------------------------------% + %-------------------------------------------------------------------------% end \ No newline at end of file diff --git a/plotly/plotlyfig_aux/handlegraphics/updateMesh.m b/plotly/plotlyfig_aux/handlegraphics/updateMesh.m index 9b1c8cf2..2440e169 100644 --- a/plotly/plotlyfig_aux/handlegraphics/updateMesh.m +++ b/plotly/plotlyfig_aux/handlegraphics/updateMesh.m @@ -8,7 +8,6 @@ %-SURFACE DATA STRUCTURE- % meshData = get(obj.State.Plot(surfaceIndex).Handle); -figureData = get(obj.State.Figure.Handle); %-AXIS STRUCTURE-% axisData = get(ancestor(meshData.Parent,'axes')); @@ -104,7 +103,7 @@ %-------------------------------------------------------------------------% %-get colormap-% -cMap = figureData.Colormap; +cMap = axisData.Colormap; fac = 1/(length(cMap)-1); colorScale = {}; diff --git a/plotly/plotlyfig_aux/handlegraphics/updateOnlyAxes.m b/plotly/plotlyfig_aux/handlegraphics/updateOnlyAxes.m new file mode 100644 index 00000000..e22a1737 --- /dev/null +++ b/plotly/plotlyfig_aux/handlegraphics/updateOnlyAxes.m @@ -0,0 +1,28 @@ +function updateOnlyAxes(obj, plotIndex) + + %-------------------------------------------------------------------------% + + %-AXIS INDEX-% + axIndex = obj.getAxisIndex(obj.State.Plot(plotIndex).AssociatedAxis); + + %-CHECK FOR MULTIPLE AXES-% + [xsource, ysource] = findSourceAxis(obj, axIndex); + + %-ASSOCIATE AXIS LAYOUT-% + obj.data{plotIndex}.xaxis = sprintf('x%d', xsource); + obj.data{plotIndex}.yaxis = sprintf('y%d', ysource); + + %-------------------------------------------------------------------------% + + %-set scatter trace-% + obj.data{plotIndex}.type = 'scatter'; + obj.data{plotIndex}.mode = 'none'; + + %-------------------------------------------------------------------------% + + %-set empty data-% + obj.data{plotIndex}.x = []; + obj.data{plotIndex}.y = []; + + %-------------------------------------------------------------------------% +end \ No newline at end of file diff --git a/plotly/plotlyfig_aux/handlegraphics/updatePolarplot.m b/plotly/plotlyfig_aux/handlegraphics/updatePolarplot.m index 4d3df342..cbce5fd7 100644 --- a/plotly/plotlyfig_aux/handlegraphics/updatePolarplot.m +++ b/plotly/plotlyfig_aux/handlegraphics/updatePolarplot.m @@ -1,135 +1,265 @@ -function updatePolarplot(obj,plotIndex) - -%-------------------------------------------------------------------------% - -%-Get plot class-% -plotclass = obj.State.Plot(plotIndex).Class; +function updatePolarplot(obj, plotIndex) -%-------------------------------------------------------------------------% + %-AXIS INDEX-% + axIndex = obj.getAxisIndex(obj.State.Plot(plotIndex).AssociatedAxis); -%-run the correct plot class-% -if strcmpi(plotclass, 'line') - updatePolarline(obj,plotIndex) -elseif strcmpi(plotclass, 'polaraxes') - updatePolaraxes(obj,plotIndex) -end + %-PLOT DATA STRUCTURE- % + plotData = get(obj.State.Plot(plotIndex).Handle); -%-------------------------------------------------------------------------% + %-CHECK FOR MULTIPLE AXES-% + [xsource, ysource] = findSourceAxis(obj, axIndex); -end + %-ASSOCIATE POLAR-AXES LAYOUT-% + obj.data{plotIndex}.subplot = sprintf('polar%d', xsource+1); + %-------------------------------------------------------------------------% -%-------------------------------------------------------------------------% -%-HELPERS FUNCTIONS-% -%-------------------------------------------------------------------------% + %-parse plot data-% + rData = plotData.RData; + thetaData = rad2deg(plotData.ThetaData); -function updatePolaraxes(obj,plotIndex) + thetaData(rData<0) = mod(thetaData(rData<0)+180, 360); + rData = abs(rData); -%-------------------------------------------------------------------------% - -%-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 = ''; + %-------------------------------------------------------------------------% -%-------------------------------------------------------------------------% + %-scatterpolar trace setting-% + obj.data{plotIndex}.type = 'scatterpolar'; + obj.data{plotIndex}.visible = strcmp(plotData.Visible,'on'); + obj.data{plotIndex}.name = plotData.DisplayName; -end + %-------------------------------------------------------------------------% -function updatePolarline(obj,plotIndex) + %-set scatterpolar data-% + obj.data{plotIndex}.r = rData; + obj.data{plotIndex}.theta = thetaData; -%-------------------------------------------------------------------------% + %-------------------------------------------------------------------------% -%-PLOT DATA STRUCTURE- % -plot_data = get(obj.State.Plot(plotIndex).Handle); + %-trace settings-% + if ~strcmpi('none', plotData.Marker) && ~strcmpi('none', plotData.LineStyle) + obj.data{plotIndex}.mode = 'lines+markers'; + elseif ~strcmpi('none', plotData.Marker) + obj.data{plotIndex}.mode = 'markers'; + elseif ~strcmpi('none', plotData.LineStyle) + obj.data{plotIndex}.mode = 'lines'; + else + obj.data{plotIndex}.mode = 'none'; + end -%-------------------------------------------------------------------------% + obj.data{plotIndex}.marker = extractLineMarker(plotData); + obj.data{plotIndex}.line = extractLineLine(plotData); + obj.data{plotIndex}.line.width = 2 * obj.data{plotIndex}.line.width; -%-scatterpolar type-% -obj.data{plotIndex}.type = 'scatterpolar'; + %-------------------------------------------------------------------------% -%-------------------------------------------------------------------------% + %-legend setting-% + leg = get(plotData.Annotation); + legInfo = get(leg.LegendInformation); -%-scatter visible-% -obj.data{plotIndex}.visible = strcmp(plot_data.Visible,'on'); + switch legInfo.IconDisplayStyle + case 'on' + obj.data{plotIndex}.showlegend = true; + case 'off' + obj.data{plotIndex}.showlegend = false; + end -%-------------------------------------------------------------------------% + %-------------------------------------------------------------------------% -%-scatter r-data-% -obj.data{plotIndex}.r = abs(plot_data.RData); + %-set polar axes-% + updatePolaraxes(obj, plotIndex) -%-------------------------------------------------------------------------% + %-------------------------------------------------------------------------% +end -%-scatter theta-data-% -obj.data{plotIndex}.theta = rad2deg(plot_data.ThetaData); %-------------------------------------------------------------------------% - -%-scatterpolar name-% -obj.data{plotIndex}.name = plot_data.DisplayName; - +% +%-SET POLAR AXIS-% +% %-------------------------------------------------------------------------% -%-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 +function updatePolaraxes(obj, plotIndex) -obj.data{plotIndex}.mode = mode; + %-------------------------------------------------------------------------% -%-------------------------------------------------------------------------% + %-AXIS INDEX-% + axIndex = obj.getAxisIndex(obj.State.Plot(plotIndex).AssociatedAxis); -%-scatter line-% -obj.data{plotIndex}.line = extractLineLine(plot_data); -obj.data{plotIndex}.line.width = 2 * obj.data{plotIndex}.line.width; + %-CHECK FOR MULTIPLE AXES-% + [xsource, ysource] = findSourceAxis(obj, axIndex); + + %-GET DATA STRUCTURES-% + plotData = get(obj.State.Plot(plotIndex).Handle); + axisData = get(plotData.Parent); + thetaAxis = get(axisData.ThetaAxis); + rAxis = get(axisData.RAxis); -%-------------------------------------------------------------------------% - -%-scatter marker-% -obj.data{plotIndex}.marker = extractLineMarker(plot_data); + %-------------------------------------------------------------------------% -%-------------------------------------------------------------------------% + %-set domain plot-% + xo = axisData.Position(1); + yo = axisData.Position(2); + w = axisData.Position(3); + h = axisData.Position(4); -%-scatter showlegend-% -leg = get(plot_data.Annotation); -legInfo = get(leg.LegendInformation); + polarAxis.domain.x = min([xo xo + w], 1); + polarAxis.domain.y = min([yo yo + h], 1); -switch legInfo.IconDisplayStyle - case 'on' - showleg = true; - case 'off' - showleg = false; + %-------------------------------------------------------------------------% + + %-setting angular axis-% + gridColor = sprintf('rgba(%f,%f,%f,%f)', 255*axisData.GridColor, ... + axisData.GridAlpha); + gridWidth = axisData.LineWidth; + thetaLim = thetaAxis.Limits; + + polarAxis.angularaxis.linecolor = gridColor; + polarAxis.angularaxis.ticklen = mean(thetaAxis.TickLength); + + if isnumeric(thetaLim) + polarAxis.angularaxis.range = thetaLim; + else + polarAxis.angularaxis.autorange = true; + end + + if strcmp(axisData.ThetaGrid, 'on') + polarAxis.angularaxis.gridwidth = gridWidth; + polarAxis.angularaxis.gridcolor = gridColor; + end + + %-------------------------------------------------------------------------% + + %-set angular axis label-% + thetaLabel = thetaAxis.Label; + + polarAxis.angularaxis.title.text = thetaLabel.String; + polarAxis.radialaxis.title.font.family = matlab2plotlyfont(... + thetaLabel.FontName); + polarAxis.radialaxis.title.font.size = thetaLabel.FontSize; + polarAxis.radialaxis.title.font.color = sprintf('rgb(%f,%f,%f)', ... + 255*thetaLabel.Color); + + %-------------------------------------------------------------------------% + + %-setting radial axis-% + rLim = rAxis.Limits; + + polarAxis.radialaxis.showline = false; + polarAxis.radialaxis.angle = axisData.RAxisLocation+6; + polarAxis.radialaxis.tickangle = 90-rAxis.TickLabelRotation; + polarAxis.radialaxis.ticklen = mean(rAxis.TickLength); + + if isnumeric(rLim) + polarAxis.radialaxis.range = rLim; + else + polarAxis.radialaxis.autorange = true; + end + + if strcmp(axisData.RGrid, 'on') + polarAxis.radialaxis.gridwidth = gridWidth; + polarAxis.radialaxis.gridcolor = gridColor; + end + + %-------------------------------------------------------------------------% + + %-set radial axis label-% + rLabel = thetaAxis.Label; + + polarAxis.angularaxis.title.text = 'label';%rLabel.String; + polarAxis.angularaxis.title.font.family = matlab2plotlyfont(... + rLabel.FontName); + polarAxis.angularaxis.title.font.size = rLabel.FontSize; + polarAxis.angularaxis.title.font.color = sprintf('rgb(%f,%f,%f)', ... + 255*rLabel.Color); + + %-------------------------------------------------------------------------% + + %-angular tick labels settings-% + tickValues = axisData.ThetaTick; + tickLabels = axisData.ThetaTickLabel; + showTickLabels = true; + + try + if tickValues(1) == 0 && tickValues(end) == 360 + tickValues = tickValues(1:end-1); + end + catch + tickValues = tickValues; + end + + if isempty(tickValues) + showTickLabels = false; + polarAxis.angularaxis.showticklabels = showTickLabels; + polarAxis.angularaxis.ticks = ''; + + elseif isempty(tickLabels) + polarAxis.angularaxis.tickvals = tickValues; + + else + polarAxis.angularaxis.tickvals = tickValues; + polarAxis.angularaxis.ticktext = tickLabels; + + end + + if showTickLabels + switch thetaAxis.TickDirection + case 'in' + polarAxis.angularaxis.ticks = 'inside'; + case 'out' + polarAxis.angularaxis.ticks = 'outside'; + end + + %-tick font-% + polarAxis.angularaxis.tickfont.family = matlab2plotlyfont(... + thetaAxis.FontName); + polarAxis.angularaxis.tickfont.size = thetaAxis.FontSize; + polarAxis.angularaxis.tickfont.color = sprintf('rgb(%f,%f,%f)', ... + 255*thetaAxis.Color); + end + + + %-------------------------------------------------------------------------% + + %-radial tick labels settings-% + tickValues = axisData.RTick; + tickLabels = axisData.RTickLabel; + showTickLabels = true; + + if isempty(tickValues) + showTickLabels = false; + polarAxis.radialaxis.showticklabels = showTickLabels; + polarAxis.radialaxis.ticks = ''; + + elseif isempty(tickLabels) + polarAxis.radialaxis.tickvals = tickValues; + + else + polarAxis.radialaxis.tickvals = tickValues; + polarAxis.radialaxis.ticktext = tickLabels; + end + + if showTickLabels + switch rAxis.TickDirection + case 'in' + polarAxis.radialaxis.ticks = 'inside'; + case 'out' + polarAxis.radialaxis.ticks = 'outside'; + end + + %-tick font-% + polarAxis.radialaxis.tickfont.family = matlab2plotlyfont(... + rAxis.FontName); + polarAxis.radialaxis.tickfont.size = rAxis.FontSize; + polarAxis.radialaxis.tickfont.color = sprintf('rgb(%f,%f,%f)', ... + 255*rAxis.Color); + end + + + %-------------------------------------------------------------------------% + + %-set polaraxes to layout-% + obj.layout = setfield(obj.layout, sprintf('polar%d', xsource+1), polarAxis); + + %-------------------------------------------------------------------------% end - -obj.data{plotIndex}.showlegend = showleg; - -%-------------------------------------------------------------------------% - -end \ No newline at end of file diff --git a/plotly/plotlyfig_aux/handlegraphics/updateScatterPolar.m b/plotly/plotlyfig_aux/handlegraphics/updateScatterPolar.m index bf71564f..67498feb 100644 --- a/plotly/plotlyfig_aux/handlegraphics/updateScatterPolar.m +++ b/plotly/plotlyfig_aux/handlegraphics/updateScatterPolar.m @@ -1,196 +1,265 @@ -function updateScatterPolar(obj,scatterIndex) - -%check: http://undocumentedmatlab.com/blog/undocumented-scatter-plot-behavior - -%----SCATTER FIELDS----% - -% x - [DONE] -% y - [DONE] -% r - [HANDLED BY SCATTER] -% t - [HANDLED BY SCATTER] -% mode - [DONE] -% name - [DONE] -% text - [NOT SUPPORTED IN MATLAB] -% error_y - [HANDLED BY ERRORBAR] -% error_x - [NOT SUPPORTED IN MATLAB] -% textfont - [NOT SUPPORTED IN MATLAB] -% textposition - [NOT SUPPORTED IN MATLAB] -% xaxis [DONE] -% yaxis [DONE] -% showlegend [DONE] -% stream - [HANDLED BY PLOTLYSTREAM] -% visible [DONE] -% type [DONE] -% opacity ---[TODO] - -% MARKER -% marler.color - [DONE] -% marker.size - [DONE] -% marker.opacity - [NOT SUPPORTED IN MATLAB] -% marker.colorscale - [NOT SUPPORTED IN MATLAB] -% marker.sizemode - [DONE] -% marker.sizeref - [DONE] -% marker.maxdisplayed - [NOT SUPPORTED IN MATLAB] - -% MARKER LINE -% marker.line.color - [DONE] -% marker.line.width - [DONE] -% marker.line.dash - [NOT SUPPORTED IN MATLAB] -% marker.line.opacity - [DONE] -% marker.line.smoothing - [NOT SUPPORTED IN MATLAB] -% marker.line.shape - [NOT SUPPORTED IN MATLAB] - -% LINE -% line.color - [NA] -% line.width - [NA] -% line.dash - [NA] -% line.opacity [NA] -% line.smoothing - [NOT SUPPORTED IN MATLAB] -% line.shape - [NOT SUPPORTED IN MATLAB] -% connectgaps - [NOT SUPPORTED IN MATLAB] -% fill - [HANDLED BY AREA] -% fillcolor - [HANDLED BY AREA] - -%-AXIS INDEX-% -axIndex = obj.getAxisIndex(obj.State.Plot(scatterIndex).AssociatedAxis); - -%-SCATTER DATA STRUCTURE- % -scatter_data = get(obj.State.Plot(scatterIndex).Handle); +function updateScatterPolar(obj, plotIndex) -%-------------------------------------------------------------------------% + %-AXIS INDEX-% + axIndex = obj.getAxisIndex(obj.State.Plot(plotIndex).AssociatedAxis); -%-scatterpolar type-% -obj.data{scatterIndex}.type = 'scatterpolar'; + %-PLOT DATA STRUCTURE- % + plotData = get(obj.State.Plot(plotIndex).Handle); -%-------------------------------------------------------------------------% + %-CHECK FOR MULTIPLE AXES-% + [xsource, ysource] = findSourceAxis(obj, axIndex); -%-scatter mode-% -obj.data{scatterIndex}.mode = 'markers'; + %-ASSOCIATE POLAR-AXES LAYOUT-% + obj.data{plotIndex}.subplot = sprintf('polar%d', xsource+1); -%-------------------------------------------------------------------------% + %-------------------------------------------------------------------------% -%-scatter visible-% -obj.data{scatterIndex}.visible = strcmp(scatter_data.Visible,'on'); + %-parse plot data-% + rData = plotData.RData; + thetaData = rad2deg(plotData.ThetaData); -%-------------------------------------------------------------------------% + thetaData(rData<0) = mod(thetaData(rData<0)+180, 360); + rData = abs(rData); -%-scatter name-% -obj.data{scatterIndex}.name = scatter_data.DisplayName; + %-------------------------------------------------------------------------% -%-------------------------------------------------------------------------% + %-scatterpolar trace setting-% + obj.data{plotIndex}.type = 'scatterpolar'; + obj.data{plotIndex}.mode = 'markers'; + obj.data{plotIndex}.visible = strcmp(plotData.Visible,'on'); + obj.data{plotIndex}.name = plotData.DisplayName; -%-scatter patch data-% -for m = 1:length(scatter_data) + %-------------------------------------------------------------------------% - %reverse counter - n = length(scatter_data) - m + 1; - - %---------------------------------------------------------------------% - - %-scatter r-% - if length(scatter_data) > 1 - obj.data{scatterIndex}.r(m) = scatter_data(n).RData; - else - obj.data{scatterIndex}.r = scatter_data.RData; + %-set scatterpolar data-% + obj.data{plotIndex}.r = rData; + obj.data{plotIndex}.theta = thetaData; + + %-------------------------------------------------------------------------% + + %-trace settings-% + markerStruct = extractScatterMarker(plotData); + + obj.data{plotIndex}.marker = markerStruct; + + if length(markerStruct.size) == 1 + obj.data{plotIndex}.marker.size = markerStruct.size * 0.2; end - - %---------------------------------------------------------------------% - - %-scatter theta-% - if length(scatter_data) > 1 - obj.data{scatterIndex}.theta(m) = rad2deg(scatter_data(n).ThetaData); - else - obj.data{scatterIndex}.theta = rad2deg(scatter_data.ThetaData); + + if length(markerStruct.line.color) > 1 + obj.data{plotIndex}.marker.line.color = markerStruct.line.color{1}; end - - - %---------------------------------------------------------------------% - - %-scatter showlegend-% - leg = get(scatter_data.Annotation); + + %-------------------------------------------------------------------------% + + %-legend setting-% + leg = get(plotData.Annotation); legInfo = get(leg.LegendInformation); - + switch legInfo.IconDisplayStyle case 'on' - showleg = true; + obj.data{plotIndex}.showlegend = true; case 'off' - showleg = false; + obj.data{plotIndex}.showlegend = false; end + + %-------------------------------------------------------------------------% + + %-set polar axes-% + updatePolaraxes(obj, plotIndex); + + %-------------------------------------------------------------------------% +end + +%-------------------------------------------------------------------------% +% +%-SET POLAR AXIS-% +% +%-------------------------------------------------------------------------% + +function updatePolaraxes(obj, plotIndex) + + %-------------------------------------------------------------------------% + + %-AXIS INDEX-% + axIndex = obj.getAxisIndex(obj.State.Plot(plotIndex).AssociatedAxis); + + %-CHECK FOR MULTIPLE AXES-% + [xsource, ysource] = findSourceAxis(obj, axIndex); + + %-GET DATA STRUCTURES-% + plotData = get(obj.State.Plot(plotIndex).Handle); + axisData = get(plotData.Parent); + thetaAxis = get(axisData.ThetaAxis); + rAxis = get(axisData.RAxis); + + %-------------------------------------------------------------------------% + + %-set domain plot-% + xo = axisData.Position(1); + yo = axisData.Position(2); + w = axisData.Position(3); + h = axisData.Position(4); + + polarAxis.domain.x = min([xo xo + w], 1); + polarAxis.domain.y = min([yo yo + h], 1); + + %-------------------------------------------------------------------------% + + %-setting angular axis-% + gridColor = sprintf('rgba(%f,%f,%f,%f)', 255*axisData.GridColor, ... + axisData.GridAlpha); + gridWidth = axisData.LineWidth; + thetaLim = thetaAxis.Limits; - if isfield(scatter_data,'ZData') - if isempty(scatter_data.ZData) - obj.data{scatterIndex}.showlegend = showleg; - end + polarAxis.angularaxis.linecolor = gridColor; + polarAxis.angularaxis.ticklen = mean(thetaAxis.TickLength); + + if isnumeric(thetaLim) + polarAxis.angularaxis.range = thetaLim; + else + polarAxis.angularaxis.autorange = true; end - - %---------------------------------------------------------------------% - - %-scatter marker-% - childmarker = extractScatterMarker(scatter_data(n)); - - %---------------------------------------------------------------------% - - %-line color-% - if length(scatter_data) > 1 - obj.data{scatterIndex}.marker.line.color{m} = childmarker.line.color{1}; + + if strcmp(axisData.ThetaGrid, 'on') + polarAxis.angularaxis.gridwidth = gridWidth; + polarAxis.angularaxis.gridcolor = gridColor; + end + + %-------------------------------------------------------------------------% + + %-set angular axis label-% + thetaLabel = thetaAxis.Label; + + polarAxis.angularaxis.title.text = thetaLabel.String; + polarAxis.radialaxis.title.font.family = matlab2plotlyfont(... + thetaLabel.FontName); + polarAxis.radialaxis.title.font.size = thetaLabel.FontSize; + polarAxis.radialaxis.title.font.color = sprintf('rgb(%f,%f,%f)', ... + 255*thetaLabel.Color); + + %-------------------------------------------------------------------------% + + %-setting radial axis-% + rLim = rAxis.Limits; + + polarAxis.radialaxis.showline = false; + polarAxis.radialaxis.angle = axisData.RAxisLocation+6; + polarAxis.radialaxis.tickangle = 90-rAxis.TickLabelRotation; + polarAxis.radialaxis.ticklen = mean(rAxis.TickLength); + + if isnumeric(rLim) + polarAxis.radialaxis.range = rLim; else - if length(childmarker.line.color) > 3 - obj.data{scatterIndex}.marker.line.color = childmarker.line.color; - else - obj.data{scatterIndex}.marker.line.color = childmarker.line.color{1}; + polarAxis.radialaxis.autorange = true; + end + + if strcmp(axisData.RGrid, 'on') + polarAxis.radialaxis.gridwidth = gridWidth; + polarAxis.radialaxis.gridcolor = gridColor; + end + + %-------------------------------------------------------------------------% + + %-set radial axis label-% + rLabel = thetaAxis.Label; + + polarAxis.angularaxis.title.text = 'label';%rLabel.String; + polarAxis.angularaxis.title.font.family = matlab2plotlyfont(... + rLabel.FontName); + polarAxis.angularaxis.title.font.size = rLabel.FontSize; + polarAxis.angularaxis.title.font.color = sprintf('rgb(%f,%f,%f)', ... + 255*rLabel.Color); + + %-------------------------------------------------------------------------% + + %-angular tick labels settings-% + tickValues = axisData.ThetaTick; + tickLabels = axisData.ThetaTickLabel; + showTickLabels = true; + + try + if tickValues(1) == 0 && tickValues(end) == 360 + tickValues = tickValues(1:end-1); end + catch + tickValues = tickValues; end - - %---------------------------------------------------------------------% - - %-marker color-% - if length(scatter_data) > 1 - obj.data{scatterIndex}.marker.color{m} = childmarker.color{1}; + + if isempty(tickValues) + showTickLabels = false; + polarAxis.angularaxis.showticklabels = showTickLabels; + polarAxis.angularaxis.ticks = ''; + + elseif isempty(tickLabels) + polarAxis.angularaxis.tickvals = tickValues; + else - obj.data{scatterIndex}.marker.color = childmarker.color; + polarAxis.angularaxis.tickvals = tickValues; + polarAxis.angularaxis.ticktext = tickLabels; + end - - %---------------------------------------------------------------------% - - %-sizeref-% - obj.data{scatterIndex}.marker.sizeref = childmarker.sizeref; - - %---------------------------------------------------------------------% - - %-sizemode-% - obj.data{scatterIndex}.marker.sizemode = childmarker.sizemode; - - %---------------------------------------------------------------------% - - %-symbol-% - if length(scatter_data) > 1 - obj.data{scatterIndex}.marker.symbol{m} = childmarker.symbol; - else - obj.data{scatterIndex}.marker.symbol = childmarker.symbol; + + if showTickLabels + switch thetaAxis.TickDirection + case 'in' + polarAxis.angularaxis.ticks = 'inside'; + case 'out' + polarAxis.angularaxis.ticks = 'outside'; + end + + %-tick font-% + polarAxis.angularaxis.tickfont.family = matlab2plotlyfont(... + thetaAxis.FontName); + polarAxis.angularaxis.tickfont.size = thetaAxis.FontSize; + polarAxis.angularaxis.tickfont.color = sprintf('rgb(%f,%f,%f)', ... + 255*thetaAxis.Color); end - - %---------------------------------------------------------------------% - - %-size-% - if length(scatter_data) > 1 - obj.data{scatterIndex}.marker.size = childmarker.size; + + + %-------------------------------------------------------------------------% + + %-radial tick labels settings-% + tickValues = axisData.RTick; + tickLabels = axisData.RTickLabel; + showTickLabels = true; + + if isempty(tickValues) + showTickLabels = false; + polarAxis.radialaxis.showticklabels = showTickLabels; + polarAxis.radialaxis.ticks = ''; + + elseif isempty(tickLabels) + polarAxis.radialaxis.tickvals = tickValues; + else - obj.data{scatterIndex}.marker.size = childmarker.size * 0.15; + polarAxis.radialaxis.tickvals = tickValues; + polarAxis.radialaxis.ticktext = tickLabels; end - - %---------------------------------------------------------------------% - - %-line width-% - - if length(scatter_data) > 1 || ischar(childmarker.line.color) - obj.data{scatterIndex}.marker.line.width(m) = childmarker.line.width; - else - obj.data{scatterIndex}.marker.line.width = childmarker.line.width; - % obj.data{scatterIndex}.marker.line.width(1:length(childmarker.line.color)) = childmarker.line.width; + + if showTickLabels + switch rAxis.TickDirection + case 'in' + polarAxis.radialaxis.ticks = 'inside'; + case 'out' + polarAxis.radialaxis.ticks = 'outside'; + end + + %-tick font-% + polarAxis.radialaxis.tickfont.family = matlab2plotlyfont(... + rAxis.FontName); + polarAxis.radialaxis.tickfont.size = rAxis.FontSize; + polarAxis.radialaxis.tickfont.color = sprintf('rgb(%f,%f,%f)', ... + 255*rAxis.Color); end - - %---------------------------------------------------------------------% + + %-------------------------------------------------------------------------% + + %-set polaraxes to layout-% + obj.layout = setfield(obj.layout, sprintf('polar%d', xsource+1), polarAxis); + + %-------------------------------------------------------------------------% end -end + diff --git a/plotly/plotlyfig_aux/handlegraphics/updateSurf.m b/plotly/plotlyfig_aux/handlegraphics/updateSurf.m index 85838be1..85e1b83f 100644 --- a/plotly/plotlyfig_aux/handlegraphics/updateSurf.m +++ b/plotly/plotlyfig_aux/handlegraphics/updateSurf.m @@ -8,7 +8,6 @@ %-SURFACE DATA STRUCTURE- % meshData = get(obj.State.Plot(surfaceIndex).Handle); -figureData = get(obj.State.Figure.Handle); %-AXIS STRUCTURE-% axisData = get(ancestor(meshData.Parent,'axes')); @@ -104,7 +103,7 @@ %-------------------------------------------------------------------------% %-get colormap-% -cMap = figureData.Colormap; +cMap = axisData.Colormap; fac = 1/(length(cMap)-1); colorScale = {};