[gnome-maps] transitPlan: Add function to get compact route labels
- From: Marcus Lundblad <mlundblad src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-maps] transitPlan: Add function to get compact route labels
- Date: Tue, 27 Jun 2017 20:21:21 +0000 (UTC)
commit d81b7a958d19329e6b82a8545880d873c5148d2b
Author: Marcus Lundblad <ml update uu se>
Date: Tue Jun 27 22:15:20 2017 +0200
transitPlan: Add function to get compact route labels
This was moved from the TransitRouteLabel class to be used
when rendering itinerary overviews.
https://bugzilla.gnome.org/show_bug.cgi?id=784231
src/transitPlan.js | 33 +++++++++++++++++++++++++++++++++
1 files changed, 33 insertions(+), 0 deletions(-)
---
diff --git a/src/transitPlan.js b/src/transitPlan.js
index 13c7cc1..e08fa2d 100644
--- a/src/transitPlan.js
+++ b/src/transitPlan.js
@@ -419,12 +419,45 @@ const Leg = new Lang.Class({
this.parent(params);
this.bbox = this._createBBox();
+
+ this._compactRoute = null;
},
get route() {
return this._route;
},
+ // try to get a shortened route name, suitable for overview rendering
+ get compactRoute() {
+ if (this._compactRoute)
+ return this._compactRoute;
+
+ if (this._route.startsWith(this._agencyName)) {
+ /* if the agency name is a prefix of the route name, display the
+ * agency name in the overview, this way we get a nice "transition"
+ * into the expanded route showing the full route name
+ */
+ this._compactRoute = this._agencyName;
+ } else if (this._tripShortName &&
+ (this._agencyName.length < this._tripShortName.length)) {
+ /* if the agency name is shorter than the trip short name,
+ * which can sometimes be a more "internal" number, like a
+ * "train number", which is less known by the general public,
+ * prefer the agency name */
+ this._compactRoute = this._agencyName;
+ } else if (this._tripShortName && this._tripShortName.length <= 6) {
+ /* if the above conditions are unmet, use the trip short name
+ * as a fallback if it was shorter than the original route name */
+ this._compactRoute = this._tripShortName;
+ } else {
+ /* if none of the above is true, use the original route name,
+ * and rely on label ellipsization */
+ this._compactRoute = this._route;
+ }
+
+ return this._compactRoute;
+ },
+
get routeType() {
return this._routeType;
},
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]