TeeChartPHP
[ class tree: TeeChartPHP ] [ index: TeeChartPHP ] [ all elements ]

Source for file Legend.php

Documentation is available at Legend.php

  1. <?php
  2.  
  3. /**
  4.  * Legend class
  5.  *
  6.  * Description: Accesses all Chart Legend characteristics
  7.  *
  8.  * @author
  9.  * @copyright (c) 1995-2010 by Steema Software SL. All Rights Reserved. <info@steema.com>
  10.  * @version 1.0
  11.  * @package TeeChartPHP
  12.  * @subpackage legend
  13.  * @link http://www.steema.com
  14.  */
  15.  
  16.   class Legend extends TextShapePosition {
  17.  
  18.     static $CHECKBOXSIZE 11;
  19.     static $LEGENDOFF2 2;
  20.     static $LEGENDOFF4 4;
  21.     static $MAXLEGENDCOLUMNS 2;
  22.     static $ALLVALUES = -1;
  23.  
  24.     private $animations Array();
  25.     private $resizeChart true;
  26.     private $checkBoxes false;
  27.     private $textStyle;
  28.     private $series;
  29.     private $legendStyle;
  30.     private $textAlign=-1;
  31.     private $currentPage true;
  32.     private $vertSpacing=0;
  33.     private $horizMargin=0;
  34.     private $vertMargin=0;
  35.     private $topLeftPos 10;
  36.     private $alignment;
  37.     private $numCols;
  38.     private $numRows;
  39.     private $maxNumRows 10;
  40.     private $fontSeriesColor=null;
  41.     private $inverted=false;
  42.     private $dividingLines=null;
  43.     private $title=null;
  44.     private $frameWidth;
  45.     private $iColorWidth;
  46.     private $incPos;
  47.     private $iTotalItems;
  48.     private $posXLegend;
  49.     private $posYLegend;
  50.     private $iSpaceWidth;
  51.     private $items;
  52.     private $tmpSeries;
  53.     private $itemHeight;
  54.     private $symbol;
  55.     private $xLegendColor;
  56.     private $xLegendText;
  57.     private $xLegendBox;
  58.     private $tmpMaxWidth;
  59.     private $tmpTotalWidth;
  60.  
  61.     protected $columnWidthAuto=true;
  62.     protected $columnWidths// = new int[10];
  63.     protected $firstValue=0;
  64.     protected $iLastValue=0;
  65.  
  66.     public $iLegendStyle;
  67.  
  68.  
  69.     // Class Definition
  70.  
  71.     // Interceptors
  72.     function __get$property {
  73.       $method ="get{$property}";
  74.       if method_exists$this$method ) ) {
  75.         return $this->$method();
  76.       }
  77.     }
  78.  
  79.     function __set $property,$value {
  80.       $method ="set{$property}";
  81.       if method_exists$this$method ) ) {
  82.         return $this->$method($value);
  83.       }
  84.     }
  85.  
  86.     /**
  87.     * The class constructor.
  88.     */
  89.     public function Legend($c{
  90.  
  91.         $this->columnWidthsArray();
  92.  
  93.         $this->textStyle LegendTextStyle::$LEFTVALUE;
  94.         $this->legendStyle LegendStyle::$AUTO;
  95.         $this->alignment LegendAlignment::$RIGHT;
  96.         $this->textAlign Array(StringAlignment::$HORIZONTAL_LEFT_ALIGN,
  97.                                  StringAlignment::$VERTICAL_CENTER_ALIGN);
  98.  
  99.         parent::TextShapePosition($c);
  100.  
  101.         $this->readResolve();
  102.  
  103.         $tmpColor new Color(0,0,0);
  104.         $this->getShadow()->getBrush()->setDefaultColor($tmpColor);
  105.         $this->getShadow()->setDefaultSize(3);
  106.         $this->getShadow()->setDefaultVisible(true);
  107.     }
  108.  
  109.     protected function readResolve({
  110.         $this->iLegendStyle=LegendStyle::$AUTO;
  111.         $this->items Array()// [100][10]
  112.         return $this;
  113.     }
  114.  
  115.     private function getFrame({
  116.         return $this->getPen();
  117.     }
  118.  
  119.         /**
  120.           * Determines how Legend text items will be formatted.<br>
  121.           * Plain shows the point Label only.<br>
  122.           * LeftValue shows the point Value and the point Label. <br>
  123.           * RightValue shows the point Label and the point Value. <br>
  124.           * LeftPercent shows the percent the point represents and the point Label. <br>
  125.           * RightPercent shows the point Label and the percent the points represent. <br>
  126.           * XValue shows the point's X value. It applies only to Series with X
  127.           * (horizontal) values. <br><br>
  128.           * Values are pre-formatted using the Series ValueFormat property. <br>
  129.           * Percents are pre-formatted using the Series PercentFormat property. <br><br>
  130.           * Default value: LeftValue
  131.           *
  132.           *
  133.           * @return LegendTextStyle 
  134.           */
  135.     public function getTextStyle({
  136.         return $this->textStyle;
  137.     }
  138.  
  139.         /**
  140.           * Returns the index of the first displayed value at legend.
  141.           * The index can be a series value index or a series index depending
  142.           * on legend style.
  143.           *
  144.           * @return int 
  145.           */
  146.     public function getLastValue({
  147.         return $this->iLastValue;
  148.     }
  149.  
  150.     public function getTextAlign({
  151.         return $this->textAlign;
  152.     }
  153.  
  154.         /**
  155.           * Specifies how Legend text items will be formatted.<br>
  156.           * Default value: LeftValue
  157.           *
  158.           *
  159.           * @param value LegendTextStyle
  160.           */
  161.     public function setTextStyle($value{
  162.         if ($this->textStyle != $value{
  163.             $this->textStyle $value;
  164.             $this->invalidate();
  165.         }
  166.     }
  167.  
  168.     public function setTextAlign($value{
  169. //        if ($this->textAlign != $value) {
  170. //            $this->textAlign = array($value);
  171. //            $this->invalidate();
  172. //        }
  173.           if (is_array($value)){
  174.             $this->textAlign=$value;
  175.           }
  176.           else
  177.           {
  178.             $this->textAlign=Array($value);
  179.           }
  180.           $this->invalidate();
  181.     }
  182.  
  183.         /**
  184.           * Determines which series is used as data for the Legend entries.<br>
  185.           * By default, the Legend chooses the first Active Series with
  186.           * ShowInLegend:=true. It only applies to Legend style "Values".
  187.           *
  188.           * @return Series 
  189.           */
  190.     public function getSeries({
  191.         return $this->series;
  192.     }
  193.  
  194.         /**
  195.           * Determines which series is used as data for the Legend entries.<br>
  196.           *
  197.           * @param value Series
  198.           */
  199.     public function setSeries($value{
  200.         $this->series $value;
  201.         $this->invalidate();
  202.     }
  203.  
  204.         /**
  205.           * Enables/Disables the display of Legend check boxes.<br>
  206.           * Default value: false
  207.           *
  208.           * @return boolean 
  209.           */
  210.     public function getCheckBoxes({
  211.         return $this->checkBoxes;
  212.     }
  213.  
  214.     public function setChart($c{
  215.         parent::setChart($c);
  216.  
  217.         if ($this->symbol != null{
  218.            $this->getSymbol()->legend=$this;
  219.         }
  220.     }
  221.  
  222.         /**
  223.           * Displays the Legend check boxes when true.<br>
  224.           * Default value: false
  225.           *
  226.           * @param value boolean
  227.           */
  228.     public function setCheckBoxes($value{
  229.         $this->checkBoxes $this->setBooleanProperty($this->checkBoxes$value);
  230.         $this->invalidate();
  231.     }
  232.  
  233.         /**
  234.           * Determines whether or not the Legend shows only the current page items
  235.           * when the Chart is divided into pages.<br>
  236.           * Default value: true
  237.           *
  238.           * @return boolean 
  239.           */
  240.     public function getCurrentPage({
  241.         return $this->currentPage;
  242.     }
  243.  
  244.         /**
  245.           * When true, the Legend shows only the current page items when the Chart
  246.           * is divided into pages.<br>
  247.           *
  248.           * Default value: true
  249.           *
  250.  
  251.           * @param value boolean
  252.           */
  253.     public function setCurrentPage($value{
  254.         $this->currentPage $this->setBooleanProperty($this->currentPage$value);
  255.     }
  256.  
  257.         /**
  258.           * The legend text font color to that of the Series color.<br>
  259.           * Default value: false
  260.           *
  261.           * @return boolean 
  262.           */
  263.     public function getFontSeriesColor({
  264.         return $this->fontSeriesColor;
  265.     }
  266.  
  267.         /**
  268.           * Sets the legend text font color to that of the Series color.<br>
  269.           * Default value: false
  270.           *
  271.           * @param value boolean
  272.           */
  273.     public function setFontSeriesColor($value{
  274.         $this->fontSeriesColor $this->setBooleanProperty($this->fontSeriesColor$value);
  275.     }
  276.  
  277.         /**
  278.           * Specifies the Pen attributes used to draw lines separating Legend items.
  279.           * <br>
  280.           * Lines are drawn horizontally for Left or Right aligned Legend
  281.           * and vertically for Top or Bottom Legend alignments.
  282.           *
  283.           * @return ChartPen 
  284.           */
  285.     public function getDividingLines({
  286.         if ($this->dividingLines == null{
  287.             $tmpColor new Color(0,0,0)
  288.             $this->dividingLines new ChartPen($this->chart$tmpColorfalse);
  289.         }
  290.         return $this->dividingLines;
  291.     }
  292.  
  293.         /**
  294.           * Internal use - serialization
  295.           */
  296.     public function setDividingLines($value{
  297.       $this->dividingLines =$value;
  298.     }
  299.  
  300.  
  301.         /**
  302.           * Controls the width and position of the color rectangle associated with
  303.           * each Legend's item.
  304.           *
  305.           * @return LegendSymbol 
  306.           */
  307.     public function getSymbol({
  308.         if ($this->symbol == null{
  309.             $this->symbol new LegendSymbol($this);
  310.         }
  311.         return $this->symbol;
  312.     }
  313.  
  314.     /*
  315.     * Internal use - serialization
  316.     */
  317.     public function setSymbol($value{
  318.       $this->symbol=$value;
  319.     }
  320.  
  321.         /**
  322.           * Draws the Legend items in opposite direction when true.<br>
  323.           * Legend strings are displayed starting at top for Left and Right Aligment
  324.           * and starting at left for Top and Bottom Legend orientations. You can use
  325.           * Legend.FirstValue to determine the ValueIndex for the first Legend
  326.           * text item. <br>
  327.           * Default value: false
  328.           *
  329.           * @return boolean 
  330.           */
  331.     public function getInverted({
  332.         return $this->inverted;
  333.     }
  334.  
  335.         /**
  336.           * Draws the Legend items in opposite direction when true.<br>
  337.           * Default value: false
  338.           *
  339.  
  340.           * @param value boolean
  341.           */
  342.     public function setInverted($value{
  343.         $this->inverted $this->setBooleanProperty($this->inverted$value);
  344.     }
  345.  
  346.         /**
  347.           * Defines the Legend position.<br>
  348.           * Legend can be currently placed at Top, Left, Right and Bottom side of
  349.           * Chart. <br>
  350.           * Left and Right Legend alignments define a vertical Legend with
  351.           * currently one single column of items. <br>
  352.           * Top and Bottom Legend alignments define an horizontal Legend with
  353.           * currently one single row of items. <br>
  354.           * The Legend itself automatically reduces the number of displayed
  355.           * legend items based on the available charting space. <br>
  356.           * The Legend.ResizeChart property controls if Legend dimensions should be
  357.           * used to reduce Chart points space. <br>
  358.           * The Legend.GetLegendRect event provides a mechanism to supply the
  359.           * desired Rectangle Legend dimensions and placement. <br>
  360.           * The Legend.GetLegendPos event can be used to specify fixed Legend items
  361.           * X Y coordinates. <br>
  362.           * The Legend.HorizMargin and VertMargin properties control distance
  363.           * between Legend and Left and Right margins. <br>
  364.           * The Legend.TopLeftPos property can be used in Left Legend alignments
  365.           * to control vertical distance between Legend and Top Chart Margin.  <br><br>
  366.           * These techniques allow almost complete Legend control. <br>
  367.           * Default value: Right
  368.           *
  369.           *
  370.           * @return LegendAlignment 
  371.           */
  372.     public function getAlignment({
  373.         return $this->alignment;
  374.     }
  375.  
  376.         /**
  377.           * Defines the Legend position.<br>
  378.           * Default value: Right
  379.           *
  380.           *
  381.           * @param value LegendAlignments
  382.           * @see LegLegendAlignment
  383.           */
  384.     public function setAlignment($value{
  385.         if ($this->alignment != $value{
  386.             $this->alignment $value;
  387.             $this->invalidate();
  388.         }
  389.     }
  390.  
  391.     public function getColumnWidth($column{
  392.         if ($column self::$MAXLEGENDCOLUMNS{
  393.             return $this->columnWidths[$column];
  394.         else {
  395.             return -1;
  396.         }
  397.     }
  398.  
  399.     public function setColumnWidth($column$value{
  400.         if ($column self::$MAXLEGENDCOLUMNS{
  401.             $this->columnWidths[$column$value;
  402.         };
  403.         $this->invalidate();
  404.     }
  405.  
  406.         /**
  407.           * Automatically calculates best fit of legend columns.<br>
  408.           * When set to true, columnWidths control the legend width<br>
  409.           * Default value: true
  410.           *
  411.           * @return boolean 
  412.           */
  413.     public function getColumnWidthAuto({
  414.         return $this->columnWidthAuto;
  415.     }
  416.  
  417.         /**
  418.           * Automatically calculates best fit of legend columns.<br>
  419.           * When set to true, columnWidths control the legend width<br>
  420.           * Default value: true
  421.           *
  422.           * @param value boolean
  423.           */
  424.     public function setColumnWidthAuto($value{
  425.         $this->columnWidthAuto = $this->setBooleanProperty($this->columnWidthAuto$value);
  426.     }
  427.  
  428.         /**
  429.           * Defines which is the first Legend item displayed.<br>
  430.           * Legend can display all active Series names or all points of a single
  431.           * Series. FirstValue should be set accordingly, taking care not to
  432.           * overflow the number of active Series or the number of Series points. You
  433.           * can use FirstValue to show a specific subset of Series or points in
  434.           * Legend. It should be greater or equal to zero, and lower than the number
  435.           * of active Series or Series points. See Legend.LegendStyle for a
  436.           * description of the different Legend styles. <br>
  437.           * Default value: 0
  438.           *
  439.           * @return int 
  440.           */
  441.     public function getFirstValue({
  442.         return $this->firstValue;
  443.     }
  444.  
  445.         /**
  446.           * Determines which is the first Legend item displayed.<br>
  447.           * Default value: 0
  448.           *
  449.           * @see Legend#getFirstValue
  450.           * @param value int
  451.           */
  452.     public function setFirstValue($value{
  453.         $this->firstValue = $this->setIntegerProperty($this->firstValue$value);
  454.     }
  455.  
  456.         /**
  457.           * Specifies the Legend's top position in percent of total chart height.<br>
  458.           * It's used when Legend.Alignment is Left or Right only. For Top or
  459.           * Bottom Legend alignments, you can use the Chart's MarginTop and
  460.           * MarginBottom. <br>
  461.           * Default value: 10
  462.           *
  463.           * @return int 
  464.           */
  465.     public function getTopLeftPos({
  466.         return $this->topLeftPos;
  467.     }
  468.  
  469.         /**
  470.           * Specifies the Legend's top position in percent of total chart height.<br>
  471.           * Default value: 10
  472.           *
  473.           * @param value int
  474.           */
  475.     public function setTopLeftPos($value{
  476.         $this->topLeftPos $this->setIntegerProperty($this->topLeftPos$value);
  477.     }
  478.  
  479.         /**
  480.           * The Maximum number of Legend Rows displayed for a horizontal Legend
  481.           * (Chart Top or Bottom).<br>
  482.           * Default value: 10
  483.           *
  484.           * @return int 
  485.           */
  486.     public function getMaxNumRows({
  487.         return $this->maxNumRows;
  488.     }
  489.  
  490.         /**
  491.           * Sets the Maximum number of Legend Rows displayed for a horizontal Legend
  492.           * (Chart Top or Bottom).<br>
  493.           * Default value: 10
  494.           *
  495.           * @param value int
  496.           */
  497.     public function setMaxNumRows($value{
  498.         $this->maxNumRows $this->setIntegerProperty($this->maxNumRows$value);
  499.     }
  500.  
  501.     public function getLines({
  502.         return parent::getLines();
  503.     }
  504.  
  505.     public function setLines($value{
  506.         parent::setLines($value);
  507.     }
  508.  
  509.         /**
  510.           * Adds text to the Legend.
  511.           *
  512.           * @return String 
  513.           */
  514.     public function getText({
  515.         return parent::getText();
  516.     }
  517.  
  518.         /**
  519.           * Adds text to the Legend.
  520.           *
  521.           * @param value String
  522.           */
  523.     public function setText($value{
  524.         parent::setText($value);
  525.     }
  526.  
  527.         /**
  528.           * The vertical spacing between Legend items (pixels).<br>
  529.           * Default value: 0
  530.           *
  531.           * @return int 
  532.           */
  533.     public function getVertSpacing({
  534.         return $this->vertSpacing;
  535.     }
  536.  
  537.         /**
  538.           * Determines the vertical spacing between Legend items (pixels).<br>
  539.           * Default value: 0
  540.           *
  541.           * @param value int
  542.           */
  543.     public function setVertSpacing($value{
  544.         $this->vertSpacing $this->setIntegerProperty($this->vertSpacing$value);
  545.     }
  546.  
  547.         /**
  548.           * Speficies the number of screen pixels between Legend and Chart
  549.           * rectangles.<br>
  550.           * By default it is 0, meaning Legend will calculate a predefined margin
  551.           * based on total Legend width. It is only used when Legend position is
  552.           * Left or Right aligned otherwise use VertMargin. <br>
  553.           * Default value: 0
  554.           *
  555.           * @return int 
  556.           */
  557.     public function getHorizMargin({
  558.         return $this->horizMargin;
  559.     }
  560.  
  561.         /**
  562.           * Speficies the number of screen pixels between Legend and Chart
  563.           * rectangles.<br>
  564.           * Default value: 0
  565.           *
  566.           * @param value int
  567.           */
  568.     public function setHorizMargin($value{
  569.         $this->horizMargin $this->setIntegerProperty($this->horizMargin$value);
  570.     }
  571.  
  572.         /**
  573.           * The vertical margin in pixels between Legend and Chart
  574.           * rectangle.<br>
  575.           * Legend.ResizeChart must be true and Legend.Alignment must be
  576.           * Top or Bottom. When 0, the corresponding Chart margin method is used to
  577.           * determine the amount of pixels for margins (Chart.MarginTop for Top
  578.           * Legend.alignment and Chart.MarginBottom for Bottom Legend.Alignment).<br>
  579.           * Default value: 0
  580.           *
  581.           * @return int 
  582.           */
  583.     public function getVertMargin({
  584.         return $this->vertMargin;
  585.     }
  586.  
  587.         /**
  588.           * Determines the vertical margin in pixels between Legend and Chart
  589.           * rectangle.<br>
  590.           * Default value: 0
  591.           *
  592.           * @param value int
  593.           */
  594.     public function setVertMargin($value{
  595.         $this->vertMargin $this->setIntegerProperty($this->vertMargin$value);
  596.     }
  597.  
  598.         /**
  599.           * Automatically resizes Chart rectangle to prevent overlap with Legend.<br>
  600.           * When set to true, Legend.HorizMargin and Legend.VertMargin control the
  601.           * amount of pixels by which the Chart rectangle will be reduced. <br>
  602.           * Default value: true
  603.           *
  604.           * @return boolean 
  605.           */
  606.     public function getResizeChart({
  607.         return $this->resizeChart;
  608.     }
  609.  
  610.         /**
  611.           * Automatically resizes Chart rectangle to prevent overlap with Legend.<br>
  612.           * When set to true, Legend.HorizMargin and Legend.VertMargin control the
  613.           * amount of pixels by which the Chart rectangle will be reduced. <br>
  614.           * Default value: true
  615.           *
  616.           * @param value boolean
  617.           */
  618.     public function setResizeChart($value{
  619.         $this->resizeChart $this->setBooleanProperty($this->resizeChart$value);
  620.     }
  621.  
  622.     private function getLegendSeries({
  623.         $tmpResult $this->series;
  624.         if ($tmpResult == null{
  625.             return $this->chart->getFirstActiveSeries();
  626.         else {
  627.             return $tmpResult;
  628.         }
  629.     }
  630.  
  631.         /**
  632.           * Defines which items will be displayed in the Chart Legend. <br>
  633.           * Series style shows the Series.Title of all active Series in a Chart.
  634.           * Whenever a Series Title is empty, Series Name is used. <br>
  635.           * Values style shows a text representation of all points of the first
  636.           * active Series in a Chart. <br>
  637.           * LastValues style shows the last point value and the Series.Title of all
  638.           * active Series in a Chart.  It is useful for real-time charting, where
  639.           * new points are being added at the end of each Series. <br>
  640.           * Auto style (the default) means LegendStyle will be Series when there's
  641.           * more than one Active Series, and Values when there's only one Series
  642.           * in a Chart. <br>
  643.           * Legend.TextStyle determines how the Series point values are formatted.<br>
  644.           * Default value: auto
  645.           *
  646.           *
  647.           * @return LegendStyle 
  648.           */
  649.     public function getLegendStyle({
  650.         return $this->legendStyle;
  651.     }
  652.  
  653.     /**
  654.     * Defines which items will be displayed in the Chart Legend. <br>
  655.     * Default value: Auto
  656.     *
  657.     *
  658.     * @param value LegendStyles
  659.     * @see Legend#getLegendStyle
  660.     */
  661.     public function setLegendStyle($value{
  662.         if ($this->legendStyle != $value{
  663.             $this->legendStyle $value;
  664.             $this->calcLegendStyle();
  665.             $this->invalidate();
  666.         }
  667.     }
  668.  
  669.     /**
  670.     * Sets the Title text and its characteristics at the top of the legend
  671.     */
  672.     public function getTitle({
  673.         if($this->title == null{
  674.             $this->title new LegendTitle($this->chart);
  675.         }
  676.         return $this->title;
  677.     }
  678.  
  679.     public function doMouseDown($p{
  680.         $result false;
  681.  
  682.         if ($this->hasCheckBoxes()) {
  683.             $tmp $this->clicked($p);
  684.             if ($tmp != -1{
  685.                  $s $this->chart->seriesLegend($tmpfalse);
  686.                 $s->setActive(!$s->getActive());
  687.                 $result true;
  688.             }
  689.         }
  690.         return $result;
  691.     }
  692.  
  693.     private function clickedRow($tmpH$y{
  694.         $result = -1;
  695.         for $t 0$t $this->numRows$t++{
  696.             $tmp=round($this->getFirstItemTop()+1+$t $tmpH);
  697.             // review TODO before line...       int tmp = getShapeBounds().getTop() + 1 + t * tmpH;
  698.  
  699.             if (($y >= $tmp&& ($y <= ($tmp $tmpH))) {
  700.                 $result $t;
  701.                 if ($this->getInverted()) {
  702.                     $result $this->numRows $t 1;
  703.                 }
  704.                 break;
  705.             }
  706.         }
  707.         return $result;
  708.     }
  709.  
  710.     /**
  711.     * Returns the index of the clicked Legend Point.
  712.     *
  713.     * @param Point
  714.     * @return int 
  715.     */
  716.     public function _clicked($p{
  717.         return $this->clicked($p->x$p->y);
  718.     }
  719.  
  720.     /**
  721.     * Returns the index of the clicked Legend Point.
  722.     *
  723.     * @param int
  724.     * @param int
  725.     * @return int 
  726.     */
  727.     public function clicked($x$y{
  728.  
  729.         $result = -1;
  730.  
  731.         if ($this->getShapeBounds()->contains($x$y)) {
  732.  
  733.             $this->chart->getGraphics3D()->setFont($this->getFont());
  734.             $tmpH $this->calcItemHeight();
  735.  
  736.             if ($this->getVertical()) {
  737.                 if ($this->numRows 0{
  738.                     $result $this->clickedRow($tmpH$y);
  739.                 }
  740.             else {
  741.                 if ($this->numCols 0{
  742.                      $tmpW ($this->getShapeBounds()->getRight(-
  743.                                $this->getShapeBounds()->getLeft()) /
  744.                                $this->numCols;
  745.  
  746.                     for $t 0$t $this->numCols$t++{
  747.                         $tmp2 $this->getShapeBounds()->getLeft($t $tmpW;
  748.                         if (($x >= $tmp2&& ($x <= ($tmp2 $tmpW))) {
  749.                             $result $this->clickedRow($tmpH$y);
  750.                             if ($result != -1{
  751.                                 $result *= $this->numCols;
  752.                                 if ($this->getInverted()) {
  753.                                     $result += $this->numCols $t 1// 5.02
  754.                                 else {
  755.                                     $result += $t;
  756.                                 }
  757.  
  758.                                 if ($result $this->iTotalItems 1{
  759.                                     $result = -1;
  760.                                 }
  761.                             }
  762.                         }
  763.                     }
  764.                 }
  765.             }
  766.         }
  767.         return $result;
  768.     }
  769.  
  770.     public /*protected*/ function calcItemHeight({
  771.         $result $this->chart->getGraphics3D()->getFontHeight();
  772.         if ($this->hasCheckBoxes()) {
  773.             $result max(self::$CHECKBOXSIZE$result);
  774.         }
  775.         $result += $this->vertSpacing;
  776.  
  777.         if ($this->getVertical(&& ($this->dividingLines != null&&
  778.             $this->dividingLines->getVisible())
  779.         /* 5.02 */
  780.         {
  781.             $result += MathUtils::round($this->dividingLines->getWidth());
  782.         }
  783.  
  784.         return $result;
  785.     }
  786.  
  787.     protected function drawTitle({
  788.         return $this->getTitle()->getVisible(&& $this->getTitle()->getText(!= "";
  789.     }
  790.  
  791.     private function calcLegendStyle({
  792.  
  793.         if ($this->legendStyle == LegendStyle::$AUTO{
  794.             if (($this->checkBoxes|| ($this->chart->countActiveSeries(1)) {
  795.                 $this->iLegendStyle = LegendStyle::$SERIES;
  796.             else {
  797.                 /*  TODO
  798.                 if($this->getLegendSeries() instanceof Custom3DPalette) {
  799.                     $this->maxNumRows = 8;
  800.                     $this->iLegendStyle = LegendStyle::$PALETTE;
  801.                 }
  802.                 else {*/
  803.                     $this->maxNumRows 10;
  804.                     $this->iLegendStyle = LegendStyle::$VALUES;
  805.                // }
  806.             }
  807.         else {
  808.             $this->iLegendStyle = $this->legendStyle;
  809.         }
  810.     }
  811.  
  812.     private function calcTotalItems({
  813.         $result 0;
  814.  
  815.         if (($this->iLegendStyle == LegendStyle::$SERIES||
  816.             ($this->iLegendStyle == LegendStyle::$LASTVALUES)) {
  817.             for $t 0$t $this->chart->getSeriesCount()$t++{
  818.                  $s $this->chart->getSeries($t);
  819.                 if (($this->checkBoxes || $s->getActive()) && $s->getShowInLegend()) {
  820.                     $result++;
  821.                 }
  822.             }
  823.             $result -= $this->firstValue;
  824.         else {
  825.             $aSeries $this->getLegendSeries();
  826.             if (($aSeries != null&& $aSeries->getShowInLegend()) {
  827.                 $result $aSeries->getCountLegendItems($this->firstValue;
  828.             }
  829.         }
  830.         return max(0$result);
  831.     }
  832.  
  833.     /**
  834.     * Returns true when the legend displays checkboxes and it is showing
  835.     * series names.
  836.     *
  837.     * @return boolean 
  838.     */
  839.     public function hasCheckBoxes({
  840.         return ($this->checkBoxes && ($this->iLegendStyle != LegendStyle::$VALUES));
  841.     }
  842.  
  843.     /**
  844.     * Is read only and returns true only if the legend is left or right
  845.     * aligned.
  846.     *
  847.     * @return boolean 
  848.     */
  849.     public function getVertical({
  850.         return ($this->alignment == LegendAlignment::$LEFT||
  851.                 ($this->alignment == LegendAlignment::$RIGHT);
  852.     }
  853.  
  854.     private function calcSymbolTextPos($leftPos{
  855.         $tmp $leftPos self::$LEGENDOFF2 self::$LEGENDOFF4;
  856.         if ($this->getSymbol()->position == LegendSymbolPosition::$LEFT{
  857.             $this->xLegendColor $tmp;
  858.             $this->xLegendText $this->xLegendColor $this->iColorWidth self::$LEGENDOFF4;
  859.         else {
  860.             $this->xLegendText $tmp;
  861.             $this->xLegendColor $this->xLegendText $this->tmpMaxWidth;
  862.         }
  863.     }
  864.  
  865.     private function calcHorizontalPositions({
  866.  
  867.         $halfMaxWidth self::$LEGENDOFF2 self::$LEGENDOFF4 +
  868.                            (($this->tmpMaxWidth $this->iColorWidth$this->numCols+
  869.                            ((self::$LEGENDOFF2 self::$LEGENDOFF4($this->numCols 1));
  870.  
  871.         if ($this->hasCheckBoxes()) {
  872.             $halfMaxWidth += self::$LEGENDOFF4 (self::$CHECKBOXSIZE self::$LEGENDOFF2$this->numCols;
  873.             $halfMaxWidth += self::$LEGENDOFF4 2;
  874.         }
  875.  
  876.         $halfMaxWidth min($this->chart->getWidth()$halfMaxWidth);
  877.         $halfMaxWidth /= 2;
  878.  
  879.         if (!$this->getCustomPosition()) {
  880.             $tmpW MathUtils::round(1.0 $this->topLeftPos *
  881.                                         ($this->chart->getRight($this->chart->getLeft(-
  882.                                          $halfMaxWidth0.01)// 5.02
  883.             $this->setLeft($this->chart->getGraphics3D()->getXCenter($halfMaxWidth $tmpW);
  884.         }
  885.  
  886.         $this->setRight($this->shapeBounds->($halfMaxWidth));
  887.  
  888.         $tmpW $this->shapeBounds->x;
  889.  
  890.         if ($this->hasCheckBoxes()) {
  891.             $this->xLegendBox $this->shapeBounds->self::$LEGENDOFF4;
  892.             $tmpW += self::$CHECKBOXSIZE self::$LEGENDOFF4;
  893.         }
  894.         $this->calcSymbolTextPos($tmpW);
  895.     }
  896.  
  897.     private function calcColumnsWidth($numLegendValues{
  898.         if ($this->columnWidthAuto{
  899.             $g $this->chart->getGraphics3D();
  900.  
  901.             for $t 0$t self::$MAXLEGENDCOLUMNS-1$t++{
  902.                 $this->columnWidths[$t0;
  903.                 for $tt $this->firstValue$tt <= $this->iLastValue$tt++{
  904.                     $s $this->items[$tt $this->firstValue][$t];
  905.                     if ($s != null{
  906.                         $this->columnWidths[$tmax($this->columnWidths[$t],
  907.                                 MathUtils::round($g->textWidth($s)));
  908.                     }
  909.                 }
  910.             }
  911.         }
  912.  
  913.         $result $this->iSpaceWidth self::$MAXLEGENDCOLUMNS 1;
  914.         for $t 0$t self::$MAXLEGENDCOLUMNS-1$t++{
  915.             $result += $this->columnWidths[$t];
  916.         }
  917.         return $result;
  918.     }
  919.  
  920.     public function getColorWidth({
  921.         return $this->getSymbol()->getWidth();
  922.     }
  923.  
  924.     public function setColorWidth($value{
  925.         $this->getSymbol()->setWidth($value);
  926.     }
  927.  
  928.     private function calcWidths({
  929.         $this->tmpMaxWidth $this->calcColumnsWidth($this->numRows);
  930.         $this->tmpTotalWidth self::$LEGENDOFF4 $this->tmpMaxWidth self::$LEGENDOFF2;
  931.         $this->iColorWidth $this->getSymbol()->calcWidth($this->tmpTotalWidth);
  932.         $this->tmpTotalWidth += $this->iColorWidth 2//  03 //#  2 pixels
  933.  
  934.         if ($this->drawTitle()) {
  935.             $this->tmpTotalWidth=max($this->tmpTotalWidth,$this->getTitle()->getTotalWidth());
  936.         }
  937.     }
  938.  
  939.     private function calcVerticalPositions({
  940.  
  941.         if ($this->getCustomPosition(|| ($this->getAlignment(== LegendAlignment::$LEFT)) {
  942.             if (!$this->getCustomPosition()) {
  943.                 if ($this->getFrame()->getVisible()) {
  944.                     $this->shapeBounds->+= $this->frameWidth 1;
  945.                 }
  946.             }
  947.             $this->calcWidths();
  948.         else {
  949.             if ($this->getShadow()->getVisible()) {
  950.                 $this->shapeBounds->width -= max(0$this->getShadow()->getWidth());
  951.             }
  952.             if ($this->getFrame()->getVisible()) {
  953.                 $this->shapeBounds->width -= $this->frameWidth 1;
  954.             }
  955.             $this->calcWidths();
  956.  
  957.             $this->shapeBounds->$this->getRight($this->tmpTotalWidth;
  958.             $this->shapeBounds->width $this->tmpTotalWidth;
  959.  
  960.  
  961.             if ($this->hasCheckBoxes()) {
  962.                 $this->shapeBounds->-= self::$CHECKBOXSIZE self::$LEGENDOFF4;
  963.             }
  964.         }
  965.  
  966.          $tmpW $this->shapeBounds->x;
  967.  
  968.         if ($this->hasCheckBoxes()) {
  969.             $this->xLegendBox $tmpW self::$LEGENDOFF4;
  970.             $tmpW $this->xLegendBox self::$CHECKBOXSIZE;
  971.         }
  972.  
  973.         $this->shapeBounds->width $tmpW $this->tmpTotalWidth $this->shapeBounds->x;
  974.  
  975.         $this->calcSymbolTextPos($tmpW);
  976.     }
  977.  
  978.     private function setRightAlign($column$isRight{
  979.         if ($isRight{
  980.           if ($this->textAlign==-1)
  981.           {
  982.             $tmpAlign Array(/*StringAlignment::$HORIZONTAL_LEFT_ALIGN,   // RIGHT*/
  983.                               StringAlignment::$VERTICAL_CENTER_ALIGN);
  984.             $this->chart->getGraphics3D()->setTextAlign($tmpAlign);
  985.           }
  986.           else
  987.           {
  988.             $this->chart->getGraphics3D()->setTextAlign($this->textAlign);
  989.           }
  990.             $this->incPos false;
  991.         else {
  992.             $this->chart->getGraphics3D()->setTextAlign(StringAlignment::$HORIZONTAL_LEFT_ALIGN);  //LEFT
  993.         }
  994.     }
  995.  
  996.     private function drawSymbol(Series $series$index$r{
  997.         if ($this->iColorWidth 0{
  998.             if ($series != null{
  999.                 $series->drawLegend(null$index$r);
  1000.             else {
  1001.                 $tmpColor new Color(255,255,255);  //white
  1002.                 $g=$this->chart->getGraphics3D();
  1003.                 $g->getBrush()->setForegroundColor($tmpColor);
  1004.                 $g->getBrush()->setSolid(true);
  1005.                 $g->rectangle($r);
  1006.             }
  1007.         }
  1008.     }
  1009.  
  1010.     private function drawLegendItem($itemIndex$itemOrder{
  1011.  
  1012.         $old_name TChart::$controlName;
  1013.         TChart::$controlName .= 'Legend_Item_' $itemIndex;        
  1014.         
  1015.         if ($itemOrder >= $this->iTotalItems{
  1016.             return;
  1017.         }
  1018.  
  1019.         $g $this->chart->getGraphics3D();
  1020.         $g->getBrush()->setForegroundColor($this->getColor());
  1021.         $g->getBrush()->setVisible(false);
  1022.  
  1023.         $this->prepareSymbolPen();
  1024.  
  1025.         $tmp $this->xLegendText;
  1026.         $tmpX 0;
  1027.         $this->posYLegend=$this->getFirstItemTop()+1;
  1028.         $posXColor $this->xLegendColor;
  1029.  
  1030.         (int) $tmpOrder $itemOrder;
  1031.  
  1032.         if (!$this->getVertical()) {
  1033.             (int)$tmpOrder $itemOrder $this->numCols;
  1034.             $tmpX ($this->tmpMaxWidth $this->iColorWidth self::$LEGENDOFF4 self::$LEGENDOFF2);
  1035.  
  1036.             if ($this->hasCheckBoxes()) {
  1037.                 $tmpX += self::$CHECKBOXSIZE self::$LEGENDOFF2;
  1038.             }
  1039.  
  1040.             $tmpX *= ($itemOrder $this->numCols);
  1041.             $tmp += $tmpX;
  1042.             $posXColor += $tmpX;
  1043.         }
  1044.  
  1045.         $this->posYLegend += (int)$tmpOrder $this->itemHeight ($this->vertSpacing 2);
  1046.  
  1047.         if ($this->chart->getParent(!= null{
  1048.              $res new LegendItemCoordinates($itemIndex,
  1049.                    $tmp$this->posYLegend$posXColor);
  1050.             // TODO    $res = $this->chart->getParent()->getLegendResolver()->getItemCoordinates($this, $res);
  1051.             $tmp $res->getX();
  1052.             $this->posYLegend $res->getY();
  1053.             $posXColor $res->getXColor();
  1054.         }
  1055.  
  1056.         $this->posXLegend $tmp;
  1057.  
  1058.         if ($this->fontSeriesColor{
  1059.             $font=$g->getFont();
  1060.             if (($this->iLegendStyle == LegendStyle::$SERIES||
  1061.                 ($this->iLegendStyle == LegendStyle::$LASTVALUES)) {
  1062.                 $font->setColor($this->chart->seriesLegend($itemIndex!$this->checkBoxes)->
  1063.                                      $this->getColor());
  1064.             else {
  1065.                 $font->setColor($this->tmpSeries->legendItemColor($itemIndex));
  1066.             }
  1067.         }
  1068.  
  1069.         for $t 0$t self::$MAXLEGENDCOLUMNS-1$t++{
  1070.             $tmpSt $this->items[$itemOrder][$t];
  1071.             $this->incPos true;
  1072.  
  1073.             if ($tmpSt != null{
  1074.                 if ($this->iLegendStyle == LegendStyle::$SERIES{
  1075.                      $tmpAlign Array(StringAlignment::$VERTICAL_CENTER_ALIGN);
  1076.                      $g->setTextAlign($tmpAlign);
  1077.                 else
  1078.                 if ($t == 0{
  1079.                     if (($this->textStyle == LegendTextStyle::$XVALUE||
  1080.                         ($this->textStyle == LegendTextStyle::$VALUE||
  1081.                         ($this->textStyle == LegendTextStyle::$PERCENT||
  1082.                         ($this->textStyle == LegendTextStyle::$XANDVALUE||
  1083.                         ($this->textStyle == LegendTextStyle::$XANDPERCENT||
  1084.                         ($this->textStyle == LegendTextStyle::$LEFTPERCENT||
  1085.                         ($this->textStyle == LegendTextStyle::$LEFTVALUE)
  1086.                             {
  1087.                         $this->setRightAlign($ttrue);
  1088.                     else {
  1089.                         $this->setRightAlign($tfalse);
  1090.                     }
  1091.                 else
  1092.                 if ($t == 1{
  1093.                     if (($this->textStyle == LegendTextStyle::$RIGHTVALUE||
  1094.                         ($this->textStyle == LegendTextStyle::$XANDVALUE||
  1095.                         ($this->textStyle == LegendTextStyle::$XANDPERCENT||
  1096.                         ($this->textStyle == LegendTextStyle::$RIGHTPERCENT)
  1097.                             {
  1098.                         $this->setRightAlign($ttrue);
  1099.                     else {
  1100.                         $this->setRightAlign($tfalse);
  1101.                     }
  1102.                 }
  1103.  
  1104.                 if (strlen($tmpSt!= 0{
  1105.                     $tmpBox $this->hasCheckBoxes($this->posYLegend $this->posYLegend;
  1106.                     $g->textOut($this->posXLegend 3$tmpBox+10$tmpSt);
  1107.                 }
  1108.             }
  1109.  
  1110.             if ($this->incPos{
  1111.                 $this->posXLegend += $this->columnWidths[$t];
  1112.             }
  1113.             $this->posXLegend += $this->iSpaceWidth;
  1114.         }
  1115.  
  1116.         $r new Rectangle($posXColor,($this->posYLegend 1),$this->iColorWidth,
  1117.         ($this->itemHeight 1));
  1118.  
  1119.         $symbol $this->getSymbol();
  1120.         if ((!$symbol->continuous|| ($itemOrder == 0)) {
  1121.             $r->+= 2;
  1122.             $r->height -= 2;
  1123.         }
  1124.  
  1125.         if ((!$symbol->continuous|| ($itemOrder == ($this->iLastValue - $this->firstValue))) {
  1126.             $r->height -= $this->vertSpacing;
  1127.         }
  1128.  
  1129.         if (($this->iLegendStyle == LegendStyle::$SERIES||
  1130.             ($this->iLegendStyle == LegendStyle::$LASTVALUES)) {
  1131.             if ($this->checkBoxes{
  1132.                 $tmpBox $this->xLegendBox;
  1133.                 $this->tmpSeries $this->chart->seriesLegend($itemIndexfalse);
  1134.  
  1135.                 if (!$this->getVertical()) {
  1136.                     $tmpBox += $tmpX;
  1137.                 }
  1138.  
  1139.                 $checkStyle=true;
  1140.  
  1141.                 if ($g instanceof GraphicsGD{
  1142.                    /* TODO
  1143.                    Utils:drawCheckBox($tmpBox, $this->posYLegend + (($this->itemHeight - $this->vertSpacing -
  1144.                         self::$CHECKBOXSIZE) / 2) - 1, $g, $this->tmpSeries->getActive(),$checkStyle, $this->getColor());
  1145.                    */
  1146.                 }
  1147.  
  1148.                 $this->drawSymbol($this->tmpSeries-1$r);
  1149.             else {
  1150.                 $this->drawSymbol($this->chart->activeSeriesLegend($itemIndex)-1$r);
  1151.             }
  1152.         else {
  1153.             if ($this->tmpSeries != null{
  1154.                 $this->drawSymbol($this->tmpSeries$this->tmpSeries->legendToValueIndex($itemIndex),
  1155.                            $r);
  1156.             else {
  1157.                 $this->drawSymbol(null-1$r);
  1158.             }
  1159.         }
  1160.  
  1161.         if (($itemOrder 0&& ($this->dividingLines != null&&
  1162.  
  1163.             $this->dividingLines->getVisible()) {
  1164.             $g->setPen($this->dividingLines);
  1165.  
  1166.             if ($this->getVertical()) {
  1167.                 $g->horizontalLine($this->getShapeBounds()->getLeft(),
  1168.                                  $this->getShapeBounds()->getRight(),
  1169.                                  $this->posYLegend ($this->vertSpacing 2));
  1170.             else {
  1171.                 $g->verticalLine($this->getShapeBounds()->getLeft($tmpX self::$LEGENDOFF2,
  1172.                                $this->getShapeBounds()->getTop(),
  1173.                                $this->getShapeBounds()->getBottom());
  1174.             }
  1175.         }
  1176.         TChart::$controlName=$old_name;
  1177.     }
  1178.  
  1179.     private function drawItems({
  1180.         $this->tmpSeries $this->getLegendSeries();
  1181.         if ($this->inverted{
  1182.             for $t $this->iLastValue$t >= $this->firstValue$t--{
  1183.                 $this->drawLegendItem($t($this->iLastValue - $t));
  1184.             }
  1185.         else {
  1186.             for $t $this->firstValue$t <= $this->iLastValue$t++{
  1187.                 $this->drawLegendItem($t($t $this->firstValue));
  1188.             }
  1189.         }
  1190.     }
  1191.  
  1192.     private function setItem($index$pos{
  1193.  
  1194.          $tmpSt $this->chart->formattedLegend($pos)/* 5.01 */
  1195.  
  1196.          $tmp 0;
  1197.          $i = -1;
  1198.  
  1199.          do {
  1200.             $i strpos($tmpSt,Language::getString("ColumnSeparator"));
  1201.  
  1202.             if ($i !== false{
  1203.                 $this->items[$index][$tmpsubstr($tmpSt,0$i);
  1204.                 $tmpSt substr($tmpSt,$i 1);
  1205.                 $tmp++;
  1206.             }
  1207.         while (!(($i == false|| (strlen($tmpSt== 0|| ($tmp 1)));
  1208.  
  1209.         if ((strlen($tmpSt!= 0&& ($tmp <= 1)) {
  1210.             $this->items[$index][$tmp$tmpSt;
  1211.         }
  1212.     }
  1213.  
  1214.     private function getItems({
  1215.         $this->items array();
  1216.  
  1217.         if ($this->getInverted()) {
  1218.             for $t $this->iLastValue$t >= $this->firstValue$t--{
  1219.                 $this->setItem($this->iLastValue - $t$t);
  1220.             }
  1221.         else {
  1222.             for $t $this->firstValue$t <= $this->iLastValue$t++{
  1223.                 $this->setItem($t $this->firstValue$t);
  1224.             }
  1225.         }
  1226.     }
  1227.  
  1228.     private function calcMaxLegendValues($yLegend$a$b$c$itemHeight{
  1229.         if (($yLegend $a&& ($itemHeight 0)) {
  1230.              $tmp $itemHeight;
  1231.              $result = (int) ((($b $this->getFrame()->getWidth()) -
  1232.                                  $yLegend $c$tmp);
  1233.             return min($result$this->iTotalItems);
  1234.         else {
  1235.             return 0;
  1236.         }
  1237.     }
  1238.  
  1239.     private function maxLegendValues($yLegend$itemHeight{
  1240.         $tmp=$this->chart->getChartRect();
  1241.         
  1242.         if ($this->getVertical()) {
  1243.             return $this->calcMaxLegendValues($yLegend$tmp->getBottom(),
  1244.                                        $tmp->height,
  1245.                                        $tmp->y,
  1246.                                        $itemHeight);
  1247.         else {
  1248.             return $this->calcMaxLegendValues($yLegend$tmp->getRight(),
  1249.                                        $tmp->width,
  1250.                                        0,
  1251.                                        $itemHeight);
  1252.         }
  1253.     }
  1254.  
  1255.     private function resizeVertical({
  1256.         $tmp self::$LEGENDOFF2 $this->itemHeight $this->numRows;
  1257.  
  1258.         if ($this->drawTitle()) {
  1259.           $tmp += $this->getTitle()->getHeight()+2;
  1260.           if ($this->getTitle()->getTransparent())
  1261.              $tmp+=abs($this->getTitle()->getShadow()->getVertSize());
  1262.         }
  1263.  
  1264.         if (($this->getAlignment(== LegendAlignment::$BOTTOM&& (!$this->getCustomPosition())) {
  1265.             $this->shapeBounds->$this->shapeBounds->getBottom($tmp;
  1266.         }
  1267.  
  1268.         $this->shapeBounds->height $tmp;
  1269.     }
  1270.  
  1271.     private function calcMargin($margin$defaultMargin$size{
  1272.         return ($margin == 0$defaultMargin $size 100 $margin;
  1273.     }
  1274.  
  1275.     /**
  1276.     * Returns the chart rectangle minus the space occupied by the Legend.
  1277.     *
  1278.     * @param rect Rectangle
  1279.     * @return Rectangle 
  1280.     */
  1281.     public function resizeChartRect($rect{
  1282.  
  1283.         if ($this->getResizeChart(&& (!$this->getCustomPosition())) {
  1284.             if ($this->alignment == LegendAlignment::$LEFT{
  1285.                 $rect->$this->shapeBounds->getRight();
  1286.                 $rect->width -= $rect->x;
  1287.             else
  1288.             if ($this->alignment == LegendAlignment::$RIGHT{
  1289.                 $rect->width $this->shapeBounds->$rect->x;
  1290.                 if (($this->getShadow()->getVisible()) && ($this->shadow->getWidth(0)) {
  1291.                     $rect->width += $this->shadow->getWidth();
  1292.                 }
  1293.             else
  1294.             if ($this->alignment == LegendAlignment::$TOP{
  1295.                 $tmpRY $rect->y;
  1296.                 $rect->$this->shapeBounds->getBottom();
  1297.  
  1298.                 if ($this->getShadow()->getVisible()) {
  1299.                     $rect->+= max(0$this->getShadow()->getHeight());
  1300.                 }
  1301.  
  1302.                 if ($rect->$tmpRY{
  1303.                     $rect->height -= ($rect->$tmpRY);
  1304.                 }
  1305.             else
  1306.             if ($this->alignment == LegendAlignment::$BOTTOM{
  1307.                 $rect->height $this->shapeBounds->$rect->y;
  1308.             }
  1309.         }
  1310.  
  1311.         if ($this->getVertical()) {
  1312.             $tmp $this->calcMargin($this->getHorizMargin()3$this->chart->getWidth());
  1313.             if ($this->getAlignment(== LegendAlignment::$LEFT{
  1314.                 $rect->+= $tmp;
  1315.             else {
  1316.                 $rect->width -= $tmp;
  1317.             }
  1318.         else {
  1319.              $tmp $this->calcMargin($this->getVertMargin()4$this->chart->getHeight());
  1320.             if ($this->getAlignment(== LegendAlignment::$TOP{
  1321.                 $rect->+= $tmp;
  1322.             else {
  1323.                 $rect->height -= $tmp;
  1324.             }
  1325.         }
  1326.  
  1327.         return $rect;
  1328.     }
  1329.  
  1330.     private function getFirstItemTop({
  1331.         $result=$this->getShapeBounds()->getTop();
  1332.  
  1333.         if ($this->drawTitle()) {
  1334.             $result=$result $this->getTitle()->getHeight();
  1335.             if (!$this->getTitle()->getTransparent()) {
  1336.                 $result $result abs($this->getTitle()->getShadow()->getHeight());
  1337.             }
  1338.         }
  1339.  
  1340.         return $result;
  1341.     }
  1342.  
  1343.     public function paint($g$rect{
  1344.         
  1345.         TChart::$controlName .= 'Legend_';
  1346.         
  1347.         if ($this->bCustomPosition{
  1348.             $this->setShapeBounds(new Rectangle($this->getLeft()$this->getTop()$rect->width,
  1349.                                          $rect->height));
  1350.         else {
  1351.             $this->setShapeBounds($rect);
  1352.         }
  1353.  
  1354.         $this->calcLegendStyle();
  1355.  
  1356.         $isPage ($this->iLegendStyle == LegendStyle::$VALUES&& $this->currentPage &&
  1357.                          ($this->chart->getPage()->getMaxPointsPerPage(0);
  1358.  
  1359.         if ($isPage{
  1360.             $this->firstValue = ($this->chart->getPage()->getCurrent(1*
  1361.                          $this->chart->getPage()->getMaxPointsPerPage();
  1362.         }
  1363.  
  1364.         $this->iTotalItems $this->calcTotalItems();
  1365.  
  1366.         if ($isPage{
  1367.             $this->iTotalItems min($this->iTotalItems,
  1368.                                    $this->chart->getPage()->getMaxPointsPerPage());
  1369.         }
  1370.  
  1371.         $g->setFont($this->getFont());
  1372.  
  1373.         $this->iSpaceWidth MathUtils::round($g->textWidth(" "1);
  1374.  
  1375.         // calculate default Height for each Legend Item
  1376.         $this->itemHeight $this->calcItemHeight();
  1377.  
  1378.         if ($this->drawTitle()) {
  1379.             $this->getTitle()->calcHeight();
  1380.         }
  1381.  
  1382.         // calculate Frame Width offset
  1383.         if ($this->getFrame()->getVisible()) {
  1384.             $this->frameWidth MathUtils::round($this->getFrame()->getWidth());
  1385.         else {
  1386.             $this->frameWidth 0;
  1387.         }
  1388.         if ($this->getBevel()->getInner(!= BevelStyle::$NONE{
  1389.             $this->frameWidth $this->getBevel()->getWidth();
  1390.         }
  1391.  
  1392.         if ($this->getVertical()) {
  1393.             if (!$this->bCustomPosition{
  1394.                 $this->getShapeBounds()->setY($this->getShapeBounds()->getY(+ (int) ($this->topLeftPos $this->getShapeBounds()->getHeight(0.01));
  1395.             }
  1396.  
  1397.             $this->numCols 1;
  1398.             $this->numRows=$this->maxLegendValues($this->getFirstItemTop(),$this->itemHeight);
  1399.  
  1400.             $this->iLastValue = $this->firstValue + min($this->iTotalItems$this->numRows1;
  1401.             $this->getItems()// Visible !!
  1402.         }
  1403.  
  1404.         else {
  1405.             $this->iLastValue = $this->firstValue + $this->iTotalItems 1;
  1406.             $this->getItems()// All !!
  1407.             $this->tmpMaxWidth $this->calcColumnsWidth(self::$ALLVALUES);
  1408.             $this->iColorWidth $this->getSymbol()->calcWidth($this->tmpMaxWidth);
  1409.  
  1410.             if (!$this->bCustomPosition{
  1411.                 if ($this->getAlignment(== LegendAlignment::$BOTTOM{
  1412.                     $this->setBottom($rect->getBottom($this->frameWidth 1);
  1413.                     if ($this->getShadow()->getVisible()) {
  1414.                         $this->shapeBounds->height -= $this->getShadow()->getHeight();
  1415.                     }
  1416.                 else {
  1417.                     $this->shapeBounds->$rect->$this->frameWidth 1;
  1418.                 }
  1419.             }
  1420.  
  1421.             //CDI TF02010041
  1422.             $tmpCol $this->tmpMaxWidth $this->iColorWidth self::$LEGENDOFF4;
  1423.             if ($this->hasCheckBoxes()) {
  1424.                 $tmpCol += self::$CHECKBOXSIZE self::$LEGENDOFF2 self::$LEGENDOFF4;
  1425.             }
  1426.  
  1427.             $this->numCols $this->maxLegendValues(self::$LEGENDOFF4$tmpCol);
  1428.             if ($this->numCols 0{
  1429.                 $this->numRows $this->iTotalItems $this->numCols;
  1430.                 if (($this->iTotalItems $this->numCols0{
  1431.                     $this->numRows++;
  1432.                 }
  1433.                 $this->numRows min($this->numRows$this->maxNumRows);
  1434.             else {
  1435.                 $this->numRows 0;
  1436.             }
  1437.             /* adjust the last index now we know the max number of rows... */
  1438.             $this->iLastValue = $this->firstValue + min($this->iTotalItems,
  1439.                   $this->numCols $this->numRows1;
  1440.         }
  1441.  
  1442.         if ($this->iLastValue >= $this->firstValue{
  1443.             $this->resizeVertical();
  1444.  
  1445.             if ($this->getVertical()) {
  1446.                 $this->calcVerticalPositions();
  1447.             else {
  1448.                 $this->calcHorizontalPositions();
  1449.             }
  1450.  
  1451.             if ($this->chart->getParent(!= null{
  1452.                 /* TODO $this->setShapeBounds($this->chart->getParent()->getLegendResolver()->getBounds(
  1453.                         $this,
  1454.                         $this->getShapeBounds()));
  1455.                         */
  1456.             }
  1457.  
  1458.             parent::_paint($g$this->getShapeBounds()$this->getAnimations());
  1459.  
  1460.             if ($this->drawTitle()) {
  1461.                 $this->getTitle()->internalDraw($g$this->getShapeBounds());
  1462.                 $g->getFont()->assign($this->getFont());
  1463.             }
  1464.  
  1465.             $this->drawItems();
  1466.         }
  1467.     }
  1468.     
  1469.     function getAnimations()
  1470.     {
  1471.        return $this->animations;   
  1472.     }
  1473.     
  1474.     function addAnimation($animation)
  1475.     {
  1476.        $this->animations[$animation;   
  1477.     }
  1478.  
  1479.     /**
  1480.     * Returns the text string corresponding to a Legend position.<br>
  1481.     * The Legend position depends on Legend.LegendStyle. If LegendStyle is
  1482.     * lsSeries, then the text string will be the SeriesOrValueIndexth Active
  1483.     * Series Title.<br> If LegendStyle is lsValues, then the text string will
  1484.     * be the formatted SeriesOrValueIndexth value of the first Active Series
  1485.     * in the Chart.<br>
  1486.     * If LegendStyle is lsAuto and only one Active Series exists in the Chart,
  1487.     * then the LegendStyle is considered to be lsValues.<br>
  1488.     * If there is more than one Active Series then LegendStyle will be
  1489.     * lsSeries. <br>
  1490.     * Values are formatted accordingly to LegendTextStyle.
  1491.     *
  1492.     * @param seriesOrValueIndex int
  1493.     * @return String 
  1494.     */
  1495.     public function formattedLegend($seriesOrValueIndex{
  1496.         $c $this->chart;
  1497.  
  1498.         if ($this->iLegendStyle == LegendStyle::$SERIES{
  1499.             return $c->getSeriesTitleLegend($seriesOrValueIndex!$this->getCheckBoxes());
  1500.         else
  1501.         if ($this->iLegendStyle == LegendStyle::$VALUES{
  1502.             return $c->formattedValueLegend($this->getLegendSeries()$seriesOrValueIndex);
  1503.         else
  1504.         if ($this->iLegendStyle == LegendStyle::$LASTVALUES{
  1505.             return $c->formattedValueLegend($c->getSeries($seriesOrValueIndex),
  1506.                                           $c->getSeries($seriesOrValueIndex)->
  1507.                                           $this->getCount(-
  1508.                                           1);
  1509.         else
  1510.         if($this->iLegendStyle == LegendStyle::$PALETTE{
  1511.             return $c->formattedValueLegend($this->getLegendSeries()$seriesOrValueIndex);
  1512.         }
  1513.  
  1514.         return "";
  1515.     }
  1516.  
  1517.     private function prepareSymbolPen({
  1518.         $this->chart->setLegendPen($this->getSymbol()->getDefaultPen(null :
  1519.                            $this->getSymbol()->getPen());
  1520.     }
  1521.  
  1522.     private function removeChar($c$s{
  1523.         $i 0;
  1524.         while (($i strpos($s,$c)) !== false{
  1525.             $s substr($s,0,$isubstr($s,$i,$i+1);
  1526.         }
  1527.         return $s;
  1528.     }
  1529.  
  1530.     /**
  1531.     * Returns the corresponding Legend text for the Series ValueIndex point.
  1532.     * <br>
  1533.     * Legend.LegendTextStyle is used to properly format the point values
  1534.     * and labels.
  1535.     *
  1536.     * @param aSeries Series
  1537.     * @param valueIndex int
  1538.     * @return String 
  1539.     */
  1540.     public function formattedValue($aSeries$valueIndex{
  1541.         if ($valueIndex != self::$ALLVALUES{
  1542.             $tmpResult $aSeries->getLegendString($valueIndex$this->getTextStyle());
  1543.  
  1544.             // eliminate breaks in String... }
  1545.             return $this->removeChar(Language::getString("LineSeparator")$tmpResult);
  1546.         else {
  1547.             return "";
  1548.         }
  1549.     }
  1550. }
  1551. ?>

Documentation generated on Wed, 16 Jun 2010 12:06:40 +0200 by phpDocumentor 1.4.1