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

Message ListMessage List     Post MessagePost Message

  set long times
Posted by Babak on Oct-06-2016 20:03
Attachments:
Dear Peter
I would like maximum scale of data scale will about 500 millisecond but i have a problem.
that  after 60 second labels start from 0 .

    c->yAxis()->setDateScale(Chart::chartTime2(1), Chart::chartTime2(400), 0 );
Gantt_1.png

  Re: set long times
Posted by Peter Kwan on Oct-06-2016 21:18
Hi Babak,

In ChartDirector, the date/time axis refers to date/time instance as indicated in the calendar and the clock. For example, Jan 1, 2015 13:33:56.

If your case, the "time" you mentioned is elapsed time in milliseconds. It is just a number and should use the linear axis, like:

c->yAxis()->setLinearScale(0, 400, 50);

Hope this can help.

Regards
Peter Kwan

  Re: set long times
Posted by Babak on Oct-07-2016 17:40
Attachments:
hi it does not work and it restart from 0
Gantt_1.png

  Re: set long times
Posted by Peter Kwan on Oct-07-2016 21:14
Hi Babak,

Is it possible you have another line of code that sets that label formatting to restart from 0 (such as a line using Axis.setLabelFormat or Axis.setMultiFormat and use the format "ss")? Is it possible to provide me with your complete charting code?

Regards
Peter Kwan

  Re: set long times
Posted by Babak on Oct-08-2016 01:19
#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; // 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 = 14; // Total visited HOP
    int SW_Num =pm->switches ; // Numbers of switchs
    int ES_Num =pm->endsystems ; // Numbers of switchs



    /************************************ 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";

     /*
         char const* SWlabels={"   "};
    string  ES,SW;
    string  ESSWlabel[2]={"ES","SW"};
    char const* FinalLabels[MAX_LABELS];


         cout << "ES " << pm->endsystems << "n";
        cout << "SW " << pm->switches << "n";




    for (int i=0;i<pm->endsystems;i++)
        {
            string No=to_string(i) ;
            ES =ESSWlabel[0]+No;
            FinalLabels[i]=ES.c_str();
        cout << "**********************************************"<< "n";
        cout << "string No " << No << "n";
        cout << "ESe " << ES<< "n";
        cout << "FinalLabels " << FinalLabels[i] << "n";
           cout << "FinalLabel0 " << FinalLabels[0] << "n";
                   cout << "FinalLabels1 " << FinalLabels[1] << "n";
                           cout << "FinalLabels10 " << FinalLabels[10] << "n";



        }
       cout << "**********************************************"<< "n";
         cout << "FinalLabelsE0 " << FinalLabels[0] << "n";
         cout << "FinalLabelsE1 " << FinalLabels[1] << "n";
         cout << "FinalLabelsE2 " << FinalLabels[2] << "n";
         cout << "FinalLabelsE3 " << FinalLabels[pm->switches] << "n";


     // FinalLabels[i] = ESlabels[i];
    for (int i=0;i<pm->switches;i++)
        {
         string No=to_string(i) ;
         SW =ESSWlabel[1]+No;

        SWlabels=SW.c_str();
        FinalLabels[i+pm->endsystems] =SWlabels;
        cout << "**********************************************"<< "n";
        cout << "string No " << No << "n";
        cout << "SWe " << SW << "n";
         cout << "FinalLabelsM " << FinalLabels[i+pm->endsystems] << "n";
        };

        cout << "**********************************************"<< "n";
         cout << "FinalLabelsM0 " << FinalLabels[pm->switches+1] << "n";
         cout << "FinalLabelsM1 " << FinalLabels[pm->switches+2] << "n";
         cout << "FinalLabelsM2 " << FinalLabels[pm->switches+3] << "n";
         cout << "FinalLabelsM3 " << FinalLabels[pm->endsystems+pm->switches] << "n";

*/


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

     char const* Mlabels[] = { "MSG0", "MSG0", "MSG0", "MSG0", "MSG1", "MSG1", "MSG1", "MSG1", "MSG2", "MSG2", "MSG2",
        "MSG2", "MSG3", "MSG3", "MSG3", "MSG3", "MSG4", "MSG4", "MSG4", "MSG4" };
    /************************************ Task relation Define  **************************************************/
    /************************************ JOB Defines   **************************************************/
    vector<double>* JOB_Start_Time = new vector<double>(JN);
    JOB_Start_Time->at(0) = Chart::chartTime2(1);
    JOB_Start_Time->at(1) = Chart::chartTime2(8);
    JOB_Start_Time->at(2) = Chart::chartTime2(12);
    JOB_Start_Time->at(3) = Chart::chartTime2(18);
    JOB_Start_Time->at(4) = Chart::chartTime2(28);
    JOB_Start_Time->at(5) = Chart::chartTime2(4);
    JOB_Start_Time->at(6) = Chart::chartTime2(28);
    JOB_Start_Time->at(7) = Chart::chartTime2(36);


    vector<double> JOB_WCET(JN);
    vector<double>* MSG_Inject_Time = new vector<double>(MSN);

    for (int i=0;i<JN;i++)
         JOB_WCET.at(i) = Chart::chartTime2(am->jobs[i].ET);

