Skip to content

Sankey#

SankeyPlayback #

SankeyPlayback(
    *,
    series_name: str = "series",
    nodes: Nodes,
    connections: Connections,
    playback: Playback,
    widget_id: str | None = None,
    formatting: NumberFormatting | None = None,
    title: WidgetTitleType = "",
)

Spec for Base Sankey Playback widget.

Construct spec for base Sankey Playback widget.

Parameters:

Name Type Description Default
series_name str

name shown next to values in nodes and connections.

'series'
nodes Nodes

spec for nodes.

required
connections Connections

spec for connections.

required
playback Playback

specs for Playback component.

required
widget_id str | None

unique widget id in a dashboard.

None
formatting NumberFormatting | None

formatting spec for value associated with nodes and connections.

None
title WidgetTitleType

title of widget can be either a string (fixed value) or determined by a value from another widget using a WidgetLink.

''

Example:#

Create a minimal Sankey Playback widget with three frames

import pandas as pd
from engineai.sdk.dashboard.dashboard import Dashboard
from engineai.sdk.dashboard.widgets.sankey import playback

nodes = {}
connections = {}
frames = []

data = [[0.76, 0.24], [0.23, 0.54], [0.23, 0.11]]

for month, values in zip(["Jan", "Feb", "Mar"], data):
    nodes[month] = [{"id": "company"}, {"id": "imports"}, {"id": "exports"}]

    connections[month] = [
        {
            "from": "company",
            "to": "imports",
            "value": values[0],
        },
        {
            "from": "company",
            "to": "exports",
            "value": values[1],
        },
    ]

    frames.append({"id": month})

sankey_widget = playback.SankeyPlayback(
    nodes=playback.Nodes(
        data=nodes,
    ),
    connections=playback.Connections(
        data_column="value",
        data=connections,
    ),
    playback=playback.Playback(
        data=pd.DataFrame(data=frames),
    ),
)

Dashboard(
    workspace_slug="my-workspace",
    app_slug="my-app",
    slug="first-dashboard",
    content=sankey_widget,
)
sankey playback example

Components#

BaseConnections#

ConnectionsStyling #

ConnectionsStyling(
    *,
    color_spec: ColorSpec | None = None,
    data_column: TemplatedStringItem | None = None,
)

Spec to style connections in a Sankey widget.

Construct style spec for a node.

Parameters:

Name Type Description Default
color_spec ColorSpec | None

spec for coloring a node.

None
data_column TemplatedStringItem | None

name of column in pandas dataframe(s) used for color spec if a gradient is used.

None

Raises:

Type Description
SankeyDataColumnMissingError

if color_spec is DiscreteMap/Gradient and data_column has not been specified

BaseNodes#

NodesStyling #

NodesStyling(
    *,
    color_spec: ColorSpec | None = None,
    data_column: TemplatedStringItem | None = None,
    width: int = 8,
)

Spec to style nodes in a Sankey widget.

Construct style spec for a node.

Parameters:

Name Type Description Default
color_spec ColorSpec | None

spec for coloring a node.

None
data_column TemplatedStringItem | None

name of column in pandas dataframe(s) used for color spec if a gradient is used.

None
width int

width of nodes in pixels.

8

Raises:

Type Description
SankeyDataColumnMissingError

if color_spec is DiscreteMap/Gradient and data_column has not been specified

Playback #

Playback(
    *,
    id_column: str = "id",
    data: DataType | DataFrame,
    label_column: str | None = None,
    label_formatting: FormattingType | None = None,
    update_interval: int = 1,
    loop: bool = False,
    auto_play: bool = False,
    initial_state: InitialState | None = None,
)

Spec for Playback widget.

Construct spec for Playback widget.

Parameters:

Name Type Description Default
id_column str

Id Column to match the field in the Data for the Frame.

'id'
data DataType | DataFrame

data for the widget. Can be a pandas dataframe or Storage object if the data is to be retrieved from a storage.

required
label_column str | None

Label Column to match the field in the Data for the Frame Label.

None
label_formatting FormattingType | None

Class to modify the Frame Label Formatting.

None
update_interval int

Configuration for update interval.

1
loop bool

Configuration for Loop.

False
auto_play bool

Configuration for Auto Play.

False
initial_state InitialState | None

Class to add an initial state.

None

InitialState #

InitialState(
    *,
    start_frame_id: str | None = None,
    end_frame_id: str | None = None,
)

Spec for InitialState widget.

Construct spec for Playback Initial State widget.

Parameters:

Name Type Description Default
start_frame_id str | None

column in Pandas DataFrame to define the starting frame.

None
end_frame_id str | None

column in Pandas DataFrame to define the ending frame.

None

Types#

Connections module-attribute #

Connections = BaseConnections[dict[str, DataFrame]]

Nodes module-attribute #

Nodes = BaseNodes[dict[str, DataFrame]]