<?php
class Goweb_Chart_TrendLine {
    
    // ------------------------------------------------ //
    // PROPERTIES -------------------------- PROPERTIES //
    // ------------------------------------------------ //
    private $_line = array();
    private $_options = array();
    private $_trendElement = array();
    
    // ------------------------------------------------ //
    // METHODS -------------------------------- METHODS //
    // ------------------------------------------------ //
    public function __construct() {
        $this->_options = array('startValue', 'endValue', 'displayValue', 
                                'color', 'isTrendZone', 'showOnTop', 
                                'thickness', 'alpha', 'dashed', 'dashLen',
                                'dashGap', 'valueOnRight');
    }
    
    public function add() {
        $trendLineInput = '<line ';
        foreach ($this->_line as $key => $value) {
            $trendLineInput .= $key . "='" . $value . "' ";
        }
        $trendLineInput .= ' />';
        $this->_trendElement[] = $trendLineInput;
        
        $this->_clearOptions();
    }
    
    public function render() {
        if (count($this->_trendElement) > 0) {
            $trendLineInputs = '<trendLines>';
            foreach ($this->_trendElement as $trendLineElement) {
                $trendLineInputs .= $trendLineElement;
            }
            $trendLineInputs .= '</trendLines>';
            return $trendLineInputs;
        } else {
            return "";
        }
    }
    
    public function __set($key, $value) {
        if (in_array($key, $this->_options)) {
            $this->_line[$key] = $value;
        }
    }
    
    private function _clearOptions() {
        $this->_line = array();
    }
    
}
?>
