linea21-externals
[ class tree: linea21-externals ] [ index: linea21-externals ] [ all elements ]

Source for file ScatterPlot.class.php

Documentation is available at ScatterPlot.class.php

  1. <?php
  2. /*
  3.  * This work is hereby released into the Public Domain.
  4.  * To view a copy of the public domain dedication,
  5.  * visit http://creativecommons.org/licenses/publicdomain/ or send a letter to
  6.  * Creative Commons, 559 Nathan Abbott Way, Stanford, California 94305, USA.
  7.  *
  8.  */
  9.  
  10. require_once dirname(__FILE__)."/Plot.class.php";
  11.  
  12. /**
  13.  * ScatterPlot
  14.  *
  15.  * @package linea21.externals
  16.  * @subpackage artichow
  17.  */
  18. class awScatterPlot extends awPlot implements awLegendable {
  19.     
  20.     /**
  21.      * Add marks to the scatter plot
  22.      *
  23.      * @var Mark 
  24.      */
  25.     public $mark;
  26.     
  27.     /**
  28.      * Labels on the plot
  29.      *
  30.      * @var Label 
  31.      */
  32.     public $label;
  33.     
  34.     /**
  35.      * Link points ?
  36.      *
  37.      * @var bool 
  38.      */
  39.     protected $link = FALSE;
  40.     
  41.     /**
  42.      * Display impulses
  43.      *
  44.      * @var bool 
  45.      */
  46.     protected $impulse = NULL;
  47.     
  48.     /**
  49.      * Link NULL points ?
  50.      *
  51.      * @var bool 
  52.      */
  53.     protected $linkNull = FALSE;
  54.     
  55.     /**
  56.      * Line color
  57.      *
  58.      * @var Color 
  59.      */
  60.     protected $lineColor;
  61.     
  62.     /**
  63.      * Line type
  64.      *
  65.      * @var int 
  66.      */
  67.     protected $lineStyle = awLine::SOLID;
  68.     
  69.     /**
  70.      * Line thickness
  71.      *
  72.      * @var int 
  73.      */
  74.     protected $lineThickness = 1;
  75.          
  76.     /**
  77.      * Construct a new awScatterPlot
  78.      *
  79.      * @param array $datay Numeric values for Y axis
  80.      * @param array $datax Numeric values for X axis
  81.      * @param int $mode 
  82.      */
  83.     public function __construct($datay$datax NULL{
  84.     
  85.         parent::__construct();
  86.         
  87.         // Defaults marks
  88.         $this->mark = new awMark;
  89.         $this->mark->setType(awMark::CIRCLE);
  90.         $this->mark->setSize(7);
  91.         $this->mark->border->show();
  92.         
  93.         $this->label = new awLabel;
  94.         
  95.         $this->setValues($datay$datax);
  96.         $this->setColor(new awBlack);
  97.     
  98.     }
  99.     
  100.     /**
  101.      * Display plot as impulses
  102.      *
  103.      * @param awColor $impulse Impulses color (or NULL to disable impulses)
  104.      */
  105.     public function setImpulse($color{
  106.         $this->impulse = $color;
  107.     }
  108.     
  109.     /**
  110.      * Link scatter plot points
  111.      *
  112.      * @param bool $link 
  113.      * @param awColor $color Line color (default to black)
  114.      */
  115.     public function link($link$color NULL{
  116.         $this->link = (bool)$link;
  117.         if($color instanceof awColor{
  118.             $this->setColor($color);
  119.         }
  120.     }
  121.     
  122.     /**
  123.      * Ignore null values for Y data and continue linking
  124.      *
  125.      * @param bool $link 
  126.      */
  127.     public function linkNull($link{
  128.         $this->linkNull = (bool)$link;
  129.     }
  130.     
  131.     /**
  132.      * Change line color
  133.      *
  134.      * @param awColor $color 
  135.      */
  136.     public function setColor(awColor $color{
  137.         $this->lineColor = $color;
  138.     }
  139.     
  140.     /**
  141.      * Change line style
  142.      *
  143.      * @param int $style 
  144.      */
  145.     public function setStyle($style{
  146.         $this->lineStyle = (int)$style;
  147.     }
  148.     
  149.     /**
  150.      * Change line tickness
  151.      *
  152.      * @param int $tickness 
  153.      */
  154.     public function setThickness($tickness{
  155.         $this->lineThickness = (int)$tickness;
  156.     }
  157.  
  158.     /**
  159.      * Get the line thickness
  160.      *
  161.      * @return int 
  162.      */
  163.     public function getLegendLineThickness({
  164.         return $this->lineThickness;
  165.     }
  166.  
  167.     /**
  168.      * Get the line type
  169.      *
  170.      * @return int 
  171.      */
  172.     public function getLegendLineStyle({
  173.         return $this->lineStyle;
  174.     }
  175.  
  176.     /**
  177.      * Get the color of line
  178.      *
  179.      * @return Color 
  180.      */
  181.     public function getLegendLineColor({
  182.         return $this->lineColor;
  183.     }
  184.  
  185.     /**
  186.      * Get the background color or gradient of an element of the component
  187.      *
  188.      * @return Color, Gradient
  189.      */
  190.     public function getLegendBackground({
  191.         return NULL;
  192.     }
  193.  
  194.     /**
  195.      * Get a mark object
  196.      *
  197.      * @return Mark 
  198.      */
  199.     public function getLegendMark({
  200.         return $this->mark;
  201.     }
  202.     
  203.     public function drawComponent(awDriver $driver$x1$y1$x2$y2$aliasing{
  204.     
  205.         $count count($this->datay);
  206.         
  207.         // Get start and stop values
  208.         list($start$stop$this->getLimit();
  209.         
  210.         // Build the polygon
  211.         $polygon new awPolygon;
  212.         
  213.         for($key 0$key $count$key++{
  214.         
  215.             $x $this->datax[$key];
  216.             $y $this->datay[$key];
  217.             
  218.             if($y !== NULL{
  219.                 $p awAxis::toPosition($this->xAxis$this->yAxisnew awPoint($x$y));
  220.                 $polygon->set($key$p);
  221.             else if($this->linkNull === FALSE{
  222.                 $polygon->set($keyNULL);
  223.             }
  224.         
  225.         }
  226.         
  227.         // Link points if needed
  228.         if($this->link{
  229.         
  230.             $prev NULL;
  231.             
  232.             foreach($polygon->all(as $point{
  233.             
  234.                 if($prev !== NULL and $point !== NULL{
  235.                     $driver->line(
  236.                         $this->lineColor,
  237.                         new awLine(
  238.                             $prev,
  239.                             $point,
  240.                             $this->lineStyle,
  241.                             $this->lineThickness
  242.                         )
  243.                     );
  244.                 }
  245.                 $prev $point;
  246.                 
  247.             }
  248.         }
  249.         
  250.         // Draw impulses
  251.         if($this->impulse instanceof awColor{
  252.             
  253.             foreach($polygon->all(as $key => $point{
  254.             
  255.                 if($point !== NULL{
  256.                     
  257.                     $zero awAxis::toPosition(
  258.                         $this->xAxis,
  259.                         $this->yAxis,
  260.                         new awPoint($key0)
  261.                     );
  262.                     
  263.                     $driver->line(
  264.                         $this->impulse,
  265.                         new awLine(
  266.                             $zero,
  267.                             $point,
  268.                             awLine::SOLID,
  269.                             1
  270.                         )
  271.                     );
  272.                     
  273.                 }
  274.                 
  275.             }
  276.         
  277.         }
  278.         
  279.         // Draw marks and labels
  280.         foreach($polygon->all(as $key => $point{
  281.  
  282.             $this->mark->draw($driver$point);
  283.             $this->label->draw($driver$point$key);
  284.             
  285.         }
  286.         
  287.     }
  288.     
  289.     protected function xAxisPoint($position{
  290.         $y $this->xAxisZero ? $this->getRealYMin();
  291.         return awAxis::toPosition($this->xAxis$this->yAxisnew awPoint($position$y));
  292.     }
  293.     
  294.     public function getXCenter({
  295.         return FALSE;
  296.     }
  297.  
  298. }
  299.  
  300. registerClass('ScatterPlot');
  301. ?>

Documentation generated on Fri, 16 Oct 2009 09:39:08 +0200 by phpDocumentor 1.4.1