commit 3167fce5ce254c0cd71891b929c324ced2fd5325 from: rsc date: Sun May 21 15:56:16 2006 UTC colors (Gregor Asplund) commit - dff99a80b6e4c4b2024b346cc4e39db35f877d91 commit + 3167fce5ce254c0cd71891b929c324ced2fd5325 blob - d602f83ea119f34f9ed86a62afbd1d532eb7a56a blob + e82d312620f9c2d1565d6c8f2623abc7889afe7c --- man/man1/graph.1 +++ 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 blob - 3e740cb07a2a345e582f259ac00c3caa2abe5c7b blob + 336b0b183077edb09e70c12f37a77fe1ec278800 --- src/cmd/graph/graph.c +++ 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(); } @@ -264,6 +284,26 @@ numb(float *np, int *argcp, char ***argvp){ (*argcp)--; (*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