/code/plot2svg.m
https://github.com/hananel/piggottDesignCode · Objective C · 3079 lines · 3032 code · 47 blank · 0 comment · 588 complexity · d8b3bad0a49ffca9f1c0f150d16951b8 MD5 · raw file
Large files are truncated click here to view the full file
- function varargout = plot2svg(param1,id,pixelfiletype)
- % Matlab to SVG converter
- % Prelinary version supporting 3D plots as well
- %
- % Usage: plot2svg(filename,graphic handle,pixelfiletype)
- % optional optional optional
- % or
- %
- % plot2svg(figuresize,graphic handle,pixelfiletype)
- % optional optional optional
- %
- % pixelfiletype = 'png' (default), 'jpg'
- %
- % Juerg Schwizer 23-Oct-2005
- % See http://www.zhinst.com/blogs/schwizer/ to get more informations
- %
- % 07.06.2005 - Bugfix axxindex (Index exceeds matrix dimensions)
- % 19.09.2005 - Added possibility to select output format of pixel graphics
- % 23.10.2005 - Bugfix cell array strings (added by Bill)
- % Handling of 'hggroups' and improved grouping of objects
- % Improved handling of pixel images (indexed and true color pictures)
- % 23.10.2005 - Switched default pixelfromat to 'png'
- % 07.11.2005 - Added handling of hidden axes for annotations (added by Bill)
- % 03.12.2005 - Bugfix of viewBox to make Firefox 1.5 working
- % 04.12.2005 - Improved handling of exponent values for log-plots
- % Improved markers
- % 09.12.2005 - Bugfix '<' '>' '?' '"'
- % 22.12.2005 - Implementation of preliminary 3D version
- % Clipping
- % Minor tick marks
- % 22.01.2005 - Removed unused 'end'
- % 29.10.2006 - Bugfix '°','ą','ľ','˛','ł','ź''˝','ž','Š''Ž'
- % 17-04-2007 - Bugfix 'projection' in hggroup and hgtransform
- % 27-01-2008 - Added Octave functionality (thanks to Jakob Malm)
- % Bugfixe cdatamapping (thanks to Tom)
- % Bugfix image data writing (thanks to Tom)
- % Patches includes now markers as well (needed for 'scatter'
- % plots (thanks to Phil)
- % 04-02-2008 - Bugfix markers for Octave (thanks to Jakob Malm)
- % 30-12-2008 - Bugfix image scaling and orientation
- % Bugfix correct backslash (thanks to Jason Merril)
- % 20-06-2009 - Improvment of image handling (still some remaining issues)
- % Fix for -. line style (thanks to Ritesh Sood)
- % 28-06-2009 - Improved depth sorting for patches and surface
- % - Bugfix patches
- % - Bugfix 3D axis handling
- % 11-07-2009 - Support of FontWeight and FontAngle properties
- % - Improved markers (polygon instead of polyline for closed markers)
- % - Added character encoding entry to be fully SVG 1.1 conform
- % 13-07-2009 - Support of rectangle for 2D
- % - Added preliminary support for SVG filters
- % - Added preliminary support for clipping with pathes
- % - Added preliminary support for turning axis tickmarks
- % 18-07-2009 - Line style scaling with line width (will not match with png
- % output)
- % - Small optimizations for the text base line
- % - Bugfix text rotation versus shift
- % - Added more SVG filters
- % - Added checks for filter strings
- % 21-07-2009 - Improved bounding box calculation for filters
- % - Bugfixes for text size / line distance
- % - Support of background box for text
- % - Correct bounding box for text objects
- % 31-07-2009 - Improved support of filters
- % - Experimental support of animations
- % 16-08-2009 - Argument checks for filters
- % - Rework of latex string handling
- % - 'sub' and 'super' workaround for Firefox and Inkscape
- % 31-10-2009 - Bugfix for log axes (missing minor grid for some special
- % cases)
- % 24-01-2010 - Bugfix nomy line #1102 (thanks to Pooya Jannaty)
- % 17-02-2010 - Bugfix minor tickmarks for log axis scaling (thanks to
- % Harke Pera)
- % - Added more lex symbols
- % 06-03-2010 - Automatic correction of illegal axis scalings by the user
- % (thanks to Juergen)
- % - Renamed plot2svg_beta to plot2svg
- % 12-04-2010 - Improved Octave compatibility
- % 05-05-2010 - Bugfix for ticklabels outside of the axis limits (thanks to
- % Ben Scandella)
- % 30-10-2010 - Improved handling of empty cells for labels (thanks to
- % Constantine)
- % - Improved HTML character coding (thanks to David Mack)
- % - Bugfix for last ')' (thanks to Jonathon Harding and Benjamin)
- % - Enabled scatter plots using hggroups
- % - Closing patches if they do not contain NaNs
- % 10-11-2010 - Support of the 'Layer' keyword to but the grid on top of
- % of the other axis content using 'top' (Many thanks to Justin
- % Ashmall)
- % - Tiny optimization of the grid display at axis borders
- global PLOT2SVG_globals
- global colorname
- progversion='10-Nov-2010';
- PLOT2SVG_globals.runningIdNumber = 0;
- PLOT2SVG_globals.octave = false;
- PLOT2SVG_globals.checkUserData = true;
- if nargout==1
- varargout={0};
- end
- disp([' Matlab/Octave to SVG converter version ' progversion ', Juerg Schwizer (converter@bluewin.ch).'])
- matversion=version;
- if exist('OCTAVE_VERSION','builtin')
- PLOT2SVG_globals.octave = true;
- disp(' Info: PLOT2SVG runs in Octave mode.')
- else
- if str2num(matversion(1))<6 % Check for matlab version and print warning if matlab version lower than version 6.0 (R.12)
- disp(' Warning: Future versions may no more support older versions than MATLAB R12.')
- end
- end
- if nargout > 1
- error('Function returns only one return value.')
- end
- if nargin<2 % Check if handle was included into function call, otherwise take current figure
- id=gcf;
- end
- if nargin==0
- if PLOT2SVG_globals.octave
- error('PLOT2SVG in Octave mode does not yet support a file menu. File name is needed during function call.')
- else
- [filename, pathname] = uiputfile( {'*.svg', 'SVG File (*.svg)'},'Save Figure as SVG File');
- if ~( isequal( filename, 0) || isequal( pathname, 0))
- % yes. add backslash to path (if not already there)
- pathname = addBackSlash( pathname);
- % check, if extension is allrigth
- if ( ~strcmpi( getFileExtension( filename), '.svg'))
- filename = [ filename, '.svg'];
- end
- finalname=[pathname filename];
- else
- disp(' Cancel button was pressed.')
- return
- end
- end
- else
- if isnumeric(param1)
- if PLOT2SVG_globals.octave
- error('PLOT2SVG in Octave mode does not yet support a file menu. File name is needed during function call.')
- else
- [filename, pathname] = uiputfile( {'*.svg', 'SVG File (*.svg)'},'Save Figure as SVG File');
- if ~( isequal( filename, 0) || isequal( pathname, 0))
- % yes. add backslash to path (if not already there)
- pathname = addBackSlash( pathname);
- % check, if ectension is allrigth
- if ( ~strcmpi( getFileExtension( filename), '.svg'))
- filename = [ filename, '.svg'];
- end
- finalname=[pathname filename];
- else
- disp(' Cancel button was pressed.')
- return
- end
- end
- else
- finalname=param1;
- end
- end
- % needed to see annotation axes
- originalShowHiddenHandles = get(0, 'ShowHiddenHandles');
- set(0, 'ShowHiddenHandles', 'on');
- originalFigureUnits=get(id,'Units');
- set(id,'Units','pixels'); % All data in the svg-file is saved in pixels
- paperpos=get(id,'Position');
- if ( nargin > 0)
- if isnumeric(param1)
- paperpos(3)=param1(1);
- paperpos(4)=param1(2);
- end
- end
- if (nargin < 3)
- PLOT2SVG_globals.pixelfiletype = 'png';
- else
- PLOT2SVG_globals.pixelfiletype = pixelfiletype;
- end
- cmap=get(id,'Colormap');
- colorname='';
- for i=1:size(cmap,1)
- colorname(i,:)=sprintf('%02x%02x%02x',fix(cmap(i,1)*255),fix(cmap(i,2)*255),fix(cmap(i,3)*255));
- end
- % Open SVG-file
- [pathstr,name,ext,versn] = fileparts(finalname);
- %PLOT2SVG_globals.basefilename = fullfile(pathstr,name);
- PLOT2SVG_globals.basefilepath = pathstr;
- PLOT2SVG_globals.basefilename = name;
- PLOT2SVG_globals.figurenumber = 1;
- fid=fopen(finalname,'wt'); % Create a new text file
- fprintf(fid,'<?xml version="1.0" encoding="utf-8" standalone="no"?><!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">\n'); % Insert file header
- fprintf(fid,'<svg preserveAspectRatio="xMinYMin meet" width="100%%" height="100%%" viewBox="0 0 %0.3f %0.3f" ',paperpos(3),paperpos(4));
- fprintf(fid,' version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"');
- %fprintf(fid,' onload="Init(evt)"');
- fprintf(fid,'>\n');
- fprintf(fid,' <desc>Matlab Figure Converted by PLOT2SVG written by Juerg Schwizer</desc>\n');
- %fprintf(fid,' <script type="text/ecmascript" xlink:href="puzzle_script.js" />\n');
- fprintf(fid,' <g id="topgroup">\n');
- group=1;
- groups=[];
- axfound=0;
- % Frame of figure
- figcolor = searchcolor(id,get(id, 'Color'));
- if (~ strcmp(figcolor, 'none'))
- % Draw rectangle in the background of the graphic frame to cover all
- % other graphic elements
- try % Octave does not have support for InvertHardcopy yet -- Jakob Malm
- if strcmp(get(id,'InvertHardcopy'),'on')
- fprintf(fid,' <rect x="0" y="0" width="%0.3f" height="%0.3f" fill="#ffffff" stroke="none" />\n',paperpos(3),paperpos(4));
- else
- fprintf(fid,' <rect x="0" y="0" width="%0.3f" height="%0.3f" fill="%s" stroke="none" />\n',paperpos(3),paperpos(4),figcolor);
- end
- catch
- fprintf(fid,' <rect x="0" y="0" width="%0.3f" height="%0.3f" fill="%s" stroke="none" />\n',paperpos(3),paperpos(4),figcolor);
- end
- end
- % Search all axes
- ax=get(id,'Children');
- for j=length(ax):-1:1
- currenttype = get(ax(j),'Type');
- if strcmp(currenttype,'axes')
- group=group+1;
- groups=[groups group];
- group=axes2svg(fid,id,ax(j),group,paperpos);
- axfound=1;
- elseif strcmp(currenttype,'uicontrol')
- if strcmp(get(ax(j),'Visible'),'on')
- control2svg(fid,id,ax(j),group,paperpos);
- axfound=1;
- end
- elseif strcmp(currenttype, 'uicontextmenu') || ...
- strcmp(currenttype, 'uimenu') || ...
- strcmp(currenttype, 'hgjavacomponent') || ...
- strcmp(currenttype, 'uitoolbar')
- % ignore these types
- else
- disp([' Warning: Unhandled main figure child type: ' currenttype]);
- end
- end
- fprintf(fid,' </g>\n');
- fprintf(fid,'</svg>\n');
- fclose(fid); % close text file
- if nargout==1
- varargout={0};
- end
- set(id,'Units',originalFigureUnits);
- set(0, 'ShowHiddenHandles', originalShowHiddenHandles);
- function clippingIdString = clipping2svg(fid, id, ax, paperpos, axpos, projection, clippingIdString)
- global PLOT2SVG_globals
- if PLOT2SVG_globals.checkUserData && isstruct(get(id,'UserData'))
- struct_data = get(id,'UserData');
- if isfield(struct_data,'svg')
- if isfield(struct_data.svg,'ClippingPath')
- clip = struct_data.svg.ClippingPath;
- if ~isempty(clip)
- if size(clip, 2) ~=3
- if size(clip, 2) ==2
- clipx = clip(:, 1);
- clipy = clip(:, 2);
- clipz = zeros(size(clip,1),1);
- else
- error('The clipping vector has to be a nx3 or nx2 matrix.');
- end
- else
- clipx = clip(:, 1);
- clipy = clip(:, 2);
- clipz = clip(:, 3);
- end
- if strcmp(get(ax,'XScale'),'log')
- clipx(find(clipx<=0)) = NaN;
- clipx=log10(clipx);
- end
- if strcmp(get(ax,'YScale'),'log')
- clipy(find(clipy<=0)) = NaN;
- clipy=log10(clipy);
- end
- if strcmp(get(ax,'ZScale'),'log')
- clipz(find(clipz<=0)) = NaN;
- clipz=log10(clipz);
- end
- [x,y,z] = project(clipx,clipy,clipz,projection);
- x = (x*axpos(3)+axpos(1))*paperpos(3);
- y = (1-(y*axpos(4)+axpos(2)))*paperpos(4);
- clippingIdString = createId;
- fprintf(fid,'<clipPath id="%s">\n <polygon fill="none" stroke="none" points="', clippingIdString);
- fprintf(fid,'%0.3f,%0.3f ',[x';y']);
- fprintf(fid,'"/>\n</clipPath>\n');
- end
- end
- end
- end
- function [angle, align] = improvedXLabel(id, angle, align)
- global PLOT2SVG_globals
- if PLOT2SVG_globals.checkUserData && isstruct(get(id,'UserData'))
- struct_data = get(id,'UserData');
- if isfield(struct_data,'svg')
- if isfield(struct_data.svg,'XTickLabelAngle')
- angle = struct_data.svg.XTickLabelAngle;
- align = 'Left';
- end
- end
- end
- function [angle, align] = improvedYLabel(id, angle, align)
- global PLOT2SVG_globals
- if PLOT2SVG_globals.checkUserData && isstruct(get(id,'UserData'))
- struct_data = get(id,'UserData');
- if isfield(struct_data,'svg')
- if isfield(struct_data.svg,'YTickLabelAngle')
- angle = struct_data.svg.YTickLabelAngle;
- align = 'Left';
- end
- end
- end
- function animation2svg(fid, id)
- global PLOT2SVG_globals
- if PLOT2SVG_globals.checkUserData && isstruct(get(id,'UserData'))
- struct_data = get(id,'UserData');
- if isfield(struct_data,'svg')
- if isfield(struct_data.svg,'Animation')
- animation = struct_data.svg.Animation;
- for i = 1:length(animation)
- if ~isfield(animation(i).SubAnimation, 'Type')
- error(['Missing field ''Type'' for animation.']);
- end
- switch animation(i).SubAnimation.Type
- case 'Opacity', type = 'opacity'; animationType = 0;
- case 'Translate', type = 'translate'; animationType = 2;
- case 'Scale', type = 'scale'; animationType = 2;
- case 'Rotate', type = 'rotate'; animationType = 1;
- case 'skewX', type = 'skewX'; animationType = 1;
- case 'skewY', type = 'skewY'; animationType = 1;
- otherwise, error(['Unknown animation type ''' animation(i).SubAnimation.Type '''.']);
- end
- %fprintf(fid,' <animate attributeType="XML" attributeName="%s" from="%0.3f" to="%0.3f" dur="%0.3fs" repeatCount="%s" />',...
- % 'opacity' , 0, 1, 5, 'indefinite');
- if animationType == 0
- fprintf(fid,' <animate attributeType="XML" attributeName="%s" dur="%0.3fs"', type, animation(i).SubAnimation.Duration);
- fprintf(fid,' values="');
- fprintf(fid,'%0.2f;', animation(i).SubAnimation.Value);
- fprintf(fid,'" keyTimes="');
- fprintf(fid,'%0.2f;', max(min(animation(i).SubAnimation.Key, 1), 0));
- fprintf(fid,'" repeatCount="%s" calcMode="linear" />', 'indefinite');
- elseif animationType == 1
- fprintf(fid,' <animateTransform attributeName="transform" attributeType="XML" type="%s" dur="%0.3fs"', type, animation(i).SubAnimation.Duration);
- fprintf(fid,' values="');
- fprintf(fid,'%0.2f;', animation(i).SubAnimation.Value);
- fprintf(fid,'" keyTimes="');
- fprintf(fid,'%0.2f;', max(min(animation(i).SubAnimation.Key, 1), 0));
- fprintf(fid,'" repeatCount="%s" calcMode="linear" additive="sum" />', 'indefinite');
- elseif animationType == 2
- fprintf(fid,' <animateTransform attributeName="transform" attributeType="XML" type="%s" dur="%0.3fs"', type, animation(i).SubAnimation.Duration);
- fprintf(fid,' values="');
- fprintf(fid,'%0.2f,%0.2f;', animation(i).SubAnimation.Value);
- fprintf(fid,'" keyTimes="');
- fprintf(fid,'%0.2f;', max(min(animation(i).SubAnimation.Key, 1), 0));
- fprintf(fid,'" repeatCount="%s" calcMode="linear" additive="sum" />', 'indefinite');
- end
- end
- end
- end
- end
- function [filterString, boundingBox] = filter2svg(fid, id, boundingBoxAxes, boundingBoxElement)
- global PLOT2SVG_globals
- filterString = '';
- boundingBox = boundingBoxAxes;
- if PLOT2SVG_globals.checkUserData && isstruct(get(id,'UserData'))
- struct_data = get(id,'UserData');
- if isfield(struct_data,'svg')
- boundingBox = boundingBoxElement;
- absolute = true;
- offset = 0;
- if isfield(struct_data.svg,'BoundingBox')
- if isfield(struct_data.svg.BoundingBox, 'Type')
- switch struct_data.svg.BoundingBox.Type
- case 'axes', boundingBox = boundingBoxAxes; absolute = true;
- case 'element', boundingBox = boundingBoxElement; absolute = true;
- case 'relative', boundingBox = boundingBoxElement; absolute = false;
- otherwise
- error(['Unknown bounding box type ''' struct_data.svg.BoundingBox.Type '''.']);
- end
- end
- if isfield(struct_data.svg.BoundingBox, 'Overlap')
- overlap = struct_data.svg.BoundingBox.Overlap;
- if absolute
- boundingBox(1) = boundingBox(1) - overlap;
- boundingBox(2) = boundingBox(2) - overlap;
- boundingBox(3) = boundingBox(3) + 2 * overlap;
- boundingBox(4) = boundingBox(4) + 2 * overlap;
- else
- boundingBox(1) = boundingBox(1) - boundingBox(3) * overlap;
- boundingBox(2) = boundingBox(2) - boundingBox(4) * overlap;
- boundingBox(3) = boundingBox(3) + 2 * boundingBox(3) * overlap;
- boundingBox(4) = boundingBox(4) + 2 * boundingBox(4) * overlap;
- end
- end
- if isfield(struct_data.svg.BoundingBox, 'Visible') && strcmp(struct_data.svg.BoundingBox.Visible, 'on')
- % This functionality is very interesting for debugging of
- % bounding boxes of filters
- fprintf(fid,'<rect x="%0.3f" y="%0.3f" width="%0.3f" height="%0.3f" fill="none" stroke="#000000" stroke-dasharray="1pt,1pt" stroke-width="0.2pt" />\n', boundingBox(1), boundingBox(2), boundingBox(3), boundingBox(4));
- end
- end
- if isfield(struct_data.svg,'Filter')
- % Predefined filter sources. Additional filter sources will be
- % added later.
- predefinedSources = {'SourceGraphic','SourceAlpha','BackgroundImage','BackgroundAlpha','FillPaint','StrokePaint'};
- resultStrings = predefinedSources;
- filterId = createId;
- filterString = ['filter="url(#' filterId ')"'];
- fprintf(fid,'<defs>\n');
- fprintf(fid,' <filter x="%0.3f%%" y="%0.3f%%" width="%0.3f%%" height="%0.3f%%" id="%s">\n', 0, 0, 100, 100, filterId);
- %if absolute
- % fprintf(fid,' <filter x="%0.3f" y="%0.3f" width="%0.3f" height="%0.3f" filterUnits="userSpaceOnUse" id="%s">\n', boundingBox(1), boundingBox(2), boundingBox(3), boundingBox(4), filterId);
- %else
- % fprintf(fid,' <filter x="%0.3f%%" y="%0.3f%%" width="%0.3f%%" height="%0.3f%%" id="%s">\n', -(offset * 100), -(offset * 100), 100 + (offset * 200), 100 + (offset * 200), filterId);
- % % Note: use default -10% for attribute x
- % % use default -10% for attribute y
- % % use default 120% for attribute width
- % % use default 120% for attribute height
- %end
- filter = struct_data.svg.Filter;
- for i = 1:length(filter)
- if isfield(filter(i).Subfilter, 'Type')
- fprintf(fid,' <%s', filter(i).Subfilter.Type);
- else
- error(['Missing field ''Type'' for filter.'])
- end
- try
- if isfield(filter(i).Subfilter, 'Position')
- printAttributeArray(fid, {'x','y','width','height'}, filter(i).Subfilter, 'Position');
- end
- printAttributeString(fid, 'result', filter(i).Subfilter, 'Result');
- % Add result string to the list in order to check the in
- % strings.
- resultStrings{length(resultStrings) + 1} = filter(i).Subfilter.Result;
- % The strmatch below is a very inefficient search (Matlab limitation)
- if ~isempty(strmatch(filter(i).Subfilter.Result, predefinedSources))
- error('Usage of a predefined filter source as filter result string is not allowed.');
- end
- switch (filter(i).Subfilter.Type)
- case 'feGaussianBlur'
- printAttributeIn(fid, 'in', filter(i).Subfilter, 'Source', 'SourceGraphic', resultStrings);
- printAttributeDouble(fid, 'stdDeviation', filter(i).Subfilter, 'Deviation');
- fprintf(fid,' />\n');
- case 'feImage'
- printAttributeString(fid, 'xlink:href', filter(i).Subfilter, 'File');
- printAttributeString(fid, 'preserveAspectRatio', filter(i).Subfilter, 'AspectRatio', 'xMidYMid meet');
- fprintf(fid,' />\n');
- case 'feComposite'
- printAttributeIn(fid, 'in', filter(i).Subfilter, 'Source1', 'SourceGraphic', resultStrings);
- printAttributeIn(fid, 'in2', filter(i).Subfilter, 'Source2', 'SourceGraphic', resultStrings);
- printAttributeList(fid, 'operator', filter(i).Subfilter, 'Operator', {'over','in','out','atop','xor','arithmetic'}, 'over'); % 'over' | 'in' | 'out' | 'atop' | 'xor' | 'arithmetic'
- if isfield(filter(i).Subfilter, 'Operator') && strcmp(filter(i).Subfilter.Operator, 'arithmetic')
- printAttributeArray(fid, {'k1','k2','k3','k4'}, filter(i).Subfilter, 'k');
- end
- fprintf(fid,' />\n');
- case 'feSpecularLighting'
- printAttributeDouble(fid, 'specularConstant', filter(i).Subfilter, 'SpecularConstant');
- printAttributeDouble(fid, 'specularExponent', filter(i).Subfilter, 'SpecularExponent');
- printAttributeDouble(fid, 'surfaceScale', filter(i).Subfilter, 'SurfaceScale');
- fprintf(fid,' style="lighting-color:white"');
- printAttributeIn(fid, 'in', filter(i).Subfilter, 'Source', 'SourceGraphic', resultStrings);
- fprintf(fid,' >\n');
- if isfield(filter(i).Subfilter, 'LightType')
- fprintf(fid,' <%s', filter(i).Subfilter.LightType);
- switch filter(i).Subfilter.LightType
- case 'feDistantLight'
- printAttributeDouble(fid, 'azimuth', filter(i).Subfilter, 'Azimuth');
- printAttributeDouble(fid, 'elevation', filter(i).Subfilter, 'Elevation');
- case 'fePointLight'
- printAttributeArray(fid, {'x','y','z'}, filter(i).Subfilter, 'Position');
- case 'feSpotLight'
- printAttributeArray(fid, {'x','y','z'}, filter(i).Subfilter, 'Position');
- printAttributeArray(fid, {'pointsAtX','pointsAtY','pointsAtZ'}, filter(i).Subfilter, 'PositionsAt');
- printAttributeDouble(fid, 'specularExponent', filter(i).Subfilter, 'LightSpecularExponent');
- printAttributeDouble(fid, 'limitingConeAngle', filter(i).Subfilter, 'LimitingConeAngle');
- otherwise, error(['Unknown light type ''' filter(i).Subfilter.LightType ''.']);
- end
- fprintf(fid,' />\n');
- else
- error('Missing field ''LightType''.');
- end
- fprintf(fid,'</%s>\n',filter(i).Subfilter.Type);
- case 'feOffset'
- printAttributeIn(fid, 'in', filter(i).Subfilter, 'Source', 'SourceGraphic', resultStrings);
- printAttributeArray(fid, {'dx','dy'}, filter(i).Subfilter, 'Offset');
- fprintf(fid,' />\n');
- case 'feBlend'
- printAttributeIn(fid, 'in', filter(i).Subfilter, 'Source1', 'SourceGraphic', resultStrings);
- printAttributeIn(fid, 'in2', filter(i).Subfilter, 'Source2', 'SourceGraphic', resultStrings);
- printAttributeList(fid, 'mode', filter(i).Subfilter, 'Mode', {'normal','multiply','screen','darken','lighten'}, 'normal'); % 'normal' | 'multiply' | 'screen' | 'darken' | 'lighten'
- fprintf(fid,' />\n');
- case 'feTurbulence'
- printAttributeDouble(fid, 'baseFrequency', filter(i).Subfilter, 'BaseFrequency');
- printAttributeDouble(fid, 'numOctaves', filter(i).Subfilter, 'NumOctaves');
- printAttributeDouble(fid, 'seed', filter(i).Subfilter, 'Seed');
- printAttributeList(fid, 'stitchTiles', filter(i).Subfilter, 'StitchTiles', {'stitch','noStitch'}, 'noStitch'); % stitch | noStitch
- printAttributeList(fid, 'type', filter(i).Subfilter, 'TurbulenceType', {'fractalNoise','turbulence'}, 'turbulence'); % 'fractalNoise' | 'turbulence'
- fprintf(fid,' />\n');
- case 'feColorMatrix'
- printAttributeIn(fid, 'in', filter(i).Subfilter, 'Source', 'SourceGraphic', resultStrings);
- printAttributeList(fid, 'type', filter(i).Subfilter, 'ColorType', {'matrix','saturate','hueRotate','luminanceToAlpha'}); % 'matrix' | 'saturate' | 'hueRotate' | 'luminanceToAlpha'
- if isfield(filter(i).Subfilter, 'ColorType') && strcmp(filter(i).Subfilter.ColorType, 'matrix')
- if isfield(filter(i).Subfilter, 'Matrix') && (lenght(filter(i).Subfilter.Matrix) == 20)
- fprintf(fid,' values="');
- fprintf(fid,' %0.3f', filter(i).Subfilter.Matrix);
- fprintf(fid,'"');
- else
- error('Field ''Matrix'' is missing or not a 5x4 matrix.');
- end
- end
- if isfield(filter(i).Subfilter, 'ColorType') && (strcmp(filter(i).Subfilter.ColorType, 'saturate') || strcmp(filter(i).Subfilter.ColorType, 'hueRotate'))
- printAttributeDouble(fid, 'values', filter(i).Subfilter, 'Matrix');
- end
- fprintf(fid,' />\n');
- case 'feFlood'
- printAttributeColor(fid, 'flood-color', filter(i).Subfilter, 'Color');
- printAttributeDouble(fid, 'flood-opacity', filter(i).Subfilter, 'Opacity');
- fprintf(fid,' />\n');
- case 'feDisplacementMap'
- printAttributeIn(fid, 'in', filter(i).Subfilter, 'Source1', 'SourceGraphic', resultStrings);
- printAttributeIn(fid, 'in2', filter(i).Subfilter, 'Source2', 'SourceGraphic', resultStrings);
- printAttributeDouble(fid, 'scale', filter(i).Subfilter, 'Scale');
- printAttributeList(fid, 'xChannelSelector', filter(i).Subfilter, 'xChannel', {'R','G','B','A'}, 'A'); % 'R' | 'G' | 'B' | 'A'
- printAttributeList(fid, 'yChannelSelector', filter(i).Subfilter, 'yChannel', {'R','G','B','A'}, 'A'); % 'R' | 'G' | 'B' | 'A'
- fprintf(fid,' />\n');
- case 'feMerge'
- printAttributeIn(fid, 'in', filter(i).Subfilter, 'Source1', 'SourceGraphic', resultStrings);
- printAttributeIn(fid, 'in2', filter(i).Subfilter, 'Source2', 'SourceGraphic', resultStrings);
- printAttributeList(fid, 'mode', filter(i).Subfilter, 'Mode', {'normal','multiply','screen','darken','lighten'}); % 'normal' | 'multiply' | 'screen' | 'darken' | 'lighten'
- fprintf(fid,' />\n');
- case 'feMorphology'
- printAttributeIn(fid, 'in', filter(i).Subfilter, 'Source', 'SourceGraphic', resultStrings);
- printAttributeList(fid, 'operator', filter(i).Subfilter, 'Operator', {'erode','dilate'}); % 'erode' | 'dilate'
- printAttributeDouble(fid, 'radius', filter(i).Subfilter, 'Radius');
- fprintf(fid,' />\n');
- case 'feTile'
- printAttributeIn(fid, 'in', filter(i).Subfilter, 'Source', 'SourceGraphic', resultStrings);
- fprintf(fid,' />\n');
- case 'feDiffuseLighting'
- printAttributeIn(fid, 'in', filter(i).Subfilter, 'Source', 'SourceGraphic', resultStrings);
- fprintf(fid,' style="lighting-color:white"');
- printAttributeDouble(fid, 'surfaceScale', filter(i).Subfilter, 'SurfaceScale');
- printAttributeDouble(fid, 'diffuseConstant', filter(i).Subfilter, 'DiffuseConstant');
- printAttributeDouble(fid, 'kernelUnitLength', filter(i).Subfilter, 'KernelUnitLength');
- fprintf(fid,' />\n');
-
- % case 'feConvolveMatrix'
- %
- % printAttributeDouble(fid, 'order', filter(i).Subfilter);
- % kernelMatrix
- % printAttributeDouble(fid, 'divisor', filter(i).Subfilter, 1.0);
- % printAttributeDouble(fid, 'bias', filter(i).Subfilter, 0);
- % targetX
- % targetY
- % printAttributeString(fid, 'edgeMode', filter(i).Subfilter, 'EdgeMode', 'duplicate');
- % fprintf(fid,' kernelUnitLength="1 1"');
- % printAttributeString(fid, 'preserveAlpha', filter(i).Subfilter, 'PreserveAlpha', 'true');
- % fprintf(fid,' />\n');
- case {'feComponentTransfer','feConvolveMatrix'}
- error('Filter not yet implemented.');
- otherwise
- error(['Unknown filter ''' filter(i).Subfilter.Type '''.']);
- end
- catch
- error([lasterr ' Error is caused by filter type ''' filter(i).Subfilter.Type '''.']);
- end
- end
- fprintf(fid,' </filter>\n');
- fprintf(fid,'</defs>\n');
- end
- end
- end
- function printAttributeArray(fid, names, svgstruct, svgfield)
- if isfield(svgstruct, svgfield)
- if isnumeric(svgstruct.(svgfield))
- if length(svgstruct.(svgfield)) ~= length(names)
- error(['Length mismatch for field ''' svgfield '''.'])
- end
- for i = 1:length(names)
- fprintf(fid,' %s="%0.3f"', names{i}, svgstruct.(svgfield)(i));
- end
- else
- error(['Field ''' svgfield ''' must be numeric.']);
- end
- else
- if nargin < 5
- error(['Missing field ''' svgfield '''.'])
- else
- for i = 1:length(names)
- fprintf(fid,' %s="%0.3f"', names{i}, default(i));
- end
- end
- end
- function printAttributeDouble(fid, name, svgstruct, svgfield, default)
- if isfield(svgstruct, svgfield)
- if isnumeric(svgstruct.(svgfield))
- fprintf(fid,' %s="%0.3f"', name, svgstruct.(svgfield));
- else
- error(['Field ''' svgfield ''' must be numeric.']);
- end
- else
- if nargin < 5
- error(['Missing field ''' svgfield '''.'])
- else
- fprintf(fid,' %s="%0.3f"', name, default);
- end
- end
- function printAttributeIn(fid, name, svgstruct, svgfield, default, resultStrings)
- if isfield(svgstruct, svgfield)
- if ischar(svgstruct.(svgfield))
- % The strmatch below is a very inefficient search (Matlab limitation)
- if isempty(strmatch(svgstruct.(svgfield), resultStrings))
- error(['The source string ''' svgstruct.(svgfield) ''' was never a result string of a previous filter. Check for correct spelling.']);
- else
- fprintf(fid,' %s="%s"', name, svgstruct.(svgfield));
- end
- else
- error(['Field ''' svgfield ''' must be a string.']);
- end
- else
- if nargin < 5
- error(['Missing field ''' svgfield '''.'])
- else
- fprintf(fid,' %s="%s"', name, default);
- end
- end
- function printAttributeString(fid, name, svgstruct, svgfield, default)
- if isfield(svgstruct, svgfield)
- if ischar(svgstruct.(svgfield))
- fprintf(fid,' %s="%s"', name, svgstruct.(svgfield));
- else
- error(['Field ''' svgfield ''' must be a string.']);
- end
- else
- if nargin < 5
- error(['Missing field ''' svgfield '''.'])
- else
- fprintf(fid,' %s="%s"', name, default);
- end
- end
- function printAttributeList(fid, name, svgstruct, svgfield, list, default)
- if isfield(svgstruct, svgfield)
- if ischar(svgstruct.(svgfield))
- if isempty(strmatch(svgstruct.(svgfield), list))
- listString = strcat(list, ''' | ''');
- listString = [listString{:}];
- error(['Illegal string identifier ''' svgstruct.(svgfield) '''. Must be one out of the list: ''' listString(1:end-4) '.']);
- else
- fprintf(fid,' %s="%s"', name, svgstruct.(svgfield));
- end
- else
- error(['Field ''' svgfield ''' must be a string.']);
- end
- else
- if nargin < 6
- error(['Missing field ''' svgfield '''.'])
- else
- fprintf(fid,' %s="%s"', name, default);
- end
- end
- function printAttributeColor(fid, name, svgstruct, svgfield, default)
- if isfield(svgstruct, svgfield)
- if isnumeric(svgstruct.(svgfield))
- if length(svgstruct.(svgfield)) ~= 3
- error(['Color must be a 1x3 vector for field ''' svgfield '''.'])
- else
- fprintf(fid,' %s="%s"', name, searchcolor(gca, svgstruct.(svgfield)));
- end
- else
- error(['Field ''' svgfield ''' must be a 1x3 vector.']);
- end
- else
- if nargin < 5
- error(['Missing field ''' svgfield '''.'])
- else
- fprintf(fid,' %s="%s"', name, default);
- end
- end
- function frontTicks(fid, grouplabel, axpos, x, y, scolorname, linewidth, tick, index, edge_neighbours, c, valid_ticks, ticklength, tick_ratio, lim, drawBorder)
- for k = 1:length(index)
- x_tick_end1 = interp1([0 1],[x(index(k)) x(edge_neighbours(index(k),c(1)))],ticklength*tick_ratio(c(3)),'linear','extrap');
- y_tick_end1 = interp1([0 1],[y(index(k)) y(edge_neighbours(index(k),c(1)))],ticklength*tick_ratio(c(3)),'linear','extrap');
- x_tick_end2 = interp1([0 1],[x(edge_neighbours(index(k),c(2))) x(edge_neighbours(edge_neighbours(index(k),c(2)),c(1)))],ticklength*tick_ratio(c(3)),'linear','extrap');
- y_tick_end2 = interp1([0 1],[y(edge_neighbours(index(k),c(2))) y(edge_neighbours(edge_neighbours(index(k),c(2)),c(1)))],ticklength*tick_ratio(c(3)),'linear','extrap');
- xg_line_start = interp1(lim,[x(index(k)) x(edge_neighbours(index(k),c(2)))],tick);
- yg_line_start = interp1(lim,[y(index(k)) y(edge_neighbours(index(k),c(2)))],tick);
- xg_line_end = interp1(lim,[x_tick_end1 x_tick_end2],tick);
- yg_line_end = interp1(lim,[y_tick_end1 y_tick_end2],tick);
- for i = valid_ticks
- line2svg(fid,grouplabel,axpos,[xg_line_start(i) xg_line_end(i)],[yg_line_start(i) yg_line_end(i)],scolorname,'-',linewidth)
- end
- if drawBorder
- line2svg(fid,grouplabel,axpos,[x(index(k)) x(edge_neighbours(index(k),c(2)))],[y(index(k)) y(edge_neighbours(index(k),c(2)))],scolorname,'-',linewidth)
- end
- end
- function gridLines(fid, grouplabel, axpos, x, y, scolorname, gridlinestyle, linewidth, axlim, axtick, axindex_inner, corners, c)
- xg_line_start = interp1([axlim(1) axlim(2)],[x(corners(c(1))) x(corners(c(2)))], axtick);
- yg_line_start = interp1([axlim(1) axlim(2)],[y(corners(c(1))) y(corners(c(2)))], axtick);
- xg_line_end = interp1([axlim(1) axlim(2)],[x(corners(c(3))) x(corners(c(4)))], axtick);
- yg_line_end = interp1([axlim(1) axlim(2)],[y(corners(c(3))) y(corners(c(4)))], axtick);
- for i = axindex_inner
- line2svg(fid, grouplabel, axpos, [xg_line_start(i) xg_line_end(i)],[yg_line_start(i) yg_line_end(i)], scolorname, gridlinestyle, linewidth)
- end
- function minorGridLines(fid, grouplabel, axpos, x, y, scolorname, minor_gridlinestyle, linewidth, axlim, minor_axtick, corners, c)
- xg_line_start = interp1([axlim(1) axlim(2)],[x(corners(c(1))) x(corners(c(2)))], minor_axtick);
- yg_line_start = interp1([axlim(1) axlim(2)],[y(corners(c(1))) y(corners(c(2)))], minor_axtick);
- xg_line_end = interp1([axlim(1) axlim(2)],[x(corners(c(3))) x(corners(c(4)))], minor_axtick);
- yg_line_end = interp1([axlim(1) axlim(2)],[y(corners(c(3))) y(corners(c(4)))], minor_axtick);
- for i = 1:length(xg_line_start)
- line2svg(fid, grouplabel, axpos, [xg_line_start(i) xg_line_end(i)],[yg_line_start(i) yg_line_end(i)], scolorname, minor_gridlinestyle, linewidth)
- end
- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% SUBFUNCTIONS %%%%%
- % Create axis frame and insert all children of this axis frame
- function group=axes2svg(fid,id,ax,group,paperpos)
- global colorname
- global PLOT2SVG_globals
- originalAxesUnits=get(ax,'Units');
- set(ax,'Units','normalized');
- axpos=get(ax,'Position');
- faces = [1 2 4 3; 2 4 8 6; 3 4 8 7; 1 2 6 5; 1 5 7 3; 5 6 8 7];
- % x-y ; y-z ; x-z ; y-z ; x-z ; x-y
- corners(:,:,1) = [1 1 2 3 4; 2 1 3 2 4];
- corners(:,:,2) = [2 2 4 6 8; 3 2 6 4 8];
- corners(:,:,3) = [1 3 4 7 8; 3 3 7 4 8];
- corners(:,:,4) = [1 1 2 5 6; 3 1 5 2 6];
- corners(:,:,5) = [2 1 3 5 7; 3 1 5 3 7];
- corners(:,:,6) = [1 5 6 7 8; 2 5 7 6 8];
- edge_neighbours = [2 3 5; 1 4 6; 4 1 7; 3 2 8; 6 7 1; 5 8 2; 8 5 3; 7 6 4];
- edge_opposite = [8 7 6 5 4 3 2 1];
- nomx = [0 1 0 1 0 1 0 1];
- nomy = [0 0 1 1 0 0 1 1];
- nomz = [0 0 0 0 1 1 1 1];
- [projection,edges] = get_projection(ax,id);
- x = (edges(1,:)*axpos(3)+axpos(1))*paperpos(3);
- y = (1-(edges(2,:)*axpos(4)+axpos(2)))*paperpos(4);
- % Depth Sort of view box edges
- [edge_z,edge_index]=sort(edges(3,:));
- most_back_edge_index = edge_index(1);
- % Back faces are plot box faces that are behind the plot (as seen by the
- % view point)
- back_faces = find(any(faces == most_back_edge_index,2));
- front_faces = find(all(faces ~= most_back_edge_index,2));
- groupax=group;
- axlimx=get(ax,'XLim');
- axlimy=get(ax,'YLim');
- axlimz=get(ax,'ZLim');
- axlimxori=axlimx;
- axlimyori=axlimy;
- axlimzori=axlimz;
- if strcmp(get(ax,'XScale'),'log')
- axlimx=log10(axlimx);
- axlimx(find(isinf(axlimx)))=0;
- end
- if strcmp(get(ax,'YScale'),'log')
- axlimy=log10(axlimy);
- axlimy(find(isinf(axlimy)))=0;
- end
- if strcmp(get(ax,'ZScale'),'log')
- axlimz=log10(axlimz);
- axlimz(find(isinf(axlimz)))=0;
- end
- if strcmp(get(ax,'XDir'),'reverse')
- axlimx = fliplr(axlimx);
- end
- if strcmp(get(ax,'YDir'),'reverse')
- axlimy = fliplr(axlimy);
- end
- if strcmp(get(ax,'ZDir'),'reverse')
- axlimz = fliplr(axlimz);
- end
- axlimori = [axlimxori(1) axlimyori(1) axlimzori(1) axlimxori(2)-axlimxori(1) axlimyori(2)-axlimyori(1) axlimzori(2)-axlimzori(1)];
- fprintf(fid,' <g id ="%s">\n', createId);
- axIdString = createId;
- boundingBoxAxes = [min(x) min(y) max(x)-min(x) max(y)-min(y)];
- fprintf(fid,' <clipPath id="%s">\n',axIdString);
- fprintf(fid,' <rect x="%0.3f" y="%0.3f" width="%0.3f" height="%0.3f"/>\n',...
- boundingBoxAxes(1), boundingBoxAxes(2), boundingBoxAxes(3), boundingBoxAxes(4));
- fprintf(fid,' </clipPath>\n');
- if strcmp(get(ax,'Visible'),'on')
- group=group+1;
- grouplabel=group;
- axxtick=get(ax,'XTick');
- axytick=get(ax,'YTick');
- axztick=get(ax,'ZTick');
- axlabelx=get(ax,'XTickLabel');
- axlabely=get(ax,'YTickLabel');
- axlabelz=get(ax,'ZTickLabel');
- % Workaround for Octave
- if PLOT2SVG_globals.octave
- if isempty(axlabelx)
- if strcmp(get(ax,'XScale'),'log')
- axlabelx = num2str(log10(axxtick)');
- else
- axlabelx = num2str(axxtick');
- end
- end
- if isempty(axlabely)
- if strcmp(get(ax,'YScale'),'log')
- axlabely = num2str(log10(axytick)');
- else
- axlabely = num2str(axytick');
- end
- end
- if isempty(axlabelz)
- if strcmp(get(ax,'ZScale'),'log')
- axlabelz = num2str(log10(axztick)');
- else
- axlabelz = num2str(axztick');
- end
- end
- if projection.xyplane
- axlabelz = [];
- end
- end
- gridlinestyle=get(ax,'GridLineStyle');
- minor_gridlinestyle=get(ax,'MinorGridLineStyle');
- try % Octave does not have 'TickLength' yet. --Jakob Malm
- both_ticklength = get(ax,'TickLength');
- catch
- both_ticklength = [ 0.01 0.025 ];
- end
- gridBehind = true; % Default setting
- try
- if strcmp(get(ax, 'Layer'), 'top') && projection.xyplane
- gridBehind = false;
- end
- catch
- gridBehind = true;
- end
- if projection.xyplane
- ticklength = both_ticklength(1);
- xy_ratio = axpos(3)*paperpos(3)/ (axpos(4)*paperpos(4));
- if xy_ratio < 1
- tick_ratio = [1 1/xy_ratio 1];
- else
- tick_ratio = [xy_ratio 1 1];
- end
- if strcmp(get(ax,'TickDir'),'out')
- label_distance = -(0.02 + ticklength);
- else
- label_distance = -0.02;
- end
- else
- ticklength = both_ticklength(2);
- label_distance = -2*abs(ticklength);
- tick_ratio = [1 1 1];
- end
- linewidth = get(ax,'LineWidth');
- axxindex=find((axxtick >= axlimori(1)) & (axxtick <= (axlimori(1)+axlimori(4))));
- axyindex=find((axytick >= axlimori(2)) & (axytick <= (axlimori(2)+axlimori(5))));
- axzindex=find((axztick >= axlimori(3)) & (axztick <= (axlimori(3)+axlimori(6))));
- % remove sticks outside of the axes (-1 of legends)
- axxtick=axxtick(axxindex);
- axytick=axytick(axyindex);
- axztick=axztick(axzindex);
- if length(axxtick) > 1
- minor_lin_sticks = (0.2:0.2:0.8)*(axxtick(2)-axxtick(1));
- minor_axxtick = [];
- for stick = [2*axxtick(1)-axxtick(2) axxtick]
- minor_axxtick = [minor_axxtick minor_lin_sticks + stick];
- end
- minor_axxtick = minor_axxtick(find(minor_axxtick > min(axlimx) & minor_axxtick < max(axlimx)));
- else
- minor_axxtick = [];
- end
- if length(axytick) > 1
- minor_lin_sticks = (0.2:0.2:0.8)*(axytick(2)-axytick(1));
- minor_axytick = [];
- for stick = [2*axytick(1)-axytick(2) axytick]
- minor_axytick = [minor_axytick minor_lin_sticks + stick];
- end
- minor_axytick = minor_axytick(find(minor_axytick > min(axlimy) & minor_axytick < max(axlimy)));
- else
- minor_axytick = [];
- end
- if length(axztick) > 1
- minor_lin_sticks = (0.2:0.2:0.8)*(axztick(2)-axztick(1));
- minor_axztick = [];
- for stick = [2*axztick(1)-axztick(2) axztick]
- minor_axztick = [minor_axztick minor_lin_sticks + stick];
- end
- minor_axztick = minor_axztick(find(minor_axztick > min(axlimz) & minor_axztick < max(axlimz)));
- else
- minor_axztick = [];
- end
- if strcmp(get(ax,'Box'),'on')
- axxindex_inner = find((axxtick > axlimori(1)) & (axxtick < (axlimori(1)+axlimori(4))));
- axyindex_inner = find((axytick > axlimori(2)) & (axytick < (axlimori(2)+axlimori(5))));
- axzindex_inner = find((axztick > axlimori(3)) & (axztick < (axlimori(3)+axlimori(6))));
- else
- axxindex_inner = find((axxtick >= axlimori(1)) & (axxtick <= (axlimori(1)+axlimori(4))));
- axyindex_inner = find((axytick >= axlimori(2)) & (axytick <= (axlimori(2)+axlimori(5))));
- axzindex_inner = find((axztick >= axlimori(3)) & (axztick <= (axlimori(3)+axlimori(6))));
- end
- minor_log_sticks = log10(0.2:0.1:0.9);
- if strcmp(get(ax,'TickDir'),'out')
- ticklength=-ticklength;
- valid_xsticks = 1:length(axxindex);
- valid_ysticks = 1:length(axyindex);
- valid_zsticks = 1:length(axzindex);
- else
- valid_xsticks = axxindex_inner;
- valid_ysticks = axyindex_inner;
- valid_zsticks = axzindex_inner;
- end
- if strcmp(get(ax,'XScale'),'log')
- axxtick = log10(get(ax,'XTick'));
- minor_axxtick = [];
- if ~isempty(axxtick)
- all_axxtick = axxtick(1):1:axxtick(end);
- for stick = all_axxtick
- minor_axxtick = [minor_axxtick minor_log_sticks + stick];
- end
- end
- minor_axxtick = minor_axxtick(find(minor_axxtick > min(axlimx) & minor_axxtick < max(axlimx)));
- end
- if strcmp(get(ax,'YScale'),'log')
- axytick=log10(get(ax,'YTick'));
- minor_axytick = [];
- if ~isempty(axytick)
- all_axytick = axytick(1):1:axytick(end);
- for stick = all_axytick
- minor_axytick = [minor_axytick minor_log_sticks + stick];
- end
- end
- minor_axytick = minor_axytick(find(minor_axytick > min(axlimy) & minor_axytick < max(axlimy)));
- end
- if strcmp(get(ax,'ZScale'),'log')
- axztick=log10(get(ax,'ZTick'));
- minor_axztick = [];
- if ~isempty(axztick)
- all_axztick = axztick(1):1:axztick(end);
- for stick = all_axztick
- minor_axztick = [minor_axztick minor_log_sticks + stick];
- end
- end
- minor_axztick = minor_axztick(find(minor_axztick > min(axlimz) & minor_axztick < max(axlimz)));
- end
- % Draw back faces
- linewidth=get(ax,'LineWidth');
- if ~strcmp(get(ax,'Color'),'none')
- background_color = searchcolor(id,get(ax,'Color'));
- background_opacity = 1;
- else
- background_color = '#000000';
- background_opacity = 0;
- end
- for p=1:size(back_faces)
- patch2svg(fid, group, axpos, x(faces(back_faces(p),:)), y(faces(back_faces(p),:)), background_color, '-', linewidth, 'none', background_opacity, 1.0, true)
- end
- for pindex = 1:size(back_faces)
- p = back_faces(pindex);
- for k = 1:size(corners,1)
- selectedCorners = squeeze(corners(k,:,p));
- switch corners(k,1,p)
- case 1 % x
- % Draw x-grid
- scolorname = searchcolor(id,get(ax,'XColor'));
- if strcmp(get(ax,'XGrid'),'on') && gridBehind
- if axlimx(1)~=axlimx(2)
- gridLines(fid, grouplabel, axpos, x, y, scolorname, gridlinestyle, linewidth, axlimx, axxtick, axxindex_inner, selectedCorners, [2 3 4 5])
- if strcmp(get(ax,'XTickMode'),'auto') && strcmp(get(ax,'XMinorGrid'),'on') && ~isempty(minor_axxtick)
- minorGridLines(fid, grouplabel, axpos, x, y, scolorname, minor_gridlinestyle, linewidth, axlimx, minor_axxtick, selectedCorners, [2 3 4 5])
- end
- end
- end
- if projection.xyplane == false
- if strcmp(get(ax,'Box'),'on')
- line2svg(fid,grouplabel,axpos,[x(corners(k,2,p)) x(corners(k,3,p))],[y(corners(k,2,p)) y(corners(k,3,p))],scolorname,'-',linewidth);
- line2svg(fid,grouplabel,axpos,[x(corners(k,4,p)) x(corners(k,5,p))],[y(corners(k,4,p)) y(corners(k,5,p))],scolorname,'-',linewidth);
- else
- if strcmp(get(ax,'XGrid'),'on')
- line2svg(fid,grouplabel,axpos,[x(corners(k,2,p)) x(corners(k,3,p))],[y(corners(k,2,p)) y(corners(k,3,p))],scolorname,gridlinestyle,linewidth);
- line2svg(fid,grouplabel,axpos,[x(corners(k,4,p)) x(corners(k,5,p))],[y(corners(k,4,p)) y(corners(k,5,p))],scolorname,gridlinestyle,linewidth);
- end
- end
- end
- case 2 % y
- % Draw y-grid
- scolorname = searchcolor(id,get(ax,'YColor'));…