← Back to team overview

widelands-dev team mailing list archive

[Merge] lp:~widelands-dev/widelands/bug-1655168-statistics-overlap into lp:widelands

 

Notabilis has proposed merging lp:~widelands-dev/widelands/bug-1655168-statistics-overlap into lp:widelands.

Requested reviews:
  Widelands Developers (widelands-dev)
Related bugs:
  Bug #1655168 in widelands: "statistic window: switch ealier to hours instead of minutes"
  https://bugs.launchpad.net/widelands/+bug/1655168

For more details, see:
https://code.launchpad.net/~widelands-dev/widelands/bug-1655168-statistics-overlap/+merge/323441

Fixing overlap of labels in the plot of the ware statistics.
Also moves y-labels a bit since they overlapped with the axis, especially the min-value in the economy health.

It can still happen that the label "minutes" or the y-labels overlap with the graph. A possible improvement would be to change the drawing order from diagram-data-zeroLine to zeroLine-data-diagram.
-- 
Your team Widelands Developers is requested to review the proposed merge of lp:~widelands-dev/widelands/bug-1655168-statistics-overlap into lp:widelands.
=== modified file 'src/wui/plot_area.cc'
--- src/wui/plot_area.cc	2017-02-24 19:22:36 +0000
+++ src/wui/plot_area.cc	2017-04-30 10:00:24 +0000
@@ -79,7 +79,7 @@
 }
 
 /**
- * scale value down to the available space, which is specifiey by
+ * scale value down to the available space, which is specified by
  * the length of the y axis and the highest scale.
  */
 float scale_value(float const yline_length, uint32_t const highest_scale, int32_t const value) {
@@ -184,6 +184,12 @@
 	dst.blit(point, pic, BlendMode::UseAlpha, UI::Align::kRight);
 }
 
+uint32_t calc_max_ticks(int32_t plot_width) {
+	// Render a number with 3 digits (maximal length which should appear)
+	const Image* pic = UI::g_fh1->render(ytick_text_style(" -888 ", kAxisLineColor));
+	return plot_width / pic->width();
+}
+
 /**
  * draw the background and the axis of the diagram
  */
@@ -218,6 +224,8 @@
 	}
 	// Make sure that we always have a tick
 	how_many_ticks = std::max(how_many_ticks, 1u);
+	// Make sure we haven't more ticks than we have space for -> avoid overlap
+	how_many_ticks = std::min(how_many_ticks, calc_max_ticks(inner_w));
 
 	// first, tile the background
 	dst.tile(Recti(Vector2i(0, 0), inner_w, inner_h), g_gr->images().get(BG_PIC), Vector2i(0, 0));
@@ -460,7 +468,7 @@
 
 	//  print the maximal value into the top right corner
 	draw_value(yscale_label, RGBColor(60, 125, 0),
-	           Vector2f(get_inner_w() - kSpaceRight - 2, kSpacing + 2), dst);
+	           Vector2f(get_inner_w() - kSpaceRight - 3, kSpacing + 2), dst);
 
 	//  plot the pixels
 	for (uint32_t plot = 0; plot < plotdata_.size(); ++plot) {
@@ -646,7 +654,7 @@
 
 	// Print the min value
 	draw_value((boost::format("-%u") % (highest_scale_)).str(), RGBColor(125, 0, 0),
-	           Vector2f(get_inner_w() - kSpaceRight - 2, get_inner_h() - kSpacing - 15), dst);
+	           Vector2f(get_inner_w() - kSpaceRight - 3, get_inner_h() - kSpacing - 23), dst);
 
 	// draw zero line
 	dst.draw_line_strip({Vector2f(get_inner_w() - kSpaceRight, yoffset),


Follow ups