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

Source for file DataExportFormat.php

Documentation is available at DataExportFormat.php

  1. <?php
  2.  
  3.  /**
  4.  * DataExportFormat class
  5.  *
  6.  * Description:
  7.  *
  8.  * @author
  9.  * @copyright (c) 1995-2008 by Steema Software SL. All Rights Reserved. <info@steema.com>
  10.  * @version 1.0
  11.  * @package TeeChartPHP
  12.  * @subpackage exports
  13.  * @link http://www.steema.com
  14.  */
  15.  
  16.  abstract class DataExportFormat {
  17.  
  18.     private $includeIndex=false;
  19.     private $includeHeader=false;
  20.     private $includeSeriesTitle=false;
  21.     private $includeLabels=true;
  22.     private $textLineSeparator '\r\n';
  23.  
  24.     protected $hasColors;
  25.     protected $hasLabels;
  26.     protected $hasNoMandatory;
  27.     protected $hasMarkPositions;
  28.     protected $series;
  29.     protected $chart;
  30.  
  31.     public $fileExtension = "";
  32.  
  33.  
  34.     // Interceptors
  35.     function __get$property {
  36.       $method ="get{$property}";
  37.       if method_exists$this$method ) ) {
  38.         return $this->$method();
  39.       }
  40.     }
  41.  
  42.     function __set $property,$value {
  43.       $method ="set{$property}";
  44.       if method_exists$this$method ) ) {
  45.         return $this->$method($value);
  46.       }
  47.     }
  48.  
  49.     /// <summary>
  50.     /// Data export constructor, named Series
  51.     /// </summary>
  52.     public function DataExportFormat($c=null$s=null{
  53.  
  54.         $this->chart = $c;
  55.  
  56.         if ($s!=null{
  57.           $this->series = $s;
  58.         }
  59.     }
  60.  
  61.     public function lostOwnership($clipboard$contents{
  62.     }
  63.  
  64.     protected function prepare({
  65.         $tmp null;
  66.  
  67.         if ($this->series != null{
  68.             $tmp $this->series;
  69.         else
  70.         if ($this->chart->getSeriesCount(0{
  71.             $i 0;
  72.  
  73.             while (($i $this->chart->getSeriesCount())) {
  74.                 if ($this->chart->getSeries($i)->getCount(!= 0{
  75.                     $tmp $this->chart->getSeries($i);
  76.                     break;
  77.                 }
  78.                 $i++;
  79.             }
  80.         }
  81.  
  82.         if ($tmp != null{
  83.             $this->seriesGuessContents($tmp);
  84.         }
  85.  
  86.         if (!$this->includeLabels{
  87.             $this->hasLabels = false;
  88.         }
  89.     }
  90.  
  91.     private function seriesGuessContents($aSeries{
  92.         $this->hasNoMandatory = $this->hasNoMandatoryValues($aSeries);
  93.         $this->hasColors = $this->hasColors($aSeries);
  94.         $this->hasLabels = $this->hasLabels($aSeries);
  95.         $this->hasMarkPositions = $aSeries->getMarks()->getPositions()->existCustom();
  96.     }
  97.  
  98.     private function maxSeriesCount({
  99.         if ($this->series != null{
  100.             return $this->series->getCount();
  101.         else {
  102.             $tmpResult = -1;
  103.  
  104.             for $t 0$t $this->chart->getSeriesCount()$t++{
  105.                  $s $this->chart->getSeries($t);
  106.                 if ($s->getCount($tmpResult{
  107.                     $tmpResult $s->getCount();
  108.                 }
  109.             }
  110.             return $tmpResult;
  111.  
  112.         }
  113.     }
  114.  
  115.     // Returns if a Series has "X" values (or Y values for HorizBar series)
  116.     private function hasNoMandatoryValues($aSeries{
  117.  
  118.         $s $aSeries;
  119.  
  120.         if ($s->getCount(0{
  121.             $tmp $s->getNotMandatory();
  122.  
  123.             if (($tmp->getFirst(== 0&& ($tmp->getLast(== $s->getCount(1)) {
  124.  
  125.                  $tmpCount ($s->getCount(10000$s->getCount(:
  126.                                10000;
  127.  
  128.                 for $t 0$t <= $tmpCount$t++{
  129.                     if ($tmp->getValue($t!= $t{
  130.                         return true;
  131.                     }
  132.                 }
  133.             else {
  134.                 return true;
  135.             }
  136.         }
  137.  
  138.         return false;
  139.     }
  140.  
  141.     // Returns if a Series has Colors
  142.     private function hasColors($aSeries{
  143.         $s $aSeries;
  144.         $tmpSeriesColor $s->getColor();
  145.  
  146.         $tmpCount ($s->getCount(10000$s->getCount(10000;
  147.  
  148.         for $t 0$t <= $tmpCount$t++{
  149.              $tmpColor $s->getValueColor($t);
  150.  
  151.             if ((!$tmpColor->isEmpty()) &&
  152.                 ($this->tmpColor != $tmpSeriesColor)) {
  153.                 return true;
  154.             }
  155.         }
  156.         return false;
  157.     }
  158.  
  159.     // Returns if a Series has labels
  160.     private function hasLabels($aSeries{
  161.  
  162.         if (sizeof($aSeries->getLabels()) 0{
  163.  
  164.             $tmpCount ($aSeries->getCount(10000?
  165.                            $aSeries->getCount(:
  166.                            10000;
  167.  
  168.             for $t 0$t <= $tmpCount$t++{
  169.                 $labels=$aSeries->getLabels();
  170.                 if (strlen($labels[$t]!= 0{
  171.                     return true;
  172.                 }
  173.             }
  174.         }
  175.  
  176.         return false;
  177.     }
  178.  
  179.     protected function pointToString($index)
  180.     {}
  181.  
  182.     protected function getContent({
  183.         $this->prepare();
  184.  
  185.         $tmpResult="";
  186.  
  187.         $tmp $this->maxSeriesCount();
  188.  
  189.         for $t 0$t $tmp$t++{
  190.             $tmpResult $tmpResult . (string)$this->pointToString($t);
  191.             $tmpResult $tmpResult . (string)$this->textLineSeparator;
  192.         }
  193.  
  194.         return $tmpResult;
  195.     }
  196.  
  197.     /// <summary>
  198.     /// Save Chart to file with Data export format
  199.     /// </summary>
  200.     /// <param name="fileName">string eg. "c:\tempFiles\MyChart.xml"</param>
  201.     public function save($fileName/* TODO throw IOException*/ {
  202.  
  203.         $ffopen($fileName,'w');
  204.         if($f==false)
  205.         {
  206.               die("Unable to create file");
  207.         }
  208.         else
  209.         {
  210.           if (file_exists($fileName)) {
  211. // TODO             if (Utils::yesNo("File $exists-> " + "Overwrite ($this->y/$this->n)?"))
  212.                 $this->writeData($f);
  213.           }
  214.           else
  215.           {
  216.             $this->writeData($f);
  217.           }
  218.         }
  219.     }
  220.  
  221.     /// <summary>
  222.     /// Save Chart to stream with Data export format
  223.     /// </summary>
  224.     public function writeData($fw/* tODO throws IOException*/ {
  225.  
  226.       fwrite($fw$this->getContent());
  227.       fclose($fw);
  228.     }
  229.  
  230.     /// <summary>
  231.     /// return descriptive name of Dataformat
  232.     /// </summary>
  233.     protected function getDataFormat({
  234.         //TODO: ??
  235.         return ""// $this->DataFormats->Text;
  236.     }
  237.  
  238.     /// <summary>
  239.     /// Copy Chart data to clipboard
  240.     /// </summary>
  241.     public function copyToClipboard({
  242.         $this->Toolkit->getDefaultToolkit()->getSystemClipboard()->setContents(
  243.                 new StringSelection($this->getContent())$this);
  244.     }
  245.  
  246.     /// <summary>
  247.     /// Include the Series index with exported data
  248.     /// </summary>
  249.     public function getIncludeIndex({
  250.         return $this->includeIndex;
  251.     }
  252.  
  253.     public function setIncludeIndex($value{
  254.         $this->includeIndex $value;
  255.     }
  256.  
  257.     /// <summary>
  258.     /// Include the Series valuelist name with exported data
  259.     /// </summary>
  260.     public function getIncludeHeader({
  261.         return $this->includeHeader;
  262.     }
  263.  
  264.     public function setIncludeHeader($value{
  265.         $this->includeHeader $value;
  266.     }
  267.  
  268.     /// <summary>
  269.     /// Include the Series title with exported data
  270.     /// </summary>
  271.     public function getIncludeSeriesTitle({
  272.         return $this->includeSeriesTitle;
  273.     }
  274.  
  275.     public function setIncludeSeriesTitle($value{
  276.         $this->includeSeriesTitle $value;
  277.     }
  278.  
  279.     /// <summary>
  280.     /// Include data Labels with exported data
  281.     /// </summary>
  282.     public function getIncludeLabels({
  283.         return $this->includeLabels;
  284.     }
  285.  
  286.     public function setIncludeLabels($value{
  287.         $this->includeLabels $value;
  288.     }
  289.  
  290.     public function getFilterFiles({
  291.         return "";
  292.     }
  293.  
  294.     /// <summary>
  295.     /// Line separator for ascii export formats
  296.     /// </summary>
  297.     public function getTextLineSeparator({
  298.         return $this->textLineSeparator;
  299.     }
  300.  
  301.     public function setTextLineSeparator($value{
  302.         $this->textLineSeparator $value;
  303.     }
  304.  
  305.     /// <summary>
  306.     /// Series whose data is to be exported
  307.     /// </summary>
  308.     public function getSeries({
  309.         return $this->series;
  310.     }
  311.  
  312.     public function setSeries($value{
  313.         $this->series = $value;
  314.     }
  315.  
  316.     public function getFileExtension({
  317.         return $this->fileExtension;
  318.     }
  319.  
  320.     public function setFileExtension($value{
  321.         $this->fileExtension = $value;
  322.     }
  323. }
  324.  
  325. ?>

Documentation generated on Wed, 16 Jun 2010 12:04:59 +0200 by phpDocumentor 1.4.1