<?php

/**
 * Google_Format_Arrow
 * 
 * @author Thomas Schaefer
 * @copyright Thomas Schaefer
 * @since 2009-05-20
 * @desc Adds an up or down arrow to a numeric cell, depending on whether the
 * value is above or below a specified base value. If equal to the base value,
 * no arrow is shown.
 */
class Google_Format_Arrow implements Google_Format_Interface {

    private static 
$isRegistered = array(
        
"base"=>true
    
);
    private 
$provider 'google';
    private 
$scope 'visualization';
    private 
$type 'ArrowFormat';
    private 
$dataTable 'data';
    private 
$columnIndex 0;
    private 
$base '';
    private 
$properties=null;

    public function 
__construct() {}

    public function 
__set($name$value) {
        if(
array_key_exists($nameself::$isRegistered)) {
            if(empty(
$this->properties)) {
                
$this->properties = new stdClass;
            }
            
$this->properties->{$name} = $value;
        } else {
            throw new 
Exception("no such property named "$name);
        }
    }

    
/**
     * desc The standard format() method to apply formatting to the specified
     * column.
     * @param string $dataTable
     * @param integer $columnIndex
     */
    
public function format($dataTable$columnIndex) {
        
$this->dataTable $dataTable;
        
$this->columnIndex $columnIndex;
    }

    public function 
__toString() {
        
$string 'var formatter=new ';
        
$string .= $this->provider;
        
$string .= '.';
        
$string .= $this->scope;
        
$string .= '.';
        
$string .= $this->type;
        
$string .= '('. (!empty($this->properties)?Google_Base::toJson($this->properties):'').');';
        
$string .= "\n";
        
$string .= 'formatter.format('.$this->dataTable.', '.$this->columnIndex.');';
        
$string .= "\n";
        return 
$string;
    }
}