cosmicds / hubbleds

Hubble's law data story
MIT License
0 stars 8 forks source link

Zooming on the dotplot does not refine the bin size #575

Closed johnarban closed 1 month ago

johnarban commented 3 months ago

Zooming in on the dotplot does not refine the bin size

before

image

after zoom

image
johnarban commented 2 months ago

This can be closed. It does refine the bins, it is just that, perhaps due to rounding, a lot of points have the same value.

johnarban commented 2 months ago

So this does seem to be an issue, but just in the app

The following code in a notebook does work (zoom seems to work properly)

import solara 

from glue_jupyter import jglue
from glue.core import Data

from hubbleds.state import LOCAL_STATE
from hubbleds.remote import LOCAL_API
from hubbleds.components import DotplotViewer

app = jglue()

data = LOCAL_API.get_example_seed_measurement(LOCAL_STATE, which='second' )
glue_seed = Data(label='Second',
                                **{
                    k: np.asarray([r[k] for r in data])
                    for k in data[0].keys()
                })
glue_seed.style.color = 'blue'
app.data_collection.append(glue_seed)

@solara.component
def Page():
    with solara.Card(style={"width": "700px"}):
        DotplotViewer(app, 
                    data = [app.data_collection["Second"]],
                    component_id="velocity_value",
                    vertical_line_visible=False,
                    )

Page()
johnarban commented 2 months ago

The issue seems to occur when a seconds data set is added with a single value

This fails when single data is second

def Page():
    with solara.Card(style={"width": "700px"}):
        DotplotViewer(app, 
                    data = [app.data_collection["AllData"],app.data_collection["Single"]],
                    component_id="velocity_value",
                    vertical_line_visible=False,
                    )

Page()

However, things work again, if Single is added first

@solara.component
def Page():
    with solara.Card(style={"width": "700px"}):
        DotplotViewer(app, 
                    data = [app.data_collection["Single"],app.data_collection["AllData"]],
                    component_id="velocity_value",
                    vertical_line_visible=False,
                    )

Page()

However, in this case the plot will initially render with the incorrect zoom level set.

I have fixed this for the story in a commit on #585

When using HubbleDotPlotView directly, it often works, regardless of which is first or second, but can begin have strange intial views when the single data is loaded first, and intermittently may not zoom properly.