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

Adding javascript renderer causes columns to change size randomly #212

Open
MichaelTiemannOSC opened this issue Sep 28, 2021 · 0 comments
Open

Comments

@MichaelTiemannOSC
Copy link

I have pieced together two examples from the documentation, creating a spreadsheet that renders the background colors of a changing value:

import ipywidgets as widgets
import ipysheet

jscode_renderer_negative = """function (value) {
  return {
    backgroundColor: value < 0 ?  'lightpink' : 'lightgreen'
  };
}
"""
ipysheet.renderer(code=jscode_renderer_negative, name='negative');

sheet = ipysheet.sheet(rows=3, columns=2, column_headers=False, row_headers=False)
cell_a = ipysheet.cell(0, 1, 1, label_left='a', renderer='negative')
cell_b = ipysheet.cell(1, 1, 2, label_left='b', renderer='negative')
cell_sum = ipysheet.cell(2, 1, 3, label_left='sum', read_only=True, renderer='negative')

# create a slider linked to cell a
slider = widgets.FloatSlider(min=-10, max=10, description='a', layout=widgets.Layout(width='50%'))
widgets.jslink((cell_a, 'value'), (slider, 'value'))

# changes in a or b should trigger this function
def calculate(change):
    cell_sum.value = cell_a.value + cell_b.value

cell_a.observe(calculate, 'value')

widgets.VBox([sheet, slider])

When I move the slider in the positive realm, the columns remain stable. When I move to the negative realm, sometimes the column width changes dramatically, from the normal 50/50 break expected with two columns to a 25/75 break.

This happens in particular as I move from -4 to -3.5 using the arrow key to move in increments of 0.1. When I remove the javascript renderer, the column widths change very subtly, likely as the widget is recalculating the width differences due to the slize of the rendered numbers.

Please let me know what scripts you'd like me to run if you need additional information.

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

No branches or pull requests

1 participant