COIN-OR::LEMON - Graph Library

Changeset 1103:f196dc4f1b31 in lemon-0.x


Ignore:
Timestamp:
01/28/05 10:09:59 (19 years ago)
Author:
Alpar Juttner
Branch:
default
Phase:
public
Convert:
svn:c9d7d8f5-90d6-0310-b91f-818b3a526b0e/lemon/trunk@1502
Message:

Add a 'scaleToA4()' function.

Location:
src
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • src/demo/graph_to_eps_demo.cc

    r1091 r1103  
    141141    nodeTexts(id).nodeTextSize(3).
    142142    enableParallel().parEdgeDist(1).
    143     //    hideNodes().
    144143    drawArrows().arrowWidth(1).arrowLength(1).
    145     run();;
     144    run();
     145
     146  graphToEps(g,"graph_to_eps_demo_out_a4.eps").scaleToA4().
     147    nodeScale(2).nodeSizes(sizes).
     148    coords(coords).
     149    nodeShapes(shapes).
     150    nodeColors(composeMap(colorSet,colors)).
     151    edgeColors(composeMap(colorSet,ecolors)).
     152    edgeWidthScale(.3).edgeWidths(widths).
     153    nodeTexts(id).nodeTextSize(3).
     154    enableParallel().parEdgeDist(1).
     155    drawArrows().arrowWidth(1).arrowLength(1).
     156    run();
     157
    146158}
  • src/lemon/graph_to_eps.h

    r1091 r1103  
    8787
    8888  ConstMap<typename Graph::Edge,double > _edgeWidths;
     89
     90  static const double A4HEIGHT = 841.8897637795276;
     91  static const double A4WIDTH  = 595.275590551181;
     92  static const double A4BORDER = 15;
     93
    8994 
    9095  double _edgeWidthScale;
     
    113118  bool _undir;
    114119  bool _pleaseRemoveOsStream;
     120
     121  bool _scaleToA4;
     122 
    115123  ///Constructor
    116124
     
    136144    _showNodePsText(false), _nodePsTexts(false), _nodePsTextsPreamble(0),
    137145    _undir(false),
    138     _pleaseRemoveOsStream(_pros) {}
     146    _pleaseRemoveOsStream(_pros), _scaleToA4(false) {}
    139147};
    140148
     
    144152///\todo Is 'helper class' a good name for this?
    145153///
     154///\todo Follow PostScript's DSC.
     155///\todo Use own dictionary.
    146156template<class T> class GraphToEps : public T
    147157{
     
    202212
    203213  ///Sets the map of the node coordinates.
    204   ///\param x must be a node map with xy<double> or xy<int> values.
     214  ///\param x must be a node map with xy<double> or \ref xy "xy<int>" values.
    205215  template<class X> GraphToEps<CoordsTraits<X> > coords(const X &x) {
    206216    dontPrint=true;
     
    359369  ///
    360370  GraphToEps<T> &arrowWidth(double d) {_arrowWidth*=d;return *this;}
     371 
     372  ///Scales the drawing to fit to A4 page
     373
     374  ///Scales the drawing to fit to A4 page
     375  ///
     376  GraphToEps<T> &scaleToA4() {_scaleToA4=true;return *this;}
    361377 
    362378  ///Enables parallel edges
     
    442458      bb+=-p+_coords[n];
    443459      }
    444     os << "%%BoundingBox: "
    445         << bb.left()*  _scale-_xBorder << ' '
    446         << bb.bottom()*_scale-_yBorder << ' '
    447         << bb.right()* _scale+_xBorder << ' '
    448         << bb.top()*   _scale+_yBorder << '\n';
     460    if(!_scaleToA4) os << "%%BoundingBox: "
     461                      << bb.left()*  _scale-_xBorder << ' '
     462                      << bb.bottom()*_scale-_yBorder << ' '
     463                      << bb.right()* _scale+_xBorder << ' '
     464                      << bb.top()*   _scale+_yBorder << '\n';
    449465    //x1 y1 x2 y2 x3 y3 cr cg cb w
    450466    os << "/lb { setlinewidth setrgbcolor newpath moveto\n"
     
    497513
    498514    os << "\ngsave\n";
    499     if(_scale!=1.0) os << _scale << " dup scale\n";
     515    if(_scaleToA4)
     516      if(bb.height()>bb.width()) {
     517        double sc= min((A4HEIGHT-2*A4BORDER)/bb.height(),
     518                  (A4WIDTH-2*A4BORDER)/bb.width());
     519        os << ((A4WIDTH -2*A4BORDER)-sc*bb.width())/2 + A4BORDER << ' '
     520           << ((A4HEIGHT-2*A4BORDER)-sc*bb.height())/2 + A4BORDER << " translate\n"
     521           << sc << " dup scale\n"
     522           << -bb.left() << ' ' << -bb.bottom() << " translate\n";
     523      }
     524      else {
     525        //\todo Verify centering
     526        double sc= min((A4HEIGHT-2*A4BORDER)/bb.width(),
     527                  (A4WIDTH-2*A4BORDER)/bb.height());
     528        os << ((A4WIDTH -2*A4BORDER)-sc*bb.height())/2 + A4BORDER << ' '
     529           << ((A4HEIGHT-2*A4BORDER)-sc*bb.width())/2 + A4BORDER  << " translate\n"
     530           << sc << " dup scale\n90 rotate\n"
     531           << -bb.left() << ' ' << -bb.top() << " translate\n";
     532        }
     533    else if(_scale!=1.0) os << _scale << " dup scale\n";
    500534   
    501535    if(_showEdges) {
     
    659693    }
    660694   
    661     os << "grestore\n";
     695    os << "grestore\nshowpage\n";
    662696
    663697    //CleanUp:
     
    698732///Generates an EPS file from a graph
    699733
    700 //\ingroup misc
     734///\ingroup misc
    701735///This function does the same as
    702736///\ref graphToEps(G &g,std::ostream& os)
Note: See TracChangeset for help on using the changeset viewer.