Ignore:
Timestamp:
07/02/19 11:42:27 (5 years ago)
Author:
yushan
Message:

MARK: Dynamic workflow graph developement. Branch up to date with trunk @1676. Using vis.js

File:
1 edited

Legend:

Unmodified
Added
Removed
  • XIOS/dev/dev_trunk_omp/src/graphviz.cpp

    r1671 r1679  
    1111   * 
    1212   */ 
    13   void CGraphviz::buildStaticWorkflowGraph() 
     13  void CGraphviz::buildWorkflowGraphDot() 
    1414  TRY 
    1515  { 
    16     if (CWorkflowGraph::mapFieldToFilters_ptr !=0 && !CWorkflowGraph::mapFieldToFilters_ptr->empty()) 
     16    if (CWorkflowGraph::mapFieldToFilters_ptr_with_info !=0 && !CWorkflowGraph::mapFieldToFilters_ptr_with_info->empty()) 
    1717    { 
    1818      CWorkflowGraph::buildStaticWorkflow(); 
     
    6565 
    6666 
     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      std::ofstream fs_json; 
     76      fs_json.open ("graph_data.json", std::fstream::out); 
     77 
     78      fs_json << "{ \"node\" : ["<<std::endl; 
     79     
     80      for (auto it=CWorkflowGraph::mapFilters_ptr_with_info->begin(); it != CWorkflowGraph::mapFilters_ptr_with_info->end(); it++) 
     81      { 
     82        fs_json << "        {\"id\": "<<it->first +1<<"}, "<<std::endl; 
     83        fs_json << "            {\"label\": \""<<it->second.filter_name<<"\"}, "<<std::endl  ; 
     84        fs_json << "            {\"class\": "<<it->second.filter_class<<"}, "<<std::endl  ; 
     85        fs_json << "            {\"filled\": "<<it->second.filter_filled<<"}, "<<std::endl  ; 
     86        fs_json << "            {\"entry\": "<<it->second.expected_entry_nb<<"}, "<<std::endl  ; 
     87        // fs_json << "            {\"date\": \""<<it->second.date<<"\"}, "<<std::endl  ; 
     88        fs_json << "            {\"type\": \""<<it->second.transform_type<<"\"}, "<<std::endl  ; 
     89      } 
     90      fs_json << "    ]}"<<std::endl<<std::endl; 
     91 
     92      fs_json << "{ \"edge\" : ["<<std::endl; 
     93 
     94      for (auto it=CWorkflowGraph::mapFieldToFilters_ptr_with_info->begin(); it != CWorkflowGraph::mapFieldToFilters_ptr_with_info->end(); it++) 
     95      { 
     96        fs_json << "        {\"id\": "<<it->first +1<<"}, "<<std::endl; 
     97        fs_json << "            {\"from\": "<<it->second.from +1<<"}, "<<std::endl; 
     98        fs_json << "            {\"to\": "<<it->second.to+1<<"}, "<<std::endl  ; 
     99        fs_json << "            {\"fid\": \""<<it->second.field_id<<"\"}, "<<std::endl  ; 
     100        fs_json << "            {\"fname\": \""<<it->second.field_name<<"\"}, "<<std::endl  ; 
     101        fs_json << "            {\"gid\": \""<<it->second.grid_id<<"\"}, "<<std::endl  ; 
     102        fs_json << "            {\"date\": \""<<it->second.date<<"\"}, "<<std::endl  ; 
     103      } 
     104      fs_json << "    ]}"<<std::endl<<std::endl; 
     105 
     106 
     107       
     108 
     109       
     110 
     111      fs_json.close(); 
     112 
     113 
     114 
     115 
     116      std::ofstream fs; 
     117      fs.open ("graph_with_info.html", std::fstream::out); 
     118 
     119      fs << "<html>" <<std::endl; 
     120      fs << "<head>" <<std::endl; 
     121      fs << "    <script type=\"text/javascript\" src=\"../../../vis-4.21.0/dist/vis.js\"></script>" <<std::endl; 
     122      fs << "    <link href=\"../../../vis-4.21.0/dist/vis.css\" rel=\"stylesheet\" type=\"text/css\" />" <<std::endl <<std::endl; 
     123      fs << "    <style type=\"text/css\">"<<std::endl; 
     124      fs << "        #mynetwork {"<<std::endl; 
     125      fs << "            width: 1000px;"<<std::endl; 
     126      fs << "            height: 800px;"<<std::endl; 
     127      fs << "            border: 1px solid lightgray"<<std::endl; 
     128      fs << "        }"<<std::endl; 
     129      fs << "    </style>"<<std::endl; 
     130      fs << "</head>"<<std::endl; 
     131      fs << "<body>"<<std::endl; 
     132      fs << "<div id=\"mynetwork\"></div>"<<std::endl<<std::endl; 
     133      fs << "<script type=\"text/javascript\">"<<std::endl; 
     134 
     135      fs << "    var nodes = new vis.DataSet(["<<std::endl; 
     136      for(int i=0; i<CWorkflowGraph::filters.size(); i++) 
     137      { 
     138        fs << "        {id: "<<i+1<<", label: \'"<<CWorkflowGraph::filters[i]<<"\'},"<<std::endl  ; 
     139      } 
     140      fs << "    ]);"<<std::endl<<std::endl; 
     141 
     142 
     143      fs << "    var edges = new vis.DataSet(["<<std::endl; 
     144      for(int i=0; i<CWorkflowGraph::fieldsToFilters.size(); i++) 
     145      { 
     146        fs <<"        {from: "<<CWorkflowGraph::fieldsToFilters[i].first+1<<", to: "<<CWorkflowGraph::fieldsToFilters[i].second+1<<", label: \'"<<CWorkflowGraph::fields[i]<<"\'},"<<std::endl; 
     147      } 
     148      fs << "    ]);"<<std::endl<<std::endl; 
     149 
     150   
     151      fs << "    var container = document.getElementById(\'mynetwork\');" <<std::endl<<std::endl; 
     152      fs << "    var data = {" <<std::endl; 
     153      fs << "        nodes: nodes," <<std::endl; 
     154      fs << "        edges: edges" <<std::endl; 
     155      fs << "    };" <<std::endl; 
     156      fs << "    var options = {"<<std::endl; 
     157      fs << "        edges:{"<<std::endl; 
     158      fs << "            smooth: false,"<<std::endl; 
     159      fs << "            arrows: \'to\',"<<std::endl; 
     160      fs << "            color: 'red',"<<std::endl; 
     161      fs << "            font:{align: \'middle\'},"<<std::endl; 
     162      fs << "        },"<<std::endl; 
     163      fs << "        physics:{"<<std::endl; 
     164      fs << "            enabled: false,"<<std::endl; 
     165      fs << "        },"<<std::endl; 
     166      fs << "};" <<std::endl<<std::endl; 
     167 
     168      fs << "    var network = new vis.Network(container, data, options);" <<std::endl<<std::endl; 
     169 
     170      fs << "</script>"<<std::endl; 
     171      fs << "</body>"<<std::endl; 
     172      fs << "</html>"<<std::endl; 
     173 
     174       
     175 
     176      fs.close(); 
     177          
     178    } 
     179  } 
     180  CATCH 
     181 
     182 
     183 
    67184  void CGraphviz::showStaticWorkflowGraph() 
    68185  TRY 
Note: See TracChangeset for help on using the changeset viewer.