cosmograph.base

Base functionality of cosmograph

class cosmograph.base.CosmoArguments(data=None, kwargs=())[source]

Container for cosmograph arguments, along with diagnosis and processing methods

Get the points and links from the arguments, and raise an error if both are specified and data is also specified.

The rules: - If data is not given (i.e. None), then points and links are returned as is. - If data is given, then:

  • If points is not given, then points is taken to be data.

  • If links is not given, then links is taken to be data.

  • If both points and links are given, raise an error.

class cosmograph.base.GraphJson(*, links: List[Link], nodes: List[Node] = [])[source]
model_config: ClassVar[ConfigDict] = {}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

model_config: ClassVar[ConfigDict] = {}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

class cosmograph.base.Node(*, id: str)[source]
model_config: ClassVar[ConfigDict] = {}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

cosmograph.base.base_cosmo(*, disable_simulation: bool = False, simulation_decay: float = 1000, simulation_gravity: float = 0, simulation_center: float = 0, simulation_repulsion: float = 0.1, simulation_repulsion_theta: float = 1.7, simulation_repulsion_quadtree_levels: float = 12, simulation_link_spring: float = 1, simulation_link_distance: float = 2, simulation_link_dist_random_variation_range: list[Any] = [1, 1.2], simulation_repulsion_from_mouse: float = 2, simulation_friction: float = 0.85, simulation_cluster: float | None = None, background_color: str | list[float] = '#222222', space_size: int = 4096, point_color: str | list[float] = '#b3b3b3', point_greyout_opacity: float = 0.1, point_size: float = 4, point_size_scale: float = 1, hovered_point_cursor: str | None = None, render_hovered_point_ring: bool = False, hovered_point_ring_color: str | list[float] = 'white', focused_point_ring_color: str | list[float] | None = None, focused_point_index: int | None = None, render_links: bool = True, link_color: str | list[float] = '#666666', link_greyout_opacity: float = 0.1, link_width: float = 1, link_width_scale: float = 1, curved_links: bool = False, curved_link_segments: int = 19, curved_link_weight: float = 0.8, curved_link_control_point_distance: float = 0.5, link_arrows: bool | None = None, link_arrows_size_scale: float = 1, link_visibility_distance_range: list[float] = [50, 150], link_visibility_min_transparency: float = 0.25, use_quadtree: bool = False, show_FPS_monitor: bool = False, pixel_ratio: float = 2, scale_points_on_zoom: bool = True, initial_zoom_level: float = 3, disable_zoom: bool = False, enable_drag: bool | None = None, fit_view_on_init: bool = True, fit_view_delay: float = 250, fit_view_padding: float | None = None, fit_view_duration: float | None = None, fit_view_by_points_in_rect: list[list[float]] | None = None, random_seed: int | str | None = None, point_sampling_distance: int = 150, point_id_by: str | None = None, point_index_by: str | None = None, point_color_by: str | None = None, point_color_palette: list[str] | None = None, point_color_by_map: list[list[str | list[float]]] | None = None, point_color_strategy: str | None = None, point_size_by: str | None = None, point_size_range: list[float] | None = None, point_label_by: str | None = None, point_label_weight_by: str | None = None, point_x_by: str | None = None, point_y_by: str | None = None, point_cluster_by: str | None = None, point_cluster_strength_by: str | None = None, point_include_columns: list[str] | None = None, point_timeline_by: str | None = None, link_source_by: str | None = None, link_source_index_by: str | None = None, link_target_by: str | None = None, link_target_index_by: str | None = None, link_color_by: str | None = None, link_width_by: str | None = None, link_arrow_by: str | None = None, link_strength_by: str | None = None, link_strength_range: list[float] | None = None, link_include_columns: list[str] | None = None, show_labels: bool | None = None, show_dynamic_labels: bool | None = None, show_labels_for: list[str] | None = None, show_top_labels: bool | None = None, show_top_labels_limit: int | None = None, show_top_labels_by: str | None = None, static_label_weight: float | None = None, dynamic_label_weight: float | None = None, label_margin: float | None = None, show_hovered_point_label: bool | None = None, disable_point_size_legend: bool | None = None, disable_link_width_legend: bool | None = None, disable_point_color_legend: bool | None = None, disable_link_color_legend: bool | None = None, points: object | None = None, links: object | None = None, clicked_point_index: int | None = None, clicked_point_id: str | None = None, selected_point_indices: list[int] | None = None, selected_point_ids: list[str] | None = None, changePoints: Callable[[Dict[str, Any]], Any] | None = None, changeLinks: Callable[[Dict[str, Any]], Any] | None = None)[source]

