{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Tooltips on Nodes" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "import ipycytoscape" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "data = {\n", " 'nodes': [\n", " { 'data': { 'id': '1', 'tooltip': 'a'} },\n", " { 'data': { 'id': '2', 'tooltip': 'b'} },\n", " { 'data': { 'id': '3', 'tooltip': 'c' } }\n", " ],\n", " \n", " 'edges': [\n", " {\n", " 'data': {\n", " 'source': '1',\n", " 'target': '2',\n", " 'tooltip': '4'\n", " }\n", " },\n", " {\n", " 'data': {\n", " 'source': '1',\n", " 'target': '3',\n", " 'tooltip': '6'\n", " }\n", " }\n", " ]\n", "}" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [], "source": [ "cytoscapeobj = ipycytoscape.CytoscapeWidget(nodeSpacing=10)\n", "cytoscapeobj.graph.add_graph_from_json(data)\n", "cytoscapeobj.set_tooltip_source('tooltip')" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Try clicking on the nodes in the graph below. When you click the associated tooltip will show up." ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "bdc9714a566a4f14a828e98c5c2ea571", "version_major": 2, "version_minor": 0 }, "text/plain": [ "CytoscapeWidget(cytoscape_layout={'name': 'cola'}, cytoscape_style=[{'selector': 'node', 'css': {'background-c…" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "display(cytoscapeobj)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.9.2" } }, "nbformat": 4, "nbformat_minor": 4 }