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

Color handling #104

Closed
pantierra opened this issue Dec 16, 2017 · 12 comments
Closed

Color handling #104

pantierra opened this issue Dec 16, 2017 · 12 comments
Assignees

Comments

@pantierra
Copy link
Contributor

pantierra commented Dec 16, 2017

Transit lines in GTFS have a route_color and a route_text_color, whereas the text color "should provide sufficient contrast when viewed on a black and white screen".

osm2gtfs tries to get this information from OpenStreetMap's colour tag. This can be information in RB hex code or a W3C color name.

In a first step, in #99, it is introduced to map the information from colour to the Line object to be used in the creators. The standard creator assume RGB hex colors, as also desired by GTFS. However for Estelí two good and additional functionalities are used, that could be considered to be moved also into the core of osm2gtfs:

  • Transform W3C color code into RGB hex code.
  • Calculate a suitable route_text_color based on route_color.
@pantierra
Copy link
Contributor Author

In the current Estelí implementation the two things are addressed the following:

  • Transform W3C color code into RGB hex code: The python extension webcolors is used to provide the functionality. A proper test of there is a valid name of a valid RGB hex code or a non-valid string would need to be included, I guess, in order to make it attractive to the core.
  • Calculate a suitable route_text_color based on route_color: Currently it uses this code snippet which calculates the complementary or opposite color in the color spectrum. As far as I understand, this doesn't seem to fit the requirement GTFS is putting on this, to have a good contrast. I think we need more a function that checks the "brightness" of the given route_color and returns either #000000 (black) or #ffffff (white).

@pantierra
Copy link
Contributor Author

I think those screenshots show pretty nicely why a white-black decision (right side) should be taken to generate the route_text_color rather than the complementary color (left side):

image

@ialokim
Copy link
Contributor

ialokim commented Dec 21, 2017

I think those screenshots show pretty nicely why a white-black decision (right side) should be taken to generate the route_text_color rather than the complementary color (left side)

You're completely right 👍 Looks like ugly the left side 🤢😅

I think we need more a function that checks the "brightness" of the given route_color and returns either #000000 (black) or #ffffff (white).

I think I found a good approach, see this blog post.

@pantierra
Copy link
Contributor Author

This looks convincing. Let's try it.

@nlehuby
Copy link
Collaborator

nlehuby commented Dec 22, 2017

transitfeed lib already have some useful functions we should investigate:
https://github.com/google/transitfeed/blob/23e953749e4024130db102d30b2088e9bfae0e3b/transitfeed/route.py#L220

@ialokim
Copy link
Contributor

ialokim commented Dec 22, 2017

transitfeed lib already have some useful functions we should investigate

I've checked it and they use the W3C formula to calculate the perceived brightness, but as stated on the blog post I've already posted above:

it tends to give wrong results for many colors, especially shades of yellow.

@pantierra
Copy link
Contributor Author

pantierra commented Dec 23, 2017

Implemented the suggestion by @ialokim in the RoutesCreatorEsteli, see function _define_route_text_color. Seem to work very well for Estelí.

@pantierra
Copy link
Contributor Author

I'm pretty happy with the current implementation, now. And I would suggest to move them to core but to two different places:

  • name to hex: into the osm_connector so to normalize the data from OSM, where it can be either a web color name or the RGB hex value, to be consistent in our classes as hex value.
  • move the function to get a corresponding color with high visible contrast into the Helper class and call it from the standard routes_creator, not before.

@ialokim
Copy link
Contributor

ialokim commented Dec 23, 2017

I'm pretty happy with the current implementation, now. And I would suggest to move them to core

🎉

but to two different places

Why not having them both inside the Helper class to group colour functions together?

@pantierra
Copy link
Contributor Author

pantierra commented Dec 23, 2017

Why not having them both inside the Helper class to group colour functions together?

Because there is only one function, for the other purpose we use the python extension webcolors (Probably it is easier to see it in code than talkng abstractly about it).

A proper test of there is a valid name of a valid RGB hex code or a non-valid string would need to be included

Is included now (see changes in the osm_connector)

@pantierra
Copy link
Contributor Author

Created a PR for this: #114

@pantierra pantierra self-assigned this Dec 23, 2017
@pantierra pantierra added the ready label Jan 6, 2018
@pantierra
Copy link
Contributor Author

Done.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants