[GRASS-SVN] r69621 - grass/trunk/display/d.linegraph

svn_grass at osgeo.org svn_grass at osgeo.org
Sat Oct 1 13:59:34 PDT 2016


Author: wenzeslaus
Date: 2016-10-01 13:59:33 -0700 (Sat, 01 Oct 2016)
New Revision: 69621

Modified:
   grass/trunk/display/d.linegraph/Makefile
   grass/trunk/display/d.linegraph/main.c
Log:
d.linegraph: support color table for individual variables

Modified: grass/trunk/display/d.linegraph/Makefile
===================================================================
--- grass/trunk/display/d.linegraph/Makefile	2016-10-01 20:48:55 UTC (rev 69620)
+++ grass/trunk/display/d.linegraph/Makefile	2016-10-01 20:59:33 UTC (rev 69621)
@@ -2,8 +2,8 @@
 
 PGM = d.linegraph
 
-LIBES = $(DISPLAYLIB) $(GISLIB)
-DEPENDENCIES = $(DISPLAYDEP) $(GISDEP)
+LIBES = $(DISPLAYLIB) $(GISLIB) $(RASTERLIB)
+DEPENDENCIES = $(DISPLAYDEP) $(GISDEP) $(RASTERDEP)
 
 include $(MODULE_TOPDIR)/include/Make/Module.make
 

Modified: grass/trunk/display/d.linegraph/main.c
===================================================================
--- grass/trunk/display/d.linegraph/main.c	2016-10-01 20:48:55 UTC (rev 69620)
+++ grass/trunk/display/d.linegraph/main.c	2016-10-01 20:59:33 UTC (rev 69621)
@@ -86,6 +86,7 @@
     {
 	int num_pnts;		/* number of lines in file  */
 	int color;		/* color to use for y lines */
+        int r, g, b;
 	float max;		/* maximum value in file    */
 	float min;		/* minimum value in file    */
 	float value;		/* current value read in    */
@@ -112,6 +113,7 @@
 
     struct Option *dir_opt, *x_opt, *y_opt;
     struct Option *y_color_opt;
+    struct Option *color_table_opt;
     struct Option *title[3];
     struct Option *t_color_opt;
     struct Option *y_min, *y_max;
@@ -156,6 +158,10 @@
     y_color_opt->gisprompt = "old_color,color,color";
     y_color_opt->answers = NULL;
 
+    color_table_opt = G_define_standard_option(G_OPT_M_COLR);
+    color_table_opt->key = "color_table";
+    color_table_opt->guisection = _("Define");
+
     t_color_opt = G_define_option();
     t_color_opt->key = "title_color";
     t_color_opt->description = _("Color for axis, tics, numbers, and title");
@@ -271,6 +277,29 @@
 	    G_fatal_error(_("Only <%d> colors given for <%d> lines"), j,
 			  num_y_files);
     }
+    else if (color_table_opt->answer) {
+        struct Colors colors;
+        Rast_init_colors(&colors);
+        Rast_make_colors(&colors, color_table_opt->answer, 1, num_y_files);
+        int* values = G_malloc(sizeof(int));
+        unsigned char* r = G_malloc(sizeof(unsigned char));
+        unsigned char* g = G_malloc(sizeof(unsigned char));
+        unsigned char* b = G_malloc(sizeof(unsigned char));
+        unsigned char* set = G_malloc(sizeof(unsigned char));
+        for (i = 0; i < num_y_files; i++)
+            values[i] = i + 1;
+        Rast_lookup_c_colors(values, r, g, b, set, num_y_files, &colors);
+        for (i = 0; i < num_y_files; i++) {
+            /* the in list is indexed from 1 */
+            in[i + 1].r = r[i];
+            in[i + 1].g = g[i];
+            in[i + 1].b = b[i];
+        }
+        G_free(r);
+        G_free(g);
+        G_free(b);
+        G_free(set);
+    }
     else
 	/* no colors given on command line, use default list */
     {
@@ -417,7 +446,10 @@
 
 		/* draw increment of each Y file's data */
 
-		D_use_color(in[i].color);
+                if (color_table_opt->answer)
+                    D_RGB_color(in[i].r, in[i].g, in[i].b);
+                else
+                    D_use_color(in[i].color);
 
 		/* find out position of where Y should be drawn. */
 		/* if our minimum value of y is not negative, this is easy */



More information about the grass-commit mailing list