<commit_before>// @(#)root/hist:$Id$
// Author: <NAME> 13/07/09

/*************************************************************************
 * Copyright (C) 1995-2000, <NAME> and <NAME>.               *
 * All rights reserved.                                                  *
 *                                                                       *
 * For the licensing terms see $ROOTSYS/LICENSE.                         *
 * For the list of contributors see $ROOTSYS/README/CREDITS.             *
 *************************************************************************/

#include "TPad.h"
#include "TGraphStruct.h"

#include <stdio.h>

#include <gvc.h>

ClassImp(TGraphStruct)


//______________________________________________________________________________
/* Begin_Html
<center><h2>Graph Structure class</h2></center>
The Graph Structure is an interface to the graphviz package.
End_Html */


//______________________________________________________________________________
TGraphStruct::TGraphStruct()
{
   // Graph Structure default constructor.

   fNodes   = 0;
   fEdges   = 0;
   fGVGraph = 0;
   fGVC     = 0;

   SetMargin();
}


//______________________________________________________________________________
TGraphStruct::~TGraphStruct()
{
   // Graph Structure default destructor.

   gvFreeLayout(fGVC,fGVGraph);
   agclose(fGVGraph);
   gvFreeContext(fGVC);

   if (fNodes) delete fNodes;
   if (fEdges) delete fEdges;

}


//______________________________________________________________________________
void TGraphStruct::AddEdge(TGraphEdge *edge)
{
   // Add the edge "edge" in this TGraphStruct.

   if (!fEdges) fEdges = new TList;

   fEdges->Add(edge);
}


//______________________________________________________________________________
TGraphEdge *TGraphStruct::AddEdge(TGraphNode *n1, TGraphNode *n2)
{
   // Create an edge between n1 and n2 and put it in this graph.
   //
   // Two edges can connect the same nodes the same way, so there
   // is no need to check if an edge already exists.

   if (!fEdges) fEdges = new TList;

   TGraphEdge *edge = new TGraphEdge(n1, n2);
   fEdges->Add(edge);

   return edge;
}


//______________________________________________________________________________
void TGraphStruct::AddNode(TGraphNode *node)
{
   // Add the node "node" in this TGraphStruct.

   if (!fNodes) fNodes = new TList;

   fNodes->Add(node);
}


//______________________________________________________________________________
TGraphNode *TGraphStruct::AddNode(const char *name, const char *title)
{
   // Create the node "name" if it does not exist and add it to this TGraphStruct.

   if (!fNodes) fNodes = new TList;

   TGraphNode *node = (TGraphNode*)fNodes->FindObject(name);

   if (!node) {
      node = new TGraphNode(name, title);
      fNodes->Add(node);
   }

   return node;
}



//______________________________________________________________________________
void TGraphStruct::DumpAsDotFile(const char *filename)
{
   // Dump this graph structure as a "dot" file.

   if (!fGVGraph) Layout();
   FILE  *file;
   file=fopen(filename,"w");
   agwrite(fGVGraph, file);
   fclose(file);
}


