X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Foutput%2Fcharts%2Fplot-chart.c;h=5641db1213be2cd070d66cffb7daf479823076f6;hb=c4d3dc3d90c9a34ac2f0989dc0ede812a8b85c49;hp=5b6618e518c88bbe87bb55875092c7d4461d80d8;hpb=f5c108becd49d78f4898cab11352291f5689d24e;p=pspp-builds.git diff --git a/src/output/charts/plot-chart.c b/src/output/charts/plot-chart.c index 5b6618e5..5641db12 100644 --- a/src/output/charts/plot-chart.c +++ b/src/output/charts/plot-chart.c @@ -1,20 +1,18 @@ -/* PSPP - computes sample statistics. - Copyright (C) 2004 Free Software Foundation, Inc. +/* PSPP - a program for statistical analysis. + Copyright (C) 2004, 2009 Free Software Foundation, Inc. - 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 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 3 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. + 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., 51 Franklin Street, Fifth Floor, Boston, MA - 02110-1301, USA. */ + along with this program. If not, see . */ #include @@ -34,23 +32,24 @@ #include -#include #include #include #include +#include "xalloc.h" -const char *const data_colour[] = { - "brown", - "red", - "orange", - "yellow", - "green", - "blue", - "violet", - "grey", - "pink" -}; +const char *const data_colour[N_CHART_COLOURS] = + { + "brown", + "red", + "orange", + "yellow", + "green", + "blue", + "violet", + "grey", + "pink" + }; @@ -211,3 +210,47 @@ chart_write_ylabel(struct chart *ch, const char *label) pl_restorestate_r(ch->lp); } + + +void +chart_write_legend (struct chart *ch) +{ + int i; + const int vstep = ch->font_size * 2; + const int xpad = 10; + const int ypad = 10; + const int swatch = 20; + const int legend_top = ch->data_top; + const int legend_bottom = legend_top - + (vstep * ch->n_datasets + 2 * ypad ); + + if ( ! ch ) + return ; + + pl_savestate_r (ch->lp); + + pl_box_r (ch->lp, ch->legend_left, legend_top, + ch->legend_right - xpad, legend_bottom); + + for (i = 0 ; i < ch->n_datasets ; ++i ) + { + const int ypos = vstep * (i + 1); + const int xpos = ch->legend_left + xpad; + pl_move_r (ch->lp, xpos, legend_top - ypos); + + pl_savestate_r(ch->lp); + pl_fillcolorname_r (ch->lp, data_colour [ i % N_CHART_COLOURS]); + + pl_pentype_r (ch->lp, 1); + pl_filltype_r (ch->lp, 1); + pl_boxrel_r (ch->lp, 0, 0, swatch, swatch); + + + pl_moverel_r (ch->lp, swatch, 0); + pl_alabel_r (ch->lp, 0, 0, ch->dataset[i]); + + pl_restorestate_r (ch->lp); + } + + pl_restorestate_r (ch->lp); +}