📄 make-barchart.prl
字号:
#!/usr/local/bin/perl5 -w## Copyright (C) 1996-1998 by the Board of Trustees# of Leland Stanford Junior University.# # This file is part of the SimOS distribution. # See LICENSE file for terms of the license. ## This script should make a stacked bar chart from data of the# following form. Order is unimportant, and items preceded by a * are# optional ## GROUPS <number of different clusters of bars># SETS <number of sets in a group># SECTIONS <number of sections in a single bar># GROUP_LABELS <label1> <label2> ...# SET_LABELS <label1> <label2> ...# SECTION_LABELS <label1> <label2> ...# EXCLUDE_KEY# *NEW_HEIGHT <inches># *SET_LABEL_ALIGNMENT <center|left|right># *KEY_XPOS <group num> <set num># *X_LABEL <label for x axis># *Y_LABEL <label for y axis># *COLOR <section num> [color foo | grey 0.x] # *CONNECT_SECTIONS <num1> <num2> ...# *SEPARATE_SECTIONS <num1> <num2> ...# *TITLE <title for graph># *MAXY <maximum y value># *NO_X_STAGGER# *TOP_SET_LABELS <label1> <label2> ...# *NUM_SUPERGROUPS <numSuperGroups># *GROUPS_PER_SUPERGROUP <barsPerSuperGroup># *SUPERGROUP_LABELS <label1> <label2> ...# *KEY_BOX_UPPER_LEFT <x-value> <y-value> # *KEY_BOX_LOWER_RIGHT <x-value> <y-value># D <group #> <section #> <size of 1st block> <size of 2nd block> ...## Comments can be included with a # at the start of a line# Graph Variables$WIDTH = 2.8;$HEIGHT = 1.9;$YMIN = 0;$YMAX = 100;$NUM_TICKS = 5;$MAX_NUM = 50;# Fonts$TITLE_FONT = "helvetica8b";$GROUP_FONT = "helvetica6b";$SET_FONT = "helvetica6";$GRAPH_FONT = "helvetica6";$TIC_FONT = "helvetica4";$AXIS_FONT = "helvetica6";# Local IFDEF-like variables$EXCLUDE_KEY = 0; # Set in input file to not use a key$DEBUG = 0; # Set to print out all kinds of info$COLOR = 1; # Set to print pretty color graphs################################################################## Procedure for printing text in splot################################################################sub PrintText {# ARGS(x-pos, y-pos, text, font, alignment, angle) my $x = shift; my $y = shift; my $text = shift; my $font = shift; my $alignment = shift || "center"; my $angle = shift || 0; $text =~ s/_/ /g; printf "\n\nnew text $x, $y\n"; printf "%s\n\n", $text; printf "text font %s\n", $font; printf "text align $alignment\n\n"; if ($angle) { printf "text angle $angle\n"; }}################################################################## Procedure for printing a splot curve header#################################################################sub PrintHeader {# ARGS(label, type, color) my $label = shift; my $type = shift; my $color = shift; my $curvemat = shift; printf "\nnew curve\n"; if ($label ne "") { if ($label eq "BLANK") { printf "curve label \n"; } else { printf "curve label $label\n"; } } if ($type ne "") { printf "curve type $type\n"; } if (defined($curvemat)) { # print STDERR "defining curvemat '$curvemat' for $label \n"; print "curve mat $curvemat \n"; } else { printf "curve $color\n"; } printf "new points\n";}################################################################## Procedure for drawing a line#################################################################sub DrawLine {# ARGS(x1, y1, x2, y2) my $x1 = shift; my $y1 = shift; my $x2 = shift; my $y2 = shift; PrintHeader("", "bold", "color black"); printf "$x1, $y1\n"; printf "$x2, $y2\n";}################################################################## Procedure for figuring out the x position of a set or group#################################################################sub GroupLocation { # ARGS(group_num) my $group_num = shift; return ($num_sets*2+1)*$group_num + ($num_sets*2+1)/2 + $extra_space[$group_num];}sub SetLocation {# ARGS(group_num, set_num, slack) my $group_num = shift; my $set_num = shift; my $slack = shift; return (($num_sets*2+1) * $group_num) + $extra_space[$group_num] + (2 * $set_num) + $slack;}sub Debug { my $string = shift; printf STDERR $string;}################################################################## Setup arrays containing information for each variable we are# collecting data on.################################################################## Setup colorsif ($COLOR == 1) { $COLOR[7] = "color green"; $COLOR[6] = "color black"; $COLOR[5] = "color purple"; $COLOR[4] = "color blue"; $COLOR[3] = "color aquamarine"; $COLOR[2] = "color red"; $COLOR[1] = "color yellow"; $COLOR[0] = "color green";} else { $COLOR[7] = "gray .7"; $COLOR[6] = "gray .5"; $COLOR[5] = "gray .2"; $COLOR[4] = "gray .9"; $COLOR[3] = "gray .1"; $COLOR[2] = "gray .8"; $COLOR[1] = "gray .0"; $COLOR[0] = "gray .7";}################################################################# Initialization - keep perl quiet################################################################for ($i=0; $i <= $MAX_NUM; $i++) { $extra_space[$i] = 0; $top_set_label[$i] = "BLANK";}$num_groups = 0;$num_sets = 0;$num_sections = 0;$custom_key_position = 0;$no_x_stagger = 0;$set_label_alignment = "center";$num_supergroups = 0;$num_supersets = 0;$rotate_set_labels = 0;$key_box_x1 = 0;################################################################## Process the input file#################################################################while (<>) { if (/^MAXY(.*)/) { @fields = split; $YMAX = $fields[1]; } if (/^GROUPS(.*)/) { @fields = split; $num_groups = $fields[1]; Debug("Num groups $num_groups\n"); } if (/^SETS(.*)/) { @fields = split; $num_sets = $fields[1]; Debug("Num sets $num_sets\n"); } if (/^SECTIONS(.*)/) { @fields = split; $num_sections = $fields[1]; Debug("Num sections $num_sections\n"); } if (/^EXCLUDE_KEY/) { $EXCLUDE_KEY = 1; } if (/^GROUP_LABELS(.*)/) { @fields = split; for ($i=0; $i < $num_groups; $i++) { $group_label[$i] = $fields[$i+1]; } } if (/^SET_LABELS(.*)/) { @fields = split; for ($i=0; $i < $num_sets; $i++) { $set_label[$i] = $fields[$i+1]; } } if (/^NEW_HEIGHT(.*)/) { @fields = split; $HEIGHT = $fields[1]; } if (/^ROTATE_SET_LABELS/) { $rotate_set_labels = 90; Debug("Rotating set labels\n"); } if (/^TOP_SET_LABELS(.*)/) { @fields = split; for ($i=0; $i < $num_sets; $i++) { $top_set_label[$i] = $fields[$i+1]; } } if (/^NUM_SUPERSETS(.*)/) { @fields = split; $num_supersets = $fields[1]; } if (/^SETS_PER_SUPERSET(.*)/) { @fields = split; $sets_per_superset = $fields[1]; } if (/^SUPERSET_LABELS(.*)/) { @fields = split; for ($i=0; $i < $num_supersets; $i++) { $superset_label[$i] = $fields[$i+1]; } } if (/^GROUPS_PER_SUPERGROUPS(.*)/) { @fields = split; $groups_per_supergroup = $fields[1]; } if (/^NUM_SUPER_GROUPS(.*)/) { @fields = split; $num_supergroups = $fields[1]; } if (/^SUPER_GROUP_LABELS(.*)/) { @fields = split; for ($i=0; $i < $num_supergroups; $i++) { $supergroup_label[$i] = $fields[$i+1]; } } if (/^SET_LABEL_ALIGNMENT(.*)/) { @fields = split; $set_label_alignment = $fields[1]; } if (/^KEY_XPOS(.*)/) { @fields = split; $custom_key_position = 1; $key_group = $fields[1]; $key_set = $fields[2]; } if (/^SECTION_LABELS(.*)/) { @fields = split; for ($i=0; $i < $num_sections; $i++) { $section_label[$i] = $fields[$i+1]; } } if (/^EXTRA_GROUP_SPACE /) { @fields = split(' ',$'); foreach $group (@fields) { $extra_space[$group]++; } } if (/^COLOR\s(\d)/) { $group = $1; $COLOR[$group] = $'; } if (/CURVEMAT\s(\d)/) { $group = $1; $CURVEMAT[$group] = $'; } if (/^CONNECT_SECTIONS /) { @fields = split(' ',$'); $connect_sections = 1; foreach $sec (@fields) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -