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

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

Closed
slochower opened this issue Apr 1, 2021 · 5 comments · Fixed by #12
Closed

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

slochower opened this issue Apr 1, 2021 · 5 comments · Fixed by #12

Comments

@slochower
Copy link

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.

@cbouy
Copy link
Owner

cbouy commented Apr 1, 2021

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
Copy link
Author

Yep, that sounds like a good plan!

@fredrikw
Copy link
Contributor

fredrikw commented Apr 6, 2021

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.

fredrikw pushed a commit to fredrikw/mols2grid that referenced this issue Apr 6, 2021
@cbouy cbouy linked a pull request Apr 7, 2021 that will close this issue
@cbouy cbouy closed this as completed in #12 Apr 7, 2021
cbouy pushed a commit that referenced this issue Apr 7, 2021
* New `transform` parameter that accepts a dictionary of field-function items where each function transforms the input value that will be displayed.

Co-authored-by: Fredrik Wallner <fredrik.wallner@irlab.se>
Co-authored-by: Cédric Bouysset <cedric.bouysset@unice.fr>
@cbouy
Copy link
Owner

cbouy commented Apr 8, 2021

Now available in v0.0.5 with the transform parameter:

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

@slochower
Copy link
Author

Looks great! 🎉

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 a pull request may close this issue.

3 participants