gravatar
alpar (Alpar Juttner)
alpar@cs.elte.hu
Scale the node sizes and arc widths in a more sensible way
0 2 0
default
2 files changed with 5 insertions and 5 deletions:
↑ Collapse diff ↑
Ignore white space 96 line context
... ...
@@ -154,55 +154,55 @@
154 154
    title("Sample .eps figure (parallel arcs and arrowheads)").
155 155
    copyright("(C) 2003-2007 LEMON Project").
156 156
    absoluteNodeSizes().absoluteArcWidths().
157 157
    nodeScale(2).nodeSizes(sizes).
158 158
    coords(coords).
159 159
    nodeShapes(shapes).
160 160
    nodeColors(composeMap(palette,colors)).
161 161
    arcColors(composeMap(palette,ecolors)).
162 162
    arcWidthScale(.3).arcWidths(widths).
163 163
    nodeTexts(id).nodeTextSize(3).
164 164
    enableParallel().parArcDist(1).
165 165
    drawArrows().arrowWidth(1).arrowLength(1).
166 166
    run();
167 167

	
168 168
  cout << "Create 'graph_to_eps_demo_out_a4.eps'" << endl;
169 169
  graphToEps(g,"graph_to_eps_demo_out_a4.eps").scaleToA4().
170 170
    title("Sample .eps figure (fits to A4)").
171 171
    copyright("(C) 2003-2007 LEMON Project").
172 172
    absoluteNodeSizes().absoluteArcWidths().
173 173
    nodeScale(2).nodeSizes(sizes).
174 174
    coords(coords).
175 175
    nodeShapes(shapes).
176 176
    nodeColors(composeMap(palette,colors)).
177 177
    arcColors(composeMap(palette,ecolors)).
178 178
    arcWidthScale(.3).arcWidths(widths).
179 179
    nodeTexts(id).nodeTextSize(3).
180 180
    enableParallel().parArcDist(1).
181 181
    drawArrows().arrowWidth(1).arrowLength(1).
182 182
    run();
183 183

	
184 184
  ListDigraph h;
185 185
  ListDigraph::NodeMap<int> hcolors(h);
186 186
  ListDigraph::NodeMap<Point> hcoords(h);
187 187
  
188 188
  int cols=int(sqrt(double(palette.size())));
189 189
  for(int i=0;i<int(paletteW.size());i++) {
190 190
    Node n=h.addNode();
191 191
    hcoords[n]=Point(i%cols,i/cols);
192 192
    hcolors[n]=i;
193 193
  }
194 194
  
195 195
  cout << "Create 'graph_to_eps_demo_out_colors.eps'" << endl;
196 196
  graphToEps(h,"graph_to_eps_demo_out_colors.eps").
197 197
    //scale(60).
198 198
    title("Sample .eps figure (Palette demo)").
199 199
    copyright("(C) 2003-2007 LEMON Project").
200 200
    coords(hcoords).
201 201
    absoluteNodeSizes().absoluteArcWidths().
202
    nodeScale(45).
202
    nodeScale(.45).
203 203
    distantColorNodeTexts().
204 204
    //    distantBWNodeTexts().
205 205
    nodeTexts(hcolors).nodeTextSize(.6).
206 206
    nodeColors(composeMap(paletteW,hcolors)).
207 207
    run();
208 208
}
Ignore white space 96 line context
... ...
@@ -105,100 +105,100 @@
105 105
  
106 106
  bool _showNodes, _showArcs;
107 107

	
108 108
  bool _enableParallel;
109 109
  double _parArcDist;
110 110

	
111 111
  bool _showNodeText;
112 112
  ConstMap<typename Graph::Node,bool > _nodeTexts;  
113 113
  double _nodeTextSize;
114 114

	
115 115
  bool _showNodePsText;
116 116
  ConstMap<typename Graph::Node,bool > _nodePsTexts;  
117 117
  char *_nodePsTextsPreamble;
118 118
  
119 119
  bool _undirected;
120 120

	
121 121
  bool _pleaseRemoveOsStream;
122 122

	
123 123
  bool _scaleToA4;
124 124

	
125 125
  std::string _title;
126 126
  std::string _copyright;
127 127

	
128 128
  enum NodeTextColorType 
129 129
    { DIST_COL=0, DIST_BW=1, CUST_COL=2, SAME_COL=3 } _nodeTextColorType;
130 130
  ConstMap<typename Graph::Node,Color > _nodeTextColors;
131 131

	
132 132
  bool _autoNodeScale;
133 133
  bool _autoArcWidthScale;
134 134

	
135 135
  bool _absoluteNodeSizes;
136 136
  bool _absoluteArcWidths;
137 137

	
138 138
  bool _negY;
139 139

	
140 140
  bool _preScale;
141 141
  ///Constructor
142 142

	
143 143
  ///Constructor
144 144
  ///\param _g is a reference to the graph to be printed
145 145
  ///\param _os is a reference to the output stream.
146 146
  ///\param _os is a reference to the output stream.
147 147
  ///\param _pros If it is \c true, then the \c ostream referenced by \c _os
