[1704] | 1 | #include "graphviz.hpp" |
---|
| 2 | #include "workflow_graph.hpp" |
---|
| 3 | |
---|
| 4 | namespace xios |
---|
| 5 | { |
---|
| 6 | |
---|
| 7 | CGraphviz::CGraphviz() |
---|
| 8 | { } |
---|
| 9 | |
---|
| 10 | /*! |
---|
| 11 | * |
---|
| 12 | */ |
---|
| 13 | void CGraphviz::buildWorkflowGraphDot() |
---|
| 14 | TRY |
---|
| 15 | { |
---|
| 16 | if (CWorkflowGraph::mapFieldToFilters_ptr_with_info !=0 && !CWorkflowGraph::mapFieldToFilters_ptr_with_info->empty()) |
---|
| 17 | { |
---|
| 18 | CWorkflowGraph::buildStaticWorkflow(); |
---|
| 19 | |
---|
| 20 | typedef boost::property<boost::edge_name_t, std::string> EdgeProperty; |
---|
| 21 | typedef boost::adjacency_list<boost::vecS, boost::vecS, boost::directedS, boost::no_property, EdgeProperty> Graph; |
---|
| 22 | |
---|
| 23 | // Input 1: nodes (=filters) |
---|
| 24 | vector<StdString>& nodes = CWorkflowGraph::filters; |
---|
| 25 | const int nbNodes = nodes.size(); |
---|
| 26 | |
---|
| 27 | // Input 2: edges (=fields) |
---|
| 28 | vector<StdString>& edges = CWorkflowGraph::fields; |
---|
| 29 | |
---|
| 30 | // Input 3: nodes to edges connectivity |
---|
| 31 | vector<pair<int, int> >& nodesToEdges = CWorkflowGraph::fieldsToFilters; |
---|
| 32 | const int nbEdges = nodesToEdges.size(); |
---|
| 33 | |
---|
| 34 | // Declare a graph object, adding the edges and edge properties |
---|
| 35 | Graph g(nbNodes); |
---|
| 36 | for (int j = 0; j < nbEdges; ++j) |
---|
| 37 | { |
---|
| 38 | graph_traits<Graph>::edge_descriptor e; |
---|
| 39 | bool inserted; |
---|
| 40 | boost::tie(e, inserted) = boost::add_edge(nodesToEdges[j].first, nodesToEdges[j].second, edges[j], g); |
---|
| 41 | } |
---|
| 42 | |
---|
| 43 | std::for_each(vertices(g).first, vertices(g).second, exercise_vertex<Graph>(g)); |
---|
| 44 | |
---|
| 45 | std::map<std::string,std::string> graph_attr, vertex_attr, edge_attr; |
---|
| 46 | graph_attr["size"] = "5,5"; |
---|
| 47 | graph_attr["rankdir"] = "LR"; |
---|
| 48 | graph_attr["ratio"] = "fill"; |
---|
| 49 | vertex_attr["shape"] = "record"; |
---|
| 50 | vertex_attr["width"] = "2.2"; |
---|
| 51 | vertex_attr["fontsize"] = "16"; |
---|
| 52 | |
---|
| 53 | const std::string filename = "graph.dot"; |
---|
| 54 | std::ofstream file (filename.c_str()); |
---|
| 55 | |
---|
| 56 | boost::write_graphviz(file, g, |
---|
| 57 | boost::make_label_writer(&nodes[0]), |
---|
| 58 | boost::make_label_writer(get(edge_name, g)), |
---|
| 59 | boost::make_graph_attributes_writer(graph_attr, vertex_attr, edge_attr)); |
---|
| 60 | |
---|
| 61 | } |
---|
| 62 | } |
---|
| 63 | CATCH |
---|
| 64 | |
---|
| 65 | |
---|
| 66 | |
---|
| 67 | |
---|
| 68 | void CGraphviz::buildWorkflowGraphVisjs_with_info() |
---|
| 69 | TRY |
---|
| 70 | { |
---|
| 71 | if (CWorkflowGraph::mapFilters_ptr_with_info !=0 && !CWorkflowGraph::mapFilters_ptr_with_info->empty()) |
---|
| 72 | { |
---|
| 73 | CWorkflowGraph::buildStaticWorkflow_with_info(); |
---|
| 74 | |
---|
| 75 | StdString color_table[7] = {"black", "red", "blue", "green", "purple", "yellow", "gray"}; |
---|
| 76 | |
---|
| 77 | std::ofstream fs_json; |
---|
| 78 | fs_json.open ("graph_data.json", std::fstream::out); |
---|
| 79 | |
---|
| 80 | fs_json << "{\"nodes\":["<<std::endl<<" "; |
---|
| 81 | static bool firstnode=true; |
---|
| 82 | static bool firstedge=true; |
---|
| 83 | |
---|
| 84 | for (auto it=CWorkflowGraph::mapFilters_ptr_with_info->begin(); it != CWorkflowGraph::mapFilters_ptr_with_info->end(); it++) |
---|
| 85 | { |
---|
| 86 | if(firstnode) |
---|
| 87 | { |
---|
| 88 | fs_json << "{\"id\": "<<it->first +1<<", "<<std::endl; |
---|
| 89 | firstnode = false; |
---|
| 90 | } |
---|
| 91 | else |
---|
| 92 | { |
---|
| 93 | fs_json << ",{\"id\": "<<it->first +1<<", "<<std::endl; |
---|
| 94 | } |
---|
| 95 | if(it->second.filter_class == 1) // source filter |
---|
| 96 | fs_json << " \"label\": \""<<it->second.filter_name<<"\\n("<<it->second.field_id<<")\", "<<std::endl; |
---|
| 97 | else |
---|
| 98 | fs_json << " \"label\": \""<<it->second.filter_name<<"\", "<<std::endl; |
---|
| 99 | fs_json << " \"class\": "<<it->second.filter_class<<", "<<std::endl; |
---|
| 100 | fs_json << " \"filled\": "<<it->second.filter_filled<<", "<<std::endl; |
---|
| 101 | fs_json << " \"type\": \""<<it->second.transform_type<<"\", "<<std::endl; |
---|
| 102 | fs_json << " \"entry\": "<<it->second.expected_entry_nb<<", "<<std::endl; |
---|
| 103 | fs_json << " \"inputs\": "<<it->second.inputs_complete<<", "<<std::endl; |
---|
| 104 | fs_json << " \"tag\": "<<it->second.filter_tag<<", "<<std::endl; |
---|
| 105 | fs_json << " \"cid\": "<<it->second.clusterID<<", "<<std::endl; |
---|
| 106 | fs_json << " \"distance\": "<<it->second.distance<<", "<<std::endl; |
---|
| 107 | fs_json << " \"attributes\": \""<<it->second.attributes<<"\"}"<<std::endl<<" "; |
---|
| 108 | } |
---|
| 109 | fs_json << " ],"<<std::endl; |
---|
| 110 | |
---|
| 111 | |
---|
| 112 | fs_json << " \"edges\" : ["<<std::endl<<" "; |
---|
| 113 | |
---|
| 114 | for (auto it=CWorkflowGraph::mapFieldToFilters_ptr_with_info->begin(); it != CWorkflowGraph::mapFieldToFilters_ptr_with_info->end(); it++) |
---|
| 115 | { |
---|
| 116 | if(firstedge) |
---|
| 117 | { |
---|
| 118 | fs_json << "{\"id\": "<<it->first +1<<", "<<std::endl; |
---|
| 119 | firstedge = false; |
---|
| 120 | } |
---|
| 121 | else |
---|
| 122 | { |
---|
| 123 | fs_json << ",{\"id\": "<<it->first +1<<", "<<std::endl; |
---|
| 124 | } |
---|
| 125 | fs_json << " \"from\": "<<it->second.from+1<<", "<<std::endl; |
---|
| 126 | fs_json << " \"to\": "<<it->second.to+1<<", "<<std::endl; |
---|
| 127 | fs_json << " \"label\": \""<<it->second.field_id<<"\\n"<<it->second.date<<"\", "<<std::endl; |
---|
| 128 | // fs_json << " \"title\": \""<<"Show more information about this field"<<"\", "<<std::endl; |
---|
| 129 | // fs_json << " \"fid\": \""<<it->second.field_id<<"\", "<<std::endl; |
---|
| 130 | // fs_json << " \"fname\": \""<<it->second.field_name<<"\", "<<std::endl; |
---|
| 131 | // fs_json << " \"gid\": \""<<it->second.grid_id<<"\", "<<std::endl; |
---|
| 132 | fs_json << " \"date\": \""<<it->second.date<<"\", "<<std::endl; |
---|
| 133 | fs_json << " \"attributes\": \"id = "<<it->second.field_id<<"</br>"<<it->second.attributes<<"\"}"<<std::endl<<" "; |
---|
| 134 | |
---|
| 135 | } |
---|
| 136 | fs_json << " ]}"<<std::endl; |
---|
| 137 | |
---|
| 138 | fs_json.close(); |
---|
| 139 | } |
---|
| 140 | } |
---|
| 141 | CATCH |
---|
| 142 | |
---|
| 143 | |
---|
| 144 | |
---|
| 145 | void CGraphviz::showStaticWorkflowGraph() |
---|
| 146 | TRY |
---|
| 147 | { |
---|
| 148 | CWorkflowGraph::showStaticWorkflow(); |
---|
| 149 | } |
---|
| 150 | CATCH |
---|
| 151 | } |
---|