ASE Home Page Products Download Purchase Support About ASE
ChartDirector Support
Forum HomeForum Home   SearchSearch

Message ListMessage List     Post MessagePost Message

  overlap and box size
Posted by Babak on Oct-11-2016 19:40
Attachments:
Dear Peter
1-you can see that in some place in SW0,SW1  MM31,MM9  have overlap of labels and boxes how can i separating them in other levels that they show in true coordination .
I mean that they stay in correct  SW  but upper or downer each other .
2- how can i show my parameters and data as legend .
Regards
Babak
Gantt_554.png

  Re: overlap and box size
Posted by Babak on Oct-11-2016 19:42
and other question how can i save my output in special folder.

My codes is :
#include "visualize.h"

#include "chartdir.h"
#include "memblock.h"



#define MAX_LABELS 20

using namespace std;

int visualize::vis(AM *am, PM *pm, SM *sm) {

  static int counter = 0;
  counter++;
  cout << "visualize " << counter << "n";

    /************************************ VARIABLES  Define  **************************************************/
    double HT = 2;//am->msg[0].size; // hope to hope static time
    int JN = am->jobs.size(); // Finding size of Job array
    int MSN = am->msg.size(); // Finding size of Message array
    int Total_VH = 0; // Total visited HOP
    int last_job = 0;
    int SW_Num =pm->switches ; // Numbers of switchs
    int ES_Num =pm->endsystems ; // Numbers of switchs
    int Total_Exc_Time =am->jobs[0].starttime(*am,*sm)+am->jobs[0].ET;;//Total excecution time of schedule

    /************************************ Total System Duration Time   **************************************************/

    for (int i=1;i< JN;i++)
        {
         if (Total_Exc_Time < am->jobs[i].starttime(*am,*sm)+am->jobs[i].ET)
            {
             Total_Exc_Time = am->jobs[i].starttime(*am,*sm)+am->jobs[i].ET ;
             last_job=i;
             cout << "Last Job starttime= " << am->jobs[i].starttime(*am,*sm)<< " last Job ID=" << am->jobs[i].ID <<"n";
             cout << "Total_Exc_Time " << Total_Exc_Time << "n";

            }
        }

    /************************************ Label Define  **************************************************/
    /************************************ Y Axis Lables Define  **************************************************/
     char const* ESlabels[] = { "ES0", "ES1", "ES2", "ES3", "ES4", "ES5", "ES6", "ES7", "ES8", "ES9", "ES10", "ES11",
        "ES12","ES13","ES14","ES15","ES16","ES17","ES18","ES19","ES20","ES21","ES22","ES23","ES24","ES25","ES26","ES27","ES28","ES29","ES30" };
         char const* SWlabels[] = { "SW0", "SW1", "SW2", "SW3", "SW4", "SW5", "SW6", "SW7", "SW8", "SW9", "SW10", "SW11",
        "SW12", "SW12", "SW13", "SW14", "SW15", "SW16", "SW17", "SW18", "SW19", "SW20", "SW21", "SW22", "SW23", "SW24", "SW25", "SW26", "SW27", "SW28", "SW29", "SW30" };



         cout << "ES " << ES_Num << "n";
         cout << "SW " << SW_Num << "n";
         cout << "last Job ID" << last_job<< "n";

    /************************************ Task Lables Define  **************************************************/
    char const* Jlabels[] = { "JOB0", "JOB1", "JOB2", "JOB3", "JOB4", "JOB5", "JOB6", "JOB7", "JOB8", "JOB9", "JOB10",
        "JOB11", "JOB12", "JOB13" };

     char const* MSGlabels[] = { "M0", "M1", "M2", "M3", "M4", "M5", "M6", "M7", "M8", "M9", "M10",
        "M11", "M12", "M13", "M14", "M15", "M16", "M17", "M18", "M19" , "M20" };
    /************************************ Task relation Define  **************************************************/
    /************************************ JOB Defines   **************************************************/
    vector<double>* JOB_Start_Time = new vector<double>(JN);
    vector<double> JOB_WCET(JN);

    for (int i=0;i<JN;i++)
         {
             JOB_Start_Time->at(i) =am->jobs[i].starttime(*am,*sm);
             JOB_WCET.at(i) =am->jobs[i].ET+JOB_Start_Time->at(i);
         }





    double startDate3[] = { Chart::chartTime2(2), Chart::chartTime2(13), Chart::chartTime2(28), Chart::chartTime2(15) };
    /************************************ Routing    **************************************************/
    vector<vector<double> > MSG_Path(MSN, vector<double>(SW_Num)); // Row  Message number ,Priority =Switch No
     cout << "MSGp" << 0 << " to ES " << sm->path[0].h[0] << "n";
       cout << "MSGP" << 1 << " to ES " << sm->path[0].h[1] << "n";
       cout << "MSGP" << 2 << " to ES " << sm->path[0].h[2] << "n";

for (int i=0;i<MSN;i++)
     for (int j=0;j< sm->path[i].h.size()-2;j++)
  {
   MSG_Path.at(i).at(j)= sm->path[i].h[j+1];
   Total_VH++;
           cout << "Total_VH++ " << Total_VH++ << "n";

     }

                 cout << "MSG_Path[0][j] " << MSG_Path[0][0] << "n";
                 cout << "MSG_Path[1][j] " << MSG_Path[6][0] << "n";
                 cout << "MSG_Path[5][j] " << MSG_Path[11][0] << "n";



   /************************************ MESSAGE TO MESSAGE relation    ***************************************************/
  vector<double> MSG_Finish_Time(Total_VH); // Message finishing time array
  vector<double> MSG_Inject_Time(Total_VH);
  char const* Mlabels[Total_VH];
  int count=0;


  for (int i=0;i<MSN;i++)
       for (int j=0;j < sm->path[i].h.size()-2;j++)
       {
          if(j ==0) MSG_Inject_Time.at(count) =sm->path[i].inject_time;
          else  MSG_Inject_Time.at(count)=MSG_Inject_Time.at(count-1)+HT; //making message times from inject to finish
          MSG_Finish_Time.at(count) = MSG_Inject_Time.at(count) + HT;//am->msg[i].size; //multi message finish time
          cout << "count++" << count<< "n";
         //cout << "am->msg[i].size" << am->msg[i].size<< "n";
               //  cout << "i " << i<< "n";
               //  cout << "j " << j<< "n";

         count++ ;
        };

     Total_VH=count ;//Total message that path
    /************************************ Message Path making   **************************************************/
    int Total_Hop = 0;

    vector<double> MCoor(Total_VH);

    for(int i = 0; i < MSN; i++) {
        for(int j = 0; j < SW_Num - 1; j++) {
         if(MSG_Path[i][j] != 0)
{
                Mlabels[Total_Hop]=MSGlabels[i];
                MCoor[Total_Hop] = MSG_Path[i][j];
                 cout << " ************************************" <<"n";
                 cout << " MCoor[Total_Hop]"<<"="<< MCoor[Total_Hop] <<"n";
                 cout << "MSG_Inject_Time->at( Total_Hop)" << MSG_Inject_Time.at( Total_Hop)<< "n";
                 cout << " MSG_Finish_Time.at(Total_Hop)"<< MSG_Finish_Time.at(Total_Hop) <<"n";
                 cout << " Mlabels[ Total_Hop]"<< Mlabels[ Total_Hop] <<"n";

                 cout << " Total_Hop " <<  Total_Hop << "n";

                Total_Hop++;
            }
        }
    };


    cout << "Total_Hop" << "=" << Total_Hop << "n";
    cout << "SW_Num" << SW_Num << "n";
    cout << "job_Num" << am->jobs.size() << "n";



    /************************************ Chart Define  **************************************************/

    // Create a XYChart object of size 620 x 280 pixels. Set background color to light blue
    // (ccccff), with 1 pixel 3D border effect.
    XYChart* c = new XYChart(1680,1100, 0xccccff, 0x000000, 1);

    c->setRoundedFrame();

    // Add a title to the chart using 15 points Times Bold Itatic font, with white (ffffff) text on
    // a deep blue (000080) background
    c->addTitle("MetaScheduling Time System", "timesbi.ttf", 15, 0xffffff)->setBackground(0x000080);

    // Set the plotarea at (140, 55) and of size 460 x 200 pixels. Use alternative white/grey
    // background. Enable both horizontal and vertical grids by setting their colors to grey
    // (c0c0c0). Set vertical major grid (represents month boundaries) 2 pixels in width
    c->setPlotArea(40, 55,1550,1000, 0xffffff, 0xeeeeee, Chart::Transparent, 0xc0c0c0, 0xc0c0c0)
        ->setGridWidth(2, 1, 1, 1);

    // swap the x and y axes to create a horziontal box-whisker chart
    c->swapXY();

    // Set the y-axis scale to be date scale from minimum to maxmim
   // c->yAxis()->setDateScale(Chart::chartTime2(1), Chart::chartTime2(200), 0 );
c->yAxis()->setLinearScale(0,Total_Exc_Time,0);
    // Set multi-style axis label formatting. Month labels are in Arial Bold font in "mmm d" format.
    // Weekly labels just show the day of month and use minor tick (by using '-' as first character
    // of format string).
    //c->yAxis()->setMultiFormat(Chart::StartOfSecondFilter(), "<*font=arialbd.ttf*>{value|s}", Chart::StartOfSecondFilter(), "{value|s}");

    // Set the y-axis to shown on the top (right + swapXY = top)
    c->setYAxisOnRight();

    // Set the labels on the x axis
    /*************************************** Y AXIS Lable **************************************************/

   char const* FinalLabels[MAX_LABELS];

    for (int i=0;i<ES_Num;i++)
      FinalLabels[i] = ESlabels[i];

    for (int i=0;i<SW_Num;i++)
      FinalLabels[i+ES_Num] = SWlabels[i];

    c->xAxis()->setLabels(StringArray(FinalLabels, ES_Num + SW_Num ));


    // Reverse the x-axis scale so that it points downwards.
    c->xAxis()->setReverse();

    // Set the horizontal ticks and grid lines to be between the bars
    c->xAxis()->setTickOffset(0.5);

    /*************************************** Job **************************************************/
    /************************************Draw  BOX Job **************************************************/

    // Add a green (33ff33) box-whisker layer showing the box only.
    BoxWhiskerLayer* JLayer =c->addBoxWhiskerLayer(DoubleArray(&((*JOB_Start_Time)[0]), JN), DoubleArray(&(JOB_WCET[0]), JN), DoubleArray(),
            DoubleArray(), DoubleArray(), 0x00cc00, Chart::SameAsMainColor, Chart::SameAsMainColor);

    /************************************ BOX labels Job  **************************************************/
    vector<double> JCoor(ES_Num);
    char const* FinalJobLabels[JN];

for (int i=0;i<JN;i++)
   {
       cout << "Alloc Job#" << i << " to ES " << sm->alloc.at(i) << "n";
    }

  for(int i = 0; i < JN; i++)
        {
  for(int j = 0; j < ES_Num;j++)
            {
            if(sm->alloc[i] == j)
                {
                 JCoor[j] = sm->alloc[i] ;//Job coordination
                 FinalJobLabels[j]=Jlabels[i];//Job label cordination
                // cout << "SW"<<k<<"="<<MCoor[k] <<"n";
               // cout << "Hop_Num"<<Hop_Num <<"n";

            }
        }
    };


    JLayer->setXData(DoubleArray(&(JCoor[0]), ES_Num)); // Job cordination
    JLayer->setDataLabelFormat(*FinalJobLabels);
    JLayer->addExtraField(StringArray(FinalJobLabels, (int)(sizeof(FinalJobLabels) / sizeof(FinalJobLabels[0]))));
    JLayer->setDataLabelFormat("{field0}");
    JLayer->setDataLabelStyle("arialbd.ttf", 10)->setAlignment(Chart::Center);

    /*************************************** Message **************************************************/
    /************************************Draw  BOX Message **************************************************/

    BoxWhiskerLayer* MLayer =
        c->addBoxWhiskerLayer(DoubleArray(&(MSG_Inject_Time[0]), Total_VH), DoubleArray(&(MSG_Finish_Time[0]), Total_VH),
            DoubleArray(), DoubleArray(), DoubleArray(), 0x44ccFE, Chart::SameAsMainColor, Chart::SameAsMainColor);

    /************************************ BOX labels Message  **************************************************/
    MLayer->setDataLabelFormat(*Mlabels);
    //MLayer->addExtraField(StringArray(Mlabels, (int)(sizeof(Mlabels) / sizeof(Mlabels[0]))));
    MLayer->addExtraField(StringArray(Mlabels,  Total_VH));
    MLayer->setDataLabelFormat("{field0}");
    MLayer->setDataLabelStyle("arialbd.ttf", 10)->setAlignment(Chart::Center);

    MLayer->setXData(DoubleArray(&(MCoor[0]), Total_Hop)); // BOX cordination

    /************************************ Layer Define  **************************************************/
    // Add a line layer to the chart
    LineLayer* layer0 = c->addLineLayer();
    LineLayer* layer1 = c->addLineLayer();
    LineLayer* layer2 = c->addLineLayer();

    // Set the line width to 3 pixels
    layer0->setLineWidth(3);
    layer1->setLineWidth(3);
    layer2->setLineWidth(3);

    /************************************ Line connectio Start **************************************************/

    // Add the 2 data sets to the line layer, using circles, diamands and X shapes as symbols

     /*  layer0->addDataSet(DoubleArray(&((*JOB_Start_Time)[4]), JN), 0x33ff33,
            "Set1")->setDataSymbol(Chart::CircleSymbol, 4);
    */
    /*layer1->setXData(DoubleArray(&(MCoor[0]), Total_Hop));//Number of tasks fore new layer connection


      layer1->addDataSet(DoubleArray(&((*MSG_Inject_Time)[0]), MSN), 0x33ff33,
          "Set2")->setDataSymbol(Chart::DiamondSymbol, 18);

  /*    double xCoor2[] = {0,2,6,8};//related tasks
          layer2->setXData(DoubleArray(xCoor2, 4));//Number of tasks fore new layer connection

      layer2->addDataSet(DoubleArray(startDate3, (int)(sizeof( startDate3) / sizeof( startDate3[0]))), 0xf3ff33,
          "Set2")->setDataSymbol(Chart::DiamondSymbol, 18);


  /************************************ End Output the chart**************************************************/
    string  GT[2]={"Gantt_",".png"};
    string  OUT="";


    string Count_No=to_string(counter) ;//conver int to string

    OUT =GT[0]+Count_No+GT[1];// Make output string

    c->makeChart(OUT.c_str()); // Make output file
    cout << "OUT.c_str()"<<OUT.c_str() <<"n";
    // free up resources
    delete c;
    return 0;

  }

  Re: overlap and box size
Posted by Peter Kwan on Oct-12-2016 01:54
Hi Babak,

I see in your code you are saving the chart to a file, giving just the filename. If you want the file to be in a specific folder, please provide the full path name, including the name of the folder.

Hope this can help.

Regards
Peter Kwan

  Re: overlap and box size
Posted by Peter Kwan on Oct-12-2016 01:52
Hi Babak,

You can adjust the x-coordinates of the boxes to move them up and down. In assume in your code, you are uisng integer values like 7, 8, 9 to specify the x-coordinates of the boxes. You can use fractional values like 7.2, 6.8, etc., to move the boxes a little bit up or down.

For your case, you would need to write code to detect if the boxes overlap, and shift them accordingly by adjusting their x-coordinates up or down.

In ChartDirector, a legend box is used to provide names to some colors or icons. For example, if there are 3 lines with different colors, then we can create a legend box so that the user can know which color is for which type of data.

For your case, I am not sure which "parameters and data" you would like to display and how you would like them to be displayed. If you just want to show a text table, you can just display a table. I am not sure which GUI framework you are using. Most GUI framework has a control that can display a text table. If you would like to include a table in the chart, you can use a CDMLTable (see BaseChart.addTable).

Hope this can help.

Regards
Peter Kwan

  Re: overlap and box size
