From d8daaf97dc726f13b2a2f5fad128d9c6ecac004f Mon Sep 17 00:00:00 2001
From: niusiyuan <siyuan.niu@telecom-paristech.fr>
Date: Thu, 13 Jun 2019 17:26:25 +0200
Subject: [PATCH] one pie chart ok without color

---
 simulators/c++2/src_simulator/arch/CPU.cpp    | 92 +++++++++++++------
 simulators/c++2/src_simulator/arch/FPGA.cpp   |  2 +-
 .../src_simulator/arch/SchedulableDevice.cpp  |  2 +-
 simulators/c++2/src_simulator/definitions.h   | 59 +++++++-----
 .../c++2/src_simulator/sim/Simulator.cpp      | 22 +++--
 5 files changed, 118 insertions(+), 59 deletions(-)

diff --git a/simulators/c++2/src_simulator/arch/CPU.cpp b/simulators/c++2/src_simulator/arch/CPU.cpp
index 7eb14f6474..6dbb361881 100644
--- a/simulators/c++2/src_simulator/arch/CPU.cpp
+++ b/simulators/c++2/src_simulator/arch/CPU.cpp
@@ -70,42 +70,80 @@ double CPU::averageLoad (unsigned int n) const{
  
 }
 
-
 void CPU::drawPieChart(std::ofstream& myfile) const {
  
-   TMLTime _maxEndTime=0;
-   for(unsigned int j = 0; j < amountOfCore ; ++j){
-     for( TransactionList::const_iterator i = _transactList.begin(); i != _transactList.end(); ++i ) {
-       if( (*i)->getTransactCoreNumber() == j ){
-	 TMLTime _endTime= (*i)->getEndTime();
-	 _maxEndTime=max(_maxEndTime,_endTime);
-       }
-     }
-     std::map <TMLTask*, double > transPercentage;
-     for( TransactionList::const_iterator i = _transactList.begin(); i!= _transactList.end(); ++i){
-       if( (*i)->getTransactCoreNumber() == j ){
-	 transPercentage[(*i)-> getCommand()->getTask()]+=(double)((*i)->getEndTime()-(*i)->getStartTime())/_maxEndTime;      
-       }
-     }
-     std::map <TMLTask*, double>::iterator iter = transPercentage.begin();
-     myfile << "     var chart" << _ID << "_" << j << "= new CanvasJS.Chart(\"chartContainer" << _ID << "_" << j <<"\"," << std::endl;
-     myfile <<  SCHED_HTML_JS_CONTENT2 << "Average load is " << averageLoad(j) <<  SCHED_HTML_JS_CONTENT3 << std::endl;
-     double idle=1;
-     while( iter != transPercentage.end()){
+  TMLTime _maxEndTime=0;
+  for(unsigned int j = 0; j < amountOfCore ; ++j){
+    for( TransactionList::const_iterator i = _transactList.begin(); i != _transactList.end(); ++i ) {
+      if( (*i)->getTransactCoreNumber() == j ){
+	TMLTime _endTime= (*i)->getEndTime();
+	_maxEndTime=max(_maxEndTime,_endTime);
+      }
+    }
+    std::map <TMLTask*, double > transPercentage;
+    for( TransactionList::const_iterator i = _transactList.begin(); i!= _transactList.end(); ++i){
+      if( (*i)->getTransactCoreNumber() == j ){
+	transPercentage[(*i)-> getCommand()->getTask()]+=(double)((*i)->getEndTime()-(*i)->getStartTime())/_maxEndTime;      
+      }
+    }
+    std::map <TMLTask*, double>::iterator iter = transPercentage.begin();
+    myfile << SCHED_HTML_JS_WINDOW << std::endl;
+    myfile << "   var ctx" << _ID << "_"  << j << "= $(\"#pie-chartcanvas-" << _ID << "_" << j << "\");\n";
+    myfile << "   var data" << _ID << "_" << j << " = { \n";
+    myfile << "           labels : [";
+    double idle=1;
+    while( iter != transPercentage.end()){
+      myfile << " \"" << iter->first->toString() << "\",";
+      idle-=iter->second;
+      ++iter;
+    }
+    myfile << "\"idle time\"],\n";
+    myfile << "            datasets : [ \n" << "             {\n";
+    iter = transPercentage.begin();
+    myfile << "                     data : [";
+    while( iter != transPercentage.end()){
+      myfile << iter->second << ",";
+      ++iter;
+    }
+    myfile << idle << "],\n";
+  
+    myfile << SCHED_HTML_PIE_END << std::endl;
+    myfile << SCHED_HTML_JS_CONTENT1 << "Average load is " << averageLoad(j) << SCHED_HTML_JS_CONTENT2 << std::endl; 
+    myfile << "    var chart" << _ID << "_" << this->_cycleTime << " = new Chart( "<<
+      "ctx" << _ID << "_" << j << ", {\n \
+              type : \"pie\",\n";
+    myfile << "               data : data" << _ID << "_" << j <<",\n";
+    myfile << "               " << SCHED_HTML_JS_CONTENT3 << std::endl;
+  }
+	 
+      
+     //myfile << "     var chart" << _ID << "_" << j << "= new CanvasJS.Chart(\"chartContainer" << _ID << "_" << j <<"\"," << std::endl;
+     //myfile <<  SCHED_HTML_JS_CONTENT2 << "Average load is " << averageLoad(j) <<  SCHED_HTML_JS_CONTENT3 << std::endl;
+     /*double idle=1;
+       while( iter != transPercentage.end()){
        myfile << "                { y:" << (iter->second)*100 << ", indexLabel: \"" << iter->first->toString() << "\" }," << std::endl;
        idle-=iter->second;
        ++iter;  
-     }
-     myfile << "                { y:" << idle*100 << ", indexLabel: \"idle time\"" << " }" << std::endl;
-     myfile << std::endl;
-     myfile << SCHED_HTML_PIE_END;
-     myfile << "chart" << _ID << "_" << j << ".render();" << std::endl; 
-   }
+       }
+       myfile << "                { y:" << idle*100 << ", indexLabel: \"idle time\"" << " }" << std::endl;
+       myfile << std::endl;
+       myfile << SCHED_HTML_PIE_END;
+       myfile << "chart" << _ID << "_" << j << ".render();" << std::endl; 
+       }*/
   
 }
 
 void CPU::showPieChart(std::ofstream& myfile) const{
-  myfile << SCHED_HTML_JS_DIV_ID << _ID << "_" << this->_cycleTime << SCHED_HTML_JS_DIV_ID_END << std::endl;
+  //myfile << SCHED_HTML_JS_DIV_ID << _ID << "_" << this->_cycleTime << SCHED_HTML_JS_DIV_ID_END << std::endl;
+  /* myfile << "    var chart" << _ID << "_" << this->_cycleTime << " = new Chart( "<<
+    "ctx" << _ID << "_" << this->_cycleTime << ", {\n \
+    type : \"pie\",\n";
+  myfile << "data : data " << _ID << this->_cycleTime <<",\n";
+  myfile << SCHED_HTML_JS_CONTENT2 << std::endl;*/
+  myfile << SCHED_HTML_JS_DIV_BEGIN << std::endl;
+  myfile << SCHED_HTML_JS_BEGIN_CANVAS << _ID << "_" << this->_cycleTime << SCHED_HTML_JS_END_CANVAS <<std::endl;
+  myfile << SCHED_HTML_JS_DIV_END << std::endl;
+    
 }
   
    
diff --git a/simulators/c++2/src_simulator/arch/FPGA.cpp b/simulators/c++2/src_simulator/arch/FPGA.cpp
index 8537f4b012..b46d25e16c 100644
--- a/simulators/c++2/src_simulator/arch/FPGA.cpp
+++ b/simulators/c++2/src_simulator/arch/FPGA.cpp
@@ -476,7 +476,7 @@ void FPGA::drawPieChart(std::ofstream& myfile) const {
   
    std::map <TMLTask*, double>::iterator iter = transPercentage.begin();
    myfile << "     var chart" << _ID << "_" <<  _htmlCurrTask->toShortString() << "= new CanvasJS.Chart(\"chartContainer" << _ID << "_" <<   _htmlCurrTask->toShortString() <<"\"," << std::endl;
-   myfile <<  SCHED_HTML_JS_CONTENT2 << "Average load is " << averageLoad( _htmlCurrTask) <<  SCHED_HTML_JS_CONTENT3 << std::endl;
+   myfile <<  SCHED_HTML_JS_CONTENT2 << "Average load is " << averageLoad( _htmlCurrTask) <<  SCHED_HTML_JS_CONTENT2 << std::endl;
    double idle=1;
    while( iter != transPercentage.end()){
      myfile << "                { y:" << (iter->second)*100 << ", indexLabel: \"" << iter->first->toString() << "\" }," << std::endl;
diff --git a/simulators/c++2/src_simulator/arch/SchedulableDevice.cpp b/simulators/c++2/src_simulator/arch/SchedulableDevice.cpp
index d528b73267..5792537c98 100644
--- a/simulators/c++2/src_simulator/arch/SchedulableDevice.cpp
+++ b/simulators/c++2/src_simulator/arch/SchedulableDevice.cpp
@@ -230,7 +230,7 @@ void SchedulableDevice::drawPieChart(std::ofstream& myfile) const {
  
   std::map <TMLTask*, double>::iterator iter = transPercentage.begin();
   myfile << "     var chart" << _ID << "= new CanvasJS.Chart(\"chartContainer" << _ID <<"\"," << std::endl;
-  myfile <<  SCHED_HTML_JS_CONTENT2 << "Average load is " << averageLoad() <<  SCHED_HTML_JS_CONTENT3 << std::endl;
+  myfile <<  SCHED_HTML_JS_CONTENT2 << "Average load is " << averageLoad() <<  SCHED_HTML_JS_CONTENT2 << std::endl;
   double idle=1;
   while( iter != transPercentage.end()){
     myfile << "                { y:" << (iter->second)*100 << ", indexLabel: \"" << iter->first->toString() << "\" }," << std::endl;
diff --git a/simulators/c++2/src_simulator/definitions.h b/simulators/c++2/src_simulator/definitions.h
index ca2400f3f1..1ab96e76ac 100644
--- a/simulators/c++2/src_simulator/definitions.h
+++ b/simulators/c++2/src_simulator/definitions.h
@@ -259,36 +259,49 @@ using std::max;
 #define SCHED_HTML_END_STYLE "</style>\n"
 #define SCHED_HTML_CSS_BEG_LINK "<link rel=\"stylesheet\" type=\"text/css\" href=\""
 #define SCHED_HTML_CSS_END_LINK "\" />\n"
-#define SCHED_HTML_JS_TYPE "<script type=\"text/javascript\">\n"
+
+
+
+
+#define SCHED_HTML_JS_LINK1 "<script src=\"jquery.min.js\">"
+#define SCHED_HTML_JS_LINK2 "<script src=\"Chart.min.js\">"
+#define SCHED_HTML_BEGIN_JS "<script>\n"
 #define SCHED_HTML_END_JS "</script>\n"
-#define SCHED_HTML_JS_LINK "<script type=\"text/javascript\" src=\"https://canvasjs.com/assets/script/canvasjs.min.js\">"
-#define SCHED_HTML_JS_DIV_BEGIN "<div>"
+#define SCHED_HTML_JS_BEGIN_CANVAS "     <canvas id=\"pie-chartcanvas-"
+#define SCHED_HTML_JS_END_CANVAS "\"></canvas>"
+#define SCHED_HTML_JS_WINDOW "window.onload = function () {"
+#define SCHED_HTML_JS_DIV_BEGIN "<div class=\"wrapper\">"
 #define SCHED_HTML_JS_DIV_END "</div>"
 #define SCHED_HTML_JS_DIV_ID "<div id=\"chartContainer"
 #define SCHED_HTML_JS_DIV_ID_END "\" style=\"height: 300px; width: 300px;\"></div>\n"
 #define SCHED_HTML_JS_DIV_ID_END_FPGA "\" style=\"height: 300px; width: 300px;float:left;margin-right:40px;\"></div>\n"
 #define SCHED_HTML_JS_CLEAR "<div class = \"clear\"></div>"
 #define NB_HTML_COLORS 15
-#define SCHED_HTML_JS_CONTENT1 "window.onload = function () {\n"
-#define SCHED_HTML_JS_CONTENT2 "{\n \
-		title:{\n \
-			text: \""
-#define SCHED_HTML_JS_CONTENT3 "\"\n \
-		},\n \
-		legend: {\n \
-			maxWidth: 350,\n \
-			itemWidth: 120\n \
+
+#define SCHED_HTML_JS_CONTENT1 "var options = {\n \
+		title : {\n \
+			display : true,\n \
+			position : \"top\",\n \
+			text : \""
+
+#define SCHED_HTML_JS_CONTENT2 "\", \n \
+			fontSize : 18,\n \
+			fontColor : \"#111\"\n \
 		},\n \
-		data: [\n \
-		{\n \
-			type: \"pie\",\n \
-			showInLegend: true,\n \
-			legendText: \"{indexLabel}\",\n \
-			dataPoints: [ \n"
-#define SCHED_HTML_PIE_END "]\n \
+		legend : {\n \
+			display : true,\n \
+			position : \"bottom\"\n \
 		}\n \
-		]\n \
-	});\n"
+	};\n"
+
+#define SCHED_HTML_JS_CONTENT3 "options : options\n \
+			});"
+
+
+#define SCHED_HTML_PIE_END "}\n \
+		]\n\
+	};\n"		
+	
 
 #define SCHED_HTML_CSS_CONTENT "table{\n \
 	border-collapse: collapse;\n \
@@ -533,6 +546,10 @@ h2 span {\n \
 	background-color: LightGoldenRodYellow;\n \
 	border-style: solid solid solid none;\n \
 }\n \
+.wrapper {\n \
+	width: 256px;\n \
+	height: 256px;\n \
+}\n \
 .clear {\n \
 	clear:both\n \
 }"
diff --git a/simulators/c++2/src_simulator/sim/Simulator.cpp b/simulators/c++2/src_simulator/sim/Simulator.cpp
index 8ac1118f63..9375232cd3 100644
--- a/simulators/c++2/src_simulator/sim/Simulator.cpp
+++ b/simulators/c++2/src_simulator/sim/Simulator.cpp
@@ -419,11 +419,15 @@ std::cout<<"schedule2HTML--------------------------------------*****************
     myfile << "<li> Date: " << asctime(aTimeinfo) << "</li>\n"; //date and time
     myfile << "</ul>\n";
     
-    myfile << SCHED_HTML_JS_TYPE;
-    myfile << SCHED_HTML_JS_CONTENT1;
+    // myfile << SCHED_HTML_JS_DIV_SUB_BEGIN;
+    // myfile << SCHED_HTML_JS_TYPE;
+    // myfile << SCHED_HTML_JS_CONTENT1;
+    myfile << SCHED_HTML_JS_LINK1 << SCHED_HTML_END_JS << std::endl;
+    myfile << SCHED_HTML_JS_LINK2 << SCHED_HTML_END_JS << std::endl;
+    myfile << SCHED_HTML_BEGIN_JS << std::endl;
     for(CPUList::const_iterator i=_simComp->getCPUList().begin(); i != _simComp->getCPUList().end(); ++i){
       (*i)->drawPieChart(myfile);
-    }
+      }
     for(FPGAList::const_iterator i=_simComp->getFPGAList().begin(); i != _simComp->getFPGAList().end(); ++i){
       for(TaskList::const_iterator j = (*i)->getTaskList().begin(); j != (*i)->getTaskList().end(); ++j){
       	(*i)->setHtmlCurrTask(*j);
@@ -431,15 +435,15 @@ std::cout<<"schedule2HTML--------------------------------------*****************
       }
     }
     for(BusList::const_iterator j=_simComp->getBusList().begin(); j != _simComp->getBusList().end(); ++j){
-      (*j)->drawPieChart(myfile);
+      // (*j)->drawPieChart(myfile);
     }
        
     myfile << "}" <<std::endl;
   
-   
-    myfile << SCHED_HTML_END_JS;
-    myfile << SCHED_HTML_JS_LINK;
-    myfile << SCHED_HTML_END_JS;
+    myfile << SCHED_HTML_END_JS << std::endl; //<script>
+    // myfile << SCHED_HTML_END_JS;
+    //myfile << SCHED_HTML_JS_LINK;
+    //myfile << SCHED_HTML_END_JS;
     
     //for(CPUList::const_iterator i=_simComp->getCPUIterator(false); i != _simComp->getCPUIterator(true); ++i){
     for(CPUList::const_iterator i=_simComp->getCPUList().begin(); i != _simComp->getCPUList().end(); ++i){
@@ -478,7 +482,7 @@ std::cout<<"schedule2HTML--------------------------------------*****************
     
     for(BusList::const_iterator j=_simComp->getBusList().begin(); j != _simComp->getBusList().end(); ++j){
       (*j)->schedule2HTML(myfile);     
-      (*j)->showPieChart(myfile);
+      // (*j)->showPieChart(myfile);
     }
     //for_each(iCPUlist.begin(), iCPUlist.end(),std::bind2nd(std::mem_fun(&CPU::schedule2HTML),myfile));
 
-- 
GitLab