radioviz.services.color_service

Color service module for generating sequential colors.

This module provides functionality for generating a sequence of distinct colors using the HSV color space. It includes utilities for converting colors between different formats and a service class for generating sequential colors based on the golden ratio.

The main components are: - Color data class for immutable color representation - to_mpl() and to_qcolor() conversion functions - ColorService for generating sequential colors

Functions

cmap_to_mpl(cmap_name)

Convert a colormap name to matplotlib format.

to_mpl(color)

Convert a Color object to matplotlib RGB tuple format.

to_qcolor(color)

Convert a Color object to Qt QColor.

Classes

Color(r, g, b)

Immutable color representation in RGB space.

ColorService([saturation, value])

Service for generating sequential colors using HSV color space.

class radioviz.services.color_service.Color(r: float, g: float, b: float)[source]

Bases: object

Immutable color representation in RGB space.

This class represents a color using RGB values in the range [0, 1]. It is designed to be immutable and can be used as a key in dictionaries or stored in sets.

Variables:
  • r (float) – Red component of the color (0.0 to 1.0)

  • g (float) – Green component of the color (0.0 to 1.0)

  • b (float) – Blue component of the color (0.0 to 1.0)

b: float

Blue component of the color (0.0 to 1.0).

g: float

Green component of the color (0.0 to 1.0).

r: float

Red component of the color (0.0 to 1.0).

class radioviz.services.color_service.ColorService(saturation: float = 0.65, value: float = 0.9)[source]

Bases: object

Service for generating sequential colors using HSV color space.

This class generates a sequence of distinct colors using the golden ratio to distribute hues evenly across the color spectrum. Colors are generated in HSV color space and converted to RGB for output.

Variables:
  • _hue (float) – Current hue value in the color space

  • _step (float) – Step size for hue increment (golden ratio)

  • _s (float) – Saturation value for generated colors

  • _v (float) – Value (brightness) value for generated colors

Initialize the ColorService with given saturation and value.

Parameters:
  • saturation (float) – Saturation value for generated colors (default: 0.65)

  • value (float) – Value (brightness) value for generated colors (default: 0.9)

from_workspace(workspace: ServiceWorkspace, ctx: WorkspaceReferenceManager) None[source]

Restore the color service state from a workspace.

This method updates the internal state of the color service using the data stored in the provided ServiceWorkspace object. It retrieves the hue, saturation, and value settings from the workspace state.

Parameters:
next_color() Color[source]

Generate the next color in the sequence.

This method advances the internal hue value by the golden ratio step and returns the corresponding RGB color in the HSV color space.

Returns:

The next color in the sequence

Return type:

Color

reset() None[source]

Reset the color generation sequence to the beginning.

This method resets the internal hue value to zero, allowing the color sequence to start from the beginning again.

to_workspace() ServiceWorkspace[source]

Serialize the current state of the color service to a workspace.

This method creates a ServiceWorkspace object containing the current hue, saturation, and value settings of the color service. This allows the color service state to be saved and restored later.

Returns:

A ServiceWorkspace object containing the current state

Return type:

ServiceWorkspace

radioviz.services.color_service.cmap_to_mpl(cmap_name: str) Colormap[source]

Convert a colormap name to matplotlib format.

This function attempts to convert a colormap name to a matplotlib compatible format. It first checks if the cmap library has a to_mpl method, and if not, it creates a Colormap instance and converts it manually.

Parameters:

cmap_name (str) – Name of the colormap to convert

Returns:

Matplotlib compatible colormap

Return type:

matplotlib.colors.Colormap

radioviz.services.color_service.to_mpl(color: Color) tuple[float, float, float][source]

Convert a Color object to matplotlib RGB tuple format.

Convert a Color instance to a tuple of RGB values suitable for matplotlib plotting functions.

Parameters:

color (Color) – The color to convert

Returns:

RGB tuple in the range [0, 1]

Return type:

tuple[float, float, float]

radioviz.services.color_service.to_qcolor(color: Color) QColor[source]

Convert a Color object to Qt QColor.

Convert a Color instance to a QColor object for use in Qt applications.

Parameters:

color (Color) – The color to convert

Returns:

QColor object representing the same color

Return type:

QColor