lemon/graph_to_eps.h
changeset 1606 dc4ea2010dee
parent 1588 b79bcba43661
child 1642 a2dda876316f
equal deleted inserted replaced
7:d112fee9f094 8:287daa7b9352
   232 
   232 
   233   enum NodeTextColorType 
   233   enum NodeTextColorType 
   234     { DIST_COL=0, DIST_BW=1, CUST_COL=2, SAME_COL=3 } _nodeTextColorType;
   234     { DIST_COL=0, DIST_BW=1, CUST_COL=2, SAME_COL=3 } _nodeTextColorType;
   235   ConstMap<typename Graph::Node,Color > _nodeTextColors;
   235   ConstMap<typename Graph::Node,Color > _nodeTextColors;
   236 
   236 
       
   237   bool _autoNodeScale;
       
   238   bool _autoEdgeWidthScale;
       
   239 
   237   ///Constructor
   240   ///Constructor
   238 
   241 
   239   ///Constructor
   242   ///Constructor
   240   ///\param _g is a reference to the graph to be printed
   243   ///\param _g is a reference to the graph to be printed
   241   ///\param _os is a reference to the output stream.
   244   ///\param _os is a reference to the output stream.
   256     _enableParallel(false), _parEdgeDist(1),
   259     _enableParallel(false), _parEdgeDist(1),
   257     _showNodeText(false), _nodeTexts(false), _nodeTextSize(1),
   260     _showNodeText(false), _nodeTexts(false), _nodeTextSize(1),
   258     _showNodePsText(false), _nodePsTexts(false), _nodePsTextsPreamble(0),
   261     _showNodePsText(false), _nodePsTexts(false), _nodePsTextsPreamble(0),
   259     _undir(false),
   262     _undir(false),
   260     _pleaseRemoveOsStream(_pros), _scaleToA4(false),
   263     _pleaseRemoveOsStream(_pros), _scaleToA4(false),
   261     _nodeTextColorType(SAME_COL), _nodeTextColors(Color(0,0,0))
   264     _nodeTextColorType(SAME_COL), _nodeTextColors(Color(0,0,0)),
       
   265     _autoNodeScale(false),
       
   266     _autoEdgeWidthScale(false)
   262   {}
   267   {}
   263 };
   268 };
   264 
   269 
   265 ///Helper class to implement the named parameters of \ref graphToEps()
   270 ///Helper class to implement the named parameters of \ref graphToEps()
   266 
   271 
   322   using T::CUST_COL;
   327   using T::CUST_COL;
   323   using T::DIST_COL;
   328   using T::DIST_COL;
   324   using T::DIST_BW;
   329   using T::DIST_BW;
   325   using T::_nodeTextColorType;
   330   using T::_nodeTextColorType;
   326   using T::_nodeTextColors;
   331   using T::_nodeTextColors;
       
   332 
       
   333   using T::_autoNodeScale;
       
   334   using T::_autoEdgeWidthScale;
       
   335 
   327   // dradnats ++C eht yb deriuqer si ti eveileb t'naC
   336   // dradnats ++C eht yb deriuqer si ti eveileb t'naC
   328 
   337 
   329   typedef typename T::Graph Graph;
   338   typedef typename T::Graph Graph;
   330   typedef typename Graph::Node Node;
   339   typedef typename Graph::Node Node;
   331   typedef typename Graph::NodeIt NodeIt;
   340   typedef typename Graph::NodeIt NodeIt;
   549     dontPrint=true;
   558     dontPrint=true;
   550     return GraphToEps<EdgeColorsTraits<X> >(EdgeColorsTraits<X>(*this,x));
   559     return GraphToEps<EdgeColorsTraits<X> >(EdgeColorsTraits<X>(*this,x));
   551   }
   560   }
   552   ///Sets a global scale factor for node sizes
   561   ///Sets a global scale factor for node sizes
   553 
   562 
   554   ///Sets a global scale factor for node sizes
   563   ///Sets a global scale factor for node sizes.
   555   ///
   564   /// 
       
   565   /// If nodeSizes() is not given, this function simply sets the node
       
   566   /// sizes to \c d.  If nodeSizes() is given, but
       
   567   /// autoNodeScale() is not, then the node size given by
       
   568   /// nodeSizes() will be multiplied by the value \c d.
       
   569   /// If both nodeSizes() and autoNodeScale() are used, then the
       
   570   /// node sizes will be scaled in such a way that the greatest size will be
       
   571   /// equal to \c d.
   556   GraphToEps<T> &nodeScale(double d) {_nodeScale=d;return *this;}
   572   GraphToEps<T> &nodeScale(double d) {_nodeScale=d;return *this;}
       
   573   ///Turns on/off the automatic node width scaling.
       
   574 
       
   575   ///Turns on/off the automatic node width scaling.
       
   576   ///
       
   577   ///\sa nodeScale()
       
   578   ///
       
   579   GraphToEps<T> &autoNodeScale(bool b=true) {
       
   580     _autoNodeScale=b;return *this;
       
   581   }
   557   ///Sets a global scale factor for edge widths
   582   ///Sets a global scale factor for edge widths
   558 
   583 
   559   ///Sets a global scale factor for edge widths
   584   /// Sets a global scale factor for edge widths.
   560   ///
   585   ///
       
   586   /// If edgeWidths() is not given, this function simply sets the edge
       
   587   /// widths to \c d.  If edgeWidths() is given, but
       
   588   /// autoEdgeWidthScale() is not, then the edge withs given by
       
   589   /// edgeWidths() will be multiplied by the value \c d.
       
   590   /// If both edgeWidths() and autoEdgeWidthScale() are used, then the
       
   591   /// edge withs will be scaled in such a way that the greatest width will be
       
   592   /// equal to \c d.
   561   GraphToEps<T> &edgeWidthScale(double d) {_edgeWidthScale=d;return *this;}
   593   GraphToEps<T> &edgeWidthScale(double d) {_edgeWidthScale=d;return *this;}
       
   594   ///Turns on/off the automatic edge width scaling.
       
   595 
       
   596   ///Turns on/off the automatic edge width scaling.
       
   597   ///
       
   598   ///\sa edgeWidthScale()
       
   599   ///
       
   600   GraphToEps<T> &autoEdgeWidthScale(bool b=true) {
       
   601     _autoEdgeWidthScale=b;return *this;
       
   602   }
   562   ///Sets a global scale factor for the whole picture
   603   ///Sets a global scale factor for the whole picture
   563 
   604 
   564   ///Sets a global scale factor for the whole picture
   605   ///Sets a global scale factor for the whole picture
   565   ///
   606   ///
       
   607 
   566   GraphToEps<T> &scale(double d) {_scale=d;return *this;}
   608   GraphToEps<T> &scale(double d) {_scale=d;return *this;}
   567   ///Sets the width of the border around the picture
   609   ///Sets the width of the border around the picture
   568 
   610 
   569   ///Sets the width of the border around the picture
   611   ///Sets the width of the border around the picture
   570   ///
   612   ///
   712       timeval tv;
   754       timeval tv;
   713       gettimeofday(&tv, 0);
   755       gettimeofday(&tv, 0);
   714       ctime_r(&tv.tv_sec,cbuf);
   756       ctime_r(&tv.tv_sec,cbuf);
   715       os << "%%CreationDate: " << cbuf;
   757       os << "%%CreationDate: " << cbuf;
   716     }
   758     }
       
   759 
       
   760     if (_autoEdgeWidthScale) {
       
   761       double max_w=0;
       
   762       for(EdgeIt e(g);e!=INVALID;++e)
       
   763 	max_w=std::max(double(_edgeWidths[e]),max_w);
       
   764       ///\todo better 'epsilon' would be nice here.
       
   765       if(max_w>1e-9) {
       
   766 	_edgeWidthScale/=max_w;
       
   767       }
       
   768     }
       
   769 
       
   770     if (_autoNodeScale) {
       
   771       double max_s=0;
       
   772       for(NodeIt n(g);n!=INVALID;++n)
       
   773 	max_s=std::max(double(_nodeSizes[n]),max_s);
       
   774       ///\todo better 'epsilon' would be nice here.
       
   775       if(max_s>1e-9) {
       
   776 	_nodeScale/=max_s;
       
   777       }
       
   778     }
       
   779 
       
   780 
   717     BoundingBox<double> bb;
   781     BoundingBox<double> bb;
   718     ///\bug: Chech whether the graph is empty.
   782     ///\bug: Chech whether the graph is empty.
   719     for(NodeIt n(g);n!=INVALID;++n) {
   783     for(NodeIt n(g);n!=INVALID;++n) {
   720       double ns=_nodeSizes[n]*_nodeScale;
   784       double ns=_nodeSizes[n]*_nodeScale;
   721       xy<double> p(ns,ns);
   785       xy<double> p(ns,ns);
   723       bb.add(-p+_coords[n]);
   787       bb.add(-p+_coords[n]);
   724     }
   788     }
   725     if (bb.empty()) {
   789     if (bb.empty()) {
   726       bb = BoundingBox<double>(xy<double>(0,0));
   790       bb = BoundingBox<double>(xy<double>(0,0));
   727     }
   791     }
       
   792     
   728     if(_scaleToA4)
   793     if(_scaleToA4)
   729       os <<"%%BoundingBox: 0 0 596 842\n%%DocumentPaperSizes: a4\n";
   794       os <<"%%BoundingBox: 0 0 596 842\n%%DocumentPaperSizes: a4\n";
   730     else os << "%%BoundingBox: "
   795     else os << "%%BoundingBox: "
   731 	    << bb.left()   * _scale - _xBorder << ' '
   796 	    << bb.left()   * _scale - _xBorder << ' '
   732 	    << bb.bottom() * _scale - _yBorder << ' '
   797 	    << bb.bottom() * _scale - _yBorder << ' '