SolaraViz API Design #2236
Replies: 6 comments 12 replies
-
I'm swamped today and maybe tomorrow, but will find a time window tomorrow to look into this. |
Beta Was this translation helpful? Give feedback.
-
It is, and you're right on time, since we're in 3.0 alpha phase and can break everything :)
Love it, that's obviously a win.
If you might have the time, could you read though this issue and give your insights on it? I think it's related: For example, in my head it's useful to be able to pass a model instance, so I'm curious what you think about that.
Yes, this is better that the current practice of passing measure strings.
Agreed, I never liked the This sounds way more modular and scalable than what we currently have (and it's hard to get it right on the first iteration, so that's understandable). You're the absolute expert of us on front-end development and I trust your choice on UI/UX design, I like these ideas, so from my part, go ahead and built it. If you're serious about this I'm going to fix that our examples are tested in CI Monday, so we can see which examples need to be updated and keep them in sync. |
Beta Was this translation helpful? Give feedback.
-
Thanks for your input! I was playing around yesterday evening and one of the comments from maarten in #2176 could be extremly helpful, so thanks for bringing this back on my attention. Regarding the current state: I hope my initial post didn't sound too dismissive, as you said its hard to get right on first try and actually most of my proposed building blocks are already there, but just scattered around and not always clearly seperated. I think I'll have to conceptually rebuild from the ground up in a POC fashion, but once that works I can probably reuse most of the existing logic. |
Beta Was this translation helpful? Give feedback.
-
Just to keep this updated. I didn't have the time to put up a PR, but I keep refining the API in my head and I think I'm pretty close to a good solution. First step would be a minimal PR to introduce the new API and have a more focused discussion there. Hope to get this done this week |
Beta Was this translation helpful? Give feedback.
-
The Looking forward! |
Beta Was this translation helpful? Give feedback.
-
Hi @Corvince, I'm wondering if there's any easier ways to customize the default column layout of the components? For instance if we'd like to have two measure plots side-by-side on the same row. Thanks! |
Beta Was this translation helpful? Give feedback.
-
I realize I’m a bit late to the discussion on the fundamental API designs for the new SolaraViz frontend, but I hope my input is still valuable.
What sets Solara apart is its ability to create modular and reusable components that can be assembled into a complete frontend. I believe we should leverage this capability much more effectively. Currently, the SolaraViz codebase feels like a catch-all solution, which contributes to a somewhat fragile API. While this is something that can always be refined later, I think it’s worth discussing how we might build a more robust frontend from the ground up.
Let’s start with the foundational layer: a simple visualization component that takes in a model instance and outputs a visualization. This could be something like SpacePlot(model) or BarChart(model). The beauty of these components is that they can stand alone; for instance, in an exploratory notebook, you could simply call BarChart(model) and immediately see the result.
The next layer would be a LayoutLayer that receives a model instance, a list of VisualizationComponents, and a layout specification—like a column-based arrangement.
Moving up, we have the model handler layer. Importantly, this is completely independent of the visualization itself. It receives a model instance and manages its controls: step, run, reset, etc. This layer can also function on its own, allowing you to interactively step through a model, even if you're writing directly to a database without using any other components.
Alongside the model handler is the Model Creator. This module receives the model class along with a combination of static and user-defined parameters, which are visualized by the UserParams widget. The Model Creator is responsible for generating model instances.
At the highest level, we have the "opinionated" glue-code that binds these components and layers together—essentially, the current SolaraViz component. From the structure of the layers below, it’s clear that this should include the model class, model parameters, and a list of visualization modules as the only required parameters. If we compare this to the current API, we see that “measures” correspond to the list of visualization modules (albeit under a different name). However, we also have elements like agent_portrayal and space drawer, which I believe are unnecessary. We could simply pass SpaceDrawer as part of the "measures". Additionally, we have parameters like "name", "seed", and "play_interval", which are essentially modifiers for the underlying components. These should be made keyword arguments (kwargs) to avoid breaking changes when adding new kwargs for different underlying modules, such as layout specifications.
This is my attempt at visualizing this structure:
I think implementing this structure long-term will lead to much more maintainable code. It will also lead to better understanding how to add new vizcomponents and generally solve some of the already open issues with solara. But I think a good first step would be to have a stable API for SolaraViz, on which we can build upon (or even top-down) without breaking changes
Initial diagram
Beta Was this translation helpful? Give feedback.
All reactions