{ "cells": [ { "celltype": "markdown", "metadata": {}, "source": [ "pegraph-evcxr allows you to display petgraph graphs in jupyter\n", "---------------------------------------------------------------\n", "\n", "github author Timothy Hobbs crates.io" ] }, { "celltype": "code", "executioncount": 2, "metadata": {}, "outputs": [], "source": [ ":dep petgraph = \"*\"\n", ":dep petgraph-evcxr = \"*\"" ] }, { "celltype": "code", "executioncount": 3, "metadata": {}, "outputs": [ { "ename": "Error", "evalue": "unresolved import petgraph_evcxr::draw_graph_with_attr_getters", "outputtype": "error", "traceback": [ "use petgraphevcxr::{drawgraph, drawgraphwithattrgetters, drawdot};", "\u001b[91m ^^^^^^^^^^^^^^^^^^^^^^^^^^^^\u001b[0m \u001b[94mno draw_graph_with_attr_getters in the root\u001b[0m", "unresolved import petgraph_evcxr::draw_graph_with_attr_getters" ] } ], "source": [ "extern crate petgraph;\n", "use petgraph::graph::Graph;\n", "use petgraph::dot::Dot;\n", "use petgraphevcxr::{drawgraph, drawgraphwithattrgetters, drawdot};" ] }, { "celltype": "markdown", "metadata": {}, "source": [ "You draw graphs using the draw_graph function." ] }, { "celltype": "code", "executioncount": 4, "metadata": {}, "outputs": [ { "ename": "Error", "evalue": "failed to resolve: use of undeclared type or module Graph", "outputtype": "error", "traceback": [ "let mut g : Graph<&str, &str> = Graph::new();", "\u001b[91m ^^^^^\u001b[0m \u001b[94muse of undeclared type or module Graph\u001b[0m", "failed to resolve: use of undeclared type or module Graph" ] }, { "ename": "Error", "evalue": "cannot find type Graph in this scope", "outputtype": "error", "traceback": [ "let mut g : Graph<&str, &str> = Graph::new();", "\u001b[91m ^^^^^\u001b[0m \u001b[94mnot found in this scope\u001b[0m", "cannot find type Graph in this scope" ] }, { "ename": "Error", "evalue": "cannot find function draw_graph in this scope", "outputtype": "error", "traceback": [ "drawgraph(&g);", "\u001b[91m^^^^^^^^^^\u001b[0m \u001b[94mnot found in this scope\u001b[0m", "cannot find function draw_graph in this scope" ] } ], "source": [ "let mut g : Graph<&str, &str> = Graph::new();\n", "let a = g.addnode(\"a\");\n", "let b = g.addnode(\"b\");\n", "g.addedge(a, b, \"a to b\");\n", "drawgraph(&g);" ] }, { "celltype": "code", "executioncount": 5, "metadata": {}, "outputs": [ { "ename": "Error", "evalue": "cannot find function draw_graph_with_attr_getters in this scope", "outputtype": "error", "traceback": [ "drawgraphwithattrgetters(", "\u001b[91m^^^^^^^^^^^^^^^^^^^^^^^^^^^^\u001b[0m \u001b[94mnot found in this scope\u001b[0m", "cannot find function draw_graph_with_attr_getters in this scope" ] }, { "ename": "Error", "evalue": "cannot find value g in this scope", "outputtype": "error", "traceback": [ " &g,", "\u001b[91m ^\u001b[0m \u001b[94mnot found in this scope\u001b[0m", "cannot find value g in this scope" ] }, { "ename": "Error", "evalue": "expected value, found module self", "outputtype": "error", "traceback": [ " (if nr.id() == self.state {", "\u001b[91m ^^^^\u001b[0m \u001b[94mself value is a keyword only available in methods with a self parameter\u001b[0m", " &|, nr| {", " (if nr.id() == self.state {", " \"shape = circle style = filled fillcolor = red\"", " } else {", " \"shape = circle\"", " }).tostring()", " },", "\u001b[91m \u001b[0m \u001b[94mthis function doesn't have a self parameter\u001b[0m", "expected value, found module self" ] } ], "source": [ "drawgraphwithattrgetters(\n", " &g,\n", " &[],\n", " &|, _| \"\".tostring(),\n", " &|, nr| {\n", " (if nr.id() == self.state {\n", " \"shape = circle style = filled fillcolor = red\"\n", " } else {\n", " \"shape = circle\"\n", " }).tostring()\n", " },\n", ");" ] }, { "celltype": "markdown", "metadata": {}, "source": [ "You can also draw dot code directly using the draw_dot function." ] }, { "celltype": "code", "executioncount": 6, "metadata": {}, "outputs": [ { "ename": "Error", "evalue": "cannot find function draw_dot in this scope", "outputtype": "error", "traceback": [ "drawdot(dot);", "\u001b[91m^^^^^^^^\u001b[0m \u001b[94mnot found in this scope\u001b[0m", "cannot find function draw_dot in this scope" ] } ], "source": [ "let dot = \"digraph {\\n", " 0 [label=\\"a\\"]\\n", " 1 [label=\\"b\\"]\\n", " 0 -> 1 [label=\\"a → b\\"]\\n", "}\";\n", "drawdot(dot);" ] } ], "metadata": { "kernelspec": { "displayname": "Rust", "language": "rust", "name": "rust" }, "languageinfo": { "codemirrormode": "rust", "fileextension": ".rs", "mimetype": "text/rust", "name": "Rust", "pygmentlexer": "rust", "version": "" } }, "nbformat": 4, "nbformatminor": 2 }