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

Source for file Component.class.php

Documentation is available at Component.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__)."/Graph.class.php";
  11.  
  12.  
  13. /**
  14.  * A graph can contain some groups of components
  15.  *
  16.  * @package linea21.externals
  17.  * @subpackage artichow
  18.  */
  19.  class awComponentGroup extends awComponent {
  20.  
  21.     /**
  22.      * Components of this group
  23.      *
  24.      * @var array 
  25.      */
  26.     var $components;
  27.     
  28.     /**
  29.      * Build the component group
  30.      */
  31.      function awComponentGroup({
  32.         parent::awComponent();
  33.         $this->components = array();
  34.     }
  35.  
  36.     /**
  37.      * Add a component to the group
  38.      *
  39.      * @param &$component A component
  40.      */
  41.      function add(&$component{
  42.         $this->components[$component;
  43.     }
  44.  
  45. }
  46.  
  47. registerClass('ComponentGroup'TRUE);
  48.  
  49.  class awComponent {
  50.  
  51.     /**
  52.      * Component driver
  53.      *
  54.      * @var Driver 
  55.      */
  56.     var $driver;
  57.  
  58.     /**
  59.      * Component width
  60.      *
  61.      * @var float 
  62.      */
  63.     var $width = 1.0;
  64.  
  65.     /**
  66.      * Component height
  67.      *
  68.      * @var float 
  69.      */
  70.     var $height = 1.0;
  71.  
  72.     /**
  73.      * Position X of the center the graph (from 0 to 1)
  74.      *
  75.      * @var float 
  76.      */
  77.     var $x = 0.5;
  78.  
  79.     /**
  80.      * Position Y of the center the graph (from 0 to 1)
  81.      *
  82.      * @var float 
  83.      */
  84.     var $y = 0.5;
  85.     
  86.     /**
  87.      * Component absolute width (in pixels)
  88.      *
  89.      *
  90.      * @var int 
  91.      */
  92.     var $w;
  93.     
  94.     /**
  95.      * Component absolute height (in pixels)
  96.      *
  97.      *
  98.      * @var int 
  99.      */
  100.     var $h;
  101.  
  102.     /**
  103.      * Left-top corner Y position
  104.      *
  105.      * @var float 
  106.      */
  107.     var $top;
  108.  
  109.     /**
  110.      * Left-top corner X position
  111.      *
  112.      * @var float 
  113.      */
  114.     var $left;
  115.     
  116.     /**
  117.      * Component background color
  118.      *
  119.      * @var Color 
  120.      */
  121.     var $background;
  122.     
  123.     /**
  124.      * Component padding
  125.      *
  126.      * @var Side 
  127.      */
  128.     var $padding;
  129.     
  130.     /**
  131.      * Component space
  132.      *
  133.      * @var Side 
  134.      */
  135.     var $space;
  136.     
  137.     /**
  138.      * Component title
  139.      *
  140.      * @var Label 
  141.      */
  142.     var $title;
  143.     
  144.     /**
  145.      * Adjust automatically the component ?
  146.      *
  147.      * @var bool 
  148.      */
  149.     var $auto = TRUE;
  150.     
  151.     /**
  152.      * Legend
  153.      *
  154.      * @var Legend 
  155.      */
  156.     var $legend;
  157.     
  158.     /**
  159.      * Build the component
  160.      */
  161.      function awComponent({
  162.         
  163.         // Component legend
  164.         $this->legend = new awLegend();
  165.         
  166.         $this->padding = new awSide(25252525);
  167.         $this->space = new awSide(0000);
  168.         
  169.         // Component title
  170.         $this->title = new awLabel(
  171.             NULL,
  172.             new awTuffy(10),
  173.             NULL,
  174.             0
  175.         );
  176.         $this->title->setAlign(LABEL_CENTERLABEL_TOP);
  177.         
  178.     }
  179.     
  180.     /**
  181.      * Adjust automatically the component ?
  182.      *
  183.      * @param bool $auto 
  184.      */
  185.      function auto($auto{
  186.         $this->auto = (bool)$auto;
  187.     }
  188.     
  189.     /**
  190.      * Change the size of the component
  191.      *
  192.      * @param int $width Component width (from 0 to 1)
  193.      * @param int $height Component height (from 0 to 1)
  194.      */
  195.      function setSize($width$height{
  196.     
  197.         $this->width = (float)$width;
  198.         $this->height = (float)$height;
  199.         
  200.     }
  201.     
  202.     /**
  203.      * Change the absolute size of the component
  204.      *
  205.      * @param int $w Component width (in pixels)
  206.      * @param int $h Component height (in pixels)
  207.      */
  208.      function setAbsSize($w$h{
  209.     
  210.         $this->w = (int)$w;
  211.         $this->h = (int)$h;
  212.         
  213.     }
  214.     
  215.     /**
  216.      * Change component background color
  217.      *
  218.      * @param $color (can be null)
  219.      */
  220.      function setBackgroundColor($color{
  221.         if($color === NULL or is_a($color'awColor')) {
  222.             $this->background = $color;
  223.         }
  224.     }
  225.     
  226.     /**
  227.      * Change component background gradient
  228.      *
  229.      * @param $gradient (can be null)
  230.      */
  231.      function setBackgroundGradient($gradient{
  232.         if($gradient === NULL or is_a($gradient'awGradient')) {
  233.             $this->background = $gradient;
  234.         }
  235.     }
  236.     
  237.     /**
  238.      * Change component background image
  239.      *
  240.      * @param &$image (can be null)
  241.      */
  242.      function setBackgroundImage($image{
  243.         if($image === NULL or is_a($image'awImage')) {
  244.             $this->background = $image;
  245.         }
  246.     }
  247.     
  248.     /**
  249.      * Return the component background
  250.      *
  251.      * @return Color, Gradient
  252.      */
  253.      function getBackground({
  254.         return $this->background;
  255.     }
  256.     
  257.     /**
  258.      * Change component padding
  259.      *
  260.      * @param int $left Padding in pixels (NULL to keep old value)
  261.      * @param int $right Padding in pixels (NULL to keep old value)
  262.      * @param int $top Padding in pixels (NULL to keep old value)
  263.      * @param int $bottom Padding in pixels (NULL to keep old value)
  264.      */
  265.      function setPadding($left NULL$right NULL$top NULL$bottom NULL{
  266.         $this->padding->set($left$right$top$bottom);
  267.     }
  268.     
  269.     /**
  270.      * Change component space
  271.      *
  272.      * @param float $left Space in % (NULL to keep old value)
  273.      * @param float $right Space in % (NULL to keep old value)
  274.      * @param float $bottom Space in % (NULL to keep old value)
  275.      * @param float $top Space in % (NULL to keep old value)
  276.      */
  277.      function setSpace($left NULL$right NULL$bottom NULL$top NULL{
  278.         $this->space->set($left$right$bottom$top);
  279.     }
  280.     
  281.     /**
  282.      * Change the absolute position of the component on the graph
  283.      *
  284.      * @var int $x Left-top corner X position
  285.      * @var int $y Left-top corner Y position
  286.      */
  287.      function setAbsPosition($left$top{
  288.     
  289.         $this->left = (int)$left;
  290.         $this->top = (int)$top;
  291.         
  292.     }
  293.     
  294.     /**
  295.      * Set the center of the component
  296.      *
  297.      * @param int $x Position X of the center of the component
  298.      * @param int $y Position Y of the center of the component
  299.      */
  300.      function setCenter($x$y{
  301.     
  302.         $this->x = (float)$x;
  303.         $this->y = (float)$y;
  304.         
  305.     }
  306.     
  307.     /**
  308.      * Get component coords with its padding
  309.      *
  310.      * @return array Coords of the component
  311.      */
  312.      function getPosition({
  313.         
  314.         // Get component coords
  315.         $x1 $this->padding->left;
  316.         $y1 $this->padding->top;
  317.         $x2 $this->w - $this->padding->right;
  318.         $y2 $this->h - $this->padding->bottom;
  319.     
  320.         return array($x1$y1$x2$y2);
  321.     
  322.     }
  323.     
  324.     /**
  325.      * Init the drawing of the component
  326.      */
  327.      function init($driver{
  328.  
  329.         // Set component background
  330.         $background $this->getBackground();
  331.         
  332.         if($background !== NULL{
  333.             
  334.             $p1 new awPoint(00);
  335.             $p2 new awPoint($this->w - 1$this->h - 1);
  336.             
  337.             if(is_a($background'awImage')) {
  338.     
  339.                 $driver->copyImage(
  340.                     $background,
  341.                     $p1,
  342.                     $p2
  343.                 );
  344.                 
  345.             else {
  346.             
  347.                 $driver->filledRectangle(
  348.                     $background,
  349.                     new awLine($p1$p2)
  350.                 );
  351.                 
  352.             }
  353.             
  354.         }
  355.     }
  356.     
  357.     /**
  358.      * Finalize the drawing of the component
  359.      */
  360.      function finalize($driver{
  361.         
  362.         // Draw component title
  363.         $point new awPoint(
  364.             $this->w / 2,
  365.             $this->padding->top 8
  366.         );
  367.         $this->title->draw($driver$point);
  368.         
  369.         // Draw legend
  370.         $this->legend->draw($driver);
  371.         
  372.     }
  373.     
  374.     /**
  375.      * Draw the grid around your component
  376.      *
  377.      * @param Driver A driver
  378.      * @return array Coords for the component
  379.      */
  380.       
  381.     
  382.     /**
  383.      * Draw the component on the graph
  384.      * Component should be drawed into specified coords
  385.      *
  386.      * @param Driver A driver
  387.      * @param int $x1 
  388.      * @param int $y1 
  389.      * @param int $x2 
  390.      * @param int $y2 
  391.      * @param bool $aliasing Use anti-aliasing to draw the component ?
  392.      */
  393.       
  394.     
  395.     /**
  396.      * Get space width in pixels
  397.      *
  398.      * @param int $width Component width
  399.      * @param int $height Component height
  400.      * @return array 
  401.      */
  402.      function getSpace($width$height{
  403.         
  404.         $left = (int)($width $this->space->left 100);
  405.         $right = (int)($width $this->space->right 100);
  406.         $top = (int)($height $this->space->top 100);
  407.         $bottom = (int)($height $this->space->bottom 100);
  408.         
  409.         return array($left$right$top$bottom);
  410.         
  411.     }
  412.     
  413. }
  414.  
  415. registerClass('Component'TRUE);
  416. ?>

Documentation generated on Sat, 08 Nov 2008 14:51:41 +0100 by phpDocumentor 1.4.1