This repository has been archived by the owner on Apr 1, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 25
/
bargraph.pl
executable file
·1808 lines (1686 loc) · 64.7 KB
/
bargraph.pl
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
#!/usr/bin/perl
# bargraph.pl: a bar graph builder that supports stacking and clustering.
# Modifies gnuplot's output to fill in bars and add a legend.
#
# Copyright (C) 2004-2012 Derek Bruening <[email protected]>
# http://www.burningcutlery.com/derek/bargraph/
# http://code.google.com/p/bargraphgen/
#
# Contributions:
# * sorting by data contributed by Tom Golubev
# * legendfill= code inspired by Kacper Wysocki's code
# * =barsinbg option contributed by Manolis Lourakis
# * gnuplot 4.3 fixes contributed by Dima Kogan
# * ylabelshift contributed by Ricardo Nabinger Sanchez.
# * Error bar code contributed by Mohammad Ansari.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or (at
# your option) any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
# USA.
###########################################################################
###########################################################################
$usage = "
Usage: $0 [-gnuplot] [-fig] [-pdf] [-png [-non-transparent]] [-eps]
[-gnuplot-path <path>] [-fig2dev-path <path>] <graphfile>
File format:
<graph parameters>
<data>
Graph parameter types:
<value_param>=<value>
=<bool_param>
";
# Main features:
# * Stacked bars of 9+ datasets
# * Clustered bars of 8+ datasets
# * Clusters of stacked bars
# * Lets you keep your data in table format, or separated but listed in
# the same file, rather than requiring each dataset to be in a separate file
# * Custom gnuplot command pass-through for fine-grained customization
# without having a separate tool chain step outside the script
# * Color control
# * Font face control and limited font size control
# * Automatic arithmetic or harmonic mean calculation
# * Automatic legend creation
# * Automatic sorting, including sorting into SPEC CPU 2000 integer and
# floating point benchmark groups and sorting by data
#
# Multiple data sets can either be separated by =multi,
# or in a table with =table. Does support incomplete datasets,
# but issues warning.
# For clusters of stacked bars, separate your stacked data for each
# cluster with =multi or place in a table, and separate (and optionally
# name) each cluster with multimulti=
# For complete documentation see
# http://www.burningcutlery.com/derek/bargraph/
# This is version 4.7.
# Changes in version 4.7, released March 25, 2012:
# * added xscale= and yscale= to properly scale graphs on
# gnuplot 4.2+. Note that this may change absolute coordinates
# in existing graphs.
# * switched to boxerror to avoid the data marker for yerrorbars
# * added custfont= feature
# * fixed bugs in centering in-graph legend box
# * added fudging for capital letters to work around gnuplot weirdness
# (issue #15)
# Changes in version 4.6, released January 31, 2010:
# * added automatic legend placement, including automatically
# finding an empty spot inside the graph, via the 'inside',
# 'right', 'top', and 'center' keywords in legendx= and legendy=
# * added logscaley= to support logarithmic y values
# * added leading_space_mul=, intra_space_mul=, and barwidth=
# parameters to control spacing and bar size. as part of this change,
# bars are no longer placed in an integer-based fashion.
# * fixed gnuplot 4.0 regression
# Changes in version 4.5, released January 17, 2010:
# * changed legends to have a white background and border outline
# by default, with legendfill= option (inspired by Kacper
# Wysocki's code) to control the background fill color (and
# whether there is a fill) and =nolegoutline to turn off the
# outline
# * the legend bounding box is now much more accurately calculated
# * eliminated =patterns color with recent gnuplots
# * added legendfontsz= option
# * added =legendinbg option (legend in fg is new default)
# * added =reverseorder option (from Tom Golubev)
# * added =sortdata_ascend option (from Tom Golubev)
# * added =sortdata_descend option (from Tom Golubev)
# * added =barsinbg option (from Manolis Lourakis)
# * added horizline= option (issue #2)
# * added grouprotateby= option (issue #1)
# Changes in version 4.4, released August 10, 2009:
# * added rotateby= option
# * added xticshift= option
# * added support for gnuplot 4.3 (from Dima Kogan)
# * added ylabelshift= option (from Ricardo Nabinger Sanchez)
# * added =stackabs option
# Changes in version 4.3, released June 1, 2008:
# * added errorbar support (from Mohammad Ansari)
# * added support for multiple colors in a single dataset
# * added -non-transparent option to disable png transparency
# * added option to disable the legend
# * added datascale and datasub options
# Changes in version 4.2, released May 25, 2007:
# * handle gnuplot 4.2 fig terminal output
# Changes in version 4.1, released April 1, 2007:
# * fixed bug in handling scientific notation
# * fixed negative offset font handling bug
# Changes in version 4.0, released October 16, 2006:
# * added support for clusters of stacked bars
# * added support for font face and size changes
# * added support for negative maximum values
# Changes in version 3.0, released July 15, 2006:
# * added support for spaces and quotes in x-axis labels
# * added support for missing values in table format
# * added support for custom table delimiter
# * added an option to suppress adding of commas
# Changes in version 2.0, released January 21, 2006:
# * added pattern fill support
# * fixed errors in large numbers of datasets:
# - support > 8 clustered bars
# - fix > 9 dataset color bug
# - support > 25 stacked bars
# we need special support for bidirectional pipe
use IPC::Open2;
###########################################################################
###########################################################################
# The full set of Postscript fonts supported by FIG
%fig_font = (
'Default' => -1,
'Times Roman' => 0,
# alias
'Times' => 0,
'Times Italic' => 1,
'Times Bold' => 2,
'Times Bold Italic' => 3,
'AvantGarde Book' => 4,
'AvantGarde Book Oblique' => 5,
'AvantGarde Demi' => 6,
'AvantGarde Demi Oblique' => 7,
'Bookman Light' => 8,
'Bookman Light Italic' => 9,
'Bookman Demi' => 10,
'Bookman Demi Italic' => 11,
'Courier' => 12,
'Courier Oblique' => 13,
'Courier Bold' => 14,
'Courier Bold Oblique' => 15,
'Helvetica' => 16,
'Helvetica Oblique' => 17,
'Helvetica Bold' => 18,
'Helvetica Bold Oblique' => 19,
'Helvetica Narrow' => 20,
'Helvetica Narrow Oblique' => 21,
'Helvetica Narrow Bold' => 22,
'Helvetica Narrow Bold Oblique' => 23,
'New Century Schoolbook Roman' => 24,
'New Century Schoolbook Italic' => 25,
'New Century Schoolbook Bold' => 26,
'New Century Schoolbook Bold Italic' => 27,
'Palatino Roman' => 28,
'Palatino Italic' => 29,
'Palatino Bold' => 30,
'Palatino Bold Italic' => 31,
'Symbol' => 32,
'Zapf Chancery Medium Italic' => 33,
'Zapf Dingbats' => 34,
);
###########################################################################
###########################################################################
# default is to output eps
$output = "eps";
$gnuplot_path = "gnuplot";
$fig2dev_path = "fig2dev";
$debug_seefig_unmod = 0;
$png_transparent = 1;
$verbose = 0;
# FIXME i#13: switch to GetOptions
while ($#ARGV >= 0) {
if ($ARGV[0] eq '-fig') {
$output = "fig";
} elsif ($ARGV[0] eq '-rawfig') {
$output = "fig";
$debug_seefig_unmod = 1;
} elsif ($ARGV[0] eq '-gnuplot') {
$output = "gnuplot";
} elsif ($ARGV[0] eq '-pdf') {
$output = "pdf";
} elsif ($ARGV[0] eq '-png') {
$output = "png";
} elsif ($ARGV[0] eq '-non-transparent') {
$png_transparent = 0;
} elsif ($ARGV[0] eq '-eps') {
$output = "eps";
} elsif ($ARGV[0] eq '-gnuplot-path') {
die $usage if ($#ARGV <= 0);
shift;
$gnuplot_path = $ARGV[0];
} elsif ($ARGV[0] eq '-fig2dev-path') {
die $usage if ($#ARGV <= 0);
shift;
$fig2dev_path = $ARGV[0];
} elsif ($ARGV[0] eq '-v') {
$verbose = 1;
} else {
$graph = $ARGV[0];
shift;
last;
}
shift;
}
die $usage if ($#ARGV >= 0 || $graph eq "");
open(IN, "< $graph") || die "Couldn't open $graph";
# gnuplot syntax varies by version
$gnuplot_version = `$gnuplot_path --version`;
$gnuplot_version =~ /gnuplot ([\d\.]+)/;
$gnuplot_version = $1;
$gnuplot_uses_offset = 1;
$gnuplot_uses_offset = 0 if ($gnuplot_version <= 4.0);
# support for clusters and stacked
$stacked = 0;
$stacked_absolute = 0;
$stackcount = 1;
$clustercount = 1;
$plotcount = 1; # multi datasets to cycle colors through
$dataset = 0;
$table = 0;
# leave $column undefined by default
# support for clusters of stacked
$stackcluster = 0;
$groupcount = 1;
$grouplabels = 0;
$groupset = 0;
$grouplabel_rotateby = 0;
$title = "";
$xlabel = "";
$ylabel = "";
$usexlabels = 1;
# xlabel rotation seems to not be supported by gnuplot
# default is to rotate x tic labels by 90 degrees
# when tic labels are rotated, need to shift axis label down. -1 is reasonable:
$xlabelshift = "0,-1";
$xticsopts = "rotate";
$xticshift = "0,0";
$ylabelshift = "0,0";
$sort = 0;
# sort into SPEC CPU 2000 and JVM98 groups: first, SPECFP, then SPECINT, then JVM
$sortbmarks = 0;
$sortdata_ascend = 0; # sort by data, from low to high
$sortdata_descend = 0; # sort by data, from high to low
$reverseorder = 0; # if not sorting, reverse order
$bmarks_fp = "ammp applu apsi art equake facerec fma3d galgel lucas mesa mgrid sixtrack swim wupwise";
$bmarks_int = "bzip2 crafty eon gap gcc gzip mcf parser perlbmk twolf vortex vpr";
$bmarks_jvm = "check compress jess raytrace db javac mpegaudio mtrt jack checkit";
$ymax = "";
$ymin = 0;
$calc_min = 1;
$lineat = "";
$gridx = "noxtics";
$gridy = "ytics";
$noupperright = 0;
# space on both ends of graph
$leading_space_mul = 0; # set below
# space between clusters
$intra_space_mul = 0; # set below
# width of bars
$barwidth = 0; # set below
$invert = 0;
$use_mean = 0;
$arithmean = 0; # else, harmonic
# leave $mean_label undefined by default
$datascale = 1;
$datasub = 0;
$percent = 0;
$base1 = 0;
$yformat = "%.0f";
$logscaley = 0;
$extra_gnuplot_cmds = "";
# if still 0 later will be initialized to default
$use_legend = 1;
$legendx = 'inside';
$legendy = 'top';
$legend_fill = 'white';
$legend_outline = 1;
$legend_font_size = 0; # if left at 0 will be $font_size-1
# use patterns instead of solid fills?
$patterns = 0;
# there are only 22 patterns that fig supports
$max_patterns = 22;
$custom_colors = 0;
$color_per_datum = 0;
# fig depth: leave enough room for many datasets
# (for stacked bars we subtract 2 for each)
# but max gnuplot terminal depth for fig is 99!
# fig depth might change later via =barsinbg
$legend_depth = 0; # 100 for =legendinbg
$plot_depth = 98;
$add_commas = 1;
$font_face = $fig_font{'Default'};
$font_size = 10.0;
# let user have some control over font bounding box heuristic
$bbfudge = 1.0;
# yerrorbar support
$yerrorbars = 0;
# are bars in the foreground (default) or background of plot?
$barsinbg = 0;
# sentinel value
$sentinel = 999999;
# scaling support
# targets gnuplot 4.2+ where "set size x,y" scales the chart but not
# the canvas and so ends up truncated: instead we need to set the size
# of the canvas up front (which works on older gnuplot too).
$canvas_default_x = 5.0;
$canvas_default_y = 3.0;
$canvas_min = 2;
$canvas_max = 99;
$xscale = 1.0;
$yscale = 1.0;
while (<IN>) {
next if (/^\#/ || /^\s*$/);
# line w/ = is a control line (except =>)
# FIXME i#13: switch to GetOptions
if (/=[^>]/) {
if (/^=cluster(.)/) {
$splitby = $1;
s/=cluster$splitby//;
chop;
@legend = split($splitby, $_);
$clustercount = $#legend + 1;
$plotcount = $clustercount;
} elsif (/^=stacked(.)/) {
$splitby = $1;
s/=stacked$splitby//;
chop;
@legend = split($splitby, $_);
$stackcount = $#legend + 1;
$plotcount = $stackcount;
$stacked = 1;
# reverse order of datasets
$dataset = $#legend;
} elsif (/^=stackcluster(.)/) {
$splitby = $1;
s/=stackcluster$splitby//;
chop;
@legend = split($splitby, $_);
$stackcount = $#legend + 1;
$plotcount = $stackcount;
$stackcluster = 1;
# reverse order of datasets
$dataset = $#legend;
# FIXME: two types of means: for stacked (mean bar per cluster)
# or for cluster (cluster of stacked bars)
$use_mean = 0;
} elsif (/^multimulti=(.*)/) {
if (!($groupset == 0 && $dataset == $stackcount-1)) {
$groupset++;
$dataset = $stackcount-1;
}
$groupname[$groupset] = $1;
$grouplabels = 1 if ($groupname[$groupset] ne "");
} elsif (/^=multi/) {
die "Neither cluster nor stacked specified for multiple dataset"
if ($plotcount == 1);
if ($stacked || $stackcluster) {
# reverse order of datasets
$dataset--;
} else {
$dataset++;
}
} elsif (/^=patterns/) {
$patterns = 1;
} elsif (/^=color_per_datum/) {
$color_per_datum = 1;
} elsif (/^colors=(.*)/) {
$custom_colors = 1;
@custom_color = split(',', $1);
} elsif (/^=table/) {
$table = 1;
if (/^=table(.)/) {
$table_splitby = $1;
} else {
$table_splitby = ' ';
}
} elsif (/^column=(\S+)/) {
$column = $1;
} elsif (/^=base1/) {
$base1 = 1;
} elsif (/^=invert/) {
$invert = 1;
} elsif (/^datascale=(.*)/) {
$datascale = $1;
} elsif (/^datasub=(.*)/) {
$datasub = $1;
} elsif (/^=percent/) {
$percent = 1;
} elsif (/^=sortdata_ascend/) {
$sort = 1;
$sortdata_ascend = 1;
} elsif (/^=sortdata_descend/) {
$sort = 1;
$sortdata_descend = 1;
} elsif (/^=sortbmarks/) {
$sort = 1;
$sortbmarks = 1;
} elsif (/^=sort/) { # don't prevent match of =sort*
$sort = 1;
} elsif (/^=reverseorder/) {
$reverseorder = 1;
} elsif (/^=arithmean/) {
die "Stacked-clustered does not suport mean" if ($stackcluster);
$use_mean = 1;
$arithmean = 1;
} elsif (/^=harmean/) {
die "Stacked-clustered does not suport mean" if ($stackcluster);
$use_mean = 1;
} elsif (/^meanlabel=(.*)$/) {
$mean_label = $1;
} elsif (/^min=([-\d\.]+)/) {
$ymin = $1;
$calc_min = 0;
} elsif (/^max=([-\d\.]+)/) {
$ymax = $1;
} elsif (/^=norotate/) {
$xticsopts = "";
# actually looks better at -1 when not rotated, too
$xlabelshift = "0,-1";
} elsif (/^xlabelshift=(.+)/) {
$xlabelshift = $1;
} elsif (/^ylabelshift=(.+)/) {
$ylabelshift = $1;
} elsif (/^xticshift=(.+)/) {
$xticsopts .= " offset $1";
} elsif (/^rotateby=(.+)/) {
$xticsopts = "rotate by $1";
} elsif (/^grouprotateby=(.+)/) {
$grouplabel_rotateby = $1;
} elsif (/^title=(.*)$/) {
$title = $1;
} elsif (/^=noxlabels/) {
$usexlabels = 0;
} elsif (/^xlabel=(.*)$/) {
$xlabel = $1;
} elsif (/^ylabel=(.*)$/) {
$ylabel = $1;
} elsif (/^yformat=(.*)$/) {
$yformat = $1;
} elsif (/^=noupperright/) {
$noupperright = 1;
} elsif (/^=gridx/) {
$gridx = "xtics";
} elsif (/^=nogridy/) {
$gridy = "noytics";
} elsif (/^=nolegend/) {
$use_legend = 0;
} elsif (/^legendx=(\S+)/) {
$legendx = $1;
} elsif (/^legendy=(\S+)/) {
$legendy = $1;
} elsif (/^legendfill=(.*)/) {
$legend_fill = $1;
} elsif (/^=nolegoutline/) {
$legend_outline = 0;
} elsif (/^legendfontsz=(.+)/) {
$legend_font_size = $1;
} elsif (/^extraops=(.*)/) {
$extra_gnuplot_cmds .= "$1\n";
} elsif (/^=nocommas/) {
$add_commas = 0;
} elsif (/^font=(.+)/) {
if (defined($fig_font{$1})) {
$font_face = $fig_font{$1};
} else {
@known_fonts = keys(%fig_font);
die "Unknown font \"$1\": known fonts are @known_fonts";
}
} elsif (/^custfont=([^=]+)=(.+)/) {
if (defined($fig_font{$1})) {
$custfont{$2} = $fig_font{$1};
} else {
@known_fonts = keys(%fig_font);
die "Unknown font \"$1\": known fonts are @known_fonts";
}
} elsif (/^fontsz=(.+)/) {
$font_size = $1;
} elsif (/^bbfudge=(.+)/) {
$bbfudge = $1;
} elsif (/^=yerrorbars/) {
$table = 0;
$yerrorbars = 1;
if (/^=yerrorbars(.)/) {
$yerrorbars_splitby = $1;
} else {
$yerrorbars_splitby = ' ';
}
} elsif (/^=stackabs/) {
$stacked_absolute = 1;
} elsif (/^horizline=(.+)/) {
$lineat .= "f(x)=$1,f(x) notitle lt -1,"; # put black line at $1
} elsif (/^=barsinbg/) {
$barsinbg = 1;
} elsif (/^=legendinbg/) {
$legend_depth = 100;
} elsif (/^leading_space_mul=(.+)/) {
$leading_space_mul = $1;
} elsif (/^intra_space_mul=(.+)/) {
$intra_space_mul = $1;
} elsif (/^barwidth=(.+)/) {
$barwidth = $1;
} elsif (/^logscaley=(.+)/) {
$logscaley = $1;
} elsif (/^xscale=(.+)/) {
$xscale = $1;
# gnuplot fig terminal imposes some limits
if ($xscale*$canvas_default_x < $canvas_min) {
$xscale = $canvas_min / $canvas_default_x;
print STDERR "WARNING: minimum scale exceeded: setting to min $xscale\n";
} elsif ($xscale*$canvas_default_x > $canvas_max) {
$xscale = $canvas_max / $canvas_default_x;
print STDERR "WARNING: maximum scale exceeded: setting to max $xscale\n";
}
} elsif (/^yscale=(.+)/) {
$yscale = $1;
# gnuplot fig terminal imposes some limits
if ($yscale*$canvas_default_y < $canvas_min) {
$yscale = $canvas_min / $canvas_default_y;
print STDERR "WARNING: minimum scale exceeded: setting to min $yscale\n";
} elsif ($yscale*$canvas_default_y > $canvas_max) {
$yscale = $canvas_max / $canvas_default_y;
print STDERR "WARNING: maximum scale exceeded: setting to max $yscale\n";
}
} else {
die "Unknown command $_\n";
}
next;
}
# compatibility checks
die "Graphs of type stacked or stackcluster do not suport yerrorbars"
if ($yerrorbars && ($stacked || $stackcluster));
# this line must have data on it!
if ($table) {
# table has to look like this, separated by $table_splitby (default ' '):
# <bmark1> <dataset1> <dataset2> <dataset3> ...
# <bmark2> <dataset1> <dataset2> <dataset3> ...
# ...
# perl split has a special case for literal ' ' to collapse adjacent
# spaces
if ($table_splitby eq ' ') {
@table_entry = split(' ', $_);
} else {
@table_entry = split($table_splitby, $_);
}
if ($#table_entry != $plotcount) { # not +1 since bmark
print STDERR "WARNING: table format error on line $_: found $#table_entry entries, expecting $plotcount entries\n";
}
# remove leading and trailing spaces, and escape quotes
$table_entry[0] =~ s/^\s*//;
$table_entry[0] =~ s/\s*$//;
$table_entry[0] =~ s/\"/\\\"/g;
$bmark = $table_entry[0];
for ($i=1; $i<=$#table_entry; $i++) {
$table_entry[$i] =~ s/^\s*//;
$table_entry[$i] =~ s/\s*$//;
if ($stacked || $stackcluster) {
# reverse order of datasets
$dataset = $stackcount-1 - ($i-1);
} else {
$dataset = $i-1;
}
$val = get_val($table_entry[$i], $dataset);
if (($stacked || $stackcluster) && $dataset < $stackcount-1 &&
!$stacked_absolute) {
# need to add prev bar to stick above
$entry{$groupset,$bmark,$dataset+1} =~ /([-\d\.eE]+)/;
$val += $1;
}
if ($val ne '') {
$entry{$groupset,$bmark,$dataset} = "$val";
} # else, leave undefined
}
goto nextiter;
}
if ($yerrorbars) {
# yerrorbars has to look like this, separated by $yerrorbars_splitby (default ' '):
# <bmark1> <dataset1> <dataset2> <dataset3> ...
# <bmark2> <dataset1> <dataset2> <dataset3> ...
# ...
# perl split has a special case for literal ' ' to collapse adjacent
# spaces
if ($yerrorbars_splitby eq ' ') {
@yerrorbars_entry = split(' ', $_);
} else {
@yerrorbars_entry = split($yerrorbars_splitby, $_);
}
if ($#yerrorbars_entry != $plotcount) { # not +1 since bmark
print STDERR "WARNING: yerrorbars format error on line $_: found $#yerrorbars_entry entries, expecting $plotcount entries\n";
}
# remove leading and trailing spaces, and escape quotes
$yerrorbars_entry[0] =~ s/^\s*//;
$yerrorbars_entry[0] =~ s/\s*$//;
$yerrorbars_entry[0] =~ s/\"/\\\"/g;
$bmark = $yerrorbars_entry[0];
for ($i=1; $i<=$#yerrorbars_entry; $i++) {
$yerrorbars_entry[$i] =~ s/^\s*//;
$yerrorbars_entry[$i] =~ s/\s*$//;
if ($stacked || $stackcluster) {
# reverse order of datasets
$dataset = $stackcount-1 - ($i-1);
} else {
$dataset = $i-1;
}
$val = get_val($yerrorbars_entry[$i], $dataset);
if (($stacked || $stackcluster) && $dataset < $stackcount-1 &&
!$stacked_absolute) {
# need to add prev bar to stick above
$yerror_entry{$groupset,$bmark,$dataset+1} =~ /([-\d\.eE]+)/;
$val += $1;
}
if ($val ne '') {
$yerror_entry{$groupset,$bmark,$dataset} = "$val";
} # else, leave undefined
}
goto nextiter;
}
# support the column= feature
if (defined($column)) {
# only support separation by spaces
my @columns = split(' ', $_);
$bmark = $columns[0];
if ($column eq "last") {
$val_string = $columns[$#columns];
} else {
die "Column $column out of bounds" if ($column > 1 + $#columns);
$val_string = $columns[$column - 1];
}
} elsif (/^\s*(.+)\s+([-\d\.]+)\s*$/) {
$bmark = $1;
$val_string = $2;
# remove leading spaces, and escape quotes
$bmark =~ s/\s+$//;
$bmark =~ s/\"/\\\"/g;
} else {
if (/\S+/) {
print STDERR "WARNING: unexpected, unknown-format line $_";
}
next;
}
# strip out trailing %
$val_string =~ s/%$//;
if ($val_string !~ /^[-\d\.]+$/) {
print STDERR "WARNING: non-numeric value \"$val_string\" for $bmark\n";
}
$val = get_val($val_string, $dataset);
if (($stacked || $stackcluster) && $dataset < $stackcount-1 &&
!$stacked_absolute) {
# need to add prev bar to stick above
# remember that we're walking backward
$entry{$groupset,$bmark,$dataset+1} =~ /([-\d\.]+)/;
$val += $1;
}
$entry{$groupset,$bmark,$dataset} = "$val";
nextiter:
if (!defined($names{$bmark})) {
$names{$bmark} = $bmark;
$order{$bmark} = $bmarks_seen++;
}
}
close(IN);
###########################################################################
###########################################################################
$groupcount = $groupset + 1;
$clustercount = $bmarks_seen if ($stackcluster);
if ($barwidth > 0) {
$boxwidth = $barwidth;
} else {
# default
$boxwidth = 0.75/$clustercount;
}
if ($sort) {
if ($sortbmarks) {
@sorted = sort sort_bmarks (keys %names);
} elsif ($sortdata_ascend) {
@sorted = sort { $entry{0,$a,0} <=> $entry{0,$b,0}} (keys %names);
} elsif ($sortdata_descend) {
@sorted = sort { $entry{0,$b,0} <=> $entry{0,$a,0}} (keys %names);
} else {
@sorted = sort (keys %names);
}
} else {
# put into order seen in file, or reverse
if ($reverseorder) {
@sorted = sort {$order{$b} <=> $order{$a}} (keys %names);
} else {
@sorted = sort {$order{$a} <=> $order{$b}} (keys %names);
}
}
# default spacing: increase spacing if have many clusters+bmarks
# but keep lead spacing small if only one bmark
if ($leading_space_mul != 0) {
# user-specified
$outer_space = $boxwidth * $leading_space_mul;
} else {
$outer_space = $boxwidth * (1.0 + ($clustercount-1)/4.);
}
if ($intra_space_mul != 0) {
# user-specified
$intra_space = $boxwidth * $intra_space_mul;
} else {
$intra_space = $boxwidth * (1.0 + ($clustercount-1)/10.);
}
# clamp at 1/10 the full width, if not user-specified
$num_items = $#sorted + 1 + (($use_mean) ? 1 : 0);
$xmax = get_xval($groupcount-1, $clustercount-1, $num_items-1)
+ $boxwidth/2.;
$outer_space = $xmax/10. if ($outer_space > $xmax/10. && $leading_space_mul == 0);
$intra_space = $xmax/10. if ($intra_space > $xmax/10. && $intra_space_mul == 0);
# re-calculate now that we know $intra_space and $outer_space
$xmax = get_xval($groupcount-1, $clustercount-1, $num_items-1)
+ $boxwidth/2. + $outer_space;
if ($use_mean) {
for ($i=0; $i<$plotcount; $i++) {
if ($stacked || $stackcluster) {
$category = $plotcount-$i;
} else {
$category = $i;
}
if ($arithmean) {
die "Error calculating mean: category $category has denom 0"
if ($harnum[$i] == 0);
$harmean[$i] = $harsum[$i] / $harnum[$i];
} else {
die "Error calculating mean: category $category has denom 0"
if ($harsum[$i] == 0);
$harmean[$i] = $harnum[$i] / $harsum[$i];
}
if ($datascale != 1) {
$harmean[$i] *= $datascale;
}
if ($percent) {
$harmean[$i] = ($harmean[$i] - 1) * 100;
} elsif ($base1) {
$harmean[$i] = ($harmean[$i] - 1);
}
}
if (($stacked || $stackcluster) && !$stacked_absolute) {
for ($i=$plotcount-2; $i>=0; $i--) {
# need to add prev bar to stick above
# since reversed, prev is +1
$harmean[$i] += $harmean[$i+1];
}
}
}
# x-axis labels
$xtics = "";
for ($g=0; $g<$groupcount; $g++) {
$item = 0;
foreach $b (@sorted) {
if ($stackcluster) {
$xval = get_xval($g, $item, $item);
} else {
$xval = get_xval($g, ($clustercount-1)/2., $item);
}
if ($usexlabels) {
$label = $b;
} else {
if ($stackcluster && $grouplabels && $item==&ceil($bmarks_seen/2)-1) {
$label = $groupname[$g];
} else {
$label = "";
}
}
$xtics .= "\"$label\" $xval, ";
$item++;
}
if ($stackcluster && $grouplabels && $usexlabels) {
$label = sprintf("set label \"%s\" at %f,0 center rotate by %d",
$groupname[$g], get_xval($g, ($clustercount-1)/2.,
($clustercount-1)/2.),
$grouplabel_rotateby);
$extra_gnuplot_cmds .= "$label\n";
}
}
# For stackcluster we need to find the y value for the group labels
# so we look where gnuplot put the x label. If the user specifies none,
# we add our own.
$unique_xlabel = "UNIQUEVALUETOLOOKFOR";
if ($stackcluster && $xlabel eq "") {
$xlabel = $unique_xlabel;
}
if ($use_mean) {
if ($usexlabels) {
if (!defined($mean_label)) {
if ($arithmean) {
$mean_label = "mean";
} else {
$mean_label = "har_mean";
}
}
} else {
$xtics .= "\"\" $item, ";
}
if ($stackcluster) {
# FIXME: support mean and move this into $g loop
$xval = get_xval(0, $item, $item);
} else {
$xval = get_xval(0, ($clustercount-1)/2., $item);
}
$xtics .= "\"$mean_label\" $xval, ";
$item++;
}
# lose the last comma-space
chop $xtics;
chop $xtics;
# add space between y-axis label and y tic labels
if ($ylabel ne "") {
$yformat = " $yformat";
} else {
# fix bounding box problem: cutting off tic labels on left if
# no axis label -- is it gnuplot bug? we're not mangling these
$yformat = " $yformat";
}
if ($calc_min) {
if ($logscaley > 0) {
die "Error: logscaley does not support negative values\n" if ($min < 0);
$ymin = 1;
} elsif ($min < 0) {
# round to next lower int
if ($min < 0) {
$min = int($min - 1);
}
$ymin = $min;
$lineat .= "f(x)=0,f(x) notitle lt -1,"; # put black line at 0
} # otherwise leave ymin at 0
} # otherwise leave ymin at user-specified value
###########################################################################
###########################################################################
# add dummy labels so we can extract the bounds of the legend text
# from gnuplot's text extent calculations.
# use a prefix so we can identify, process, and remove these.
# to be really thorough we should check that no user-specified string
# matches the prefix but too unlikely.
my $dummy_prefix = "BARGRAPH_TEMP_";
my $legend_old_fontsz = 0;
my $legend_text_widest = ""; # widest legend string
my $legend_text_width = 0; # width of widest legend string
my $legend_text_height = 0;
my $legend_prefix_width = 0;
# base to subtract prefix itself
# avoid x or y of 0 since illegal for logscale
$extra_gnuplot_cmds .= "set label \"$dummy_prefix\" at 1,1\n";
for ($i=0; $i<$plotcount; $i++) {
# no need to reverse labels: order doesn't matter
$label = sprintf("set label \"%s%s\" at %d,1",
$dummy_prefix, $legend[$i], $i + 1);
$extra_gnuplot_cmds .= "$label\n";
}
###########################################################################
###########################################################################
$use_colors=1;
# some default fig colors
$colornm{'blue'}=1;
$colornm{'green'}=2;
$colornm{'white'}=7;
# custom colors are from 32 onward, we insert them into the fig file
# the order here is the order for 9+ datasets
$basefigcolor=32;
$numfigclrs=0;
$figcolor[$numfigclrs]="#000000"; $fig_black=$colornm{'black'}=$basefigcolor + $numfigclrs++;
$figcolor[$numfigclrs]="#aaaaff"; $fig_light_blue=$colornm{'light_blue'}=$basefigcolor + $numfigclrs++;
$figcolor[$numfigclrs]="#00aa00"; $fig_dark_green=$colornm{'dark_green'}=$basefigcolor + $numfigclrs++;
$figcolor[$numfigclrs]="#77ff00"; $fig_light_green=$colornm{'light_green'}=$basefigcolor + $numfigclrs++;
$figcolor[$numfigclrs]="#ffff00"; $fig_yellow=$colornm{'yellow'}=$basefigcolor + $numfigclrs++;
$figcolor[$numfigclrs]="#ff0000"; $fig_red=$colornm{'red'}=$basefigcolor + $numfigclrs++;
$figcolor[$numfigclrs]="#dd00ff"; $fig_magenta=$colornm{'magenta'}=$basefigcolor + $numfigclrs++;
$figcolor[$numfigclrs]="#0000ff"; $fig_dark_blue=$colornm{'dark_blue'}=$basefigcolor + $numfigclrs++;
$figcolor[$numfigclrs]="#00ffff"; $fig_cyan=$colornm{'cyan'}=$basefigcolor + $numfigclrs++;
$figcolor[$numfigclrs]="#dddddd"; $fig_grey=$colornm{'grey'}=$basefigcolor + $numfigclrs++;
$figcolor[$numfigclrs]="#6666ff"; $fig_med_blue=$colornm{'med_blue'}=$basefigcolor + $numfigclrs++;
$num_nongrayscale = $numfigclrs;
# for grayscale
$figcolor[$numfigclrs]="#222222"; $fig_grey=$colornm{'grey1'}=$basefigcolor + $numfigclrs++;
$figcolor[$numfigclrs]="#444444"; $fig_grey=$colornm{'grey2'}=$basefigcolor + $numfigclrs++;
$figcolor[$numfigclrs]="#666666"; $fig_grey=$colornm{'grey3'}=$basefigcolor + $numfigclrs++;
$figcolor[$numfigclrs]="#888888"; $fig_grey=$colornm{'grey4'}=$basefigcolor + $numfigclrs++;
$figcolor[$numfigclrs]="#aaaaaa"; $fig_grey=$colornm{'grey5'}=$basefigcolor + $numfigclrs++;
$figcolor[$numfigclrs]="#cccccc"; $fig_grey=$colornm{'grey6'}=$basefigcolor + $numfigclrs++;
$figcolor[$numfigclrs]="#eeeeee"; $fig_grey=$colornm{'grey7'}=$basefigcolor + $numfigclrs++;
$figcolorins = "";
for ($i=0; $i<=$#figcolor; $i++) {
$figcolorins .= sprintf("0 %d %s\n", 32+$i, $figcolor[$i]);
}
chomp($figcolorins);
$colorcount = $plotcount; # re-set for color_per_datum below
if ($patterns) {
$colorcount = $max_patterns if ($color_per_datum);
for ($i=0; $i<$colorcount; $i++) {
# cycle around at max
$fillstyle[$i] = 41 + ($i % $max_patterns);
# FIXME: could combine patterns and colors, we don't bother to support that
$fillcolor[$i] = 7; # white
}
} elsif ($use_colors) {
$colorcount = $num_nongrayscale if ($color_per_datum);
# colors: all solid fill
for ($i=0; $i<$colorcount; $i++) {
$fillstyle[$i]=20;
}
if ($custom_colors) {
$colorcount = $#custom_color+1 if ($color_per_datum);
for ($i=0; $i<$colorcount; $i++) {
$fillcolor[$i]=$colornm{$custom_color[$i]};
}
} else {
# color schemes that I tested as providing good contrast when
# printed on a non-color printer.
if ($yerrorbars && $colorcount >= 5) {
# for yerrorbars we avoid using black since the errorbars are black.
# a hack where we take the next-highest set and then remove black:
$colorcount++;
}
if ($colorcount == 1) {
$fillcolor[0]=$fig_light_blue;
} elsif ($colorcount == 2) {
$fillcolor[0]=$fig_med_blue;