Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

move viewport rect logic from subplot and docks to Figure #724

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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 18 commits into from
Feb 21, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion 2 .github/workflows/ci-pygfx-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ jobs:
- uses: actions/upload-artifact@v4
if: ${{ failure() }}
with:
name: screenshot-diffs-${{ matrix.pyversion }}-${{ matrix.imgui_dep }}-${{ matrix.notebook_dep }}
name: screenshot-diffs-${{ matrix.os }}-${{ matrix.pyversion }}-${{ matrix.imgui_dep }}-${{ matrix.notebook_dep }}
path: |
examples/diffs
examples/notebooks/diffs
2 changes: 1 addition & 1 deletion 2 .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ jobs:
- uses: actions/upload-artifact@v4
if: ${{ failure() }}
with:
name: screenshot-diffs-${{ matrix.pyversion }}-${{ matrix.imgui_dep }}-${{ matrix.notebook_dep }}
name: screenshot-diffs-${{ matrix.os }}-${{ matrix.pyversion }}-${{ matrix.imgui_dep }}-${{ matrix.notebook_dep }}
path: |
examples/diffs
examples/notebooks/diffs
5 changes: 3 additions & 2 deletions 5 docs/source/api/layouts/figure.rst
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,11 @@ Properties
Figure.cameras
Figure.canvas
Figure.controllers
Figure.mode
Figure.names
Figure.renderer
Figure.shape
Figure.spacing

Methods
~~~~~~~
Expand All @@ -36,10 +38,9 @@ Methods
Figure.clear
Figure.close
Figure.export
Figure.export_numpy
Figure.get_pygfx_render_area
Figure.open_popup
Figure.remove_animation
Figure.render
Figure.show
Figure.start_render

5 changes: 3 additions & 2 deletions 5 docs/source/api/layouts/imgui_figure.rst
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,11 @@ Properties
ImguiFigure.controllers
ImguiFigure.guis
ImguiFigure.imgui_renderer
ImguiFigure.mode
ImguiFigure.names
ImguiFigure.renderer
ImguiFigure.shape
ImguiFigure.spacing

Methods
~~~~~~~
Expand All @@ -39,11 +41,10 @@ Methods
ImguiFigure.clear
ImguiFigure.close
ImguiFigure.export
ImguiFigure.export_numpy
ImguiFigure.get_pygfx_render_area
ImguiFigure.open_popup
ImguiFigure.register_popup
ImguiFigure.remove_animation
ImguiFigure.render
ImguiFigure.show
ImguiFigure.start_render

4 changes: 0 additions & 4 deletions 4 docs/source/api/layouts/subplot.rst
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ Properties
Subplot.name
Subplot.objects
Subplot.parent
Subplot.position
Subplot.renderer
Subplot.scene
Subplot.selectors
Expand All @@ -58,12 +57,9 @@ Methods
Subplot.clear
Subplot.delete_graphic
Subplot.get_figure
Subplot.get_rect
Subplot.insert_graphic
Subplot.map_screen_to_world
Subplot.remove_animation
Subplot.remove_graphic
Subplot.render
Subplot.set_title
Subplot.set_viewport_rect

37 changes: 37 additions & 0 deletions 37 examples/gridplot/gridplot_viewports_check.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
"""
GridPlot test viewport rects
============================

Test figure to test that viewport rects are positioned correctly
"""

# test_example = true
# sphinx_gallery_pygfx_docs = 'hidden'

import fastplotlib as fpl
import numpy as np


figure = fpl.Figure(
shape=(2, 3),
size=(700, 560),
names=list(map(str, range(6)))
)

np.random.seed(0)
a = np.random.rand(6, 10, 10)

for data, subplot in zip(a, figure):
subplot.add_image(data)
subplot.docks["left"].size = 20
subplot.docks["right"].size = 30
subplot.docks["bottom"].size = 40

figure.show()


# NOTE: `if __name__ == "__main__"` is NOT how to use fastplotlib interactively
# please see our docs for using fastplotlib interactively in ipython and jupyter
if __name__ == "__main__":
print(__doc__)
fpl.loop.run()
35 changes: 35 additions & 0 deletions 35 examples/image_widget/image_widget_viewports_check.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
"""
ImageWidget test viewport rects
===============================

Test Figure to test that viewport rects are positioned correctly in an image widget
"""