Thin layer over CosmographWidget to provide a base interface to the widget object.

All this layer does is pass on the arguments to the CosmographWidget object. The only difference between this and the cosmograph object is that this one has an actual signature, with argument names, defaults, and type annotations.

Parameters:
  • disable_simulation (bool, default=False) – Prevents the simulation from running, merely rendering the graph.

  • simulation_decay (float, default=1000) – Defines how quickly the simulation cools down.

  • simulation_gravity (float, default=0) – Coefficient for gravity force.

  • simulation_center (float, default=0) – Centers the mass force coefficient.

  • simulation_repulsion (float, default=0.1) – Configures point repulsion between points.

  • simulation_repulsion_theta (float, default=1.7) – Decreases / increases the detalization of the Many-Body force calculations.

  • simulation_repulsion_quadtree_levels (float, default=12) – Barnes–Hut approximation depth, usable when useQuadtree is set to True.

  • simulation_link_spring (float, default=1) – Spring constant for links.

  • simulation_link_distance (float, default=2) – Default distance for links.

  • simulation_link_dist_random_variation_range (list[Any], default=[1, 1.2]) – Random link distance range.

  • simulation_repulsion_from_mouse (float, default=2) – Mouse position repulsion coefficient, activated by right-click.

  • simulation_friction (float, default=0.85) – Sets simulation friction.

  • simulation_cluster (float, default=None)

  • background_color (Union[str, list[float]], default="#222222") – Canvas background color.

  • space_size (int, default=4096) – Size of the simulation space.

  • point_color (Union[str, list[float]], default="#b3b3b3") – Column name for point colors.

  • point_greyout_opacity (float, default=0.1) – Opacity of unselected nodes during selection.

  • point_size (float, default=4) – Column name for point sizes.

  • point_size_scale (float, default=1) – Scale factor for point sizes.

  • hovered_point_cursor (str, default=None) – Cursor type when hovering over a point.

  • render_hovered_point_ring (bool, default=False) – Enables ring around hovered points.

  • hovered_point_ring_color (Union[str, list[float]], default="white") – Color of hovered point ring.

  • focused_point_ring_color (Union[str, list[float]], default=None) – Color of the focused point ring.

  • focused_point_index (int, default=None) – Index of the focused point, prioritized over focus_point method.

  • render_links (bool, default=True) – Enables or disables link rendering.

  • link_color (Union[str, list[float]], default="#666666") – Column name for link colors.

  • link_greyout_opacity (float, default=0.1) – Opacity of unselected links during selection.

  • link_width (float, default=1) – Column name for link widths.

  • link_width_scale (float, default=1) – Scale factor for link widths.

  • curved_links (bool, default=False) – Enables or disables curved links.

  • curved_link_segments (int, default=19) – Segments defining curved links.

  • curved_link_weight (float, default=0.8) – Weight factor for link curvature.

  • curved_link_control_point_distance (float, default=0.5) – Control point positioning for curves.

  • link_arrows (bool, default=None)

  • link_arrows_size_scale (float, default=1) – Scale factor for link arrow size.

  • link_visibility_distance_range (list[float], default=[50, 150]) – Pixel distance range for link transparency.

  • link_visibility_min_transparency (float, default=0.25) – Minimum transparency of links based on link_visibility_distance_range.

  • use_quadtree (bool, default=False) – Activates quadtree algorithm for Many-Body force when set to True.

  • show_FPS_monitor (bool, default=False) – Display an FPS counter in the upper right corner of the canvas.

  • pixel_ratio (float, default=2) – Canvas pixel ratio.

  • scale_points_on_zoom (bool, default=True) – Scales point sizes when zooming.

  • initial_zoom_level (float, default=3) – Starting zoom level.

  • disable_zoom (bool, default=False) – Enables or disables zooming.

  • enable_drag (bool, default=None) – Allows graph dragging.

  • fit_view_on_init (bool, default=True) – Automatically fits view to all points upon initialization.

  • fit_view_delay (float, default=250) – Delay for fitting view after initialization in milliseconds.

  • fit_view_padding (float, default=None) – Padding around fit view area.

  • fit_view_duration (float, default=None) – Animation duration for view fitting in milliseconds.

  • fit_view_by_points_in_rect (list[list[float]], default=None) – Fits view to specified rectangle of points, active when fit_view_on_init is True.

  • random_seed (Union[int, str], default=None) – Seed value for generating random numbers in simulations.

  • point_sampling_distance (int, default=150) – Distance threshold for sampling points.

  • point_id_by (str, default=None)

  • point_index_by (str, default=None)

  • point_color_by (str, default=None)

  • point_color_palette (list[str], default=None) – An optional array of color strings that can be used to color the points in the visualization. If provided, the points will be colored using the colors in this palette, cycling through the array as needed. Used when point_color_strategy is set to ‘palette’, ‘interpolatePalette’, or ‘degree’.

  • point_color_by_map (list[list[Union[str, list[float]]]], default=None) – An optional mapping of values to colors for the points in the visualization. The keys in the map should be string and the values can be either color strings or arrays of RGBA values. Used when point_color_strategy is set to ‘map’.

  • point_color_strategy (str, default=None) – Specifies the strategy for coloring points based on data from the point_color_by column.

  • point_size_by (str, default=None)

  • point_size_range (list[float], default=None)

  • point_label_by (str, default=None)

  • point_label_weight_by (str, default=None)

  • point_x_by (str, default=None)

  • point_y_by (str, default=None)

  • point_cluster_by (str, default=None)

  • point_cluster_strength_by (str, default=None)

  • point_include_columns (list[str], default=None) – An array of additional column names to include in point data.

  • point_timeline_by (str, default=None) – Column to determine values for the timeline. Shows a timeline if set.

  • link_source_by (str, default=None)

  • link_source_index_by (str, default=None)

  • link_target_by (str, default=None)

  • link_target_index_by (str, default=None)

  • link_color_by (str, default=None)

  • link_width_by (str, default=None)

  • link_arrow_by (str, default=None)

  • link_strength_by (str, default=None)

  • link_strength_range (list[float], default=None)

  • link_include_columns (list[str], default=None) – An array of additional column names to include in link data.

  • show_labels (bool, default=None)

  • show_dynamic_labels (bool, default=None) – Flag to show dynamic labels for visible points.

  • show_labels_for (list[str], default=None) – An array of point ids for which to show labels.

  • show_top_labels (bool, default=None) – Flag to display labels for the top points.

  • show_top_labels_limit (int, default=None) – Maximum number of top points to show labels for.

  • show_top_labels_by (str, default=None) – Column to determine which points are considered as a top.

  • static_label_weight (float, default=None) – Weight of static labels.

  • dynamic_label_weight (float, default=None) – Weight of dynamic labels.

  • label_margin (float, default=None)

  • show_hovered_point_label (bool, default=None) – Flag to display the label for the currently hovered point.

  • disable_point_size_legend (bool, default=None)

  • disable_link_width_legend (bool, default=None)

  • disable_point_color_legend (bool, default=None)

  • disable_link_color_legend (bool, default=None)

  • points (object, default=None) – Data in a pandas DataFrame format.

  • links (object, default=None) – Data in a pandas DataFrame format.

  • clicked_point_index (int, default=None)

  • clicked_point_id (str, default=None)

  • selected_point_indices (list[int], default=None)

  • selected_point_ids (list[str], default=None)

  • changePoints (Callable[[Dict[str, Any]], Any], default=None)

  • changeLinks (Callable[[Dict[str, Any]], Any], default=None)

