@opentripplanner/core-utils 11.4.2 → 11.4.3-mobility-profile

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (58) hide show
  1. package/lib/__tests__/__mocks__/bike-rental-itinerary.json +863 -0
  2. package/lib/__tests__/__mocks__/config.json +54 -0
  3. package/lib/__tests__/__mocks__/fare-products-itinerary.json +1299 -0
  4. package/lib/__tests__/__mocks__/routes.json +107 -0
  5. package/lib/__tests__/__mocks__/tnc-itinerary.json +1726 -0
  6. package/lib/bike-rental-itinerary.json +863 -0
  7. package/lib/config.json +54 -0
  8. package/lib/core-utils.story.d.ts +0 -1
  9. package/lib/core-utils.story.d.ts.map +1 -1
  10. package/lib/fare-products-itinerary.json +1299 -0
  11. package/lib/index.d.ts +2 -0
  12. package/lib/index.d.ts.map +1 -1
  13. package/lib/index.js +10 -0
  14. package/lib/index.js.map +1 -1
  15. package/lib/otpSchema.json +13383 -0
  16. package/lib/planQuery.graphql +283 -0
  17. package/lib/query-gen.d.ts +2 -1
  18. package/lib/query-gen.d.ts.map +1 -1
  19. package/lib/query-gen.js +5 -3
  20. package/lib/query-gen.js.map +1 -1
  21. package/lib/routes.json +107 -0
  22. package/lib/suspense.d.ts +8 -0
  23. package/lib/suspense.d.ts.map +1 -0
  24. package/lib/suspense.js +26 -0
  25. package/lib/suspense.js.map +1 -0
  26. package/lib/tnc-itinerary.json +1726 -0
  27. package/package.json +1 -1
  28. package/src/index.ts +2 -0
  29. package/src/otpSchema.json +10 -0
  30. package/src/planQuery.graphql +2 -0
  31. package/src/query-gen.ts +5 -2
  32. package/src/suspense.tsx +19 -0
  33. package/tsconfig.json +1 -2
  34. package/esm/graphql.d.js +0 -2
  35. package/esm/graphql.d.js.map +0 -1
  36. package/esm/index.js +0 -24
  37. package/esm/index.js.map +0 -1
  38. package/esm/itinerary.js +0 -688
  39. package/esm/itinerary.js.map +0 -1
  40. package/esm/map.js +0 -53
  41. package/esm/map.js.map +0 -1
  42. package/esm/profile.js +0 -172
  43. package/esm/profile.js.map +0 -1
  44. package/esm/query-gen.js +0 -233
  45. package/esm/query-gen.js.map +0 -1
  46. package/esm/query-params.js +0 -786
  47. package/esm/query-params.js.map +0 -1
  48. package/esm/query.js +0 -538
  49. package/esm/query.js.map +0 -1
  50. package/esm/route.js +0 -460
  51. package/esm/route.js.map +0 -1
  52. package/esm/storage.js +0 -46
  53. package/esm/storage.js.map +0 -1
  54. package/esm/time.js +0 -94
  55. package/esm/time.js.map +0 -1
  56. package/esm/ui.js +0 -48
  57. package/esm/ui.js.map +0 -1
  58. package/tsconfig.tsbuildinfo +0 -1
