{ "cells": [ { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import ipycytoscape" ] }, { "cell_type": "code", "execution_count": null, "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": null, "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": null, "metadata": {}, "outputs": [], "source": [ "cytoscapeobj.set_tooltip_source('name')" ] }, { "cell_type": "code", "execution_count": null, "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": null, "metadata": {}, "outputs": [], "source": [ "cytoscapeobj" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# edits graph directly \n", "\n", "cytoscapeobj.set_layout(nodeSpacing=100)\n", "cytoscapeobj.get_layout()" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# connects a slider to the nodeSpacing of the graph\n", "\n", "import ipywidgets as widgets\n", "\n", "node_range = widgets.IntSlider()\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" ] } ], "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.8.2" } }, "nbformat": 4, "nbformat_minor": 4 }