Skip to content

Commit

Permalink
docs: update sankey diagram (#9077)
Browse files Browse the repository at this point in the history
## Description of changes

this started as trying to get dynamic light/dark mode for plotting (with
the sankey diagram, but any) working with Quarto. I still couldn't
figure it out. there's definitely a path that's like save both versions
of the image and use JavaScript to dynamically load the right one.
another option, if we could get the HTML for the page in Python, would
be to use that

so anyway, this actually just updates the sankey diagram to put it in a
funciton to choose light/dark mode, minor code improvements, and
improving the colors

one suggestion from Jim was simplifying the cateogires and I agree, so
now it's just SQL/DataFrame

## Issues closed
  • Loading branch information
lostmygithubaccount authored Apr 29, 2024
1 parent 1926eb4 commit b691959
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 21 deletions.
5 changes: 2 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -160,11 +160,10 @@ Ibis supports 20+ backends:

Most Python dataframes are tightly coupled to their execution engine. And many databases only support SQL, with no Python API. Ibis solves this problem by providing a common API for data manipulation in Python, and compiling that API into the backend’s native language. This means you can learn a single API and use it across any supported backend (execution engine).

Ibis supports three types of backend:
Ibis broadly supports two types of backend:

1. SQL-generating backends
2. Expression-generating backends
3. Naïve execution backends
2. DataFrame-generating backends

![Ibis backend types](docs/images/backends.png)

Expand Down
47 changes: 32 additions & 15 deletions docs/backends_sankey.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,28 @@

import plotly.graph_objects as go


def to_greyish(hex_code, grey_value=128):
hex_code = hex_code.lstrip("#")
r, g, b = int(hex_code[0:2], 16), int(hex_code[2:4], 16), int(hex_code[4:6], 16)

new_r = (r + grey_value) // 2
new_g = (g + grey_value) // 2
new_b = (b + grey_value) // 2

new_hex_code = f"#{new_r:02x}{new_g:02x}{new_b:02x}"

return new_hex_code


category_colors = {
"Ibis API": "#7C65A0",
"SQL": "#6A9BC9",
"DataFrame": "#D58273",
}

backend_categories = {
"SQL-generating": [
list(category_colors.keys())[1]: [
"BigQuery",
"ClickHouse",
"DataFusion",
Expand All @@ -22,15 +42,7 @@
"SQLite",
"Trino",
],
"Expression-generating": ["Dask", "Polars"],
"Naïve execution": ["pandas"],
}

category_colors = {
"Ibis API": "#999999",
"Naïve execution": "#FF8C00",
"Expression-generating": "#6A5ACD",
"SQL-generating": "#3CB371",
list(category_colors.keys())[2]: ["Dask", "pandas", "Polars"],
}

nodes, links = [], []
Expand All @@ -39,7 +51,6 @@
nodes.append({"label": "Ibis API", "color": category_colors["Ibis API"]})
node_index["Ibis API"] = 0


idx = 1
for category, backends in backend_categories.items():
nodes.append({"label": category, "color": category_colors[category]})
Expand All @@ -60,26 +71,32 @@
}
)


fig = go.Figure(
data=[
go.Sankey(
node=dict(
pad=20,
thickness=20,
line=dict(color="black", width=0.5),
line=dict(color="grey", width=0.5),
label=[node["label"] for node in nodes],
color=[node["color"] for node in nodes],
),
link=dict(
source=[link["source"] for link in links],
target=[link["target"] for link in links],
value=[link["value"] for link in links],
line=dict(color="grey", width=0.5),
color=[to_greyish(nodes[link["target"]]["color"]) for link in links],
),
)
]
],
)

fig.update_layout(
title_text="Ibis backend types", font_size=14, margin=dict(l=30, r=30, t=80, b=30)
title_text="Ibis backend types",
font_size=24,
# font_family="Arial",
title_font_size=30,
margin=dict(l=30, r=30, t=80, b=30),
template="plotly_dark",
)
Binary file modified docs/images/backends.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 2 additions & 3 deletions docs/why.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -202,11 +202,10 @@ providing a common API for data manipulation in Python, and compiling that API
into the backend's native language. This means you can learn a single API and
use it across any supported backend (execution engine).

Ibis supports three types of backend:
Ibis broadly supports two types of backend:

1. SQL-generating backends
2. Expression-generating backends
3. Naïve execution backends
2. DataFrame-generating backends

```{python}
#| echo: false
Expand Down

0 comments on commit b691959

Please sign in to comment.