[1668] | 1 | #include "graphviz.hpp" |
---|
| 2 | #include "workflow_graph.hpp" |
---|
| 3 | |
---|
| 4 | namespace xios |
---|
| 5 | { |
---|
| 6 | |
---|
| 7 | CGraphviz::CGraphviz() |
---|
| 8 | { } |
---|
| 9 | |
---|
| 10 | /*! |
---|
| 11 | * |
---|
| 12 | */ |
---|
[1679] | 13 | void CGraphviz::buildWorkflowGraphDot() |
---|
[1668] | 14 | TRY |
---|
| 15 | { |
---|
[1679] | 16 | if (CWorkflowGraph::mapFieldToFilters_ptr_with_info !=0 && !CWorkflowGraph::mapFieldToFilters_ptr_with_info->empty()) |
---|
[1668] | 17 | { |
---|
[1671] | 18 | CWorkflowGraph::buildStaticWorkflow(); |
---|
[1668] | 19 | |
---|
[1671] | 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; |
---|
[1668] | 22 | |
---|
[1671] | 23 | // Input 1: nodes (=filters) |
---|
| 24 | vector<StdString>& nodes = CWorkflowGraph::filters; |
---|
| 25 | const int nbNodes = nodes.size(); |
---|
[1668] | 26 | |
---|
[1671] | 27 | // Input 2: edges (=fields) |
---|
| 28 | vector<StdString>& edges = CWorkflowGraph::fields; |
---|
[1668] | 29 | |
---|
[1671] | 30 | // Input 3: nodes to edges connectivity |
---|
| 31 | vector<pair<int, int> >& nodesToEdges = CWorkflowGraph::fieldsToFilters; |
---|
| 32 | const int nbEdges = nodesToEdges.size(); |
---|
[1668] | 33 | |
---|
[1671] | 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 | } |
---|
[1668] | 42 | |
---|
[1671] | 43 | std::for_each(vertices(g).first, vertices(g).second, exercise_vertex<Graph>(g)); |
---|
[1668] | 44 | |
---|
[1671] | 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"; |
---|
[1668] | 52 | |
---|
[1671] | 53 | const std::string filename = "graph.dot"; |
---|
| 54 | std::ofstream file (filename.c_str()); |
---|
[1668] | 55 | |
---|
[1671] | 56 | boost::write_graphviz(file, g, |
---|
[1668] | 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)); |
---|
[1671] | 60 | |
---|
[1668] | 61 | } |
---|
| 62 | } |
---|
| 63 | CATCH |
---|
[1669] | 64 | |
---|
| 65 | |
---|
| 66 | |
---|
[1679] | 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(); |
---|
[1680] | 74 | |
---|
| 75 | StdString color_table[7] = {"black", "red", "blue", "green", "purple", "yellow", "gray"}; |
---|
[1679] | 76 | |
---|
| 77 | std::ofstream fs_json; |
---|
| 78 | fs_json.open ("graph_data.json", std::fstream::out); |
---|
| 79 | |
---|
[1680] | 80 | fs_json << "{\"nodes\":["<<std::endl<<" "; |
---|
| 81 | static bool firstnode=true; |
---|
| 82 | static bool firstedge=true; |
---|
[1679] | 83 | |
---|
| 84 | for (auto it=CWorkflowGraph::mapFilters_ptr_with_info->begin(); it != CWorkflowGraph::mapFilters_ptr_with_info->end(); it++) |
---|
| 85 | { |
---|
[1680] | 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; |
---|
[1683] | 99 | fs_json << " \"class\": "<<it->second.filter_class<<", "<<std::endl; |
---|
| 100 | fs_json << " \"filled\": "<<it->second.filter_filled<<", "<<std::endl; |
---|
[1680] | 101 | fs_json << " \"type\": \""<<it->second.transform_type<<"\", "<<std::endl; |
---|
[1683] | 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; |
---|
[1680] | 107 | fs_json << " \"attributes\": \""<<it->second.attributes<<"\"}"<<std::endl<<" "; |
---|
[1679] | 108 | } |
---|
[1680] | 109 | fs_json << " ],"<<std::endl; |
---|
[1679] | 110 | |
---|
| 111 | |
---|
[1680] | 112 | fs_json << " \"edges\" : ["<<std::endl<<" "; |
---|
| 113 | |
---|
[1679] | 114 | for (auto it=CWorkflowGraph::mapFieldToFilters_ptr_with_info->begin(); it != CWorkflowGraph::mapFieldToFilters_ptr_with_info->end(); it++) |
---|
| 115 | { |
---|
[1680] | 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 | |
---|
[1679] | 135 | } |
---|
[1680] | 136 | fs_json << " ]}"<<std::endl; |
---|
[1679] | 137 | |
---|
| 138 | fs_json.close(); |
---|
| 139 | } |
---|
| 140 | } |
---|
| 141 | CATCH |
---|
| 142 | |
---|
| 143 | |
---|
| 144 | |
---|
[1669] | 145 | void CGraphviz::showStaticWorkflowGraph() |
---|
| 146 | TRY |
---|
| 147 | { |
---|
| 148 | CWorkflowGraph::showStaticWorkflow(); |
---|
| 149 | } |
---|
| 150 | CATCH |
---|
[1668] | 151 | } |
---|