148 148
  ///will be explicitly deallocated by the destructor.
149 149
  ///By default it is <tt>std::cout</tt>
150 150
  DefaultGraphToEpsTraits(const G &_g,std::ostream& _os=std::cout,
151 151
			  bool _pros=false) :
152 152
    g(_g), os(_os),
153
    _coords(dim2::Point<double>(1,1)), _nodeSizes(.01), _nodeShapes(0),
153
    _coords(dim2::Point<double>(1,1)), _nodeSizes(1), _nodeShapes(0),
154 154
    _nodeColors(WHITE), _arcColors(BLACK),
155 155
    _arcWidths(1.0), _arcWidthScale(0.003),
156
    _nodeScale(1.0), _xBorder(10), _yBorder(10), _scale(1.0),
156
    _nodeScale(.01), _xBorder(10), _yBorder(10), _scale(1.0),
157 157
    _nodeBorderQuotient(.1),
158 158
    _drawArrows(false), _arrowLength(1), _arrowWidth(0.3),
159 159
    _showNodes(true), _showArcs(true),
160 160
    _enableParallel(false), _parArcDist(1),
161 161
    _showNodeText(false), _nodeTexts(false), _nodeTextSize(1),
162 162
    _showNodePsText(false), _nodePsTexts(false), _nodePsTextsPreamble(0),
163 163
    _undirected(lemon::UndirectedTagIndicator<G>::value),
164 164
    _pleaseRemoveOsStream(_pros), _scaleToA4(false),
165 165
    _nodeTextColorType(SAME_COL), _nodeTextColors(BLACK),
166 166
    _autoNodeScale(false),
167 167
    _autoArcWidthScale(false),
168 168
    _absoluteNodeSizes(false),
169 169
    _absoluteArcWidths(false),
170 170
    _negY(false),
171 171
    _preScale(true)
172 172
  {}
173 173
};
174 174

	
175 175
///Helper class to implement the named parameters of \ref graphToEps()
176 176

	
177 177
///Helper class to implement the named parameters of \ref graphToEps()
178 178
///\todo Is 'helper class' a good name for this?
179 179
///
180 180
///\todo Follow PostScript's DSC.
181 181
/// Use own dictionary.
182 182
///\todo Useful new features.
183 183
/// - Linestyles: dotted, dashed etc.
184 184
/// - A second color and percent value for the lines.
185 185
template<class T> class GraphToEps : public T 
186 186
{
187 187
  // Can't believe it is required by the C++ standard
188 188
  using T::g;
189 189
  using T::os;
190 190

	
191 191
  using T::_coords;
192 192
  using T::_nodeSizes;
193 193
  using T::_nodeShapes;
194 194
  using T::_nodeColors;
195 195
  using T::_arcColors;
196 196
  using T::_arcWidths;
197 197

	
198 198
  using T::_arcWidthScale;
199 199
  using T::_nodeScale;
200 200
  using T::_xBorder;
201 201
  using T::_yBorder;
202 202
  using T::_scale;
203 203
  using T::_nodeBorderQuotient;
204 204
  
... ...
@@ -451,150 +451,150 @@
451 451
  }
452 452
  template<class X> struct NodeTextColorsTraits : public T {
453 453
    const X &_nodeTextColors;
454 454
    NodeTextColorsTraits(const T &t,const X &x) : T(t), _nodeTextColors(x) {}
455 455
  };
456 456
  ///Sets the map of the node text colors
457 457

	
458 458
  ///Sets the map of the node text colors
459 459
  ///\param x must be a node map with \ref Color values. 
460 460
  ///
461 461
  ///\sa Palette
462 462
  template<class X> GraphToEps<NodeTextColorsTraits<X> >
463 463
  nodeTextColors(const X &x)
464 464
  {
465 465
    dontPrint=true;
466 466
    _nodeTextColorType=CUST_COL;
467 467
    return GraphToEps<NodeTextColorsTraits<X> >
468 468
      (NodeTextColorsTraits<X>(*this,x));
469 469
  }
470 470
  template<class X> struct ArcColorsTraits : public T {
471 471
    const X &_arcColors;
472 472
    ArcColorsTraits(const T &t,const X &x) : T(t), _arcColors(x) {}
473 473
  };
474 474
  ///Sets the map of the arc colors
475 475

	
476 476
  ///Sets the map of the arc colors
477 477
  ///\param x must be a arc map with \ref Color values. 
478 478
  ///
479 479
  ///\sa Palette
480 480
  template<class X> GraphToEps<ArcColorsTraits<X> >
481 481
  arcColors(const X &x)
482 482
  {
483 483
    dontPrint=true;
484 484
    return GraphToEps<ArcColorsTraits<X> >(ArcColorsTraits<X>(*this,x));
485 485
  }
486 486
  ///Sets a global scale factor for node sizes
487 487

	
488 488
  ///Sets a global scale factor for node sizes.
489 489
  /// 
490 490
  /// If nodeSizes() is not given, this function simply sets the node
491 491
  /// sizes to \c d.  If nodeSizes() is given, but
492 492
  /// autoNodeScale() is not, then the node size given by
