jangada.mixin.Colorable#
- class jangada.mixin.Colorable#
Bases:
objectMixin that adds a color attribute for visualization.
Provides a color attribute stored as a canonical HTML hex string (
#RRGGBBformat). Accepts various color formats via matplotlib’s color parsing, including hex strings, RGB tuples, and named colors.The default color is matplotlib’s C0 (
#1F77B4), a pleasant blue.- Attributes:
- colorstr
Color as uppercase HTML hex string (
#RRGGBBformat). Default is'#1F77B4'(matplotlib C0 blue).
See also
matplotlib.colors.to_hexColor conversion function used
Notes
- Color Formats
Input accepts any format that matplotlib’s
to_hex()understands:Hex strings:
'#FF0000','#F00'(short form)RGB tuples:
(1.0, 0.0, 0.0)or(255, 0, 0)Named colors:
'red','blue', etc.Matplotlib colors:
'C0','C1', etc.
- Output Format
Always stored as uppercase
#RRGGBB(6 hex digits). This canonical format ensures consistency.- Matplotlib Dependency
Requires matplotlib for color parsing. Consider making this optional or providing a lightweight fallback in future versions.
- Use Cases
Visualization and plotting
UI styling and themes
Legend entries
Color-coded categories
Examples
Default color:
obj = Colorable() print(obj.color) # '#1F77B4'
Set from hex string:
obj.color = '#FF0000' print(obj.color) # '#FF0000' (red)
Set from RGB tuple:
obj.color = (1.0, 0.0, 0.0) # Float format (0-1) print(obj.color) # '#FF0000'
Set from color name:
obj.color = 'red' print(obj.color) # '#FF0000'
Get as RGB tuple:
obj.color = '#FF0000' print(obj.color_rgb) # (255, 0, 0)
Case normalization:
obj.color = '#ff0000' print(obj.color) # '#FF0000' (uppercase)
- __init__(*args, **kwargs)#
Methods
__delattr__(name, /)Implement delattr(self, name).
__dir__(/)Default dir() implementation.
__eq__(value, /)Return self==value.
__format__(format_spec, /)Default object formatter.
__ge__(value, /)Return self>=value.
__getattribute__(name, /)Return getattr(self, name).
__getstate__(/)Helper for pickle.
__gt__(value, /)Return self>value.
__hash__(/)Return hash(self).
__init__(*args, **kwargs)__init_subclass__This method is called when a class is subclassed.
__le__(value, /)Return self<=value.
__lt__(value, /)Return self<value.
__ne__(value, /)Return self!=value.
__reduce__(/)Helper for pickle.
__reduce_ex__(protocol, /)Helper for pickle.
__repr__(/)Return repr(self).
__sizeof__(/)Size of object in memory, in bytes.
__str__(/)Return str(self).
__subclasshook__Abstract classes can override this to customize issubclass().
Attributes
__annotations__Color for visualization and styling.
color_rgbGet color as RGB tuple.