<?
class c_page_pChart_graf_popilometr
{

   function show(&$options=array())
   {   $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();


       if ($_GET['mo_id']) $recs=execSQL("select * from obj_site_narko_data narko where id_mo in (".$_GET['mo_id'].')');
       if ($_GET['pp_id']) $recs=execSQL("select * from obj_site_narko_data narko where pkey in (".$_GET['pp_id'].')');
       if (_sizeof($recs)) foreach ($recs as &$rec){
           $rec['leftEye']=PP()->get_pp_value($rec['pkey'],'left');
           $rec['rightEye']=PP()->get_pp_value($rec['pkey'],'right');
       }


       if (_sizeof($recs)) foreach($recs as $rec) $pers_id=$rec['personal_id'] ;
       $rec_norm=execSQL_van('select * from obj_site_narko_data_out_303 where user_id='.$pers_id);
       if ($rec_norm['pp_id'])
       {   $pp_norm=execSQL_van('select * from obj_site_narko_data where pkey='.$rec_norm['pp_id']);
           $pp_norm['leftEye']=PP()->get_pp_value($pp_norm['pkey'],'left');
           $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')
               { $leftEye=($pp_norm['leftEye'])? $pp_norm['leftEye']:PP()->get_pp_value($pp_norm['pkey'],'left') ;
                 $analyzer->stringToArrays($leftEye);
                 $leftMassive=$analyzer->getMassive();  //damp_array($leftMassive) ;
                 $MyData->addPoints($leftMassive,'NORM');
               }
               if (!$_GET['a'] or $_GET['a']=='r')
               { $rightEye=($pp_norm['rightEye'])? $pp_norm['rightEye']:PP()->get_pp_value($pp_norm['pkey'],'right') ;
                 $analyzer->stringToArrays($rightEye);
                 $rightMassive=$analyzer->getMassive();  //damp_array($leftMassive) ;
                 $MyData->addPoints($rightMassive,'NORM');
               }


           }
       }


       if (_sizeof($recs)) foreach($recs as $rec)
       { $analyzer=new Analyzer();
         if (!$_GET['a'] or $_GET['a']=='l')
         {  $leftEye=($rec['leftEye'])? $rec['leftEye']:PP()->get_pp_value($rec['pkey'],'left') ;
            $analyzer->stringToArrays($leftEye);
            $leftMassive=$analyzer->getMassive();  //damp_array($leftMassive) ;
            $MyData->addPoints($leftMassive,$rec['pkey']);
         }
         if (!$_GET['a'] or $_GET['a']=='r')
         {  $rightEye=($rec['rightEye'])? $rec['rightEye']:PP()->get_pp_value($rec['pkey'],'right') ;
            $analyzer->stringToArrays($rightEye);
            $rightMassive=$analyzer->getMassive();  //damp_array($leftMassive) ;
            $MyData->addPoints($rightMassive,$rec['pkey']);
         }
       }

        //$MyData->setAxisName(0,"Temperatures");
        //$MyData->addPoints(array("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"),"Labels");
        $MyData->setSerieDescription("Labels","Время");
        $MyData->setAbscissa("Labels");
        $MyData->setAbscissaName("Время");

        /* Create the pChart object */
        $myPicture = new pImage(1100,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,1000,250);

        /* Draw the scale */
        $scaleSettings = array("XMargin"=>10,"YMargin"=>10,"Floating"=>TRUE,"DrawSubTicks"=>TRUE,"GridR"=>100,"GridG"=>100,"GridB"=>100,"GridAlpha"=>15,"LabelSkip"=>24);
        $myPicture->drawScale($scaleSettings);

        /* Draw the chart */
        $myPicture->Antialias = TRUE;
        $myPicture->drawSplineChart();
        $myPicture->Antialias = FALSE;

        /* Draw the series derivative graph */
        //$myPicture->drawDerivative(array("Caption"=>FALSE));

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

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