<?

// обозначения графика
class Gr_legend {

	public $graph;
	public $graph_name; // без слова graph
	public $color_hidden = 0xaaaaaa;
	/*
	$story = {
		nomer => { nomer совпадает с ключом строки
			visible:0/1
			v: значение
			name
		}
	}
	*/
	public $story = array(); 
	protected $fmName = 'Fm';
		
	// fields_name никак не связан с классом fields
	function __construct($graph, $fields_name) {
		$this->graph = $graph;
		$this->graph_name = str_replace('graph_', '', $graph->name);

		$this->story = array();
		foreach($fields_name as $col_key=>$name) {
			$this->story[$col_key] = array('v'=>0, 'visible'=>-1, 'name'=>$name, 'about'=>0);

			$this->visible($col_key, 1); // нужно чтобы установились цвета
		}
	}

	// показываем что значение строки приблизительное
	function about($nomer, $is_about) {
		if($this->story[$nomer]['about'] == $is_about)
			return false;

		$this->story[$nomer]['about'] = $is_about;

		$name = $this->story[$nomer]['name'];
		$field_name = "{$this->graph_name}_{$name}";

		c($this->fmName."->{$field_name}_about")->visible = $is_about;
	}

	function visible($nomer, $is_visible) {
		GLOBAL $log;

		if($this->story[$nomer]['visible'] == $is_visible)
			return false;

		$this->story[$nomer]['visible'] = $is_visible;

		$name = $this->story[$nomer]['name'];
		$field_name = "{$this->graph_name}_{$name}";

		$display = c($this->fmName.'->'.$field_name. '_display');
		$mark = c($this->fmName.'->'.$field_name. '_mark');
		$text = c($this->fmName.'->'.$field_name);

		if($is_visible == 1) { // показываем
			$display->visible = 1;
			$mark->brushColor = $this->graph->col_colors[$nomer][0];
			$mark->penStyle = 'psSolid';
			$text->enabled = 1;
		}
		else { // скрываем
			$display->visible = 0;
			$this->color = $mark->brushColor;
			$mark->brushColor = $this->color_hidden;
			$mark->penStyle = 'psClear';
			$text->enabled = 0;

			// обнуляем строку
			$this->graph->set_col($nomer, 0);
		}
	}

	function get_visible($nomer) {
		return $this->story[$nomer]['visible'];
	}

	function set($nomer, $v) {
		GLOBAL $log;
		if(!isset($this->story[$nomer]))
			throw new Error_def("Поле $nomer не существует");

		$field = $this->story[$nomer];

		if($field['v'] != $v) {
			$this->story[$nomer]['v'] = $v;
			cCache_text($this->fmName.'->'."{$this->graph_name}_{$field['name']}_display", $v);
		}
	}

	function get($nomer) {
		if(!isset($this->story[$nomer]))
			throw new Error_def("Поле $nomer не существует");

		return $this->story[$nomer]['v'];
	}

	// возвращаем все легенды в виде массива  array(имя=>значение, ..)
	function get_all_values() {

		$results = array();
		foreach($this->story as $key) {
			$name = $key['name'];
			$value = $key['v'];
			$results[$name] = $value;
		}

		return $results;
	}
}


?>