src/graph_gui.cpp
changeset 5777 6a780a23cb59
parent 5776 d36a554d7ccd
child 5778 94301697f913
equal deleted inserted replaced
5776:d36a554d7ccd 5777:6a780a23cb59
    63 
    63 
    64 static const int64 INVALID_VALUE = 0x80000000;
    64 static const int64 INVALID_VALUE = 0x80000000;
    65 
    65 
    66 static void DrawGraph(const GraphDrawer *gw)
    66 static void DrawGraph(const GraphDrawer *gw)
    67 {
    67 {
    68 
       
    69 	int i,j,k;
       
    70 	uint x,y,old_x,old_y;
    68 	uint x,y,old_x,old_y;
    71 	int right;
    69 	int right;
    72 	int num_x, num_dataset;
    70 	int num_x, num_dataset;
    73 	const int64 *row_ptr, *col_ptr;
    71 	const int64 *row_ptr, *col_ptr;
    74 	int64 mx;
    72 	int64 mx;
   172 
   170 
   173 	/* draw strings on the x axis */
   171 	/* draw strings on the x axis */
   174 	if (gw->month != 0xFF) {
   172 	if (gw->month != 0xFF) {
   175 		x = gw->left + GRAPH_X_POSITION_BEGINNING;
   173 		x = gw->left + GRAPH_X_POSITION_BEGINNING;
   176 		y = gw->top + gw->height + 1;
   174 		y = gw->top + gw->height + 1;
   177 		j = gw->month;
   175 		byte month = gw->month;
   178 		k = gw->year;
   176 		Year year  = gw->year;
   179 		i = gw->num_on_x_axis;assert(i>0);
   177 		for (int i = 0; i < gw->num_on_x_axis; i++) {
   180 		do {
   178 			SetDParam(0, month + STR_0162_JAN);
   181 			SetDParam(2, k);
   179 			SetDParam(1, month + STR_0162_JAN + 2);
   182 			SetDParam(0, j + STR_0162_JAN);
   180 			SetDParam(2, year);
   183 			SetDParam(1, j + STR_0162_JAN + 2);
   181 			DrawString(x, y, month == 0 ? STR_016F : STR_016E, GRAPH_AXIS_LABEL_COLOUR);
   184 			DrawString(x, y, j == 0 ? STR_016F : STR_016E, GRAPH_AXIS_LABEL_COLOUR);
   182 
   185 
   183 			month += 3;
   186 			j += 3;
   184 			if (month >= 12) {
   187 			if (j >= 12) {
   185 				month = 0;
   188 				j = 0;
   186 				year++;
   189 				k++;
       
   190 			}
   187 			}
   191 			x += GRAPH_X_POSITION_SEPARATION;
   188 			x += GRAPH_X_POSITION_SEPARATION;
   192 		} while (--i);
   189 		}
   193 	} else {
   190 	} else {
   194 		/* Add 8 to make the string appear centred between the lines. */
   191 		/* Add 8 to make the string appear centred between the lines. */
   195 		x = gw->left + GRAPH_X_POSITION_BEGINNING + 8;
   192 		x = gw->left + GRAPH_X_POSITION_BEGINNING + 8;
   196 		y = gw->top + gw->height + 1;
   193 		y = gw->top + gw->height + 1;
   197 		uint16 label = gw->x_values_start;
   194 		uint16 label = gw->x_values_start;
   203 			x += GRAPH_X_POSITION_SEPARATION;
   200 			x += GRAPH_X_POSITION_SEPARATION;
   204 		}
   201 		}
   205 	}
   202 	}
   206 
   203 
   207 	/* draw lines and dots */
   204 	/* draw lines and dots */
   208 	i = 0;
       
   209 	row_ptr = gw->cost[0];
   205 	row_ptr = gw->cost[0];
   210 	sel = gw->sel; // show only selected lines. GraphDrawer qw->sel set in Graph-Legend (_legend_excludebits)
   206 	sel = gw->sel; // show only selected lines. GraphDrawer qw->sel set in Graph-Legend (_legend_excludebits)
   211 	do {
   207 
       
   208 	for (int i = 0; i < gw->num_dataset; i++) {
   212 		if (!(sel & 1)) {
   209 		if (!(sel & 1)) {
   213 			/* Centre the dot between the grid lines. */
   210 			/* Centre the dot between the grid lines. */
   214 			x = gw->left + GRAPH_X_POSITION_BEGINNING + (GRAPH_X_POSITION_SEPARATION / 2);
   211 			x = gw->left + GRAPH_X_POSITION_BEGINNING + (GRAPH_X_POSITION_SEPARATION / 2);
   215 			col_ptr = row_ptr;
   212 			col_ptr = row_ptr;
   216 			byte color = gw->colors[i];
   213 			byte color = gw->colors[i];
   231 					old_x = INVALID_VALUE;
   228 					old_x = INVALID_VALUE;
   232 				}
   229 				}
   233 				x += GRAPH_X_POSITION_SEPARATION;
   230 				x += GRAPH_X_POSITION_SEPARATION;
   234 			}
   231 			}
   235 		}
   232 		}
   236 	} while (sel>>=1,row_ptr+=24, ++i < gw->num_dataset);
   233 		sel >>= 1;
       
   234 		row_ptr += 24;
       
   235 	}
   237 }
   236 }
   238 
   237 
   239 /****************/
   238 /****************/
   240 /* GRAPH LEGEND */
   239 /* GRAPH LEGEND */
   241 /****************/
   240 /****************/