static inline bool readVizAttribute( GraphAttributes &GA, edge e, const pugi::xml_node tag) { const long attrs = GA.attributes(); if(string(tag.name()) == "viz:color") { if(attrs & GraphAttributes::edgeStyle) { return readColor(GA.strokeColor(e), tag); } } else if(string(tag.name()) == "viz:thickness") { auto thickAttr = tag.attribute("value"); if(!thickAttr) { GraphIO::logger.lout() << "Missing \"value\" on thickness tag." << std::endl; return false; } if(attrs & GraphAttributes::edgeDoubleWeight) { GA.doubleWeight(e) = thickAttr.as_double(); } else if(attrs & GraphAttributes::edgeIntWeight) { GA.intWeight(e) = thickAttr.as_int(); } } else if(string(tag.name()) == "viz:shape") { // Values: solid, dotted, dashed, double. Not supported in OGDF. } else { GraphIO::logger.lout() << "Incorrect tag \"" << tag.name() << "\"." << std::endl; return false; } return true; }
static inline void writeAttributes( std::ostream &out, int depth, const GraphAttributes &GA, edge e) { const long attrs = GA.attributes(); if(attrs & GraphAttributes::edgeStyle) { const Color &color = GA.strokeColor(e); const int red = color.red(); const int green = color.green(); const int blue = color.blue(); const int alpha = color.alpha(); GraphIO::indent(out, depth) << "<viz:color " << "red=\"" << red << "\" " << "green=\"" << green << "\" " << "blue=\"" << blue << "\" " << "alpha=\"" << alpha << "\" " << "/>\n"; } if(attrs & GraphAttributes::edgeDoubleWeight) { const double weight = GA.doubleWeight(e); GraphIO::indent(out, depth) << "<viz:thickness " << "value=\"" << weight << "\" " << "/>\n"; } else if(attrs & GraphAttributes::edgeIntWeight) { const int weight = GA.intWeight(e); GraphIO::indent(out, depth) << "<viz:thickness " << "value=\"" << weight << "\" " << "/>\n"; } /* * Edge type and arrow are not supported by VIZ module. Therefore, they * need to be written using <attvalues> tag (for estetic reasons, we write * them only if either of them is present). For convenience reasons, we use * the same names and values as in GraphML format. */ if(!(attrs & (GraphAttributes::edgeType | GraphAttributes::edgeArrow))) { return; } GraphIO::indent(out, depth) << "<attvalues>\n"; if(attrs & GraphAttributes::edgeType) { writeAttValue( out, depth + 1, graphml::a_edgeType, graphml::toString(GA.type(e))); } if(attrs & GraphAttributes::edgeArrow) { writeAttValue( out, depth + 1, graphml::a_edgeArrow, graphml::toString(GA.arrowType(e))); } GraphIO::indent(out, depth) << "</attvalues>\n"; }
static inline void writeAttributes( std::ostream &out, const GraphAttributes &GA, const edge &e) { const long flags = GA.attributes(); out << "["; bool comma = false; // Whether to put comma before attribute. if(flags & GraphAttributes::edgeLabel) { writeAttribute(out, comma, "label", GA.label(e)); } if(flags & GraphAttributes::edgeDoubleWeight) { writeAttribute(out, comma, "weight", GA.doubleWeight(e)); } else if(flags & GraphAttributes::edgeIntWeight) { writeAttribute(out, comma, "weight", GA.intWeight(e)); } if(flags & GraphAttributes::edgeGraphics) { // This should be legal cubic B-Spline in the future. std::stringstream sstream; for(const DPoint &p : GA.bends(e)) { sstream << p.m_x << "," << p.m_y << " "; } writeAttribute(out, comma, "pos", sstream.str()); } if(flags & GraphAttributes::edgeArrow) { writeAttribute(out, comma, "dir", dot::toString(GA.arrowType(e))); } if(flags & GraphAttributes::edgeStyle) { writeAttribute(out, comma, "color", GA.strokeColor(e)); } if(flags & GraphAttributes::edgeType) { writeAttribute(out, comma, "arrowhead", GA.arrowType(e)); // Additionaly, according to IBM UML doc dependency is a dashed edge. if(GA.type(e) == Graph::dependency) { writeAttribute(out, comma, "style", "dashed"); } } // NOTE: Edge subgraphs are not supported. out << "]"; }
bool GraphMLParser::readData( GraphAttributes &GA, const edge &e, const pugi::xml_node edgeData) { pugi::xml_attribute keyId = edgeData.attribute("key"); if (!keyId) { GraphIO::logger.lout() << "Edge data does not have a key." << endl; return false; } const long attrs = GA.attributes(); pugi::xml_text text = edgeData.text(); switch(graphml::toAttribute(m_attrName[keyId.value()])) { case graphml::a_edgeLabel: if(attrs & GraphAttributes::edgeLabel) { GA.label(e) = text.get(); } break; case graphml::a_edgeWeight: if(attrs & GraphAttributes::edgeIntWeight) { GA.intWeight(e) = text.as_int(); } else if(attrs & GraphAttributes::edgeDoubleWeight) { GA.doubleWeight(e) = text.as_double(); } break; case graphml::a_edgeType: if(attrs & GraphAttributes::edgeType) { GA.type(e) = graphml::toEdgeType(text.get()); } break; case graphml::a_edgeArrow: if(attrs & GraphAttributes::edgeArrow) { GA.arrowType(e) = graphml::toArrow(text.get()); } break; case graphml::a_edgeStroke: if(attrs & GraphAttributes::edgeStyle) { GA.strokeColor(e) = text.get(); } break; default: GraphIO::logger.lout(Logger::LL_MINOR) << "Unknown edge attribute with \"" << keyId.value() << "\"." << endl; } return true; }
//************************************************************* // returns GraphAttributes associated with basic graph i // void SimDraw::getBasicGraphAttributes(int i, GraphAttributes &GA, Graph &G) { G = m_G; GA.init(G,m_GA.attributes()); List<edge> LE; m_G.allEdges(LE); forall_listiterators(edge,it,LE) if(m_GA.inSubGraph(*it,i)) { node v; forall_nodes(v,G) { if(compare(GA,v,m_GA,(*it)->source())) { if(m_GA.attributes() & GraphAttributes::nodeGraphics) { GA.x(v) = m_GA.x((*it)->source()); GA.y(v) = m_GA.y((*it)->source()); GA.height(v) = m_GA.height((*it)->source()); GA.width(v) = m_GA.width((*it)->source()); } if(m_GA.attributes() & GraphAttributes::nodeId) GA.idNode(v) = m_GA.idNode((*it)->source()); if(m_GA.attributes() & GraphAttributes::nodeLabel) GA.labelNode(v) = m_GA.labelNode((*it)->source()); } if(compare(GA,v,m_GA,(*it)->target())) { if(m_GA.attributes() & GraphAttributes::nodeGraphics) { GA.x(v) = m_GA.x((*it)->target()); GA.y(v) = m_GA.y((*it)->target()); GA.height(v) = m_GA.height((*it)->target()); GA.width(v) = m_GA.width((*it)->target()); } if(m_GA.attributes() & GraphAttributes::nodeId) GA.idNode(v) = m_GA.idNode((*it)->target()); if(m_GA.attributes() & GraphAttributes::nodeLabel) GA.labelNode(v) = m_GA.labelNode((*it)->target()); } } edge e; forall_edges(e,G) { if(compare(GA,e->source(),m_GA,(*it)->source()) && compare(GA,e->target(),m_GA,(*it)->target())) { if(m_GA.attributes() & GraphAttributes::edgeIntWeight) GA.intWeight(e) = m_GA.intWeight(*it); if(m_GA.attributes() & GraphAttributes::edgeLabel) GA.labelEdge(e) = m_GA.labelEdge(*it); if(m_GA.attributes() & GraphAttributes::edgeColor) GA.colorEdge(e) = m_GA.colorEdge(*it); if(m_GA.attributes() & GraphAttributes::edgeGraphics) GA.bends(e) = m_GA.bends(*it); } } }
//************************************************************* // returns GraphAttributes associated with basic graph i // void SimDraw::getBasicGraphAttributes(int i, GraphAttributes &GA, Graph &G) { G = m_G; GA.init(G,m_GA.attributes()); List<edge> LE; m_G.allEdges(LE); for(edge eLE : LE) if(m_GA.inSubGraph(eLE,i)) { for(node v : G.nodes) { if(compare(GA,v,m_GA,eLE->source())) { if(m_GA.attributes() & GraphAttributes::nodeGraphics) { GA.x(v) = m_GA.x(eLE->source()); GA.y(v) = m_GA.y(eLE->source()); GA.height(v) = m_GA.height(eLE->source()); GA.width(v) = m_GA.width(eLE->source()); } if(m_GA.attributes() & GraphAttributes::nodeId) GA.idNode(v) = m_GA.idNode(eLE->source()); if(m_GA.attributes() & GraphAttributes::nodeLabel) GA.label(v) = m_GA.label(eLE->source()); } if(compare(GA,v,m_GA,eLE->target())) { if(m_GA.attributes() & GraphAttributes::nodeGraphics) { GA.x(v) = m_GA.x(eLE->target()); GA.y(v) = m_GA.y(eLE->target()); GA.height(v) = m_GA.height(eLE->target()); GA.width(v) = m_GA.width(eLE->target()); } if(m_GA.attributes() & GraphAttributes::nodeId) GA.idNode(v) = m_GA.idNode(eLE->target()); if(m_GA.attributes() & GraphAttributes::nodeLabel) GA.label(v) = m_GA.label(eLE->target()); } } for(edge e : G.edges) { if(compare(GA,e->source(),m_GA,eLE->source()) && compare(GA,e->target(),m_GA,eLE->target())) { if(m_GA.attributes() & GraphAttributes::edgeIntWeight) GA.intWeight(e) = m_GA.intWeight(eLE); if(m_GA.attributes() & GraphAttributes::edgeLabel) GA.label(e) = m_GA.label(eLE); if(m_GA.attributes() & GraphAttributes::edgeStyle) GA.strokeColor(e) = m_GA.strokeColor(eLE); if(m_GA.attributes() & GraphAttributes::edgeGraphics) GA.bends(e) = m_GA.bends(eLE); } } } else { List<edge> LE2; G.allEdges(LE2); for(edge e2 : LE2) { if(compare(GA,e2->source(),m_GA,eLE->source()) && compare(GA,e2->target(),m_GA,eLE->target())) { G.delEdge(e2); } } } //remove all Nodes with degree == 0 //this can change the IDs of the nodes in G. List<node> LN; G.allNodes(LN); for(node v : LN) if(v->degree() == 0) G.delNode(v); }//end getBasicGraphAttributes