{ "cells": [ { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "import ipycytoscape" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "import json\n", "with open(\"geneData.json\") as fi:\n", " json_file = json.load(fi)\n", "with open(\"geneStyle.json\") as fi:\n", " s = json.load(fi)" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [], "source": [ "cytoscapeobj = ipycytoscape.CytoscapeWidget()\n", "cytoscapeobj.graph.add_graph_from_json(json_file)\n", "cytoscapeobj.set_style(s)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Setting the tooltip text\n", "\n", "You can control what shows up in the tooltip when you click on a node with the `tooltip_source` attribute. By default the widget will look for `data['tooltip']` and if that exists use it as the text for the tooltip. Using the `set_tooltip_source` function you can choose to use other attributes, here we use `'name'` " ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [], "source": [ "cytoscapeobj.set_tooltip_source('name')" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [], "source": [ "cytoscapeobj.set_layout(name = 'cola',\n", " nodeSpacing = 5,\n", " edgeLengthVal = 45,\n", " animate = True,\n", " randomize = False,\n", " maxSimulationTime = 1500)" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "9c181d602a7741b1b3ce522b013998e5", "version_major": 2, "version_minor": 0 }, "text/plain": [ "CytoscapeWidget(cytoscape_layout={'name': 'cola', 'nodeSpacing': 5, 'edgeLengthVal': 45, 'animate': True, 'ran…" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "cytoscapeobj" ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "{'name': 'cola',\n", " 'nodeSpacing': 100,\n", " 'edgeLengthVal': 45,\n", " 'animate': True,\n", " 'randomize': False,\n", " 'maxSimulationTime': 1500}" ] }, "execution_count": 7, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# edits graph directly \n", "\n", "cytoscapeobj.set_layout(nodeSpacing=100)\n", "cytoscapeobj.get_layout()" ] }, { "cell_type": "code", "execution_count": 8, "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "8116b4121ceb497d9aa165e816994632", "version_major": 2, "version_minor": 0 }, "text/plain": [ "IntSlider(value=100)" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "0d6b0cda664b4f69bdf838cd566986aa", "version_major": 2, "version_minor": 0 }, "text/plain": [ "Output()" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "# connects a slider to the nodeSpacing of the graph\n", "\n", "import ipywidgets as widgets\n", "\n", "node_range = widgets.IntSlider(value=100)\n", "output = widgets.Output()\n", "display(node_range, output)\n", "\n", "def on_value_change(change):\n", " with output:\n", " cytoscapeobj.set_layout(nodeSpacing = node_range.value)\n", " cytoscapeobj.get_layout()\n", "\n", "node_range.observe(on_value_change)\n" ] }, { "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 }