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

Model properties and/or model parameters as arguments for VisualisationElements #1216

Closed
Holzhauer opened this issue Mar 28, 2022 · 11 comments
Closed

Comments

@Holzhauer
Copy link
Contributor

Holzhauer commented Mar 28, 2022

Currently, visualisation element parameters such as CanvasGrid's width and heights parameters need to be hard-coded more or less, and it seems not possible to initialise the grid with other dimensions than initially defined, when resetting the model.

It would be great to allow functions as arguments which are called with the model or model parameter objects.

@rht
Copy link
Contributor

rht commented Mar 29, 2022

This is possible if this part of ModularServer's __init__

        self.js_code = []
        for element in self.visualization_elements:
            for include_file in element.package_includes:
                self.package_includes.add(include_file)
            for include_file in element.local_includes:
                self.local_includes.add(include_file)
            self.js_code.append(element.js_code)

is moved to be inside reset_model() instead. Where the self.js_code of the CanvasGrid is modified to the dimensions you need before the explicit reset.

Would be great if you can describe the use case you're facing, so that I can understand the context better.

@rht
Copy link
Contributor

rht commented Mar 29, 2022

This part of the code:

self.js_code = []
for element in self.visualization_elements:
for include_file in element.package_includes:
self.package_includes.add(include_file)
for include_file in element.local_includes:
self.local_includes.add(include_file)
self.js_code.append(element.js_code)
. I should have linked it from GH instead of copy-pasting it from my local file.

@Holzhauer
Copy link
Contributor Author

Thanks @rht! Use case: Analysing impact of grid size (here: fire evacuation model) via GUI slider. Therefore, the grid extent is changed on reset. However, currently the canvas does not adapt: for smaller extents than initially, the grid covers only part of the canvas, for higher extents only part of the grid is displayed.
I copied the code above to ModularServer.reset_model(). I added

        canvas.new_element = "new CanvasModule({}, {}, {}, {})".format(
            canvas.canvas_width, canvas.canvas_height, floor_size, floor_size
        )
        canvas.js_code = "elements.push(" + canvas.new_element + ");"
        canvas.render(self)

to Model.__init__() after MultiGrid was instantiated.
The only issue left is, I still need to reload the webpage to update the canvas extent. I haven't found a solution yet to render the PageHandler in ModularServer.reset_model().

@rht
Copy link
Contributor

rht commented Apr 5, 2022

Do you have a sample repo that I can build on to do some experimentation?

@Holzhauer
Copy link
Contributor Author

The model I used to test grid resize is https://github.com/UniK-INES/MesaSimpleEvacuation.
Modifications to mesa have been done in https://github.com/UniK-INES/mesa/tree/ines_edu.

@rht
Copy link
Contributor

rht commented Apr 6, 2022

OK, thank you! It looks like you have also improved the boid_flockers example. Looking forward to the PR. And also, I think you can also help review the discrepancy in the Mesa/Agents.jl/MASON/NetLogo implementation of the boid_flockers, in this thread JuliaDynamics/Agents.jl#394 (comment).

@stephenfmann
Copy link
Contributor

This would be extremely useful, but it looks like it has been quiet for 2 years. I assume we aren't going to get a pull request from @Holzhauer on this specific issue? If so, would a PR from me be considered instead, if I replicated the changes in a new fork?

@Holzhauer
Copy link
Contributor Author

@stephenfmann is your comment about the boid_flockers example or about the grid size update? The former I can push next week after minor reviews, the latter I think is not relevant anymore as the new solara framework supports resizing.

@stephenfmann
Copy link
Contributor

Ah, I meant the latter, in which case I'll check out solara -- I've only used tornado in the past. Thanks.

@EwoutH
Copy link
Member

EwoutH commented Jul 11, 2024

Somewhat related: #2176

@quaquel
Copy link
Member

quaquel commented Oct 30, 2024

with the current solara front end this is largely resolved.

@quaquel quaquel closed this as completed Oct 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants