aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrsc <devnull@localhost>2006-05-21 15:56:16 +0000
committerrsc <devnull@localhost>2006-05-21 15:56:16 +0000
commit3167fce5ce254c0cd71891b929c324ced2fd5325 (patch)
treed1c8860c2d7e8485700627e5ed508512015f0fcd
parentdff99a80b6e4c4b2024b346cc4e39db35f877d91 (diff)
downloadplan9port-3167fce5ce254c0cd71891b929c324ced2fd5325.tar.gz
plan9port-3167fce5ce254c0cd71891b929c324ced2fd5325.tar.bz2
plan9port-3167fce5ce254c0cd71891b929c324ced2fd5325.zip
colors (Gregor Asplund)
-rw-r--r--man/man1/graph.17
-rw-r--r--src/cmd/graph/graph.c42
2 files changed, 49 insertions, 0 deletions
diff --git a/man/man1/graph.1 b/man/man1/graph.1
index d602f83e..e82d3126 100644
--- a/man/man1/graph.1
+++ b/man/man1/graph.1
@@ -85,6 +85,13 @@ with each abscissa value.
The next argument is
.IR n .
.TP
+.B -p
+Next argument is one or more of the characters
+.B bcgkmrwy,
+choosing pen colors by their initial letter, as in
+.IR plot (6).
+Successive curves will cycle through the colors in the given order.
+.TP
.B -s
Save screen; no new page for this graph.
.TP
diff --git a/src/cmd/graph/graph.c b/src/cmd/graph/graph.c
index 3e740cb0..336b0b18 100644
--- a/src/cmd/graph/graph.c
+++ b/src/cmd/graph/graph.c
@@ -63,6 +63,22 @@ double ident(double x){
struct z {
float lb,ub,mult,quant;
};
+
+struct {
+ char *name;
+ int next;
+} palette[] = {
+ ['b'] { "blue", 'b' },
+ ['c'] { "cyan", 'c' },
+ ['g'] { "green", 'g' },
+ ['k'] { "kblack", 'k' },
+ ['m'] { "magenta", 'm' },
+ ['r'] { "red", 'r' },
+ ['w'] { "white", 'w' },
+ ['y'] { "yellow", 'y' }
+};
+int pencolor = 'k';
+
void init(struct xy *);
void setopt(int, char *[]);
void readin(void);
@@ -72,6 +88,7 @@ void equilibrate(struct xy *, struct xy *);
void scale(struct xy *);
void limread(struct xy *, int *, char ***);
int numb(float *, int *, char ***);
+void colread(int *, char ***);
int copystring(int);
struct z setloglim(int, int, float, float);
struct z setlinlim(int, int, float, float);
@@ -221,6 +238,9 @@ again: switch(argv[0][0]) {
if(!numb(&yd.xoff,&argc,&argv))
badarg();
break;
+ case 'p': /*pen color*/
+ colread(&argc, &argv);
+ break;
default:
badarg();
}
@@ -266,6 +286,26 @@ numb(float *np, int *argcp, char ***argvp){
return(1);
}
+void colread(int *argcp, char ***argvp){
+ int c, cnext;
+ int i, n;
+
+ if(*argcp<=1)
+ return;
+ n = strlen((*argvp)[1]);
+ if(strspn((*argvp)[1], "bcgkmrwy")!=n)
+ return;
+ pencolor = cnext = (*argvp)[1][0];
+ for(i=0; i<n-1; i++){
+ c = (unsigned char)(*argvp)[1][i];
+ cnext = (unsigned char)(*argvp)[1][i+1];
+ palette[c].next = cnext;
+ }
+ palette[cnext].next = pencolor;
+ (*argcp)--;
+ (*argvp)++;
+}
+
void readin(void){
int i, t;
struct val *temp;
@@ -599,6 +639,7 @@ void plot(void){
default:
pen(modes[mode]);
}
+ color(palette[pencolor].name);
conn = 0;
for(i=j; i<n; i+=ovlay) {
if(!conv(xx[i].xv,&xd,&ix) ||
@@ -615,6 +656,7 @@ void plot(void){
}
conn &= symbol(ix,iy,xx[i].lblptr);
}
+ pencolor = palette[pencolor].next;
}
pen(modes[1]);
}