[Lemon-commits] [lemon_svn] alpar: r2109 - hugo/trunk/lemon
Lemon SVN
svn at lemon.cs.elte.hu
Mon Nov 6 20:50:13 CET 2006
Author: alpar
Date: Thu Jul 28 21:05:45 2005
New Revision: 2109
Modified:
hugo/trunk/lemon/graph_to_eps.h
Log:
Edge width and node size autoscaling added.
Modified: hugo/trunk/lemon/graph_to_eps.h
==============================================================================
--- hugo/trunk/lemon/graph_to_eps.h (original)
+++ hugo/trunk/lemon/graph_to_eps.h Thu Jul 28 21:05:45 2005
@@ -234,6 +234,9 @@
{ DIST_COL=0, DIST_BW=1, CUST_COL=2, SAME_COL=3 } _nodeTextColorType;
ConstMap<typename Graph::Node,Color > _nodeTextColors;
+ bool _autoNodeScale;
+ bool _autoEdgeWidthScale;
+
///Constructor
///Constructor
@@ -258,7 +261,9 @@
_showNodePsText(false), _nodePsTexts(false), _nodePsTextsPreamble(0),
_undir(false),
_pleaseRemoveOsStream(_pros), _scaleToA4(false),
- _nodeTextColorType(SAME_COL), _nodeTextColors(Color(0,0,0))
+ _nodeTextColorType(SAME_COL), _nodeTextColors(Color(0,0,0)),
+ _autoNodeScale(false),
+ _autoEdgeWidthScale(false)
{}
};
@@ -324,6 +329,10 @@
using T::DIST_BW;
using T::_nodeTextColorType;
using T::_nodeTextColors;
+
+ using T::_autoNodeScale;
+ using T::_autoEdgeWidthScale;
+
// dradnats ++C eht yb deriuqer si ti eveileb t'naC
typedef typename T::Graph Graph;
@@ -551,18 +560,51 @@
}
///Sets a global scale factor for node sizes
- ///Sets a global scale factor for node sizes
- ///
+ ///Sets a global scale factor for node sizes.
+ ///
+ /// If nodeSizes() is not given, this function simply sets the node
+ /// sizes to \c d. If nodeSizes() is given, but
+ /// autoNodeScale() is not, then the node size given by
+ /// nodeSizes() will be multiplied by the value \c d.
+ /// If both nodeSizes() and autoNodeScale() are used, then the
+ /// node sizes will be scaled in such a way that the greatest size will be
+ /// equal to \c d.
GraphToEps<T> &nodeScale(double d) {_nodeScale=d;return *this;}
- ///Sets a global scale factor for edge widths
+ ///Turns on/off the automatic node width scaling.
+ ///Turns on/off the automatic node width scaling.
+ ///
+ ///\sa nodeScale()
+ ///
+ GraphToEps<T> &autoNodeScale(bool b=true) {
+ _autoNodeScale=b;return *this;
+ }
///Sets a global scale factor for edge widths
+
+ /// Sets a global scale factor for edge widths.
///
+ /// If edgeWidths() is not given, this function simply sets the edge
+ /// widths to \c d. If edgeWidths() is given, but
+ /// autoEdgeWidthScale() is not, then the edge withs given by
+ /// edgeWidths() will be multiplied by the value \c d.
+ /// If both edgeWidths() and autoEdgeWidthScale() are used, then the
+ /// edge withs will be scaled in such a way that the greatest width will be
+ /// equal to \c d.
GraphToEps<T> &edgeWidthScale(double d) {_edgeWidthScale=d;return *this;}
+ ///Turns on/off the automatic edge width scaling.
+
+ ///Turns on/off the automatic edge width scaling.
+ ///
+ ///\sa edgeWidthScale()
+ ///
+ GraphToEps<T> &autoEdgeWidthScale(bool b=true) {
+ _autoEdgeWidthScale=b;return *this;
+ }
///Sets a global scale factor for the whole picture
///Sets a global scale factor for the whole picture
///
+
GraphToEps<T> &scale(double d) {_scale=d;return *this;}
///Sets the width of the border around the picture
@@ -714,6 +756,28 @@
ctime_r(&tv.tv_sec,cbuf);
os << "%%CreationDate: " << cbuf;
}
+
+ if (_autoEdgeWidthScale) {
+ double max_w=0;
+ for(EdgeIt e(g);e!=INVALID;++e)
+ max_w=std::max(double(_edgeWidths[e]),max_w);
+ ///\todo better 'epsilon' would be nice here.
+ if(max_w>1e-9) {
+ _edgeWidthScale/=max_w;
+ }
+ }
+
+ if (_autoNodeScale) {
+ double max_s=0;
+ for(NodeIt n(g);n!=INVALID;++n)
+ max_s=std::max(double(_nodeSizes[n]),max_s);
+ ///\todo better 'epsilon' would be nice here.
+ if(max_s>1e-9) {
+ _nodeScale/=max_s;
+ }
+ }
+
+
BoundingBox<double> bb;
///\bug: Chech whether the graph is empty.
for(NodeIt n(g);n!=INVALID;++n) {
@@ -725,6 +789,7 @@
if (bb.empty()) {
bb = BoundingBox<double>(xy<double>(0,0));
}
+
if(_scaleToA4)
os <<"%%BoundingBox: 0 0 596 842\n%%DocumentPaperSizes: a4\n";
else os << "%%BoundingBox: "
More information about the Lemon-commits
mailing list