(svn r25364) -Add: support for flow stats to linkgraph overlay

This commit is contained in:
fonsinchen 2013-06-09 13:07:53 +00:00
parent 0e5fa8d195
commit b4ab43be5f
2 changed files with 9 additions and 6 deletions

View File

@ -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);

View File

@ -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);
};