jupyter-widgets / ipydatagrid

Fast Datagrid widget for the Jupyter Notebook and JupyterLab
BSD 3-Clause "New" or "Revised" License
579 stars 51 forks source link

Use sensible defaults for BarRenderer.bar_value #490

Closed ianthomas23 closed 8 months ago

ianthomas23 commented 8 months ago

Describe your changes

This PR adds some sensible defaults for scales used in BarRenderer.bar_value so that they can be omitted by the user. If min or max arguments of a DateScale, LinearScale or LogScale are omitted, they are determined from the data in the corresponding column. An example from some of the example notebooks is that the previous use of

BarRenderer(bar_value=DateScale(min=df[\"Dates\"][0], max=df[\"Dates\"][n - 1]))

can be replaced by

BarRenderer(bar_value=DateScale())

The calculations occur in the DataGrid constructor on the Python side.

Also, bar_value now accepts None and will create either a DateScale or LinearScale depending on the data type of the corresponding column. bar_value already has a default of 0.0 and we cannot change this default without causing a backwards incompatibility, hence the use of None.

This new functionality is not supported in default_renderer, header_renderer, or corner_renderer as they are not attached to a particular data column.

Testing performed

Possible future work

This work could be extended to cover other Renderer classes, and renderers that refer to multiple columns (e.g. default_renderer.