Skip to content

Navigation Menu

Sign in
Appearance settings

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

legends, part 1 #406

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

Merged
merged 25 commits into from
Feb 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
59ed74c
start legends, not functional yet
kushalkolar Feb 19, 2024
6966097
add faq (#400)
kushalkolar Feb 15, 2024
0967ea0
fix bug when remove_graphic() is used (#405)
kushalkolar Feb 19, 2024
d537a4e
add 'Deleted' as a graphic feature (#404)
kushalkolar Feb 20, 2024
0dc0d95
very basic adding line legends works
kushalkolar Feb 20, 2024
c7f6284
use OrderedDict for legend items
kushalkolar Feb 20, 2024
fee30f5
allow accessing legend items via Graphic, updating colors works
kushalkolar Feb 20, 2024
de23dd9
legend mesh resizes properly
kushalkolar Feb 20, 2024
e316c5e
remove legend items and reorder works
kushalkolar Feb 21, 2024
b6e2531
enforce all legend labels to be unique
kushalkolar Feb 21, 2024
a6743cc
add legends property to PlotArea
kushalkolar Feb 22, 2024
1e639b4
checks for Graphic name
kushalkolar Feb 22, 2024
d5b4f5b
highlight linegraphic when legend item is clicked
kushalkolar Feb 22, 2024
bcae1f2
legend is moveable
kushalkolar Feb 22, 2024
b7e6fc5
remove weird characters that were committed for some reason
kushalkolar Feb 22, 2024
d8840dd
Merge branch 'legends' of https://github.com/fastplotlib/fastplotlib …
kushalkolar Feb 22, 2024
e3637ca
weird merge conflict
kushalkolar Feb 23, 2024
80cd459
progress on legend grid placement, not yet working
kushalkolar Feb 23, 2024
9024465
Merge branch 'legends' of https://github.com/fastplotlib/fastplotlib …
kushalkolar Feb 27, 2024
fc98604
Merge branch 'legends' of https://github.com/fastplotlib/fastplotlib …
kushalkolar Feb 27, 2024
142c989
max_rows works for legend
kushalkolar Feb 27, 2024
c2122e8
just allow max_rows kwarg for legends, no cols
kushalkolar Feb 27, 2024
5ed8e38
Merge branch 'main' into legends
kushalkolar Feb 27, 2024
9609d8c
line that snuck in from another branch
kushalkolar Feb 27, 2024
29f646d
small changes
kushalkolar Feb 29, 2024
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
7 changes: 3 additions & 4 deletions 7 fastplotlib/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from .layouts import Plot, GridPlot
from .graphics import *
from .graphics.selectors import *
from .utils import _notebook_print_banner, config
from .legends import *

from wgpu.gui.auto import run

Expand All @@ -23,14 +23,13 @@
"No WGPU adapters found, fastplotlib will not work."
)

_notebook_print_banner()

with open(Path(__file__).parent.joinpath("VERSION"), "r") as f:
__version__ = f.read().split("\n")[0]

__all__ = [
"Plot",
"GridPlot",
"run",
"ImageWidget"
"ImageWidget",
"Legend",
]
21 changes: 19 additions & 2 deletions 21 fastplotlib/graphics/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ class Graphic(BaseGraphic):
feature_events = {}

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"}

Expand All @@ -62,14 +63,16 @@ def __init__(
Parameters
----------
name: str, optional
name this graphic, makes it indexable within plots
name this graphic to use it as a key to access from the plot

metadata: Any, optional
metadata attached to this Graphic, this is for the user to manage

"""
if (name is not None) and (not isinstance(name, str)):
raise TypeError("Graphic `name` must be of type <str>")

self.name = name
self._name = name
self.metadata = metadata
self.collection_index = collection_index
self.registered_callbacks = dict()
Expand All @@ -80,6 +83,20 @@ def __init__(

self.deleted = Deleted(self, False)

self._plot_area = None

@property
def name(self) -> Union[str, None]:
"""str name reference for this item"""
return self._name

@name.setter
def name(self, name: str):
if not isinstance(name, str):
raise TypeError("`Graphic` name must be of type <str>")
if self._plot_area is not None:
self._plot_area._check_graphic_name_exists(name)

@property
def world_object(self) -> WorldObject:
"""Associated pygfx WorldObject. Always returns a proxy, real object cannot be accessed directly."""
Expand Down
25 changes: 23 additions & 2 deletions 25 fastplotlib/layouts/_plot_area.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from ._utils import create_camera, create_controller
from ..graphics._base import Graphic
from ..graphics.selectors._base_selector import BaseSelector
from ..legends import Legend

# dict to store Graphic instances
# this is the only place where the real references to Graphics are stored in a Python session
Expand Down Expand Up @@ -62,7 +63,7 @@ def __init__(

name: str, optional
name this ``subplot`` or ``plot``

"""

self._parent: PlotArea = parent
Expand Down Expand Up @@ -208,6 +209,8 @@ def graphics(self) -> Tuple[Graphic, ...]:
proxies = list()
for loc in self._graphics:
p = weakref.proxy(GRAPHICS[loc])
if p.__class__.__name__ == "Legend":
kushalkolar marked this conversation as resolved.
Show resolved Hide resolved
continue
proxies.append(p)

return tuple(proxies)
Expand All @@ -222,6 +225,17 @@ def selectors(self) -> Tuple[BaseSelector, ...]:

return tuple(proxies)

@property
def legends(self) -> Tuple[Legend, ...]:
"""Legends in the plot area."""
proxies = list()
for loc in self._graphics:
p = weakref.proxy(GRAPHICS[loc])
if p.__class__.__name__ == "Legend":
proxies.append(p)

return tuple(proxies)

@property
def name(self) -> Any:
"""The name of this plot area"""
Expand Down Expand Up @@ -486,6 +500,9 @@ def _check_graphic_name_exists(self, name):
for s in self.selectors:
graphic_names.append(s.name)

for l in self.legends:
graphic_names.append(l.name)

if name in graphic_names:
raise ValueError(
f"graphics must have unique names, current graphic names are:\n {graphic_names}"
Expand Down Expand Up @@ -666,6 +683,10 @@ def __getitem__(self, name: str):
if selector.name == name:
return selector

for legend in self.legends:
if legend.name == name:
return legend

graphic_names = list()
for g in self.graphics:
graphic_names.append(g.name)
Expand All @@ -681,7 +702,7 @@ def __getitem__(self, name: str):
)

def __contains__(self, item: Union[str, Graphic]):
to_check = [*self.graphics, *self.selectors]
to_check = [*self.graphics, *self.selectors, *self.legends]

if isinstance(item, Graphic):
if item in to_check:
Expand Down
3 changes: 3 additions & 0 deletions 3 fastplotlib/legends/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from .legend import Legend

__all__ = ["Legend"]
Loading
Morty Proxy This is a proxified and sanitized view of the page, visit original site.