cosmograph.base.cosmo(data=None, *, ingress: ~typing.Sequence[~typing.Callable[[~typing.Dict[str, ~typing.Any]], ~typing.Dict[str, ~typing.Any]]] = (), points: object | None = None, links: object | None = None, point_x_by: str | None = None, point_y_by: str | None = None, point_size_by: str | None = None, point_color_by: str | None = None, point_color_palette: list[str] | None = None, point_color_by_map: list[list[str | list[float]]] | None = None, point_color_strategy: str | None = None, point_label_by: str | None = None, point_color: str | list[float] | None = None, point_greyout_opacity: float | None = None, point_size: float | None = None, point_size_scale: float | None = None, point_sampling_distance: int | None = None, point_id_by: str | None = None, point_index_by: str | None = None, point_size_range: list[float] | None = None, point_label_weight_by: str | None = None, point_cluster_by: str | None = None, point_cluster_strength_by: str | None = None, point_include_columns: list[str] | None = None, point_timeline_by: str | None = None, link_color: str | list[float] | None = None, link_greyout_opacity: float | None = None, link_width: float | None = None, link_width_scale: float | None = None, link_arrows: bool | None = None, link_arrows_size_scale: float | None = None, link_visibility_distance_range: list[float] | None = None, link_visibility_min_transparency: float | None = None, link_source_by: str | None = None, link_source_index_by: str | None = None, link_target_by: str | None = None, link_target_index_by: str | None = None, link_color_by: str | None = None, link_width_by: str | None = None, link_arrow_by: str | None = None, link_strength_by: str | None = None, link_strength_range: list[float] | None = None, link_include_columns: list[str] | None = None, disable_simulation: bool | None = None, simulation_decay: float | None = None, simulation_gravity: float | None = None, simulation_center: float | None = None, simulation_repulsion: float | None = None, simulation_repulsion_theta: float | None = None, simulation_repulsion_quadtree_levels: float | None = None, simulation_link_spring: float | None = None, simulation_link_distance: float | None = None, simulation_link_dist_random_variation_range: list[~typing.Any] | None = None, simulation_repulsion_from_mouse: float | None = None, simulation_friction: float | None = None, simulation_cluster: float | None = None, background_color: str | list[float] | None = None, space_size: int | None = None, hovered_point_cursor: str | None = None, render_hovered_point_ring: bool | None = None, hovered_point_ring_color: str | list[float] | None = None, focused_point_ring_color: str | list[float] | None = None, focused_point_index: int | None = None, render_links: bool | None = None, curved_links: bool | None = None, curved_link_segments: int | None = None, curved_link_weight: float | None = None, curved_link_control_point_distance: float | None = None, use_quadtree: bool | None = None, show_FPS_monitor: bool | None = None, pixel_ratio: float | None = None, scale_points_on_zoom: bool | None = None, initial_zoom_level: float | None = None, disable_zoom: bool | None = None, enable_drag: bool | None = None, fit_view_on_init: bool | None = None, fit_view_delay: float | None = None, fit_view_padding: float | None = None, fit_view_duration: float | None = None, fit_view_by_points_in_rect: list[list[float]] | None = None, random_seed: int | str | None = None, show_labels: bool | None = None, show_dynamic_labels: bool | None = None, show_labels_for: list[str] | None = None, show_top_labels: bool | None = None, show_top_labels_limit: int | None = None, show_top_labels_by: str | None = None, static_label_weight: float | None = None, dynamic_label_weight: float | None = None, label_margin: float | None = None, show_hovered_point_label: bool | None = None, disable_point_size_legend: bool | None = None, disable_link_width_legend: bool | None = None, disable_point_color_legend: bool | None = None, disable_link_color_legend: bool | None = None, clicked_point_index: int | None = None, clicked_point_id: str | None = None, selected_point_indices: list[int] | None = None, selected_point_ids: list[str] | None = None, changePoints: ~typing.Callable[[~typing.Dict[str, ~typing.Any]], ~typing.Any] | None = None, changeLinks: ~typing.Callable[[~typing.Dict[str, ~typing.Any]], ~typing.Any] | None = None, copy_before_ingress: bool = True, data_resolution: ~typing.Callable[[~typing.Dict[str, ~typing.Any], ~typing.Any], ~typing.Dict[str, ~typing.Any]] = <function prioritize_points>, validate_kwargs: ~typing.Callable[[~typing.Dict[str, ~typing.Any]], ~typing.Dict[str, ~typing.Any]] = <function validate_kwargs>)[source]

