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 option to white marker label color #5

Open
mkaulisch opened this issue Jan 16, 2023 · 8 comments
Open

add option to white marker label color #5

mkaulisch opened this issue Jan 16, 2023 · 8 comments
Assignees
Labels
enhancement New feature or request

Comments

@mkaulisch
Copy link

some colors in the scheme / colorpalette I need to use due to corporate design are so dark that white would be a better choice as mlabcolor(). Not sure if there is a way to determine it automatically by colorpalette - but an option to say e.g. color 3 = white - would be cool.

@mkaulisch
Copy link
Author

It would be cool if the labcolor()-option from the sunburst-package can be ported to treemap (asjadnaqvi/stata-sunburst#3 (comment)).

@mkaulisch
Copy link
Author

mkaulisch commented Oct 8, 2024

Dear @asjadnaqvi, I propose the following changes to the code:
Insert after line 673

            mata: S = ColrSpace()
            mata: S.colors("black `r(p`clr0'name)'")
            mata: st_local("contrast_black",strofreal(S.contrast((1,2))))
            
            if `contrast_black' > 4.5 {
	            local mlabcolor "black"
            }
            if `contrast_black' <= 4.5 {
	            local mlabcolor "white"
            }

Then change all mlabc(black) into mlabc(mlabcolor')`

I tested it with my use case and it works.

@mkaulisch
Copy link
Author

My code above only works with named colors. I try to find a way to get the RGB values working...

@asjadnaqvi
Copy link
Owner

Marc, can you give an example figure to show what you are trying to do?

@mkaulisch
Copy link
Author

Of course:
My own program is called treemap2:

cwf default
cap frame drop auto
frame create auto
cwf auto
sysuse auto

split make, parse(" ") gen(brand)
ren brand1 brand
egen model = concat(brand2 brand3)

treemap2 weight, by(brand model) ///
		addtitles palette(hhu_color_fak) ///
		name(brand_model, replace)

brand_model

@mkaulisch
Copy link
Author

With the palettes that do not use named colors - it does not work. But I am a Mata Newbie - so no clue how to do it the best way. It should be possible to add the RGB into the color list and then to contrast them...

@asjadnaqvi
Copy link
Owner

Ok so for darker background colors, the label color should be lighter in order to increase the contrast for readability.

I prefer having a generic solution that can be added to all packages. For sure it will be very useful. For example bimap, labels are not visible with darker colors. I will have a look!

@mkaulisch
Copy link
Author

This code-addition also works with the tableau-palette without named colors:


            mata: S = ColrSpace()
            mata: S.colors("black")
            mata: S.add_Colors("rgb `r(p`clr0')'")
            mata: st_local("contrast_black",strofreal(S.contrast((1,2))))
            
            if `contrast_black' > 4.5 {
	            local mlabcolor "black"
            }
            if `contrast_black' <= 4.5 {
	            local mlabcolor "white"
            }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants