function drawComponent($drawer, $x1, $y1, $x2, $y2, $aliasing) { foreach ($this->functions as $function) { $f = $function->f; $fromX = is_null($function->fromX) ? $this->extremum->left : $function->fromX; $toX = is_null($function->toX) ? $this->extremum->right : $function->toX; $old = NULL; for ($i = $fromX; $i <= $toX; $i += $this->interval) { $p = awAxis::toPosition($this->xAxis, $this->yAxis, new awPoint($i, $f($i))); if ($p->y >= $y1 and $p->y <= $y2) { $function->mark->draw($drawer, $p); } if ($old !== NULL) { $line = $function->line; $line->setLocation($old, $p); if ($line->p1->y >= $y1 and $line->p1->y <= $y2 or $line->p2->y >= $y1 and $line->p2->y <= $y2) { $drawer->line($function->getColor(), $line); } } $old = $p; } // Draw last point if needed if ($old !== NULL and $i - $this->interval != $toX) { $p = awAxis::toPosition($this->xAxis, $this->yAxis, new awPoint($toX, $f($toX))); if ($p->y >= $y1 and $p->y <= $y2) { $function->mark->draw($drawer, $p); } $line = $function->line; $line->setLocation($old, $p); if ($line->p1->y >= $y1 and $line->p1->y <= $y2 or $line->p2->y >= $y1 and $line->p2->y <= $y2) { $drawer->line($function->getColor(), $line); } } } }
public function drawComponent(awDrawer $drawer, $x1, $y1, $x2, $y2, $aliasing) { $count = count($this->datay); $max = $this->getRealYMax(NULL); $min = $this->getRealYMin(NULL); // Find zero for bars if ($this->xAxisZero and $min <= 0 and $max >= 0) { $zero = 0; } else { if ($max < 0) { $zero = $max; } else { $zero = $min; } } // Get base position $zero = awAxis::toPosition($this->xAxis, $this->yAxis, new awPoint(0, $zero)); // Distance between two values on the graph $distance = $this->xAxis->getDistance(0, 1); // Compute paddings $leftPadding = $this->barPadding->left * $distance; $rightPadding = $this->barPadding->right * $distance; $padding = $leftPadding + $rightPadding; $space = $this->barSpace * ($this->number - 1); $barSize = ($distance - $padding - $space) / $this->number; $barPosition = $leftPadding + $barSize * ($this->identifier - 1); for ($key = 0; $key < $count; $key++) { $value = $this->datay[$key]; if ($value !== NULL) { $position = awAxis::toPosition($this->xAxis, $this->yAxis, new awPoint($key, $value)); $barStart = $barPosition + ($this->identifier - 1) * $this->barSpace + $position->x; $barStop = $barStart + $barSize; $t1 = min($zero->y, $position->y); $t2 = max($zero->y, $position->y); if (round($t2 - $t1) == 0) { continue; } $p1 = new awPoint(round($barStart) + $this->depth + $this->move->left, round($t1) - $this->depth + $this->move->top); $p2 = new awPoint(round($barStop) + $this->depth + $this->move->left, round($t2) - $this->depth + $this->move->top); $this->drawBar($drawer, $p1, $p2); } } // Draw labels foreach ($this->datay as $key => $value) { if ($value !== NULL) { $position = awAxis::toPosition($this->xAxis, $this->yAxis, new awPoint($key, $value)); $point = new awPoint($barPosition + ($this->identifier - 1) * $this->barSpace + $position->x + $barSize / 2 + 1 + $this->depth, $position->y - $this->depth); $this->label->draw($drawer, $point, $key); } } }
protected function yAxis(awAxis $axis) { $axis->addTick('major', new awTick(0, 5)); $axis->addTick('minor', new awTick(0, 3)); $axis->setNumberByTick('minor', 'major', 3); $axis->label->setFont(new awTuffy(7)); $axis->title->setAngle(90); }
protected function xAxisPoint($position) { $y = $this->xAxisZero ? 0 : $this->getRealYMin(); return awAxis::toPosition($this->xAxis, $this->yAxis, new awPoint($position, $y)); }
/** * Center Y values of the axis * * @param awAxis $axis An axis * @param float $value The reference value on the axis */ public function setYCenter(awAxis $axis, $value) { // Check vector angle if ($this->line->isHorizontal() === FALSE) { trigger_error("setYCenter() can only be used on horizontal axes", E_USER_ERROR); } $p = $axis->getPointFromValue($value); $this->line->setY($p->y, $p->y); }
/** * Center Y values of the axis * * @param awAxis $axis An axis * @param float $value The reference value on the axis */ public function setYCenter(awAxis $axis, $value) { // Check vector angle if ($this->line->isHorizontal() === FALSE) { awImage::drawError("Class Axis: setYCenter() can only be used on horizontal axes."); } $p = $axis->getPointFromValue($value); $this->line->setY($p->y, $p->y); }
public function drawComponent(awDrawer $drawer, $x1, $y1, $x2, $y2, $aliasing) { $this->label->setFont(new Tuffy(8)); $datayReal = $this->datay; $dataySkewed = array(); for ($index = 0; $index < count($this->datay); $index++) { $dataySkewed[$index] = false; } $count = count($this->datay); $max = $this->getRealYMax(NULL); $min = $this->getRealYMin(NULL); // Find zero for bars if ($this->xAxisZero and $min <= 0 and $max >= 0) { $zero = 0; } else { if ($max < 0) { $zero = $max; } else { $zero = $min; } } // Get base position $zero = awAxis::toPosition($this->xAxis, $this->yAxis, new awPoint(0, $zero)); // Distance between two values on the graph $distance = $this->xAxis->getDistance(0, 1); // Compute paddings $leftPadding = $this->barPadding->left * $distance; $rightPadding = $this->barPadding->right * $distance; $padding = $leftPadding + $rightPadding; $space = $this->barSpace * ($this->number - 1); $barSize = ($distance - $padding - $space) / $this->number; $barPosition = $leftPadding + $barSize * ($this->identifier - 1); for ($key = 0; $key < $count; $key++) { $value = $this->datay[$key]; if ($value !== NULL) { /* Determine if we should use cut symbol */ $position = awAxis::toPosition($this->xAxis, $this->yAxis, new awPoint($key, $value)); $barStart = $barPosition + ($this->identifier - 1) * $this->barSpace + $position->x; $barStop = $barStart + $barSize; $t1 = min($zero->y, $position->y); $t2 = max($zero->y, $position->y); if (round($t2 - $t1) == 0) { continue; } if ($dataySkewed[$key]) { $xmin = round($t1) - $this->depth + $this->move->top; $xmax = round($t2) - $this->depth + $this->move->top; $dividerPoint = ($xmax - $xmin) * 0.2 + $xmin; $p1x = round($barStart) + $this->depth + $this->move->left; $p1y = round($t1) - $this->depth + $this->move->top; $p2x = round($barStop) + $this->depth + $this->move->left; $p2y = round($t2) - $this->depth + $this->move->top; $p1 = new awPoint($p1x, $p1y); $p2 = new awPoint($p2x, $p2y); $this->drawBar($drawer, $p1, $p2, $key); $lineX = round($barStop) + $this->depth + $this->move->left; $lineY = $dividerPoint; /* Draw a two-pixel white line over the bar at the divider point. */ $white = imagecolorallocate($drawer->resource, 255, 255, 255); imageline($drawer->resource, $lineX - $barSize + 1, $lineY, $lineX + 1, $lineY, $white); imageline($drawer->resource, $lineX - $barSize + 1, $lineY + 1, $lineX + 1, $lineY + 1, $white); } else { $p1 = new awPoint(round($barStart) + $this->depth + $this->move->left, round($t1) - $this->depth + $this->move->top); $p2 = new awPoint(round($barStop) + $this->depth + $this->move->left, round($t2) - $this->depth + $this->move->top); $this->drawBar($drawer, $p1, $p2, $key); } } } $maxValue = $this->maxValue; // Draw labels foreach ($datayReal as $key => $value) { if ($value !== NULL) { if ($value > $maxValue) { $maxValue = $value; } $position = awAxis::toPosition($this->xAxis, $this->yAxis, new awPoint($key, $this->datay[$key])); $position2 = awAxis::toPosition($this->xAxis, $this->yAxis, new awPoint($key, $this->datay[$key] / 2)); $point = new awPoint($barPosition + ($this->identifier - 1) * $this->barSpace + $position->x + $barSize / 2 + 1 + $this->depth, $position->y - $this->depth); $point2 = new awPoint($barPosition + ($this->identifier - 1) * $this->barSpace + $position2->x + $barSize / 2 + 1 + $this->depth, $position2->y - $this->depth); if ($maxValue == 0) { $maxValue = 1; } if ($value != 0 && $this->drawPercent) { /* Mode 2 is the white box number at the top of the bar */ $this->label->drawSpecial($drawer, $point2, $key, $value); //$this->label->draw($drawer, $point, $key); } } } switch ($this->view) { case DASHBOARD_GRAPH_YEARLY: $tabImage = imagecreatefrompng('images/tab3.png'); imagecopy($drawer->resource, $tabImage, 399, 0, 0, 0, 63, 73); break; case DASHBOARD_GRAPH_MONTHLY: $tabImage = imagecreatefrompng('images/tab2.png'); imagecopy($drawer->resource, $tabImage, 399, 0, 0, 0, 63, 73); break; case DASHBOARD_GRAPH_WEEKLY: default: $tabImage = imagecreatefrompng('images/tab1.png'); imagecopy($drawer->resource, $tabImage, 399, 0, 0, 0, 63, 73); break; } if ($this->noData) { $noDataImage = imagecreatefromjpeg('images/graphNoData.jpg'); imagecopy($drawer->resource, $noDataImage, 27, 13, 0, 0, 363, 195); } }
public function drawComponent(awDrawer $drawer, $x1, $y1, $x2, $y2, $aliasing) { $datayReal = $this->datay; $dataySkewed = array(); for ($index = 0; $index < count($this->datay); $index++) { $dataySkewed[$index] = false; } if (count($this->datay) > 5) { for ($index = 0; $index < count($this->datay); $index++) { if ($index < 3) { if ($this->datay[$index] * 0.5 > $this->datay[$index + 1] && $this->datay[$index + 1] != 0) { $multiplyer = $this->datay[$index] * 0.5 / $this->datay[$index + 1]; for ($i = $index + 1; $i < count($this->datay); $i++) { $this->datay[$i] = $this->datay[$i] * $multiplyer; } for ($i = $index; $i >= 0; $i--) { $dataySkewed[$index] = true; } } } } } $count = count($this->datay); $max = $this->getRealYMax(NULL); $min = $this->getRealYMin(NULL); // Find zero for bars if ($this->xAxisZero and $min <= 0 and $max >= 0) { $zero = 0; } else { if ($max < 0) { $zero = $max; } else { $zero = $min; } } // Get base position $zero = awAxis::toPosition($this->xAxis, $this->yAxis, new awPoint(0, $zero)); // Distance between two values on the graph $distance = $this->xAxis->getDistance(0, 1); // Compute paddings $leftPadding = $this->barPadding->left * $distance; $rightPadding = $this->barPadding->right * $distance; $padding = $leftPadding + $rightPadding; $space = $this->barSpace * ($this->number - 1); $barSize = ($distance - $padding - $space) / $this->number; $barPosition = $leftPadding + $barSize * ($this->identifier - 1); for ($key = 0; $key < $count; $key++) { $value = $this->datay[$key]; if ($value !== NULL) { /* Determine if we should use cut symbol */ $position = awAxis::toPosition($this->xAxis, $this->yAxis, new awPoint($key, $value)); $barStart = $barPosition + ($this->identifier - 1) * $this->barSpace + $position->x; $barStop = $barStart + $barSize; $t1 = min($zero->y, $position->y); $t2 = max($zero->y, $position->y); if (round($t2 - $t1) == 0) { continue; } if ($dataySkewed[$key]) { $xmin = round($t1) - $this->depth + $this->move->top; $xmax = round($t2) - $this->depth + $this->move->top; $dividerPoint = ($xmax - $xmin) * 0.2 + $xmin; $p1x = round($barStart) + $this->depth + $this->move->left; $p1y = round($t1) - $this->depth + $this->move->top; $p2x = round($barStop) + $this->depth + $this->move->left; $p2y = round($t2) - $this->depth + $this->move->top; $p1 = new awPoint($p1x, $p1y); $p2 = new awPoint($p2x, $p2y); $this->drawBar($drawer, $p1, $p2, $key); $lineX = round($barStop) + $this->depth + $this->move->left; $lineY = $dividerPoint; /* Draw a two-pixel white line over the bar at the divider point. */ $white = imagecolorallocate($drawer->resource, 255, 255, 255); imageline($drawer->resource, $lineX - $barSize + 1, $lineY, $lineX + 1, $lineY, $white); imageline($drawer->resource, $lineX - $barSize + 1, $lineY + 1, $lineX + 1, $lineY + 1, $white); } else { $p1 = new awPoint(round($barStart) + $this->depth + $this->move->left, round($t1) - $this->depth + $this->move->top); $p2 = new awPoint(round($barStop) + $this->depth + $this->move->left, round($t2) - $this->depth + $this->move->top); $this->drawBar($drawer, $p1, $p2, $key); } } } $maxValue = $this->maxValue; // Draw labels foreach ($datayReal as $key => $value) { if ($value !== NULL) { if ($value > $maxValue) { $maxValue = $value; } $position = awAxis::toPosition($this->xAxis, $this->yAxis, new awPoint($key, $this->datay[$key])); $position2 = awAxis::toPosition($this->xAxis, $this->yAxis, new awPoint($key, $this->datay[$key] / 2)); $point = new awPoint($barPosition + ($this->identifier - 1) * $this->barSpace + $position->x + $barSize / 2 + 1 + $this->depth, $position->y - $this->depth); $point2 = new awPoint($barPosition + ($this->identifier - 1) * $this->barSpace + $position2->x + $barSize / 2 + 1 + $this->depth, $position2->y - $this->depth); if ($maxValue == 0) { $maxValue = 1; } if ($value != 0 && $this->drawPercent) { $this->label->drawSpecial($drawer, $point2, $key, '' . round($value / $maxValue * 100, 0) . '%'); $this->label->draw($drawer, $point, $key); } } } }