cbouy / mols2grid

Interactive molecule viewer for 2D structures

Home Page:https://mols2grid.readthedocs.io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Feature request: allow string formatting for values in subsets

slochower opened this issue · comments

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:

value_names = value_names[:-1] + f", {{ attr: 'style', name: {name!r} }}]"

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

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

Yep, that sounds like a good plan!

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.

Now available in v0.0.5 with the transform parameter:

transform={"Solubility": lambda x: f"{x:.2f}"}

Looks great! 🎉