Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
65 commits
Select commit Hold shift + click to select a range
c221cff
refactor cmap and cmap_transform for positional graphics
kushalkolar Aug 8, 2026
125a128
color mode stuff
kushalkolar Aug 8, 2026
5e0bd95
WIP
kushalkolar Aug 13, 2026
b269f07
more WIP
kushalkolar Aug 14, 2026
3914db6
better add_graphic autogen
kushalkolar Aug 19, 2026
419069a
more progress
kushalkolar Aug 19, 2026
8fe4054
mostly done refactoring positions graphics cmap stuff
kushalkolar Aug 20, 2026
ad2e1d0
forgot to update mixin
kushalkolar Aug 20, 2026
782017f
cmap_transform tweaks
kushalkolar Aug 24, 2026
b102462
wip, JaggedArray
kushalkolar Aug 30, 2026
1f3def7
mostly works, writing tests
kushalkolar Sep 1, 2026
42aceb9
remove a print
kushalkolar Sep 1, 2026
0284cfa
image collection examples
kushalkolar Sep 2, 2026
c9fe59d
fix
kushalkolar Sep 2, 2026
21c9f68
feature inheritance in PositionsGraphic and cmap_range
kushalkolar Sep 2, 2026
b1f8d2e
cmap handling
kushalkolar Sep 2, 2026
ebfa98a
cmap tweaks
kushalkolar Sep 3, 2026
bff755b
remove parse_cmap_values, rely on cmap lib
kushalkolar Sep 3, 2026
f9c23f2
fix example, remove unused line of code
kushalkolar Sep 3, 2026
665952c
Image just uses cmap lib now too
kushalkolar Sep 3, 2026
f43d25f
delete_ndgraphic()
kushalkolar Sep 3, 2026
e3035c6
ndtimeseries cmap example
kushalkolar Sep 3, 2026
a997728
steps for stacks
kushalkolar Sep 3, 2026
565a689
ndtimeseries sets stack steps
kushalkolar Sep 3, 2026
467029f
docstrings
kushalkolar Sep 5, 2026
bc844c0
docstrings
kushalkolar Sep 5, 2026
72371e1
comments
kushalkolar Sep 5, 2026
7fb798b
renames
kushalkolar Sep 5, 2026
d51d19c
docstring
kushalkolar Sep 5, 2026
29c95f2
fixes
kushalkolar Sep 8, 2026
687e10a
update tests/test_colors_buffer_manager.py
kushalkolar Sep 9, 2026
a23cfb0
update test_markers_buffer_manager.py
kushalkolar Sep 9, 2026
a9d9444
update plot_helpers test
kushalkolar Sep 9, 2026
c52e829
update test_point_rotations_buffer_manager.py
kushalkolar Sep 9, 2026
7246c96
update test_positions_graphics.py
kushalkolar Sep 9, 2026
3225331
update another test
kushalkolar Sep 9, 2026
ebbae33
more tests
kushalkolar Sep 9, 2026
a568853
update yet more tests
kushalkolar Sep 9, 2026
aec89c9
remove unused
kushalkolar Sep 9, 2026
a32d3af
infline tests
kushalkolar Sep 9, 2026
650fd29
collections tests
kushalkolar Sep 9, 2026
c024321
updating examples, wip
kushalkolar Sep 9, 2026
45ea886
more examples updates
kushalkolar Sep 9, 2026
4a8f444
more examples updates
kushalkolar Sep 9, 2026
92e34d9
more example updates
kushalkolar Sep 9, 2026
f0ddde1
more example updates
kushalkolar Sep 9, 2026
7b04a0d
example and docstring
kushalkolar Sep 9, 2026
55864b0
docstring
kushalkolar Sep 9, 2026
2554a3d
remove complex line collection slicing example, stick with real usecases
kushalkolar Sep 9, 2026
4148e3c
better line stack example
kushalkolar Sep 9, 2026
b6b80ba
update example
kushalkolar Sep 9, 2026
d6a8fb8
update example
kushalkolar Sep 9, 2026
712d94b
update link
kushalkolar Sep 9, 2026
2949c81
update more examples
kushalkolar Sep 9, 2026
a5dd607
examples and fixes
kushalkolar Sep 9, 2026
2d59e6a
fix
kushalkolar Sep 9, 2026
b57d0a4
more fixes
kushalkolar Sep 9, 2026
df7c823
fix
kushalkolar Sep 9, 2026
cfdfdca
updates
kushalkolar Sep 9, 2026
cad9ee4
Fix
kushalkolar Sep 9, 2026
dee42ec
update docs
kushalkolar Sep 9, 2026
05acb46
docs
kushalkolar Sep 9, 2026
87f74b0
add image collection to docs conf.py
kushalkolar Sep 9, 2026
911570f
update docs
kushalkolar Sep 9, 2026
d5f1da9
Merge branch 'ndwidget' into flat-gfeatures2
kushalkolar Sep 9, 2026
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
Prev Previous commit
Next Next commit
better add_graphic autogen
  • Loading branch information
