Skip to content

Commit

Permalink
comitting stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
kushalkolar committed May 18, 2024
1 parent 9635bc0 commit 9be017c
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 21 deletions.
13 changes: 8 additions & 5 deletions fastplotlib/graphics/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

from pygfx import WorldObject

from ._features import GraphicFeature, PresentFeature, GraphicFeatureIndexable, Deleted
from ._features import GraphicFeature, PresentFeature, BufferManager, GraphicFeatureDescriptor, Deleted


HexStr: TypeAlias = str
Expand Down Expand Up @@ -49,12 +49,15 @@ def __init_subclass__(cls, **kwargs):


class Graphic(BaseGraphic):
feature_events = {}
features = {}

def __init_subclass__(cls, **kwargs):
super().__init_subclass__(**kwargs)
# all graphics give off a feature event when deleted
cls.feature_events = {*cls.feature_events, "deleted"}
cls.features = {*cls.features}#, "deleted"}

for f in cls.features:
setattr(cls, f, GraphicFeatureDescriptor(f))

def __init__(
self,
Expand All @@ -80,12 +83,12 @@ def __init__(
self.metadata = metadata
self.collection_index = collection_index
self.registered_callbacks = dict()
self.present = PresentFeature(parent=self)
# self.present = PresentFeature(parent=self)

# store hex id str of Graphic instance mem location
self._fpl_address: HexStr = hex(id(self))

self.deleted = Deleted(self, False)
# self.deleted = Deleted(self, False)

self._plot_area = None

Expand Down
30 changes: 14 additions & 16 deletions fastplotlib/graphics/line.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@

from ..utils import parse_cmap_values
from ._base import Graphic, Interaction, PreviouslyModifiedData
from ._features import PointsDataFeature, ColorFeature, CmapFeature, ThicknessFeature
from ._features import GraphicFeatureDescriptor, PointsDataFeature, ColorFeature#, CmapFeature, ThicknessFeature
from .selectors import LinearRegionSelector, LinearSelector


class LineGraphic(Graphic, Interaction):
feature_events = {"data", "colors", "cmap", "thickness", "present"}
features = {"data", "colors"}#, "cmap", "thickness", "present"}

def __init__(
self,
Expand All @@ -24,6 +24,7 @@ def __init__(
cmap_values: np.ndarray | Iterable = None,
z_position: float = None,
collection_index: int = None,
isolated_buffer: bool = True,
*args,
**kwargs,
):
Expand Down Expand Up @@ -64,6 +65,7 @@ def __init__(
Features
--------
**data**: :class:`.ImageDataFeature`
Manages the line [x, y, z] positions data buffer, allows regular and fancy indexing.
Expand All @@ -81,26 +83,24 @@ def __init__(
"""

self.data = PointsDataFeature(self, data, collection_index=collection_index)
self._data = PointsDataFeature(data, isolated_buffer=isolated_buffer)

if cmap is not None:
n_datapoints = self.data().shape[0]
n_datapoints = self._data.value.shape[0]

colors = parse_cmap_values(
n_colors=n_datapoints, cmap_name=cmap, cmap_values=cmap_values
)

self.colors = ColorFeature(
self,
self._colors = ColorFeature(
colors,
n_colors=self.data().shape[0],
n_colors=self._data.value.shape[0],
alpha=alpha,
collection_index=collection_index,
)

self.cmap = CmapFeature(
self, self.colors(), cmap_name=cmap, cmap_values=cmap_values
)
# self.cmap = CmapFeature(
# self, self.colors(), cmap_name=cmap, cmap_values=cmap_values
# )

super().__init__(*args, **kwargs)

Expand All @@ -109,14 +109,12 @@ def __init__(
else:
material = pygfx.LineMaterial

self.thickness = ThicknessFeature(self, thickness)
# self.thickness = ThicknessFeature(self, thickness)

world_object: pygfx.Line = pygfx.Line(
# self.data.feature_data because data is a Buffer
geometry=pygfx.Geometry(positions=self.data(), colors=self.colors()),
material=material(
thickness=self.thickness(), color_mode="vertex", pick_write=True
),
geometry=pygfx.Geometry(positions=self._data.buffer, colors=self._colors.buffer),
material=material(thickness=thickness, color_mode="vertex"),
)

self._set_world_object(world_object)
Expand Down

0 comments on commit 9be017c

Please sign in to comment.