///message trace and time





    cout << "Hop0" << "=" <<  sm->path[0].h.size() << "n";
     cout << "Hop1" << "=" <<  sm->path[10].h.size() << "n";

    /************************************ MESSAGE TO MESSAGE relation    ***************************************************/

   for (int i=0;i<MSN;i++)
        {
          MSG_Inject_Time->at(i) =sm->path[i].inject_time;
         //or (int j=1;j<sm->path[i].inject_time;j++)
          //   MSG_Inject_Time->at(j)+=HT; //making message times from inject to finish
        };
  /*
    MSG_Inject_Time->at(0) = Chart::chartTime2(sm->path[0].inject_time); // Message 0 Start
    MSG_Inject_Time->at(1) = Chart::chartTime2(8);
    MSG_Inject_Time->at(2) = Chart::chartTime2(10);
    MSG_Inject_Time->at(3) = Chart::chartTime2(16); // Message 1 Start
    MSG_Inject_Time->at(4) = Chart::chartTime2(18);
    MSG_Inject_Time->at(5) = Chart::chartTime2(20);
    MSG_Inject_Time->at(6) = Chart::chartTime2(22);
    MSG_Inject_Time->at(7) = Chart::chartTime2(12); // Message 2 Start
    MSG_Inject_Time->at(8) = Chart::chartTime2(14);
    MSG_Inject_Time->at(9) = Chart::chartTime2(16);
    MSG_Inject_Time->at(10) = Chart::chartTime2(28); // Message 3 Start
    MSG_Inject_Time->at(11) = Chart::chartTime2(30);
    MSG_Inject_Time->at(12) = Chart::chartTime2(32);
    MSG_Inject_Time->at(13) = Chart::chartTime2(34);
*/

    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
    MSG_Path[0][0] = 1;
    MSG_Path[0][1] = 2;
    MSG_Path[0][2] = 4;
    MSG_Path[0][3] = 0;
    MSG_Path[1][0] = 1;
    MSG_Path[1][1] = 2;
    MSG_Path[1][2] = 4;
    MSG_Path[1][3] = 3;
    MSG_Path[2][0] = 3;
    MSG_Path[2][1] = 2;
    MSG_Path[2][2] = 4;
    MSG_Path[2][3] = 0;
    MSG_Path[3][0] = 4;
    MSG_Path[3][1] = 3;
    MSG_Path[3][2] = 1;
    MSG_Path[3][3] = 2;

    /************************************ Path making  Define  **************************************************/
    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) {
                MCoor[Total_Hop] = ES_Num + MSG_Path[i][j]-1 ;
                // cout << "SW"<<k<<"="<<MCoor[k] <<"n";
                // cout << "Hop_Num"<<Hop_Num <<"n";

                Total_Hop++;
            }
        }
    };


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


    /************************************   Define finishing time of Messages ***************************************************/
    vector<double> MSG_Finish_Time(MSN); // Message finishing time array
    double HTT = Chart::chartTime2(HT);
    for(int i = 0; i <= MSN - 1; i++)
        {
         MSG_Finish_Time.at(i) = MSG_Inject_Time->at(i) + HT;
        };

    /************************************ 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, 1050, 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, 1600, 950, 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()->setDateScale(0,200,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  **************************************************/

    //    c->xAxis()->setLabels(StringArray(SWlabels, (Hop_Num + JN)));

    JLayer->setDataLabelFormat(*Jlabels);
    JLayer->addExtraField(StringArray(Jlabels, (int)(sizeof(Jlabels) / sizeof(Jlabels[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]), MSN), DoubleArray(&(MSG_Finish_Time[0]), MSN),
            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->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

    // free up resources
    delete c;
    return 0;

  }

  Re: set long times
Posted by Babak on Oct-08-2016 02:55
Thank you it works !

  Re: set long times
Posted by Peter Kwan on Oct-08-2016 01:57
Hi Babak,

In your code, there are two issues:

(a) In my last message, I suggest to use Axis.setLinearScale for a numeric axis. However, your code uses Axis.setDateScale as follows:

c->yAxis()->setDateScale(0,200,0);

Please change to Axis.setLinearScale as follows:

c->yAxis()->setLinearScale(0,200,0);


(b) In your code, it formats the labels to show the second of minute (with {value|s}). That means 60 will become 0, because the second of minute is always from 0 to 59.

c->yAxis()->setMultiFormat(
   Chart::StartOfSecondFilter(), "<*font=arialbd.ttf*>{value|s}",    Chart::StartOfSecondFilter(), "{value|s}");

Please remove the above code, as you mentioned you do not want to use this format.

Hope this can help.

Regards
Peter Kwan