diff --git a/plotly/plotlyfig.m b/plotly/plotlyfig.m index 03e47f27..2a434006 100644 --- a/plotly/plotlyfig.m +++ b/plotly/plotlyfig.m @@ -714,7 +714,7 @@ function validate(obj) end % update plots - obj.PlotOptions.nplots = obj.State.Figure.NumPlots; + obj.PlotOptions.nPlots = obj.State.Figure.NumPlots; for n = 1:obj.State.Figure.NumPlots updateData(obj,n); @@ -1051,7 +1051,7 @@ function delete(obj) || strcmpi(fieldname,'heatmap') || strcmpi(fieldname,'xaxis') ... || strcmpi(fieldname,'yaxis') || strcmpi(fieldname,'cone')... || strcmpi(fieldname,'legend') || strcmpi(fieldname,'histogram')... - || strcmpi(fieldname,'scatter')... + || strcmpi(fieldname,'scatter') || strcmpi(fieldname,'line')... ) fprintf(['\nWhoops! ' exception.message(1:end-1) ' in ' fieldname '\n\n']); end diff --git a/plotly/plotlyfig_aux/core/updateData.m b/plotly/plotlyfig_aux/core/updateData.m index 7d9fe029..f50bbb89 100644 --- a/plotly/plotlyfig_aux/core/updateData.m +++ b/plotly/plotlyfig_aux/core/updateData.m @@ -29,6 +29,8 @@ updateBar3h(obj, dataIndex); elseif strcmpi(obj.PlotOptions.TreatAs, 'surf') updateSurf(obj, dataIndex); + elseif strcmpi(obj.PlotOptions.TreatAs, 'fmesh') + updateFmesh(obj, dataIndex); % this one will be revomed elseif strcmpi(obj.PlotOptions.TreatAs, 'streamtube') diff --git a/plotly/plotlyfig_aux/handlegraphics/updateFmesh.m b/plotly/plotlyfig_aux/handlegraphics/updateFmesh.m new file mode 100644 index 00000000..2cbd9fc9 --- /dev/null +++ b/plotly/plotlyfig_aux/handlegraphics/updateFmesh.m @@ -0,0 +1,293 @@ +function obj = updateFmesh(obj, surfaceIndex) + +%-AXIS INDEX-% +axIndex = obj.getAxisIndex(obj.State.Plot(surfaceIndex).AssociatedAxis); + +%-CHECK FOR MULTIPLE AXES-% +[xsource, ysource] = findSourceAxis(obj,axIndex); + +%-SURFACE DATA STRUCTURE- % +meshData = get(obj.State.Plot(surfaceIndex).Handle); +figureData = get(obj.State.Figure.Handle); + +%-AXIS STRUCTURE-% +axisData = get(ancestor(meshData.Parent,'axes')); + +%-SCENE DATA-% +eval( sprintf('scene = obj.layout.scene%d;', xsource) ); + +%-GET CONTOUR INDEX-% +obj.PlotOptions.nPlots = obj.PlotOptions.nPlots + 1; +contourIndex = obj.PlotOptions.nPlots; + +%-------------------------------------------------------------------------% + +%-associate scene-% +obj.data{surfaceIndex}.scene = sprintf('scene%d', xsource); +obj.data{contourIndex}.scene = sprintf('scene%d', xsource); + +%-------------------------------------------------------------------------% + +%-surface type for face color-% +obj.data{surfaceIndex}.type = 'surface'; + +%-scatter3d type for contour mesh lines-% +obj.data{contourIndex}.type = 'scatter3d'; +obj.data{contourIndex}.mode = 'lines'; + +%-------------------------------------------------------------------------% + +%-get plot data-% +meshDensity = meshData.MeshDensity; +xData = meshData.XData(1:meshDensity^2); +yData = meshData.YData(1:meshDensity^2); +zData = meshData.ZData(1:meshDensity^2); + +%-reformat data to mesh-% +xDataSurface = reshape(xData, [meshDensity, meshDensity])'; +yDataSurface = reshape(yData, [meshDensity, meshDensity])'; +zDataSurface = reshape(zData, [meshDensity, meshDensity])'; + +xDataContour = [xDataSurface; NaN(1, size(xDataSurface, 2))]; +yDataContour = [yDataSurface; NaN(1, size(yDataSurface, 2))]; +zDataContour = [zDataSurface; NaN(1, size(zDataSurface, 2))]; + +xDataContour = [xDataContour; xDataContour(1:end-1,:)']; +yDataContour = [yDataContour; yDataContour(1:end-1,:)']; +zDataContour = [zDataContour; zDataContour(1:end-1,:)']; + +xDataContour = [xDataContour; NaN(1, size(xDataContour, 2))]; +yDataContour = [yDataContour; NaN(1, size(yDataContour, 2))]; +zDataContour = [zDataContour; NaN(1, size(zDataContour, 2))]; + +%-------------------------------------------------------------------------% + +%-set data on surface-% +obj.data{surfaceIndex}.x = xDataSurface; +obj.data{surfaceIndex}.y = yDataSurface; +obj.data{surfaceIndex}.z = zDataSurface; + +%-------------------------------------------------------------------------% + +%-set data on scatter3d-% +obj.data{contourIndex}.x = xDataContour(:); +obj.data{contourIndex}.y = yDataContour(:); +obj.data{contourIndex}.z = zDataContour(:); + +%-------------------------------------------------------------------------% + +%-COLORING-% + +%-------------------------------------------------------------------------% + +%-get colormap-% +cMap = figureData.Colormap; +fac = 1/(length(cMap)-1); +colorScale = {}; + +for c = 1: length(cMap) + colorScale{c} = { (c-1)*fac , sprintf('rgb(%f,%f,%f)', 255*cMap(c, :))}; +end + +%-------------------------------------------------------------------------% + +%-get edge color-% +if isnumeric(meshData.EdgeColor) + cDataContour = sprintf('rgb(%f,%f,%f)', 255*meshData.EdgeColor); + +elseif strcmpi(meshData.EdgeColor, 'interp') + cDataContour = zDataContour(:); + obj.data{contourIndex}.line.colorscale = colorScale; +end + +%-set edge color-% +obj.data{contourIndex}.line.color = cDataContour; + +%-------------------------------------------------------------------------% + +%-get face color-% +if isnumeric(meshData.FaceColor) + + for n = 1:size(zDataSurface, 2) + for m = 1:size(zDataSurface, 1) + cDataSurface(m, n, :) = meshData.FaceColor; + end + end + + [cDataSurface, cMapSurface] = rgb2ind(cDataSurface, 256); + + for c = 1: size(cMapSurface, 1) + colorScale{c} = { (c-1)*fac , sprintf('rgba(%f,%f,%f, 1)', cMapSurface(c, :))}; + end + + obj.data{surfaceIndex}.cmin = 0; + obj.data{surfaceIndex}.cmax = 255; + +elseif strcmpi(meshData.FaseColor, 'interp') + cDataSurface = zDataSurface; +end + +%-set face color-% +obj.data{surfaceIndex}.colorscale = colorScale; +obj.data{surfaceIndex}.surfacecolor = cDataSurface; + +%-lighting settings-% +obj.data{surfaceIndex}.lighting.diffuse = 0.5;%0.5; +obj.data{surfaceIndex}.lighting.ambient = 0.725 + (1-meshData.FaceAlpha);%0.7; + +%-opacity-% +obj.data{surfaceIndex}.opacity = meshData.FaceAlpha; + +%-------------------------------------------------------------------------% + +%-line style-% + +obj.data{contourIndex}.line.width = 3*meshData.LineWidth; + +switch meshData.LineStyle + case '-' + obj.data{contourIndex}.line.dash = 'solid'; + case '--' + obj.data{contourIndex}.line.dash = 'dash'; + case '-.' + obj.data{contourIndex}.line.dash = 'dashdot'; + case ':' + obj.data{contourIndex}.line.dash = 'dot'; +end + +%-------------------------------------------------------------------------% + +%-SCENE CONFIGUTATION-% + +%-------------------------------------------------------------------------% + +%-aspect ratio-% +asr = obj.PlotOptions.AspectRatio; + +if ~isempty(asr) + if ischar(asr) + scene.aspectmode = asr; + elseif isvector(ar) && length(asr) == 3 + xar = asr(1); + yar = asr(2); + zar = asr(3); + end +else + + %-define as default-% + xar = max(xData(:)); + yar = max(yData(:)); + xyar = max([xar, yar]); + zar = 0.75*xyar; +end + +scene.aspectratio.x = 1.1*xyar; +scene.aspectratio.y = 1.0*xyar; +scene.aspectratio.z = zar; + +%---------------------------------------------------------------------% + +%-camera eye-% +ey = obj.PlotOptions.CameraEye; + +if ~isempty(ey) + if isvector(ey) && length(ey) == 3 + scene.camera.eye.x = ey(1); + scene.camera.eye.y = ey(2); + scene.camera.eye.z = ey(3); + end +else + + %-define as default-% + xey = - xyar; if xey>0 xfac = 0.0; else xfac = 0.0; end + yey = - xyar; if yey>0 yfac = -0.3; else yfac = 0.3; end + if zar>0 zfac = 0.2; else zfac = -0.2; end + + scene.camera.eye.x = xey + xfac*xey; + scene.camera.eye.y = yey + yfac*yey; + scene.camera.eye.z = zar + zfac*zar; +end + +%-------------------------------------------------------------------------% + +%-scene axis configuration-% + +scene.xaxis.range = axisData.XLim; +scene.yaxis.range = axisData.YLim; +scene.zaxis.range = axisData.ZLim; + +scene.xaxis.tickvals = axisData.XTick; +scene.xaxis.ticktext = axisData.XTickLabel; + +scene.yaxis.tickvals = axisData.YTick; +scene.yaxis.ticktext = axisData.YTickLabel; + +scene.zaxis.tickvals = axisData.ZTick; +scene.zaxis.ticktext = axisData.ZTickLabel; + +scene.xaxis.zeroline = false; +scene.yaxis.zeroline = false; +scene.zaxis.zeroline = false; + +scene.xaxis.showline = true; +scene.yaxis.showline = true; +scene.zaxis.showline = true; + +scene.xaxis.tickcolor = 'rgba(0,0,0,1)'; +scene.yaxis.tickcolor = 'rgba(0,0,0,1)'; +scene.zaxis.tickcolor = 'rgba(0,0,0,1)'; + +scene.xaxis.ticklabelposition = 'outside'; +scene.yaxis.ticklabelposition = 'outside'; +scene.zaxis.ticklabelposition = 'outside'; + +scene.xaxis.title = axisData.XLabel.String; +scene.yaxis.title = axisData.YLabel.String; +scene.zaxis.title = axisData.ZLabel.String; + +scene.xaxis.tickfont.size = axisData.FontSize; +scene.yaxis.tickfont.size = axisData.FontSize; +scene.zaxis.tickfont.size = axisData.FontSize; + +scene.xaxis.tickfont.family = matlab2plotlyfont(axisData.FontName); +scene.yaxis.tickfont.family = matlab2plotlyfont(axisData.FontName); +scene.zaxis.tickfont.family = matlab2plotlyfont(axisData.FontName); + +%-------------------------------------------------------------------------% + +%-SET SCENE TO LAYOUT-% +obj.layout = setfield(obj.layout, sprintf('scene%d', xsource), scene); + +%-------------------------------------------------------------------------% + +%-surface name-% +obj.data{contourIndex}.name = meshData.DisplayName; + +%-------------------------------------------------------------------------% + +%-surface showscale-% +obj.data{surfaceIndex}.showscale = false; +obj.data{contourIndex}.showscale = false; + +%-------------------------------------------------------------------------% + +%-surface visible-% +obj.data{contourIndex}.visible = strcmp(meshData.Visible,'on'); + +%-------------------------------------------------------------------------% + +leg = get(meshData.Annotation); +legInfo = get(leg.LegendInformation); + +switch legInfo.IconDisplayStyle + case 'on' + showleg = true; + case 'off' + showleg = false; +end + +obj.data{contourIndex}.showlegend = showleg; + +%-------------------------------------------------------------------------% + +end