<?
	//	   c_graf_popilometr_preview
class c_services_esmo_pp_graf_popilometr_preview
{

   function show(&$options=array())
   {   if (!$_GET['pp_id']) return ;
       $dir_to_pChart=_DIR_TO_ADDONS.'/pChart2.1.4' ;
       /* CAT:Line chart */
       include($dir_to_pChart."/class/pData.class.php");
       include($dir_to_pChart."/class/pDraw.class.php");
       include($dir_to_pChart."/class/pImage.class.php");

       /* Create and populate the pData object */
       $MyData = new pData();


       $rec=execSQL_van("select * from obj_site_narko_data narko where pkey=".$_GET['pp_id']);
       if (!$rec['leftEye']) $rec['leftEye']=PP()->get_pp_value($rec['pkey'],'left');
       if (!$rec['rightEye']) $rec['rightEye']=PP()->get_pp_value($rec['pkey'],'right');

       $rec_norm=execSQL_van('select * from obj_site_narko_data_out_303 where user_id='.$rec['personal_id']);
       if ($rec_norm['pp_id'])
       {   $pp_norm=execSQL_van('select * from obj_site_narko_data where pkey='.$rec_norm['pp_id']);
           if (!$pp_norm['leftEye']) $pp_norm['leftEye']=PP()->get_pp_value($pp_norm['pkey'],'left');
           if (!$pp_norm['rightEye']) $pp_norm['rightEye']=PP()->get_pp_value($pp_norm['pkey'],'right');
           if ($pp_norm['pkey'])
           {   $analyzer=new Analyzer();
               if (!$_GET['a'] or $_GET['a']=='l')
               { $analyzer->stringToArrays($pp_norm['leftEye']);
                 $leftMassive_norm=$analyzer->getMassive();  //damp_array($leftMassive) ;
                 $MyData->addPoints($leftMassive_norm,'NORM');
               }
               if (!$_GET['a'] or $_GET['a']=='r')
               { $analyzer->stringToArrays($pp_norm['rightEye']);
                 $rightMassive_norm=$analyzer->getMassive();  //damp_array($leftMassive) ;
                 $MyData->addPoints($rightMassive_norm,'NORM');
               }
           }
       }


       $analyzer=new Analyzer();
       if (!$_GET['a'] or $_GET['a']=='l')
       {
          if (!$_GET['no_approximate']) $analyzer->stringToArrays($rec['leftEye']);
          else $analyzer->stringToArrays($rec['leftEye'],'',array('no_approximate'=>1));
          $leftMassive=$analyzer->getMassive();  //damp_array($leftMassive) ;
          $MyData->addPoints($leftMassive,'LEFT');
       }
       if (!$_GET['a'] or $_GET['a']=='r')
       {
          if (!$_GET['no_approximate']) $analyzer->stringToArrays($rec['rightEye']);
          else $analyzer->stringToArrays($rec['rightEye'],'',array('no_approximate'=>1));
          $rightMassive=$analyzer->getMassive();  //damp_array($leftMassive) ;
          $MyData->addPoints($rightMassive,'RIGHT');
       }

       $MyData->setSerieDescription("Labels","Время");
       $MyData->setAbscissa("Labels");
       $MyData->setAbscissaName("Время");

        /* Create the pChart object */
        $myPicture = new pImage(400,300,$MyData);

        /* Turn of AAliasing */
        $myPicture->Antialias = FALSE;

        /* Set the default font */
        $myPicture->setFontProperties(array("R"=>0,"G"=>0,"B"=>0,"FontName"=>$dir_to_pChart."/fonts/verdana.ttf","FontSize"=>10));

        /* Define the chart area */
        $myPicture->setGraphArea(50,40,400,250);
        $scaleSettings = array("Mode"=>SCALE_MODE_START0,"XMargin"=>10,"YMargin"=>10,"Floating"=>TRUE,"DrawSubTicks"=>TRUE,"GridR"=>100,"GridG"=>100,"GridB"=>100,"GridAlpha"=>15,"LabelSkip"=>99);
        $myPicture->drawScale($scaleSettings);
        $myPicture->Antialias = TRUE;
        $myPicture->drawSplineChart();
        $myPicture->Antialias = FALSE;

        /* Write the chart legend */
        $myPicture->drawLegend(200,20,array("Style"=>LEGEND_NOBORDER,"Mode"=>LEGEND_HORIZONTAL));

        /* Render the picture (choose the best way) */
        $myPicture->autoOutput($dir_to_pChart."/examples/pictures/example.drawDerivative.simple.png");
   }
}