diff --git a/plotly/plotlyfig.m b/plotly/plotlyfig.m index 8732b56f..92e5e512 100644 --- a/plotly/plotlyfig.m +++ b/plotly/plotlyfig.m @@ -87,7 +87,7 @@ end %-PlotlyDefaults-% - obj.PlotlyDefaults.MinTitleMargin = 80; + obj.PlotlyDefaults.MinTitleMargin = 10; obj.PlotlyDefaults.TitleHeight = 0.01; obj.PlotlyDefaults.TitleFontSizeIncrease = 40; obj.PlotlyDefaults.FigureIncreaseFactor = 1.5; @@ -788,7 +788,6 @@ function validate(obj) end catch % TODO to the future - % disp('catch at line 679 in plotlyfig.m file') end end @@ -1108,7 +1107,7 @@ function delete(obj) || strcmpi(fieldname,'legend') || strcmpi(fieldname,'histogram')... || strcmpi(fieldname,'scatter') || strcmpi(fieldname,'line')... || strcmpi(fieldname,'scattergeo') || strcmpi(fieldname,'scattermapbox')... - || strcmpi(fieldname,'scatterternary')... + || strcmpi(fieldname,'scatterternary') || strcmpi(fieldname,'colorbar')... ) fprintf(['\nWhoops! ' exception.message(1:end-1) ' in ' fieldname '\n\n']); end diff --git a/plotly/plotlyfig_aux/core/updateAxis.m b/plotly/plotlyfig_aux/core/updateAxis.m index 1dc0ffd0..047a6e2d 100644 --- a/plotly/plotlyfig_aux/core/updateAxis.m +++ b/plotly/plotlyfig_aux/core/updateAxis.m @@ -42,60 +42,61 @@ % position:...[NOT SUPPORTED IN MATLAB] %-STANDARDIZE UNITS-% -axisunits = get(obj.State.Axis(axIndex).Handle,'Units'); +axisUnits = get(obj.State.Axis(axIndex).Handle,'Units'); set(obj.State.Axis(axIndex).Handle,'Units','normalized') try - fontunits = get(obj.State.Axis(axIndex).Handle,'FontUnits'); + fontUnits = get(obj.State.Axis(axIndex).Handle,'FontUnits'); set(obj.State.Axis(axIndex).Handle,'FontUnits','points') catch % TODO end %-AXIS DATA STRUCTURE-% -axis_data = get(obj.State.Axis(axIndex).Handle); +axisData = get(obj.State.Axis(axIndex).Handle); %-------------------------------------------------------------------------% %-check if headmap axis-% -is_headmap_axis = isfield(axis_data, 'XDisplayData'); +is_headmap_axis = isfield(axisData, 'XDisplayData'); obj.PlotOptions.is_headmap_axis = is_headmap_axis; %-------------------------------------------------------------------------% %-check if geo-axis-% -isGeoaxis = isfield(axis_data, 'Type') && strcmpi(axis_data.Type, 'geoaxes'); +isGeoaxis = isfield(axisData, 'Type') && strcmpi(axisData.Type, 'geoaxes'); obj.PlotlyDefaults.isGeoaxis = isGeoaxis; %-------------------------------------------------------------------------% %-xaxis-% if is_headmap_axis - xaxis = extractHeatmapAxisData(obj,axis_data, 'X'); + xaxis = extractHeatmapAxisData(obj,axisData, 'X'); + xExponentFormat = 0; else - xaxis = extractAxisData(obj,axis_data, 'X'); + [xaxis, xExponentFormat] = extractAxisData(obj,axisData, 'X'); end %-------------------------------------------------------------------------% %-yaxis-% if is_headmap_axis - yaxis = extractHeatmapAxisData(obj,axis_data, 'Y'); + yaxis = extractHeatmapAxisData(obj,axisData, 'Y'); + yExponentFormat = 0; else - yaxis = extractAxisData(obj,axis_data, 'Y'); + [yaxis, yExponentFormat] = extractAxisData(obj,axisData, 'Y'); end %-------------------------------------------------------------------------% %-getting and setting postion data-% - -xo = axis_data.Position(1); -yo = axis_data.Position(2); -w = axis_data.Position(3); -h = axis_data.Position(4); +xo = axisData.Position(1); +yo = axisData.Position(2); +w = axisData.Position(3); +h = axisData.Position(4); if obj.PlotOptions.AxisEqual - wh = min(axis_data.Position(3:4)); + wh = min(axisData.Position(3:4)); w = wh; h = wh; end @@ -114,10 +115,56 @@ %-------------------------------------------------------------------------% +%-get source axis-% [xsource, ysource, xoverlay, yoverlay] = findSourceAxis(obj,axIndex); %-------------------------------------------------------------------------% +%-set exponent format-% +anIndex = obj.State.Figure.NumTexts; + +if yExponentFormat ~= 0 + anIndex = anIndex + 1; + exponentText = sprintf('x10^%d', yExponentFormat); + + obj.layout.annotations{anIndex}.text = exponentText; + obj.layout.annotations{anIndex}.xref = ['x' num2str(xsource)]; + obj.layout.annotations{anIndex}.yref = ['y' num2str(ysource)]; + obj.layout.annotations{anIndex}.xanchor = 'left'; + obj.layout.annotations{anIndex}.yanchor = 'bottom'; + obj.layout.annotations{anIndex}.font.size = yaxis.tickfont.size; + obj.layout.annotations{anIndex}.font.color = yaxis.tickfont.color; + obj.layout.annotations{anIndex}.font.family = yaxis.tickfont.family; + obj.layout.annotations{anIndex}.showarrow = false; + + if isfield(xaxis, 'range') && isfield(yaxis, 'range') + obj.layout.annotations{anIndex}.x = min(xaxis.range); + obj.layout.annotations{anIndex}.y = max(yaxis.range); + end +end + +if xExponentFormat ~= 0 + anIndex = anIndex + 1; + exponentText = sprintf('x10^%d', xExponentFormat); + + obj.layout.annotations{anIndex}.text = exponentText; + obj.layout.annotations{anIndex}.xref = ['x' num2str(xsource)]; + obj.layout.annotations{anIndex}.yref = ['y' num2str(ysource)]; + obj.layout.annotations{anIndex}.xanchor = 'left'; + obj.layout.annotations{anIndex}.yanchor = 'bottom'; + obj.layout.annotations{anIndex}.font.size = xaxis.tickfont.size; + obj.layout.annotations{anIndex}.font.color = xaxis.tickfont.color; + obj.layout.annotations{anIndex}.font.family = xaxis.tickfont.family; + obj.layout.annotations{anIndex}.showarrow = false; + + if isfield(xaxis, 'range') && isfield(yaxis, 'range') + obj.layout.annotations{anIndex}.x = max(xaxis.range); + obj.layout.annotations{anIndex}.y = min(yaxis.range); + end +end + +%-------------------------------------------------------------------------% + %-xaxis anchor-% xaxis.anchor = ['y' num2str(ysource)]; @@ -145,9 +192,7 @@ % update the layout field (do not overwrite source) if xsource == axIndex obj.layout = setfield(obj.layout,['xaxis' num2str(xsource)],xaxis); - obj.layout = setfield(obj.layout,['scene' num2str(xsource)],scene); -else - + obj.layout = setfield(obj.layout,['scene' num2str(xsource)],scene); end %-------------------------------------------------------------------------% @@ -155,17 +200,15 @@ % update the layout field (do not overwrite source) if ysource == axIndex obj.layout = setfield(obj.layout,['yaxis' num2str(ysource)],yaxis); -else - end %-------------------------------------------------------------------------% %-REVERT UNITS-% -set(obj.State.Axis(axIndex).Handle,'Units',axisunits); +set(obj.State.Axis(axIndex).Handle,'Units',axisUnits); try - set(obj.State.Axis(axIndex).Handle,'FontUnits',fontunits); + set(obj.State.Axis(axIndex).Handle,'FontUnits',fontUnits); catch % TODO end diff --git a/plotly/plotlyfig_aux/core/updateColorbar.m b/plotly/plotlyfig_aux/core/updateColorbar.m index a38273d3..2ac56064 100644 --- a/plotly/plotlyfig_aux/core/updateColorbar.m +++ b/plotly/plotlyfig_aux/core/updateColorbar.m @@ -1,362 +1,343 @@ function obj = updateColorbar(obj,colorbarIndex) -% title: ...[DONE] -% titleside: ...[DONE] -% titlefont: ...[DONE] -% thickness: ...[DONE] -% thicknessmode: ...[DONE] -% len: ...[DONE] -% lenmode: ...[DONE] -% x: ...[DONE] -% y: ...[DONE] -% autotick: ...[DONE] -% nticks: ...[DONE] -% ticks: ...[DONE] -% showticklabels: ...[DONE] -% tick0: ...[DONE] -% dtick: ...[DONE] -% ticklen: ...[DONE] -% tickwidth: ...[DONE] -% tickcolor: ...[DONE] -% tickangle: ...[NOT SUPPORTED IN MATLAB] -% tickfont: ...[DONE] -% exponentformat: ...[DONE] -% showexponent: ...[NOT SUPPORTED IN MATLAB] -% xanchor: ...[DONE] -% yanchor: ...[DONE] -% bgcolor: ...[DONE] -% outlinecolor: ...[DONE] -% outlinewidth: ...[DONE] -% borderwidth: ...[NOT SUPPORTED IN MATLAB] -% bordercolor: ...[NOT SUPPORTED IN MATLAB] -% xpad: ...[DONE] -% ypad: ...[DONE] - -%-FIGURE STRUCTURE-% -figure_data = get(obj.State.Figure.Handle); - -%-PLOT DATA STRUCTURE- % -try - colorbar_data = get(obj.State.Colorbar(colorbarIndex).Handle); -catch - disp('here'); -end - -%-STANDARDIZE UNITS-% -colorbarunits = colorbar_data.Units; -set(obj.State.Colorbar(colorbarIndex).Handle,'Units','normalized'); - -%-------------------------------------------------------------------------% - -%-x anchor-% -colorbar.xanchor = 'left'; - -%-------------------------------------------------------------------------% - -%-y anchor-% -colorbar.yanchor = 'bottom'; - -%-------------------------------------------------------------------------% - -%-x position-% -colorbar.x = colorbar_data.Position(1); - -%-------------------------------------------------------------------------% - -%-y position-% -colorbar.y = colorbar_data.Position(2); - -%-------------------------------------------------------------------------% + % title: ...[DONE] + % titleside: ...[DONE] + % titlefont: ...[DONE] + % thickness: ...[DONE] + % thicknessmode: ...[DONE] + % len: ...[DONE] + % lenmode: ...[DONE] + % x: ...[DONE] + % y: ...[DONE] + % autotick: ...[DONE] + % nticks: ...[DONE] + % ticks: ...[DONE] + % showticklabels: ...[DONE] + % tick0: ...[DONE] + % dtick: ...[DONE] + % ticklen: ...[DONE] + % tickwidth: ...[DONE] + % tickcolor: ...[DONE] + % tickangle: ...[NOT SUPPORTED IN MATLAB] + % tickfont: ...[DONE] + % exponentformat: ...[DONE] + % showexponent: ...[NOT SUPPORTED IN MATLAB] + % xanchor: ...[DONE] + % yanchor: ...[DONE] + % bgcolor: ...[DONE] + % outlinecolor: ...[DONE] + % outlinewidth: ...[DONE] + % borderwidth: ...[NOT SUPPORTED IN MATLAB] + % bordercolor: ...[NOT SUPPORTED IN MATLAB] + % xpad: ...[DONE] + % ypad: ...[DONE] + + %-FIGURE STRUCTURE-% + figureData = get(obj.State.Figure.Handle); + + %-PLOT DATA STRUCTURE- % + try + colorbarData = get(obj.State.Colorbar(colorbarIndex).Handle); + catch + disp('could not get colorbar data'); + end -%-exponent format-% -colorbar.exponentformat = obj.PlotlyDefaults.ExponentFormat; + %-STANDARDIZE UNITS-% + colorbarUnits = colorbarData.Units; + set(obj.State.Colorbar(colorbarIndex).Handle,'Units','normalized'); -%-------------------------------------------------------------------------% + %-------------------------------------------------------------------------% -% get colorbar title and labels -if isHG2 - colorbar_title = colorbar_data.Label; - colorbar_title_data = get(colorbar_title); - colorbar_ylabel = colorbar_data.Label; - colorbar_ylabel_data = get(colorbar_data.Label); - colorbar_xlabel_data.String = []; -else - colorbar_title = colorbar_data.Title; - colorbar_title_data = get(colorbar_title); - colorbar_xlabel = colorbar_data.XLabel; - colorbar_xlabel_data = get(colorbar_xlabel); - colorbar_ylabel = colorbar_data.YLabel; - colorbar_ylabel_data = get(colorbar_ylabel); -end + %-variable initialization-% + if isHG2 + outlineColor = [0 0 0]; + else + if colorbarData.Position(4) > colorbarData.Position(3) + outlineColor = 255*colorbarData.YColor; + else + outlineColor = 255*colorbarData.XColor; + end + end -%-colorbar title-% -if ~isempty(colorbar_title_data.String) - %-colorbar title-% - colorbar.title = parseString(colorbar_title_data.String,colorbar_title_data.Interpreter); -elseif ~isempty(colorbar_xlabel_data.String) - %-colorbar title-% - colorbar.title = parseString(colorbar_xlabel_data.String,colorbar_xlabel_data.Interpreter); -elseif ~isempty(colorbar_ylabel_data.String) - %-colorbar title-% - colorbar.title = parseString(colorbar_ylabel_data.String,colorbar_ylabel_data.Interpreter); + outlineColor = sprintf('rgb(%f,%f,%f)', outlineColor); + lineWidth = colorbarData.LineWidth*obj.PlotlyDefaults.AxisLineIncreaseFactor; + tickLength = min(obj.PlotlyDefaults.MaxTickLength,... + max(colorbarData.TickLength(1)*colorbarData.Position(3)*obj.layout.width,... + colorbarData.TickLength(1)*colorbarData.Position(4)*obj.layout.height)); + + %-------------------------------------------------------------------------% + + %-colorbar placement-% + colorbar.x = colorbarData.Position(1); + colorbar.y = colorbarData.Position(2); + colorbar.len = colorbarData.Position(4); + colorbar.thickness = colorbarData.Position(3); + + colorbar.xpad = obj.PlotlyDefaults.MarginPad; + colorbar.ypad = obj.PlotlyDefaults.MarginPad; + colorbar.xanchor = 'left'; + colorbar.yanchor = 'bottom'; + + colorbar.outlinewidth = lineWidth; + colorbar.outlinecolor = outlineColor; + colorbar.exponentformat = obj.PlotlyDefaults.ExponentFormat; + colorbar.thicknessmode = 'fraction'; + colorbar.lenmode = 'fraction'; -end + %-------------------------------------------------------------------------% + + %-tick setings-% + colorbar.tickcolor = outlineColor; + colorbar.tickfont.color = outlineColor; + colorbar.tickfont.size = colorbarData.FontSize; + colorbar.tickfont.family = matlab2plotlyfont(colorbarData.FontName); + colorbar.ticklen = tickLength; + colorbar.tickwidth = lineWidth; + + %-------------------------------------------------------------------------% + + %-get colorbar title and labels-% + colorbarTitle = colorbarData.Label; + + if isHG2 + colorbarTitleData = get(colorbarTitle); + colorbarYLabel = colorbarTitle; + colorbarYLabelData = get(colorbarTitle); + colorbarXLabelData.String = []; + else + colorbarTitleData = get(colorbarTitle); + colorbarXLabel = colorbarData.XLabel; + colorbarXLabelData = get(colorbarXLabel); + colorbarYLabel = colorbarData.YLabel; + colorbarYLabelData = get(colorbarYLabel); + end + %-------------------------------------------------------------------------% + + %-STANDARDIZE UNITS FOR TITLE-% + titleunits = colorbarTitleData.Units; + titlefontunits = colorbarTitleData.FontUnits; + ylabelunits = colorbarYLabelData.Units; + ylabelfontunits = colorbarYLabelData.FontUnits; + set(colorbarTitle,'Units','data'); + set(colorbarYLabel,'Units','data'); + set(colorbarYLabel,'FontUnits','points'); + if ~isHG2 + xlabelunits = colorbarXLabelData.Units; + xlabelfontunits = colorbarXLabelData.FontUnits; + set(colorbarTitle,'FontUnits','points'); + set(colorbarXLabel,'Units','data'); + set(colorbarXLabel,'FontUnits','points'); + end -%-------------------------------------------------------------------------% - -%-STANDARDIZE UNITS-% -titleunits = colorbar_title_data.Units; -titlefontunits = colorbar_title_data.FontUnits; -ylabelunits = colorbar_ylabel_data.Units; -ylabelfontunits = colorbar_ylabel_data.FontUnits; -set(colorbar_title,'Units','data'); -set(colorbar_ylabel,'Units','data'); -set(colorbar_ylabel,'FontUnits','points'); -if ~isHG2 - xlabelunits = colorbar_xlabel_data.Units; - xlabelfontunits = colorbar_xlabel_data.FontUnits; - set(colorbar_title,'FontUnits','points'); - set(colorbar_xlabel,'Units','data'); - set(colorbar_xlabel,'FontUnits','points'); -end + %-------------------------------------------------------------------------% + %-colorbar title settings-% + isTitle = true; -if ~isempty(colorbar_title_data.String) - %-colorbar titleside-% - colorbar.titleside = 'top'; - %-colorbar titlefont family-%: - colorbar.titlefont.family = matlab2plotlyfont(colorbar_title_data.FontName); - %-colorbar titlefont color-% - col = 255*colorbar_title_data.Color; - colorbar.titlefont.color = ['rgb(' num2str(col(1)) ',' num2str(col(2)) ',' num2str(col(3)) ')']; - %-colorbar titlefont size-% - colorbar.titlefont.size = colorbar_title_data.FontSize; -elseif ~isempty(colorbar_xlabel_data.String) - %-colorbar titleside-% - colorbar.titleside = 'right'; - %-colorbar titlefont family-%: - colorbar.titlefont.family = matlab2plotlyfont(colorbar_xlabel_data.FontName); - %-colorbar titlefont color-% - col = 255*colorbar_xlabel_data.Color; - colorbar.titlefont.color = ['rgb(' num2str(col(1)) ',' num2str(col(2)) ',' num2str(col(3)) ')']; - %-colorbar titlefont size-% - colorbar.titlefont.size = colorbar_xlabel_data.FontSize; -elseif ~isempty(colorbar_ylabel_data.String) - %-colorbar titleside-% - colorbar.titleside = 'bottom'; - %-colorbar titlefont family-%: - colorbar.titlefont.family = matlab2plotlyfont(colorbar_ylabel_data.FontName); - %-colorbar titlefont color-% - col = 255*colorbar_ylabel_data.Color; - colorbar.titlefont.color = ['rgb(' num2str(col(1)) ',' num2str(col(2)) ',' num2str(col(3)) ')']; - %-colorbar titlefont size-% - colorbar.titlefont.size = colorbar_ylabel_data.FontSize; -end + if ~isempty(colorbarTitleData.String) + titleString = colorbarTitleData.String; + titleInterpreter = colorbarTitleData.Interpreter; -%-REVERT UNITS-% -set(colorbar_title,'Units',titleunits); -set(colorbar_title,'FontUnits',titlefontunits); -set(colorbar_ylabel,'Units',ylabelunits); -set(colorbar_ylabel,'FontUnits',ylabelfontunits); - -if ~isHG2 - set(colorbar_xlabel,'Units',xlabelunits); - set(colorbar_xlabel,'FontUnits',xlabelfontunits); -end + if colorbarTitleData.Rotation == 90 + titleSide = 'right'; + else + titleSide = 'top'; + end + titleFontSize = 1.20 * colorbarTitleData.FontSize; + titleFontColor = sprintf('rgb(%f,%f,%f)', 255*colorbarTitleData.Color); + titleFontFamily = matlab2plotlyfont(colorbarTitleData.FontName); -%-thicknessmode-% -colorbar.thicknessmode = 'fraction'; + elseif ~isempty(colorbarXLabelData.String) + titleString = colorbarXLabelData.String; + titleInterpreter = colorbarXLabelData.Interpreter; -%-------------------------------------------------------------------------% + titleSide = 'right'; + titleFontSize = 1.20 * colorbarXLabelData.FontSize; + titleFontColor = sprintf('rgb(%f,%f,%f)', 255*colorbarXLabelData.Color); + titleFontFamily = matlab2plotlyfont(colorbarXLabelData.FontName); -%-thickness-% -colorbar.thickness = colorbar_data.Position(3); + elseif ~isempty(colorbarYLabelData.String) + titleString = colorbarYLabelData.String; + titleInterpreter = colorbarYLabelData.Interpreter; -%-------------------------------------------------------------------------% + titleSide = 'bottom'; + titleFontSize = 1.20 * colorbarYLabelData.FontSize; + titleFontColor = sprintf('rgb(%f,%f,%f)', 255*colorbarYLabelData.Color); + titleFontFamily = matlab2plotlyfont(colorbarYLabelData.FontName); -%-lenmode-% -colorbar.lenmode = 'fraction'; + else + isTitle = false; + end -%-------------------------------------------------------------------------% + if isTitle + colorbar.title = parseString(titleString, titleInterpreter); + colorbar.titleside = titleSide; + colorbar.titlefont.size = titleFontSize; + colorbar.titlefont.color = titleFontColor; + colorbar.titlefont.family = titleFontFamily; + end -%-length-% -colorbar.len = colorbar_data.Position(4); + %-------------------------------------------------------------------------% -%-------------------------------------------------------------------------% + %-REVERT UNITS FOR TITLE-% + set(colorbarTitle,'Units',titleunits); + set(colorbarTitle,'FontUnits',titlefontunits); + set(colorbarYLabel,'Units',ylabelunits); + set(colorbarYLabel,'FontUnits',ylabelfontunits); -% orientation vertical check -orientVert = colorbar.len > colorbar.thickness; + if ~isHG2 + set(colorbarXLabel,'Units',xlabelunits); + set(colorbarXLabel,'FontUnits',xlabelfontunits); + end -%-------------------------------------------------------------------------% + %-------------------------------------------------------------------------% -%-outline width-% -linewidth = colorbar_data.LineWidth*obj.PlotlyDefaults.AxisLineIncreaseFactor; -colorbar.outlinewidth = linewidth; + %-tick labels-% + tickValues = colorbarData.Ticks; + tickLabels = colorbarData.TickLabels; + showTickLabels = true; -%-------------------------------------------------------------------------% + if isHG2 + if isempty(tickValues) + showTickLabels = false; + colorbar.ticks = ''; -%-tickwidth-% -colorbar.tickwidth = linewidth; + elseif isempty(tickLabels) + colorbar.tickvals = tickValues; -%-------------------------------------------------------------------------% + else + colorbar.tickvals = tickValues; + colorbar.ticktext = tickLabels; + end -ticklength = min(obj.PlotlyDefaults.MaxTickLength,... - max(colorbar_data.TickLength(1)*colorbar_data.Position(3)*obj.layout.width,... - colorbar_data.TickLength(1)*colorbar_data.Position(4)*obj.layout.height)); + if showTickLabels + colorbar.showticklabels = showTickLabels; -%-xaxis ticklen-% -colorbar.ticklen = ticklength; + switch colorbarData.AxisLocation + case 'in' + colorbar.ticklabelposition = 'inside'; + case 'out' + colorbar.ticklabelposition = 'outside'; + end -%-------------------------------------------------------------------------% + switch colorbarData.TickDirection + case 'in' + colorbar.ticks = 'inside'; + case 'out' + colorbar.ticks = 'outside'; + end -% check orientation for x/y properties + end -if isHG2 - col = [0 0 0]; -else - if orientVert - col = 255*colorbar_data.YColor; else - col = 255*colorbar_data.XColor; + colorbar = setTicksNotHG2(colorbar, colorbarData); end -end -colorbar_col = ['rgb(' num2str(col(1)) ',' num2str(col(2)) ',' num2str(col(3)) ')']; + %-------------------------------------------------------------------------% -%-outlinecolor-% -colorbar.outlinecolor = colorbar_col; - -%-------------------------------------------------------------------------% - -%-tickcolor-% -colorbar.tickcolor = colorbar_col; - -%-------------------------------------------------------------------------% + %-colorbar bg-color-% + if ~isHG2 + if ~ischar(colorbarData.Color) + bgColor = 255*colorbarData.Color; + else + bgColor = 255*figureData.Color; + end + + obj.layout.plot_bgcolor = sprintf('rgb(%f,%f,%f', bgColor); + end -%-tickfont-% -colorbar.tickfont.color = colorbar_col; + %-------------------------------------------------------------------------% -%-------------------------------------------------------------------------% + %-ASSOCIATED DATA-% + if isfield(colorbarData.UserData,'dataref') + colorbarDataIndex = colorbarData.UserData.dataref; + else + colorbarDataIndex = findColorbarData(obj,colorbarIndex,colorbarData); + end -%-xaxis tick font size-% -colorbar.tickfont.size = colorbar_data.FontSize; + obj.data{colorbarDataIndex}.colorbar = colorbar; + obj.data{colorbarDataIndex}.showscale = true; -%-------------------------------------------------------------------------% + %-------------------------------------------------------------------------% -%-xaxis tick font family-% -colorbar.tickfont.family = matlab2plotlyfont(colorbar_data.FontName); + %-REVERT UNITS-% + set(obj.State.Colorbar(colorbarIndex).Handle,'Units',colorbarUnits); -%-------------------------------------------------------------------------% + %-------------------------------------------------------------------------% +end -%-colorbar pad-% -colorbar.xpad = obj.PlotlyDefaults.MarginPad; -colorbar.ypad = obj.PlotlyDefaults.MarginPad; -%-------------------------------------------------------------------------% +function colorbar = setTicksNotHG2(colorbar, colorbarData) + verticalOrientation = colorbar.len > colorbar.thickness; -% check orientation for x/y properties -if ~isHG2 - if orientVert - if isempty(colorbar_data.YTick) + if verticalOrientation + if isempty(colorbarData.YTick) %-show tick labels-% colorbar.ticks = ''; colorbar.showticklabels = false; else %-tick direction-% - switch colorbar_data.TickDir + switch colorbarData.TickDir case 'in' colorbar.ticks = 'inside'; case 'out' colorbar.ticks = 'outside'; end - if strcmp(colorbar_data.YTickLabelMode,'auto') + if strcmp(colorbarData.YTickLabelMode,'auto') %-autotick-% colorbar.autotick = true; %-numticks-% - colorbar.nticks = length(colorbar_data.YTick) + 1; %nticks = max ticks (so + 1) + colorbar.nticks = length(colorbarData.YTick) + 1; %nticks = max ticks (so + 1) else %-show tick labels-% - if isempty(colorbar_data.YTickLabel) + if isempty(colorbarData.YTickLabel) colorbar.showticklabels = false; else %-autotick-% colorbar.autotick = false; %-tick0-% - colorbar.tick0 = str2double(colorbar_data.YTickLabel(1,:)); + colorbar.tick0 = str2double(colorbarData.YTickLabel(1,:)); %-dtick-% - colorbar.dtick = str2double(colorbar_data.YTickLabel(2,:)) - str2double(colorbar_data.YTickLabel(1,:)); + colorbar.dtick = str2double(colorbarData.YTickLabel(2,:)) - str2double(colorbarData.YTickLabel(1,:)); end end end else - if isempty(colorbar_data.XTick) + if isempty(colorbarData.XTick) %-show tick labels-% colorbar.ticks = ''; colorbar.showticklabels = false; else %-tick direction-% - switch colorbar_data.TickDir + switch colorbarData.TickDir case 'in' colorbar.ticks = 'inside'; case 'out' colorbar.ticks = 'outside'; end - if strcmp(colorbar_data.XTickLabelMode,'auto') + if strcmp(colorbarData.XTickLabelMode,'auto') %-autotick-% colorbar.autotick = true; %-numticks-% - colorbar.nticks = length(colorbar_data.XTick) + 1; + colorbar.nticks = length(colorbarData.XTick) + 1; else %-show tick labels-% - if isempty(colorbar_data.XTickLabel) + if isempty(colorbarData.XTickLabel) colorbar.showticklabels = false; else %-autotick-% colorbar.autotick = false; %-tick0-% - colorbar.tick0 = str2double(colorbar_data.XTickLabel(1,:)); + colorbar.tick0 = str2double(colorbarData.XTickLabel(1,:)); %-dtick-% - colorbar.dtick = str2double(colorbar_data.XTickLabel(2,:)) - str2double(colorbar_data.XTickLabel(1,:)); + colorbar.dtick = str2double(colorbarData.XTickLabel(2,:)) - str2double(colorbarData.XTickLabel(1,:)); end end end end end -%-------------------------------------------------------------------------% - -if ~isHG2 - %-colorbar bg-color-% - if ~ischar(colorbar_data.Color) - col = 255*colorbar_data.Color; - else - col = 255*figure_data.Color; - end - - obj.layout.plot_bgcolor = ['rgb(' num2str(col(1)) ',' num2str(col(2)) ',' num2str(col(3)) ')']; -end -%-------------------------------------------------------------------------% - - -%--------------------------ASSOCIATED DATA--------------------------------% - -if isfield(colorbar_data.UserData,'dataref') - colorbarDataIndex = colorbar_data.UserData.dataref; -else - colorbarDataIndex = findColorbarData(obj,colorbarIndex); -end - -%-set colorbar-% -obj.data{colorbarDataIndex}.colorbar = colorbar; - -%-show scale-% -obj.data{colorbarDataIndex}.showscale = true; - -%-REVERT UNITS-% -set(obj.State.Colorbar(colorbarIndex).Handle,'Units',colorbarunits); - -end diff --git a/plotly/plotlyfig_aux/core/updateData.m b/plotly/plotlyfig_aux/core/updateData.m index 05486ea1..82e641f8 100644 --- a/plotly/plotlyfig_aux/core/updateData.m +++ b/plotly/plotlyfig_aux/core/updateData.m @@ -26,12 +26,8 @@ updateBar3(obj, dataIndex); elseif ismember('bar3h', lower(obj.PlotOptions.TreatAs)) updateBar3h(obj, dataIndex); - elseif ismember('surf', lower(obj.PlotOptions.TreatAs)) - updateSurf(obj, dataIndex); elseif ismember('fmesh', lower(obj.PlotOptions.TreatAs)) updateFmesh(obj, dataIndex); - elseif ismember('mesh', lower(obj.PlotOptions.TreatAs)) - updateMesh(obj, dataIndex); elseif ismember('surfc', lower(obj.PlotOptions.TreatAs)) updateSurfc(obj, dataIndex); elseif ismember('meshc', lower(obj.PlotOptions.TreatAs)) @@ -97,7 +93,13 @@ case 'rectangle' updateRectangle(obj,dataIndex); case 'surface' - updateSurfaceplot(obj,dataIndex); + if ismember('surf', lower(obj.PlotOptions.TreatAs)) + updateSurf(obj, dataIndex); + elseif ismember('mesh', lower(obj.PlotOptions.TreatAs)) + updateMesh(obj, dataIndex); + else + updateSurfaceplot(obj,dataIndex); + end case {'functionsurface', 'parameterizedfunctionsurface'} updateFunctionSurface(obj,dataIndex); case 'implicitfunctionsurface' diff --git a/plotly/plotlyfig_aux/handlegraphics/updateContourgroup.m b/plotly/plotlyfig_aux/handlegraphics/updateContourgroup.m index d7f86aec..5453fcd9 100644 --- a/plotly/plotlyfig_aux/handlegraphics/updateContourgroup.m +++ b/plotly/plotlyfig_aux/handlegraphics/updateContourgroup.m @@ -239,7 +239,7 @@ %-------------------------------------------------------------------------% %-contour showscale-% -obj.data{contourIndex}.showscale = true; +obj.data{contourIndex}.showscale = false; %-------------------------------------------------------------------------% diff --git a/plotly/plotlyfig_aux/handlegraphics/updateMesh.m b/plotly/plotlyfig_aux/handlegraphics/updateMesh.m index 0660026a..9b1c8cf2 100644 --- a/plotly/plotlyfig_aux/handlegraphics/updateMesh.m +++ b/plotly/plotlyfig_aux/handlegraphics/updateMesh.m @@ -43,6 +43,10 @@ yData = meshData.YData; zData = meshData.ZData; +if isvector(xData) + [xData, yData] = meshgrid(xData, yData); +end + %-reformat data to mesh-% xDataSurface = xData; yDataSurface = yData; diff --git a/plotly/plotlyfig_aux/handlegraphics/updateSurf.m b/plotly/plotlyfig_aux/handlegraphics/updateSurf.m index b3b4feda..85838be1 100644 --- a/plotly/plotlyfig_aux/handlegraphics/updateSurf.m +++ b/plotly/plotlyfig_aux/handlegraphics/updateSurf.m @@ -43,6 +43,10 @@ yData = meshData.YData; zData = meshData.ZData; +if isvector(xData) + [xData, yData] = meshgrid(xData, yData); +end + %-reformat data to mesh-% xDataSurface = xData; yDataSurface = yData; diff --git a/plotly/plotlyfig_aux/helpers/extractAxisData.m b/plotly/plotlyfig_aux/helpers/extractAxisData.m index dcc2008b..834fbd9a 100644 --- a/plotly/plotlyfig_aux/helpers/extractAxisData.m +++ b/plotly/plotlyfig_aux/helpers/extractAxisData.m @@ -1,371 +1,282 @@ -function [axis] = extractAxisData(obj,axis_data,axisName) -%extract information related to each axis -% axis_data is the data extrated from the figure, axisName take the -% values 'x' 'y' or 'z' - - -%-------------------------------------------------------------------------% - -%-axis-side-% -axis.side = eval(['axis_data.' axisName 'AxisLocation;']); - -%-------------------------------------------------------------------------% - -%-axis zeroline-% -axis.zeroline = false; +function [axis, exponentFormat] = extractAxisData(obj,axisData,axisName) + % extract information related to each axis + % axisData is the data extrated from the figure, axisName take the + % values 'x' 'y' or 'z' + + %=========================================================================% + % + % AXIS INITIALIZATION + % + %=========================================================================% + + %-general axis settings-% + axisColor = 255 * eval(sprintf('axisData.%sColor', axisName)); + axisColor = sprintf('rgb(%f,%f,%f)', axisColor); + lineWidth = max(1,axisData.LineWidth*obj.PlotlyDefaults.AxisLineIncreaseFactor); + exponentFormat = eval(sprintf('axisData.%sAxis.Exponent', axisName)); + + axis.side = eval(sprintf('axisData.%sAxisLocation', axisName)); + axis.zeroline = false; + axis.autorange = false; + axis.linecolor = axisColor; + axis.linewidth = lineWidth; + axis.exponentformat = obj.PlotlyDefaults.ExponentFormat; + + %-------------------------------------------------------------------------% + + %-general tick settings-% + tickRotation = eval(sprintf('axisData.%sTickLabelRotation', axisName)); + tickLength = min(obj.PlotlyDefaults.MaxTickLength,... + max(axisData.TickLength(1)*axisData.Position(3)*obj.layout.width,... + axisData.TickLength(1)*axisData.Position(4)*obj.layout.height)); + + axis.tickfont.size = axisData.FontSize; + axis.tickfont.family = matlab2plotlyfont(axisData.FontName); + axis.tickfont.color = axisColor; + + axis.ticklen = tickLength; + axis.tickcolor = axisColor; + axis.tickwidth = lineWidth; + axis.tickangle = -tickRotation; + + switch axisData.TickDir + case 'in' + axis.ticks = 'inside'; + case 'out' + axis.ticks = 'outside'; + end -%-------------------------------------------------------------------------% + %-------------------------------------------------------------------------% -%-axis autorange-% -axis.autorange = false; + %-set axis grid-% -%-------------------------------------------------------------------------% + isGrid = sprintf('axisData.%sGrid', axisName); + isMinorGrid = sprintf('axisData.%sMinorGrid', axisName); -%-axis exponent format-% -axis.exponentformat = obj.PlotlyDefaults.ExponentFormat; + if strcmp(isGrid, 'on') || strcmp(isMinorGrid, 'on') + axis.showgrid = true; + axis.gridwidth = lineWidth; + else + axis.showgrid = false; + end -%-------------------------------------------------------------------------% + %-------------------------------------------------------------------------% -%-axis tick font size-% -axis.tickfont.size = axis_data.FontSize; + %-axis grid color-% + try + gridColor = 255*axisData.GridColor; + gridAlpha = axisData.GridAlpha; + axis.gridcolor = sprintf('rgba(%f,,%f,%f,%f)', gridColor, gridAlpha); + catch + axis.gridcolor = axisColor; + end -%-------------------------------------------------------------------------% + %-------------------------------------------------------------------------% -%-axis tick font family-% -axis.tickfont.family = matlab2plotlyfont(axis_data.FontName); + %-axis type-% + axis.type = eval(sprintf('axisData.%sScale', axisName)); -%-------------------------------------------------------------------------% + %=========================================================================% + % + % SET TICK LABELS + % + %=========================================================================% -ticklength = min(obj.PlotlyDefaults.MaxTickLength,... - max(axis_data.TickLength(1)*axis_data.Position(3)*obj.layout.width,... - axis_data.TickLength(1)*axis_data.Position(4)*obj.layout.height)); -%-axis ticklen-% -axis.ticklen = ticklength; + %-get tick label data-% + tickValues = eval(sprintf('axisData.%sTick', axisName)); + tickLabels = eval(sprintf('axisData.%sTickLabel', axisName)); -%-------------------------------------------------------------------------% + %-------------------------------------------------------------------------% -col = eval(['255*axis_data.' axisName 'Color;']); -axiscol = ['rgb(' num2str(col(1)) ',' num2str(col(2)) ',' num2str(col(3)) ')']; + %-there is not tick label case-% + if isempty(tickValues) && isempty(tickLabels) + + axis.ticks = ''; + axis.showticklabels = false; + axis.autorange = true; + + switch axisData.Box + case 'on' + axis.mirror = true; + case 'off' + axis.mirror = false; + end -%-axis linecolor-% -axis.linecolor = axiscol; -%-axis tickcolor-% -axis.tickcolor = axiscol; -%-axis tickfont-% -axis.tickfont.color = axiscol; + %-------------------------------------------------------------------------% -%-axis grid color-% -try - axis.gridcolor = sprintf('rgba(%f,,%f,%f,%f)', 255*axis_data.GridColor, axis_data.GridAlpha); -catch - axis.gridcolor = axiscol; -end + %-there is tick labels-% + else -%-------------------------------------------------------------------------% + %---------------------------------------------------------------------% -if strcmp(axis_data.XGrid, 'on') || strcmp(axis_data.XMinorGrid, 'on') - %-axis show grid-% - axis.showgrid = true; -else - axis.showgrid = false; -end + %-some tick label settings-% + axisLim = eval( sprintf('axisData.%sLim', axisName) ); -%-------------------------------------------------------------------------% + switch axisData.Box + case 'on' + axis.mirror = 'ticks'; + case 'off' + axis.mirror = false; + end -grid = eval(['axis_data.' axisName 'Grid;']); -minorGrid = eval(['axis_data.' axisName 'MinorGrid;']); + if isnumeric(axisLim) + axis.range = axisLim; + else + axis.autorange = true; + end -if strcmp(grid, 'on') || strcmp(minorGrid, 'on') - %-axis show grid-% - axis.showgrid = true; -else - axis.showgrid = false; -end + axis.showticklabels = true; -%-------------------------------------------------------------------------% - -linewidth = max(1,axis_data.LineWidth*obj.PlotlyDefaults.AxisLineIncreaseFactor); - -%-axis line width-% -axis.linewidth = linewidth; -%-axis tick width-% -axis.tickwidth = linewidth; -%-axis grid width-% -axis.gridwidth = linewidth; - -%-------------------------------------------------------------------------% - -%-axis type-% -axis.type = eval(['axis_data.' axisName 'Scale']); - -%-------------------------------------------------------------------------% - -%-axis showtick labels / ticks-% -tick = eval(['axis_data.' axisName 'Tick']); -if isempty(tick) - - %-axis ticks-% - axis.ticks = ''; - axis.showticklabels = false; - - %-axis autorange-% - axis.autorange = true; - - %---------------------------------------------------------------------% - - switch axis_data.Box - case 'on' - %-axis mirror-% - axis.mirror = true; - case 'off' - axis.mirror = false; - end - - %---------------------------------------------------------------------% + %---------------------------------------------------------------------% -else + %-set tick labels by using tick values and tick texts-% + if ~isempty(tickValues) && ~isempty(tickLabels) - %-get axis limits-% - dataLim = eval( sprintf('axis_data.%sLim', axisName) ); - - %-axis tick direction-% - switch axis_data.TickDir - case 'in' - axis.ticks = 'inside'; - case 'out' - axis.ticks = 'outside'; - end - - %---------------------------------------------------------------------% - switch axis_data.Box - case 'on' - %-axis mirror-% - axis.mirror = 'ticks'; - case 'off' - axis.mirror = false; - end - - %---------------------------------------------------------------------% - - %-LOG TYPE-% - if strcmp(axis.type,'log') - - %-axis range-% - axis.range = eval( sprintf('log10(dataLim)') ); %['log10(axis_data.' axisName 'Lim);']); - %-axis autotick-% - axis.autotick = true; - %-axis nticks-% - axis.nticks = eval(['length(axis_data.' axisName 'Tick) + 1;']); - - %---------------------------------------------------------------------% - - %-LINEAR TYPE-% - elseif strcmp(axis.type,'linear') - - %-----------------------------------------------------------------% - - %-get tick label mode-% - TickLabelMode = eval(['axis_data.' axisName 'TickLabelMode;']); - - %-----------------------------------------------------------------% - - %-AUTO MODE-% - if strcmp(TickLabelMode,'auto') - - %-------------------------------------------------------------% - - if isnumeric(dataLim) - % axis.title = 'axis'; - axis.range = dataLim; - - %-------------------------------------------------------------% - elseif isduration(dataLim) - [temp,type] = convertDuration(dataLim); - - if (~isduration(temp)) - axis.range = temp; - axis.type = 'duration'; - axis.title = type; - else - nticks = eval(['length(axis_data.' axisName 'Tick)-1;']); - delta = 0.1; - axis.range = [-delta nticks+delta]; - axis.type = 'duration - specified format'; - end - - %-------------------------------------------------------------% - - elseif isdatetime(dataLim) - axis.range = convertDate(dataLim); - axis.type = 'date'; - else - % data is a category type other then duration and datetime - end - - %-axis autotick-% - axis.autotick = true; - %-axis numticks-% - axis.nticks = eval(['length(axis_data.' axisName 'Tick)+1']); - - %-----------------------------------------------------------------% - - %-CUSTOM MODE-% - else + axis.tickmode = 'array'; + axis.tickvals = tickValues; + axis.ticktext = tickLabels; - %-------------------------------------------------------------% + %---------------------------------------------------------------------% - %-get tick labels-% - tickLabels = eval(['axis_data.' axisName 'TickLabel;']); + %-set tick labels by using only tick values-% + elseif ~isempty(tickValues) && isempty(tickLabels) - %-------------------------------------------------------------% + axis.showticklabels = true; + axis.tickmode = 'array'; + axis.tickvals = tickValues; - %-hide tick labels as lichkLabels field is empty-% - if isempty(tickLabels) - - %-------------------------------------------------------------% + %+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++% + % + % TODO: determine if following code piece is necessary. For this we need + % to test fig2plotly with more examples + % + %+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++% - %-hide tick labels-% - axis.showticklabels = false; + % %-LOG TYPE-% + % if strcmp(axis.type,'log') - %-------------------------------------------------------------% + % axis.range = log10(axisLim); + % axis.autotick = true; + % axis.nticks = eval(['length(axisData.' axisName 'Tick) + 1;']); - %-axis autorange-% - axis.autorange = true; + % %---------------------------------------------------------------------% - %-------------------------------------------------------------% + % %-LINEAR TYPE-% + % elseif strcmp(axis.type,'linear') - %-axis show tick labels as tickLabels matlab field-% - else + % %-----------------------------------------------------------------% - %-------------------------------------------------------------% + % % %-get tick label mode-% + % % tickLabelMode = eval(['axisData.' axisName 'TickLabelMode;']); - axis.showticklabels = true; - axis.type = 'linear'; + % % %-----------------------------------------------------------------% - %-------------------------------------------------------------% + % % %-AUTO MODE-% + % % if strcmp(tickLabelMode,'auto') - if isnumeric(dataLim) - axis.range = eval(['axis_data.' axisName 'Lim;']); - else - axis.autorange = true; - end + % %-------------------------------------------------------------% + + % if isnumeric(axisLim) + % %-axis range-% + % axis.range = axisLim; + % %-axis tickvals-% + % axis.tickvals = tick; + + % %-------------------------------------------------------------% + + % elseif isduration(axisLim) + % [temp,type] = convertDuration(axisLim); + + % if (~isduration(temp)) + % axis.range = temp; + % axis.type = 'duration'; + % axis.title = type; + % else + % nticks = eval(['length(axisData.' axisName 'Tick)-1;']); + % delta = 0.1; + % axis.range = [-delta nticks+delta]; + % axis.type = 'duration - specified format'; + % end + + % %-------------------------------------------------------------% - %-------------------------------------------------------------% - - axis.tickvals = tick; - axis.ticktext = tickLabels; - - %-------------------------------------------------------------% - - %+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++% - % NOTE: - % The next piece of code was replaced by the previous one. - % I think that the new piece of code is better, optimal and - % extends to all cases. However, I will leave this piece of - % code commented in case there is a problem in the future. - % - % If there is a problem with the new piece of code, please - % comment and uncomment the next piece of code. - % - % If everything goes well with the new gripping piece, at - % the end of the development we will be able to remove the - % commented lines - %+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++% - - %-axis labels - % labels = str2double(tickLabels); - % try - % %find numbers in labels - % labelnums = find(~isnan(labels)); - % %-axis type linear-% - % axis.type = 'linear'; - % %-range (overwrite)-% - % delta = (labels(labelnums(2)) - labels(labelnums(1)))/(labelnums(2)-labelnums(1)); - % axis.range = [labels(labelnums(1))-delta*(labelnums(1)-1) labels(labelnums(1)) + (length(labels)-labelnums(1))*delta]; - % %-axis autotick-% - % axis.autotick = true; - % %-axis numticks-% - % axis.nticks = eval(['length(axis_data.' axisName 'Tick) + 1;']); - % catch - % %-axis type category-% - % axis.type = 'category'; - % %-range (overwrite)-% - % axis.autorange = true; - % %-axis autotick-% - % % axis.autotick = true; - % end - end + % elseif isdatetime(axisLim) + % axis.range = convertDate(axisLim); + % axis.type = 'date'; + % else + % % data is a category type other then duration and datetime + % end + + % %-------------------------------------------------------------% + + % if ~isnumeric(axisLim) + % %-axis autotick-% + % axis.autotick = true; + % %-axis numticks-% + % axis.nticks = eval(['length(axisData.' axisName 'Tick)+1']); + % end + % end + % end + + %+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++% + end end -end - -%-------------------------------------------------------------------------% - -Dir = eval(['axis_data.' axisName 'Dir;']); -if strcmp(Dir,'reverse') - axis.range = [axis.range(2) axis.range(1)]; -end - -%-------------------------------LABELS------------------------------------% -label = eval(['axis_data.' axisName 'Label;']); + %-------------------------------------------------------------------------% -label_data = get(label); + %-axis direction-% + axisDirection = eval(sprintf('axisData.%sDir', axisName)); -%STANDARDIZE UNITS -fontunits = get(label,'FontUnits'); -set(label,'FontUnits','points'); - -%-------------------------------------------------------------------------% + if strcmp(axisDirection,'reverse') + axis.range = [axis.range(2) axis.range(1)]; + end -%-title-% -if ~isempty(label_data.String) - axis.title = parseString(label_data.String,label_data.Interpreter); -end + %=========================================================================% + % + % SET AXIS LABEL + % + %=========================================================================% -%-------------------------------------------------------------------------% + %-get label data-% + label = eval(sprintf('axisData.%sLabel', axisName)); + labelData = get(label); -%-axis title font color-% -col = 255*label_data.Color; -axis.titlefont.color = ['rgb(' num2str(col(1)) ',' num2str(col(2)) ',' num2str(col(3)) ')']; + %-------------------------------------------------------------------------% -%-------------------------------------------------------------------------% + %-STANDARDIZE UNITS-% + fontunits = get(label,'FontUnits'); + set(label,'FontUnits','points'); -%-axis title font size-% -axis.titlefont.size = label_data.FontSize; + %-------------------------------------------------------------------------% -%-------------------------------------------------------------------------% + %-title label settings-% + if ~isempty(labelData.String) + axis.title = parseString(labelData.String,labelData.Interpreter); + end -%-axis title font family-% -axis.titlefont.family = matlab2plotlyfont(label_data.FontName); + axis.titlefont.color = sprintf('rgb(%f,%f,%f)', 255*labelData.Color); + axis.titlefont.size = labelData.FontSize; + axis.titlefont.family = matlab2plotlyfont(labelData.FontName); -%-------------------------------------------------------------------------% + %-------------------------------------------------------------------------% -%REVERT UNITS -set(label,'FontUnits',fontunits); + %-REVERT UNITS-% + set(label,'FontUnits',fontunits); -%-------------------------------------------------------------------------% + %-------------------------------------------------------------------------% -if strcmp(axis_data.Visible,'on') - %-axis showline-% - axis.showline = true; -else - %-axis showline-% - axis.showline = false; - %-axis showticklabels-% - axis.showticklabels = false; - %-axis ticks-% - axis.ticks = ''; - %-axis showline-% - axis.showline = false; - %-axis showticklabels-% - axis.showticklabels = false; - %-axis ticks-% - axis.ticks = ''; -end + %-set visibility conditions-% + if strcmp(axisData.Visible,'on') + axis.showline = true; + else + axis.showticklabels = false; + axis.showline = false; + axis.ticks = ''; + end -%-------------------------------------------------------------------------% + %-------------------------------------------------------------------------% end diff --git a/plotly/plotlyfig_aux/helpers/findColorbarAxis.m b/plotly/plotlyfig_aux/helpers/findColorbarAxis.m index 23c7d6e2..f58f8b21 100644 --- a/plotly/plotlyfig_aux/helpers/findColorbarAxis.m +++ b/plotly/plotlyfig_aux/helpers/findColorbarAxis.m @@ -1,14 +1,23 @@ function colorbarAxis = findColorbarAxis(obj,colorbarHandle) -if isHG2 - colorbarAxisIndex = find(arrayfun(@(x)(isequal(getappdata(x.Handle,'ColorbarPeerHandle'),colorbarHandle)),obj.State.Axis)); - % If the above returns empty then we are on a more recent Matlab - % release where the appdata entry is called LayoutPeers - if isempty(colorbarAxisIndex) - colorbarAxisIndex = find(arrayfun(@(x)(isequal(getappdata(x.Handle,'LayoutPeers'),colorbarHandle)),obj.State.Axis)); + + if isHG2 + colorbarAxisIndex = find(arrayfun(@(x)(isequal(getappdata(x.Handle,'ColorbarPeerHandle'),colorbarHandle)),obj.State.Axis)); + + % If the above returns empty then we are on a more recent Matlab + % release where the appdata entry is called LayoutPeers + if isempty(colorbarAxisIndex) + colorbarAxisIndex = find(arrayfun(@(x)(isequal(getappdata(x.Handle,'LayoutPeers'),colorbarHandle)),obj.State.Axis)); + end + + else + colorbarAxisIndex = find(arrayfun(@(x)(isequal(getappdata(x.Handle,'LegendColorbarInnerList'),colorbarHandle) + ... + isequal(getappdata(x.Handle,'LegendColorbarOuterList'),colorbarHandle)),obj.State.Axis)); end -else - colorbarAxisIndex = find(arrayfun(@(x)(isequal(getappdata(x.Handle,'LegendColorbarInnerList'),colorbarHandle) + ... - isequal(getappdata(x.Handle,'LegendColorbarOuterList'),colorbarHandle)),obj.State.Axis)); -end -colorbarAxis = obj.State.Axis(colorbarAxisIndex).Handle; + + try + colorbarAxis = obj.State.Axis(colorbarAxisIndex).Handle; + catch + colorbarAxis = 1; + end + end diff --git a/plotly/plotlyfig_aux/helpers/findColorbarData.m b/plotly/plotlyfig_aux/helpers/findColorbarData.m index c582bf88..19d89333 100644 --- a/plotly/plotlyfig_aux/helpers/findColorbarData.m +++ b/plotly/plotlyfig_aux/helpers/findColorbarData.m @@ -1,8 +1,39 @@ -function colorbarDataIndex = findColorbarData(obj,colorbarIndex) -%locate index of data associated with colorbar -colorbarDataIndex = find(arrayfun(@(x)eq(x.AssociatedAxis,obj.State.Colorbar(colorbarIndex).AssociatedAxis),obj.State.Plot),1); -%if no matching data index found -if isempty(colorbarDataIndex) - colorbarDataIndex = max(min(colorbarIndex,obj.State.Figure.NumPlots),1); -end +function colorbarDataIndex = findColorbarData(obj, colorbarIndex, colorbarData) + + if nargin == 2 + + %locate index of data associated with colorbar + colorbarDataIndex = find( ... + arrayfun( @(x)eq(x.AssociatedAxis, ... + obj.State.Colorbar(colorbarIndex).AssociatedAxis), ... + obj.State.Plot ... + ), ... + 1 ); + + %if no matching data index found + if isempty(colorbarDataIndex) + colorbarDataIndex = max(min(colorbarIndex,obj.State.Figure.NumPlots),1); + end + + elseif nargin == 3 + c = 1; a = 1; + allAxesIndex = zeros(length(colorbarData.Parent.Children), 1); + + for n = 1:length(colorbarData.Parent.Children) + if strcmp(colorbarData.Parent.Children(n).Type, 'colorbar') + allColorbarIndex(c) = n; + c = c + 1; + elseif strcmp(colorbarData.Parent.Children(n).Type, 'axes') + allAxesIndex(n) = a; + a = a + 1; + end + end + + colorbarAxisIndex = allColorbarIndex(colorbarIndex) + 1; + colorbarAxisIndex = allAxesIndex(colorbarAxisIndex); + colorbarDataIndex = obj.State.Figure.NumAxes - colorbarAxisIndex + 1; + + colorbarDataIndex = colorbarDataIndex; + end + end \ No newline at end of file