lightningchart.utils package

Submodules

lightningchart.utils.utils module

class lightningchart.utils.utils.LegendEntryOptions[source]

Bases: TypedDict

Configuration for legend.set_entry_options() method.

button_fill_style: str
button_rotation: float
button_shape: str
button_size: int | Dict[str, int]
button_stroke_style: Dict[str, int | str]
highlight: bool
lut: Any
lut_display_proportional_steps: bool
lut_length: int
lut_thickness: int
match_style_exactly: bool
show: bool
text: str
text_fill_style: str
text_font: Dict[str, int | str]
class lightningchart.utils.utils.LegendOptions[source]

Bases: TypedDict

Configuration dictionary for chart legends.

add_entries_automatically: bool
auto_hide_threshold: float
background_fill_style: str
background_stroke_style: Dict[str, int | str]
background_visible: bool
entries: LegendEntryOptions
entry_margin: int
margin_inner: int
margin_outer: int | Dict[str, int]
orientation: str
padding: int | Dict[str, int]
position: str | Dict[str, int | str]
render_on_top: bool
title: str
title_fill_style: str
title_font: Dict[str, int | str]
visible: bool
class lightningchart.utils.utils.NumpyEncoder(*, skipkeys=False, ensure_ascii=True, check_circular=True, allow_nan=True, sort_keys=False, indent=None, separators=None, default=None)[source]

Bases: JSONEncoder

default(obj)[source]

Implement this method in a subclass such that it returns a serializable object for o, or calls the base implementation (to raise a TypeError).

For example, to support arbitrary iterators, you could implement default like this:

def default(self, o):
    try:
        iterable = iter(o)
    except TypeError:
        pass
    else:
        return list(iterable)
    # Let the base class default method raise the TypeError
    return super().default(o)
class lightningchart.utils.utils.PaddingKwargs[source]

Bases: TypedDict

bottom: int | float
left: int | float
right: int | float
top: int | float
class lightningchart.utils.utils.TickStyleKwargs[source]

Bases: TypedDict

background_fill_color: object
background_stroke_color: object
background_stroke_thickness: float
font_family: str
font_size: float
font_style: str
font_weight: str
padding: int | float | dict
text_color: object
text_padding: float
text_rotation: float
tick_length: float
tick_stroke_color: object
tick_stroke_thickness: float
lightningchart.utils.utils.apply_post_legend_config(chart_instance, legend_config)[source]

Apply post-initialization legend configurations that require instance methods.

Parameters:
  • chart_instance – Chart instance with legend property

  • legend_config (dict) – Legend configuration dictionary

lightningchart.utils.utils.build_legend_config(legend=None)[source]

Build legend configuration from legend dictionary.

lightningchart.utils.utils.build_series_legend_options(legend=None)[source]

Build series legend options from dictionary.

Parameters:

legend (dict) – Legend configuration dictionary

Returns:

Processed legend options for series, or None if no options

Return type:

dict

lightningchart.utils.utils.compose_tick_args(text_color=None, text_rotation: float | None = None, font_size: float | None = None, font_family: str | None = None, font_weight: str | None = None, font_style: str | None = None, text_padding: float | None = None, tick_length: float | None = None, tick_stroke_thickness: float | None = None, tick_stroke_color=None, background_fill_color=None, background_stroke_thickness: float | None = None, background_stroke_color=None, padding: int | float | dict | None = None) dict[source]
lightningchart.utils.utils.convert_color_to_hex(color: str | int | tuple[int, int, int] | tuple[int, int, int, int] | dict[str, int] | Color) str[source]

Convert various color representations to a hex string.

Supports: - Hex strings (3, 4, 6, or 8 characters) - CSS color names - Integer RGB (0x000000 to 0xFFFFFF) or ARGB (0x00000000 to 0xFFFFFFFF) - RGB tuples/lists (3 or 4 integers in 0-255 range) - RGB dicts (keys: ‘r’, ‘g’, ‘b’ and optional ‘a’) - lightningchart.Color objects

Parameters:

color – Color representation to convert.

Returns:

Hex color string in the format ‘#RRGGBB’ or ‘#RRGGBBAA’.

lightningchart.utils.utils.convert_for_serialization(obj)[source]

Convert numpy/pandas types to JSON/msgpack-serializable types.

lightningchart.utils.utils.convert_to_base64(source: str) str[source]

Converts an image or video file (local or remote) to a Base64 data URI.

Parameters:

source (str) – File path or URL. If the source already starts with ‘data:’, it is returned unchanged.

Returns:

A data URI in the form ‘data:<mime_type>;base64,<base64_data>’.

Return type:

str

Raises:
  • FileNotFoundError – If a local file is not found.

  • ValueError – If the file extension is unsupported.

lightningchart.utils.utils.convert_to_dict(arg)[source]

Converts various data types to a Python dictionary format.

Parameters:

arg – The input object to be converted to a dictionary.

Returns:

A Python dictionary containing the converted values from the input.

lightningchart.utils.utils.convert_to_list(arg)[source]

Converts various data types to a Python list format.

For v8 compatibility, handles Color objects and preserves single values when appropriate to avoid asymmetric data issues.

Parameters:

arg – The input object to be converted to a list.

Returns:

A Python list containing the converted values from the input, or the original value if it should remain as a single value.

lightningchart.utils.utils.convert_to_matrix(arg)[source]

Converts various multidimensional data types to a Python matrix represented as a list of lists containing native Python numbers (int or float).

Parameters:

arg – The input object to be converted to a matrix.

Returns:

A Python list of lists representing the converted matrix.

lightningchart.utils.utils.convert_to_unix_time(arg, str_format: str = None)[source]

Convert various datetime formats to Unix timestamp in milliseconds.

Parameters:
  • arg – The datetime value(s) to convert. Acceptable types include: int, float, datetime, pd.Timestamp, np.datetime64, str, or list

  • str_format – The expected format of the string date if arg is a string and not in ISO format. This should follow the Python datetime.strptime format codes.

Returns:

A Unix timestamp in milliseconds as an integer if a single item was passed, or a list of Unix timestamps in milliseconds if a list was passed.

lightningchart.utils.utils.msgpack_default(obj)[source]
lightningchart.utils.utils.normalize_schema(schema: dict | None) dict | None[source]

Normalize user-provided schema for series (validates storage types and copies known keys).

Returns processed schema dict or None if input is falsy.

lightningchart.utils.utils.process_spark_chart_cell(cell)[source]

Process spark chart cell with color conversions.

lightningchart.utils.utils.process_spark_chart_color(color)[source]

Convert color to hex if string, preserve other formats.

lightningchart.utils.utils.process_spark_chart_marker(marker)[source]

Process marker colors.

lightningchart.utils.utils.send_cursor_tick_style(cursor, command: str, **kwargs)[source]

Internal helper: build tick-style args and send them to TS command handler.

Module contents