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

Consider adding a layer to remove coupling with views and BlueskyRun API #65

Open
danielballan opened this issue Dec 4, 2020 · 4 comments

Comments

@danielballan
Copy link
Member

danielballan commented Dec 4, 2020

The view code knows about of the concept of a BlueskyRun and its particular interface and signals:

run = line_spec.run
x, y = line_spec.func(run)

self.connect(run.events.new_data, update)
self.connect(
run.events.completed,
lambda event: run.events.new_data.disconnect(update),
)

What if, instead, we separate the bluesky-aware aspect into a separate components, perhaps by subclassing like so:

class LineSpec:
    "Not bluesky-aware, just knows about an abstract `transform` (callable) and `data`"
    def __init__(self, update: callable, label, style=None):
        "Expected signature of update is: update() -> x: Array, y: Array"
        ...
        self.events = EmitterGroup(new_data=Event, completed=Event)

class BlueskyLineSpec(LineSpec):
    "Hooks up LineSpec's signals to BlueskyRun signals."
    def __init__(self, transform: callable, run: BlueskyRun, label, style=None):

        run.events.new_data.connect(self.events.new_data)
        run.events.completed.connect(self.events.completed)

        def update():
            return transform(data)

        super().__init__(update, label, style)

then LineSpec and the views become generic. That would extend the utility of these components at the cost of an additional layer of signaling.

@danielballan
Copy link
Member Author

Another important consequence of this is that the bottom layer LineSpec is not bound to a single BlueskyRun, and you could generate LineSpecs joining data from multiple Runs. And of course from things that have nothing to do with BlueskyRun at all.

@danielballan
Copy link
Member Author

danielballan commented Dec 4, 2020

Also, if transform always returns a dict of kwargs rather than an artist-specific construct (like (x, y) for lines) we can simplify the view code and reduce the artist-specific code.

h/t @tacaswell

@danielballan
Copy link
Member Author

#97 does this almost entirely. It moves the 1:1 correspondence to BlueskyRun into a classmethod. That could easily be moved off to a subclass in the future.

@danielballan
Copy link
Member Author

@tacaswell shared this snippet of work related to matplotlib 4.0 https://gist.github.com/tacaswell/95177903175dbc28be5353b4a0e5118f. Keeping this here so I don't lose it.

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