cbouy / mols2grid

Interactive molecule viewer for 2D structures
https://mols2grid.readthedocs.io
Apache License 2.0
207 stars 25 forks source link

Feature request: allow string formatting for values in subsets #10

Closed slochower closed 3 years ago

slochower commented 3 years ago

Hi, thanks again.

It's really handy that you built-in CSS styling of the labels and tooltips, like color: red. It would also be great to support Python string formatting (e.g., to trim the string representation of floats). For example:

image

I'm guessing this will be tricky since it looks like you're building up the CSS manually here: https://github.com/cbouy/mols2grid/blob/849cf49a105b941c3c6918bb4b91d9b4d348c4ed/mols2grid/molgrid.py#L316

...but I think it's something to consider for the future.

cbouy commented 3 years ago

Yes that would be a nice addition! However, I'll very likely put it outside of the style parameter for both clarity for users and simplicity on my side... Something like this with a fmt parameter that works similarly to style:

image

slochower commented 3 years ago

Yep, that sounds like a good plan!

fredrikw commented 3 years ago

What do you think about also allowing callbacks? You could check in your "what would run internally" code if the format is a string or a callable and apply .format if its a string or otherwise just hand it over to apply. That way, the format could be very flexible.

cbouy commented 3 years ago

Now available in v0.0.5 with the transform parameter:

transform={"Solubility": lambda x: f"{x:.2f}"}
slochower commented 3 years ago

Looks great! 🎉