Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add “Maximum Speed” to analysis sidebar #830

Merged
merged 3 commits into from
Oct 21, 2024

Conversation

mjaschen
Copy link
Contributor

It shows the distribution of maximum speeds for all ways on the current route (if that data is available, otherwise it’s summed up under “unknown”).

maxspeed:forward and maxspeed:backward is respected in conjunction with reversedirection.

Hovering/clicking table rows to highlight matching segments on the route work the identical to the other analysis tables.

Additionally, all tags in the analysis tab (way type, surface, smoothness) are translateable now. The values were added to en.json.

Some HTML is rendered with template literals now, instead of concatenating strings.

Variable declarations were changed from var to const/let.

It shows the distribution of maximum speeds for all ways on the
current route (if that data is available, otherwise it’s summed up
under “unknown”).

`maxspeed:forward` and `maxspeed:backward` is respected in conjunction
with `reversedirection`.

Hovering/clicking table rows to highlight matching segments on the
route work the identical to the other analysis tables.

Additionally, all tags in the analysis tab (way type, surface,
smoothness) are translateable now. The values were added to `en.json`.

Some HTML is rendered with template literals now, instead of
concatenating strings.

Variable declarations were changed from `var` to `const`/`let`.
Copy link
Collaborator

@bagage bagage left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for implementing this feature 👍 looks good to me only few minor nitpickings but good to go!

* for the whole track
* - renders statistics tables
* - create event listeners which allow to hover/click a
* table row for highlighting matching track segments
*
* @param {Polyline} polyline
* @param {Array} segments
* @param {Array} segments route segments between waypoints
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: segments route segments? Shouldn't it be route segments alone?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The first segments refers to the variable name, the three following words are the description.

As per JSDoc a hyphen should be inserted after the parameter name. I'll add this in a follow-up pull request.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah yeah ok my bad, 👍

locales/en.json Show resolved Hide resolved
wayTagParts[1],
]);
if (tagName.indexOf('maxspeed') === 0) {
formattedName += ' km/h';
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: not possible to have it within the i18n content directly?

Eg add sidebar.analysis.data.maxspeed.XXX and in English set to %s km/h?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, good catch. I'll change it in a follow-up PR.

analysisSortable[type].sort(function (a, b) {
return b.distance - a.distance;
});
if (type === 'maxspeed') {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: probably would have used a switch case for this but not a blocker at all :)

if (tagName.indexOf('maxspeed') === 0) {
formattedName += ' km/h';
formattedName = i18next.t('sidebar.analysis.data.maxspeed', {
maxspeed: wayTagParts[1],
Copy link
Collaborator

@bagage bagage Oct 20, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could totally remove the if specific to maxSpeed, and instead have a fallback mecanism:

  1. try to use the full key sidebar.analysis.data.highway.footway
  2. if not available, try sidebar.analysis.data.highway
  3. otherwise simply fallback to untranslated highway type eg footway here

It should cover all cases while being agnostic of the kind of analysis (if there are more analysis coming in the future 😏)

const highwayType = wayTagParts[1];
formattedName = i18next.t(
    [
         'sidebar.analysis.data.' + tagName + '.' + highwayType,
         'sidebar.analysis.data.' + tagName,
          highwayType
    ], 
    {highwayType: highwayType}
);

If a translation key needs the highwayType it can use it, otherwise it can just skip it and it should work just fine.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I spotted some more possibilities to simplify the translations for the analysis sidebar, but I'd rather create a separate PR as there're changes on places unrelated to this PR.

Can you agree with this?

@bagage bagage merged commit 59a1435 into nrenner:master Oct 21, 2024
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants