From: Ariel G. <ag...@us...> - 2001-12-03 23:51:17
|
Update of /cvsroot/vagrant/vagrant-2.5 In directory usw-pr-cvs1:/tmp/cvs-serv32015 Modified Files: ImagePrimitives.class Graph.class VAGRANT.class Log Message: Now handles empty datasets (by disregarding them) and validates mins and maxes to prevent multiple divide by zero errors. If a single datapoint is entered and no max or mins are specified by the user, the mins are .5 less than the value of the data and the maxes are .5 higher. Index: ImagePrimitives.class =================================================================== RCS file: /cvsroot/vagrant/vagrant-2.5/ImagePrimitives.class,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** ImagePrimitives.class 2001/12/03 18:21:05 1.6 --- ImagePrimitives.class 2001/12/03 23:51:14 1.7 *************** *** 62,77 **** // Font Defaults // ! $this->DEFAULTS['default_font'] = VAGRANT_DEFAULT_FONT; ! $this->DEFAULTS['x_tick_font'] = VAGRANT_DEFAULT_SMALL_FONT; ! $this->DEFAULTS['x_title_font'] = VAGRANT_DEFAULT_MEDIUM_FONT; ! $this->DEFAULTS['y_tick_font'] = VAGRANT_DEFAULT_SMALL_FONT; ! $this->DEFAULTS['y_title_font'] = VAGRANT_DEFAULT_MEDIUM_FONT; ! $this->DEFAULTS['axis2_tick_font'] = VAGRANT_DEFAULT_SMALL_FONT; ! $this->DEFAULTS['axis2_title_font'] = VAGRANT_DEFAULT_MEDIUM_FONT; ! $this->DEFAULTS['title_font'] = VAGRANT_DEFAULT_LARGE_FONT; ! $this->DEFAULTS['subtitle_font'] = VAGRANT_DEFAULT_MEDIUM_FONT; ! $this->DEFAULTS['highlight_font'] = VAGRANT_DEFAULT_SMALL_FONT; ! $this->DEFAULTS['legend_font'] = VAGRANT_DEFAULT_SMALL_FONT; ! $this->DEFAULTS['legend_title_font'] = VAGRANT_DEFAULT_SMALL_FONT; // Various padding parameters --- 62,78 ---- // Font Defaults // ! $this->DEFAULTS['default_font'] = VAGRANT_DEFAULT_FONT; ! $this->DEFAULTS['x_tick_font'] = VAGRANT_DEFAULT_SMALL_FONT; ! $this->DEFAULTS['x_title_font'] = VAGRANT_DEFAULT_MEDIUM_FONT; ! $this->DEFAULTS['y_tick_font'] = VAGRANT_DEFAULT_SMALL_FONT; ! $this->DEFAULTS['y_title_font'] = VAGRANT_DEFAULT_MEDIUM_FONT; ! $this->DEFAULTS['axis2_tick_font'] = VAGRANT_DEFAULT_SMALL_FONT; ! $this->DEFAULTS['axis2_title_font'] = VAGRANT_DEFAULT_MEDIUM_FONT; ! $this->DEFAULTS['title_font'] = VAGRANT_DEFAULT_LARGE_FONT; ! $this->DEFAULTS['subtitle_font'] = VAGRANT_DEFAULT_MEDIUM_FONT; ! $this->DEFAULTS['highlight_font'] = VAGRANT_DEFAULT_SMALL_FONT; ! $this->DEFAULTS['legend_font'] = VAGRANT_DEFAULT_SMALL_FONT; ! $this->DEFAULTS['legend_title_font'] = VAGRANT_DEFAULT_SMALL_FONT; ! $this->DEFAULTS['no_data_string_font'] = VAGRANT_DEFAULT_MEDIUM_FONT; // Various padding parameters *************** *** 105,123 **** // Set up colors // ! $this->DEFAULTS['background_color'] = 'white'; ! $this->DEFAULTS['axis_color'] = 'black'; ! $this->DEFAULTS['grid_color'] = 'gray'; ! $this->DEFAULTS['x_tick_color'] = 'black'; ! $this->DEFAULTS['x_title_color'] = 'black'; ! $this->DEFAULTS['y_tick_color'] = 'black'; ! $this->DEFAULTS['y_title_color'] = 'black'; ! $this->DEFAULTS['axis2_tick_color'] = 'black'; ! $this->DEFAULTS['axis2_title_color'] = 'black'; ! $this->DEFAULTS['title_color'] = 'black'; ! $this->DEFAULTS['subtitle_color'] = 'black'; ! $this->DEFAULTS['legend_background'] = 'white'; ! $this->DEFAULTS['legend_title_color'] = 'black'; ! $this->DEFAULTS['legend_text_color'] = 'black'; ! $this->DEFAULTS['legend_border_color'] = 'black'; // Grid parameters --- 106,125 ---- // Set up colors // ! $this->DEFAULTS['background_color'] = 'white'; ! $this->DEFAULTS['axis_color'] = 'black'; ! $this->DEFAULTS['grid_color'] = 'gray'; ! $this->DEFAULTS['x_tick_color'] = 'black'; ! $this->DEFAULTS['x_title_color'] = 'black'; ! $this->DEFAULTS['y_tick_color'] = 'black'; ! $this->DEFAULTS['y_title_color'] = 'black'; ! $this->DEFAULTS['axis2_tick_color'] = 'black'; ! $this->DEFAULTS['axis2_title_color'] = 'black'; ! $this->DEFAULTS['title_color'] = 'black'; ! $this->DEFAULTS['subtitle_color'] = 'black'; ! $this->DEFAULTS['legend_background'] = 'white'; ! $this->DEFAULTS['legend_title_color'] = 'black'; ! $this->DEFAULTS['legend_text_color'] = 'black'; ! $this->DEFAULTS['legend_border_color'] = 'black'; ! $this->DEFAULTS['no_data_string_color'] = "red"; // Grid parameters *************** *** 144,147 **** --- 146,150 ---- $this->DEFAULTS['legend_top'] = -1; // it will adjust to the bottom left corner $this->DEFAULTS['legend_left'] = -1; // + $this->DEFAULTS['no_data_string'] = "No Data Available"; } // function InitializePrimitives *************** *** 259,268 **** if ($axis2) { ! $y_min = $this->GetValue('axis2_min'); ! $y_data_diff = $this->GetValue('axis2_data_diff'); } // if we are using axis2 values else { ! $y_min = $this->GetValue('y_min'); ! $y_data_diff = $this->GetValue('y_data_diff'); } // else use the y axis for the translation --- 262,269 ---- if ($axis2) { ! $axis_name = 'axis2'; } // if we are using axis2 values else { ! $axis_name = 'y'; } // else use the y axis for the translation *************** *** 296,301 **** $vertical_space = $this->GetValue('y_padding') + $this->GetValue('y_top_padding') + $this->GetValue('y_bottom_padding') + $this->GetValue('x_tick_padding') + $title_padding + $x_title_padding; ! $x_pixel = $this->GetValue('y_tick_padding') + $this->GetValue('x_padding') + (($x_value - $this->GetValue('x_min')) / $this->GetValue('x_data_diff')) * ($this->GetValue('width') - $horizontal_space); ! $y_pixel = $this->GetValue('y_padding') + (1 - (($y_value - $y_min) / $y_data_diff)) * ($this->GetValue('height') - $vertical_space); $x_pixel += $this->GetValue('origin_x') + $y_title_padding; --- 297,313 ---- $vertical_space = $this->GetValue('y_padding') + $this->GetValue('y_top_padding') + $this->GetValue('y_bottom_padding') + $this->GetValue('x_tick_padding') + $title_padding + $x_title_padding; ! if ($this->GetValue('x_data_diff')) { ! $x_pixel = $this->GetValue('y_tick_padding') + $this->GetValue('x_padding') + (($x_value - $this->GetValue('x_min')) / $this->GetValue('x_data_diff')) * ($this->GetValue('width') - $horizontal_space); ! } // if we have a difference in the data ! else { ! $x_pixel = $this->GetValue('y_tick_padding') + $this->GetValue('x_padding') + (($x_value - $this->GetValue('x_min')) / $this->GetValue('x_data_diff')) * ($this->GetValue('width') - $horizontal_space); ! } ! ! if ($y_data_diff) { ! $y_pixel = $this->GetValue('y_padding') + (1 - (($y_value - $this->GetValue($axis_name . '_min')) / $this->GetValue($axis_name . '_data_diff'))) * ($this->GetValue('height') - $vertical_space); ! } // if we have a difference in data ! else { ! $y_pixel = $this->GetValue('y_padding') + (1 - (($y_value - $this->GetValue($axis_name . '_min')) / $this->GetValue($axis_name . '_data_diff'))) * ($this->GetValue('height') - $vertical_space); ! } $x_pixel += $this->GetValue('origin_x') + $y_title_padding; *************** *** 507,510 **** --- 519,523 ---- */ function GetTick($data_diff, $num_grid, $integer = false) { + $num_grid = max($num_grid, 1); $tick_guess = $data_diff / $num_grid; $tick = $this->AdjustNum($tick_guess, $data_diff); *************** *** 537,545 **** $multiplier = pow(10, $this->GetValue('grid_precision')); - $decimals = floor(log10($data_diff)); - $divisor = pow(10,$decimals); - $num = $round_func($num / $divisor * $multiplier) * $divisor / $multiplier; - return $num; } // function AdjustNum --- 550,557 ---- $multiplier = pow(10, $this->GetValue('grid_precision')); + $decimals = floor(log10($data_diff)); + $divisor = pow(10,$decimals); + $num = $round_func($num / $divisor * $multiplier) * $divisor / $multiplier; return $num; } // function AdjustNum *************** *** 554,557 **** --- 566,618 ---- /** + * ValidData makes checks whether or not this graph contains any datasets + * + * @author Ariel Garza (ag...@va...) + */ + function ValidData() { + return sizeof($this->datasets); + } // function ValidData + + + /** + * ValidateExtents makes sure that we always have a max greater than the min for each axis + */ + function ValidateExtents() { + if (!$this->GetValue('x_data_diff')) { + $this->SetValue('x_min', $this->GetValue('x_min') - .5); + $this->SetValue('x_max', $this->GetValue('x_max') + .5); + } // if we had no x diff + + if (!$this->GetValue('y_data_diff')) { + $this->SetValue('y_min', $this->GetValue('y_min') - .5); + $this->SetValue('y_max', $this->GetValue('y_max') + .5); + } // if we had no y diff + + if (is_array($this->axis2_data) && sizeof($this->axis2_data)) { + if (!$this->GetValue('axis2_data_diff')) { + $this->SetValue('y_min', $this->GetValue('axis2_min')); + $this->SetValue('y_max', $this->GetValue('axis2_max')); + } // if we had no y diff + } // if we have axis2 data + } // function ValidateExtents + + + /** + * ShowNoData shows a no data string + * + * @author Ariel Garza (ag...@va...) + */ + function ShowNoData() { + $text_size = $this->image_object->GetTextSize($this->GetValue('no_data_string'), TEXT_HORIZONTAL, $this->GetFont($this->GetValue('no_data_string_font'))); + + $x_pos = $this->width / 2 + $this->origin_x - $text_size['width'] / 2; + $y_pos = $this->height / 2 + $this->origin_x - $text_size['height'] / 2; + + $this->image_object->DrawText($this->GetFont($this->GetValue('no_data_string_font')), $x_pos, $y_pos, $this->GetValue('no_data_string'), + $this->GetColor($this->GetValue('no_data_string_color')), TEXT_HORIZONTAL); + } // function ShowNoData + + + /** * AddData adds a dataset to this object. The dataset itself should just be a pointer to the real data set * to conserve memory. *************** *** 563,566 **** --- 624,633 ---- */ function AddData($id, $dataset, $axis2 = false) { + if (!is_array($dataset['x']) || !is_array($dataset['y']) || + !sizeof($dataset['x']) || !sizeof($dataset['y'])) { + + return false; + } // if + $this->datasets[$id] = $dataset; *************** *** 664,671 **** --- 731,740 ---- case('x_tick'): + $value = max(1, $value); $this->USER_VALUES['num_x_grid'] = ceil($this->GetValue('x_data_diff') / $value); break; case('y_tick'): + $value = max(1, $value); $this->USER_VALUES['num_y_grid'] = ceil($this->GetValue('y_data_diff') / $value); break; *************** *** 860,864 **** } // if...else... are we setting an internal or user value? ! return $this->GetValue('x_data_diff'); } // function SetXDataDiff --- 929,933 ---- } // if...else... are we setting an internal or user value? ! return $this->GetValue('x_data_diff', $internal); } // function SetXDataDiff *************** *** 879,883 **** } // if...else... are we setting an internal or user value? ! return $this->y_data_diff; } // function SetYDataDiff --- 948,952 ---- } // if...else... are we setting an internal or user value? ! return $this->GetValue('y_data_diff', $internal); } // function SetYDataDiff *************** *** 898,902 **** } // if...else... are we setting an internal or user value? ! return $this->axis2_data_diff; } // function SetAxis2DataDiff --- 967,971 ---- } // if...else... are we setting an internal or user value? ! return $this->GetValue('axis2_data_diff', $internal); } // function SetAxis2DataDiff *************** *** 966,970 **** return false; - //return array(array('x' => $start_point['x'], 'y' => $this->GetValue($axis_max)), array('x' => $end_point['x'], 'y' => $this->GetValue($axis_max))); } --- 1035,1038 ---- Index: Graph.class =================================================================== RCS file: /cvsroot/vagrant/vagrant-2.5/Graph.class,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** Graph.class 2001/12/01 00:52:09 1.6 --- Graph.class 2001/12/03 23:51:14 1.7 *************** *** 43,46 **** --- 43,48 ---- $this->GetColor($this->GetValue('background_color'))); + $this->ValidateExtents(); + // First let's focus on the x axis. // If the user has assigned either a max or a minimum, those values will be used at *************** *** 314,318 **** $this->DrawXTitle(); $this->DrawYTitle(); ! $this->DrawAxis2Title(); } // function DrawGrid --- 316,323 ---- $this->DrawXTitle(); $this->DrawYTitle(); ! ! if ($axis2_data) { ! $this->DrawAxis2Title(); ! } // if we have axis2 data } // function DrawGrid Index: VAGRANT.class =================================================================== RCS file: /cvsroot/vagrant/vagrant-2.5/VAGRANT.class,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** VAGRANT.class 2001/12/01 00:53:54 1.5 --- VAGRANT.class 2001/12/03 23:51:14 1.6 *************** *** 75,78 **** --- 75,79 ---- $this->image_object->InitImage(); + $this->added_data = array(); $this->highlight_map = array(); $this->legend_map = array(); *************** *** 148,152 **** function AddData($x_data, $y_data, $object_id = "", $axis2 = false) { ! $dataset_id = sizeof($this->datasets); $this->datasets[$dataset_id]['x'] = $x_data; --- 149,157 ---- function AddData($x_data, $y_data, $object_id = "", $axis2 = false) { ! if (!is_array($x_data) || !is_array($y_data) || !sizeof($x_data) || !sizeof($y_data)) { ! return false; ! } // if we have a dataset ! ! $dataset_id = "dataset-" . sizeof($this->datasets); $this->datasets[$dataset_id]['x'] = $x_data; *************** *** 156,160 **** $this->AddObjectData($object_id, $dataset_id, $axis2); } // if there was an object_id passed in ! return $dataset_id; } // function AddData --- 161,165 ---- $this->AddObjectData($object_id, $dataset_id, $axis2); } // if there was an object_id passed in ! return $dataset_id; } // function AddData *************** *** 228,236 **** $object_array = $this->GetObjectArrayFromID($object_id); ! if ($object_array) { ! $this->data_map[$object_id][$dataset_id] = $dataset_id; ! ! $this->{$object_array}[$object_id]->AddData($dataset_id, &$this->datasets[$dataset_id], $axis2); ! return true; } // if we are adding data to a chart --- 233,245 ---- $object_array = $this->GetObjectArrayFromID($object_id); ! if ($object_array && ("$dataset_id" !== "")) { ! if ($this->{$object_array}[$object_id]->AddData($dataset_id, &$this->datasets[$dataset_id], $axis2)) { ! $this->data_map[$object_id][$dataset_id] = $dataset_id; ! $this->added_data[$object_array][$object_id] = 1; ! return true; ! } // if we added the data successfully ! else { ! return false; ! } // else we could not add the data } // if we are adding data to a chart *************** *** 303,321 **** @reset($this->graphs); while (list($graph_id,) = each($this->graphs)) { ! $this->graphs[$graph_id]->DrawGrid(); ! while (list($dataset_id, $map) = @each($this->graph_map[$graph_id])) { ! $this->graphs[$graph_id]->DrawGraph($dataset_id, $map['type'], $map['color'], $map['options']); ! } // while we step through the data in this graph ! if (is_array($this->highlight_map[$graph_id]) && sizeof($this->highlight_map[$graph_id])) { ! while (list($highlight_id,) = @each($this->highlight_map[$graph_id])) { ! $this->graphs[$graph_id]->DrawHighlight($highlight_id); ! } // while we step through the highlights for this graph ! } // if we have highlights to show ! if (is_array($this->legend_map[$graph_id]) && sizeof($this->legend_map[$graph_id])) { ! $this->graphs[$graph_id]->DrawLegend($this->legend_map[$graph_id]); ! } // if we have legends to show } // while we step through the charts } // if we have graphs to draw --- 312,337 ---- @reset($this->graphs); while (list($graph_id,) = each($this->graphs)) { ! if ($this->added_data['graphs'][$graph_id]) { ! $this->graphs[$graph_id]->DrawGrid(); ! if ($this->graphs[$graph_id]->ValidData()) { ! while (list($dataset_id, $map) = @each($this->graph_map[$graph_id])) { ! $this->graphs[$graph_id]->DrawGraph($dataset_id, $map['type'], $map['color'], $map['options']); ! } // while we step through the data in this graph ! if (is_array($this->highlight_map[$graph_id]) && sizeof($this->highlight_map[$graph_id])) { ! while (list($highlight_id,) = @each($this->highlight_map[$graph_id])) { ! $this->graphs[$graph_id]->DrawHighlight($highlight_id); ! } // while we step through the highlights for this graph ! } // if we have highlights to show ! if (is_array($this->legend_map[$graph_id]) && sizeof($this->legend_map[$graph_id])) { ! $this->graphs[$graph_id]->DrawLegend($this->legend_map[$graph_id]); ! } // if we have legends to show ! } // if this graph has valid data ! } // if this graph had data added to it ! else { ! $this->graphs[$graph_id]->ShowNoData($object_id); ! } // else show that no data was added } // while we step through the charts } // if we have graphs to draw *************** *** 362,366 **** $object_array = $this->GetObjectArrayFromID($graph_id); ! if ($object_array) { $this->graph_map[$graph_id][$dataset_id]['type'] = $type; $this->graph_map[$graph_id][$dataset_id]['color'] = $color; --- 378,382 ---- $object_array = $this->GetObjectArrayFromID($graph_id); ! if ($object_array && $dataset_id) { $this->graph_map[$graph_id][$dataset_id]['type'] = $type; $this->graph_map[$graph_id][$dataset_id]['color'] = $color; |