src/graph_gui.cpp
changeset 7487 9ef3bd32c2eb
parent 6987 b0f13039bda2
child 7498 ce6588257e8d
equal deleted inserted replaced
7486:d130c10f4dab 7487:9ef3bd32c2eb
    62 
    62 
    63 	int left, top;  ///< Where to start drawing the graph, in pixels.
    63 	int left, top;  ///< Where to start drawing the graph, in pixels.
    64 	uint height;    ///< The height of the graph in pixels.
    64 	uint height;    ///< The height of the graph in pixels.
    65 	StringID format_str_y_axis;
    65 	StringID format_str_y_axis;
    66 	byte colors[GRAPH_MAX_DATASETS];
    66 	byte colors[GRAPH_MAX_DATASETS];
    67 	int64 cost[GRAPH_MAX_DATASETS][24]; ///< last 2 years
    67 	Money cost[GRAPH_MAX_DATASETS][24]; ///< last 2 years
    68 };
    68 };
    69 
    69 
    70 static void DrawGraph(const GraphDrawer *gw)
    70 static void DrawGraph(const GraphDrawer *gw)
    71 {
    71 {
    72 	uint x, y;            ///< Reused whenever x and y coordinates are needed.
    72 	uint x, y;            ///< Reused whenever x and y coordinates are needed.
   130 	highest_value = x_axis_offset * 2;
   130 	highest_value = x_axis_offset * 2;
   131 
   131 
   132 	for (int i = 0; i < gw->num_dataset; i++) {
   132 	for (int i = 0; i < gw->num_dataset; i++) {
   133 		if (!HASBIT(gw->excluded_data, i)) {
   133 		if (!HASBIT(gw->excluded_data, i)) {
   134 			for (int j = 0; j < gw->num_on_x_axis; j++) {
   134 			for (int j = 0; j < gw->num_on_x_axis; j++) {
   135 				int64 datapoint = gw->cost[i][j];
   135 				Money datapoint = gw->cost[i][j];
   136 
   136 
   137 				if (datapoint != INVALID_DATAPOINT) {
   137 				if (datapoint != INVALID_DATAPOINT) {
   138 					/* For now, if the graph has negative values the scaling is
   138 					/* For now, if the graph has negative values the scaling is
   139 					 * symmetrical about the x axis, so take the absolute value
   139 					 * symmetrical about the x axis, so take the absolute value
   140 					 * of each data point. */
   140 					 * of each data point. */
   212 			byte color  = gw->colors[i];
   212 			byte color  = gw->colors[i];
   213 			uint prev_x = INVALID_DATAPOINT_POS;
   213 			uint prev_x = INVALID_DATAPOINT_POS;
   214 			uint prev_y = INVALID_DATAPOINT_POS;
   214 			uint prev_y = INVALID_DATAPOINT_POS;
   215 
   215 
   216 			for (int j = 0; j < gw->num_on_x_axis; j++) {
   216 			for (int j = 0; j < gw->num_on_x_axis; j++) {
   217 				int64 datapoint = gw->cost[i][j];
   217 				Money datapoint = gw->cost[i][j];
   218 
   218 
   219 				if (datapoint != INVALID_DATAPOINT) {
   219 				if (datapoint != INVALID_DATAPOINT) {
   220 					/* XXX: This can overflow if x_axis_offset * datapoint is
   220 					/* XXX: This can overflow if x_axis_offset * datapoint is
   221 					 * too big to fit in an int64. */
   221 					 * too big to fit in an int64. */
   222 					y = gw->top + x_axis_offset - (x_axis_offset * datapoint) / highest_value;
   222 					y = gw->top + x_axis_offset - (x_axis_offset * datapoint) / highest_value;