Changeset - r14937:65047ab44d07
[Not reviewed]
master
0 1 0
terkhen - 14 years ago 2010-04-03 19:32:14
terkhen@openttd.org
(svn r19550) -Fix (r19543): Scale graphs without taking into account excluded data.
1 file changed with 4 insertions and 3 deletions:
0 comments (0 inline, 0 general)
src/graph_gui.cpp
Show inline comments
 
@@ -191,33 +191,34 @@ protected:
 

	
 
	/* These values are used if the graph is being plotted against values
 
	 * rather than the dates specified by month and year. */
 
	uint16 x_values_start;
 
	uint16 x_values_increment;
 

	
 
	int graph_widget;
 
	StringID format_str_y_axis;
 
	byte colours[GRAPH_MAX_DATASETS];
 
	OverflowSafeInt64 cost[GRAPH_MAX_DATASETS][GRAPH_NUM_MONTHS]; ///< Stored costs for the last #GRAPH_NUM_MONTHS months
 

	
 
	/**
 
	 * Get the highest value of the graph's data. Excluded data is taken into account too, to prevent the graph
 
	 * from changing its size when enabling / disabling data.
 
	 * @return Highest value of the graph.
 
	 * Get the highest value of the graph's data. Excluded data is ignored to allow showing smaller values in
 
	 * better detail when disabling higher ones.
 
	 * @return Highest value of the graph (ignoring disabled data).
 
	 */
 
	int64 GetHighestValue() const
 
	{
 
		OverflowSafeInt64 highest_value = 0;
 

	
 
		for (int i = 0; i < this->num_dataset; i++) {
 
			if (HasBit(this->excluded_data, i)) continue;
 
			for (int j = 0; j < this->num_on_x_axis; j++) {
 
				OverflowSafeInt64 datapoint = this->cost[i][j];
 

	
 
				if (datapoint != INVALID_DATAPOINT) {
 
					/* For now, if the graph has negative values the scaling is
 
					 * symmetrical about the x axis, so take the absolute value
 
					 * of each data point. */
 
					highest_value = max(highest_value, abs(datapoint));
 
				}
 
			}
 
		}
 

	
0 comments (0 inline, 0 general)