Skip to content

Conversation

@VincentVanlaer
Copy link
Collaborator

This is refactor of the pgstar colors that partially originates from the build system branch.

The first two commits (those effectively come from the build system branch) are just a cleanup of the color setting code. I replaced some custom code to map color names to rgb values using a file provided by pgplot with an equivalent function in pgplot itself. There was

The next two commits then get rid of the dynamic mapping of color indices, and just make the list static, since that is what ends up happening in practice anyway. I have also lifted the actual named colors from the pgplot provided rgb.txt.

I would consider the first set of changes more or less of a bug fix, so I would like to see those go in. The second set is a refactor I would do, but not something I would consider necessary.

This has the following benefits:

- Remove effectively duplicated code, since pgplot supports the same
  thing.
- Support more locations for rgb.txt, as given by the pgplot library
  (e.g. loading from a system default folder, if pgplot has been
  installed system wide)
The color indices were written to every time a new device was opened.
While these indices should be the same time set_device_colors is called,
there is not really a reason to make these not static. The colors that
were set by name also didn't have an associated variable, so the only
way to refer to them was by specifying the actual values.

Since this removes a bunch of variables from the star_pgstar,
pgstar_support and pgbinary_support, this is a breaking change.
@pmocz pmocz self-assigned this Apr 14, 2025
@pmocz
Copy link
Member

pmocz commented Apr 14, 2025

This is great!

@Debraheem
Copy link
Member

The next two commits then get rid of the dynamic mapping of color indices, and just make the list static, since that is what ends up happening in practice anyway.

Naive question here. Does this mean the colors in pgstar (say in the abundance panel) will not change on the fly?

@VincentVanlaer
Copy link
Collaborator Author

The way pgplot works is that in order to draw something in a certain color, you have to

  1. Map a color index to the color (the rgb values) with pgscr
  2. Select that color index before you draw the thing you want with pgsci

At the initialization of pgplot, MESA sets up a bunch of color indices. This happens whenever a pgplot device is opened, so also when a plot is saved as png for example. The values of those indices where computed dynamically, and written to bunch of global variables (clr_Red, clr_Green, ...). These variables would always have the exact same values, and map to the exact same color, since that is all hard coded (except for white-on-black vs black-on-white). This PR makes those variables static instead.

When one of the panels selects a color, it does so by taking one of these global variables/parameters and pass them to pgsci. So in order to have dynamic colors, one either needs to have some flag to switch which parameter to use, or use the color indices directly (e.g. reading them from an inlist). But none of this has been affected by this PR (in fact, it makes it a bit easier to see what the values of those color indices are, and to keep them actually stable as colors are added).

@pmocz pmocz self-requested a review April 18, 2025 17:37
@pmocz
Copy link
Member

pmocz commented Apr 18, 2025

Looks good! @VincentVanlaer ready to merge?

@VincentVanlaer VincentVanlaer merged commit dc8932f into main Apr 23, 2025
4 checks passed
@VincentVanlaer VincentVanlaer deleted the VincentVanlaer/pgplot-static-colors branch May 13, 2025 21:50
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.

4 participants