<?php
# -----------------------------------------------------------------------------
#
# Plots a simple marker plot (optionally connected)
#
# -----------------------------------------------------------------------------
#
# Copyright (C) 2004 Christian Eheim
#
# This file is part of TVEz (tvez.sourceforge.net).
#
# TVEz is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# TVEz is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with TVEz; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
# -----------------------------------------------------------------------------
#
# Created on 02/01/2004 by Christian Eheim (hide@address.com)
#
# LAST MODIFIED:
# $Date: 2004/02/03 00:02:17 $
# $Revision: 1.2 $
# $Author: eheim $
#
# -----------------------------------------------------------------------------
/*
-------------------------------------------------------------------------------
TODO:
- Only works for evenly speced data right now
-------------------------------------------------------------------------------
*/
include("Graph.php");
class Plot extends Graph {
var $_sum;
var $_marker;
var $_markerColor;
var $_markerSize;
var $_connected;
var $_lineColor;
var $_graphLeft;
var $_graphTop;
var $_graphWidth;
var $_graphHeight;
var $_mcolor;
var $_lcolor;
function Plot($width,$height,$title=null) {
# Instantiate the base class
$this->Graph($width,$height,$title);
# Set the base class properties
$this->legend_show(false);
$this->set_bgcolor("#dddddd");
$this->set_margin(1,5,1,1);
$this->set_x_axis_title_margin(3);
$this->set_y_axis_title_margin(3);
$this->_marker = "circle";
$this->_markerColor = "red";
$this->_markerSize = 4;
$this->_lineColor = "red";
$this->_connected = false;
}
function set_marker_type($type) {
$this->_marker = $type;
}
function set_marker_size($size) {
$this->_markerSize = 2*$size;
}
function set_marker_color($color) {
$this->_markerColor = $color;
}
function set_line_color($color) {
$this->_lineColor = $color;
}
function set_marker_connected($bool) {
$this->_connected = $bool;
}
#
# Generate the legend items
# We only allow one data set at this time, so there is no reason
# for a legend
#
function generate_legend() {
;
}
#
# Generate the axes
#
function generate_axes() {
list($min,$max) = $this->minmax();
list($lx,$ly) = $this->get_longest();
if ($this->get_y_axis_min_value() === "unset")
$this->set_y_axis_min_value($min);
if ($this->get_y_axis_max_value() === "unset")
$this->set_y_axis_max_value($max);
if (! $this->get_x_axis_num_ticks()) {
$l = array();
foreach ($this->_data as $label => $value) {
array_push($l,$label);
}
$this->set_x_axis_labels($l);
}
else {
# This is not good
$lx = $this->get_x_axis_min_value();
}
$this->set_x_axis_longest($lx);
$this->set_y_axis_longest($ly);
# if ($this->get_y_axis_min_value() === "unset") {
# }
}
#
# Draw the Bar Graph
#
function create_graph() {
$min = $this->get_y_axis_min_value();
$max = $this->get_y_axis_max_value();
$this->_sum = $this->sum();
$this->compute();
$count = count($this->_data);
$dwidth = $this->_graphWidth / ($count-1);
$left = $this->_graphLeft;
$this->_mcolor = $this->_image->_rgb->allocate_color($this->_markerColor);
$this->_lcolor = $this->_image->_rgb->allocate_color($this->_lineColor);
$i=0;
$lastLeft = null; $lastTop = null;
foreach ($this->_data as $label => $value) {
$top = $this->_graphTop + $this->_graphHeight
- round((($value-$min)/($max-$min))*$this->_graphHeight);
$this->draw_marker($left,$top);
if ($this->_connected)
if ($lastLeft)
$this->draw_line($lastLeft,$lastTop,$left,$top);
$lastLeft = $left; $lastTop = $top;
$left += $dwidth;
}
}
function draw_marker($left,$top) {
switch ($this->_marker) {
case "diamond":
$values = array(
$left, $top+$this->_markerSize/2,
$left+$this->_markerSize/2, $top,
$left, $top-$this->_markerSize/2,
$left-$this->_markerSize/2, $top,
);
ImageFilledPolygon(
$this->_image->_image,
$values, 4,
$this->_mcolor
);
break;
default:
ImageFilledEllipse (
$this->_image->_image,
$left, $top,
$this->_markerSize, $this->_markerSize,
$this->_mcolor
);
break;
}
}
function draw_line($lastLeft,$lastTop,$left,$top) {
ImageLine (
$this->_image->_image,
$lastLeft, $lastTop,
$left, $top,
$this->_lcolor
);
}
#
# Compute the center and size
#
function compute() {
list(
$this->_graphLeft, $this->_graphTop,
$this->_graphWidth, $this->_graphHeight
) = $this->_image->get_graph_area();
}
}
?>