493 493
  /// nodeSizes() will be multiplied by the value \c d.
494 494
  /// If both nodeSizes() and autoNodeScale() are used, then the
495 495
  /// node sizes will be scaled in such a way that the greatest size will be
496 496
  /// equal to \c d.
497 497
  /// \sa nodeSizes()
498 498
  /// \sa autoNodeScale()
499
  GraphToEps<T> &nodeScale(double d) {_nodeScale=d;return *this;}
499
  GraphToEps<T> &nodeScale(double d=.01) {_nodeScale=d;return *this;}
500 500
  ///Turns on/off the automatic node width scaling.
501 501

	
502 502
  ///Turns on/off the automatic node width scaling.
503 503
  ///
504 504
  ///\sa nodeScale()
505 505
  ///
506 506
  GraphToEps<T> &autoNodeScale(bool b=true) {
507 507
    _autoNodeScale=b;return *this;
508 508
  }
509 509

	
510 510
  ///Turns on/off the absolutematic node width scaling.
511 511

	
512 512
  ///Turns on/off the absolutematic node width scaling.
513 513
  ///
514 514
  ///\sa nodeScale()
515 515
  ///
516 516
  GraphToEps<T> &absoluteNodeSizes(bool b=true) {
517 517
    _absoluteNodeSizes=b;return *this;
518 518
  }
519 519

	
520 520
  ///Negates the Y coordinates.
521 521

	
522 522
  ///Negates the Y coordinates.
523 523
  ///
524 524
  ///\todo More docs.
525 525
  ///
526 526
  GraphToEps<T> &negateY(bool b=true) {
527 527
    _negY=b;return *this;
528 528
  }
529 529

	
530 530
  ///Turn on/off prescaling
531 531

	
532 532
  ///By default graphToEps() rescales the whole image in order to avoid
533 533
  ///very big or very small bounding boxes.
534 534
  ///
535 535
  ///This (p)rescaling can be turned off with this function.
536 536
  ///
537 537
  GraphToEps<T> &preScale(bool b=true) {
538 538
    _preScale=b;return *this;
539 539
  }
540 540

	
541 541
  ///Sets a global scale factor for arc widths
542 542

	
543 543
  /// Sets a global scale factor for arc widths.
544 544
  ///
545 545
  /// If arcWidths() is not given, this function simply sets the arc
546 546
  /// widths to \c d.  If arcWidths() is given, but
547 547
  /// autoArcWidthScale() is not, then the arc withs given by
548 548
  /// arcWidths() will be multiplied by the value \c d.
549 549
  /// If both arcWidths() and autoArcWidthScale() are used, then the
550 550
  /// arc withs will be scaled in such a way that the greatest width will be
551 551
  /// equal to \c d.
552
  GraphToEps<T> &arcWidthScale(double d) {_arcWidthScale=d;return *this;}
552
  GraphToEps<T> &arcWidthScale(double d=.003) {_arcWidthScale=d;return *this;}
553 553
  ///Turns on/off the automatic arc width scaling.
554 554

	
555 555
  ///Turns on/off the automatic arc width scaling.
556 556
  ///
557 557
  ///\sa arcWidthScale()
558 558
  ///
559 559
  GraphToEps<T> &autoArcWidthScale(bool b=true) {
560 560
    _autoArcWidthScale=b;return *this;
561 561
  }
562 562
  ///Turns on/off the absolutematic arc width scaling.
563 563

	
564 564
  ///Turns on/off the absolutematic arc width scaling.
565 565
  ///
566 566
  ///\sa arcWidthScale()
567 567
  ///
568 568
  GraphToEps<T> &absoluteArcWidths(bool b=true) {
569 569
    _absoluteArcWidths=b;return *this;
570 570
  }
571 571
  ///Sets a global scale factor for the whole picture
572 572

	
573 573
  ///Sets a global scale factor for the whole picture
574 574
  ///
575 575

	
576 576
  GraphToEps<T> &scale(double d) {_scale=d;return *this;}
577 577
  ///Sets the width of the border around the picture
578 578

	
579 579
  ///Sets the width of the border around the picture
580 580
  ///
581 581
  GraphToEps<T> &border(double b) {_xBorder=_yBorder=b;return *this;}
582 582
  ///Sets the width of the border around the picture
583 583

	
584 584
  ///Sets the width of the border around the picture
585 585
  ///
586 586
  GraphToEps<T> &border(double x, double y) {
587 587
    _xBorder=x;_yBorder=y;return *this;
588 588
  }
589 589
  ///Sets whether to draw arrows
590 590

	
591 591
  ///Sets whether to draw arrows
592 592
  ///
593 593
  GraphToEps<T> &drawArrows(bool b=true) {_drawArrows=b;return *this;}
594 594
  ///Sets the length of the arrowheads
595 595

	
596 596
  ///Sets the length of the arrowheads
597 597
  ///
598 598
  GraphToEps<T> &arrowLength(double d) {_arrowLength*=d;return *this;}
599 599
  ///Sets the width of the arrowheads
600 600

	
0 comments (0 inline)