textnets.viz.TextnetPalette¶
- class textnets.viz.TextnetPalette(n: int)[source]¶
Bases:
PrecalculatedPalette
Color palette for textnets.
Creates the palette backed by the given list. The list must contain RGBA quadruplets or color names, which will be resolved first by L{color_name_to_rgba()}. Anything that is understood by L{color_name_to_rgba()} is OK here.
Methods
Clears the result cache.
Returns the given color from the palette.
Returns multiple colors from the palette.
Attributes
Returns the number of colors in this palette
- clear_cache()¶
Clears the result cache.
The return values of L{Palette.get} are cached. Use this method to clear the cache.
- get(v)¶
Returns the given color from the palette.
Values are cached: if the specific value given has already been looked up, its value will be returned from the cache instead of calculating it again. Use L{Palette.clear_cache} to clear the cache if necessary.
- @note: you shouldn’t override this method in subclasses, override
L{_get} instead. If you override this method, lookups in the L{known_colors} dict won’t work, so you won’t be able to refer to colors by names or RGBA quadruplets, only by integer indices. The caching functionality will disappear as well. However, feel free to override this method if this is exactly the behaviour you want.
- @param v: the color to be retrieved. If it is an integer, it is
passed to L{Palette._get} to be translated to an RGBA quadruplet. Otherwise it is passed to L{color_name_to_rgb()} to determine the RGBA values.
@return: the color as an RGBA quadruplet
- get_many(colors)¶
Returns multiple colors from the palette.
Values are cached: if the specific value given has already been looked upon, its value will be returned from the cache instead of calculating it again. Use L{Palette.clear_cache} to clear the cache if necessary.
- @param colors: the list of colors to be retrieved. The palette class
tries to make an educated guess here: if it is not possible to interpret the value you passed here as a list of colors, the class will simply try to interpret it as a single color by forwarding the value to L{Palette.get}.
- @return: the colors as a list of RGBA quadruplets. The result will
be a list even if you passed a single color index or color name.
- property length¶
Returns the number of colors in this palette