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

Use WCAG recommendation to fill in GTFS route text color if it is missing #6308

Merged
merged 4 commits into from
Dec 12, 2024

Conversation

miklcct
Copy link
Contributor

@miklcct miklcct commented Dec 5, 2024

Summary

This is a rework of #5490 . It uses the WCAG recommendation to decide if the text color should be black (on a light background) or white (on a dark background).

The color calculation is refactored out into a separate util module such that it is testable, and is changed to use the official sRGB color space formula.

The luminance threshold is 0.179 according to the WCAG formula (where the previous code used 0.5). It has an effect of considering red (255, 0, 0) a light color that black text (instead of white) should be placed on red background, as black has a greater contrast with red than white per accessibility guidelines. This will need some discussion.

Issue

None

Unit tests

Added for color calculation.

Documentation

Javadoc

@miklcct miklcct requested a review from a team as a code owner December 5, 2024 17:11
Copy link

codecov bot commented Dec 5, 2024

Codecov Report

Attention: Patch coverage is 90.90909% with 1 line in your changes missing coverage. Please review.

Project coverage is 69.81%. Comparing base (20696c1) to head (d12373f).
Report is 82 commits behind head on dev-2.x.

Files with missing lines Patch % Lines
.../opentripplanner/gtfs/graphbuilder/GtfsModule.java 0.00% 1 Missing ⚠️
Additional details and impacted files
@@              Coverage Diff              @@
##             dev-2.x    #6308      +/-   ##
=============================================
+ Coverage      69.79%   69.81%   +0.02%     
- Complexity     17798    17827      +29     
=============================================
  Files           2019     2021       +2     
  Lines          76126    76248     +122     
  Branches        7786     7802      +16     
=============================================
+ Hits           53132    53234     +102     
- Misses         20288    20299      +11     
- Partials        2706     2715       +9     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@t2gran
Copy link
Member

t2gran commented Dec 6, 2024

I have not read the code, but from the title, is this inserting data into the OTP model of it is missing in the feed? We do not do that in general. OTP should plan, not correct incomplete data.

@miklcct
Copy link
Contributor Author

miklcct commented Dec 6, 2024

I have not read the code, but from the title, is this inserting data into the OTP model of it is missing in the feed? We do not do that in general. OTP should plan, not correct incomplete data.

Yes, it is adding missing data in the feed. This code has already been there for 9 years. Do you think we should remove it?

I am happy to remove this piece of code as well.

@t2gran
Copy link
Member

t2gran commented Dec 6, 2024

Ok if it already exists then this is probably å good fix. We can talk about it next week

@miklcct
Copy link
Contributor Author

miklcct commented Dec 6, 2024

OK let's discuss if we should

  • remove the route_text_color generation
  • fully adopt the WCAG accessibility standard as coded in this PR
  • do the refactor but leave the threshold as 0.5

Copy link
Member

@leonardehrenfried leonardehrenfried left a comment

Choose a reason for hiding this comment

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

Generally I'm ok with this, since it replaces one type of guesswork with another one.

I have a comment about the test, so please take a look.

@t2gran
Copy link
Member

t2gran commented Dec 11, 2024

I am ok with this as well. I think it removes guesswork with something that is better, the WCAG recommendation is after all a W3C Guideline.

abyrd
abyrd previously approved these changes Dec 12, 2024
Copy link
Member

@abyrd abyrd left a comment

Choose a reason for hiding this comment

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

This looks fine to me. As @t2gran said, this is replacing some existing guesswork with newer guesswork that we seem to all agree yields a better result. My only concern was that readers might be left wondering whether the WCAG recommendations hold some special status in the OTP project, whether they should start applying or implementing those standard elsewhere in the project. A note to that effect, even on this PR could help someone in the future.

@optionsome
Copy link
Member

I wasn't even aware that this functionality exists. I think we would be hesitant to add this as a default functionality now but since this has already existed for a long time, I don't know if this is something we can get rid of or make default off anymore. Main problem with this code is that it makes it difficult to know if some color is part of some brand or is it something we generate (i.e. making it more difficult for a client to decide if this color should be used or not).

@optionsome optionsome requested review from t2gran and abyrd and removed request for t2gran December 12, 2024 14:57
@optionsome optionsome added this to the 2.7 (next release) milestone Dec 12, 2024
@optionsome optionsome added the GTFS Related to import of GTFS data label Dec 12, 2024
@optionsome optionsome merged commit 8c965c9 into opentripplanner:dev-2.x Dec 12, 2024
6 checks passed
t2gran pushed a commit that referenced this pull request Dec 12, 2024
@miklcct miklcct deleted the gtfs-text-luminance branch December 17, 2024 17:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
GTFS Related to import of GTFS data Improvement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants