src/demo/graph_to_eps_demo.cc
changeset 1247 60708e1475ae
parent 1164 80bb73097736
child 1268 a1f9a4d4ea0c
equal deleted inserted replaced
6:b89c4402255d 7:57b86c02677c
    21 
    21 
    22 
    22 
    23 using namespace std;
    23 using namespace std;
    24 using namespace lemon;
    24 using namespace lemon;
    25 
    25 
    26 class ColorSet : public MapBase<int,Color>
       
    27 {
       
    28 public:
       
    29   Color operator[](int i) const
       
    30   {
       
    31     switch(i%8){
       
    32     case 0: return Color(0,0,0);
       
    33     case 1: return Color(1,0,0);
       
    34     case 2: return Color(0,1,0);
       
    35     case 3: return Color(0,0,1);
       
    36     case 4: return Color(1,1,0);
       
    37     case 5: return Color(1,0,1);
       
    38     case 6: return Color(0,1,1);
       
    39     case 7: return Color(1,1,1);
       
    40     }
       
    41     return Color(0,0,0);
       
    42   }
       
    43 } colorSet;
       
    44 
       
    45 class IdMap :public MapBase<ListGraph::Node,int>
    26 class IdMap :public MapBase<ListGraph::Node,int>
    46 {
    27 {
    47   const ListGraph &g;
    28   const ListGraph &g;
    48 public:
    29 public:
    49   IdMap(const ListGraph &_g) :g(_g) {}
    30   IdMap(const ListGraph &_g) :g(_g) {}
    50   Value operator[](Key n) const { return g.id(n); }
    31   Value operator[](Key n) const { return g.id(n); }
    51 };
    32 };
    52 
    33 
    53 int main()
    34 int main()
    54 {
    35 {
       
    36   ColorSet colorSet;
       
    37 
    55   ListGraph g;
    38   ListGraph g;
    56   typedef ListGraph::Node Node;
    39   typedef ListGraph::Node Node;
    57   typedef ListGraph::NodeIt NodeIt;
    40   typedef ListGraph::NodeIt NodeIt;
    58   typedef ListGraph::Edge Edge;
    41   typedef ListGraph::Edge Edge;
    59   typedef xy<int> Xy;
    42   typedef xy<int> Xy;
   163     nodeTexts(id).nodeTextSize(3).
   146     nodeTexts(id).nodeTextSize(3).
   164     enableParallel().parEdgeDist(1).
   147     enableParallel().parEdgeDist(1).
   165     drawArrows().arrowWidth(1).arrowLength(1).
   148     drawArrows().arrowWidth(1).arrowLength(1).
   166     run();
   149     run();
   167 
   150 
       
   151   ListGraph h;
       
   152   ListGraph::NodeMap<int> hcolors(h);
       
   153   ListGraph::NodeMap<Xy> hcoords(h);
       
   154   
       
   155   int cols=int(sqrt(double(colorSet.size())));
       
   156   for(int i=0;i<int(colorSet.size());i++) {
       
   157     Node n=h.addNode();
       
   158     hcoords[n]=Xy(i%cols,i/cols);
       
   159     hcolors[n]=i;
       
   160   }
       
   161   
       
   162   graphToEps(h,"graph_to_eps_demo_out_colors.eps").scale(60).
       
   163     title("Sample .eps figure (parallel edges and arrowheads)").
       
   164     copyright("(C) 2005 LEMON Project").
       
   165     coords(hcoords).
       
   166     nodeScale(.45).
       
   167     distantColorNodeTexts().
       
   168     //    distantBWNodeTexts().
       
   169     nodeTexts(hcolors).nodeTextSize(.6).
       
   170     nodeColors(composeMap(colorSet,hcolors)).
       
   171     run();
       
   172 
       
   173 
   168 }
   174 }