Sankey visualisation¶
plot_lineage_sankey renders any dependency graph as an interactive
Plotly Sankey diagram — orange flow lines on a navy background, matching
the Teradata visual identity.
Basic usage¶
from tdfs4ds.lineage import build_teradata_dependency_graph, plot_lineage_sankey
graph = build_teradata_dependency_graph(sql_query=sql)
fig = plot_lineage_sankey(graph, title='Customer Dataset Lineage')
fig.show() # inline in a Jupyter notebook
Save to a self-contained HTML¶
from tdfs4ds.lineage import show_plotly_robust
show_plotly_robust(fig, html_path='lineage_customer_dataset.html')
show_plotly_robust writes a standalone HTML file that requires no Python
or Jupyter — share it with stakeholders directly.
Customise the figure¶
plot_lineage_sankey is a thin Plotly wrapper, so you can post-process
the figure:
fig.update_layout(
title_text='Customer Dataset Lineage',
font=dict(family='Inter', size=12),
paper_bgcolor='#FFFFFF',
)
fig.write_html('lineage.html')
Reading the diagram¶
| Visual | Meaning |
|---|---|
| Left → Right | Upstream → Downstream |
| Node width | Cumulative weight (number of incoming edges) |
| Edge colour | Constant orange (Teradata brand) |
| Hover text | Object name + type (table / view / dataset) |
The graph is directed but Sankey rendering is symmetric — read it as a flow of derived columns rather than as physical I/O.
Combining with the consumer agent¶
The agent's LINEAGE intent calls build_teradata_dependency_graph under
the hood and synthesises a plain-language summary alongside a depth-ordered
dependency list:
from tdfs4ds.agent import consumer_agent
print(consumer_agent("Where does total_amount come from?", thread_id="x"))
For a richer multi-process view, build the graph yourself and use
plot_lineage_sankey — it scales to dozens of nodes without losing
readability.