-
Notifications
You must be signed in to change notification settings - Fork 8
/
plot2svg.m
executable file
·3156 lines (3101 loc) · 159 KB
/
plot2svg.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
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
% 25-08-2011 - Fix for degree character (thanks to Manes Recheis)
% - Fix for problems with dash-arrays in Inkscape (thanks to
% Rüdiger Stirnberg)
% - Modified shape of driangles (thanks to Rüdiger Stirnberg)
% 22-10-2011 - Removed versn as return value of function fileparts (thanks
% to Andrew Scott)
% - Fix for images (thanks to Roeland)
% 20-05-2012 - Added some security checks for empty data
% - Fixed rotation for multiline text
% 25-08-2012 - Special handling of 1xn char arrays for tick labels
% (thanks to David Plavcan)
% - Fix for 'Index exceeds matrix dimensions' of axis labels
% (thanks to Aslak Grinsted)
% - Fix for another axis label problem (thanks to Ben Mitch)
% 15-09-2012 - Fix for linestyle none of rectangles (thanks to Andrew)
% - Enabled scatter plot functionality
global PLOT2SVG_globals
global colorname
progversion='15-Sep-2012';
PLOT2SVG_globals.runningIdNumber = 0;
PLOT2SVG_globals.octave = false;
PLOT2SVG_globals.checkUserData = true;
PLOT2SVG_globals.ScreenPixelsPerInch = 90; % Default 90ppi
try
PLOT2SVG_globals.ScreenPixelsPerInch = get(0, 'ScreenPixelsPerInch');
catch
% Keep the default 90ppi
end
if nargout==1
varargout={0};
end
disp([' Matlab/Octave to SVG converter version ' progversion ', Juerg Schwizer ([email protected]).'])
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
paperpos = paperpos * 90 / PLOT2SVG_globals.ScreenPixelsPerInch;
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] = 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=[];
% 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);
elseif strcmp(currenttype,'uicontrol')
if strcmp(get(ax(j),'Visible'),'on')
control2svg(fid,id,ax(j),group,paperpos);
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="1,1" 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