{ "cells": [ { "cell_type": "markdown", "id": "895d7469", "metadata": {}, "source": [ "# gr016_struct\n", "Draw a simple graph structure.\n", "The graph layout is made using graphviz. This macro creates some\n", "nodes and edges and change a few graphical attributes on some of them.\n", "\n", "\n", "\n", "**Author:** Olivier Couet \n", "This notebook tutorial was automatically generated with ROOTBOOK-izer from the macro found in the ROOT repository on Tuesday, May 19, 2026 at 08:38 PM." ] }, { "cell_type": "code", "execution_count": 1, "id": "af5c9f41", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:38:05.476195Z", "iopub.status.busy": "2026-05-19T20:38:05.476076Z", "iopub.status.idle": "2026-05-19T20:38:05.802590Z", "shell.execute_reply": "2026-05-19T20:38:05.802209Z" } }, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "Unbalanced braces. This cell was not processed.\n" ] } ], "source": [ "#if __has_include(\"TGraphStruct.h\") // handy check on whether gviz was installed\n", "TGraphStruct *gs = new TGraphStruct();" ] }, { "cell_type": "markdown", "id": "d76cddf1", "metadata": {}, "source": [ "create some nodes and put them in the graph in one go ..." ] }, { "cell_type": "code", "execution_count": 2, "id": "748213f9", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:38:05.806022Z", "iopub.status.busy": "2026-05-19T20:38:05.805890Z", "iopub.status.idle": "2026-05-19T20:38:06.017958Z", "shell.execute_reply": "2026-05-19T20:38:06.017324Z" } }, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "input_line_53:19:18: error: cannot take the address of an rvalue of type 'EColor'\n", "n0->SetTextColor(kRed);\n", " ^~~~\n", "Error while creating dynamic expression for:\n", " n0->SetTextColor(kRed)\n", "input_line_53:21:18: error: cannot take the address of an rvalue of type 'EColor'\n", "n9->SetFillColor(kRed-10);\n", " ^~~~\n", "Error while creating dynamic expression for:\n", " n9->SetFillColor(kRed - 10)\n", "input_line_53:22:18: error: cannot take the address of an rvalue of type 'EColor'\n", "n0->SetFillColor(kYellow-9);\n", " ^~~~~~~\n", "Error while creating dynamic expression for:\n", " n0->SetFillColor(kYellow - 9)\n", "input_line_53:23:18: error: cannot take the address of an rvalue of type 'EColor'\n", "n7->SetFillColor(kViolet-9);\n", " ^~~~~~~\n", "Error while creating dynamic expression for:\n", " n7->SetFillColor(kViolet - 9)\n" ] } ], "source": [ "TGraphNode *n0 = gs->AddNode(\"n0\",\"Node 0\");\n", "TGraphNode *n1 = gs->AddNode(\"n1\",\"First node\");\n", "TGraphNode *n2 = gs->AddNode(\"n2\",\"Second node\");\n", "TGraphNode *n3 = gs->AddNode(\"n3\",\"Third node\");\n", "TGraphNode *n4 = gs->AddNode(\"n4\",\"Fourth node\");\n", "TGraphNode *n5 = gs->AddNode(\"n5\",\"5th node\");\n", "TGraphNode *n6 = gs->AddNode(\"n6\",\"Node number six\");\n", "TGraphNode *n7 = gs->AddNode(\"n7\",\"Node 7\");\n", "TGraphNode *n8 = gs->AddNode(\"n8\",\"Node 8\");\n", "TGraphNode *n9 = gs->AddNode(\"n9\",\"Node 9\");\n", "\n", "n4->SetTextSize(0.03);\n", "n6->SetTextSize(0.03);\n", "n2->SetTextSize(0.04);\n", "\n", "n3->SetTextFont(132);\n", "\n", "n0->SetTextColor(kRed);\n", "\n", "n9->SetFillColor(kRed-10);\n", "n0->SetFillColor(kYellow-9);\n", "n7->SetFillColor(kViolet-9);" ] }, { "cell_type": "markdown", "id": "f0faf6e4", "metadata": {}, "source": [ "some edges ..." ] }, { "cell_type": "code", "execution_count": 3, "id": "b579e312", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:38:06.019366Z", "iopub.status.busy": "2026-05-19T20:38:06.019250Z", "iopub.status.idle": "2026-05-19T20:38:06.232075Z", "shell.execute_reply": "2026-05-19T20:38:06.226645Z" } }, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "input_line_54:24:2: error: #else without #if\n", "#else\n", " ^\n", "input_line_54:26:2: error: #endif without #if\n", "#endif\n", " ^\n", "input_line_54:2:35: error: cannot take the address of an rvalue of type 'EColor'\n", " gs->AddEdge(n0,n1)->SetLineColor(kRed);\n", " ^~~~\n", "Error while creating dynamic expression for:\n", " gs->AddEdge(n0, n1)->SetLineColor(kRed)\n", "input_line_54:4:19: error: cannot take the address of an rvalue of type 'EColor'\n", "e06->SetLineColor(kRed-3);\n", " ^~~~\n", "Error while creating dynamic expression for:\n", " e06->SetLineColor(kRed - 3)\n" ] } ], "source": [ "gs->AddEdge(n0,n1)->SetLineColor(kRed);\n", "TGraphEdge *e06 = gs->AddEdge(n0,n6);\n", "e06->SetLineColor(kRed-3);\n", "e06->SetLineWidth(4);\n", "gs->AddEdge(n1,n7);\n", "gs->AddEdge(n4,n6);\n", "gs->AddEdge(n3,n9);\n", "gs->AddEdge(n6,n8);\n", "gs->AddEdge(n7,n2);\n", "gs->AddEdge(n8,n3);\n", "gs->AddEdge(n2,n3);\n", "gs->AddEdge(n9,n0);\n", "gs->AddEdge(n1,n4);\n", "gs->AddEdge(n1,n6);\n", "gs->AddEdge(n2,n5);\n", "gs->AddEdge(n3,n6);\n", "gs->AddEdge(n4,n5);\n", "\n", "TCanvas *c = new TCanvas(\"c\",\"c\",800,600);\n", "c->SetFillColor(38);\n", "gs->Draw();\n", "return c;\n", "#else\n", "return new TCanvas(\"c\",\"c\",800,600);\n", "#endif" ] }, { "cell_type": "markdown", "id": "3a7ef048", "metadata": {}, "source": [ "Draw all canvases " ] }, { "cell_type": "code", "execution_count": 4, "id": "9ac54dd6", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:38:06.235575Z", "iopub.status.busy": "2026-05-19T20:38:06.235449Z", "iopub.status.idle": "2026-05-19T20:38:06.447138Z", "shell.execute_reply": "2026-05-19T20:38:06.446619Z" } }, "outputs": [], "source": [ "gROOT->GetListOfCanvases()->Draw()" ] } ], "metadata": { "kernelspec": { "display_name": "ROOT C++", "language": "c++", "name": "root" }, "language_info": { "codemirror_mode": "text/x-c++src", "file_extension": ".C", "mimetype": " text/x-c++src", "name": "c++" } }, "nbformat": 4, "nbformat_minor": 5 }