//______________________________________________________________________________
void TGraphStruct::Draw(Option_t */*option*/)
{
   // Draw the graph

   if (!fGVGraph) Layout();

   // Get the bounding box
   if (gPad) {
      gPad->Range(GD_bb(fGVGraph).LL.x-fMargin, GD_bb(fGVGraph).LL.y-fMargin,
                  GD_bb(fGVGraph).UR.x+fMargin, GD_bb(fGVGraph).UR.y+fMargin);
   }

   // Draw the nodes
   TGraphNode *node;
   node = (TGraphNode*) fNodes->First();
   node->Draw();
   for(Int_t i = 1; i < fNodes->GetSize(); i++){
      node = (TGraphNode*)fNodes->After(node);
      node->Draw();<commit_msg>- A .dot file in a text file: fopen should be call with option "wt".<commit_after>// @(#)root/hist:$Id$
// Author: <NAME> 13/07/09

/*************************************************************************
 * Copyright (C) 1995-2000, <NAME> and <NAME>.               *
 * All rights reserved.                                                  *
 *                                                                       *
 * For the licensing terms see $ROOTSYS/LICENSE.                         *
 * For the list of contributors see $ROOTSYS/README/CREDITS.             *
 *************************************************************************/

#include "TPad.h"
#include "TGraphStruct.h"

#include <stdio.h>

#include <gvc.h>

ClassImp(TGraphStruct)


//______________________________________________________________________________
/* Begin_Html
<center><h2>Graph Structure class</h2></center>
The Graph Structure is an interface to the graphviz package.
End_Html */


//______________________________________________________________________________
TGraphStruct::TGraphStruct()
{
   // Graph Structure default constructor.

   fNodes   = 0;
   fEdges   = 0;
   fGVGraph = 0;
   fGVC     = 0;

   SetMargin();
}


//______________________________________________________________________________
TGraphStruct::~TGraphStruct()
{
   // Graph Structure default destructor.

   gvFreeLayout(fGVC,fGVGraph);
   agclose(fGVGraph);
   gvFreeContext(fGVC);

   if (fNodes) delete fNodes;
   if (fEdges) delete fEdges;

}


//______________________________________________________________________________
void TGraphStruct::AddEdge(TGraphEdge *edge)
{
   // Add the edge "edge" in this TGraphStruct.

   if (!fEdges) fEdges = new TList;

   fEdges->Add(edge);
}


//______________________________________________________________________________
TGraphEdge *TGraphStruct::AddEdge(TGraphNode *n1, TGraphNode *n2)
{
   // Create an edge between n1 and n2 and put it in this graph.
   //
   // Two edges can connect the same nodes the same way, so there
   // is no need to check if an edge already exists.

   if (!fEdges) fEdges = new TList;

   TGraphEdge *edge = new TGraphEdge(n1, n2);
   fEdges->Add(edge);

   return edge;
}


//______________________________________________________________________________
void TGraphStruct::AddNode(TGraphNode *node)
{
   // Add the node "node" in this TGraphStruct.

   if (!fNodes) fNodes = new TList;

   fNodes->Add(node);
}


//______________________________________________________________________________
TGraphNode *TGraphStruct::AddNode(const char *name, const char *title)
{
   // Create the node "name" if it does not exist and add it to this TGraphStruct.

   if (!fNodes) fNodes = new TList;

   TGraphNode *node = (TGraphNode*)fNodes->FindObject(name);

   if (!node) {
      node = new TGraphNode(name, title);
      fNodes->Add(node);
   }

   return node;
}



//______________________________________________________________________________
void TGraphStruct::DumpAsDotFile(const char *filename)
{
   // Dump this graph structure as a "dot" file.

   if (!fGVGraph) Layout();
   FILE  *file;
   file=fopen(filename,"wt");
   agwrite(fGVGraph, file);
   fclose(file);
}


//______________________________________________________________________________
void TGraphStruct::Draw(Option_t */*option*/)
{
   // Draw the graph

   if (!fGVGraph) Layout();

   // Get the bounding box
   if (gPad) {
      gPad->Range(GD_bb(fGVGraph).LL.x-fMargin, GD_bb(fGVGraph).LL.y-fMargin,
                  GD_bb(fGVGraph).UR.x+fMargin, GD_bb(fGVGraph).UR.y+fMargin);
   }

   // Draw the nodes
   TGraphNode *node;
   node = (TGraphNode*) fNodes->First();
   node->Draw();
   for(Int_t i = 1; i < fNodes->GetSize(); i++){
      node = (TGraphNode*)fNodes->After(node);
      node->Draw();
{'fraction_non_alphanumeric': 0.14602003162888771, 'fraction_numerical': 0.007116499736425936, 'mean_word_length': 3.3968713789107765, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 43, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 10, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2953980', 'n_tokens_mistral': 2208, 'n_tokens_neox': 2070, 'n_words': 539}