From bb2861f7a51d5f396fc5de281014c0abbffe173b Mon Sep 17 00:00:00 2001 From: Mykel Kochenderfer Date: Sun, 4 Feb 2018 18:06:20 -0800 Subject: [PATCH] add passing of options to tikzpictures; ref #21 --- doc/TikzGraphs.ipynb | 520 +++++++++++++++++++++++-------------------- src/TikzGraphs.jl | 10 +- 2 files changed, 286 insertions(+), 244 deletions(-) diff --git a/doc/TikzGraphs.ipynb b/doc/TikzGraphs.ipynb index 24b8640..717004a 100644 --- a/doc/TikzGraphs.ipynb +++ b/doc/TikzGraphs.ipynb @@ -24,9 +24,7 @@ { "cell_type": "code", "execution_count": null, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [], "source": [ "Pkg.add(\"TikzGraphs\")" @@ -46,9 +44,7 @@ { "cell_type": "code", "execution_count": 1, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [], "source": [ "using TikzGraphs" @@ -64,9 +60,7 @@ { "cell_type": "code", "execution_count": 2, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [ { "data": { @@ -75,19 +69,19 @@ "\n", "\n", "\n", - "\n", + "\n", "\n", "\n", - "\n", + "\n", "\n", "\n", - "\n", + "\n", "\n", "\n", - "\n", + "\n", "\n", "\n", - "\n", + "\n", "\n", "\n", "\n", @@ -98,23 +92,23 @@ "\n", "\n", "\n", - " \n", + " \n", "\n", "\n", - " \n", + " \n", "\n", "\n", - " \n", + " \n", "\n", "\n", - " \n", + " \n", "\n", "\n", "\n", "\n" ], "text/plain": [ - "TikzPictures.TikzPicture(\"\\\\graph [layered layout, ] {\\n1/\\\"1\\\" [],\\n2/\\\"2\\\" [],\\n3/\\\"3\\\" [],\\n4/\\\"4\\\" [],\\n;\\n1 -> [,] 2;\\n2 -> [,] 3;\\n};\\n\",\"\",\"\\\\usepackage{fontspec}\\r\\n\\\\setmainfont{Latin Modern Math}\\r\\n\\\\usetikzlibrary{graphs}\\r\\n\\\\usetikzlibrary{graphdrawing}\\r\\n\\n\\\\usegdlibrary{layered}\",true,true)" + "TikzPictures.TikzPicture(\"\\\\graph [layered layout, ] {\\n1/\\\"1\\\" [],\\n2/\\\"2\\\" [],\\n3/\\\"3\\\" [],\\n4/\\\"4\\\" [],\\n;\\n1 -> [,] 2;\\n2 -> [,] 3;\\n};\\n\", \"\", \"\\\\usepackage{fontspec}\\r\\n\\\\setmainfont{Latin Modern Math}\\r\\n\\\\usetikzlibrary{graphs}\\r\\n\\\\usetikzlibrary{graphdrawing}\\r\\n\\n\\\\usegdlibrary{layered}\", true, true)" ] }, "execution_count": 2, @@ -134,9 +128,7 @@ { "cell_type": "code", "execution_count": 3, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [ { "data": { @@ -145,19 +137,19 @@ "\n", "\n", "\n", - "\n", + "\n", "\n", "\n", - "\n", + "\n", "\n", "\n", - "\n", + "\n", "\n", "\n", - "\n", + "\n", "\n", "\n", - "\n", + "\n", "\n", "\n", "\n", @@ -172,23 +164,23 @@ "\n", "\n", "\n", - " \n", + " \n", "\n", "\n", - " \n", + " \n", "\n", "\n", - " \n", + " \n", "\n", "\n", - " \n", + " \n", "\n", "\n", "\n", "\n" ], "text/plain": [ - "TikzPictures.TikzPicture(\"\\\\graph [layered layout, ] {\\n1/\\\"1\\\" [],\\n2/\\\"2\\\" [],\\n3/\\\"3\\\" [],\\n4/\\\"4\\\" [],\\n;\\n1 -> [,] 2;\\n1 -> [,] 4;\\n2 -> [,] 3;\\n3 -> [,] 4;\\n};\\n\",\"\",\"\\\\usepackage{fontspec}\\r\\n\\\\setmainfont{Latin Modern Math}\\r\\n\\\\usetikzlibrary{graphs}\\r\\n\\\\usetikzlibrary{graphdrawing}\\r\\n\\n\\\\usegdlibrary{layered}\",true,true)" + "TikzPictures.TikzPicture(\"\\\\graph [layered layout, ] {\\n1/\\\"1\\\" [],\\n2/\\\"2\\\" [],\\n3/\\\"3\\\" [],\\n4/\\\"4\\\" [],\\n;\\n1 -> [,] 2;\\n1 -> [,] 4;\\n2 -> [,] 3;\\n3 -> [,] 4;\\n};\\n\", \"\", \"\\\\usepackage{fontspec}\\r\\n\\\\setmainfont{Latin Modern Math}\\r\\n\\\\usetikzlibrary{graphs}\\r\\n\\\\usetikzlibrary{graphdrawing}\\r\\n\\n\\\\usegdlibrary{layered}\", true, true)" ] }, "execution_count": 3, @@ -212,9 +204,7 @@ { "cell_type": "code", "execution_count": 4, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [], "source": [ "t = TikzGraphs.plot(g)\n", @@ -241,9 +231,7 @@ { "cell_type": "code", "execution_count": 5, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [ { "data": { @@ -252,19 +240,19 @@ "\n", "\n", "\n", - "\n", + "\n", "\n", "\n", - "\n", + "\n", "\n", "\n", - "\n", + "\n", "\n", "\n", - "\n", + "\n", "\n", "\n", - "\n", + "\n", "\n", "\n", "\n", @@ -279,23 +267,23 @@ "\n", "\n", "\n", - " \n", + " \n", "\n", "\n", - " \n", + " \n", "\n", "\n", - " \n", + " \n", "\n", "\n", - " \n", + " \n", "\n", "\n", "\n", "\n" ], "text/plain": [ - "TikzPictures.TikzPicture(\"\\\\graph [layered layout, ] {\\n1/\\\"A\\\" [],\\n2/\\\"B\\\" [],\\n3/\\\"C\\\" [],\\n4/\\\"D\\\" [],\\n;\\n1 -> [,] 2;\\n1 -> [,] 4;\\n2 -> [,] 3;\\n3 -> [,] 4;\\n};\\n\",\"\",\"\\\\usepackage{fontspec}\\r\\n\\\\setmainfont{Latin Modern Math}\\r\\n\\\\usetikzlibrary{graphs}\\r\\n\\\\usetikzlibrary{graphdrawing}\\r\\n\\n\\\\usegdlibrary{layered}\",true,true)" + "TikzPictures.TikzPicture(\"\\\\graph [layered layout, ] {\\n1/\\\"A\\\" [],\\n2/\\\"B\\\" [],\\n3/\\\"C\\\" [],\\n4/\\\"D\\\" [],\\n;\\n1 -> [,] 2;\\n1 -> [,] 4;\\n2 -> [,] 3;\\n3 -> [,] 4;\\n};\\n\", \"\", \"\\\\usepackage{fontspec}\\r\\n\\\\setmainfont{Latin Modern Math}\\r\\n\\\\usetikzlibrary{graphs}\\r\\n\\\\usetikzlibrary{graphdrawing}\\r\\n\\n\\\\usegdlibrary{layered}\", true, true)" ] }, "execution_count": 5, @@ -317,9 +305,7 @@ { "cell_type": "code", "execution_count": 6, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [ { "data": { @@ -328,19 +314,19 @@ "\n", "\n", "\n", - "\n", + "\n", "\n", "\n", - "\n", + "\n", "\n", "\n", - "\n", + "\n", "\n", "\n", - "\n", + "\n", "\n", "\n", - "\n", + "\n", "\n", "\n", "\n", @@ -355,23 +341,23 @@ "\n", "\n", "\n", - " \n", + " \n", "\n", "\n", - " \n", + " \n", "\n", "\n", - " \n", + " \n", "\n", "\n", - " \n", + " \n", "\n", "\n", "\n", "\n" ], "text/plain": [ - "TikzPictures.TikzPicture(\"\\\\graph [layered layout, ] {\\n1/\\\"α\\\" [],\\n2/\\\"β\\\" [],\\n3/\\\"γ\\\" [],\\n4/\\\"δ\\\" [],\\n;\\n1 -> [,] 2;\\n1 -> [,] 4;\\n2 -> [,] 3;\\n3 -> [,] 4;\\n};\\n\",\"\",\"\\\\usepackage{fontspec}\\r\\n\\\\setmainfont{Latin Modern Math}\\r\\n\\\\usetikzlibrary{graphs}\\r\\n\\\\usetikzlibrary{graphdrawing}\\r\\n\\n\\\\usegdlibrary{layered}\",true,true)" + "TikzPictures.TikzPicture(\"\\\\graph [layered layout, ] {\\n1/\\\"α\\\" [],\\n2/\\\"β\\\" [],\\n3/\\\"γ\\\" [],\\n4/\\\"δ\\\" [],\\n;\\n1 -> [,] 2;\\n1 -> [,] 4;\\n2 -> [,] 3;\\n3 -> [,] 4;\\n};\\n\", \"\", \"\\\\usepackage{fontspec}\\r\\n\\\\setmainfont{Latin Modern Math}\\r\\n\\\\usetikzlibrary{graphs}\\r\\n\\\\usetikzlibrary{graphdrawing}\\r\\n\\n\\\\usegdlibrary{layered}\", true, true)" ] }, "execution_count": 6, @@ -393,9 +379,7 @@ { "cell_type": "code", "execution_count": 7, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [ { "data": { @@ -404,58 +388,58 @@ "\n", "\n", "\n", - "\n", + "\n", "\n", "\n", - "\n", + "\n", "\n", "\n", - "\n", + "\n", "\n", "\n", - "\n", + "\n", "\n", "\n", - "\n", + "\n", "\n", "\n", - "\n", + "\n", "\n", "\n", - "\n", + "\n", "\n", "\n", - "\n", + "\n", "\n", "\n", - "\n", + "\n", "\n", "\n", - "\n", + "\n", "\n", "\n", - "\n", + "\n", "\n", "\n", - "\n", + "\n", "\n", "\n", - "\n", + "\n", "\n", "\n", - "\n", + "\n", "\n", "\n", - "\n", + "\n", "\n", "\n", - "\n", + "\n", "\n", "\n", - "\n", + "\n", "\n", "\n", - "\n", + "\n", "\n", "\n", "\n", @@ -470,56 +454,56 @@ "\n", "\n", "\n", - " \n", + " \n", "\n", "\n", - " \n", + " \n", "\n", "\n", - " \n", + " \n", "\n", "\n", - " \n", + " \n", "\n", "\n", - " \n", + " \n", "\n", "\n", - " \n", + " \n", "\n", "\n", - " \n", + " \n", "\n", "\n", - " \n", - " \n", + " \n", + " \n", "\n", "\n", - " \n", + " \n", "\n", "\n", "\n", - " \n", + " \n", "\n", "\n", - " \n", + " \n", "\n", "\n", - " \n", + " \n", "\n", "\n", - " \n", + " \n", "\n", "\n", "\n", - " \n", + " \n", "\n", "\n", "\n", "\n" ], "text/plain": [ - "TikzPictures.TikzPicture(\"\\\\graph [layered layout, ] {\\n1/\\\"\\$\\\\int_0^\\\\infty f(x) dx\\$\\\" [],\\n2/\\\"\\$\\\\sqrt{2}\\$\\\" [],\\n3/\\\"\\$x^2\\$\\\" [],\\n4/\\\"\\$\\\\frac{1}{2}\\$\\\" [],\\n;\\n1 -> [,] 2;\\n1 -> [,] 4;\\n2 -> [,] 3;\\n3 -> [,] 4;\\n};\\n\",\"\",\"\\\\usepackage{fontspec}\\r\\n\\\\setmainfont{Latin Modern Math}\\r\\n\\\\usetikzlibrary{graphs}\\r\\n\\\\usetikzlibrary{graphdrawing}\\r\\n\\n\\\\usegdlibrary{layered}\",true,true)" + "TikzPictures.TikzPicture(\"\\\\graph [layered layout, ] {\\n1/\\\"\\$\\\\int_0^\\\\infty f(x) dx\\$\\\" [],\\n2/\\\"\\$\\\\sqrt{2}\\$\\\" [],\\n3/\\\"\\$x^2\\$\\\" [],\\n4/\\\"\\$\\\\frac{1}{2}\\$\\\" [],\\n;\\n1 -> [,] 2;\\n1 -> [,] 4;\\n2 -> [,] 3;\\n3 -> [,] 4;\\n};\\n\", \"\", \"\\\\usepackage{fontspec}\\r\\n\\\\setmainfont{Latin Modern Math}\\r\\n\\\\usetikzlibrary{graphs}\\r\\n\\\\usetikzlibrary{graphdrawing}\\r\\n\\n\\\\usegdlibrary{layered}\", true, true)" ] }, "execution_count": 7, @@ -541,9 +525,7 @@ { "cell_type": "code", "execution_count": 8, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [ { "data": { @@ -552,16 +534,16 @@ "\n", "\n", "\n", - "\n", + "\n", "\n", "\n", - "\n", + "\n", "\n", "\n", - "\n", + "\n", "\n", "\n", - "\n", + "\n", "\n", "\n", "\n", @@ -576,23 +558,23 @@ "\n", "\n", "\n", - " \n", + " \n", "\n", "\n", - " \n", + " \n", "\n", "\n", - " \n", + " \n", "\n", "\n", - " \n", + " \n", "\n", "\n", "\n", "\n" ], "text/plain": [ - "TikzPictures.TikzPicture(\"\\\\graph [layered layout, ] {\\n1/\\\"α\\\" [],\\n2/\\\"β\\\" [],\\n3/\\\"γ\\\" [],\\n4/\\\"α\\\" [],\\n;\\n1 -> [,] 2;\\n1 -> [,] 4;\\n2 -> [,] 3;\\n3 -> [,] 4;\\n};\\n\",\"\",\"\\\\usepackage{fontspec}\\r\\n\\\\setmainfont{Latin Modern Math}\\r\\n\\\\usetikzlibrary{graphs}\\r\\n\\\\usetikzlibrary{graphdrawing}\\r\\n\\n\\\\usegdlibrary{layered}\",true,true)" + "TikzPictures.TikzPicture(\"\\\\graph [layered layout, ] {\\n1/\\\"α\\\" [],\\n2/\\\"β\\\" [],\\n3/\\\"γ\\\" [],\\n4/\\\"α\\\" [],\\n;\\n1 -> [,] 2;\\n1 -> [,] 4;\\n2 -> [,] 3;\\n3 -> [,] 4;\\n};\\n\", \"\", \"\\\\usepackage{fontspec}\\r\\n\\\\setmainfont{Latin Modern Math}\\r\\n\\\\usetikzlibrary{graphs}\\r\\n\\\\usetikzlibrary{graphdrawing}\\r\\n\\n\\\\usegdlibrary{layered}\", true, true)" ] }, "execution_count": 8, @@ -614,9 +596,7 @@ { "cell_type": "code", "execution_count": 9, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [ { "data": { @@ -625,16 +605,16 @@ "\n", "\n", "\n", - "\n", + "\n", "\n", "\n", - "\n", + "\n", "\n", "\n", - "\n", + "\n", "\n", "\n", - "\n", + "\n", "\n", "\n", "\n", @@ -650,26 +630,26 @@ "\n", "\n", "\n", - " \n", + " \n", "\n", "\n", "\n", - " \n", + " \n", "\n", "\n", "\n", - " \n", + " \n", "\n", "\n", "\n", - " \n", + " \n", "\n", "\n", "\n", "\n" ], "text/plain": [ - "TikzPictures.TikzPicture(\"\\\\graph [layered layout, ] {\\n1/\\\"α\\\" [draw, rounded corners, fill=blue!10],\\n2/\\\"β\\\" [draw, rounded corners, fill=blue!10],\\n3/\\\"γ\\\" [draw, rounded corners, fill=blue!10],\\n4/\\\"α\\\" [draw, rounded corners, fill=blue!10],\\n;\\n1 -> [,] 2;\\n1 -> [,] 4;\\n2 -> [,] 3;\\n3 -> [,] 4;\\n};\\n\",\"\",\"\\\\usepackage{fontspec}\\r\\n\\\\setmainfont{Latin Modern Math}\\r\\n\\\\usetikzlibrary{graphs}\\r\\n\\\\usetikzlibrary{graphdrawing}\\r\\n\\n\\\\usegdlibrary{layered}\",true,true)" + "TikzPictures.TikzPicture(\"\\\\graph [layered layout, ] {\\n1/\\\"α\\\" [draw, rounded corners, fill=blue!10],\\n2/\\\"β\\\" [draw, rounded corners, fill=blue!10],\\n3/\\\"γ\\\" [draw, rounded corners, fill=blue!10],\\n4/\\\"α\\\" [draw, rounded corners, fill=blue!10],\\n;\\n1 -> [,] 2;\\n1 -> [,] 4;\\n2 -> [,] 3;\\n3 -> [,] 4;\\n};\\n\", \"\", \"\\\\usepackage{fontspec}\\r\\n\\\\setmainfont{Latin Modern Math}\\r\\n\\\\usetikzlibrary{graphs}\\r\\n\\\\usetikzlibrary{graphdrawing}\\r\\n\\n\\\\usegdlibrary{layered}\", true, true)" ] }, "execution_count": 9, @@ -691,9 +671,7 @@ { "cell_type": "code", "execution_count": 10, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [ { "data": { @@ -702,16 +680,16 @@ "\n", "\n", "\n", - "\n", + "\n", "\n", "\n", - "\n", + "\n", "\n", "\n", - "\n", + "\n", "\n", "\n", - "\n", + "\n", "\n", "\n", "\n", @@ -727,26 +705,26 @@ "\n", "\n", "\n", - " \n", + " \n", "\n", "\n", "\n", - " \n", + " \n", "\n", "\n", "\n", - " \n", + " \n", "\n", "\n", "\n", - " \n", + " \n", "\n", "\n", "\n", "\n" ], "text/plain": [ - "TikzPictures.TikzPicture(\"\\\\graph [layered layout, ] {\\n1/\\\"α\\\" [draw, rounded corners, fill=blue!10,fill=green!10],\\n2/\\\"β\\\" [draw, rounded corners, fill=blue!10],\\n3/\\\"γ\\\" [draw, rounded corners, fill=blue!10,fill=yellow!10],\\n4/\\\"α\\\" [draw, rounded corners, fill=blue!10],\\n;\\n1 -> [,] 2;\\n1 -> [,] 4;\\n2 -> [,] 3;\\n3 -> [,] 4;\\n};\\n\",\"\",\"\\\\usepackage{fontspec}\\r\\n\\\\setmainfont{Latin Modern Math}\\r\\n\\\\usetikzlibrary{graphs}\\r\\n\\\\usetikzlibrary{graphdrawing}\\r\\n\\n\\\\usegdlibrary{layered}\",true,true)" + "TikzPictures.TikzPicture(\"\\\\graph [layered layout, ] {\\n1/\\\"α\\\" [draw, rounded corners, fill=blue!10,fill=green!10],\\n2/\\\"β\\\" [draw, rounded corners, fill=blue!10],\\n3/\\\"γ\\\" [draw, rounded corners, fill=blue!10,fill=yellow!10],\\n4/\\\"α\\\" [draw, rounded corners, fill=blue!10],\\n;\\n1 -> [,] 2;\\n1 -> [,] 4;\\n2 -> [,] 3;\\n3 -> [,] 4;\\n};\\n\", \"\", \"\\\\usepackage{fontspec}\\r\\n\\\\setmainfont{Latin Modern Math}\\r\\n\\\\usetikzlibrary{graphs}\\r\\n\\\\usetikzlibrary{graphdrawing}\\r\\n\\n\\\\usegdlibrary{layered}\", true, true)" ] }, "execution_count": 10, @@ -775,9 +753,7 @@ { "cell_type": "code", "execution_count": 11, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [ { "data": { @@ -786,22 +762,22 @@ "\n", "\n", "\n", - "\n", + "\n", "\n", "\n", - "\n", + "\n", "\n", "\n", - "\n", + "\n", "\n", "\n", - "\n", + "\n", "\n", "\n", - "\n", + "\n", "\n", "\n", - "\n", + "\n", "\n", "\n", "\n", @@ -810,35 +786,35 @@ "\n", "\n", "\n", - " \n", + " \n", "\n", "\n", "\n", "\n", - " \n", + " \n", "\n", "\n", "\n", "\n", "\n", "\n", - " \n", + " \n", "\n", "\n", - " \n", + " \n", "\n", "\n", - " \n", + " \n", "\n", "\n", - " \n", + " \n", "\n", "\n", "\n", "\n" ], "text/plain": [ - "TikzPictures.TikzPicture(\"\\\\graph [layered layout, ] {\\n1/\\\"α\\\" [],\\n2/\\\"β\\\" [],\\n3/\\\"γ\\\" [],\\n4/\\\"α\\\" [],\\n;\\n1 -> [,edge label={x},] 2;\\n1 -> [,edge label={y},] 4;\\n2 -> [,] 3;\\n3 -> [,] 4;\\n};\\n\",\"\",\"\\\\usepackage{fontspec}\\r\\n\\\\setmainfont{Latin Modern Math}\\r\\n\\\\usetikzlibrary{graphs}\\r\\n\\\\usetikzlibrary{graphdrawing}\\r\\n\\n\\\\usegdlibrary{layered}\",true,true)" + "TikzPictures.TikzPicture(\"\\\\graph [layered layout, ] {\\n1/\\\"α\\\" [],\\n2/\\\"β\\\" [],\\n3/\\\"γ\\\" [],\\n4/\\\"α\\\" [],\\n;\\n1 -> [,edge label={x},] 2;\\n1 -> [,edge label={y},] 4;\\n2 -> [,] 3;\\n3 -> [,] 4;\\n};\\n\", \"\", \"\\\\usepackage{fontspec}\\r\\n\\\\setmainfont{Latin Modern Math}\\r\\n\\\\usetikzlibrary{graphs}\\r\\n\\\\usetikzlibrary{graphdrawing}\\r\\n\\n\\\\usegdlibrary{layered}\", true, true)" ] }, "execution_count": 11, @@ -860,9 +836,7 @@ { "cell_type": "code", "execution_count": 12, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [ { "data": { @@ -871,22 +845,22 @@ "\n", "\n", "\n", - "\n", + "\n", "\n", "\n", - "\n", + "\n", "\n", "\n", - "\n", + "\n", "\n", "\n", - "\n", + "\n", "\n", "\n", - "\n", + "\n", "\n", "\n", - "\n", + "\n", "\n", "\n", "\n", @@ -895,35 +869,35 @@ "\n", "\n", "\n", - " \n", + " \n", "\n", "\n", "\n", "\n", - " \n", + " \n", "\n", "\n", "\n", "\n", "\n", "\n", - " \n", + " \n", "\n", "\n", - " \n", + " \n", "\n", "\n", - " \n", + " \n", "\n", "\n", - " \n", + " \n", "\n", "\n", "\n", "\n" ], "text/plain": [ - "TikzPictures.TikzPicture(\"\\\\graph [layered layout, ] {\\n1/\\\"α\\\" [],\\n2/\\\"β\\\" [],\\n3/\\\"γ\\\" [],\\n4/\\\"α\\\" [],\\n;\\n1 -> [green,edge label={x},] 2;\\n1 -> [green,edge label={y},] 4;\\n2 -> [green,] 3;\\n3 -> [green,] 4;\\n};\\n\",\"\",\"\\\\usepackage{fontspec}\\r\\n\\\\setmainfont{Latin Modern Math}\\r\\n\\\\usetikzlibrary{graphs}\\r\\n\\\\usetikzlibrary{graphdrawing}\\r\\n\\n\\\\usegdlibrary{layered}\",true,true)" + "TikzPictures.TikzPicture(\"\\\\graph [layered layout, ] {\\n1/\\\"α\\\" [],\\n2/\\\"β\\\" [],\\n3/\\\"γ\\\" [],\\n4/\\\"α\\\" [],\\n;\\n1 -> [green,edge label={x},] 2;\\n1 -> [green,edge label={y},] 4;\\n2 -> [green,] 3;\\n3 -> [green,] 4;\\n};\\n\", \"\", \"\\\\usepackage{fontspec}\\r\\n\\\\setmainfont{Latin Modern Math}\\r\\n\\\\usetikzlibrary{graphs}\\r\\n\\\\usetikzlibrary{graphdrawing}\\r\\n\\n\\\\usegdlibrary{layered}\", true, true)" ] }, "execution_count": 12, @@ -945,9 +919,7 @@ { "cell_type": "code", "execution_count": 13, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [ { "data": { @@ -956,25 +928,25 @@ "\n", "\n", "\n", - "\n", + "\n", "\n", "\n", - "\n", + "\n", "\n", "\n", - "\n", + "\n", "\n", "\n", - "\n", + "\n", "\n", "\n", - "\n", + "\n", "\n", "\n", - "\n", + "\n", "\n", "\n", - "\n", + "\n", "\n", "\n", "\n", @@ -983,35 +955,35 @@ "\n", "\n", "\n", - " \n", + " \n", "\n", "\n", "\n", "\n", - " \n", + " \n", "\n", "\n", "\n", "\n", "\n", "\n", - " \n", + " \n", "\n", "\n", - " \n", + " \n", "\n", "\n", - " \n", + " \n", "\n", "\n", - " \n", + " \n", "\n", "\n", "\n", "\n" ], "text/plain": [ - "TikzPictures.TikzPicture(\"\\\\graph [layered layout, ] {\\n1/\\\"1\\\" [],\\n2/\\\"2\\\" [],\\n3/\\\"3\\\" [],\\n4/\\\"4\\\" [],\\n;\\n1 -> [green,edge label={x},blue,] 2;\\n1 -> [green,edge label={y},] 4;\\n2 -> [green,] 3;\\n3 -> [green,] 4;\\n};\\n\",\"\",\"\\\\usepackage{fontspec}\\r\\n\\\\setmainfont{Latin Modern Math}\\r\\n\\\\usetikzlibrary{graphs}\\r\\n\\\\usetikzlibrary{graphdrawing}\\r\\n\\n\\\\usegdlibrary{layered}\",true,true)" + "TikzPictures.TikzPicture(\"\\\\graph [layered layout, ] {\\n1/\\\"1\\\" [],\\n2/\\\"2\\\" [],\\n3/\\\"3\\\" [],\\n4/\\\"4\\\" [],\\n;\\n1 -> [green,edge label={x},blue,] 2;\\n1 -> [green,edge label={y},] 4;\\n2 -> [green,] 3;\\n3 -> [green,] 4;\\n};\\n\", \"\", \"\\\\usepackage{fontspec}\\r\\n\\\\setmainfont{Latin Modern Math}\\r\\n\\\\usetikzlibrary{graphs}\\r\\n\\\\usetikzlibrary{graphdrawing}\\r\\n\\n\\\\usegdlibrary{layered}\", true, true)" ] }, "execution_count": 13, @@ -1040,9 +1012,7 @@ { "cell_type": "code", "execution_count": 14, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [ { "data": { @@ -1051,19 +1021,19 @@ "\n", "\n", "\n", - "\n", + "\n", "\n", "\n", - "\n", + "\n", "\n", "\n", - "\n", + "\n", "\n", "\n", - "\n", + "\n", "\n", "\n", - "\n", + "\n", "\n", "\n", "\n", @@ -1078,23 +1048,23 @@ "\n", "\n", "\n", - " \n", + " \n", "\n", "\n", - " \n", + " \n", "\n", "\n", - " \n", + " \n", "\n", "\n", - " \n", + " \n", "\n", "\n", "\n", "\n" ], "text/plain": [ - "TikzPictures.TikzPicture(\"\\\\graph [layered layout, ] {\\n1/\\\"1\\\" [],\\n2/\\\"2\\\" [],\\n3/\\\"3\\\" [],\\n4/\\\"4\\\" [],\\n;\\n1 -> [,] 2;\\n1 -> [,] 4;\\n2 -> [,] 3;\\n3 -> [,] 4;\\n};\\n\",\"\",\"\\\\usepackage{fontspec}\\r\\n\\\\setmainfont{Latin Modern Math}\\r\\n\\\\usetikzlibrary{graphs}\\r\\n\\\\usetikzlibrary{graphdrawing}\\r\\n\\n\\\\usegdlibrary{layered}\",true,true)" + "TikzPictures.TikzPicture(\"\\\\graph [layered layout, ] {\\n1/\\\"1\\\" [],\\n2/\\\"2\\\" [],\\n3/\\\"3\\\" [],\\n4/\\\"4\\\" [],\\n;\\n1 -> [,] 2;\\n1 -> [,] 4;\\n2 -> [,] 3;\\n3 -> [,] 4;\\n};\\n\", \"\", \"\\\\usepackage{fontspec}\\r\\n\\\\setmainfont{Latin Modern Math}\\r\\n\\\\usetikzlibrary{graphs}\\r\\n\\\\usetikzlibrary{graphdrawing}\\r\\n\\n\\\\usegdlibrary{layered}\", true, true)" ] }, "execution_count": 14, @@ -1109,9 +1079,7 @@ { "cell_type": "code", "execution_count": 15, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [ { "data": { @@ -1120,19 +1088,19 @@ "\n", "\n", "\n", - "\n", + "\n", "\n", "\n", - "\n", + "\n", "\n", "\n", - "\n", + "\n", "\n", "\n", - "\n", + "\n", "\n", "\n", - "\n", + "\n", "\n", "\n", "\n", @@ -1147,23 +1115,23 @@ "\n", "\n", "\n", - " \n", + " \n", "\n", "\n", - " \n", + " \n", "\n", "\n", - " \n", + " \n", "\n", "\n", - " \n", + " \n", "\n", "\n", "\n", "\n" ], "text/plain": [ - "TikzPictures.TikzPicture(\"\\\\graph [spring layout, random seed = 42] {\\n1/\\\"1\\\" [],\\n2/\\\"2\\\" [],\\n3/\\\"3\\\" [],\\n4/\\\"4\\\" [],\\n;\\n1 -> [,] 2;\\n1 -> [,] 4;\\n2 -> [,] 3;\\n3 -> [,] 4;\\n};\\n\",\"\",\"\\\\usepackage{fontspec}\\r\\n\\\\setmainfont{Latin Modern Math}\\r\\n\\\\usetikzlibrary{graphs}\\r\\n\\\\usetikzlibrary{graphdrawing}\\r\\n\\n\\\\usegdlibrary{force}\",true,true)" + "TikzPictures.TikzPicture(\"\\\\graph [spring layout, random seed = 42] {\\n1/\\\"1\\\" [],\\n2/\\\"2\\\" [],\\n3/\\\"3\\\" [],\\n4/\\\"4\\\" [],\\n;\\n1 -> [,] 2;\\n1 -> [,] 4;\\n2 -> [,] 3;\\n3 -> [,] 4;\\n};\\n\", \"\", \"\\\\usepackage{fontspec}\\r\\n\\\\setmainfont{Latin Modern Math}\\r\\n\\\\usetikzlibrary{graphs}\\r\\n\\\\usetikzlibrary{graphdrawing}\\r\\n\\n\\\\usegdlibrary{force}\", true, true)" ] }, "execution_count": 15, @@ -1185,9 +1153,7 @@ { "cell_type": "code", "execution_count": 16, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [ { "data": { @@ -1196,19 +1162,19 @@ "\n", "\n", "\n", - "\n", + "\n", "\n", "\n", - "\n", + "\n", "\n", "\n", - "\n", + "\n", "\n", "\n", - "\n", + "\n", "\n", "\n", - "\n", + "\n", "\n", "\n", "\n", @@ -1223,23 +1189,23 @@ "\n", "\n", "\n", - " \n", + " \n", "\n", "\n", - " \n", + " \n", "\n", "\n", - " \n", + " \n", "\n", "\n", - " \n", + " \n", "\n", "\n", "\n", "\n" ], "text/plain": [ - "TikzPictures.TikzPicture(\"\\\\graph [spring layout, random seed = 52] {\\n1/\\\"1\\\" [],\\n2/\\\"2\\\" [],\\n3/\\\"3\\\" [],\\n4/\\\"4\\\" [],\\n;\\n1 -> [,] 2;\\n1 -> [,] 4;\\n2 -> [,] 3;\\n3 -> [,] 4;\\n};\\n\",\"\",\"\\\\usepackage{fontspec}\\r\\n\\\\setmainfont{Latin Modern Math}\\r\\n\\\\usetikzlibrary{graphs}\\r\\n\\\\usetikzlibrary{graphdrawing}\\r\\n\\n\\\\usegdlibrary{force}\",true,true)" + "TikzPictures.TikzPicture(\"\\\\graph [spring layout, random seed = 52] {\\n1/\\\"1\\\" [],\\n2/\\\"2\\\" [],\\n3/\\\"3\\\" [],\\n4/\\\"4\\\" [],\\n;\\n1 -> [,] 2;\\n1 -> [,] 4;\\n2 -> [,] 3;\\n3 -> [,] 4;\\n};\\n\", \"\", \"\\\\usepackage{fontspec}\\r\\n\\\\setmainfont{Latin Modern Math}\\r\\n\\\\usetikzlibrary{graphs}\\r\\n\\\\usetikzlibrary{graphdrawing}\\r\\n\\n\\\\usegdlibrary{force}\", true, true)" ] }, "execution_count": 16, @@ -1254,9 +1220,7 @@ { "cell_type": "code", "execution_count": 17, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [ { "data": { @@ -1265,19 +1229,19 @@ "\n", "\n", "\n", - "\n", + "\n", "\n", "\n", - "\n", + "\n", "\n", "\n", - "\n", + "\n", "\n", "\n", - "\n", + "\n", "\n", "\n", - "\n", + "\n", "\n", "\n", "\n", @@ -1292,23 +1256,23 @@ "\n", "\n", "\n", - " \n", + " \n", "\n", "\n", - " \n", + " \n", "\n", "\n", - " \n", + " \n", "\n", "\n", - " \n", + " \n", "\n", "\n", "\n", "\n" ], "text/plain": [ - "TikzPictures.TikzPicture(\"\\\\graph [simple necklace layout, ] {\\n1/\\\"1\\\" [],\\n2/\\\"2\\\" [],\\n3/\\\"3\\\" [],\\n4/\\\"4\\\" [],\\n;\\n1 -> [,] 2;\\n1 -> [,] 4;\\n2 -> [,] 3;\\n3 -> [,] 4;\\n};\\n\",\"\",\"\\\\usepackage{fontspec}\\r\\n\\\\setmainfont{Latin Modern Math}\\r\\n\\\\usetikzlibrary{graphs}\\r\\n\\\\usetikzlibrary{graphdrawing}\\r\\n\\n\\\\usegdlibrary{circular}\",true,true)" + "TikzPictures.TikzPicture(\"\\\\graph [simple necklace layout, ] {\\n1/\\\"1\\\" [],\\n2/\\\"2\\\" [],\\n3/\\\"3\\\" [],\\n4/\\\"4\\\" [],\\n;\\n1 -> [,] 2;\\n1 -> [,] 4;\\n2 -> [,] 3;\\n3 -> [,] 4;\\n};\\n\", \"\", \"\\\\usepackage{fontspec}\\r\\n\\\\setmainfont{Latin Modern Math}\\r\\n\\\\usetikzlibrary{graphs}\\r\\n\\\\usetikzlibrary{graphdrawing}\\r\\n\\n\\\\usegdlibrary{circular}\", true, true)" ] }, "execution_count": 17, @@ -1320,6 +1284,84 @@ "TikzGraphs.plot(g, Layouts.SimpleNecklace())" ] }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Options" + ] + }, + { + "cell_type": "code", + "execution_count": 18, + "metadata": {}, + "outputs": [ + { + "data": { + "image/svg+xml": [ + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + " \n", + "\n", + "\n", + "\n", + " \n", + "\n", + "\n", + "\n", + " \n", + "\n", + "\n", + "\n", + " \n", + "\n", + "\n", + "\n", + "\n" + ], + "text/plain": [ + "TikzPictures.TikzPicture(\"\\\\graph [layered layout, ] {\\n1/\\\"1\\\" [draw],\\n2/\\\"2\\\" [draw],\\n3/\\\"3\\\" [draw],\\n4/\\\"4\\\" [draw],\\n;\\n1 -> [,] 2;\\n1 -> [,] 4;\\n2 -> [,] 3;\\n3 -> [,] 4;\\n};\\n\", \"scale=2, font=\\\\huge\\\\sf\", \"\\\\usepackage{fontspec}\\r\\n\\\\setmainfont{Latin Modern Math}\\r\\n\\\\usetikzlibrary{graphs}\\r\\n\\\\usetikzlibrary{graphdrawing}\\r\\n\\n\\\\usegdlibrary{layered}\", true, true)" + ] + }, + "execution_count": 18, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "TikzGraphs.plot(g, node_style=\"draw\", options=\"scale=2, font=\\\\huge\\\\sf\")" + ] + }, { "cell_type": "markdown", "metadata": {}, @@ -1337,17 +1379,17 @@ ], "metadata": { "kernelspec": { - "display_name": "Julia 0.5.0", + "display_name": "Julia 0.6.0", "language": "julia", - "name": "julia-0.5" + "name": "julia-0.6" }, "language_info": { "file_extension": ".jl", "mimetype": "application/julia", "name": "julia", - "version": "0.5.0" + "version": "0.6.0" } }, "nbformat": 4, - "nbformat_minor": 0 + "nbformat_minor": 1 } diff --git a/src/TikzGraphs.jl b/src/TikzGraphs.jl index 30a7a00..90c3716 100644 --- a/src/TikzGraphs.jl +++ b/src/TikzGraphs.jl @@ -59,9 +59,9 @@ end edge_str(g::DiGraph) = "->" edge_str(g::Graph) = "--" -function plot{T<:AbstractString}(g::AbstractGraph; layout::Layouts.Layout = Layered(), labels::Vector{T}=map(string, vertices(g)), edge_labels::Dict = Dict(), node_styles::Dict = Dict(), node_style="", edge_styles::Dict = Dict(), edge_style="") +function plot{T<:AbstractString}(g::AbstractGraph; layout::Layouts.Layout = Layered(), labels::Vector{T}=map(string, vertices(g)), edge_labels::Dict = Dict(), node_styles::Dict = Dict(), node_style="", edge_styles::Dict = Dict(), edge_style="", options="") o = IOBuffer() - println(o, "\\graph [$(layoutname(layout)), $(options(layout))] {") + println(o, "\\graph [$(layoutname(layout)), $(options_str(layout))] {") for v in vertices(g) nodeHelper(o, v, labels, node_styles, node_style) end @@ -75,7 +75,7 @@ function plot{T<:AbstractString}(g::AbstractGraph; layout::Layouts.Layout = Laye end println(o, "};") mypreamble = preamble * "\n\\usegdlibrary{$(libraryname(layout))}" - TikzPicture(String(take!(o)), preamble=mypreamble) + TikzPicture(String(take!(o)), preamble=mypreamble, options=options) end for (_layout, _libraryname, _layoutname) in [ @@ -87,7 +87,7 @@ for (_layout, _libraryname, _layoutname) in [ @eval layoutname(p::$(_layout)) = $_layoutname end -options(p::Layouts.Layout) = "" -options(p::Spring) = "random seed = $(p.randomSeed)" +options_str(p::Layouts.Layout) = "" +options_str(p::Spring) = "random seed = $(p.randomSeed)" end # module