Thin layer over CosmographWidget to provide a base interface to the widget object, with signature, docs with argument descriptions, and a more flexible interface comprising some data processing, argument aliasing and validation, error handling, etc.

param data:

Convenience argument whose value will be used for either the points or links argument.

param ingress:

A function or sequence of functions that will be applied to the kwargs before they are passed to the Cosmograph constructor.

param copy_before_ingress:

Whether to make a copy of the points and links before applying the ingress transformations. This is so that the original data is not modified by the ingress functions.

param data_resolution:

A function that will be used to resolve the data argument. This is the function that takes care of how to handle the data argument,

param validate_kwargs:

A function that will be applied to the kwargs after the ingress transformations. This is the function that will validate the kwargs before they are passed to the Cosmograph constructor.

Parameters:
  • disable_simulation (bool, default=False) – Prevents the simulation from running, merely rendering the graph.

  • simulation_decay (float, default=1000) – Defines how quickly the simulation cools down.

  • simulation_gravity (float, default=0) – Coefficient for gravity force.

  • simulation_center (float, default=0) – Centers the mass force coefficient.

  • simulation_repulsion (float, default=0.1) – Configures point repulsion between points.

  • simulation_repulsion_theta (float, default=1.7) – Decreases / increases the detalization of the Many-Body force calculations.

  • simulation_repulsion_quadtree_levels (float, default=12) – Barnes–Hut approximation depth, usable when useQuadtree is set to True.

  • simulation_link_spring (float, default=1) – Spring constant for links.

  • simulation_link_distance (float, default=2) – Default distance for links.

  • simulation_link_dist_random_variation_range (list[Any], default=[1, 1.2]) – Random link distance range.

  • simulation_repulsion_from_mouse (float, default=2) – Mouse position repulsion coefficient, activated by right-click.

  • simulation_friction (float, default=0.85) – Sets simulation friction.

  • simulation_cluster (float, default=None)

  • background_color (Union[str, list[float]], default="#222222") – Canvas background color.

  • space_size (int, default=4096) – Size of the simulation space.

  • point_color (Union[str, list[float]], default="#b3b3b3") – Column name for point colors.

  • point_greyout_opacity (float, default=0.1) – Opacity of unselected nodes during selection.

  • point_size (float, default=4) – Column name for point sizes.

  • point_size_scale (float, default=1) – Scale factor for point sizes.

  • hovered_point_cursor (str, default=None) – Cursor type when hovering over a point.

  • render_hovered_point_ring (bool, default=False) – Enables ring around hovered points.

  • hovered_point_ring_color (Union[str, list[float]], default="white") – Color of hovered point ring.

  • focused_point_ring_color (Union[str, list[float]], default=None) – Color of the focused point ring.

  • focused_point_index (int, default=None) – Index of the focused point, prioritized over focus_point method.

  • render_links (bool, default=True) – Enables or disables link rendering.

  • link_color (Union[str, list[float]], default="#666666") – Column name for link colors.

  • link_greyout_opacity (float, default=0.1) – Opacity of unselected links during selection.

  • link_width (float, default=1) – Column name for link widths.

  • link_width_scale (float, default=1) – Scale factor for link widths.

  • curved_links (bool, default=False) – Enables or disables curved links.

  • curved_link_segments (int, default=19) – Segments defining curved links.

  • curved_link_weight (float, default=0.8) – Weight factor for link curvature.

  • curved_link_control_point_distance (float, default=0.5) – Control point positioning for curves.

  • link_arrows (bool, default=None)

  • link_arrows_size_scale (float, default=1) – Scale factor for link arrow size.

  • link_visibility_distance_range (list[float], default=[50, 150]) – Pixel distance range for link transparency.

  • link_visibility_min_transparency (float, default=0.25) – Minimum transparency of links based on link_visibility_distance_range.

  • use_quadtree (bool, default=False) – Activates quadtree algorithm for Many-Body force when set to True.

  • show_FPS_monitor (bool, default=False) – Display an FPS counter in the upper right corner of the canvas.

  • pixel_ratio (float, default=2) – Canvas pixel ratio.

  • scale_points_on_zoom (bool, default=True) – Scales point sizes when zooming.

  • initial_zoom_level (float, default=3) – Starting zoom level.

  • disable_zoom (bool, default=False) – Enables or disables zooming.

  • enable_drag (bool, default=None) – Allows graph dragging.

  • fit_view_on_init (bool, default=True) – Automatically fits view to all points upon initialization.

  • fit_view_delay (float, default=250) – Delay for fitting view after initialization in milliseconds.

  • fit_view_padding (float, default=None) – Padding around fit view area.

  • fit_view_duration (float, default=None) – Animation duration for view fitting in milliseconds.

  • fit_view_by_points_in_rect (list[list[float]], default=None) – Fits view to specified rectangle of points, active when fit_view_on_init is True.

  • random_seed (Union[int, str], default=None) – Seed value for generating random numbers in simulations.

  • point_sampling_distance (int, default=150) – Distance threshold for sampling points.

  • point_id_by (str, default=None)

  • point_index_by (str, default=None)

  • point_color_by (str, default=None)

  • point_color_palette (list[str], default=None) – An optional array of color strings that can be used to color the points in the visualization. If provided, the points will be colored using the colors in this palette, cycling through the array as needed. Used when point_color_strategy is set to ‘palette’, ‘interpolatePalette’, or ‘degree’.

  • point_color_by_map (list[list[Union[str, list[float]]]], default=None) – An optional mapping of values to colors for the points in the visualization. The keys in the map should be string and the values can be either color strings or arrays of RGBA values. Used when point_color_strategy is set to ‘map’.

  • point_color_strategy (str, default=None) – Specifies the strategy for coloring points based on data from the point_color_by column.

  • point_size_by (str, default=None)

  • point_size_range (list[float], default=None)

  • point_label_by (str, default=None)

  • point_label_weight_by (str, default=None)

  • point_x_by (str, default=None)

  • point_y_by (str, default=None)

  • point_cluster_by (str, default=None)

  • point_cluster_strength_by (str, default=None)

  • point_include_columns (list[str], default=None) – An array of additional column names to include in point data.

  • point_timeline_by (str, default=None) – Column to determine values for the timeline. Shows a timeline if set.

  • link_source_by (str, default=None)

  • link_source_index_by (str, default=None)

  • link_target_by (str, default=None)

  • link_target_index_by (str, default=None)

  • link_color_by (str, default=None)

  • link_width_by (str, default=None)

  • link_arrow_by (str, default=None)

  • link_strength_by (str, default=None)

  • link_strength_range (list[float], default=None)

  • link_include_columns (list[str], default=None) – An array of additional column names to include in link data.

  • show_labels (bool, default=None)

  • show_dynamic_labels (bool, default=None) – Flag to show dynamic labels for visible points.

  • show_labels_for (list[str], default=None) – An array of point ids for which to show labels.

  • show_top_labels (bool, default=None) – Flag to display labels for the top points.

  • show_top_labels_limit (int, default=None) – Maximum number of top points to show labels for.

  • show_top_labels_by (str, default=None) – Column to determine which points are considered as a top.

  • static_label_weight (float, default=None) – Weight of static labels.

  • dynamic_label_weight (float, default=None) – Weight of dynamic labels.

  • label_margin (float, default=None)

  • show_hovered_point_label (bool, default=None) – Flag to display the label for the currently hovered point.

  • disable_point_size_legend (bool, default=None)

  • disable_link_width_legend (bool, default=None)

  • disable_point_color_legend (bool, default=None)

  • disable_link_color_legend (bool, default=None)

  • points (object, default=None) – Data in a pandas DataFrame format.

  • links (object, default=None) – Data in a pandas DataFrame format.

  • clicked_point_index (int, default=None)

  • clicked_point_id (str, default=None)

  • selected_point_indices (list[int], default=None)

  • selected_point_ids (list[str], default=None)

  • changePoints (Callable[[Dict[str, Any]], Any], default=None)

  • changeLinks (Callable[[Dict[str, Any]], Any], default=None)

cosmograph.base.prioritize_points(kwargs, data=None)[source]

A data resolver: Will priorities assigning data to points.

The rules: - If data is not given (i.e. None), then points and links are returned as is. - If data is given, then:

  • If points is not given, then points is taken to be data.

  • If links is not given, then links is taken to be data.

  • If both points and links are given, raise an error.