/** * Image_Graph_FunctionDataset [Constructor] * * @param double $minimumX The minimum X value * @param double $maximumX The maximum X value * @param string $function The name of the function, if must be a single * parameter function like fx sin(x) or cos(x) * @param int $points The number of points to create */ function __construct($minimumX, $maximumX, $function, $points) { parent::__construct(); $this->_minimumX = $minimumX; $this->_maximumX = $maximumX; $this->_dataFunction = $function; $this->_count = $points; $this->_calculateMaxima(); }
/** * Image_Graph_FunctionDataset [Constructor] * * @param double $minimumX The minimum X value * @param double $maximumX The maximum X value * @param string $function The name of the function, if must be a single * parameter function like fx sin(x) or cos(x) * @param int $points The number of points to create */ function Image_Graph_Dataset_Function($minimumX, $maximumX, $function, $points) { parent::Image_Graph_Dataset(); $this->_minimumX = $minimumX; $this->_maximumX = $maximumX; $this->_dataFunction = $function; $this->_count = $points; $this->_calculateMaxima(); }
/** * Image_Graph_VectorFunctionDataset [Constructor] * * @param double $minimumT The minimum value of the vector function variable * @param double $maximumT The maximum value of the vector function variable * @param string $functionX The name of the X function, if must be a single * parameter function like fx sin(x) or cos(x) * @param string $functionY The name of the Y function, if must be a single * parameter function like fx sin(x) or cos(x) * @param int $points The number of points to create */ function __construct($minimumT, $maximumT, $functionX, $functionY, $points) { parent::__construct(); $this->_minimumT = $minimumT; $this->_maximumT = $maximumT; $this->_functionX = $functionX; $this->_functionY = $functionY; $this->_count = $points; $this->_calculateMaxima(); }
/** * Image_Graph_VectorFunctionDataset [Constructor] * * @param double $minimumT The minimum value of the vector function variable * @param double $maximumT The maximum value of the vector function variable * @param string $functionX The name of the X function, if must be a single * parameter function like fx sin(x) or cos(x) * @param string $functionY The name of the Y function, if must be a single * parameter function like fx sin(x) or cos(x) * @param int $points The number of points to create */ function Image_Graph_Dataset_VectorFunction($minimumT, $maximumT, $functionX, $functionY, $points) { parent::__construct(); $this->_minimumT = $minimumT; $this->_maximumT = $maximumT; $this->_functionX = $functionX; $this->_functionY = $functionY; $this->_count = $points; $this->_calculateMaxima(); }
/** * Apply the dataset to the axis * * @param Image_Graph_Dataset $dataset The dataset * @access private */ function _applyDataset(&$dataset) { if ($this->_type == IMAGE_GRAPH_AXIS_X) { $this->_setMinimum($dataset->minimumX()); $this->_setMaximum($dataset->maximumX()); } else { $this->_setMinimum($dataset->minimumY()); $this->_setMaximum($dataset->maximumY()); } }
/** * Add a point to the dataset * * $ID can contain either the ID of the point, i.e. 'DK', 123, 'George', etc. or it can contain * values used for creation of the HTML image map. This is achieved using is an an associated array * with the following values: * * 'url' The URL to create the link to * * 'alt' [optional] The alt text on the link * * 'target' [optional] The target of the link * * 'htmltags' [optional] An associated array with html tags (tag as key), fx. 'onMouseOver' => 'history.go(-1);', 'id' => 'thelink' * * @param int $x The X value to add * @param int $y The Y value to add, can be omited * @param var $ID The ID of the point */ function addPoint($x, $y = false, $ID = false) { parent::addPoint($x, $y, $ID); if (is_array($ID)) { $data = $ID; $ID = isset($data['id']) ? $data['id'] : false; } else { $data = false; } $this->_data[] = array('X' => $x, 'Y' => $y, 'ID' => $ID, 'data' => $data); if (!is_numeric($x)) { $this->_maximumX = count($this->_data); } }
/** * Apply the dataset to the axis. * * This calculates the order of the categories, which is very important * for fx. line plots, so that the line does not "go backwards", consider * these X-sets:<p> * 1: (1, 2, 3, 4, 5, 6)<br> * 2: (0, 1, 2, 3, 4, 5, 6, 7)<p> * If they are not ordered, but simply appended, the categories on the axis * would be:<p> * X: (1, 2, 3, 4, 5, 6, 0, 7)<p> * Which would render the a line for the second plot to show incorrectly. * Instead this algorithm, uses and 'value- is- before' method to see that * the 0 is before a 1 in the second set, and that it should also be before * a 1 in the X set. Hence:<p> * X: (0, 1, 2, 3, 4, 5, 6, 7) * * @param Image_Graph_Dataset $dataset The dataset * @access private */ function _applyDataset(&$dataset) { $newLabels = array(); $allLabels = array(); $dataset->_reset(); $count = 0; $count_new = 0; while ($point = $dataset->_next()) { if ($this->_type == IMAGE_GRAPH_AXIS_X) { $data = $point['X']; } else { $data = $point['Y']; } if (!isset($this->_labels[$data])) { $newLabels[$data] = $count_new++; //$this->_labels[] = $data; } $allLabels[$data] = $count++; } if (count($this->_labels) == 0) { $this->_labels = $newLabels; } elseif (is_array($newLabels) && count($newLabels) > 0) { // get all intersecting labels $intersect = array_intersect(array_keys($allLabels), array_keys($this->_labels)); // traverse all new and find their relative position withing the // intersec, fx value X0 is before X1 in the intersection, which // means that X0 should be placed before X1 in the label array foreach ($newLabels as $newLabel => $id) { $key = $allLabels[$newLabel]; reset($intersect); $this_value = false; // intersect indexes are the same as in allLabels! $first = true; while ((list($id, $value) = each($intersect)) && $this_value === false) { if ($first && $id > $key) { $this_value = $value; } elseif ($id >= $key) { $this_value = $value; } $first = false; } if ($this_value === false) { // the new label was not found before anything in the // intersection -> append it $this->_labels[$newLabel] = count($this->_labels); } else { // the new label was found before $this_value in the // intersection, insert the label before this position in // the label array // $key = $this->_labels[$this_value]; $keys = array_keys($this->_labels); $key = array_search($this_value, $keys); $pre = array_slice($keys, 0, $key); $pre[] = $newLabel; $post = array_slice($keys, $key); $this->_labels = array_flip(array_merge($pre, $post)); } } unset($keys); } $labels = array_keys($this->_labels); $i = 0; foreach ($labels as $label) { $this->_labels[$label] = $i++; } // $this->_labels = array_values(array_unique($this->_labels)); $this->_calcLabelInterval(); }
/** * Add a point to the dataset * @param int $x The X value to add * @param int $y The Y value to add, can be omited * @param var $ID The ID of the point */ function addPoint($x, $y = false, $ID = false) { parent::addPoint($x, $y, $ID); $this->_data[] = array ('X' => $x, 'Y' => $y, 'ID' => $ID); }