File indexing completed on 2025-01-18 09:11:31
0001
0002
0003
0004
0005
0006
0007
0008
0009 #include "Acts/Utilities/GraphViz.hpp"
0010
0011 #include <algorithm>
0012 #include <sstream>
0013 #include <string>
0014
0015 #include <boost/algorithm/string/join.hpp>
0016
0017 namespace Acts::GraphViz {
0018
0019 std::ostream& operator<<(std::ostream& os, const Shape& shape) {
0020 switch (shape) {
0021 using enum Shape;
0022
0023 case Box:
0024 os << "box";
0025 break;
0026 case Polygon:
0027 os << "polygon";
0028 break;
0029 case Ellipse:
0030 os << "ellipse";
0031 break;
0032 case Oval:
0033 os << "oval";
0034 break;
0035 case Circle:
0036 os << "circle";
0037 break;
0038 case Point:
0039 os << "point";
0040 break;
0041 case Egg:
0042 os << "egg";
0043 break;
0044 case Triangle:
0045 os << "triangle";
0046 break;
0047 case Plaintext:
0048 os << "plaintext";
0049 break;
0050 case Plain:
0051 os << "plain";
0052 break;
0053 case Diamond:
0054 os << "diamond";
0055 break;
0056 case Trapezium:
0057 os << "trapezium";
0058 break;
0059 case Parallelogram:
0060 os << "parallelogram";
0061 break;
0062 case House:
0063 os << "house";
0064 break;
0065 case Pentagon:
0066 os << "pentagon";
0067 break;
0068 case Hexagon:
0069 os << "hexagon";
0070 break;
0071 case Septagon:
0072 os << "septagon";
0073 break;
0074 case Octagon:
0075 os << "octagon";
0076 break;
0077 case DoubleCircle:
0078 os << "doublecircle";
0079 break;
0080 case DoubleOctagon:
0081 os << "doubleoctagon";
0082 break;
0083 case TripleOctagon:
0084 os << "tripleoctagon";
0085 break;
0086 case InvTriangle:
0087 os << "invtriangle";
0088 break;
0089 case InvTrapezium:
0090 os << "invtrapezium";
0091 break;
0092 case InvHouse:
0093 os << "invhouse";
0094 break;
0095 case Mdiamond:
0096 os << "Mdiamond";
0097 break;
0098 case Msquare:
0099 os << "Msquare";
0100 break;
0101 case Mcircle:
0102 os << "Mcircle";
0103 break;
0104 case Rect:
0105 os << "rect";
0106 break;
0107 case Rectangle:
0108 os << "rectangle";
0109 break;
0110 case Square:
0111 os << "square";
0112 break;
0113 case Star:
0114 os << "star";
0115 break;
0116 case None:
0117 os << "none";
0118 break;
0119 case Underline:
0120 os << "underline";
0121 break;
0122 case Cylinder:
0123 os << "cylinder";
0124 break;
0125 case Note:
0126 os << "note";
0127 break;
0128 case Tab:
0129 os << "tab";
0130 break;
0131 case Folder:
0132 os << "folder";
0133 break;
0134 case Box3d:
0135 os << "box3d";
0136 break;
0137 case Component:
0138 os << "component";
0139 break;
0140 case Promoter:
0141 os << "promoter";
0142 break;
0143 case Cds:
0144 os << "cds";
0145 break;
0146 case Terminator:
0147 os << "terminator";
0148 break;
0149 case Utr:
0150 os << "utr";
0151 break;
0152 case PrimerSite:
0153 os << "primersite";
0154 break;
0155 case RestrictionSite:
0156 os << "restrictionsite";
0157 break;
0158 case FivePOverhang:
0159 os << "fivepoverhang";
0160 break;
0161 case ThreePOverhang:
0162 os << "threepoverhang";
0163 break;
0164 case NOverhang:
0165 os << "noverhang";
0166 break;
0167 case Assembly:
0168 os << "assembly";
0169 break;
0170 case Signature:
0171 os << "signature";
0172 break;
0173 case Insulator:
0174 os << "insulator";
0175 break;
0176 case Ribosite:
0177 os << "ribosite";
0178 break;
0179 case RNAStab:
0180 os << "rnastab";
0181 break;
0182 case ProteaseSite:
0183 os << "proteasesite";
0184 break;
0185 case ProteinStab:
0186 os << "proteinstab";
0187 break;
0188 case RPromoter:
0189 os << "rpromoter";
0190 break;
0191 case RArrow:
0192 os << "rarrow";
0193 break;
0194 case LArrow:
0195 os << "larrow";
0196 break;
0197 case LPromoter:
0198 os << "lpromoter";
0199 break;
0200 default:
0201 std::terminate();
0202 }
0203
0204 return os;
0205 }
0206
0207 std::ostream& operator<<(std::ostream& os, const Style& style) {
0208 switch (style) {
0209 using enum Style;
0210 case Filled:
0211 os << "filled";
0212 break;
0213 case Invisible:
0214 os << "invisible";
0215 break;
0216 case Diagonals:
0217 os << "diagonals";
0218 break;
0219 case Rounded:
0220 os << "rounded";
0221 break;
0222 case Dashed:
0223 os << "dashed";
0224 break;
0225 case Dotted:
0226 os << "dotted";
0227 break;
0228 case Solid:
0229 os << "solid";
0230 break;
0231 case Bold:
0232 os << "bold";
0233 break;
0234 default:
0235 os << "unknown";
0236 break;
0237 }
0238 return os;
0239 }
0240
0241 std::ostream& operator<<(std::ostream& os, const Node& node) {
0242 if (node.id.empty()) {
0243 throw std::runtime_error("Node id must not be empty");
0244 }
0245
0246 std::string id = node.id;
0247 std::ranges::replace(id, ' ', '_');
0248 os << id << " [";
0249
0250 std::vector<std::string> attributes;
0251
0252 std::vector<std::string> styles;
0253 std::ranges::transform(node.style, std::back_inserter(styles),
0254 [](const Style& style) {
0255 std::stringstream ss;
0256 ss << style;
0257 return ss.str();
0258 });
0259
0260 if (!node.label.empty()) {
0261 attributes.push_back("label=<" + node.label + ">");
0262 }
0263
0264 std::stringstream ss;
0265 ss << node.shape;
0266 attributes.push_back("shape=" + ss.str());
0267
0268 attributes.push_back("style=" + boost::algorithm::join(styles, ","));
0269
0270 os << boost::algorithm::join(attributes, ", ");
0271
0272 os << "];\n";
0273 return os;
0274 }
0275
0276 std::ostream& operator<<(std::ostream& os, const Edge& node) {
0277 os << node.from.id << " -> " << node.to.id << " [";
0278
0279 os << "style=" << node.style;
0280
0281 os << "];\n";
0282
0283 return os;
0284 }
0285
0286 }