# test_example = true
# sphinx_gallery_pygfx_docs = 'hidden'

import fastplotlib as fpl
import numpy as np

np.random.seed(0)
a = np.random.rand(6, 15, 10, 10)

iw = fpl.ImageWidget(
data=[img for img in a],
names=list(map(str, range(6))),
figure_kwargs={"size": (700, 560)},
)

for subplot in iw.figure:
subplot.docks["left"].size = 10
subplot.docks["bottom"].size = 40

iw.show()

figure = iw.figure

# NOTE: `if __name__ == "__main__"` is NOT how to use fastplotlib interactively
# please see our docs for using fastplotlib interactively in ipython and jupyter
if __name__ == "__main__":
print(__doc__)
fpl.loop.run()
20 changes: 20 additions & 0 deletions 20 examples/notebooks/nb_test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,26 @@ def plot_test(name, fig: fpl.Figure):
if not TESTING:
return

# otherwise the first render is wrong
if fpl.IMGUI:
# there doesn't seem to be a resize event for the manual offscreen canvas
fig.imgui_renderer._backend.io.display_size = fig.canvas.get_logical_size()
# run this once so any edge widgets set their sizes and therefore the subplots get the correct rect
# hacky but it works for now
fig.imgui_renderer.render()

fig._set_viewport_rects()
# render each subplot
for subplot in fig:
subplot.viewport.render(subplot.scene, subplot.camera)

# flush pygfx renderer
fig.renderer.flush()

if fpl.IMGUI:
# render imgui
fig.imgui_renderer.render()

snapshot = fig.canvas.snapshot()
rgb_img = rgba_to_rgb(snapshot.data)

Expand Down
16 changes: 0 additions & 16 deletions 16 examples/notebooks/quickstart.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -1695,22 +1695,6 @@
"figure_grid[\"top-right-plot\"]"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "cb7566a5",
"metadata": {
"collapsed": false,
"jupyter": {
"outputs_hidden": false
}
},
"outputs": [],
"source": [
"# view its position\n",
"figure_grid[\"top-right-plot\"].position"
]
},
{
"cell_type": "code",
"execution_count": null,
Expand Down
3 changes: 3 additions & 0 deletions 3 examples/screenshots/gridplot_viewports_check.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions 3 examples/screenshots/image_widget_viewports_check.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions 3 examples/screenshots/no-imgui-gridplot_viewports_check.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 3 additions & 4 deletions 7 examples/tests/test_examples.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,11 @@ def test_examples_run(module, force_offscreen):
@pytest.fixture
def force_offscreen():
"""Force the offscreen canvas to be selected by the auto gui module."""
os.environ["WGPU_FORCE_OFFSCREEN"] = "true"
os.environ["RENDERCANVAS_FORCE_OFFSCREEN"] = "true"
try:
yield
finally:
del os.environ["WGPU_FORCE_OFFSCREEN"]
del os.environ["RENDERCANVAS_FORCE_OFFSCREEN"]


def test_that_we_are_on_lavapipe():
Expand Down Expand Up @@ -103,11 +103,10 @@ def test_example_screenshots(module, force_offscreen):
# hacky but it works for now
example.figure.imgui_renderer.render()

example.figure._set_viewport_rects()
# render each subplot
for subplot in example.figure:
subplot.viewport.render(subplot.scene, subplot.camera)
for dock in subplot.docks.values():
dock.set_viewport_rect()

# flush pygfx renderer
example.figure.renderer.flush()
Expand Down
2 changes: 1 addition & 1 deletion 2 fastplotlib/graphics/_axes.py
Original file line number Diff line number Diff line change
Expand Up @@ -516,7 +516,7 @@ def update_using_camera(self):
return

if self._plot_area.camera.fov == 0:
xpos, ypos, width, height = self._plot_area.get_rect()
xpos, ypos, width, height = self._plot_area.viewport.rect
# orthographic projection, get ranges using inverse

# get range of screen space by getting the corners
Expand Down
Loading
Loading
Morty Proxy This is a proxified and sanitized view of the page, visit original site.