Skip to content

add option to randomize new tag colors #534

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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

evogelsa
Copy link

@evogelsa evogelsa commented Mar 7, 2025

Hello! This PR is mostly a draft of an idea, so open to suggestions or contributions for how to improve this.

I like to have colorful tags to create visual distinction on my timeline, but I don't really care to set colors myself, and manually randomizing the color each time is somewhat annoying since I commonly make new tags. This PR adds an option to the user settings for how to determine the default tag color. The options I added are:

  • Default - use the current "brand yellow" color
  • From Tag Name - I noticed some old code for this, so it could maybe be brought back here, but I don't think it's currently functional as is
  • Random - Randomly generate a color

This seemed mostly functional when I tested it, but there's definitely some room for improvement. A couple notes:

  • Random currently feels a little jarring because it will change the preview color of the tag as you type the name
  • Making the color options into an enum might be a little nicer than passing around raw strings
  • The from tag name setting didn't seem to work, and I didn't really try to make it work. Not sure if it's even something worth keeping around or not.

@evogelsa evogelsa changed the title feat: add option to randomize new tag colors add option to randomize new tag colors Mar 26, 2025
@almarklein
Copy link
Owner

Sorry for getting back to this after so long.

Generating the color from the name was an early idea to give unique (pseudo) random colors to tags, without actually needing to store the color. I think we can re-use that idea here?

Right now, when using "random colors", the color changes every time a tag is shown, so it should look like a dico or something? 😅

What if the default tag color can be "from name" or "yellow"?

also tidy up the settings dialog options per feedback
@evogelsa
Copy link
Author

Sorry for getting back to this after so long.

No worries 🙂

Generating the color from the name was an early idea to give unique (pseudo) random colors to tags, without actually needing to store the color. I think we can re-use that idea here?

I see, makes sense. I don't know if there's a way to keep the from tag name option without have the "disco" colors since changing the tag name would then have to change the color. Maybe the tag color could be generated when the dialog closes, but IMO I'd prefer to see the color in the dialog even if it's changing as you type.

Right now, when using "random colors", the color changes every time a tag is shown, so it should look like a dico or something? 😅

Yeah, agreed that was definitely the most jarring part of this. I've updated the "random" option in the most recent commit to generate the next color once when you open the dialog, and use that for any new tag created in that dialog. It's not perfect since creating multiple tags in the same dialog will result in them all having the same color, but I think it's still an improvement from always having new tags be yellow.

What if the default tag color can be "from name" or "yellow"?

Hopefully I understood this correctly, but I updated the selection options in the settings dialog to be "Yellow", "From Name", and "Random".

Yellow = current brand yellow default
From Name = use the tag name to generate the color
Random = Use a randomly generated color

Let me know what you think! I'd love to get this integrated if you like the changes.

@evogelsa
Copy link
Author

Oh, and I also added a small bug fix to the random color generation. I noticed it would generate colors with a leading zero, e.g. #0abcde. However, leading zeros were being dropped from the color string, and this caused them to not display correctly. I added a zero pad if necessary to ensure this would not happen.

@almarklein
Copy link
Owner

So if I know create a new tag, and have it set to random colors, in what cases will it change color?

  • Does it change color every time the app is rendered?
  • Does it change color every time the app is reloaded?

@almarklein
Copy link
Owner

Oh, and I also added a small bug fix to the random color generation

Nice! 🙏

@evogelsa
Copy link
Author

So if I know create a new tag, and have it set to random colors, in what cases will it change color?

It should only get a new color when the tag is created. It's using the same mechanism as clicking "random" from the edit tag dialog to generate the color, and the color is saved to the tag store like a custom color. Reloading the app should not affect the existing tag colors.

@evogelsa
Copy link
Author

@almarklein friendly poke🙂

Do you have any other feedback for this PR or could it be merged?

@almarklein
Copy link
Owner

I think there's still a few problems with this PR, like using the settings to set next_random_color, which is not what settings are for, and also fails when creating multiple new tags. Plus it generates and stores new colors for all tags previously created. And when the user dislikes it and sets it back to the default, the colors stay the random version.

All of these problems can be solved by using the color by name feature. So two options for the default color: Yellow, or byname. You can still call it random in the form and use the from-name implementation.

@evogelsa
Copy link
Author

Ah okay, I see the point you were trying to make earlier now regarding the color by name. Thanks for the feedback!

when the user dislikes it and sets it back to the default, the colors stay the random version.

What are the steps to reproduce this? When I tested the pressing the "default" button in the tag color dialog, it still used the default yellow color iirc.

All of these problems can be solved by using the color by name feature.

I'm not sure if I entirely agree with this statement however. I think using the color by name will still end up with the "disco" colors while typing out a new tag, unless the tag color is not generated until after the dialog is closed. I think a better option may be to still generate random colors, and store those in color generator class rather than the settings. To fix the issue of new tags sharing the same random color, the random color can just be popped each use to cause the next one to be new.

@almarklein
Copy link
Owner

What are the steps to reproduce this?

  • Change the setting to use random colors.
  • Create a new record with a new tag, it will be a ramdom color
  • Change the setting back to use yellow
  • The new tag will still be the random color that was assigned when created.

This is not too bad in itself. But the thing is that a tag is assigned as soon as it encountered. So let's say that we accept the PR as it is now. What happens for all users is this:

  • By default the setting is yellow, so every tag that the application is showing will be assigned yellow in the first moments that the new version is loaded. This happens to every tag for which get_color_for_tag() is called. So for all tags that are displayed at some point.
  • Now the user changes the setting to 'random'.
  • The tags that were visible stay yellow. New tags become random.
  • But now the user scrolls back to last week, these tags were not shown yet, and they will turn to random colors.
  • Now the user sets back the setting to use 'yellow' colors.
  • Indeed new tags will be yellow. But the tags from last week are still random.

Basically, the fact that tag colors are assigned based on whether they are shown or not is very unpredictable and will be annoying.

Using the color-by-name fixes this, because it does not need to store the color. I agree that the tag changing color as you type it looks a bit funny, but IMO that's a small price to pay.

@evogelsa
Copy link
Author

Gotcha, yeah I was able to reproduce this now with your latest comment. I agree past tags changing color is not the intent, and would be confusing.

The new tag will still be the random color that was assigned when created.

This part however was intentional, so I'd like to keep that behavior, and using the from name option is a creative way to solve that issue. I did not realize that currently the default color is not being saved to the DB with each new tag, and that definitely limits the available options. I'll update this PR in a bit with those changes. Thanks for taking a look.

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