Skip to content

Commit

Permalink
v1.7.0
Browse files Browse the repository at this point in the history
closes #49, closes #44
  • Loading branch information
fskpf committed Jun 3, 2024
1 parent 172866e commit 77403cc
Show file tree
Hide file tree
Showing 13 changed files with 1,203 additions and 125 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,12 @@ You can find the full documentation [here](https://yworks.github.io/yfiles-jupyt
<td><a href="https://github.com/yWorks/yfiles-jupyter-graphs/blob/main/examples/03_color_mapping.ipynb"><img src="https://raw.githubusercontent.com/yWorks/yfiles-jupyter-graphs/main/screenshots/element_color_mapping.png" title="Make Data Dependent Property Changes" alt="element color mapping"></a>
<a href="https://github.com/yWorks/yfiles-jupyter-graphs/blob/main/examples/03_color_mapping.ipynb">Make Data Dependent Property Changes</a><br><a target="_blank" href="https://colab.research.google.com/github/yWorks/yfiles-jupyter-graphs/blob/main/examples/03_color_mapping.ipynb"><img src="https://colab.research.google.com/assets/colab-badge.svg" alt="Open In Colab"/></a></td>
</tr>
<tr>
<td><a href="https://github.com/yWorks/yfiles-jupyter-graphs/blob/main/examples/29_heat_mapping.ipynb"><img src="https://raw.githubusercontent.com/yWorks/yfiles-jupyter-graphs/main/screenshots/heat_mapping.png" title="Define a heatmap background" alt="heat mapping"></a>
<a href="https://github.com/yWorks/yfiles-jupyter-graphs/blob/main/examples/29_heat_mapping.ipynb">Define a Heatmap Background</a><br><a target="_blank" href="https://colab.research.google.com/github/yWorks/yfiles-jupyter-graphs/blob/main/examples/29_heat_mapping.ipynb"><img src="https://colab.research.google.com/assets/colab-badge.svg" alt="Open In Colab"/></a></td>
<td><a href="https://github.com/yWorks/yfiles-jupyter-graphs/blob/main/examples/30_leaflet_mapping.ipynb"><img src="https://raw.githubusercontent.com/yWorks/yfiles-jupyter-graphs/main/screenshots/leaflet_map.png" title="Use a Map background" alt="leaflet mapping"></a>
<a href="https://github.com/yWorks/yfiles-jupyter-graphs/blob/main/examples/30_leaflet_mapping.ipynb">Use a Map Background</a><br><a target="_blank" href="https://colab.research.google.com/github/yWorks/yfiles-jupyter-graphs/blob/main/examples/30_leaflet_mapping.ipynb"><img src="https://colab.research.google.com/assets/colab-badge.svg" alt="Open In Colab"/></a></td>
</tr>
</table>

For example code look [here](https://github.com/yWorks/yfiles-jupyter-graphs/tree/master/examples).
Expand Down
11 changes: 8 additions & 3 deletions examples/00_toc.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,12 @@
"- **[Advanced example using Neo4j graph data science](./27_neo4j-sample-gds_example.ipynb)** <br>\n",
" This notebook contains a more in-depth example of the yFiles Graphs for Jupyter widget with Neo4j Graph Data Science package.\n",
"- **[Example using Little Alchemy 2 database](./28_little-alchemy_example.ipynb)** <br>\n",
" This notebook uses some Game recipes of Little Alchemy 2"
" This notebook uses some Game recipes of Little Alchemy 2\n",
"- **Backgrounds**\n",
" - [Heat Mapping](./29_heat_mapping.ipynb)\n",
" - [Leaflet Integration](./30_leaflet_mapping.ipynb)\n",
"- **[Nested Graphs](./31_nested_graphs.ipynb)** <br>\n",
" This notebook shows how to create group nodes"
]
},
{
Expand All @@ -78,7 +83,7 @@
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
Expand All @@ -92,7 +97,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.15"
"version": "3.12.3"
}
},
"nbformat": 4,
Expand Down
60 changes: 55 additions & 5 deletions examples/02_label_mapping.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,12 @@
"from yfiles_jupyter_graphs import GraphWidget\n",
"%pip install networkx --quiet\n",
"from typing import Dict\n",
"from networkx import erdos_renyi_graph\n",
"from networkx import erdos_renyi_graph, set_node_attributes, set_edge_attributes\n",
"\n",
"g = erdos_renyi_graph(10, 0.3, 2)\n",
"# We will use this additional attribute as a label later on\n",
"set_node_attributes(g, {node: {\"NodeName\": f\"Node {node}\"} for node in g.nodes})\n",
"set_edge_attributes(g, {edge: {\"EdgeName\": f\"Edge {edge}\"} for edge in g.edges})\n",
"w = GraphWidget(graph=g)\n"
]
},
Expand Down Expand Up @@ -94,6 +97,32 @@
"metadata": {},
"source": [
"## Node Label Mapping\n",
"### Property key mapping\n",
"\n",
"To only reflect the data of a property on the node, you can easily assign this using the respective key. Check out the [mapping overloads notebook](./12_mapping_overloads.ipynb) for a more detailed explanation.\n",
"\n",
"This is a shorter alternative to a local lambda function, e.g., `lambda node: node['properties']['NodeName']`."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "0057e94d-fc4a-417a-ad94-a81689ec6f16",
"metadata": {},
"outputs": [],
"source": [
"w.node_label_mapping = 'NodeName'\n",
"display(w)"
]
},
{
"cell_type": "markdown",
"id": "12bd0dd5-77c8-4aa3-bd0d-46c80f7ec83b",
"metadata": {},
"source": [
"### Function mapping\n",
"\n",
"For a more versatile node label computation you can define a mapping function:\n",
"\n",
"The node label mapping is a function that is supposed to return a label string for each given node object which is then displayed in the widget.\n",
"\n",
Expand Down Expand Up @@ -196,8 +225,31 @@
"metadata": {},
"source": [
"## Edge Label Mapping\n",
"### Property key mapping\n",
"\n",
"The edge label mapping is a function that is supposed to return a label string for each given edge object which is then displayed in the widget.\n",
"Similar to node mappings, edges also allow for a short version assigning properties by key:"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "d320734c-8a53-4bbe-8468-d0de06423bcd",
"metadata": {},
"outputs": [],
"source": [
"w2 = GraphWidget(graph=g)\n",
"w2.edge_label_mapping = 'EdgeName'\n",
"display(w2)"
]
},
{
"cell_type": "markdown",
"id": "4aeec1ca-34e6-4cb5-9e0a-a361606046fa",
"metadata": {},
"source": [
"### Function mapping\n",
"\n",
"Similar to node labels, you can define an edge label mapping function for more control over the visualized label. The edge label mapping is a function that is supposed to return a label string for each given edge object which is then displayed in the widget.\n",
"\n",
"We will use a similar mapping function as for the node labels. We negate every edge index and use this as our new edge label. \\\n",
"For this, we first a define a new mapping function and then set this function as our current edge label mapping. \\\n",
Expand All @@ -211,8 +263,6 @@
"metadata": {},
"outputs": [],
"source": [
"w2 = GraphWidget(graph=g)\n",
"\n",
"edges = w2.get_edges()\n",
"def custom_edge_label_mapping(edge: Dict):\n",
" \"\"\"let the label be the negated index\"\"\"\n",
Expand Down Expand Up @@ -301,7 +351,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.3"
"version": "3.12.3"
}
},
"nbformat": 4,
Expand Down
134 changes: 18 additions & 116 deletions examples/02a_label_styles_mapping.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,10 @@
},
{
"cell_type": "code",
"execution_count": 1,
"execution_count": null,
"id": "3ce520a0-0c33-48ae-ab02-54d7aba460a8",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Note: you may need to restart the kernel to use updated packages.\n",
"Note: you may need to restart the kernel to use updated packages.\n"
]
}
],
"outputs": [],
"source": [
"%pip install yfiles_jupyter_graphs --quiet\n",
"from yfiles_jupyter_graphs import GraphWidget\n",
Expand All @@ -58,7 +49,7 @@
},
{
"cell_type": "code",
"execution_count": 2,
"execution_count": null,
"id": "d99602b7-b89b-46bb-a477-00172006ac05",
"metadata": {},
"outputs": [],
Expand Down Expand Up @@ -89,25 +80,10 @@
},
{
"cell_type": "code",
"execution_count": 3,
"execution_count": null,
"id": "1a87056a-a345-4221-ad19-d1440a63f08e",
"metadata": {},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "e7c4d9f1bab64fe383b57d1829a39f7d",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"GraphWidget(layout=Layout(height='500px', width='100%'))"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"outputs": [],
"source": [
"display(w)"
]
Expand Down Expand Up @@ -136,7 +112,7 @@
},
{
"cell_type": "code",
"execution_count": 4,
"execution_count": null,
"id": "371c5053-6019-4a20-af67-067f38fcbf39",
"metadata": {},
"outputs": [],
Expand Down Expand Up @@ -167,47 +143,21 @@
},
{
"cell_type": "code",
"execution_count": 5,
"execution_count": null,
"id": "938719a0-d739-4ddf-8f7f-da00c1d05012",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"<function __main__.custom_label_styles_mapping(node:Dict)>"
]
},
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
}
],
"outputs": [],
"source": [
"w.set_node_label_mapping(custom_label_styles_mapping)\n",
"w.get_node_label_mapping()"
]
},
{
"cell_type": "code",
"execution_count": 6,
"execution_count": null,
"id": "a45c9447-74ba-48a1-bdcb-acb6e3bec468",
"metadata": {},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "e7c4d9f1bab64fe383b57d1829a39f7d",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"GraphWidget(layout=Layout(height='500px', width='100%'))"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"outputs": [],
"source": [
"display(w)"
]
Expand All @@ -222,21 +172,10 @@
},
{
"cell_type": "code",
"execution_count": 7,
"execution_count": null,
"id": "5f64587f-1035-4649-a751-32022baac797",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"<function yfiles_jupyter_graphs.widget.GraphWidget.default_node_label_mapping(index:int, node:Dict)>"
]
},
"execution_count": 7,
"metadata": {},
"output_type": "execute_result"
}
],
"outputs": [],
"source": [
"w.del_node_label_mapping()\n",
"w.get_node_label_mapping()"
Expand All @@ -261,21 +200,10 @@
},
{
"cell_type": "code",
"execution_count": 8,
"execution_count": null,
"id": "3cb41d68-d190-4e48-b91d-58a8973463c7",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"<function __main__.custom_label_styles_mapping(node:Dict)>"
]
},
"execution_count": 8,
"metadata": {},
"output_type": "execute_result"
}
],
"outputs": [],
"source": [
"w2 = GraphWidget(graph=g)\n",
"w2.set_edge_label_mapping(custom_label_styles_mapping)\n",
Expand All @@ -284,25 +212,10 @@
},
{
"cell_type": "code",
"execution_count": 9,
"execution_count": null,
"id": "70a11fd8-e8ff-40ce-ba01-94762d3fd78d",
"metadata": {},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "20d33b73e3a6463dacc6f2ae6ed7a685",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"GraphWidget(layout=Layout(height='500px', width='100%'))"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"outputs": [],
"source": [
"display(w2)"
]
Expand All @@ -317,21 +230,10 @@
},
{
"cell_type": "code",
"execution_count": 10,
"execution_count": null,
"id": "1b31186d-0cbb-4e2b-903e-83a9a3659640",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"<function yfiles_jupyter_graphs.widget.GraphWidget.default_edge_label_mapping(index:int, edge:Dict)>"
]
},
"execution_count": 10,
"metadata": {},
"output_type": "execute_result"
}
],
"outputs": [],
"source": [
"w2.del_edge_label_mapping()\n",
"w2.get_edge_label_mapping()"
Expand Down
5 changes: 4 additions & 1 deletion examples/16_neo4j_import.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@
"metadata": {},
"outputs": [],
"source": [
"NEO4J_URI = \"neo4j+s://demo.neo4jlabs.com\" \n",
"NEO4J_URI = \"neo4j+ssc://demo.neo4jlabs.com\" \n",
"NEO4J_USERNAME = \"movies\"\n",
"NEO4J_PASSWORD = \"movies\"\n",
"\n",
Expand Down Expand Up @@ -203,6 +203,9 @@
"w3.node_label_mapping = lambda node: node['properties']['name'] if 'name' in node['properties'] else node['properties']['title']\n",
"\n",
"w3.hierarchic_layout()\n",
"\n",
"w3.set_heat_mapping(lambda element: element['properties']['votes']/ 7000 if 'votes' in element['properties'] else 0)\n",
"\n",
"display(w3)"
]
}
Expand Down
Loading

0 comments on commit 77403cc

Please sign in to comment.