From b4ab43be5f2067e161939c87230a0d2ad9bdd952 Mon Sep 17 00:00:00 2001 From: fonsinchen Date: Sun, 9 Jun 2013 13:07:53 +0000 Subject: (svn r25364) -Add: support for flow stats to linkgraph overlay --- src/linkgraph/linkgraph_gui.cpp | 10 ++++++---- src/linkgraph/linkgraph_gui.h | 5 +++-- 2 files changed, 9 insertions(+), 6 deletions(-) (limited to 'src/linkgraph') diff --git a/src/linkgraph/linkgraph_gui.cpp b/src/linkgraph/linkgraph_gui.cpp index f272d287c..f0debfb87 100644 --- a/src/linkgraph/linkgraph_gui.cpp +++ b/src/linkgraph/linkgraph_gui.cpp @@ -149,7 +149,7 @@ void LinkGraphOverlay::AddLinks(const Station *from, const Station *to) ConstEdge edge = lg[ge.node][to->goods[c].node]; if (edge.Capacity() > 0) { this->AddStats(lg.Monthly(edge.Capacity()), lg.Monthly(edge.Usage()), - this->cached_links[from->index][to->index]); + ge.GetSumFlowVia(to->index), this->cached_links[from->index][to->index]); } } } @@ -160,13 +160,14 @@ void LinkGraphOverlay::AddLinks(const Station *from, const Station *to) * @param new_plan Planned flow for the link. * @param cargo LinkProperties to write the information to. */ -/* static */ void LinkGraphOverlay::AddStats(uint new_cap, uint new_usg, LinkProperties &cargo) +/* static */ void LinkGraphOverlay::AddStats(uint new_cap, uint new_usg, uint new_plan, LinkProperties &cargo) { /* multiply the numbers by 32 in order to avoid comparing to 0 too often. */ if (cargo.capacity == 0 || - cargo.usage * 32 / (cargo.capacity + 1) < new_usg * 32 / (new_cap + 1)) { + max(cargo.usage, cargo.planned) * 32 / (cargo.capacity + 1) < max(new_usg, new_plan) * 32 / (new_cap + 1)) { cargo.capacity = new_cap; cargo.usage = new_usg; + cargo.planned = new_plan; } } @@ -209,7 +210,8 @@ void LinkGraphOverlay::DrawContent(Point pta, Point ptb, const LinkProperties &c int offset_y = (pta.x < ptb.x ? 1 : -1) * this->scale; int offset_x = (pta.y > ptb.y ? 1 : -1) * this->scale; - int colour = LinkGraphOverlay::LINK_COLOURS[cargo.usage * lengthof(LinkGraphOverlay::LINK_COLOURS) / (cargo.capacity * 2 + 2)]; + uint usage_or_plan = min(cargo.capacity * 2 + 1, max(cargo.usage, cargo.planned)); + int colour = LinkGraphOverlay::LINK_COLOURS[usage_or_plan * lengthof(LinkGraphOverlay::LINK_COLOURS) / (cargo.capacity * 2 + 2)]; GfxDrawLine(pta.x + offset_x, pta.y, ptb.x + offset_x, ptb.y, colour, scale); GfxDrawLine(pta.x, pta.y + offset_y, ptb.x, ptb.y + offset_y, colour, scale); diff --git a/src/linkgraph/linkgraph_gui.h b/src/linkgraph/linkgraph_gui.h index fe87a0464..6edcb38a4 100644 --- a/src/linkgraph/linkgraph_gui.h +++ b/src/linkgraph/linkgraph_gui.h @@ -23,10 +23,11 @@ * Properties of a link between two stations. */ struct LinkProperties { - LinkProperties() : capacity(0), usage(0) {} + LinkProperties() : capacity(0), usage(0), planned(0) {} uint capacity; ///< Capacity of the link. uint usage; ///< Actual usage of the link. + uint planned; ///< Planned usage of the link. }; /** @@ -85,7 +86,7 @@ protected: bool IsPointVisible(Point pt, const DrawPixelInfo *dpi, int padding = 0) const; void GetWidgetDpi(DrawPixelInfo *dpi) const; - static void AddStats(uint new_cap, uint new_usg, LinkProperties &cargo); + static void AddStats(uint new_cap, uint new_usg, uint new_flow, LinkProperties &cargo); static void DrawVertex(int x, int y, int size, int colour, int border_colour); }; -- cgit v1.2.3-54-g00ecf