kushalkolar committed Aug 19, 2026
commit 3914db6edd74581bea005262eea68689f42d4a7c
172 changes: 68 additions & 104 deletions fastplotlib/layouts/_graphic_methods_mixin.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,16 @@
# This is an auto-generated file and should not be modified directly

from typing import *

import numpy
from numpy.typing import NDArray

from numpy.typing import NDArray

import pygfx

from ..graphics import *
from ..graphics._base import Graphic
from ..utils import enums
import typing
import fastplotlib
from fastplotlib.graphics._vectors import *
from fastplotlib.graphics.image import *
from fastplotlib.graphics.image_volume import *
from fastplotlib.graphics.inf_line import *
from fastplotlib.graphics.line import *
from fastplotlib.graphics.line_collection import *
from fastplotlib.graphics.mesh import *
from fastplotlib.graphics.scatter import *
from fastplotlib.graphics.scatter_collection import *
from fastplotlib.graphics.text import *
from fastplotlib.graphics import Graphic


class GraphicMethodsMixin:
Expand All @@ -40,7 +37,7 @@ def add_image(
gamma: float = 1.0,
interpolation: str = "nearest",
cmap_interpolation: str = "linear",
colorspace: fastplotlib.utils.enums.ColorspacesRGB = "srgb",
colorspace: ColorspacesRGB = "srgb",
cpu_buffer: bool = True,
**kwargs
) -> ImageGraphic:
Expand Down Expand Up @@ -143,7 +140,7 @@ def add_image_volume(
threshold: float = 0.5,
step_size: float = 1.0,
substep_size: float = 0.1,
emissive: str | tuple | numpy.ndarray = (0, 0, 0),
emissive: str | tuple | np.ndarray = (0, 0, 0),
shininess: int = 30,
**kwargs
) -> ImageVolumeGraphic:
Expand Down Expand Up @@ -231,16 +228,13 @@ def add_image_volume(

def add_image_yuv(
self,
data: (
tuple[NDArray[numpy.uint8], NDArray[numpy.uint8], NDArray[numpy.uint8]]
| fastplotlib.graphics.features._image.TextureYUV
),
data: TupleYUV | TextureYUV,
vmin: float = 0,
vmax: float = 255,
gamma: float = 1.0,
interpolation: str = "nearest",
colorspace: fastplotlib.utils.enums.ColorspacesYUV = "yuv420p",
colorrange: fastplotlib.utils.enums.ColorRange = "limited",
colorspace: ColorspacesYUV = "yuv420p",
colorrange: ColorRange = "limited",
**kwargs
) -> ImageYUVGraphic:
"""
Expand Down Expand Up @@ -328,11 +322,11 @@ def add_image_yuv(
def add_inf_line(
self,
data: Any,
axis: Optional[Literal["x", "y", "z"]] = None,
axis: Literal["x", "y", "z"] | None = None,
thickness: float = 2.0,
colors: Union[str, numpy.ndarray, Sequence] = "w",
colors: str | np.ndarray | Sequence = "w",
cmap: str = None,
cmap_transform: Union[numpy.ndarray, Sequence] = None,
cmap_transform: np.ndarray | Sequence = None,
color_mode: Literal["auto", "uniform", "vertex"] = "auto",
start_is_infinite: bool = True,
end_is_infinite: bool = True,
Expand Down Expand Up @@ -415,16 +409,16 @@ def add_inf_line(

def add_line_collection(
self,
data: Union[numpy.ndarray, List[numpy.ndarray]],
thickness: Union[float, Sequence[float]] = 2.0,
colors: Union[str, Sequence[str], numpy.ndarray, Sequence[numpy.ndarray]] = "w",
cmap: Union[Sequence[str], str] = None,
cmap_transform: Union[numpy.ndarray, List] = None,
data: np.ndarray | List[np.ndarray],
thickness: float | Sequence[float] = 2.0,
colors: str | Sequence[str] | np.ndarray | Sequence[np.ndarray] = "w",
cmap: Sequence[str] | str = None,
cmap_transform: np.ndarray | List = None,
color_mode: Literal["auto", "uniform", "vertex"] = "auto",
name: str = None,
names: list[str] = None,
metadata: Any = None,
metadatas: Union[Sequence[Any], numpy.ndarray] = None,
metadatas: Sequence[Any] | np.ndarray = None,
kwargs_lines: list[dict] = None,
**kwargs
) -> LineCollection:
Expand Down Expand Up @@ -504,10 +498,9 @@ def add_line(
self,
data: Any,
thickness: float = 2.0,
colors: Union[str, numpy.ndarray, Sequence] = "w",
cmap: str = None,
cmap_transform: Union[numpy.ndarray, Sequence] = None,
color_mode: Literal["auto", "uniform", "vertex"] = "auto",
colors: str | ColorLike | MultiColorLike = "w",
cmap: ColormapLike | None = None,
cmap_transform: np.ndarray | None = None,
size_space: str = "screen",
dash_pattern: str | tuple | list = (),
thin: bool = False,
Expand All @@ -528,23 +521,15 @@ def add_line(
thickness: float, optional, default 2.0
thickness of the line

colors: str, array, or iterable, default "w"
colors: str, ColorLike or MultiColorLike, default "w"
specify colors as a single human-readable string, a single RGBA array,
or a Sequence (array, tuple, or list) of strings or RGBA arrays

cmap: str, optional
cmap: ColormapLike, optional
Apply a colormap to the line instead of assigning colors manually, this
overrides any argument passed to "colors". For supported colormaps see the
``cmap`` library catalogue: https://cmap-docs.readthedocs.io/en/stable/catalog/

color_mode: one of "auto", "uniform", "vertex", default "auto"
"uniform" restricts to a single color for all line datapoints.
"vertex" allows independent colors per vertex.
For most cases you can keep it as "auto" and the `color_mode` is determineed automatically based on the
argument passed to `colors`. if `colors` represents a single color, then the mode is set to "uniform".
If `colors` represents a unique color per-datapoint, or if a cmap is provided, then `color_mode` is set to
"vertex". You can switch between "uniform" and "vertex" `color_mode` after creating the graphic.

cmap_transform: 1D array-like of numerical values, optional
if provided, these values are used to map the colors from the cmap

Expand Down Expand Up @@ -572,7 +557,6 @@ def add_line(
colors,
cmap,
cmap_transform,
color_mode,
size_space,
dash_pattern,
thin,
Expand All @@ -581,15 +565,15 @@ def add_line(

def add_line_stack(
self,
data: List[numpy.ndarray],
thickness: Union[float, Iterable[float]] = 2.0,
colors: Union[str, Iterable[str], numpy.ndarray, Iterable[numpy.ndarray]] = "w",
cmap: Union[Iterable[str], str] = None,
cmap_transform: Union[numpy.ndarray, List] = None,
data: List[np.ndarray],
thickness: float | Iterable[float] = 2.0,
colors: str | Iterable[str] | np.ndarray | Iterable[np.ndarray] = "w",
cmap: Iterable[str] | str = None,
cmap_transform: np.ndarray | List = None,
name: str = None,
names: list[str] = None,
metadata: Any = None,
metadatas: Union[Sequence[Any], numpy.ndarray] = None,
metadatas: Sequence[Any] | np.ndarray = None,
separation: float = 10.0,
separation_axis: str = "y",
kwargs_lines: list[dict] = None,
Expand Down Expand Up @@ -678,15 +662,9 @@ def add_mesh(
indices: Any,
mode: Literal["basic", "phong", "slice"] = "phong",
plane: tuple[float, float, float, float] = (0.0, 0.0, 1.0, 0.0),
colors: Union[str, numpy.ndarray, Sequence] = "w",
colors: str | np.ndarray | Sequence = "w",
mapcoords: Any = None,
cmap: (
str
| dict
| pygfx.resources._texture.Texture
| pygfx.resources._texturemap.TextureMap
| numpy.ndarray
) = None,
cmap: str | dict | pygfx.Texture | pygfx.TextureMap | np.ndarray = None,
clim: tuple[float, float] = None,
**kwargs
) -> MeshGraphic:
Expand Down Expand Up @@ -747,17 +725,11 @@ def add_mesh(

def add_polygon(
self,
data: numpy.ndarray,
data: np.ndarray,
mode: Literal["basic", "phong"] = "basic",
colors: Union[str, numpy.ndarray, Sequence] = "w",
colors: str | np.ndarray | Sequence = "w",
mapcoords: Any = None,
cmap: (
str
| dict
| pygfx.resources._texture.Texture
| pygfx.resources._texturemap.TextureMap
| numpy.ndarray
) = None,
cmap: str | dict | pygfx.Texture | pygfx.TextureMap | np.ndarray = None,
clim: tuple[float, float] | None = None,
**kwargs
) -> PolygonGraphic:
Expand Down Expand Up @@ -804,19 +776,19 @@ def add_polygon(

def add_scatter_collection(
self,
data: Union[numpy.ndarray, List[numpy.ndarray]],
colors: Union[str, Sequence[str], numpy.ndarray, Sequence[numpy.ndarray]] = "w",
cmap: Union[Sequence[str], str] = None,
cmap_transform: Union[numpy.ndarray, List] = None,
sizes: Union[float, Sequence[float]] = 5.0,
data: np.ndarray | List[np.ndarray],
colors: str | Sequence[str] | np.ndarray | Sequence[np.ndarray] = "w",
cmap: Sequence[str] | str = None,
cmap_transform: np.ndarray | List = None,
sizes: float | Sequence[float] = 5.0,
uniform_size: bool = True,
markers: Union[numpy.ndarray, Sequence[str]] = None,
markers: np.ndarray | Sequence[str] = None,
uniform_marker: bool = True,
edge_width: float = 1.0,
name: str = None,
names: list[str] = None,
metadata: Any = None,
metadatas: Union[Sequence[Any], numpy.ndarray] = None,
metadatas: Sequence[Any] | np.ndarray = None,
**kwargs
) -> ScatterCollection:
"""
Expand Down Expand Up @@ -889,23 +861,21 @@ def add_scatter_collection(
def add_scatter(
self,
data: Any,
colors: Union[str, numpy.ndarray, Sequence[float], Sequence[str]] = "w",
colors: str | np.ndarray | Sequence[float] | Sequence[str] = "w",
cmap: str = None,
cmap_transform: numpy.ndarray = None,
cmap_transform: np.ndarray = None,
color_mode: Literal["auto", "uniform", "vertex"] = "auto",
mode: Literal["markers", "simple", "gaussian", "image"] = "markers",
markers: Union[str, numpy.ndarray, Sequence[str]] = "o",
markers: str | np.ndarray | Sequence[str] = "o",
uniform_marker: bool = True,
custom_sdf: str = None,
edge_colors: Union[
str, pygfx.utils.color.Color, numpy.ndarray, Sequence[float]
] = "black",
edge_colors: str | np.ndarray | pygfx.Color | Sequence[float] = "black",
uniform_edge_color: bool = True,
edge_width: float = 1.0,
image: numpy.ndarray = None,
point_rotations: float | numpy.ndarray = 0,
image: np.ndarray = None,
point_rotations: float | np.ndarray = 0,
point_rotation_mode: Literal["uniform", "vertex", "curve"] = "uniform",
sizes: Union[float, numpy.ndarray, Sequence[float]] = 5,
sizes: float | np.ndarray | Sequence[float] = 5,
uniform_size: bool = True,
size_space: str = "screen",
**kwargs
Expand Down Expand Up @@ -1043,14 +1013,14 @@ def add_scatter(

def add_scatter_stack(
self,
data: Union[numpy.ndarray, List[numpy.ndarray]],
colors: Union[str, Sequence[str], numpy.ndarray, Sequence[numpy.ndarray]] = "w",
cmap: Union[Sequence[str], str] = None,
cmap_transform: Union[numpy.ndarray, List] = None,
data: np.ndarray | List[np.ndarray],
colors: str | Sequence[str] | np.ndarray | Sequence[np.ndarray] = "w",
cmap: Sequence[str] | str = None,
cmap_transform: np.ndarray | List = None,
name: str = None,
names: list[str] = None,
metadata: Any = None,
metadatas: Union[Sequence[Any], numpy.ndarray] = None,
metadatas: Sequence[Any] | np.ndarray = None,
separation: float = 0.0,
separation_axis: str = "y",
**kwargs
Expand Down Expand Up @@ -1128,17 +1098,11 @@ def add_scatter_stack(

def add_surface(
self,
data: numpy.ndarray,
data: np.ndarray,
mode: Literal["basic", "phong", "slice"] = "phong",
colors: Union[str, numpy.ndarray, Sequence] = "w",
colors: str | np.ndarray | Sequence = "w",
mapcoords: Any = None,
cmap: (
str
| dict
| pygfx.resources._texture.Texture
| pygfx.resources._texturemap.TextureMap
| numpy.ndarray
) = None,
cmap: str | dict | pygfx.Texture | pygfx.TextureMap | np.ndarray = None,
clim: tuple[float, float] | None = None,
**kwargs
) -> SurfaceGraphic:
Expand Down Expand Up @@ -1188,8 +1152,8 @@ def add_text(
self,
text: str,
font_size: float | int = 14,
face_color: str | numpy.ndarray | list[float] | tuple[float] = "w",
outline_color: str | numpy.ndarray | list[float] | tuple[float] = "w",
face_color: str | np.ndarray | list[float] | tuple[float] = "w",
outline_color: str | np.ndarray | list[float] | tuple[float] = "w",
outline_thickness: float = 0.0,
screen_space: bool = True,
offset: tuple[float] = (0, 0, 0),
Expand Down Expand Up @@ -1250,9 +1214,9 @@ def add_text(

def add_vectors(
self,
positions: Union[numpy.ndarray, Sequence[float]],
directions: Union[numpy.ndarray, Sequence[float]],
color: Union[str, Sequence[float], numpy.ndarray] = "w",
positions: np.ndarray | Sequence[float],
directions: np.ndarray | Sequence[float],
color: str | Sequence[float] | np.ndarray = "w",
size: float = None,
vector_shape_options: dict = None,
**kwargs
Expand Down
22 changes: 12 additions & 10 deletions scripts/generate_add_graphic_methods.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import ast
import inspect
import pathlib
import re
import textwrap

import black

Expand Down Expand Up @@ -31,15 +33,12 @@ def generate_add_graphics_methods():

f.write("# This is an auto-generated file and should not be modified directly\n\n")

f.write("from typing import *\n\n")
f.write("import numpy\n")
f.write("from numpy.typing import NDArray\n\n")
f.write("import pygfx\n\n")
f.write("from ..graphics import *\n")
f.write("from ..graphics._base import Graphic\n")
f.write("from ..utils import enums\n")
f.write("import typing\n")
f.write("import fastplotlib\n\n")
# star-import each module that defines a graphic, so every reference used in the
# graphics' __init__ annotations (aliases, np, pygfx, typing, enums) is in scope
for module in sorted({cls.__module__ for cls in modules}):
f.write(f"from {module} import *\n")

f.write("from fastplotlib.graphics import Graphic\n\n")

f.write("\nclass GraphicMethodsMixin:\n")

Expand Down Expand Up @@ -71,8 +70,11 @@ def generate_add_graphics_methods():
for a in class_args:
s += a

init = ast.parse(textwrap.dedent(inspect.getsource(cls.__init__))).body[0]
signature = ast.unparse(init.args)

f.write(
f" def add_{method_name}{inspect.signature(cls.__init__)} -> {cls.__name__}:\n"
f" def add_{method_name}({signature}) -> {cls.__name__}:\n"
)
f.write(' """\n')
f.write(f" {cls.__init__.__doc__}\n")
Expand Down