package/esm/query.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/query.js"],"names":["format","isMatch","parse","getGeocoder","qs","getTransitModes","hasCar","isAccessMode","coordsToString","stringToCoords","queryParams","getCurrentTime","getCurrentDate","OTP_API_DATE_FORMAT","OTP_API_TIME_FORMAT","defaultParams","TIME_FORMATS","getQueryParamProperty","paramInfo","property","query","ensureSingleAccessMode","queryModes","accessCount","filter","m","length","firstAccess","find","push","getUrlParams","window","location","href","split","getOtpUrlParams","Object","keys","key","startsWith","getTripOptionsFromQuery","keepPlace","options","time","departArrive","date","from","to","getDefaultQueryParamValue","param","getDefaultQuery","config","defaultQuery","routingType","qp","forEach","name","routingTypes","defaultQueryParams","isParamApplicable","applicable","includes","reduceOtpFlexModes","modes","enabled","reduce","prev","cur","newModes","expandOtpFlexMode","mode","map","join","isNotDefaultQuery","activeModes","sort","mergeFlex","defaultModes","concat","modesEqual","every","value","index","i","getFirstGeocodeResult","text","geocoderConfig","geocoder","search","then","result","firstResult","features","getLocationFromGeocodedFeature","parseLocationString","parts","coordinates","lat","lon","queryParamToLocation","planParamsToQuery","params","fromPlace","toPlace","arriveBy","matchedTimeFormat","timeFormat","Date","intermediatePlaces","maybeNumber","Number","isNaN","planParamsToQueryAsync","getRoutingParams","currentQuery","ignoreRealtimeUpdates","isItinerary","indexOf","rewriteFunction","itineraryRewrite","profileRewrite","assign","dateValid","timeValid","minTransitDistance","searchTimeout","onlyTransitTrips","startTimeValid","startTime","endTimeValid","endTime","reducedMode"],"mappings":";;;;;;;;;AAAA,SAASA,MAAT,EAAiBC,OAAjB,EAA0BC,KAA1B,QAAuC,UAAvC;AACA,OAAOC,WAAP,MAAwB,+BAAxB;AACA,OAAOC,EAAP,MAAe,IAAf;AAEA,SAASC,eAAT,EAA0BC,MAA1B,EAAkCC,YAAlC,QAAsD,aAAtD;AACA,SAASC,cAAT,EAAyBC,cAAzB,QAA+C,OAA/C;AACA,OAAOC,WAAP,MAAwB,gBAAxB;AACA,SACEC,cADF,EAEEC,cAFF,EAGEC,mBAHF,EAIEC,mBAJF,QAKO,QALP;AAOA;;AAEA,OAAO,IAAMC,aAAa,GAAG,CAC3B,YAD2B,EAE3B,iBAF2B,EAG3B,gBAH2B,EAI3B,aAJ2B,EAK3B,iBAL2B,EAM3B,aAN2B,EAO3B,WAP2B,EAQ3B,UAR2B,EAS3B,cAT2B,EAU3B,qBAV2B,EAW3B,OAX2B,CAAtB;AAcP;AACA;AACA;;AACA,IAAMC,YAAY,GAAG,CACnB,UADmB,EAEnB,OAFmB,EAGnB,MAHmB,EAInB,WAJmB,EAKnB,UALmB,EAMnB,QANmB,EAOnB,OAPmB,EAQnB,MARmB,EASnB,MATmB,EAUnB,KAVmB,EAWnB,IAXmB,CAArB;AAcA;AACA;;AAEA,OAAO,SAASC,qBAAT,CAA+BC,SAA/B,EAA0CC,QAA1C,EAAoDC,KAApD,EAA2D;AAChE,SAAO,OAAOF,SAAS,CAACC,QAAD,CAAhB,KAA+B,UAA/B,GACHD,SAAS,CAACC,QAAD,CAAT,CAAoBC,KAApB,CADG,GAEHF,SAAS,CAACC,QAAD,CAFb;AAGD;AAED,OAAO,SAASE,sBAAT,CAAgCC,UAAhC,EAA4C;AACjD;AACA,MAAMC,WAAW,GAAGD,UAAU,CAACE,MAAX,CAAkB,UAAAC,CAAC;AA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B,MAAAA,MAAM,CAACwB,aAAP,GAAuB,KAAvB;AACD,KAvBc,CAyBf;;;AACA,QAAIxB,MAAM,CAAC/B,IAAP,IAAe+B,MAAM,CAAC/B,IAAP,CAAYT,QAAZ,CAAqB,UAArB,CAAnB,EAAqD;AACnDwC,MAAAA,MAAM,CAACyB,gBAAP,GAA0B,IAA1B;AACD,KA5Bc,CA8Bf;;AACD,GA/BD,MA+BO;AACL;AACA,QAAMC,cAAc,GAAG9H,OAAO,CAACoG,MAAM,CAAC2B,SAAR,EAAmBlH,mBAAnB,CAA9B;AACA,QAAMmH,YAAY,GAAGhI,OAAO,CAACoG,MAAM,CAAC6B,OAAR,EAAiBpH,mBAAjB,CAA5B;;AAEA,QAAI,CAACiH,cAAD,IAAmB,CAACE,YAAxB,EAAsC;AACpC,aAAO5B,MAAM,CAAC0B,cAAd;AACA,aAAO1B,MAAM,CAAC4B,YAAd;AACD;AACF,GA1E2E,CA4E5E;AAEA;;;AACA,MAAI3H,MAAM,CAAC+F,MAAM,CAAC/B,IAAR,CAAV,EAAyB;AACvB+B,IAAAA,MAAM,CAAC/B,IAAP,IAAe,OAAf;AACD,GAjF2E,CAmF5E;AACA;;;AACA,MAAI+B,MAAM,CAAC/B,IAAP,IAAe,mBAAAnB,MAAM,CAACY,KAAP,kEAAca,SAAd,MAA4B,KAA/C,EAAsD;AACpD;AACA,QAAMuD,WAAW,GAAGrE,kBAAkB,CAACuC,MAAM,CAAC/B,IAAP,CAAYpC,KAAZ,CAAkB,GAAlB,CAAD,CAAlB,CAA2CsC,IAA3C,CAAgD,GAAhD,CAApB;AACA6B,IAAAA,MAAM,CAAC/B,IAAP,GAAcD,iBAAiB,CAAC8D,WAAD,CAA/B;AACD;;AAED,SAAO9B,MAAP;AACD","sourcesContent":["import { format, isMatch, parse } from \"date-fns\";\nimport getGeocoder from \"@opentripplanner/geocoder/lib\";\nimport qs from \"qs\";\n\nimport { getTransitModes, hasCar, isAccessMode } from \"./itinerary\";\nimport { coordsToString, stringToCoords } from \"./map\";\nimport queryParams from \"./query-params\";\nimport {\n getCurrentTime,\n getCurrentDate,\n OTP_API_DATE_FORMAT,\n OTP_API_TIME_FORMAT\n} from \"./time\";\n\n/* The list of default parameters considered in the settings panel */\n\nexport const defaultParams = [\n \"wheelchair\",\n \"maxWalkDistance\",\n \"walkReluctance\",\n \"maxWalkTime\",\n \"maxBikeDistance\",\n \"maxBikeTime\",\n \"bikeSpeed\",\n \"optimize\",\n \"optimizeBike\",\n \"maxEScooterDistance\",\n \"watts\"\n];\n\n/**\n * List of time formats to parse when reading query params.\n */\nconst TIME_FORMATS = [\n \"HH:mm:ss\",\n \"HH:mm\",\n \"H:mm\",\n \"h:mm:ss a\",\n \"h:mm:ssa\",\n \"h:mm a\",\n \"h:mma\",\n \"h:mm\",\n \"HHmm\",\n \"hmm\",\n \"ha\"\n];\n\n/* A function to retrieve a property value from an entry in the query-params\n * table, checking for either a static value or a function */\n\nexport function getQueryParamProperty(paramInfo, property, query) {\n return typeof paramInfo[property] === \"function\"\n ? paramInfo[property](query)\n : paramInfo[property];\n}\n\nexport function ensureSingleAccessMode(queryModes) {\n // Count the number of access modes\n const accessCount = queryModes.filter(m => isAccessMode(m)).length;\n\n // If multiple access modes are specified, keep only the first one\n if (accessCount > 1) {\n const firstAccess = queryModes.find(m => isAccessMode(m));\n queryModes = queryModes.filter(m => !isAccessMode(m) || m === firstAccess);\n\n // If no access modes are specified, add 'WALK' as the default\n } else if (accessCount === 0) {\n queryModes.push(\"WALK\");\n }\n\n return queryModes;\n}\n\nexport function getUrlParams() {\n return qs.parse(window.location.href.split(\"?\")[1]);\n}\n\nexport function getOtpUrlParams() {\n return Object.keys(getUrlParams()).filter(key => !key.startsWith(\"ui_\"));\n}\n\nexport function getTripOptionsFromQuery(query, keepPlace = false) {\n const options = { ...query };\n // Delete time/date options and from/to\n delete options.time;\n delete options.departArrive;\n delete options.date;\n if (!keepPlace) {\n delete options.from;\n delete options.to;\n }\n return options;\n}\n\n/**\n * Gets the query param's default value that is either a constant or by\n * executing the default value function.\n */\nfunction getDefaultQueryParamValue(param) {\n return typeof param.default === \"function\" ? param.default() : param.default;\n}\n\n/**\n * Get the default query to OTP based on the given config.\n */\nexport function getDefaultQuery(config = null) {\n const defaultQuery = { routingType: \"ITINERARY\" };\n queryParams\n .filter(qp => \"default\" in qp)\n .forEach(qp => {\n defaultQuery[qp.name] = getDefaultQueryParamValue(qp);\n });\n if (config) {\n if (config.routingTypes && config.routingTypes.length > 0) {\n defaultQuery.routingType = config.routingTypes[0].key;\n }\n if (config.defaultQueryParams) {\n Object.keys(config.defaultQueryParams).forEach(key => {\n defaultQuery[key] = config.defaultQueryParams[key];\n });\n }\n }\n return defaultQuery;\n}\n\n/**\n * Determine if the specified query param applies to the given query (based on\n * routing type and the param's own applicable function).\n * @param paramInfo an entry from query-params.js\n * @param query the query against which to check if the param applies\n * @param config OTP config\n * @return {Boolean}\n */\nfunction isParamApplicable(paramInfo, query, config) {\n const { applicable, routingTypes } = paramInfo;\n if (!routingTypes.includes(query.routingType)) return false;\n if (typeof applicable === \"function\" && !applicable(query, config)) {\n return false;\n }\n return true;\n}\n\n/**\n * Helper method which replaces OTP flex modes with single FLEX mode that's\n * more useful and easier to work with.\n */\nexport function reduceOtpFlexModes(modes, enabled = true) {\n if (!enabled) return modes;\n\n return modes.reduce((prev, cur) => {\n const newModes = prev;\n // Add the current mode if it is not a flex mode\n if (!cur.includes(\"FLEX\")) {\n newModes.push(cur);\n // If it is a flex mode, do not add it but rather add the custom flex mode\n // if not already present\n } else if (!newModes.includes(\"FLEX\")) {\n newModes.push(\"FLEX\");\n }\n return newModes;\n }, []);\n}\n\n/**\n * Helper method to process a mode string, replacing all instances of FLEX\n * with the full set of FLEX modes used by otp-2\n * @param {*} mode a mode String, not an array\n * @returns a mode String, not an array (with flex modes expanded)\n */\nexport function expandOtpFlexMode(mode) {\n const modes = reduceOtpFlexModes(mode.split(\",\"));\n return modes\n .map(m => {\n // If both the expanded and shrunk modes are included, remove the expanded one\n if (m === \"FLEX_EGRESS\" || m === \"FLEX_ACCESS\" || m === \"FLEX_DIRECT\") {\n if (mode.includes(\"FLEX\")) return \"\";\n }\n if (m === \"FLEX\") {\n return \"FLEX_EGRESS,FLEX_ACCESS,FLEX_DIRECT\";\n }\n return m;\n })\n .join(\",\");\n}\n\n/**\n * Determines whether the specified query differs from the default query, i.e.,\n * whether the user has modified any trip options (including mode) from their\n * default values.\n */\nexport function isNotDefaultQuery(query, config) {\n const activeModes = reduceOtpFlexModes(\n query.mode.split(\",\").sort(),\n config.modes?.mergeFlex\n );\n if (\n activeModes.length !== 2 ||\n activeModes[0] !== \"TRANSIT\" ||\n activeModes[1] !== \"WALK\"\n ) {\n // Default mode is TRANSIT,WALK. If general TRANSIT is not used, check\n // against available transit modes in config.\n const defaultModes = getTransitModes(config)\n .concat([\"WALK\"])\n .sort();\n const modesEqual =\n activeModes.length === defaultModes.length &&\n activeModes.every((value, index) => {\n return value === defaultModes[index];\n });\n if (!modesEqual) return true;\n }\n // If modes are equal, check the remaining params.\n const defaultQuery = getDefaultQuery(config);\n for (let i = 0; i < defaultParams.length; i++) {\n const param = defaultParams[i];\n const paramInfo = queryParams.find(qp => qp.name === param);\n // If the parameter applies to the query and does not match the default\n // value, the query is not default.\n if (\n isParamApplicable(paramInfo, query, config) &&\n query[param] !== defaultQuery[param]\n ) {\n return true;\n }\n }\n return false;\n}\n\n/**\n * Geocode utility for returning the first result for the provided place name text.\n * @param {string} text - text to search\n * @param {Object} geocoderConfig\n * @return {Location}\n */\nasync function getFirstGeocodeResult(text, geocoderConfig) {\n const geocoder = getGeocoder(geocoderConfig);\n // Attempt to geocode search text and return first result if found.\n // TODO: Import geocoder from @opentripplanner\n return geocoder.search({ text }).then(result => {\n const firstResult = result.features && result.features[0];\n if (firstResult) {\n return geocoder.getLocationFromGeocodedFeature(firstResult);\n }\n return null;\n });\n}\n\n/**\n * OTP allows passing a location in the form '123 Main St::lat,lon', so we check\n * for the double colon and parse the coordinates accordingly.\n * @param {string} value - query param for place described above\n * @return {Location} - location or null if the value is falsey or the parsed\n * coordinates do not result in both a lat and lon\n */\nexport function parseLocationString(value) {\n if (!value) return null;\n const parts = value.split(\"::\");\n const coordinates = parts[1]\n ? stringToCoords(parts[1])\n : stringToCoords(parts[0]);\n const name = parts[1] ? parts[0] : coordsToString(coordinates);\n return coordinates.length === 2\n ? {\n name: name || null,\n lat: coordinates[0] || null,\n lon: coordinates[1] || null\n }\n : null;\n}\n\n/**\n * Convert a string query param for a from or to place into a location. If\n * coordinates not provided and geocoder config is present, use the first\n * geocoded result.\n * @param {string} value\n * @param {Object} [geocoderConfig=null]\n * @return {Location}\n */\nasync function queryParamToLocation(value, geocoderConfig) {\n let location = parseLocationString(value);\n if (!location && value && geocoderConfig) {\n // If a valid location was not found, but the place name text exists,\n // attempt to geocode the name.\n location = await getFirstGeocodeResult(value, geocoderConfig);\n }\n return location;\n}\n\n/**\n * Create a otp query based on a the url params.\n *\n * @param {Object} params An object representing the parsed querystring of url\n * params.\n */\nexport function planParamsToQuery(params) {\n const query = {};\n Object.keys(params).forEach(key => {\n switch (key) {\n case \"fromPlace\":\n query.from = parseLocationString(params.fromPlace);\n break;\n case \"toPlace\":\n query.to = parseLocationString(params.toPlace);\n break;\n case \"arriveBy\":\n query.departArrive =\n params.arriveBy === \"true\"\n ? \"ARRIVE\"\n : params.arriveBy === \"false\"\n ? \"DEPART\"\n : \"NOW\";\n break;\n case \"date\":\n query.date = params.date || getCurrentDate();\n break;\n case \"time\":\n {\n // Match one of the supported time formats\n const matchedTimeFormat = TIME_FORMATS.find(timeFormat =>\n isMatch(params.time, timeFormat)\n );\n query.time = matchedTimeFormat\n ? format(\n parse(params.time, matchedTimeFormat, new Date()),\n OTP_API_TIME_FORMAT\n )\n : getCurrentTime();\n }\n break;\n case \"intermediatePlaces\":\n // If query has intermediate places, ensure that they are parsed\n // as locations.\n query.intermediatePlaces = params.intermediatePlaces\n ? params.intermediatePlaces.map(parseLocationString)\n : [];\n break;\n default: {\n const maybeNumber = Number(params[key]);\n // If the param value is an empty string literal and is not a number,\n // use string value. Else, use parsed number value.\n // See https://github.com/opentripplanner/otp-ui/issues/50\n query[key] =\n params[key] === \"\" || Number.isNaN(maybeNumber)\n ? params[key]\n : maybeNumber;\n break;\n }\n }\n });\n return query;\n}\n\n/**\n * Async method to create a otp query based on a the url params. This provides\n * the same functionality as planParamsToQuery, except that it will also attempt\n * to geocode the input from and to strings if no lat/lng values were provided.\n *\n * @param {Object} params An object representing the parsed querystring of url\n * params.\n * @param config the config in the otp-rr store.\n */\nexport async function planParamsToQueryAsync(params, config = {}) {\n // Construct query from plan params.\n const query = planParamsToQuery(params);\n // Attempt to geocode from and to params if the string parsing does not return\n // valid locations.\n if (!query.from) {\n query.from = await queryParamToLocation(params.fromPlace, config.geocoder);\n }\n if (!query.to) {\n query.to = await queryParamToLocation(params.toPlace, config.geocoder);\n }\n return query;\n}\n\n/**\n * Create an object that can be used as a querystring in making an OTP\n * PlannerResource request.\n *\n * See http://otp-docs.ibi-transit.com/api/resource_PlannerResource.html\n *\n * @param {Object} config The OTP application config. See types#configType\n * @param {Object} currentQuery The current query parameters as saved in the\n * application state. This method does some extra logic on top of this data\n * in order to create a request suitable for OTP. See __tests__/query.js#L14 for more.\n * @param {boolean} ignoreRealtimeUpdates If true, will create a request that\n * does not use realtime data.\n */\nexport function getRoutingParams(config, currentQuery, ignoreRealtimeUpdates) {\n const routingType = currentQuery.routingType;\n const isItinerary = routingType === \"ITINERARY\";\n let params = {};\n\n // Start with the universe of OTP parameters defined in query-params.js:\n queryParams\n .filter(qp => {\n // A given parameter is included in the request if all of the following:\n // 1. Must apply to the active routing type (ITINERARY or PROFILE)\n // 2. Must be included in the current user-defined query\n // 3. Must pass the parameter's applicability test, if one is specified\n return (\n qp.routingTypes.indexOf(routingType) !== -1 &&\n qp.name in currentQuery &&\n (typeof qp.applicable !== \"function\" ||\n qp.applicable(currentQuery, config))\n );\n })\n .forEach(qp => {\n // Translate the applicable parameters according to their rewrite\n // functions (if provided)\n const rewriteFunction = isItinerary\n ? qp.itineraryRewrite\n : qp.profileRewrite;\n params = Object.assign(\n params,\n rewriteFunction\n ? rewriteFunction(currentQuery[qp.name])\n : { [qp.name]: currentQuery[qp.name] }\n );\n });\n\n // Additional processing specific to ITINERARY mode\n if (isItinerary) {\n // override ignoreRealtimeUpdates if provided\n if (typeof ignoreRealtimeUpdates === \"boolean\") {\n params.ignoreRealtimeUpdates = ignoreRealtimeUpdates;\n }\n\n // check date/time validity; ignore both if either is invalid\n const dateValid = isMatch(params.date, OTP_API_DATE_FORMAT);\n const timeValid = isMatch(params.time, OTP_API_TIME_FORMAT);\n\n if (!dateValid || !timeValid) {\n delete params.time;\n delete params.date;\n }\n\n // temp: set additional parameters for CAR_HAIL or CAR_RENT trips\n if (\n params.mode &&\n (params.mode.includes(\"CAR_HAIL\") || params.mode.includes(\"CAR_RENT\"))\n ) {\n params.minTransitDistance = \"50%\";\n // increase search timeout because these queries can take a while\n params.searchTimeout = 10000;\n }\n\n // set onlyTransitTrips for car rental searches\n if (params.mode && params.mode.includes(\"CAR_RENT\")) {\n params.onlyTransitTrips = true;\n }\n\n // Additional processing specific to PROFILE mode\n } else {\n // check start and end time validity; ignore both if either is invalid\n const startTimeValid = isMatch(params.startTime, OTP_API_TIME_FORMAT);\n const endTimeValid = isMatch(params.endTime, OTP_API_TIME_FORMAT);\n\n if (!startTimeValid || !endTimeValid) {\n delete params.startTimeValid;\n delete params.endTimeValid;\n }\n }\n\n // TODO: check that valid from/to locations are provided\n\n // hack to add walking to driving/TNC trips\n if (hasCar(params.mode)) {\n params.mode += \",WALK\";\n }\n\n // Replace FLEX placeholder with OTP flex modes\n // Explicit false check allows avoiding a breaking change -- undefined is true\n if (params.mode && config.modes?.mergeFlex !== false) {\n // Ensure query is in reduced format to avoid replacing twice\n const reducedMode = reduceOtpFlexModes(params.mode.split(\",\")).join(\",\");\n params.mode = expandOtpFlexMode(reducedMode);\n }\n\n return params;\n}\n"],"file":"query.js"}
package/esm/route.js DELETED
@@ -1,460 +0,0 @@
1
- import chroma from "chroma-js";
2
- /**
3
- * Returns the transit operator (if an exact match is found) from the transit
4
- * operators config value. It is critical to use both the feedId and agencyId in
5
- * this method because it is possible in OTP for there to be a duplicate
6
- * agencyId in separate feeds.
7
- *
8
- * @param {string} feedId The feedId that this transit agency belongs to
9
- * @param {string} agencyId The agencyId of the transit agency
10
- * @param {array} transitOperators The transitOperators list from the config
11
- * @return {object} The transitOperator if a match was found or null if no match
12
- * was found
13
- */
14
-
15
- export function getTransitOperatorFromFeedIdAndAgencyId(feedId, agencyId, transitOperators) {
16
- return transitOperators.find(function (transitOperator) {
17
- return transitOperator.feedId === feedId && transitOperator.agencyId === agencyId;
18
- }) || null;
19
- }
20
- /**
21
- * Looks up an operator from the provided leg.
22
- *
23
- * @param {object} leg The Itinerary Leg from which to find the transit
24
- * operator
25
- * @param {object} transitOperators transitOperators from config.
26
- * @return {object} the operator if one was found or null if no match was found
27
- */
28
-
29
- export function getTransitOperatorFromLeg(leg, transitOperators) {
30
- if (!leg.routeId || !leg.agencyId) return null;
31
- var feedId = leg.routeId.split(":")[0];
32
- return getTransitOperatorFromFeedIdAndAgencyId(feedId, leg.agencyId, transitOperators);
33
- }
34
- /**
35
- * Looks up an operator from the provided configuration given an OTP route.
36
- * NOTE: this assumes the use of the OTP Route model or a modified OTP
37
- * RouteShort model (such as the one found in the IBI fork of OTP) that also
38
- * returns the agencyId.
39
- *
40
- * @param {object} route Either an OTP Route or RouteShort model
41
- * @param {array} transitOperators transitOperators from config
42
- * @return {object} the operator if one was found or null if no match was found
43
- */
44
-
45
- export function getTransitOperatorFromOtpRoute(route, transitOperators) {
46
- if (!route.id) return null;
47
- var feedId = route.id.split(":")[0];
48
- var agencyId;
49
-
50
- if (route.agency) {
51
- // This is returned in the OTP Route model
52
- agencyId = route.agency.id;
53
- } else if (route.agencyId) {
54
- // This is returned in the OTP RouteShort model (such as in the IBI fork)
55
- agencyId = route.agencyId;
56
- } else {
57
- return null;
58
- }
59
-
60
- return getTransitOperatorFromFeedIdAndAgencyId(feedId, agencyId, transitOperators);
61
- } // The functions below are for enhanced route sorting functions for the route
62
- // viewer on OTP-react-redux.
63
- // They address route ordering issues discussed in
64
- // https://github.com/opentripplanner/otp-react-redux/pull/123 and
65
- // https://github.com/opentripplanner/otp-react-redux/pull/124.
66
-
67
- /**
68
- * A large comparator value that can safely be used in mathematical sort
69
- * comparisons to place things at the end of lists
70
- */
71
-
72
- var END_OF_LIST_COMPARATOR_VALUE = 999999999999;
73
- /**
74
- * Returns a transit operator comparator value given a route and an optional
75
- * transitOperators config value. This function will do its best to handle all
76
- * kinds of input data as certain deployments of an implementing webapp may have
77
- * incomplete data and certain versions of OTP might not have a modified
78
- * implementation of the RouteShort model.
79
- *
80
- * @param {object} route Either an OTP Route or RouteShort model
81
- * @param {array} transitOperators transitOperators from config
82
- * @return {mixed} this could return a string value (the route's agency name) if
83
- * the transitOperators value is not defined. Otherwise an integer will be
84
- * returned.
85
- */
86
-
87
- function getTransitOperatorComparatorValue(route, transitOperators) {
88
- // if the transitOperators is undefined or has zero length, use the route's
89
- // agency name as the comparator value
90
- if (!transitOperators || transitOperators.length === 0) {
91
- // OTP Route
92
- if (route.agency) return route.agency.name; // OTP RouteShort (base OTP repo or IBI fork)
93
-
94
- if (route.agencyName) return route.agencyName; // shouldn't happen as agency names will be defined
95
-
96
- return "zzz";
97
- } // find operator associated with route
98
-
99
-
100
- var transitOperator = getTransitOperatorFromOtpRoute(route, transitOperators); // if transit operator not found, return infinity
101
-
102
- if (!transitOperator) return END_OF_LIST_COMPARATOR_VALUE; // return the transit operator's sort value or END_OF_LIST_COMPARATOR_VALUE if
103
- // the sort value is not a number
104
-
105
- return typeof transitOperator.order === "number" ? transitOperator.order : END_OF_LIST_COMPARATOR_VALUE;
106
- }
107
- /**
108
- * Calculates the sort comparator value given two routes based off of the
109
- * route's agency and provided transitOperators config data.
110
- */
111
-
112
-
113
- function makeTransitOperatorComparator(transitOperators) {
114
- return function (a, b) {
115
- var aVal = getTransitOperatorComparatorValue(a, transitOperators);
116
- var bVal = getTransitOperatorComparatorValue(b, transitOperators);
117
-
118
- if (typeof aVal === "string") {
119
- // happens when transitOperators is undefined. Both aVal are guaranteed to
120
- // be strings. Make a string comparison.
121
- if (aVal < bVal) return -1;
122
- if (aVal > bVal) return 1;
123
- return 0;
124
- } // @ts-expect-error transitOperators are defined and therefore a numeric value is guaranteed
125
- // to be returned
126
-
127
-
128
- return aVal - bVal;
129
- };
130
- }
131
- /**
132
- * Gets the desired sort values according to an optional getter function. If the
133
- * getter function is not defined, the original sort values are returned.
134
- */
135
-
136
-
137
- function getSortValues(getterFn, a, b) {
138
- var aVal;
139
- var bVal;
140
-
141
- if (typeof getterFn === "function") {
142
- aVal = getterFn(a);
143
- bVal = getterFn(b);
144
- } else {
145
- aVal = a;
146
- bVal = b;
147
- }
148
-
149
- return {
150
- aVal: aVal,
151
- bVal: bVal
152
- };
153
- } // Lookup for the sort values associated with various OTP modes.
154
- // Note: JSDoc format not used to avoid bug in documentationjs.
155
- // https://github.com/documentationjs/documentation/issues/372
156
-
157
-
158
- var modeComparatorValue = {
159
- SUBWAY: 1,
160
- TRAM: 2,
161
- TROLLEYBUS: 9,
162
- RAIL: 3,
163
- GONDOLA: 4,
164
- FERRY: 5,
165
- CABLE_CAR: 6,
166
- FUNICULAR: 7,
167
- BUS: 8
168
- }; // Lookup that maps route types to the OTP mode sort values.
169
- // Note: JSDoc format not used to avoid bug in documentationjs.
170
- // https://github.com/documentationjs/documentation/issues/372
171
-
172
- var routeTypeComparatorValue = {
173
- 0: modeComparatorValue.TRAM,
174
- // - Tram, Streetcar, Light rail.
175
- 1: modeComparatorValue.SUBWAY,
176
- // - Subway, Metro.
177
- 2: modeComparatorValue.RAIL,
178
- // - Rail. Used for intercity or long-distance travel.
179
- 3: modeComparatorValue.BUS,
180
- // - Bus.
181
- 4: modeComparatorValue.FERRY,
182
- // - Ferry.
183
- 5: modeComparatorValue.CABLE_CAR,
184
- // - Cable tram.
185
- 6: modeComparatorValue.GONDOLA,
186
- // - Gondola, etc.
187
- 7: modeComparatorValue.FUNICULAR,
188
- // - Funicular.
189
- // TODO: 11 and 12 are not a part of OTP as of 2019-02-14, but for now just
190
- // associate them with bus/rail.
191
- 11: modeComparatorValue.BUS,
192
- // - Trolleybus.
193
- 12: modeComparatorValue.RAIL,
194
- // - Monorail.
195
- 13: modeComparatorValue.TROLLEYBUS
196
- }; // Gets a comparator value for a given route's type (OTP mode).
197
- // Note: JSDoc format not used to avoid bug in documentationjs.
198
- // ttps://github.com/documentationjs/documentation/issues/372
199
-
200
- function getRouteTypeComparatorValue(route) {
201
- // For some strange reason, the short route response in OTP returns the
202
- // string-based modes, but the long route response returns the
203
- // integer route type. This attempts to account for both of those cases.
204
- if (!route) throw new Error("Route is undefined. ".concat(route));
205
-
206
- if (typeof modeComparatorValue[route.mode] !== "undefined") {
207
- return modeComparatorValue[route.mode];
208
- }
209
-
210
- if (typeof routeTypeComparatorValue[route.type] !== "undefined") {
211
- return routeTypeComparatorValue[route.type];
212
- } // Default the comparator value to a large number (placing the route at the
213
- // end of the list).
214
- // eslint-disable-next-line no-console
215
-
216
-
217
- console.warn("no mode/route type found for route", route);
218
- return END_OF_LIST_COMPARATOR_VALUE;
219
- }
220
- /**
221
- * Calculates the sort comparator value given two routes based off of route type
222
- * (OTP mode).
223
- */
224
-
225
-
226
- function routeTypeComparator(a, b) {
227
- return getRouteTypeComparatorValue(a) - getRouteTypeComparatorValue(b);
228
- }
229
- /**
230
- * Determines whether a value is a string that starts with an alphabetic
231
- * ascii character.
232
- */
233
-
234
-
235
- function startsWithAlphabeticCharacter(val) {
236
- if (typeof val === "string" && val.length > 0) {
237
- var firstCharCode = val.charCodeAt(0);
238
- return firstCharCode >= 65 && firstCharCode <= 90 || firstCharCode >= 97 && firstCharCode <= 122;
239
- }
240
-
241
- return false;
242
- }
243
- /**
244
- * Sorts routes based off of whether the shortName begins with an alphabetic
245
- * character. Routes with shortn that do start with an alphabetic character will
246
- * be prioritized over those that don't.
247
- */
248
-
249
-
250
- function alphabeticShortNameComparator(a, b) {
251
- var aStartsWithAlphabeticCharacter = startsWithAlphabeticCharacter(a.shortName);
252
- var bStartsWithAlphabeticCharacter = startsWithAlphabeticCharacter(b.shortName);
253
-
254
- if (aStartsWithAlphabeticCharacter && bStartsWithAlphabeticCharacter) {
255
- // both start with an alphabetic character, return equivalence
256
- return 0;
257
- } // a does start with an alphabetic character, but b does not. Prioritize a
258
-
259
-
260
- if (aStartsWithAlphabeticCharacter) return -1; // b does start with an alphabetic character, but a does not. Prioritize b
261
-
262
- if (bStartsWithAlphabeticCharacter) return 1; // neither route has a shortName that starts with an alphabetic character.
263
- // Return equivalence
264
-
265
- return 0;
266
- }
267
- /**
268
- * Checks whether an appropriate comparison of numeric values can be made for
269
- * sorting purposes. If both values are not valid numbers according to the
270
- * isNaN check, then this function returns undefined which indicates that a
271
- * secondary sorting criteria should be used instead. If one value is valid and
272
- * the other is not, then the valid value will be given sorting priority. If
273
- * both values are valid numbers, the difference is obtained as the sort value.
274
- *
275
- * An optional argument can be provided which will be used to obtain the
276
- * comparison value from the comparison function arguments.
277
- *
278
- * IMPORTANT: the comparison values must be numeric values or at least be
279
- * attempted to be converted to numeric values! If one of the arguments is
280
- * something crazy like an empty string, unexpected behavior will occur because
281
- * JavaScript.
282
- *
283
- * @param {function} [objGetterFn] An optional function to obtain the
284
- * comparison value from the comparator function arguments
285
- */
286
-
287
-
288
- export function makeNumericValueComparator(objGetterFn) {
289
- /* Note: Using the global version of isNaN (the Number version behaves differently. */
290
-
291
- /* eslint-disable no-restricted-globals */
292
- return function (a, b) {
293
- var _getSortValues = getSortValues(objGetterFn, a, b),
294
- aVal = _getSortValues.aVal,
295
- bVal = _getSortValues.bVal;
296
-
297
- if (typeof aVal !== "number" || typeof bVal !== "number") return 0; // if both values aren't valid numbers, use the next sort criteria
298
-
299
- if (isNaN(aVal) && isNaN(bVal)) return 0; // b is a valid number, b gets priority
300
-
301
- if (isNaN(aVal)) return 1; // a is a valid number, a gets priority
302
-
303
- if (isNaN(bVal)) return -1; // a and b are valid numbers, return the sort value
304
-
305
- return aVal - bVal;
306
- };
307
- }
308
- /**
309
- * Create a comparator function that compares string values. The comparison
310
- * values feed to the sort comparator function are assumed to be objects that
311
- * will have either undefined, null or string values at the given key. If one
312
- * object has undefined, null or an empty string, but the other does have a
313
- * string with length > 0, then that string will get priority.
314
- *
315
- * @param {function} [objGetterFn] An optional function to obtain the
316
- * comparison value from the comparator function arguments
317
- */
318
-
319
- export function makeStringValueComparator(objGetterFn) {
320
- return function (a, b) {
321
- var _getSortValues2 = getSortValues(objGetterFn, a, b),
322
- aVal = _getSortValues2.aVal,
323
- bVal = _getSortValues2.bVal; // both a and b are uncomparable strings, return equivalent value
324
-
325
-
326
- if (!aVal && !bVal) return 0; // a is not a comparable string, b gets priority
327
-
328
- if (!aVal) return 1; // b is not a comparable string, a gets priority
329
-
330
- if (!bVal) return -1; // a and b are comparable strings, return the sort value
331
-
332
- if (aVal < bVal) return -1;
333
- if (aVal > bVal) return 1;
334
- return 0;
335
- };
336
- }
337
- /**
338
- * OpenTripPlanner sets the routeSortOrder to -999 by default. So, if that value
339
- * is encountered, assume that it actually means that the routeSortOrder is not
340
- * set in the GTFS.
341
- *
342
- * See https://github.com/opentripplanner/OpenTripPlanner/issues/2938
343
- * Also see https://github.com/opentripplanner/otp-react-redux/issues/122
344
- */
345
-
346
- function getRouteSortOrderValue(val) {
347
- return val === -999 ? undefined : val;
348
- }
349
- /**
350
- * Create a multi-criteria sort comparator function composed of other sort
351
- * comparator functions. Each comparator function will be ran in the order given
352
- * until a non-zero comparison value is obtained which is then immediately
353
- * returned. If all comparison functions return equivalence, then the values
354
- * are assumed to be equivalent.
355
- */
356
-
357
-
358
- function makeMultiCriteriaSort() {
359
- for (var _len = arguments.length, criteria = new Array(_len), _key = 0; _key < _len; _key++) {
360
- criteria[_key] = arguments[_key];
361
- }
362
-
363
- return function (a, b) {
364
- for (var i = 0; i < criteria.length; i++) {
365
- var curCriteriaComparatorValue = criteria[i](a, b); // if the comparison objects are not equivalent, return the value obtained
366
- // in this current criteria comparison
367
-
368
- if (curCriteriaComparatorValue !== 0) {
369
- return curCriteriaComparatorValue;
370
- }
371
- }
372
-
373
- return 0;
374
- };
375
- }
376
- /**
377
- * Creates a sort comparator function to compares routes for the purposes of
378
- * sorting and displaying in a user interface. This takes in a single optional
379
- * argument which should be a list of transitOperators as defined in the config
380
- * file. Due to GTFS feeds having varying levels of data quality, a multi-
381
- * criteria sort is needed to account for various differences. The criteria
382
- * included here are each applied to the routes in the order listed. If a given
383
- * sort criterion yields equivalence (e.g., two routes have the short name
384
- * "20"), the comparator falls back onto the next sort criterion (e.g., long
385
- * name). The sort operates on the following values (in order):
386
- *
387
- * 1. Transit Operator. The transit operator will be attempted to be obtained
388
- * for each route. If no argument is provided when creating this comparator
389
- * function, then routes will be sorted by their agency's name. If an
390
- * argument is provided and a match is found based off of the route's feed_id
391
- * and agency_id and a transitOperator's feed_id and agency_id, then the
392
- * field transitOperator.order will be used as the comparator value as long
393
- * as it is numeric. If it is not numeric, a value is returned indicating
394
- * that this transit operator should be placed at the end of the list.
395
- * 2. sortOrder. Routes that do not have a valid sortOrder will be placed
396
- * beneath those that do.
397
- * 3. route type (OTP mode). See routeTypeComparator code for prioritization of
398
- * route types.
399
- * 4. shortNames that begin with alphabetic characters. shortNames that do not
400
- * start with alphabetic characters will be place beneath those that do.
401
- * 5. shortName as integer. shortNames that cannot be parsed as integers will
402
- * be placed beneath those that are valid.
403
- * 6. shortName as string. Routes without shortNames will be placed beneath
404
- * those with shortNames.
405
- * 7. longName as string.
406
- */
407
-
408
-
409
- export function makeRouteComparator(transitOperators) {
410
- return makeMultiCriteriaSort(makeTransitOperatorComparator(transitOperators), makeNumericValueComparator(function (obj) {
411
- return getRouteSortOrderValue(obj.sortOrder);
412
- }), routeTypeComparator, alphabeticShortNameComparator, makeNumericValueComparator(function (obj) {
413
- return parseInt(obj.shortName, 10);
414
- }), makeStringValueComparator(function (obj) {
415
- return obj.shortName;
416
- }), makeStringValueComparator(function (obj) {
417
- return obj.longName;
418
- }));
419
- }
420
- /**
421
- * Tests if a pair of colors is readable. If it is, that readable color is returned.
422
- * If it is not, a more appropriate alternative is returned.
423
- *
424
- * Uses algorithm based on combined luminance. Values have been derived from
425
- * looking at real agency color pairings. These pairings are difficult to
426
- * generate for, as some colors see both white and black used by different agencies.
427
- *
428
- * This method therefore can accept multiple colors (including black and white) for the same background color.
429
- *
430
- * @param backgroundColor A hex string, usually the "routeColor"
431
- * @param proposedTextColor A hex string, usually the "routeTextColor"
432
- */
433
-
434
- export function getMostReadableTextColor(backgroundColor, proposedTextColor) {
435
- // Sometimes input will defy the method signature. Therefore we need extra fallbacks
436
- if (!backgroundColor) backgroundColor = "#333333";
437
- if (!proposedTextColor) proposedTextColor = "#ffffff";
438
-
439
- if (!backgroundColor.startsWith("#")) {
440
- backgroundColor = "#".concat(backgroundColor);
441
- }
442
-
443
- if (!proposedTextColor.startsWith("#")) {
444
- proposedTextColor = "#".concat(proposedTextColor);
445
- } // Check if proposed color is readable
446
- // Luminance thresholds have been selected based on actual transit agency colors
447
-
448
-
449
- var fgLuminance = chroma(proposedTextColor).luminance();
450
- var bgLuminance = chroma(backgroundColor).luminance();
451
-
452
- if (bgLuminance + fgLuminance < 1.41 && bgLuminance + fgLuminance > 0.25 && Math.abs(bgLuminance - fgLuminance) > 0.2) {
453
- return proposedTextColor;
454
- } // Return black or white based on luminance of background color
455
- // When generating colors, white is preferred.
456
-
457
-
458
- return chroma(backgroundColor).luminance() < 0.4 ? "#ffffff" : "#000000";
459
- }
460
- //# sourceMappingURL=route.js.map
package/esm/route.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/route.ts"],"names":["chroma","getTransitOperatorFromFeedIdAndAgencyId","feedId","agencyId","transitOperators","find","transitOperator","getTransitOperatorFromLeg","leg","routeId","split","getTransitOperatorFromOtpRoute","route","id","agency","END_OF_LIST_COMPARATOR_VALUE","getTransitOperatorComparatorValue","length","name","agencyName","order","makeTransitOperatorComparator","a","b","aVal","bVal","getSortValues","getterFn","modeComparatorValue","SUBWAY","TRAM","TROLLEYBUS","RAIL","GONDOLA","FERRY","CABLE_CAR","FUNICULAR","BUS","routeTypeComparatorValue","getRouteTypeComparatorValue","Error","mode","type","console","warn","routeTypeComparator","startsWithAlphabeticCharacter","val","firstCharCode","charCodeAt","alphabeticShortNameComparator","aStartsWithAlphabeticCharacter","shortName","bStartsWithAlphabeticCharacter","makeNumericValueComparator","objGetterFn","isNaN","makeStringValueComparator","getRouteSortOrderValue","undefined","makeMultiCriteriaSort","criteria","i","curCriteriaComparatorValue","makeRouteComparator","obj","sortOrder","parseInt","longName","getMostReadableTextColor","backgroundColor","proposedTextColor","startsWith","fgLuminance","luminance","bgLuminance","Math","abs"],"mappings":"AACA,OAAOA,MAAP,MAAmB,WAAnB;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,SAASC,uCAAT,CACLC,MADK,EAELC,QAFK,EAGLC,gBAHK,EAIY;AACjB,SACEA,gBAAgB,CAACC,IAAjB,CACE,UAAAC,eAAe;AAAA,WACbA,eAAe,CAACJ,MAAhB,KAA2BA,MAA3B,IACAI,eAAe,CAACH,QAAhB,KAA6BA,QAFhB;AAAA,GADjB,KAIK,IALP;AAOD;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,SAASI,yBAAT,CACLC,GADK,EAELJ,gBAFK,EAGY;AACjB,MAAI,CAACI,GAAG,CAACC,OAAL,IAAgB,CAACD,GAAG,CAACL,QAAzB,EAAmC,OAAO,IAAP;AACnC,MAAMD,MAAM,GAAGM,GAAG,CAACC,OAAJ,CAAYC,KAAZ,CAAkB,GAAlB,EAAuB,CAAvB,CAAf;AACA,SAAOT,uCAAuC,CAC5CC,MAD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,CANC,EAO1BK,yBAAyB,CAAC,UAAAQ,GAAG;AAAA,WAAIA,GAAG,CAACG,QAAR;AAAA,GAAJ,CAPC,CAA5B;AASD;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,SAASC,wBAAT,CACLC,eADK,EAELC,iBAFK,EAGG;AACR;AACA,MAAI,CAACD,eAAL,EAAsBA,eAAe,GAAG,SAAlB;AACtB,MAAI,CAACC,iBAAL,EAAwBA,iBAAiB,GAAG,SAApB;;AAExB,MAAI,CAACD,eAAe,CAACE,UAAhB,CAA2B,GAA3B,CAAL,EAAsC;AACpCF,IAAAA,eAAe,cAAOA,eAAP,CAAf;AACD;;AACD,MAAI,CAACC,iBAAiB,CAACC,UAAlB,CAA6B,GAA7B,CAAL,EAAwC;AACtCD,IAAAA,iBAAiB,cAAOA,iBAAP,CAAjB;AACD,GAVO,CAYR;AACA;;;AACA,MAAME,WAAW,GAAGzE,MAAM,CAACuE,iBAAD,CAAN,CAA0BG,SAA1B,EAApB;AACA,MAAMC,WAAW,GAAG3E,MAAM,CAACsE,eAAD,CAAN,CAAwBI,SAAxB,EAApB;;AACA,MACEC,WAAW,GAAGF,WAAd,GAA4B,IAA5B,IACAE,WAAW,GAAGF,WAAd,GAA4B,IAD5B,IAEAG,IAAI,CAACC,GAAL,CAASF,WAAW,GAAGF,WAAvB,IAAsC,GAHxC,EAIE;AACA,WAAOF,iBAAP;AACD,GAtBO,CAwBR;AACA;;;AACA,SAAOvE,MAAM,CAACsE,eAAD,CAAN,CAAwBI,SAAxB,KAAsC,GAAtC,GAA4C,SAA5C,GAAwD,SAA/D;AACD","sourcesContent":["import { Leg, Route, TransitOperator } from \"@opentripplanner/types\";\nimport chroma from \"chroma-js\";\n/**\n * Returns the transit operator (if an exact match is found) from the transit\n * operators config value. It is critical to use both the feedId and agencyId in\n * this method because it is possible in OTP for there to be a duplicate\n * agencyId in separate feeds.\n *\n * @param {string} feedId The feedId that this transit agency belongs to\n * @param {string} agencyId The agencyId of the transit agency\n * @param {array} transitOperators The transitOperators list from the config\n * @return {object} The transitOperator if a match was found or null if no match\n * was found\n */\nexport function getTransitOperatorFromFeedIdAndAgencyId(\n feedId: string,\n agencyId: string | number,\n transitOperators: TransitOperator[]\n): TransitOperator {\n return (\n transitOperators.find(\n transitOperator =>\n transitOperator.feedId === feedId &&\n transitOperator.agencyId === agencyId\n ) || null\n );\n}\n\n/**\n * Looks up an operator from the provided leg.\n *\n * @param {object} leg The Itinerary Leg from which to find the transit\n * operator\n * @param {object} transitOperators transitOperators from config.\n * @return {object} the operator if one was found or null if no match was found\n */\nexport function getTransitOperatorFromLeg(\n leg: Leg,\n transitOperators: TransitOperator[]\n): TransitOperator {\n if (!leg.routeId || !leg.agencyId) return null;\n const feedId = leg.routeId.split(\":\")[0];\n return getTransitOperatorFromFeedIdAndAgencyId(\n feedId,\n leg.agencyId,\n transitOperators\n );\n}\n\n/**\n * Looks up an operator from the provided configuration given an OTP route.\n * NOTE: this assumes the use of the OTP Route model or a modified OTP\n * RouteShort model (such as the one found in the IBI fork of OTP) that also\n * returns the agencyId.\n *\n * @param {object} route Either an OTP Route or RouteShort model\n * @param {array} transitOperators transitOperators from config\n * @return {object} the operator if one was found or null if no match was found\n */\nexport function getTransitOperatorFromOtpRoute(\n route: Route,\n transitOperators: TransitOperator[]\n): TransitOperator {\n if (!route.id) return null;\n const feedId = route.id.split(\":\")[0];\n let agencyId: string | number;\n if (route.agency) {\n // This is returned in the OTP Route model\n agencyId = route.agency.id;\n } else if (route.agencyId) {\n // This is returned in the OTP RouteShort model (such as in the IBI fork)\n agencyId = route.agencyId;\n } else {\n return null;\n }\n return getTransitOperatorFromFeedIdAndAgencyId(\n feedId,\n agencyId,\n transitOperators\n );\n}\n\n// The functions below are for enhanced route sorting functions for the route\n// viewer on OTP-react-redux.\n// They address route ordering issues discussed in\n// https://github.com/opentripplanner/otp-react-redux/pull/123 and\n// https://github.com/opentripplanner/otp-react-redux/pull/124.\n\n/**\n * A large comparator value that can safely be used in mathematical sort\n * comparisons to place things at the end of lists\n */\nconst END_OF_LIST_COMPARATOR_VALUE = 999999999999;\n\n/**\n * Returns a transit operator comparator value given a route and an optional\n * transitOperators config value. This function will do its best to handle all\n * kinds of input data as certain deployments of an implementing webapp may have\n * incomplete data and certain versions of OTP might not have a modified\n * implementation of the RouteShort model.\n *\n * @param {object} route Either an OTP Route or RouteShort model\n * @param {array} transitOperators transitOperators from config\n * @return {mixed} this could return a string value (the route's agency name) if\n * the transitOperators value is not defined. Otherwise an integer will be\n * returned.\n */\nfunction getTransitOperatorComparatorValue(\n route: Route,\n transitOperators: TransitOperator[]\n): number | string {\n // if the transitOperators is undefined or has zero length, use the route's\n // agency name as the comparator value\n if (!transitOperators || transitOperators.length === 0) {\n // OTP Route\n if (route.agency) return route.agency.name;\n // OTP RouteShort (base OTP repo or IBI fork)\n if (route.agencyName) return route.agencyName;\n // shouldn't happen as agency names will be defined\n return \"zzz\";\n }\n\n // find operator associated with route\n const transitOperator = getTransitOperatorFromOtpRoute(\n route,\n transitOperators\n );\n\n // if transit operator not found, return infinity\n if (!transitOperator) return END_OF_LIST_COMPARATOR_VALUE;\n\n // return the transit operator's sort value or END_OF_LIST_COMPARATOR_VALUE if\n // the sort value is not a number\n return typeof transitOperator.order === \"number\"\n ? transitOperator.order\n : END_OF_LIST_COMPARATOR_VALUE;\n}\n\n/**\n * Calculates the sort comparator value given two routes based off of the\n * route's agency and provided transitOperators config data.\n */\nfunction makeTransitOperatorComparator(transitOperators: TransitOperator[]) {\n return (a: Route, b: Route) => {\n const aVal = getTransitOperatorComparatorValue(a, transitOperators);\n const bVal = getTransitOperatorComparatorValue(b, transitOperators);\n if (typeof aVal === \"string\") {\n // happens when transitOperators is undefined. Both aVal are guaranteed to\n // be strings. Make a string comparison.\n if (aVal < bVal) return -1;\n if (aVal > bVal) return 1;\n return 0;\n }\n // @ts-expect-error transitOperators are defined and therefore a numeric value is guaranteed\n // to be returned\n return aVal - bVal;\n };\n}\n\n/**\n * Gets the desired sort values according to an optional getter function. If the\n * getter function is not defined, the original sort values are returned.\n */\nfunction getSortValues(\n getterFn: (item: unknown) => unknown,\n a: unknown,\n b: unknown\n) {\n let aVal: unknown;\n let bVal: unknown;\n if (typeof getterFn === \"function\") {\n aVal = getterFn(a);\n bVal = getterFn(b);\n } else {\n aVal = a;\n bVal = b;\n }\n return { aVal, bVal };\n}\n\n// Lookup for the sort values associated with various OTP modes.\n// Note: JSDoc format not used to avoid bug in documentationjs.\n// https://github.com/documentationjs/documentation/issues/372\nconst modeComparatorValue = {\n SUBWAY: 1,\n TRAM: 2,\n TROLLEYBUS: 9,\n RAIL: 3,\n GONDOLA: 4,\n FERRY: 5,\n CABLE_CAR: 6,\n FUNICULAR: 7,\n BUS: 8\n};\n\n// Lookup that maps route types to the OTP mode sort values.\n// Note: JSDoc format not used to avoid bug in documentationjs.\n// https://github.com/documentationjs/documentation/issues/372\nconst routeTypeComparatorValue = {\n 0: modeComparatorValue.TRAM, // - Tram, Streetcar, Light rail.\n 1: modeComparatorValue.SUBWAY, // - Subway, Metro.\n 2: modeComparatorValue.RAIL, // - Rail. Used for intercity or long-distance travel.\n 3: modeComparatorValue.BUS, // - Bus.\n 4: modeComparatorValue.FERRY, // - Ferry.\n 5: modeComparatorValue.CABLE_CAR, // - Cable tram.\n 6: modeComparatorValue.GONDOLA, // - Gondola, etc.\n 7: modeComparatorValue.FUNICULAR, // - Funicular.\n // TODO: 11 and 12 are not a part of OTP as of 2019-02-14, but for now just\n // associate them with bus/rail.\n 11: modeComparatorValue.BUS, // - Trolleybus.\n 12: modeComparatorValue.RAIL, // - Monorail.\n 13: modeComparatorValue.TROLLEYBUS\n};\n\n// Gets a comparator value for a given route's type (OTP mode).\n// Note: JSDoc format not used to avoid bug in documentationjs.\n// ttps://github.com/documentationjs/documentation/issues/372\nfunction getRouteTypeComparatorValue(route: Route): number {\n // For some strange reason, the short route response in OTP returns the\n // string-based modes, but the long route response returns the\n // integer route type. This attempts to account for both of those cases.\n if (!route) throw new Error(`Route is undefined. ${route}`);\n if (typeof modeComparatorValue[route.mode] !== \"undefined\") {\n return modeComparatorValue[route.mode];\n }\n if (typeof routeTypeComparatorValue[route.type] !== \"undefined\") {\n return routeTypeComparatorValue[route.type];\n }\n // Default the comparator value to a large number (placing the route at the\n // end of the list).\n // eslint-disable-next-line no-console\n console.warn(\"no mode/route type found for route\", route);\n return END_OF_LIST_COMPARATOR_VALUE;\n}\n\n/**\n * Calculates the sort comparator value given two routes based off of route type\n * (OTP mode).\n */\nfunction routeTypeComparator(a: Route, b: Route): number {\n return getRouteTypeComparatorValue(a) - getRouteTypeComparatorValue(b);\n}\n\n/**\n * Determines whether a value is a string that starts with an alphabetic\n * ascii character.\n */\nfunction startsWithAlphabeticCharacter(val: unknown): boolean {\n if (typeof val === \"string\" && val.length > 0) {\n const firstCharCode = val.charCodeAt(0);\n return (\n (firstCharCode >= 65 && firstCharCode <= 90) ||\n (firstCharCode >= 97 && firstCharCode <= 122)\n );\n }\n return false;\n}\n\n/**\n * Sorts routes based off of whether the shortName begins with an alphabetic\n * character. Routes with shortn that do start with an alphabetic character will\n * be prioritized over those that don't.\n */\nfunction alphabeticShortNameComparator(a: Route, b: Route): number {\n const aStartsWithAlphabeticCharacter = startsWithAlphabeticCharacter(\n a.shortName\n );\n const bStartsWithAlphabeticCharacter = startsWithAlphabeticCharacter(\n b.shortName\n );\n\n if (aStartsWithAlphabeticCharacter && bStartsWithAlphabeticCharacter) {\n // both start with an alphabetic character, return equivalence\n return 0;\n }\n // a does start with an alphabetic character, but b does not. Prioritize a\n if (aStartsWithAlphabeticCharacter) return -1;\n // b does start with an alphabetic character, but a does not. Prioritize b\n if (bStartsWithAlphabeticCharacter) return 1;\n // neither route has a shortName that starts with an alphabetic character.\n // Return equivalence\n return 0;\n}\n\n/**\n * Checks whether an appropriate comparison of numeric values can be made for\n * sorting purposes. If both values are not valid numbers according to the\n * isNaN check, then this function returns undefined which indicates that a\n * secondary sorting criteria should be used instead. If one value is valid and\n * the other is not, then the valid value will be given sorting priority. If\n * both values are valid numbers, the difference is obtained as the sort value.\n *\n * An optional argument can be provided which will be used to obtain the\n * comparison value from the comparison function arguments.\n *\n * IMPORTANT: the comparison values must be numeric values or at least be\n * attempted to be converted to numeric values! If one of the arguments is\n * something crazy like an empty string, unexpected behavior will occur because\n * JavaScript.\n *\n * @param {function} [objGetterFn] An optional function to obtain the\n * comparison value from the comparator function arguments\n */\nexport function makeNumericValueComparator(\n objGetterFn?: (item: Route) => number\n) {\n /* Note: Using the global version of isNaN (the Number version behaves differently. */\n /* eslint-disable no-restricted-globals */\n return (a: number, b: number): number => {\n const { aVal, bVal } = getSortValues(objGetterFn, a, b);\n if (typeof aVal !== \"number\" || typeof bVal !== \"number\") return 0;\n\n // if both values aren't valid numbers, use the next sort criteria\n if (isNaN(aVal) && isNaN(bVal)) return 0;\n // b is a valid number, b gets priority\n if (isNaN(aVal)) return 1;\n // a is a valid number, a gets priority\n if (isNaN(bVal)) return -1;\n // a and b are valid numbers, return the sort value\n return aVal - bVal;\n };\n}\n\n/**\n * Create a comparator function that compares string values. The comparison\n * values feed to the sort comparator function are assumed to be objects that\n * will have either undefined, null or string values at the given key. If one\n * object has undefined, null or an empty string, but the other does have a\n * string with length > 0, then that string will get priority.\n *\n * @param {function} [objGetterFn] An optional function to obtain the\n * comparison value from the comparator function arguments\n */\nexport function makeStringValueComparator(\n objGetterFn?: (item: Route) => string\n) {\n return (a: string, b: string): number => {\n const { aVal, bVal } = getSortValues(objGetterFn, a, b);\n // both a and b are uncomparable strings, return equivalent value\n if (!aVal && !bVal) return 0;\n // a is not a comparable string, b gets priority\n if (!aVal) return 1;\n // b is not a comparable string, a gets priority\n if (!bVal) return -1;\n // a and b are comparable strings, return the sort value\n if (aVal < bVal) return -1;\n if (aVal > bVal) return 1;\n return 0;\n };\n}\n\n/**\n * OpenTripPlanner sets the routeSortOrder to -999 by default. So, if that value\n * is encountered, assume that it actually means that the routeSortOrder is not\n * set in the GTFS.\n *\n * See https://github.com/opentripplanner/OpenTripPlanner/issues/2938\n * Also see https://github.com/opentripplanner/otp-react-redux/issues/122\n */\nfunction getRouteSortOrderValue(val: number): number {\n return val === -999 ? undefined : val;\n}\n\n/**\n * Create a multi-criteria sort comparator function composed of other sort\n * comparator functions. Each comparator function will be ran in the order given\n * until a non-zero comparison value is obtained which is then immediately\n * returned. If all comparison functions return equivalence, then the values\n * are assumed to be equivalent.\n */\nfunction makeMultiCriteriaSort(\n ...criteria: ((a: unknown, b: unknown) => number)[]\n) {\n return (a: number, b: number): number => {\n for (let i = 0; i < criteria.length; i++) {\n const curCriteriaComparatorValue = criteria[i](a, b);\n // if the comparison objects are not equivalent, return the value obtained\n // in this current criteria comparison\n if (curCriteriaComparatorValue !== 0) {\n return curCriteriaComparatorValue;\n }\n }\n return 0;\n };\n}\n\n/**\n * Creates a sort comparator function to compares routes for the purposes of\n * sorting and displaying in a user interface. This takes in a single optional\n * argument which should be a list of transitOperators as defined in the config\n * file. Due to GTFS feeds having varying levels of data quality, a multi-\n * criteria sort is needed to account for various differences. The criteria\n * included here are each applied to the routes in the order listed. If a given\n * sort criterion yields equivalence (e.g., two routes have the short name\n * \"20\"), the comparator falls back onto the next sort criterion (e.g., long\n * name). The sort operates on the following values (in order):\n *\n * 1. Transit Operator. The transit operator will be attempted to be obtained\n * for each route. If no argument is provided when creating this comparator\n * function, then routes will be sorted by their agency's name. If an\n * argument is provided and a match is found based off of the route's feed_id\n * and agency_id and a transitOperator's feed_id and agency_id, then the\n * field transitOperator.order will be used as the comparator value as long\n * as it is numeric. If it is not numeric, a value is returned indicating\n * that this transit operator should be placed at the end of the list.\n * 2. sortOrder. Routes that do not have a valid sortOrder will be placed\n * beneath those that do.\n * 3. route type (OTP mode). See routeTypeComparator code for prioritization of\n * route types.\n * 4. shortNames that begin with alphabetic characters. shortNames that do not\n * start with alphabetic characters will be place beneath those that do.\n * 5. shortName as integer. shortNames that cannot be parsed as integers will\n * be placed beneath those that are valid.\n * 6. shortName as string. Routes without shortNames will be placed beneath\n * those with shortNames.\n * 7. longName as string.\n */\nexport function makeRouteComparator(\n transitOperators: TransitOperator[]\n): (a: number, b: number) => number {\n return makeMultiCriteriaSort(\n makeTransitOperatorComparator(transitOperators),\n makeNumericValueComparator(obj => getRouteSortOrderValue(obj.sortOrder)),\n routeTypeComparator,\n alphabeticShortNameComparator,\n makeNumericValueComparator(obj => parseInt(obj.shortName, 10)),\n makeStringValueComparator(obj => obj.shortName),\n makeStringValueComparator(obj => obj.longName)\n );\n}\n\n/**\n * Tests if a pair of colors is readable. If it is, that readable color is returned.\n * If it is not, a more appropriate alternative is returned.\n *\n * Uses algorithm based on combined luminance. Values have been derived from\n * looking at real agency color pairings. These pairings are difficult to\n * generate for, as some colors see both white and black used by different agencies.\n *\n * This method therefore can accept multiple colors (including black and white) for the same background color.\n *\n * @param backgroundColor A hex string, usually the \"routeColor\"\n * @param proposedTextColor A hex string, usually the \"routeTextColor\"\n */\nexport function getMostReadableTextColor(\n backgroundColor: string,\n proposedTextColor?: string\n): string {\n // Sometimes input will defy the method signature. Therefore we need extra fallbacks\n if (!backgroundColor) backgroundColor = \"#333333\";\n if (!proposedTextColor) proposedTextColor = \"#ffffff\";\n\n if (!backgroundColor.startsWith(\"#\")) {\n backgroundColor = `#${backgroundColor}`;\n }\n if (!proposedTextColor.startsWith(\"#\")) {\n proposedTextColor = `#${proposedTextColor}`;\n }\n\n // Check if proposed color is readable\n // Luminance thresholds have been selected based on actual transit agency colors\n const fgLuminance = chroma(proposedTextColor).luminance();\n const bgLuminance = chroma(backgroundColor).luminance();\n if (\n bgLuminance + fgLuminance < 1.41 &&\n bgLuminance + fgLuminance > 0.25 &&\n Math.abs(bgLuminance - fgLuminance) > 0.2\n ) {\n return proposedTextColor;\n }\n\n // Return black or white based on luminance of background color\n // When generating colors, white is preferred.\n return chroma(backgroundColor).luminance() < 0.4 ? \"#ffffff\" : \"#000000\";\n}\n"],"file":"route.js"}
package/esm/storage.js DELETED
@@ -1,46 +0,0 @@
1
- /* eslint-disable no-console */
2
- // Prefix to use with local storage keys.
3
- var STORAGE_PREFIX = "otp";
4
- /**
5
- * Store a javascript object at the specified key.
6
- */
7
-
8
- export function storeItem(key, object) {
9
- window.localStorage.setItem("".concat(STORAGE_PREFIX, ".").concat(key), JSON.stringify(object));
10
- }
11
- /**
12
- * Retrieve a javascript object at the specified key. If not found, defaults to
13
- * null or, the optionally provided notFoundValue.
14
- */
15
-
16
- export function getItem(key) {
17
- var notFoundValue = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
18
- var itemAsString;
19
-
20
- try {
21
- itemAsString = window.localStorage.getItem("".concat(STORAGE_PREFIX, ".").concat(key));
22
- var json = JSON.parse(itemAsString);
23
- if (json) return json;
24
- return notFoundValue;
25
- } catch (e) {
26
- // Catch any errors associated with parsing bad JSON.
27
- console.warn(e, itemAsString);
28
- return notFoundValue;
29
- }
30
- }
31
- /**
32
- * Remove item at specified key.
33
- */
34
-
35
- export function removeItem(key) {
36
- window.localStorage.removeItem("".concat(STORAGE_PREFIX, ".").concat(key));
37
- }
38
- /**
39
- * Generate a random ID. This might not quite be a UUID, but it serves our
40
- * purposes for now.
41
- */
42
-
43
- export function randId() {
44
- return Math.random().toString(36).substr(2, 9);
45
- }
46
- //# sourceMappingURL=storage.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/storage.ts"],"names":["STORAGE_PREFIX","storeItem","key","object","window","localStorage","setItem","JSON","stringify","getItem","notFoundValue","itemAsString","json","parse","e","console","warn","removeItem","randId","Math","random","toString","substr"],"mappings":"AAAA;AACA;AACA,IAAMA,cAAc,GAAG,KAAvB;AAEA;AACA;AACA;;AACA,OAAO,SAASC,SAAT,CAAmBC,GAAnB,EAAgCC,MAAhC,EAAuD;AAC5DC,EAAAA,MAAM,CAACC,YAAP,CAAoBC,OAApB,WACKN,cADL,cACuBE,GADvB,GAEEK,IAAI,CAACC,SAAL,CAAeL,MAAf,CAFF;AAID;AAED;AACA;AACA;AACA;;AACA,OAAO,SAASM,OAAT,CAAiBP,GAAjB,EAAsE;AAAA,MAAxCQ,aAAwC,uEAAf,IAAe;AAC3E,MAAIC,YAAJ;;AACA,MAAI;AACFA,IAAAA,YAAY,GAAGP,MAAM,CAACC,YAAP,CAAoBI,OAApB,WAA+BT,cAA/B,cAAiDE,GAAjD,EAAf;AACA,QAAMU,IAAI,GAAGL,IAAI,CAACM,KAAL,CAAWF,YAAX,CAAb;AACA,QAAIC,IAAJ,EAAU,OAAOA,IAAP;AACV,WAAOF,aAAP;AACD,GALD,CAKE,OAAOI,CAAP,EAAU;AACV;AACAC,IAAAA,OAAO,CAACC,IAAR,CAAaF,CAAb,EAAgBH,YAAhB;AACA,WAAOD,aAAP;AACD;AACF;AAED;AACA;AACA;;AACA,OAAO,SAASO,UAAT,CAAoBf,GAApB,EAAuC;AAC5CE,EAAAA,MAAM,CAACC,YAAP,CAAoBY,UAApB,WAAkCjB,cAAlC,cAAoDE,GAApD;AACD;AAED;AACA;AACA;AACA;;AACA,OAAO,SAASgB,MAAT,GAA0B;AAC/B,SAAOC,IAAI,CAACC,MAAL,GACJC,QADI,CACK,EADL,EAEJC,MAFI,CAEG,CAFH,EAEM,CAFN,CAAP;AAGD","sourcesContent":["/* eslint-disable no-console */\n// Prefix to use with local storage keys.\nconst STORAGE_PREFIX = \"otp\";\n\n/**\n * Store a javascript object at the specified key.\n */\nexport function storeItem(key: string, object: unknown): void {\n window.localStorage.setItem(\n `${STORAGE_PREFIX}.${key}`,\n JSON.stringify(object)\n );\n}\n\n/**\n * Retrieve a javascript object at the specified key. If not found, defaults to\n * null or, the optionally provided notFoundValue.\n */\nexport function getItem(key: string, notFoundValue: unknown = null): unknown {\n let itemAsString: string;\n try {\n itemAsString = window.localStorage.getItem(`${STORAGE_PREFIX}.${key}`);\n const json = JSON.parse(itemAsString);\n if (json) return json;\n return notFoundValue;\n } catch (e) {\n // Catch any errors associated with parsing bad JSON.\n console.warn(e, itemAsString);\n return notFoundValue;\n }\n}\n\n/**\n * Remove item at specified key.\n */\nexport function removeItem(key: string): void {\n window.localStorage.removeItem(`${STORAGE_PREFIX}.${key}`);\n}\n\n/**\n * Generate a random ID. This might not quite be a UUID, but it serves our\n * purposes for now.\n */\nexport function randId(): string {\n return Math.random()\n .toString(36)\n .substr(2, 9);\n}\n"],"file":"storage.js"}