materialsproject/crystaltoolkit

Structure viewer legend doesn't update when changing the color scheme.

janosh opened this issue · 1 comments

janosh commented

Visited https://next-gen.materialsproject.org/toolkit and selected "Accessible" from the "Change color scheme" dropdown.

Screenshot 2023-07-15 at 3 34 18 PM

The colors in the legend no longer match the ball and stick colors in the viewer.

Screenshot 2023-07-15 at 3 33 28 PM

janosh commented

This clientside callback looks like it might be the place to fix. Not sure if it should trigger some other callback or update the legend itself. Probably former.

app.clientside_callback(
"""
function (colorScheme, radiusStrategy, drawOptions, displayOptions) {
const newDisplayOptions = {...displayOptions}
newDisplayOptions.color_scheme = colorScheme
newDisplayOptions.radius_strategy = radiusStrategy
newDisplayOptions.draw_image_atoms = drawOptions.includes('draw_image_atoms')
newDisplayOptions.bonded_sites_outside_unit_cell = drawOptions.includes(
'bonded_sites_outside_unit_cell'
)
newDisplayOptions.hide_incomplete_bonds = drawOptions.includes('hide_incomplete_bonds')
return newDisplayOptions
}
""",
Output(self.id("display_options"), "data"),
Input(self.id("color-scheme"), "value"),
Input(self.id("radius_strategy"), "value"),
Input(self.id("draw_options"), "value"),
State(self.id("display_options"), "data"),
)