Posted by Babak on Oct-13-2016 18:33
Attachments:
i want put like this data in down of chart  as a box.
Could you please help me how can i do with a sample code.

#0 Msg (Inject at 24, arrive at 26): 6 -> 17 -> 5
#1 Msg (Inject at 26, arrive at 28): 6 -> 17 -> 4
#2 Msg (Inject at 39, arrive at 41): 5 -> 17 -> 7
#3 Msg (Inject at 25, arrive at 28): 6 -> 17 -> 18 -> 9
#4 Msg (Inject at 54, arrive at 56): 7 -> 17 -> 4
#5 Msg (Inject at 79, arrive at 82): 4 -> 17 -> 18 -> 9
#6 Msg (Inject at 9, arrive at 11): 13 -> 19 -> 12
#7 Msg (Inject at 9, arrive at 11): 1 -> 16 -> 0
#8 Msg (Inject at 139, arrive at 141): 9 -> 18 -> 10
#9 Msg (Inject at 40, arrive at 42): 5 -> 17 -> 4
#10 Msg (Inject at 39, arrive at 42): 12 -> 19 -> 18 -> 11
#11 Msg (Inject at 154, arrive at 156): 10 -> 18 -> 11
#12 Msg (Inject at 174, arrive at 176): 11 -> 18 -> 8
#13 Msg (Inject at 24, arrive at 26): 0 -> 16 -> 2
Gantt_104.png

  Re: overlap and box size
Posted by Peter Kwan on Oct-14-2016 01:24
Hi Babak,

I am not sure how you would like to represent the "data". If you want to display them as text, you can use BaseChart::addText. For example:

const char *myText = "#0 AAA {xxxx}: 6->17->5n#01 ....n#02 ....".
ChartDirector::TextBox *tb = c->addText(50, 400, myText, "arialbd.ttf", 10, 0x000000);
tb->setBackground(Chart::Transparent, 0x000000);

Note that the above code adds the text at (50, 400). Please modify it to add the text at the position you want.

Regards
Peter Kwan