This commit is contained in:
Xes
2025-08-14 22:41:49 +02:00
parent 2de81ccc46
commit 8ce45119b6
39774 changed files with 4309466 additions and 0 deletions

View File

@@ -0,0 +1,80 @@
<?php
namespace Test\CpChart;
use Codeception\Test\Unit;
use CpChart\Data;
use CpChart\Image;
use Test\CpChart\UnitTester;
use const LEGEND_HORIZONTAL;
use const LEGEND_NOBORDER;
use const TEXT_ALIGN_BOTTOMMIDDLE;
class AreaTest extends Unit
{
/**
* @var UnitTester
*/
protected $tester;
public function testChartRender()
{
$data = new Data();
for ($i = 0; $i <= 30; $i++) {
$data->addPoints(rand(1, 15), 'Probe 1');
}
$data->setSerieTicks('Probe 2', 4);
$data->setAxisName(0, 'Temperatures');
$image = new Image(700, 230, $data);
$image->Antialias = false;
$image->drawRectangle(0, 0, 699, 229, ['R' => 0, 'G' => 0, 'B' => 0]);
$image->setFontProperties(['FontName' => 'Forgotte.ttf', 'FontSize' => 11]);
$image->drawText(
150,
35,
'Average temperature',
['FontSize' => 20, 'Align' => TEXT_ALIGN_BOTTOMMIDDLE]
);
$image->setFontProperties(['FontName' => 'pf_arma_five.ttf', 'FontSize' => 6]);
$image->setGraphArea(60, 40, 650, 200);
$scaleSettings = [
'XMargin' => 10, 'YMargin' => 10, 'Floating' => true, 'GridR' => 200,
'GridG' => 200, 'GridB' => 200, 'DrawSubTicks' => true, 'CycleBackground' => true
];
$image->drawScale($scaleSettings);
$image->drawLegend(
600,
20,
['Style' => LEGEND_NOBORDER, 'Mode' => LEGEND_HORIZONTAL]
);
$image->Antialias = true;
$image->setShadow(true, ['X' => 1, 'Y' => 1, 'R' => 0, 'G' => 0, 'B' => 0, 'Alpha' => 10]);
$threshold = [
['Min' => 0, 'Max' => 5, 'R' => 207, 'G' => 240, 'B' => 20, 'Alpha' => 70],
['Min' => 5, 'Max' => 10, 'R' => 240, 'G' => 232, 'B' => 20, 'Alpha' => 70],
['Min' => 10, 'Max' => 20, 'R' => 240, 'G' => 191, 'B' => 20, 'Alpha' => 70]
];
$image->drawAreaChart(['Threshold' => $threshold]);
$image->drawThreshold(
5,
[
'WriteCaption' => true, 'Caption' => 'Warn Zone', 'Alpha' => 70, 'Ticks' => 2,
'R' => 0, 'G' => 0, 'B' => 255
]
);
$image->drawThreshold(
10,
[
'WriteCaption' => true, 'Caption' => 'Error Zone', 'Alpha' => 70, 'Ticks' => 2,
'R' => 0, 'G' => 0, 'B' => 255
]
);
$filename = $this->tester->getOutputPathForChart('drawAreaChart.threshold.png');
$image->render($filename);
$image->stroke();
$this->tester->seeFileFound($filename);
}
}

View File

@@ -0,0 +1,138 @@
<?php
namespace Test\CpChart;
use Codeception\Test\Unit;
use CpChart\Barcode\Barcode128;
use CpChart\Barcode\Barcode39;
use CpChart\Image;
use Test\CpChart\UnitTester;
use const DIRECTION_VERTICAL;
class BarCodeTest extends Unit
{
/**
* @var UnitTester
*/
protected $tester;
public function test39Code()
{
$image = new Image(700, 230);
$settings = [
'R' => 170, 'G' => 183, 'B' => 87, 'Dash' => 1, 'DashR' => 190,
'DashG' => 203, 'DashB' => 107
];
$image->drawFilledRectangle(0, 0, 700, 230, $settings);
$settings = [
'StartR' => 219, 'StartG' => 231, 'StartB' => 139, 'EndR' => 1,
'EndG' => 138, 'EndB' => 68, 'Alpha' => 50
];
$image->drawGradientArea(0, 0, 700, 230, DIRECTION_VERTICAL, $settings);
$image->drawGradientArea(
0,
0,
700,
20,
DIRECTION_VERTICAL,
[
'StartR' => 0, 'StartG' => 0, 'StartB' => 0, 'EndR' => 50, 'EndG' => 50,
'EndB' => 50, 'Alpha' => 80
]
);
$image->drawRectangle(0, 0, 699, 229, ['R' => 0, 'G' => 0, 'B' => 0]);
$image->setFontProperties(['FontName' => 'Silkscreen.ttf', 'FontSize' => 6]);
$image->drawText(
10,
13,
'Barcode 39 - Add barcode to your pictures',
['R' => 255, 'G' => 255, 'B' => 255]
);
$barcode = new Barcode39();
$image->setFontProperties(['FontName' => 'pf_arma_five.ttf', 'FontSize' => 6]);
$settings = ['ShowLegend' => true, 'DrawArea' => true];
$barcode->draw($image, 'pChart Rocks!', 50, 50, $settings);
$image->setFontProperties(['FontName' => 'Forgotte.ttf', 'FontSize' => 12]);
$settings = ['ShowLegend' => true, 'DrawArea' => true, 'Angle' => 90];
$barcode->draw($image, 'Turn me on', 650, 50, $settings);
$image->setFontProperties(['FontName' => 'Forgotte.ttf', 'FontSize' => 12]);
$settings = [
'R' => 255, 'G' => 255, 'B' => 255, 'AreaR' => 150, 'AreaG' => 30,
'AreaB' => 27, 'ShowLegend' => true, 'DrawArea' => true, 'Angle' => 350,
'AreaBorderR' => 70, 'AreaBorderG' => 20, 'AreaBorderB' => 20
];
$barcode->draw($image, 'Do what you want !', 290, 140, $settings);
$filename = $this->tester->getOutputPathForChart('drawBarcode39.png');
$barcode->pChartObject->render($filename);
$barcode->pChartObject->stroke();
$this->tester->seeFileFound($filename);
}
public function test128Code()
{
$image = new Image(700, 230);
$settings = [
'R' => 170, 'G' => 183, 'B' => 87, 'Dash' => 1, 'DashR' => 190,
'DashG' => 203, 'DashB' => 107
];
$image->drawFilledRectangle(0, 0, 700, 230, $settings);
$settings = [
'StartR' => 219, 'StartG' => 231, 'StartB' => 139, 'EndR' => 1,
'EndG' => 138, 'EndB' => 68, 'Alpha' => 50
];
$image->drawGradientArea(0, 0, 700, 230, DIRECTION_VERTICAL, $settings);
$image->drawGradientArea(
0,
0,
700,
20,
DIRECTION_VERTICAL,
[
'StartR' => 0, 'StartG' => 0, 'StartB' => 0, 'EndR' => 50, 'EndG' => 50,
'EndB' => 50, 'Alpha' => 80
]
);
$image->drawGradientArea(
0,
0,
700,
20,
DIRECTION_VERTICAL,
[
'StartR' => 0, 'StartG' => 0, 'StartB' => 0, 'EndR' => 50, 'EndG' => 50,
'EndB' => 50, 'Alpha' => 100
]
);
$image->drawRectangle(0, 0, 699, 229, ['R' => 0, 'G' => 0, 'B' => 0]);
$image->setFontProperties(['FontName' => 'Silkscreen.ttf', 'FontSize' => 6]);
$image->drawText(
10,
13,
'Barcode 128 - Add barcode to your pictures',
['R' => 255, 'G' => 255, 'B' => 255]
);
$barcode = new Barcode128();
$image->setFontProperties(['FontName' => 'pf_arma_five.ttf', 'FontSize' => 6]);
$settings = ['ShowLegend' => true, 'DrawArea' => true];
$barcode->draw($image, 'pChart Rocks!', 50, 50, $settings);
$image->setFontProperties(['FontName' => 'Forgotte.ttf', 'FontSize' => 12]);
$settings = ['ShowLegend' => true, 'DrawArea' => true, 'Angle' => 90];
$barcode->draw($image, 'Turn me on', 650, 50, $settings);
$image->setFontProperties(['FontName' => 'Forgotte.ttf', 'FontSize' => 12]);
$settings = [
'R' => 255, 'G' => 255, 'B' => 255, 'AreaR' => 150, 'AreaG' => 30,
'AreaB' => 27, 'ShowLegend' => true, 'DrawArea' => true, 'Angle' => 350,
'AreaBorderR' => 70, 'AreaBorderG' => 20, 'AreaBorderB' => 20
];
$barcode->draw($image, 'Do what you want !', 290, 140, $settings);
$filename = $this->tester->getOutputPathForChart('drawBarcode128.png');
$barcode->pChartObject->render($filename);
$barcode->pChartObject->stroke();
$this->tester->seeFileFound($filename);
}
}

View File

@@ -0,0 +1,110 @@
<?php
namespace Test\CpChart;
use Codeception\Test\Unit;
use CpChart\Data;
use CpChart\Image;
use Test\CpChart\UnitTester;
use const DIRECTION_VERTICAL;
use const DISPLAY_AUTO;
use const LEGEND_HORIZONTAL;
use const LEGEND_NOBORDER;
use const SCALE_POS_TOPBOTTOM;
use const TEXT_ALIGN_BOTTOMMIDDLE;
use const VOID;
class BarTest extends Unit
{
/**
* @var UnitTester
*/
protected $tester;
public function testChartRender()
{
$data = new Data();
$data->addPoints([-4, VOID, VOID, 12, 8, 3], 'Probe 1');
$data->addPoints([3, 12, 15, 8, 5, -5], 'Probe 2');
$data->addPoints([2, 0, 5, 18, 19, 22], 'Probe 3');
$data->setSerieTicks('Probe 2', 4);
$data->setAxisName(0, 'Temperatures');
$data->addPoints(['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun'], 'Labels');
$data->setSerieDescription('Labels', 'Months');
$data->setAbscissa('Labels');
$image = new Image(700, 230, $data);
$image->drawFilledRectangle(
0,
0,
700,
230,
['R' => 170, 'G' => 183, 'B' => 87, 'Dash' => 1, 'DashR' => 190, 'DashG' => 203, 'DashB' => 107]
);
$settings = [
'StartR' => 219,
'StartG' => 231,
'StartB' => 139,
'EndR' => 1,
'EndG' => 138,
'EndB' => 68,
'Alpha' => 50
];
$image->drawGradientArea(0, 0, 700, 230, DIRECTION_VERTICAL, $settings);
$image->drawGradientArea(
0,
0,
700,
20,
DIRECTION_VERTICAL,
['StartR' => 0, 'StartG' => 0, 'StartB' => 0, 'EndR' => 50, 'EndG' => 50, 'EndB' => 50, 'Alpha' => 80]
);
$image->drawRectangle(0, 0, 699, 229, ['R' => 0, 'G' => 0, 'B' => 0]);
$image->setFontProperties(['FontName' => 'Silkscreen.ttf', 'FontSize' => 6]);
$image->drawText(10, 13, 'drawBarChart() - draw a bar chart', ['R' => 255, 'G' => 255, 'B' => 255]);
$image->setFontProperties(['FontName' => 'Forgotte.ttf', 'FontSize' => 11]);
$image->drawText(
250,
55,
'Average temperature',
['FontSize' => 20, 'Align' => TEXT_ALIGN_BOTTOMMIDDLE]
);
$image->setGraphArea(60, 60, 450, 190);
$image->drawFilledRectangle(
60,
60,
450,
190,
['R' => 255, 'G' => 255, 'B' => 255, 'Surrounding' => -200, 'Alpha' => 10]
);
$image->drawScale(['DrawSubTicks' => true]);
$image->setShadow(true, ['X' => 1, 'Y' => 1, 'R' => 0, 'G' => 0, 'B' => 0, 'Alpha' => 10]);
$image->setFontProperties(['FontName' => 'pf_arma_five.ttf', 'FontSize' => 6]);
$image->drawBarChart([
'DisplayValues' => true,
'DisplayColor' => DISPLAY_AUTO,
'Rounded' => true,
'Surrounding' => 60
]);
$image->setShadow(false);
$image->setGraphArea(500, 60, 670, 190);
$image->drawFilledRectangle(
500,
60,
670,
190,
['R' => 255, 'G' => 255, 'B' => 255, 'Surrounding' => -200, 'Alpha' => 10]
);
$image->drawScale(['Pos' => SCALE_POS_TOPBOTTOM, 'DrawSubTicks' => true]);
$image->setShadow(true, ['X' => 1, 'Y' => 1, 'R' => 0, 'G' => 0, 'B' => 0, 'Alpha' => 10]);
$image->drawBarChart();
$image->setShadow(false);
$image->drawLegend(510, 205, ['Style' => LEGEND_NOBORDER, 'Mode' => LEGEND_HORIZONTAL]);
$filename = $this->tester->getOutputPathForChart('drawBarChart.png');
$image->render($filename);
$image->stroke();
$this->tester->seeFileFound($filename);
}
}

View File

@@ -0,0 +1,64 @@
<?php
namespace Test\CpChart;
use Codeception\Test\Unit;
use CpChart\Data;
use CpChart\Image;
use Test\CpChart\UnitTester;
use const LEGEND_HORIZONTAL;
use const LEGEND_NOBORDER;
use const TEXT_ALIGN_BOTTOMMIDDLE;
class BestFitTest extends Unit
{
/**
* @var UnitTester
*/
protected $tester;
public function testChartRender()
{
$data = new Data();
for ($i = 0; $i <= 20; $i++) {
$data->addPoints(rand(10, 30) + $i, 'Probe 1');
}
for ($i = 0; $i <= 20; $i++) {
$data->addPoints(rand(0, 10) + $i, 'Probe 2');
}
$data->setAxisName(0, 'Temperatures');
$image = new Image(700, 230, $data);
$image->Antialias = false;
$image->drawRectangle(0, 0, 699, 229, ['R' => 0, 'G' => 0, 'B' => 0]);
$image->setFontProperties(['FontName' => 'Forgotte.ttf', 'FontSize' => 11]);
$image->drawText(
150,
35,
'Average temperature',
['FontSize' => 20, 'Align' => TEXT_ALIGN_BOTTOMMIDDLE]
);
$image->setFontProperties(['FontName' => 'pf_arma_five.ttf', 'FontSize' => 6]);
$image->setGraphArea(60, 40, 650, 200);
$scaleSettings = [
'XMargin' => 10, 'YMargin' => 10, 'Floating' => true, 'GridR' => 200,
'GridG' => 200, 'GridB' => 200, 'DrawSubTicks' => true, 'CycleBackground' => true
];
$image->drawScale($scaleSettings);
$image->Antialias = true;
$image->drawBestFit();
$image->setShadow(true, ['X' => 1, 'Y' => 1, 'R' => 0, 'G' => 0, 'B' => 0, 'Alpha' => 10]);
$image->drawPlotChart();
$image->drawLegend(
580,
20,
['Style' => LEGEND_NOBORDER, 'Mode' => LEGEND_HORIZONTAL]
);
$filename = $this->tester->getOutputPathForChart('drawBestFit.png');
$image->render($filename);
$image->stroke();
$this->tester->seeFileFound($filename);
}
}

View File

@@ -0,0 +1,119 @@
<?php
namespace Test\CpChart;
use Codeception\Test\Unit;
use CpChart\Chart\Bubble;
use CpChart\Data;
use CpChart\Image;
use Test\CpChart\UnitTester;
use const DIRECTION_VERTICAL;
use const LEGEND_HORIZONTAL;
use const LEGEND_NOBORDER;
use const SCALE_POS_TOPBOTTOM;
use const TEXT_ALIGN_BOTTOMLEFT;
class BubbleTest extends Unit
{
/**
* @var UnitTester
*/
protected $tester;
public function testChartRender()
{
$data = new Data();
$data->addPoints([34, 55, 15, 62, 38, 42], 'Probe1');
$data->addPoints([5, 10, 8, 9, 15, 10], 'Probe1Weight');
$data->addPoints([5, 10, -5, -1, 0, -10], 'Probe2');
$data->addPoints([6, 10, 14, 10, 14, 6], 'Probe2Weight');
$data->setSerieDescription('Probe1', 'This year');
$data->setSerieDescription('Probe2', 'Last year');
$data->setAxisName(0, 'Current stock');
$data->addPoints(
['Apple', 'Banana', 'Orange', 'Lemon', 'Peach', 'Strawberry'],
'Product'
);
$data->setAbscissa('Product');
$image = new Image(700, 230, $data);
$settings = [
'R' => 170, 'G' => 183, 'B' => 87, 'Dash' => 1, 'DashR' => 190,
'DashG' => 203, 'DashB' => 107
];
$image->drawFilledRectangle(0, 0, 700, 230, $settings);
$settings = [
'StartR' => 219, 'StartG' => 231, 'StartB' => 139, 'EndR' => 1,
'EndG' => 138, 'EndB' => 68, 'Alpha' => 50
];
$image->drawGradientArea(0, 0, 700, 230, DIRECTION_VERTICAL, $settings);
$image->drawGradientArea(
0,
0,
700,
20,
DIRECTION_VERTICAL,
[
'StartR' => 0, 'StartG' => 0, 'StartB' => 0, 'EndR' => 50, 'EndG' => 50,
'EndB' => 50, 'Alpha' => 80
]
);
$image->drawRectangle(0, 0, 699, 229, ['R' => 0, 'G' => 0, 'B' => 0]);
$image->setFontProperties(['FontName' => 'Silkscreen.ttf', 'FontSize' => 6]);
$image->drawText(
10,
13,
'drawBubbleChart() - draw a linear bubble chart',
['R' => 255, 'G' => 255, 'B' => 255]
);
$image->setFontProperties(['FontName' => 'Forgotte.ttf', 'FontSize' => 11]);
$image->drawText(
40,
55,
'Current Stock / Needs chart',
['FontSize' => 14, 'Align' => TEXT_ALIGN_BOTTOMLEFT]
);
$image->setFontProperties(['FontName' => 'pf_arma_five.ttf', 'FontSize' => 6]);
$bubbleChart = new Bubble($image, $data);
$bubbleDataSeries = ['Probe1', 'Probe2'];
$bubbleWeightSeries = ['Probe1Weight', 'Probe2Weight'];
$bubbleChart->bubbleScale($bubbleDataSeries, $bubbleWeightSeries);
$image->setGraphArea(40, 60, 430, 190);
$image->drawFilledRectangle(
40,
60,
430,
190,
['R' => 255, 'G' => 255, 'B' => 255, 'Surrounding' => -200, 'Alpha' => 10]
);
$image->drawScale(['DrawSubTicks' => true, 'CycleBackground' => true]);
$image->setShadow(
true,
['X' => 1, 'Y' => 1, 'R' => 0, 'G' => 0, 'B' => 0, 'Alpha' => 30]
);
$bubbleChart->drawBubbleChart($bubbleDataSeries, $bubbleWeightSeries);
$image->setShadow(false);
$image->setGraphArea(500, 60, 670, 190);
$image->drawFilledRectangle(
500,
60,
670,
190,
['R' => 255, 'G' => 255, 'B' => 255, 'Surrounding' => -200, 'Alpha' => 10]
);
$image->drawScale(['Pos' => SCALE_POS_TOPBOTTOM, 'DrawSubTicks' => true]);
$image->setShadow(
true,
['X' => 1, 'Y' => 1, 'R' => 0, 'G' => 0, 'B' => 0, 'Alpha' => 30]
);
$bubbleChart->drawbubbleChart($bubbleDataSeries, $bubbleWeightSeries);
$image->drawLegend(550, 215, ['Style' => LEGEND_NOBORDER, 'Mode' => LEGEND_HORIZONTAL]);
$filename = $this->tester->getOutputPathForChart('drawBubble.png');
$image->render($filename);
$image->stroke();
$this->tester->seeFileFound($filename);
}
}

View File

@@ -0,0 +1,134 @@
<?php
namespace Test\CpChart;
use Codeception\Test\Unit;
use CpChart\Cache;
use CpChart\Data;
use CpChart\Image;
use Test\CpChart\UnitTester;
use const DIRECTION_VERTICAL;
class CacheTest extends Unit
{
/**
* @var UnitTester
*/
protected $tester;
public function testWritingAndRetrievingOperations()
{
list($data, $image) = $this->createImageData();
// Write to cache
$cache = new Cache();
$chartHash = $cache->getHash($data);
$cache->writeToCache($chartHash, $image);
$this->tester->seeFileFound($this->getCacheFilePath('cache.db'));
$this->tester->seeFileFound($this->getCacheFilePath('index.db'));
$this->tester->assertEquals(true, $cache->isInCache($chartHash));
// Render and then remove the chart
$filename = $this->tester->getOutputPathForChart('drawCachedSpline.png');
$image->render($filename);
$this->tester->seeFileFound($filename);
$this->tester->deleteFile($filename);
$this->tester->cantSeeFileFound($filename);
// Test retrieving image from cache
$cache->saveFromCache($chartHash, $filename);
$this->tester->seeFileFound($filename);
$this->tester->assertEquals(true, $cache->strokeFromCache($chartHash));
}
public function testRemovalOperations()
{
list($data, $image) = $this->createImageData();
// Write to cache
$cache = new Cache();
$chartHash = $cache->getHash($data);
$cache->writeToCache($chartHash, $image);
$this->tester->assertEquals(true, $cache->isInCache($chartHash));
// Remove by name
$cache->remove($chartHash);
$this->tester->assertEquals(false, $cache->isInCache($chartHash));
// Remove older than x seconds
$cache->writeToCache($chartHash, $image);
$this->tester->assertEquals(true, $cache->isInCache($chartHash));
$cache->removeOlderThan(4);
$this->tester->assertEquals(true, $cache->isInCache($chartHash));
sleep(5);
$cache->removeOlderThan(4);
$this->tester->assertEquals(false, $cache->isInCache($chartHash));
// Flush the cache
$cache->writeToCache($chartHash, $image);
$this->tester->assertEquals(true, $cache->isInCache($chartHash));
$cache->flush();
$this->tester->assertEquals(false, $cache->isInCache($chartHash));
}
protected function _before()
{
$this->clearCache();
}
protected function _after()
{
$this->clearCache();
}
private function createImageData()
{
$data = new Data();
$data->addPoints([1, 3, 4, 3, 5]);
$image = new Image(700, 230, $data);
$image->setFontProperties(['FontName' => 'Forgotte.ttf', 'FontSize' => 11]);
$image->setGraphArea(60, 40, 670, 190);
$image->drawScale();
$image->drawSplineChart();
$image->drawGradientArea(
0,
0,
700,
20,
DIRECTION_VERTICAL,
[ 'StartR' => 0, 'StartG' => 0, 'StartB' => 0, 'EndR' => 50, 'EndG' => 50,
'EndB' => 50, 'Alpha' => 100
]
);
$image->setFontProperties(['FontName' => 'Silkscreen.ttf', 'FontSize' => 6]);
$image->drawText(
10,
13,
'Test of the pCache class',
['R' => 255, 'G' => 255, 'B' => 255]
);
return [$data, $image];
}
private function clearCache()
{
foreach (['cache.db', 'index.db'] as $cacheFile) {
$filename = $this->getCacheFilePath($cacheFile);
if (true === file_exists($filename)) {
unlink($filename);
}
}
}
/**
* @param string $filename
* @return string
*/
private function getCacheFilePath($filename)
{
return sprintf('%s/%s', $this->tester->getCacheDirectory(), $filename);
}
}

View File

@@ -0,0 +1,110 @@
<?php
namespace Test\CpChart;
use Codeception\Test\Unit;
use CpChart\Data;
use CpChart\Image;
use Test\CpChart\UnitTester;
use const BOUND_BOTH;
use const DIRECTION_VERTICAL;
use const LEGEND_NOBORDER;
use const TEXT_ALIGN_BOTTOMLEFT;
use const TEXT_ALIGN_MIDDLEMIDDLE;
class FilledSplineTest extends Unit
{
/**
* @var UnitTester
*/
protected $tester;
public function testChartRender()
{
$data = new Data();
$data->setAxisName(0, 'Strength');
for ($i = 0; $i <= 720; $i = $i + 20) {
$data->addPoints(cos(deg2rad($i)) * 100, 'Probe 1');
$data->addPoints(cos(deg2rad($i + 90)) * 60, 'Probe 2');
}
$image = new Image(847, 304, $data);
$image->drawGradientArea(
0,
0,
847,
304,
DIRECTION_VERTICAL,
[
'StartR' => 47, 'StartG' => 47, 'StartB' => 47, 'EndR' => 17, 'EndG' => 17,
'EndB' => 17, 'Alpha' => 100
]
);
$image->drawGradientArea(
0,
250,
847,
304,
DIRECTION_VERTICAL,
[
'StartR' => 47, 'StartG' => 47, 'StartB' => 47, 'EndR' => 27, 'EndG' => 27,
'EndB' => 27, 'Alpha' => 100
]
);
$image->drawLine(0, 249, 847, 249, ['R' => 0, 'G' => 0, 'B' => 0]);
$image->drawLine(0, 250, 847, 250, ['R' => 70, 'G' => 70, 'B' => 70]);
$image->drawRectangle(0, 0, 846, 303, ['R' => 204, 'G' => 204, 'B' => 204]);
$image->setFontProperties(['FontName' => 'pf_arma_five.ttf', 'FontSize' => 6]);
$image->drawText(
423,
14,
'Cyclic magnetic field strength',
['R' => 255, 'G' => 255, 'B' => 255, 'Align' => TEXT_ALIGN_MIDDLEMIDDLE]
);
$image->setGraphArea(58, 27, 816, 228);
$image->drawFilledRectangle(
58,
27,
816,
228,
[
'R' => 0, 'G' => 0, 'B' => 0, 'Dash' => true, 'DashR' => 0, 'DashG' => 51,
'DashB' => 51, 'BorderR' => 0, 'BorderG' => 0, 'BorderB' => 0
]
);
$image->setShadow(
true,
['X' => 1, 'Y' => 1, 'R' => 0, 'G' => 0, 'B' => 0, 'Alpha' => 20]
);
$image->setFontProperties(['R' => 255, 'G' => 255, 'B' => 255]);
$ScaleSettings = [
'XMargin' => 4, 'DrawSubTicks' => true, 'GridR' => 255,
'GridG' => 255, 'GridB' => 255, 'AxisR' => 255, 'AxisG' => 255, 'AxisB' => 255,
'GridAlpha' => 30, 'CycleBackground' => true
];
$image->drawScale($ScaleSettings);
$image->drawFilledSplineChart();
$BoundsSettings = [
'MaxDisplayR' => 237, 'MaxDisplayG' => 23, 'MaxDisplayB' => 48,
'MinDisplayR' => 23, 'MinDisplayG' => 144, 'MinDisplayB' => 237
];
$image->writeBounds(BOUND_BOTH, $BoundsSettings);
$image->drawThreshold(0, ['WriteCaption' => true]);
$image->setFontProperties(['R' => 255, 'G' => 255, 'B' => 255]);
$image->drawLegend(560, 266, ['Style' => LEGEND_NOBORDER]);
$settings = ['R' => 188, 'G' => 224, 'B' => 46, 'Align' => TEXT_ALIGN_BOTTOMLEFT];
$image->drawText(620, 270, 'Max : ' . ceil($data->getMax('Probe 1')), $settings);
$image->drawText(680, 270, 'Min : ' . ceil($data->getMin('Probe 1')), $settings);
$image->drawText(740, 270, 'Avg : ' . ceil($data->getSerieAverage('Probe 1')), $settings);
$settings = ['R' => 224, 'G' => 100, 'B' => 46, 'Align' => TEXT_ALIGN_BOTTOMLEFT];
$image->drawText(620, 283, 'Max : ' . ceil($data->getMax('Probe 2')), $settings);
$image->drawText(680, 283, 'Min : ' . ceil($data->getMin('Probe 2')), $settings);
$image->drawText(740, 283, 'Avg : ' . ceil($data->getSerieAverage('Probe 2')), $settings);
$filename = $this->tester->getOutputPathForChart('drawFilledSplineChart.png');
$image->render($filename);
$image->stroke();
$this->tester->seeFileFound($filename);
}
}

View File

@@ -0,0 +1,116 @@
<?php
namespace Test\CpChart;
use Codeception\Test\Unit;
use CpChart\Data;
use CpChart\Image;
use Test\CpChart\UnitTester;
use const DIRECTION_VERTICAL;
use const DISPLAY_AUTO;
use const LEGEND_HORIZONTAL;
use const LEGEND_NOBORDER;
use const SCALE_POS_TOPBOTTOM;
use const TEXT_ALIGN_BOTTOMMIDDLE;
use const VOID;
class FilledStepTest extends Unit
{
/**
* @var UnitTester
*/
protected $tester;
public function testChartRender()
{
$data = new Data();
$data->addPoints([-4, 2, VOID, 12, 8, 3], 'Probe 1');
$data->addPoints([3, 12, 15, 8, 5, -5], 'Probe 2');
$data->addPoints([2, 7, 5, 18, 19, 22], 'Probe 3');
$data->setSerieTicks('Probe 2', 4);
$data->setAxisName(0, 'Temperatures');
$data->addPoints(['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun'], 'Labels');
$data->setSerieDescription('Labels', 'Months');
$data->setAbscissa('Labels');
$image = new Image(700, 230, $data);
$settings = [
'R' => 170, 'G' => 183, 'B' => 87, 'Dash' => 1, 'DashR' => 190,
'DashG' => 203, 'DashB' => 107
];
$image->drawFilledRectangle(0, 0, 700, 230, $settings);
$settings = [
'StartR' => 219, 'StartG' => 231, 'StartB' => 139, 'EndR' => 1,
'EndG' => 138, 'EndB' => 68, 'Alpha' => 50
];
$image->drawGradientArea(0, 0, 700, 230, DIRECTION_VERTICAL, $settings);
$image->drawGradientArea(
0,
0,
700,
20,
DIRECTION_VERTICAL,
[
'StartR' => 0, 'StartG' => 0, 'StartB' => 0, 'EndR' => 50, 'EndG' => 50,
'EndB' => 50, 'Alpha' => 80
]
);
$image->drawRectangle(0, 0, 699, 229, ['R' => 0, 'G' => 0, 'B' => 0]);
$image->setFontProperties(['FontName' => 'Silkscreen.ttf', 'FontSize' => 6]);
$image->drawText(
10,
13,
'drawFilledStepChart() - draw a filled step chart',
['R' => 255, 'G' => 255, 'B' => 255]
);
$image->setFontProperties(['FontName' => 'Forgotte.ttf', 'FontSize' => 11]);
$image->drawText(
250,
55,
'Average temperature',
['FontSize' => 20, 'Align' => TEXT_ALIGN_BOTTOMMIDDLE]
);
$image->setGraphArea(60, 60, 450, 190);
$image->drawFilledRectangle(
60,
60,
450,
190,
['R' => 255, 'G' => 255, 'B' => 255, 'Surrounding' => -200, 'Alpha' => 10]
);
$image->drawScale(['DrawSubTicks' => true]);
$image->setShadow(
true,
['X' => 1, 'Y' => 1, 'R' => 0, 'G' => 0, 'B' => 0, 'Alpha' => 10]
);
$image->setFontProperties(['FontName' => 'pf_arma_five.ttf', 'FontSize' => 6]);
$image->drawFilledStepChart([
'ForceTransparency' => 40,
'DisplayValues' => true,
'DisplayColor' => DISPLAY_AUTO
]);
$image->setShadow(false);
$image->setGraphArea(500, 60, 670, 190);
$image->drawFilledRectangle(
500,
60,
670,
190,
['R' => 255, 'G' => 255, 'B' => 255, 'Surrounding' => -200, 'Alpha' => 10]
);
$image->drawScale(['Pos' => SCALE_POS_TOPBOTTOM, 'DrawSubTicks' => true]);
$image->setShadow(
true,
['X' => -1, 'Y' => 1, 'R' => 0, 'G' => 0, 'B' => 0, 'Alpha' => 10]
);
$image->drawFilledStepChart(['ForceTransparency' => 40]);
$image->setShadow(false);
$image->drawLegend(510, 205, ['Style' => LEGEND_NOBORDER, 'Mode' => LEGEND_HORIZONTAL]);
$filename = $this->tester->getOutputPathForChart('drawFilledStepChart.png');
$image->render($filename);
$image->stroke();
$this->tester->seeFileFound($filename);
}
}

View File

@@ -0,0 +1,76 @@
<?php
namespace Test\CpChart;
use Codeception\Test\Unit;
use CpChart\Data;
use CpChart\Image;
use Test\CpChart\UnitTester;
use const DISPLAY_AUTO;
use const LEGEND_HORIZONTAL;
use const LEGEND_NOBORDER;
use const SCALE_POS_TOPBOTTOM;
use const VOID;
class LineTest extends Unit
{
/**
* @var UnitTester
*/
protected $tester;
public function testChartRender()
{
$data = new Data();
$data->addPoints([-4, VOID, VOID, 12, 8, 3], 'Probe 1');
$data->addPoints([3, 12, 15, 8, 5, -5], 'Probe 2');
$data->addPoints([2, 7, 5, 18, 19, 22], 'Probe 3');
$data->setSerieTicks('Probe 2', 4);
$data->setSerieWeight('Probe 3', 2);
$data->setAxisName(0, 'Temperatures');
$data->addPoints(['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun'], 'Labels');
$data->setSerieDescription('Labels', 'Months');
$data->setAbscissa('Labels');
$image = new Image(700, 230, $data);
$image->setGraphArea(60, 60, 450, 190);
$image->drawFilledRectangle(
60,
60,
450,
190,
['R' => 255, 'G' => 255, 'B' => 255, 'Surrounding' => -200, 'Alpha' => 10]
);
$image->drawScale(['DrawSubTicks' => true]);
$image->setShadow(
true,
['X' => 1, 'Y' => 1, 'R' => 0, 'G' => 0, 'B' => 0, 'Alpha' => 10]
);
$image->setFontProperties(['FontName' => 'pf_arma_five.ttf', 'FontSize' => 6]);
$image->drawLineChart(['DisplayValues' => true, 'DisplayColor' => DISPLAY_AUTO]);
$image->setShadow(false);
$image->setGraphArea(500, 60, 670, 190);
$image->drawFilledRectangle(
500,
60,
670,
190,
['R' => 255, 'G' => 255, 'B' => 255, 'Surrounding' => -200, 'Alpha' => 10]
);
$image->drawScale(['Pos' => SCALE_POS_TOPBOTTOM, 'DrawSubTicks' => true]);
$image->setShadow(
true,
['X' => -1, 'Y' => 1, 'R' => 0, 'G' => 0, 'B' => 0, 'Alpha' => 10]
);
$image->drawLineChart();
$image->setShadow(false);
$image->drawLegend(510, 205, ['Style' => LEGEND_NOBORDER, 'Mode' => LEGEND_HORIZONTAL]);
$filename = $this->tester->getOutputPathForChart('drawLine.png');
$image->render($filename);
$image->stroke();
$this->tester->seeFileFound($filename);
}
}

View File

@@ -0,0 +1,343 @@
<?php
namespace Test\CpChart;
use Codeception\Test\Unit;
use CpChart\Chart\Pie;
use CpChart\Data;
use CpChart\Image;
use Test\CpChart\UnitTester;
use const DIRECTION_VERTICAL;
use const LEGEND_HORIZONTAL;
use const LEGEND_NOBORDER;
use const TEXT_ALIGN_TOPMIDDLE;
class PieTest extends Unit
{
/**
* @var UnitTester
*/
protected $tester;
public function test2dPieRender()
{
$data = new Data();
$data->addPoints([40, 60, 15, 10, 6, 4], 'ScoreA');
$data->setSerieDescription('ScoreA', 'Application A');
$data->addPoints(['<10', '10<>20', '20<>40', '40<>60', '60<>80', '>80'], 'Labels');
$data->setAbscissa('Labels');
$image = new Image(700, 230, $data);
$image->drawFilledRectangle(
0,
0,
700,
230,
[
'R' => 173, 'G' => 152, 'B' => 217, 'Dash' => 1, 'DashR' => 193,
'DashG' => 172, 'DashB' => 237
]
);
$image->drawGradientArea(
0,
0,
700,
230,
DIRECTION_VERTICAL,
[
'StartR' => 209, 'StartG' => 150, 'StartB' => 231, 'EndR' => 111,
'EndG' => 3, 'EndB' => 138, 'Alpha' => 50
]
);
$image->drawGradientArea(
0,
0,
700,
20,
DIRECTION_VERTICAL,
[
'StartR' => 0, 'StartG' => 0, 'StartB' => 0, 'EndR' => 50, 'EndG' => 50,
'EndB' => 50, 'Alpha' => 100
]
);
$image->drawRectangle(0, 0, 699, 229, ['R' => 0, 'G' => 0, 'B' => 0]);
$image->setFontProperties(['FontName' => 'Silkscreen.ttf', 'FontSize' => 6]);
$image->drawText(
10,
13,
'pPie - Draw 2D pie charts',
['R' => 255, 'G' => 255, 'B' => 255]
);
$image->setFontProperties(
['FontName' => 'Forgotte.ttf', 'FontSize' => 10, 'R' => 80, 'G' => 80, 'B' => 80]
);
$image->setShadow(
true,
['X' => 2, 'Y' => 2, 'R' => 150, 'G' => 150, 'B' => 150, 'Alpha' => 100]
);
$pieChart = new Pie($image, $data);
$pieChart->draw2DPie(140, 125, ['SecondPass' => false]);
$pieChart->draw2DPie(340, 125, ['DrawLabels' => true, 'Border' => true]);
$pieChart->draw2DPie(
540,
125,
[
'DataGapAngle' => 10, 'DataGapRadius' => 6, 'Border' => true,
'BorderR' => 255, 'BorderG' => 255, 'BorderB' => 255
]
);
$image->setFontProperties(['FontName' => 'MankSans.ttf', 'FontSize' => 11]);
$image->setShadow(
true,
['X' => 1, 'Y' => 1, 'R' => 0, 'G' => 0, 'B' => 0, 'Alpha' => 20]
);
$image->drawText(
140,
200,
'Single AA pass',
['R' => 0, 'G' => 0, 'B' => 0, 'Align' => TEXT_ALIGN_TOPMIDDLE]
);
$image->drawText(
540,
200,
'Extended AA pass / Splitted',
['R' => 0, 'G' => 0, 'B' => 0, 'Align' => TEXT_ALIGN_TOPMIDDLE]
);
$filename = $this->tester->getOutputPathForChart('draw2DPie.png');
$pieChart->pChartObject->render($filename);
$pieChart->pChartObject->stroke();
$this->tester->seeFileFound($filename);
}
public function test2dRingRender()
{
$data = new Data();
$data->addPoints([50, 2, 3, 4, 7, 10, 25, 48, 41, 10], 'ScoreA');
$data->setSerieDescription('ScoreA', 'Application A');
$data->addPoints(
['A0', 'B1', 'C2', 'D3', 'E4', 'F5', 'G6', 'H7', 'I8', 'J9'],
'Labels'
);
$data->setAbscissa('Labels');
$image = new Image(300, 260, $data);
$settings = [
'R' => 170, 'G' => 183, 'B' => 87, 'Dash' => 1, 'DashR' => 190,
'DashG' => 203, 'DashB' => 107
];
$image->drawFilledRectangle(0, 0, 300, 300, $settings);
$settings = [
'StartR' => 219, 'StartG' => 231, 'StartB' => 139, 'EndR' => 1,
'EndG' => 138, 'EndB' => 68, 'Alpha' => 50
];
$image->drawGradientArea(0, 0, 300, 260, DIRECTION_VERTICAL, $settings);
$image->drawGradientArea(
0,
0,
300,
20,
DIRECTION_VERTICAL,
[
'StartR' => 0, 'StartG' => 0, 'StartB' => 0, 'EndR' => 50, 'EndG' => 50,
'EndB' => 50, 'Alpha' => 100
]
);
$image->drawRectangle(0, 0, 299, 259, ['R' => 0, 'G' => 0, 'B' => 0]);
$image->setFontProperties(['FontName' => 'Silkscreen.ttf', 'FontSize' => 6]);
$image->drawText(
10,
13,
'pPie - Draw 2D ring charts',
['R' => 255, 'G' => 255, 'B' => 255]
);
$image->setFontProperties([
'FontName' => 'Forgotte.ttf', 'FontSize' => 10, 'R' => 80, 'G' => 80, 'B' => 80
]);
$image->setShadow(
true,
['X' => 2, 'Y' => 2, 'R' => 0, 'G' => 0, 'B' => 0, 'Alpha' => 50]
);
$pieChart = new Pie($image, $data);
$pieChart->draw2DRing(
160,
140,
['DrawLabels' => true, 'LabelStacked' => true, 'Border' => true]
);
$image->setShadow(false);
$pieChart->drawPieLegend(15, 40, ['Alpha' => 20]);
$filename = $this->tester->getOutputPathForChart('draw2DRing.png');
$pieChart->pChartObject->render($filename);
$pieChart->pChartObject->stroke();
$this->tester->seeFileFound($filename);
}
public function test3dPieRender()
{
$data = new Data();
$data->addPoints([40, 30, 20], 'ScoreA');
$data->setSerieDescription('ScoreA', 'Application A');
$data->addPoints(['A', 'B', 'C'], 'Labels');
$data->setAbscissa('Labels');
$image = new Image(700, 230, $data, true);
$settings = [
'R' => 173, 'G' => 152, 'B' => 217, 'Dash' => 1, 'DashR' => 193,
'DashG' => 172, 'DashB' => 237
];
$image->drawFilledRectangle(0, 0, 700, 230, $settings);
$settings = [
'StartR' => 209, 'StartG' => 150, 'StartB' => 231, 'EndR' => 111,
'EndG' => 3, 'EndB' => 138, 'Alpha' => 50
];
$image->drawGradientArea(0, 0, 700, 230, DIRECTION_VERTICAL, $settings);
$image->drawGradientArea(
0,
0,
700,
20,
DIRECTION_VERTICAL,
[
'StartR' => 0, 'StartG' => 0, 'StartB' => 0, 'EndR' => 50, 'EndG' => 50,
'EndB' => 50, 'Alpha' => 100
]
);
$image->drawRectangle(0, 0, 699, 229, ['R' => 0, 'G' => 0, 'B' => 0]);
$image->setFontProperties(['FontName' => 'Silkscreen.ttf', 'FontSize' => 6]);
$image->drawText(
10,
13,
'pPie - Draw 3D pie charts',
['R' => 255, 'G' => 255, 'B' => 255]
);
$image->setFontProperties([
'FontName' => 'Forgotte.ttf', 'FontSize' => 10,
'R' => 80, 'G' => 80, 'B' => 80
]);
$pieChart = new Pie($image, $data);
$pieChart->setSliceColor(0, ['R' => 143, 'G' => 197, 'B' => 0]);
$pieChart->setSliceColor(1, ['R' => 97, 'G' => 77, 'B' => 63]);
$pieChart->setSliceColor(2, ['R' => 97, 'G' => 113, 'B' => 63]);
$pieChart->draw3DPie(120, 125, ['SecondPass' => false]);
$pieChart->draw3DPie(340, 125, ['DrawLabels' => true, 'Border' => true]);
$image->setShadow(
true,
['X' => 3, 'Y' => 3, 'R' => 0, 'G' => 0, 'B' => 0, 'Alpha' => 10]
);
$pieChart->draw3DPie(
560,
125,
['WriteValues' => true, 'DataGapAngle' => 10, 'DataGapRadius' => 6, 'Border' => true]
);
$image->setFontProperties(['FontName' => 'pf_arma_five.ttf', 'FontSize' => 6]);
$image->setShadow(
true,
['X' => 1, 'Y' => 1, 'R' => 0, 'G' => 0, 'B' => 0, 'Alpha' => 20]
);
$image->drawText(
120,
200,
'Single AA pass',
[
'DrawBox' => true, 'BoxRounded' => true, 'R' => 0, 'G' => 0, 'B' => 0,
'Align' => TEXT_ALIGN_TOPMIDDLE
]
);
$image->drawText(
440,
200,
'Extended AA pass / Splitted',
[
'DrawBox' => true, 'BoxRounded' => true, 'R' => 0, 'G' => 0, 'B' => 0,
'Align' => TEXT_ALIGN_TOPMIDDLE
]
);
$image->setFontProperties([
'FontName' => 'Silkscreen.ttf', 'FontSize' => 6,
'R' => 255, 'G' => 255, 'B' => 255
]);
$pieChart->drawPieLegend(
600,
8,
['Style' => LEGEND_NOBORDER, 'Mode' => LEGEND_HORIZONTAL]
);
$filename = $this->tester->getOutputPathForChart('draw3DPie.png');
$pieChart->pChartObject->render($filename);
$pieChart->pChartObject->stroke();
$this->tester->seeFileFound($filename);
}
public function test3dRingRender()
{
$data = new Data();
$data->addPoints([50, 2, 3, 4, 7, 10, 25, 48, 41, 10], 'ScoreA');
$data->setSerieDescription('ScoreA', 'Application A');
$data->addPoints(
['A0', 'B1', 'C2', 'D3', 'E4', 'F5', 'G6', 'H7', 'I8', 'J9'],
'Labels'
);
$data->setAbscissa('Labels');
$image = new Image(400, 400, $data);
$settings = [
'R' => 170, 'G' => 183, 'B' => 87, 'Dash' => 1, 'DashR' => 190,
'DashG' => 203, 'DashB' => 107
];
$image->drawFilledRectangle(0, 0, 400, 400, $settings);
$settings = [
'StartR' => 219, 'StartG' => 231, 'StartB' => 139, 'EndR' => 1,
'EndG' => 138, 'EndB' => 68, 'Alpha' => 50
];
$image->drawGradientArea(0, 0, 400, 400, DIRECTION_VERTICAL, $settings);
$image->drawGradientArea(
0,
0,
400,
20,
DIRECTION_VERTICAL,
[
'StartR' => 0, 'StartG' => 0, 'StartB' => 0, 'EndR' => 50, 'EndG' => 50,
'EndB' => 50, 'Alpha' => 100
]
);
$image->drawRectangle(0, 0, 399, 399, ['R' => 0, 'G' => 0, 'B' => 0]);
$image->setFontProperties(['FontName' => 'Silkscreen.ttf', 'FontSize' => 6]);
$image->drawText(
10,
13,
'pPie - Draw 3D ring charts',
['R' => 255, 'G' => 255, 'B' => 255]
);
$image->setFontProperties([
'FontName' => 'Forgotte.ttf',
'FontSize' => 10,
'R' => 80,
'G' => 80,
'B' => 80
]);
$image->setShadow(
true,
['X' => 2, 'Y' => 2, 'R' => 0, 'G' => 0, 'B' => 0, 'Alpha' => 50]
);
$pieChart = new Pie($image, $data);
$pieChart->draw3DRing(
200,
200,
['DrawLabels' => true, 'LabelStacked' => true, 'Border' => true]
);
$pieChart->drawPieLegend(
80,
360,
['Mode' => LEGEND_HORIZONTAL, 'Style' => LEGEND_NOBORDER, 'Alpha' => 20]
);
$filename = $this->tester->getOutputPathForChart('draw3DRing.png');
$pieChart->pChartObject->render($filename);
$pieChart->pChartObject->stroke();
$this->tester->seeFileFound($filename);
}
}

View File

@@ -0,0 +1,65 @@
<?php
namespace Test\CpChart;
use Codeception\Test\Unit;
use CpChart\Data;
use CpChart\Image;
use Test\CpChart\UnitTester;
use const LEGEND_HORIZONTAL;
use const LEGEND_NOBORDER;
use const SERIE_SHAPE_FILLEDSQUARE;
use const SERIE_SHAPE_FILLEDTRIANGLE;
use const TEXT_ALIGN_BOTTOMMIDDLE;
class PlotTest extends Unit
{
/**
* @var UnitTester
*/
protected $tester;
public function testChartRender()
{
$data = new Data();
for ($i = 0; $i <= 20; $i++) {
$data->addPoints(rand(0, 20), 'Probe 1');
}
for ($i = 0; $i <= 20; $i++) {
$data->addPoints(rand(0, 20), 'Probe 2');
}
$data->setSerieShape('Probe 1', SERIE_SHAPE_FILLEDTRIANGLE);
$data->setSerieShape('Probe 2', SERIE_SHAPE_FILLEDSQUARE);
$data->setAxisName(0, 'Temperatures');
$image = new Image(700, 230, $data);
$image->Antialias = false;
$image->drawRectangle(0, 0, 699, 229, ['R' => 0, 'G' => 0, 'B' => 0]);
$image->setFontProperties(['FontName' => 'Forgotte.ttf', 'FontSize' => 11]);
$image->drawText(
150,
35,
'Average temperature',
['FontSize' => 20, 'Align' => TEXT_ALIGN_BOTTOMMIDDLE]
);
$image->setFontProperties(['FontName' => 'pf_arma_five.ttf', 'FontSize' => 6]);
$image->setGraphArea(60, 40, 650, 200);
$scaleSettings = [
'XMargin' => 10, 'YMargin' => 10, 'Floating' => true, 'GridR' => 200,
'GridG' => 200, 'GridB' => 200, 'DrawSubTicks' => true, 'CycleBackground' => true
];
$image->drawScale($scaleSettings);
$image->Antialias = true;
$image->setShadow(
true,
['X' => 1, 'Y' => 1, 'R' => 0, 'G' => 0, 'B' => 0, 'Alpha' => 10]
);
$image->drawPlotChart();
$image->drawLegend(580, 20, ['Style' => LEGEND_NOBORDER, 'Mode' => LEGEND_HORIZONTAL]);
$filename = $this->tester->getOutputPathForChart('drawPlot.png');
$image->render($filename);
$image->stroke();
$this->tester->seeFileFound($filename);
}
}

View File

@@ -0,0 +1,113 @@
<?php
namespace Test\CpChart;
use Codeception\Test\Unit;
use CpChart\Chart\Radar;
use CpChart\Data;
use CpChart\Image;
use Test\CpChart\UnitTester;
use const DIRECTION_VERTICAL;
use const LEGEND_BOX;
use const LEGEND_HORIZONTAL;
use const RADAR_LABELS_HORIZONTAL;
class PolarTest extends Unit
{
/**
* @var UnitTester
*/
protected $tester;
public function testChartRender()
{
$data = new Data();
$data->addPoints([10, 20, 30, 40, 50, 60, 70, 80, 90], 'ScoreA');
$data->addPoints([20, 40, 50, 12, 10, 30, 40, 50, 60], 'ScoreB');
$data->setSerieDescription('ScoreA', 'Coverage A');
$data->setSerieDescription('ScoreB', 'Coverage B');
$data->addPoints([40, 80, 120, 160, 200, 240, 280, 320, 360], 'Coord');
$data->setAbscissa('Coord');
$image = new Image(700, 230, $data);
$settings = [
'R' => 179, 'G' => 217, 'B' => 91, 'Dash' => 1, 'DashR' => 199,
'DashG' => 237, 'DashB' => 111
];
$image->drawFilledRectangle(0, 0, 700, 230, $settings);
$settings = [
'StartR' => 194, 'StartG' => 231, 'StartB' => 44, 'EndR' => 43,
'EndG' => 107, 'EndB' => 58, 'Alpha' => 50
];
$image->drawGradientArea(0, 0, 700, 230, DIRECTION_VERTICAL, $settings);
$image->drawGradientArea(
0,
0,
700,
20,
DIRECTION_VERTICAL,
[
'StartR' => 0, 'StartG' => 0, 'StartB' => 0, 'EndR' => 50, 'EndG' => 50,
'EndB' => 50, 'Alpha' => 100
]
);
$image->drawRectangle(0, 0, 699, 229, ['R' => 0, 'G' => 0, 'B' => 0]);
$image->setFontProperties(['FontName' => 'Silkscreen.ttf', 'FontSize' => 6]);
$image->drawText(
10,
13,
'pRadar - Draw polar charts',
['R' => 255, 'G' => 255, 'B' => 255]
);
$image->setFontProperties(
['FontName' => 'Forgotte.ttf', 'FontSize' => 10, 'R' => 80, 'G' => 80, 'B' => 80]
);
$image->setShadow(
true,
['X' => 2, 'Y' => 2, 'R' => 0, 'G' => 0, 'B' => 0, 'Alpha' => 10]
);
$splitChart = new Radar();
$image->setGraphArea(10, 25, 340, 225);
$options = [
'BackgroundGradient' => [
'StartR' => 255,
'StartG' => 255,
'StartB' => 255,
'StartAlpha' => 100,
'EndR' => 207,
'EndG' => 227,
'EndB' => 125,
'EndAlpha' => 50
]
];
$splitChart->drawPolar($image, $data, $options);
$image->setGraphArea(350, 25, 690, 225);
$options = [
'LabelPos' => RADAR_LABELS_HORIZONTAL,
'BackgroundGradient' => [
'StartR' => 255,
'StartG' => 255,
'StartB' => 255,
'StartAlpha' => 50,
'EndR' => 32,
'EndG' => 109,
'EndB' => 174,
'EndAlpha' => 30
],
'AxisRotation' => 0,
'DrawPoly' => true,
'PolyAlpha' => 50
];
$splitChart->drawPolar($image, $data, $options);
// Write the chart legend
$image->setFontProperties(['FontName' => 'pf_arma_five.ttf', 'FontSize' => 6]);
$image->drawLegend(270, 205, ['Style' => LEGEND_BOX, 'Mode' => LEGEND_HORIZONTAL]);
$filename = $this->tester->getOutputPathForChart('drawPolar.png');
$image->render($filename);
$image->stroke();
$this->tester->seeFileFound($filename);
}
}

View File

@@ -0,0 +1,96 @@
<?php
namespace Test\CpChart;
use Codeception\Test\Unit;
use CpChart\Image;
use Test\CpChart\UnitTester;
use const LABEL_POS_BOTTOM;
use const LABEL_POS_CENTER;
use const LABEL_POS_INSIDE;
use const LABEL_POS_LEFT;
use const LABEL_POS_RIGHT;
use const LABEL_POS_TOP;
use const ORIENTATION_VERTICAL;
class ProgressTest extends Unit
{
/**
* @var UnitTester
*/
protected $tester;
public function testChartRender()
{
$image = new Image(700, 250);
$image->setShadow(
true,
['X' => 1, 'Y' => 1, 'R' => 0, 'G' => 0, 'B' => 0, 'Alpha' => 20]
);
/* Left Red bar */
$progressOptions = [
'R' => 209, 'G' => 31, 'B' => 27, 'Surrounding' => 20,
'BoxBorderR' => 0, 'BoxBorderG' => 0, 'BoxBorderB' => 0, 'BoxBackR' => 255,
'BoxBackG' => 255, 'BoxBackB' => 255, 'RFade' => 206, 'GFade' => 133,
'BFade' => 30, 'ShowLabel' => true
];
$image->drawProgress(40, 60, 77, $progressOptions);
$progressOptions = [
'Width' => 165, 'R' => 209, 'G' => 125, 'B' => 27, 'Surrounding' => 20,
'BoxBorderR' => 0, 'BoxBorderG' => 0, 'BoxBorderB' => 0, 'BoxBackR' => 255,
'BoxBackG' => 255, 'BoxBackB' => 255, 'NoAngle' => true, 'ShowLabel' => true,
'LabelPos' => LABEL_POS_RIGHT
];
$image->drawProgress(40, 100, 50, $progressOptions);
$progressOptions = [
'Width' => 165, 'R' => 209, 'G' => 198, 'B' => 27, 'Surrounding' => 20,
'BoxBorderR' => 0, 'BoxBorderG' => 0, 'BoxBorderB' => 0, 'BoxBackR' => 255,
'BoxBackG' => 255, 'BoxBackB' => 255, 'ShowLabel' => true, 'LabelPos' => LABEL_POS_LEFT
];
$image->drawProgress(75, 140, 25, $progressOptions);
$progressOptions = ['Width' => 400, 'R' => 134, 'G' => 209, 'B' => 27, 'Surrounding' => 20,
'BoxBorderR' => 0, 'BoxBorderG' => 0, 'BoxBorderB' => 0, 'BoxBackR' => 255,
'BoxBackG' => 255, 'BoxBackB' => 255, 'RFade' => 206, 'GFade' => 133,
'BFade' => 30, 'ShowLabel' => true, 'LabelPos' => LABEL_POS_CENTER];
$image->drawProgress(40, 180, 80, $progressOptions);
$progressOptions = [
'Width' => 20, 'Height' => 150, 'R' => 209, 'G' => 31,
'B' => 27, 'Surrounding' => 20, 'BoxBorderR' => 0, 'BoxBorderG' => 0,
'BoxBorderB' => 0, 'BoxBackR' => 255, 'BoxBackG' => 255, 'BoxBackB' => 255,
'RFade' => 206, 'GFade' => 133, 'BFade' => 30, 'ShowLabel' => true, 'Orientation' => ORIENTATION_VERTICAL,
'LabelPos' => LABEL_POS_BOTTOM
];
$image->drawProgress(500, 200, 77, $progressOptions);
$progressOptions = [
'Width' => 20, 'Height' => 150, 'R' => 209, 'G' => 125,
'B' => 27, 'Surrounding' => 20, 'BoxBorderR' => 0, 'BoxBorderG' => 0,
'BoxBorderB' => 0, 'BoxBackR' => 255, 'BoxBackG' => 255, 'BoxBackB' => 255,
'NoAngle' => true, 'ShowLabel' => true, 'Orientation' => ORIENTATION_VERTICAL,
'LabelPos' => LABEL_POS_TOP
];
$image->drawProgress(540, 200, 50, $progressOptions);
$progressOptions = [
'Width' => 20, 'Height' => 150, 'R' => 209, 'G' => 198,
'B' => 27, 'Surrounding' => 20, 'BoxBorderR' => 0, 'BoxBorderG' => 0,
'BoxBorderB' => 0, 'BoxBackR' => 255, 'BoxBackG' => 255, 'BoxBackB' => 255,
'ShowLabel' => true, 'Orientation' => ORIENTATION_VERTICAL, 'LabelPos' => LABEL_POS_INSIDE
];
$image->drawProgress(580, 200, 25, $progressOptions);
$progressOptions = [
'Width' => 20, 'Height' => 150, 'R' => 134, 'G' => 209,
'B' => 27, 'Surrounding' => 20, 'BoxBorderR' => 0, 'BoxBorderG' => 0,
'BoxBorderB' => 0, 'BoxBackR' => 255, 'BoxBackG' => 255, 'BoxBackB' => 255,
'RFade' => 206, 'GFade' => 133, 'BFade' => 30, 'ShowLabel' => true,
'Orientation' => ORIENTATION_VERTICAL, 'LabelPos' => LABEL_POS_CENTER
];
$image->drawProgress(620, 200, 80, $progressOptions);
$filename = $this->tester->getOutputPathForChart('drawProgress.png');
$image->render($filename);
$image->stroke();
$this->tester->seeFileFound($filename);
}
}

View File

@@ -0,0 +1,107 @@
<?php
namespace Test\CpChart;
use Codeception\Test\Unit;
use CpChart\Chart\Radar;
use CpChart\Data;
use CpChart\Image;
use Test\CpChart\UnitTester;
use const DIRECTION_VERTICAL;
use const LEGEND_BOX;
use const LEGEND_HORIZONTAL;
use const RADAR_LABELS_HORIZONTAL;
use const RADAR_LAYOUT_CIRCLE;
use const RADAR_LAYOUT_STAR;
class RadarTest extends Unit
{
/**
* @var UnitTester
*/
protected $tester;
public function testChartRender()
{
$data = new Data();
$data->addPoints([40, 20, 15, 10, 8, 4], 'ScoreA');
$data->addPoints([8, 10, 12, 20, 30, 15], 'ScoreB');
$data->setSerieDescription('ScoreA', 'Application A');
$data->setSerieDescription('ScoreB', 'Application B');
$data->addPoints(
['Size', 'Speed', 'Reliability', 'Functionalities', 'Ease of use', 'Weight'],
'Labels'
);
$data->setAbscissa('Labels');
$image = new Image(700, 230, $data);
$settings = [
'R' => 179, 'G' => 217, 'B' => 91, 'Dash' => 1, 'DashR' => 199,
'DashG' => 237, 'DashB' => 111
];
$image->drawFilledRectangle(0, 0, 700, 230, $settings);
$settings = [
'StartR' => 194, 'StartG' => 231, 'StartB' => 44, 'EndR' => 43,
'EndG' => 107, 'EndB' => 58, 'Alpha' => 50
];
$image->drawGradientArea(0, 0, 700, 230, DIRECTION_VERTICAL, $settings);
$image->drawGradientArea(
0,
0,
700,
20,
DIRECTION_VERTICAL,
[
'StartR' => 0, 'StartG' => 0, 'StartB' => 0, 'EndR' => 50, 'EndG' => 50,
'EndB' => 50, 'Alpha' => 100
]
);
$image->drawRectangle(0, 0, 699, 229, ['R' => 0, 'G' => 0, 'B' => 0]);
$image->setFontProperties(['FontName' => 'Silkscreen.ttf', 'FontSize' => 6]);
$image->drawText(
10,
13,
'pRadar - Draw radar charts',
['R' => 255, 'G' => 255, 'B' => 255]
);
$image->setFontProperties(
['FontName' => 'Forgotte.ttf', 'FontSize' => 10, 'R' => 80, 'G' => 80, 'B' => 80]
);
$image->setShadow(
true,
['X' => 2, 'Y' => 2, 'R' => 0, 'G' => 0, 'B' => 0, 'Alpha' => 10]
);
$radarChart = new Radar();
$image->setGraphArea(10, 25, 340, 225);
$options = [
'Layout' => RADAR_LAYOUT_STAR,
'BackgroundGradient' => [
'StartR' => 255,
'StartG' => 255,
'StartB' => 255,
'StartAlpha' => 100,
'EndR' => 207,
'EndG' => 227, 'EndB' => 125, 'EndAlpha' => 50
]
];
$radarChart->drawRadar($image, $data, $options);
$image->setGraphArea(350, 25, 690, 225);
$options = [
'Layout' => RADAR_LAYOUT_CIRCLE,
'LabelPos' => RADAR_LABELS_HORIZONTAL,
'BackgroundGradient' => [
'StartR' => 255, 'StartG' => 255, 'StartB' => 255,
'StartAlpha' => 50, 'EndR' => 32, 'EndG' => 109, 'EndB' => 174, 'EndAlpha' => 30
]
];
$radarChart->drawRadar($image, $data, $options);
$image->setFontProperties(['FontName' => 'pf_arma_five.ttf', 'FontSize' => 6]);
$image->drawLegend(270, 205, ['Style' => LEGEND_BOX, 'Mode' => LEGEND_HORIZONTAL]);
$filename = $this->tester->getOutputPathForChart('drawRadar.png');
$image->render($filename);
$image->stroke();
$this->tester->seeFileFound($filename);
}
}

View File

@@ -0,0 +1,69 @@
<?php
namespace Test\CpChart;
use Codeception\Test\Unit;
use CpChart\Chart\Radar;
use CpChart\Data;
use CpChart\Image;
use Test\CpChart\UnitTester;
use const RADAR_LAYOUT_CIRCLE;
final class RegressionTest extends Unit
{
/**
* @var UnitTester
*/
protected $tester;
public function testNoDeprecationThrownOnFractionalValues()
{
$values = [9, 9.29, 10, 10, 8.5];
$width = 400;
$height = 400;
$data = new Data();
$data->addPoints($values, 'Score');
$data->setSerieDescription('Score', '222');
$data->addPoints(['111', '222', '333', '444', '555'], 'Labels');
$data->setAbscissa('Labels');
$data->setPalette('Score', ['R' => 157, 'G' => 96, 'B' => 22]);
$image = new Image($width, $height, $data);
$image->setFontProperties(['FontSize' => 10, 'R' => 80, 'G' => 80, 'B' => 80]);
$image->setShadow(
true,
['X' => 2, 'Y' => 2, 'R' => 0, 'G' => 0, 'B' => 0, 'Alpha' => 10]
);
$radar = new Radar;
$image->setGraphArea(0, 0, $width, $height);
$options = [
'DrawPoly' => true,
'WriteValues' => true,
'ValueFontSize' => 7,
'Layout' => RADAR_LAYOUT_CIRCLE,
'BackgroundGradient' => [
'StartR' => 255,
'StartG' => 255,
'StartB' => 255,
'StartAlpha' => 100,
'EndR' => 207,
'EndG' => 227,
'EndB' => 125,
'EndAlpha' => 50
]
];
$radar->drawRadar($image, $data, $options);
$filename = $this->tester->getOutputPathForChart('drawRadarFractional.png');
$image->render($filename);
$image->stroke();
$this->tester->seeFileFound($filename);
}
}

View File

@@ -0,0 +1,73 @@
<?php
namespace Test\CpChart;
use Codeception\Test\Unit;
use CpChart\Data;
use CpChart\Image;
use Test\CpChart\UnitTester;
class ResourceTest extends Unit
{
/**
* @var UnitTester
*/
protected $tester;
public function testInvalidResourceLoading()
{
$data = new Data();
$this->tester->expectThrowable(
'\Exception',
function () use ($data) {
$data->loadPalette('nonExistantPalette');
}
);
$image = new Image(700, 230, $data);
$this->tester->expectThrowable(
'\Exception',
function () use ($image) {
$image->setResourcePath('nonExistantDirectory');
}
);
$this->tester->expectThrowable(
'\Exception',
function () use ($image) {
$image->setFontProperties(['FontName' => 'nonExistantFont']);
}
);
$this->tester->expectThrowable(
'\Exception',
function () use ($image) {
$image->getLegendSize(['Font' => 'nonExistantFont']);
}
);
}
public function testValidPaletteLoading()
{
$data = new Data();
$data->loadPalette(sprintf('%s/../_data/test_palette.txt', __DIR__), true);
$image = new Image(700, 230, $data);
$firstCoordinates = [[40, 80], [280, 60], [340, 166], [590, 120]];
$fistSplineSettings = ['R' => 255, 'G' => 255, 'B' => 255, 'ShowControl' => true];
$image->drawSpline($firstCoordinates, $fistSplineSettings);
$filename = $this->tester->getOutputPathForChart('drawSpline.png');
$image->render($filename);
$this->tester->seeFileFound($filename);
}
public function testInvalidPaletteLoading()
{
$data = new Data();
$this->tester->expectThrowable(
'\Exception',
function () use ($data) {
$data->loadPalette(sprintf('non_existant_palette', __DIR__), true);
}
);
}
}

View File

@@ -0,0 +1,327 @@
<?php
namespace Test\CpChart;
use Codeception\Test\Unit;
use CpChart\Chart\Scatter;
use CpChart\Data;
use CpChart\Image;
use Test\CpChart\UnitTester;
use const AXIS_POSITION_BOTTOM;
use const AXIS_POSITION_LEFT;
use const AXIS_POSITION_RIGHT;
use const AXIS_POSITION_TOP;
use const AXIS_X;
use const AXIS_Y;
use const DIRECTION_VERTICAL;
use const LEGEND_HORIZONTAL;
use const LEGEND_NOBORDER;
class ScatterTest extends Unit
{
/**
* @var UnitTester
*/
protected $tester;
public function testBestFitChartRender()
{
$data = new Data();
for ($i = 0; $i <= 360; $i = $i + 10) {
$data->addPoints(rand(1, 20) * 10 + rand(0, $i), 'Probe 1');
}
for ($i = 0; $i <= 360; $i = $i + 10) {
$data->addPoints(rand(1, 2) * 10 + rand(0, $i), 'Probe 2');
}
$data->setAxisName(0, 'X-Index');
$data->setAxisXY(0, AXIS_X);
$data->setAxisPosition(0, AXIS_POSITION_TOP);
for ($i = 0; $i <= 360; $i = $i + 10) {
$data->addPoints($i, 'Probe 3');
}
$data->setSerieOnAxis('Probe 3', 1);
$data->setAxisName(1, 'Y-Index');
$data->setAxisXY(1, AXIS_Y);
$data->setAxisPosition(1, AXIS_POSITION_LEFT);
$data->setScatterSerie('Probe 1', 'Probe 3', 0);
$data->setScatterSerieDescription(0, 'This year');
$data->setScatterSerieColor(0, ['R' => 0, 'G' => 0, 'B' => 0]);
$data->setScatterSerie('Probe 2', 'Probe 3', 1);
$data->setScatterSerieDescription(1, 'Last Year');
$image = new Image(400, 400, $data);
$settings = [
'R' => 170, 'G' => 183, 'B' => 87, 'Dash' => 1, 'DashR' => 190,
'DashG' => 203, 'DashB' => 107
];
$image->drawFilledRectangle(0, 0, 400, 400, $settings);
$settings = [
'StartR' => 219, 'StartG' => 231, 'StartB' => 139, 'EndR' => 1,
'EndG' => 138, 'EndB' => 68, 'Alpha' => 50
];
$image->drawGradientArea(0, 0, 400, 400, DIRECTION_VERTICAL, $settings);
$image->drawGradientArea(
0,
0,
400,
20,
DIRECTION_VERTICAL,
[
'StartR' => 0, 'StartG' => 0, 'StartB' => 0, 'EndR' => 50, 'EndG' => 50,
'EndB' => 50, 'Alpha' => 80
]
);
$image->setFontProperties(['FontName' => 'Silkscreen.ttf', 'FontSize' => 6]);
$image->drawText(
10,
13,
'drawScatterBestFit() - Linear regression',
['R' => 255, 'G' => 255, 'B' => 255]
);
$image->drawRectangle(0, 0, 399, 399, ['R' => 0, 'G' => 0, 'B' => 0]);
$image->setFontProperties(['FontName' => 'pf_arma_five.ttf', 'FontSize' => 6]);
$image->setGraphArea(50, 60, 350, 360);
$scatterChart = new Scatter($image, $data);
$scatterChart->drawScatterScale();
$image->setShadow(
true,
['X' => 1, 'Y' => 1, 'R' => 0, 'G' => 0, 'B' => 0, 'Alpha' => 10]
);
$scatterChart->drawScatterPlotChart();
$scatterChart->drawScatterLegend(280, 380, ['Mode' => LEGEND_HORIZONTAL, 'Style' => LEGEND_NOBORDER]);
$scatterChart->drawScatterBestFit();
$filename = $this->tester->getOutputPathForChart('drawScatterBestFit.png');
$image->render($filename);
$image->stroke();
$this->tester->seeFileFound($filename);
}
public function testLineChartRender()
{
$data = new Data();
for ($i = 0; $i <= 360; $i = $i + 10) {
$data->addPoints(cos(deg2rad($i)) * 20, 'Probe 1');
}
for ($i = 0; $i <= 360; $i = $i + 10) {
$data->addPoints(sin(deg2rad($i)) * 20, 'Probe 2');
}
$data->setAxisName(0, 'Index');
$data->setAxisXY(0, AXIS_X);
$data->setAxisPosition(0, AXIS_POSITION_BOTTOM);
for ($i = 0; $i <= 360; $i = $i + 10) {
$data->addPoints($i, 'Probe 3');
}
$data->setSerieOnAxis('Probe 3', 1);
$data->setAxisName(1, 'Degree');
$data->setAxisXY(1, AXIS_Y);
$data->setAxisUnit(1, '°');
$data->setAxisPosition(1, AXIS_POSITION_RIGHT);
$data->setScatterSerie('Probe 1', 'Probe 3', 0);
$data->setScatterSerieDescription(0, 'This year');
$data->setScatterSerieTicks(0, 4);
$data->setScatterSerieColor(0, ['R' => 0, 'G' => 0, 'B' => 0]);
$data->setScatterSerie('Probe 2', 'Probe 3', 1);
$data->setScatterSerieDescription(1, 'Last Year');
$image = new Image(400, 400, $data);
$settings = [
'R' => 170, 'G' => 183, 'B' => 87, 'Dash' => 1, 'DashR' => 190,
'DashG' => 203, 'DashB' => 107
];
$image->drawFilledRectangle(0, 0, 400, 400, $settings);
$settings = [
'StartR' => 219, 'StartG' => 231, 'StartB' => 139, 'EndR' => 1,
'EndG' => 138, 'EndB' => 68, 'Alpha' => 50
];
$image->drawGradientArea(0, 0, 400, 400, DIRECTION_VERTICAL, $settings);
$image->drawGradientArea(
0,
0,
400,
20,
DIRECTION_VERTICAL,
[
'StartR' => 0, 'StartG' => 0, 'StartB' => 0, 'EndR' => 50, 'EndG' => 50,
'EndB' => 50, 'Alpha' => 80
]
);
$image->setFontProperties(['FontName' => 'Silkscreen.ttf', 'FontSize' => 6]);
$image->drawText(
10,
13,
'drawScatterLineChart() - Draw a scatter line chart',
['R' => 255, 'G' => 255, 'B' => 255]
);
$image->drawRectangle(0, 0, 399, 399, ['R' => 0, 'G' => 0, 'B' => 0]);
$image->setFontProperties(['FontName' => 'pf_arma_five.ttf', 'FontSize' => 6]);
$image->setGraphArea(50, 50, 350, 350);
$scatterChart = new Scatter($image, $data);
$scatterChart->drawScatterScale();
$image->setShadow(
true,
['X' => 1, 'Y' => 1, 'R' => 0, 'G' => 0, 'B' => 0, 'Alpha' => 10]
);
$scatterChart->drawScatterLineChart();
$scatterChart->drawScatterLegend(280, 380, ['Mode' => LEGEND_HORIZONTAL, 'Style' => LEGEND_NOBORDER]);
$filename = $this->tester->getOutputPathForChart('drawScatterLine.png');
$image->render($filename);
$image->stroke();
$this->tester->seeFileFound($filename);
}
public function testPlotChartRender()
{
$data = new Data();
for ($i = 0; $i <= 360; $i = $i + 10) {
$data->addPoints(cos(deg2rad($i)) * 20, 'Probe 1');
}
for ($i = 0; $i <= 360; $i = $i + 10) {
$data->addPoints(sin(deg2rad($i)) * 20, 'Probe 2');
}
$data->setAxisName(0, 'Index');
$data->setAxisXY(0, AXIS_X);
$data->setAxisPosition(0, AXIS_POSITION_BOTTOM);
for ($i = 0; $i <= 360; $i = $i + 10) {
$data->addPoints($i, 'Probe 3');
}
$data->setSerieOnAxis('Probe 3', 1);
$data->setAxisName(1, 'Degree');
$data->setAxisXY(1, AXIS_Y);
$data->setAxisUnit(1, '°');
$data->setAxisPosition(1, AXIS_POSITION_RIGHT);
$data->setScatterSerie('Probe 1', 'Probe 3', 0);
$data->setScatterSerieDescription(0, 'This year');
$data->setScatterSerieColor(0, ['R' => 0, 'G' => 0, 'B' => 0]);
$data->setScatterSerie('Probe 2', 'Probe 3', 1);
$data->setScatterSerieDescription(1, 'Last Year');
$data->setScatterSeriePicture(1, sprintf('%s/../_data/accept.png', __DIR__));
$image = new Image(400, 400, $data);
$settings = [
'R' => 170, 'G' => 183, 'B' => 87, 'Dash' => 1, 'DashR' => 190,
'DashG' => 203, 'DashB' => 107
];
$image->drawFilledRectangle(0, 0, 400, 400, $settings);
$settings = [
'StartR' => 219, 'StartG' => 231, 'StartB' => 139, 'EndR' => 1,
'EndG' => 138, 'EndB' => 68, 'Alpha' => 50
];
$image->drawGradientArea(0, 0, 400, 400, DIRECTION_VERTICAL, $settings);
$image->drawGradientArea(
0,
0,
400,
20,
DIRECTION_VERTICAL,
[
'StartR' => 0, 'StartG' => 0, 'StartB' => 0, 'EndR' => 50, 'EndG' => 50,
'EndB' => 50, 'Alpha' => 80
]
);
$image->setFontProperties(['FontName' => 'Silkscreen.ttf', 'FontSize' => 6]);
$image->drawText(
10,
13,
'drawScatterPlotChart() - Draw a scatter plot chart',
['R' => 255, 'G' => 255, 'B' => 255]
);
$image->drawRectangle(0, 0, 399, 399, ['R' => 0, 'G' => 0, 'B' => 0]);
$image->setFontProperties(['FontName' => 'pf_arma_five.ttf', 'FontSize' => 6]);
$image->setGraphArea(50, 50, 350, 350);
$scatterChart = new Scatter($image, $data);
$scatterChart->drawScatterScale();
$image->setShadow(
true,
['X' => 1, 'Y' => 1, 'R' => 0, 'G' => 0, 'B' => 0, 'Alpha' => 10]
);
$scatterChart->drawScatterPlotChart();
$scatterChart->drawScatterLegend(260, 375, ['Mode' => LEGEND_HORIZONTAL, 'Style' => LEGEND_NOBORDER]);
$filename = $this->tester->getOutputPathForChart('drawScatterPlot.png');
$image->render($filename);
$image->stroke();
$this->tester->seeFileFound($filename);
}
public function testSplineChartRender()
{
$data = new Data();
for ($i = 0; $i <= 360; $i = $i + 90) {
$data->addPoints(rand(1, 30), 'Probe 1');
}
for ($i = 0; $i <= 360; $i = $i + 90) {
$data->addPoints(rand(1, 30), 'Probe 2');
}
$data->setAxisName(0, 'Index');
$data->setAxisXY(0, AXIS_X);
$data->setAxisPosition(0, AXIS_POSITION_BOTTOM);
for ($i = 0; $i <= 360; $i = $i + 90) {
$data->addPoints($i, 'Probe 3');
}
$data->setSerieOnAxis('Probe 3', 1);
$data->setAxisName(1, 'Degree');
$data->setAxisXY(1, AXIS_Y);
$data->setAxisUnit(1, '°');
$data->setAxisPosition(1, AXIS_POSITION_RIGHT);
$data->setScatterSerie('Probe 1', 'Probe 3', 0);
$data->setScatterSerieDescription(0, 'This year');
$data->setScatterSerieTicks(0, 4);
$data->setScatterSerieColor(0, ['R' => 0, 'G' => 0, 'B' => 0]);
$data->setScatterSerie('Probe 2', 'Probe 3', 1);
$data->setScatterSerieDescription(1, 'Last Year');
$image = new Image(400, 400, $data);
$settings = [
'R' => 170, 'G' => 183, 'B' => 87, 'Dash' => 1, 'DashR' => 190,
'DashG' => 203, 'DashB' => 107
];
$image->drawFilledRectangle(0, 0, 400, 400, $settings);
$settings = [
'StartR' => 219, 'StartG' => 231, 'StartB' => 139, 'EndR' => 1,
'EndG' => 138, 'EndB' => 68, 'Alpha' => 50
];
$image->drawGradientArea(0, 0, 400, 400, DIRECTION_VERTICAL, $settings);
$image->drawGradientArea(
0,
0,
400,
20,
DIRECTION_VERTICAL,
[
'StartR' => 0, 'StartG' => 0, 'StartB' => 0, 'EndR' => 50, 'EndG' => 50,
'EndB' => 50, 'Alpha' => 80
]
);
$image->setFontProperties(['FontName' => '../fonts/Silkscreen.ttf', 'FontSize' => 6]);
$image->drawText(
10,
13,
'drawScatterSplineChart() - Draw a scatter spline chart',
['R' => 255, 'G' => 255, 'B' => 255]
);
$image->drawRectangle(0, 0, 399, 399, ['R' => 0, 'G' => 0, 'B' => 0]);
$image->setFontProperties(['FontName' => '../fonts/pf_arma_five.ttf', 'FontSize' => 6]);
$image->setGraphArea(50, 50, 350, 350);
$scatterChart = new Scatter($image, $data);
$scatterChart->drawScatterScale();
$image->setShadow(
true,
['X' => 1, 'Y' => 1, 'R' => 0, 'G' => 0, 'B' => 0, 'Alpha' => 10]
);
$scatterChart->drawScatterSplineChart();
$scatterChart->drawScatterPlotChart();
$scatterChart->drawScatterLegend(
280,
380,
['Mode' => LEGEND_HORIZONTAL, 'Style' => LEGEND_NOBORDER]
);
$filename = $this->tester->getOutputPathForChart('drawScatterSpline.png');
$image->render($filename);
$image->stroke();
$this->tester->seeFileFound($filename);
}
}

View File

@@ -0,0 +1,45 @@
<?php
namespace Test\CpChart;
use Codeception\Test\Unit;
use CpChart\Data;
use CpChart\Image;
use Test\CpChart\UnitTester;
class SplineTest extends Unit
{
/**
* @var UnitTester
*/
protected $tester;
public function testChartRender()
{
$data = new Data();
$data->addPoints([], 'Serie1');
$image = new Image(700, 230, $data);
$image->setShadow(
true,
['X' => 1, 'Y' => 1, 'R' => 0, 'G' => 0, 'B' => 0, 'Alpha' => 20]
);
$firstCoordinates = [[40, 80], [280, 60], [340, 166], [590, 120]];
$fistSplineSettings = ['R' => 255, 'G' => 255, 'B' => 255, 'ShowControl' => true];
$image->drawSpline($firstCoordinates, $fistSplineSettings);
$secondCoordinates = [[250, 50], [250, 180], [350, 180], [350, 50]];
$secondSplineSettings = [
'R' => 255,
'G' => 255,
'B' => 255,
'ShowControl' => true,
'Ticks' => 4
];
$image->drawSpline($secondCoordinates, $secondSplineSettings);
$filename = $this->tester->getOutputPathForChart('drawSpline.png');
$image->render($filename);
$image->stroke();
$this->tester->seeFileFound($filename);
}
}

View File

@@ -0,0 +1,90 @@
<?php
namespace Test\CpChart;
use Codeception\Test\Unit;
use CpChart\Chart\Split;
use CpChart\Data;
use CpChart\Image;
use Test\CpChart\UnitTester;
use const DIRECTION_VERTICAL;
use const TEXT_POS_RIGHT;
class SplitPathTest extends Unit
{
/**
* @var UnitTester
*/
protected $tester;
public function testChartRender()
{
$image = new Image(700, 230);
$settings = [
'R' => 170, 'G' => 183, 'B' => 87, 'Dash' => 1, 'DashR' => 190,
'DashG' => 203, 'DashB' => 107
];
$image->drawFilledRectangle(0, 0, 700, 230, $settings);
$settings = [
'StartR' => 219, 'StartG' => 231, 'StartB' => 139, 'EndR' => 1,
'EndG' => 138, 'EndB' => 68, 'Alpha' => 50
];
$image->drawGradientArea(0, 0, 700, 230, DIRECTION_VERTICAL, $settings);
$image->drawGradientArea(
0,
0,
700,
20,
DIRECTION_VERTICAL,
[
'StartR' => 0, 'StartG' => 0, 'StartB' => 0, 'EndR' => 50, 'EndG' => 50,
'EndB' => 50, 'Alpha' => 80
]
);
$image->drawRectangle(0, 0, 699, 229, ['R' => 0, 'G' => 0, 'B' => 0]);
$image->setFontProperties(['FontName' => 'Silkscreen.ttf', 'FontSize' => 6]);
$image->drawText(
10,
13,
'pSplit - Draw splitted path charts',
['R' => 255, 'G' => 255, 'B' => 255]
);
$image->setFontProperties(
['FontName' => 'Forgotte.ttf', 'FontSize' => 10, 'R' => 80, 'G' => 80, 'B' => 80]
);
$image->setShadow(
true,
['X' => 2, 'Y' => 2, 'R' => 0, 'G' => 0, 'B' => 0, 'Alpha' => 10]
);
$data = new Data();
$data->addPoints([30, 20, 15, 10, 8, 4], 'Score');
$data->addPoints(
['End of visit', 'Home Page', 'Product Page', 'Sales', 'Statistics', 'Prints'],
'Labels'
);
$data->setAbscissa('Labels');
$SplitChart = new Split();
$settings = [
'TextPos' => TEXT_POS_RIGHT,
'TextPadding' => 10,
'Spacing' => 20,
'Surrounding' => 40
];
$image->setGraphArea(10, 20, 340, 230);
$SplitChart->drawSplitPath($image, $data, $settings);
$data2 = new Data();
$data2->addPoints([30, 20, 15], 'Score');
$data2->addPoints(['UK', 'FR', 'ES'], 'Labels');
$data2->setAbscissa('Labels');
$settings = ['TextPadding' => 4, 'Spacing' => 30, 'Surrounding' => 20];
$image->setGraphArea(350, 50, 690, 200);
$SplitChart->drawSplitPath($image, $data2, $settings);
$filename = $this->tester->getOutputPathForChart('drawSplit.png');
$image->render($filename);
$image->stroke();
$this->tester->seeFileFound($filename);
}
}

View File

@@ -0,0 +1,114 @@
<?php
namespace Test\CpChart;
use Codeception\Test\Unit;
use CpChart\Chart\Spring;
use CpChart\Image;
use Test\CpChart\UnitTester;
use const DIRECTION_HORIZONTAL;
use const DIRECTION_VERTICAL;
use const NODE_SHAPE_SQUARE;
use const NODE_SHAPE_TRIANGLE;
use const NODE_TYPE_CENTRAL;
class SpringTest extends Unit
{
/**
* @var UnitTester
*/
protected $tester;
public function testChartRender()
{
$image = new Image(300, 300);
$image->drawGradientArea(
0,
0,
300,
300,
DIRECTION_HORIZONTAL,
[
'StartR' => 217, 'StartG' => 250, 'StartB' => 116, 'EndR' => 181, 'EndG' => 209,
'EndB' => 27, 'Alpha' => 100
]
);
$image->drawGradientArea(
0,
0,
300,
20,
DIRECTION_VERTICAL,
[
'StartR' => 0, 'StartG' => 0, 'StartB' => 0, 'EndR' => 50, 'EndG' => 50,
'EndB' => 50, 'Alpha' => 100
]
);
$image->drawRectangle(0, 0, 299, 299, ['R' => 0, 'G' => 0, 'B' => 0]);
$image->setFontProperties(['FontName' => 'Silkscreen.ttf', 'FontSize' => 6]);
$image->drawText(
10,
13,
'pSpring - Draw spring charts',
['R' => 255, 'G' => 255, 'B' => 255]
);
$image->setGraphArea(20, 20, 280, 280);
$image->setFontProperties(
['FontName' => 'Forgotte.ttf', 'FontSize' => 9, 'R' => 80, 'G' => 80, 'B' => 80]
);
$image->setShadow(
true,
['X' => 2, 'Y' => 2, 'R' => 0, 'G' => 0, 'B' => 0, 'Alpha' => 10]
);
$springChart = new Spring();
$springChart->addNode(
0,
['Shape' => NODE_SHAPE_SQUARE, 'FreeZone' => 60, 'Size' => 20, 'NodeType' => NODE_TYPE_CENTRAL]
);
$springChart->addNode(1, ['Connections' => '0']);
$springChart->addNode(2, ['Connections' => '0']);
$springChart->addNode(3, ['Shape' => NODE_SHAPE_TRIANGLE, 'Connections' => '1']);
$springChart->addNode(4, ['Shape' => NODE_SHAPE_TRIANGLE, 'Connections' => '1']);
$springChart->addNode(5, ['Shape' => NODE_SHAPE_TRIANGLE, 'Connections' => '1']);
$springChart->addNode(6, ['Connections' => '2']);
$springChart->addNode(7, ['Connections' => '2']);
$springChart->addNode(8, ['Connections' => '2']);
$springChart->setNodesColor(
0,
[
'R' => 215, 'G' => 163, 'B' => 121, 'BorderR' => 166, 'BorderG' => 115,
'BorderB' => 74
]
);
$springChart->setNodesColor(
[1, 2],
['R' => 150, 'G' => 215, 'B' => 121, 'Surrounding' => -30]
);
$springChart->setNodesColor(
[3, 4, 5],
['R' => 216, 'G' => 166, 'B' => 14, 'Surrounding' => -30]
);
$springChart->setNodesColor(
[6, 7, 8],
['R' => 179, 'G' => 121, 'B' => 215, 'Surrounding' => -30]
);
$springChart->linkProperties(
0,
1,
['R' => 255, 'G' => 0, 'B' => 0, 'Ticks' => 2]
);
$springChart->linkProperties(
0,
2,
['R' => 255, 'G' => 0, 'B' => 0, 'Ticks' => 2]
);
$springChart->drawSpring($image);
$filename = $this->tester->getOutputPathForChart('drawSpring.png');
$image->render($filename);
$image->stroke();
$this->tester->seeFileFound($filename);
}
}

View File

@@ -0,0 +1,77 @@
<?php
namespace Test\CpChart;
use Codeception\Test\Unit;
use CpChart\Data;
use CpChart\Image;
use Test\CpChart\UnitTester;
use const DIRECTION_HORIZONTAL;
use const DIRECTION_VERTICAL;
use const LEGEND_HORIZONTAL;
use const LEGEND_NOBORDER;
use const SCALE_MODE_ADDALL;
class StackedAreaTest extends Unit
{
/**
* @var UnitTester
*/
protected $tester;
public function testChartRender()
{
$data = new Data();
$data->addPoints([4, 0, 0, 12, 8, 3, 0, 12, 8], 'Frontend #1');
$data->addPoints([3, 12, 15, 8, 5, 5, 12, 15, 8], 'Frontend #2');
$data->addPoints([2, 7, 5, 18, 19, 22, 7, 5, 18], 'Frontend #3');
$data->setAxisName(0, 'Average Usage');
$data->addPoints(
['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jui', 'Aug', 'Sep'],
'Labels'
);
$data->setSerieDescription('Labels', 'Months');
$data->setAbscissa('Labels');
$data->normalize(100, '%');
$image = new Image(700, 230, $data);
$image->drawGradientArea(
0,
0,
700,
230,
DIRECTION_VERTICAL,
[
'StartR' => 240, 'StartG' => 240, 'StartB' => 240, 'EndR' => 180, 'EndG' => 180,
'EndB' => 180, 'Alpha' => 100
]
);
$image->drawGradientArea(
0,
0,
700,
230,
DIRECTION_HORIZONTAL,
[
'StartR' => 240, 'StartG' => 240, 'StartB' => 240, 'EndR' => 180, 'EndG' => 180,
'EndB' => 180, 'Alpha' => 20
]
);
$image->setFontProperties(['FontName' => 'pf_arma_five.ttf', 'FontSize' => 6]);
$image->setGraphArea(60, 20, 680, 190);
$image->drawScale(['XMargin' => 2, 'DrawSubTicks' => true, 'Mode' => SCALE_MODE_ADDALL]);
$image->setShadow(
true,
['X' => 1, 'Y' => 1, 'R' => 0, 'G' => 0, 'B' => 0, 'Alpha' => 10]
);
$image->drawStackedAreaChart(['Surrounding' => 60]);
$image->setShadow(false);
$image->drawLegend(480, 210, ['Style' => LEGEND_NOBORDER, 'Mode' => LEGEND_HORIZONTAL]);
$filename = $this->tester->getOutputPathForChart('drawStackedArea.png');
$image->render($filename);
$image->stroke();
$this->tester->seeFileFound($filename);
}
}

View File

@@ -0,0 +1,85 @@
<?php
namespace Test\CpChart;
use Codeception\Test\Unit;
use CpChart\Data;
use CpChart\Image;
use Test\CpChart\UnitTester;
use const DIRECTION_VERTICAL;
use const DISPLAY_AUTO;
use const LEGEND_HORIZONTAL;
use const LEGEND_NOBORDER;
use const SCALE_MODE_ADDALL;
class StackedBarTest extends Unit
{
/**
* @var UnitTester
*/
protected $tester;
public function testChartRender()
{
$data = new Data();
$data->addPoints(
[-7, -8, -15, -20, -18, -12, 8, -19, 9, 16, -20, 8, 10, -10, -14, -20, 8, -9, -19],
'Probe 3'
);
$data->addPoints(
[19, 0, -8, 8, -8, 12, -19, -10, 5, 12, -20, -8, 10, -11, -12, 8, -17, -14, 0],
'Probe 4'
);
$data->setAxisName(0, 'Temperatures');
$data->addPoints(
[4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22],
'Time'
);
$data->setSerieDescription('Time', 'Hour of the day');
$data->setAbscissa('Time');
$data->setXAxisUnit('h');
$image = new Image(700, 230, $data);
$settings = [
'R' => 170, 'G' => 183, 'B' => 87, 'Dash' => 1, 'DashR' => 190,
'DashG' => 203, 'DashB' => 107
];
$image->drawFilledRectangle(0, 0, 700, 230, $settings);
$settings = [
'StartR' => 219, 'StartG' => 231, 'StartB' => 139, 'EndR' => 1,
'EndG' => 138, 'EndB' => 68, 'Alpha' => 50
];
$image->drawGradientArea(0, 0, 700, 230, DIRECTION_VERTICAL, $settings);
$image->setFontProperties(['FontName' => 'pf_arma_five.ttf', 'FontSize' => 6]);
$image->setGraphArea(60, 30, 650, 190);
$image->drawScale([
'CycleBackground' => true,
'DrawSubTicks' => true,
'GridR' => 0,
'GridG' => 0,
'GridB' => 0,
'GridAlpha' => 10,
'Mode' => SCALE_MODE_ADDALL
]);
$image->setShadow(true, ['X' => 1, 'Y' => 1, 'R' => 0, 'G' => 0, 'B' => 0, 'Alpha' => 10]);
$image->setShadow(false);
$image->drawThreshold(-40, ['WriteCaption' => true, 'R' => 0, 'G' => 0, 'B' => 0, 'Ticks' => 4]);
$image->drawThreshold(28, ['WriteCaption' => true, 'R' => 0, 'G' => 0, 'B' => 0, 'Ticks' => 4]);
$image->drawStackedBarChart([
'Rounded' => true,
'DisplayValues' => true,
'DisplayColor' => DISPLAY_AUTO,
'DisplaySize' => 6,
'BorderR' => 255,
'BorderG' => 255,
'BorderB' => 255
]);
$image->drawLegend(570, 212, ['Style' => LEGEND_NOBORDER, 'Mode' => LEGEND_HORIZONTAL]);
$filename = $this->tester->getOutputPathForChart('drawStackedChart.png');
$image->render($filename);
$image->stroke();
$this->tester->seeFileFound($filename);
}
}

View File

@@ -0,0 +1,112 @@
<?php
namespace Test\CpChart;
use Codeception\Test\Unit;
use CpChart\Data;
use CpChart\Image;
use Test\CpChart\UnitTester;
use const DIRECTION_VERTICAL;
use const DISPLAY_AUTO;
use const LEGEND_HORIZONTAL;
use const LEGEND_NOBORDER;
use const SCALE_POS_TOPBOTTOM;
use const TEXT_ALIGN_BOTTOMMIDDLE;
use const VOID;
class StepTest extends Unit
{
/**
* @var UnitTester
*/
protected $tester;
public function testChartRender()
{
$data = new Data();
$data->addPoints([-4, VOID, VOID, 12, 8, 3], 'Probe 1');
$data->addPoints([3, 12, 15, 8, 5, -5], 'Probe 2');
$data->addPoints([2, 7, 5, 18, 19, 22], 'Probe 3');
$data->setSerieTicks('Probe 2', 4);
$data->setAxisName(0, 'Temperatures');
$data->addPoints(['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun'], 'Labels');
$data->setSerieDescription('Labels', 'Months');
$data->setAbscissa('Labels');
$image = new Image(700, 230, $data);
$settings = [
'R' => 170, 'G' => 183, 'B' => 87, 'Dash' => 1, 'DashR' => 190,
'DashG' => 203, 'DashB' => 107
];
$image->drawFilledRectangle(0, 0, 700, 230, $settings);
$settings = [
'StartR' => 219, 'StartG' => 231, 'StartB' => 139, 'EndR' => 1,
'EndG' => 138, 'EndB' => 68, 'Alpha' => 50
];
$image->drawGradientArea(0, 0, 700, 230, DIRECTION_VERTICAL, $settings);
$image->drawGradientArea(
0,
0,
700,
20,
DIRECTION_VERTICAL,
[
'StartR' => 0, 'StartG' => 0, 'StartB' => 0, 'EndR' => 50, 'EndG' => 50,
'EndB' => 50, 'Alpha' => 80
]
);
$image->drawRectangle(0, 0, 699, 229, ['R' => 0, 'G' => 0, 'B' => 0]);
$image->setFontProperties(['FontName' => 'Silkscreen.ttf', 'FontSize' => 6]);
$image->drawText(
10,
13,
'drawStepChart() - draw a step chart',
['R' => 255, 'G' => 255, 'B' => 255]
);
$image->setFontProperties(['FontName' => 'Forgotte.ttf', 'FontSize' => 11]);
$image->drawText(
250,
55,
'Average temperature',
['FontSize' => 20, 'Align' => TEXT_ALIGN_BOTTOMMIDDLE]
);
$image->setGraphArea(60, 60, 450, 190);
$image->drawFilledRectangle(
60,
60,
450,
190,
['R' => 255, 'G' => 255, 'B' => 255, 'Surrounding' => -200, 'Alpha' => 10]
);
$image->drawScale(['DrawSubTicks' => true]);
$image->setShadow(
true,
['X' => 1, 'Y' => 1, 'R' => 0, 'G' => 0, 'B' => 0, 'Alpha' => 10]
);
$image->setFontProperties(['FontName' => 'pf_arma_five.ttf', 'FontSize' => 6]);
$image->drawStepChart(['DisplayValues' => true, 'DisplayColor' => DISPLAY_AUTO]);
$image->setShadow(false);
$image->setGraphArea(500, 60, 670, 190);
$image->drawFilledRectangle(
500,
60,
670,
190,
['R' => 255, 'G' => 255, 'B' => 255, 'Surrounding' => -200, 'Alpha' => 10]
);
$image->drawScale(['Pos' => SCALE_POS_TOPBOTTOM, 'DrawSubTicks' => true]);
$image->setShadow(
true,
['X' => -1, 'Y' => 1, 'R' => 0, 'G' => 0, 'B' => 0, 'Alpha' => 10]
);
$image->drawStepChart();
$image->setShadow(false);
$image->drawLegend(510, 205, ['Style' => LEGEND_NOBORDER, 'Mode' => LEGEND_HORIZONTAL]);
$filename = $this->tester->getOutputPathForChart('drawStep.png');
$image->render($filename);
$image->stroke();
$this->tester->seeFileFound($filename);
}
}

View File

@@ -0,0 +1,91 @@
<?php
namespace Test\CpChart;
use Codeception\Test\Unit;
use CpChart\Chart\Stock;
use CpChart\Data;
use CpChart\Image;
use Test\CpChart\UnitTester;
use const AXIS_FORMAT_CURRENCY;
use const AXIS_FORMAT_DEFAULT;
use const DIRECTION_VERTICAL;
use const SCALE_POS_TOPBOTTOM;
use const TEXT_ALIGN_BOTTOMLEFT;
class StockTest extends Unit
{
/**
* @var UnitTester
*/
protected $tester;
public function testChartRender()
{
$data = new Data();
$data->addPoints([34, 55, 15, 62, 38, 42], 'Open');
$data->addPoints([42, 25, 40, 38, 49, 36], 'Close');
$data->addPoints([27, 14, 12, 25, 32, 32], 'Min');
$data->addPoints([45, 59, 47, 65, 64, 48], 'Max');
$data->setAxisDisplay(0, AXIS_FORMAT_CURRENCY, '$');
$data->addPoints(['8h', '10h', '12h', '14h', '16h', '18h'], 'Time');
$data->setAbscissa('Time');
$image = new Image(700, 230, $data);
$settings = [
'R' => 170, 'G' => 183, 'B' => 87, 'Dash' => 1, 'DashR' => 190,
'DashG' => 203, 'DashB' => 107
];
$image->drawFilledRectangle(0, 0, 700, 230, $settings);
$settings = [
'StartR' => 219, 'StartG' => 231, 'StartB' => 139, 'EndR' => 1,
'EndG' => 138, 'EndB' => 68, 'Alpha' => 50
];
$image->drawGradientArea(0, 0, 700, 230, DIRECTION_VERTICAL, $settings);
$image->drawRectangle(0, 0, 699, 229, ['R' => 0, 'G' => 0, 'B' => 0]);
$image->setFontProperties(['FontName' => '../fonts/Forgotte.ttf', 'FontSize' => 11]);
$image->drawText(
60,
45,
'Stock price',
['FontSize' => 28, 'Align' => TEXT_ALIGN_BOTTOMLEFT]
);
$image->setGraphArea(60, 60, 450, 190);
$image->drawFilledRectangle(
60,
60,
450,
190,
['R' => 255, 'G' => 255, 'B' => 255, 'Surrounding' => -200, 'Alpha' => 10]
);
$image->drawScale(['DrawSubTicks' => true, 'CycleBackground' => true]);
$stockChart = new Stock($image, $data);
$image->setShadow(
true,
['X' => 1, 'Y' => 1, 'R' => 0, 'G' => 0, 'B' => 0, 'Alpha' => 30]
);
$stockChart->drawStockChart();
$data->setAxisDisplay(0, AXIS_FORMAT_DEFAULT);
$image->setShadow(false);
$image->setGraphArea(500, 60, 670, 190);
$image->drawFilledRectangle(
500,
60,
670,
190,
['R' => 255, 'G' => 255, 'B' => 255, 'Surrounding' => -200, 'Alpha' => 10]
);
$image->drawScale(['Pos' => SCALE_POS_TOPBOTTOM, 'DrawSubTicks' => true]);
$stockChart = new Stock($image, $data);
$image->setShadow(
true,
['X' => 1, 'Y' => 1, 'R' => 0, 'G' => 0, 'B' => 0, 'Alpha' => 30]
);
$stockChart->drawStockChart();
$filename = $this->tester->getOutputPathForChart('drawStock.png');
$image->render($filename);
$image->stroke();
$this->tester->seeFileFound($filename);
}
}

View File

@@ -0,0 +1,171 @@
<?php
namespace Test\CpChart;
use Codeception\Test\Unit;
use CpChart\Chart\Surface;
use CpChart\Image;
use Test\CpChart\UnitTester;
use const DIRECTION_VERTICAL;
use const LABEL_POSITION_BOTTOM;
class SurfaceTest extends Unit
{
/**
* @var UnitTester
*/
protected $tester;
public function testSurfaceChartRender()
{
$image = new Image(400, 400);
$settings = [
'R' => 179, 'G' => 217, 'B' => 91, 'Dash' => 1, 'DashR' => 199,
'DashG' => 237, 'DashB' => 111
];
$image->drawFilledRectangle(0, 0, 400, 400, $settings);
$settings = [
'StartR' => 194, 'StartG' => 231, 'StartB' => 44, 'EndR' => 43,
'EndG' => 107, 'EndB' => 58, 'Alpha' => 50
];
$image->drawGradientArea(0, 0, 400, 400, DIRECTION_VERTICAL, $settings);
$image->drawGradientArea(
0,
0,
400,
20,
DIRECTION_VERTICAL,
[
'StartR' => 0, 'StartG' => 0, 'StartB' => 0, 'EndR' => 50, 'EndG' => 50,
'EndB' => 50, 'Alpha' => 100
]
);
$image->drawRectangle(0, 0, 399, 399, ['R' => 0, 'G' => 0, 'B' => 0]);
$image->setFontProperties(['FontName' => 'Silkscreen.ttf', 'FontSize' => 6]);
$image->drawText(
10,
13,
'pSurface() :: 2D surface charts',
['R' => 255, 'G' => 255, 'B' => 255]
);
$image->setGraphArea(20, 40, 380, 380);
$image->drawFilledRectangle(
20,
40,
380,
380,
['R' => 255, 'G' => 255, 'B' => 255, 'Surrounding' => -200, 'Alpha' => 20]
);
$image->setShadow(true, ['X' => 1, 'Y' => 1]);
$surfaceChart = new Surface($image);
$surfaceChart->setGrid(20, 20);
$image->setFontProperties(['FontName' => 'pf_arma_five.ttf', 'FontSize' => 6]);
$surfaceChart->writeXLabels();
$surfaceChart->writeYLabels();
for ($i = 0; $i <= 50; $i++) {
$surfaceChart->addPoint(rand(0, 20), rand(0, 20), rand(0, 100));
}
$surfaceChart->computeMissing();
$surfaceChart->drawSurface(['Border' => true, 'Surrounding' => 40]);
$filename = $this->tester->getOutputPathForChart('drawSurface.png');
$image->render($filename);
$image->stroke();
$this->tester->seeFileFound($filename);
}
public function testContourChartRender()
{
$image = new Image(400, 400);
$image->drawFilledRectangle(
0,
0,
400,
400,
[
'R' => 179,
'G' => 217,
'B' => 91,
'Dash' => 1,
'DashR' => 199,
'DashG' => 237,
'DashB' => 111
]
);
$image->drawGradientArea(
0,
0,
400,
400,
DIRECTION_VERTICAL,
[
'StartR' => 194,
'StartG' => 231,
'StartB' => 44,
'EndR' => 43,
'EndG' => 107,
'EndB' => 58,
'Alpha' => 50
]
);
$image->drawGradientArea(
0,
0,
400,
20,
DIRECTION_VERTICAL,
[
'StartR' => 0,
'StartG' => 0,
'StartB' => 0,
'EndR' => 50,
'EndG' => 50,
'EndB' => 50,
'Alpha' => 100
]
);
$image->drawRectangle(0, 0, 399, 399, ['R' => 0, 'G' => 0, 'B' => 0]);
$image->setFontProperties(['FontName' => 'Silkscreen.ttf', 'FontSize' => 6]);
$image->drawText(
10,
13,
'pSurface() :: 2D surface charts',
['R' => 255, 'G' => 255, 'B' => 255]
);
$image->setGraphArea(20, 40, 380, 380);
$image->drawFilledRectangle(
20,
40,
380,
380,
[
'R' => 255,
'G' => 255,
'B' => 255,
'Surrounding' => -200,
'Alpha' => 20
]
);
$image->setShadow(true, ['X' => 1, 'Y' => 1]);
$surfaceChart = new Surface($image);
$surfaceChart->setGrid(20, 20);
$image->setFontProperties(['FontName' => 'pf_arma_five.ttf', 'FontSize' => 6]);
$surfaceChart->writeXLabels(['Position' => LABEL_POSITION_BOTTOM]);
$surfaceChart->writeYLabels();
for ($i = 0; $i <= 50; $i++) {
$surfaceChart->addPoint(rand(0, 20), rand(0, 20), rand(0, 100));
}
$surfaceChart->computeMissing();
$surfaceChart->drawSurface(['Border' => true, 'Surrounding' => 40]);
$surfaceChart->drawContour(50, ['R' => 0, 'G' => 0, 'B' => 0]);
$filename = $this->tester->getOutputPathForChart('drawContour.png');
$image->render($filename);
$image->stroke();
$this->tester->seeFileFound($filename);
}
}

View File

@@ -0,0 +1,64 @@
<?php
namespace Test\CpChart;
use Codeception\Test\Unit;
use CpChart\Data;
use CpChart\Image;
use Test\CpChart\UnitTester;
use const LEGEND_HORIZONTAL;
use const LEGEND_NOBORDER;
use const TEXT_ALIGN_BOTTOMMIDDLE;
class ZoneTest extends Unit
{
/**
* @var UnitTester
*/
protected $tester;
public function testChartRender()
{
$data = new Data();
for ($i = 0; $i <= 10; $i = $i + .2) {
$data->addPoints(log($i + 1) * 10, 'Bounds 1');
$data->addPoints(log($i + 3) * 10 + rand(0, 2) - 1, 'Probe');
$data->addPoints(log($i + 6) * 10, 'Bounds 2');
$data->addPoints($i * 10, 'Labels');
}
$data->setAxisName(0, 'Size (cm)');
$data->setSerieDescription('Labels', 'Months');
$data->setAbscissa('Labels');
$data->setAbscissaName('Time (years)');
$image = new Image(700, 230, $data);
$image->Antialias = false;
$image->drawRectangle(0, 0, 699, 229, ['R' => 0, 'G' => 0, 'B' => 0]);
$image->setFontProperties(['FontName' => 'Forgotte.ttf', 'FontSize' => 11]);
$image->drawText(
150,
35,
'Size by time generations',
['FontSize' => 20, 'Align' => TEXT_ALIGN_BOTTOMMIDDLE]
);
$image->setFontProperties(['FontName' => 'pf_arma_five.ttf', 'FontSize' => 6]);
$image->setGraphArea(40, 40, 680, 200);
$scaleSettings = [
'LabelSkip' => 4, 'XMargin' => 10, 'YMargin' => 10, 'Floating' => true,
'GridR' => 200, 'GridG' => 200, 'GridB' => 200, 'DrawSubTicks' => true,
'CycleBackground' => true
];
$image->drawScale($scaleSettings);
$image->Antialias = true;
$image->drawZoneChart('Bounds 1', 'Bounds 2');
$data->setSerieDrawable(['Bounds 1', 'Bounds 2'], false);
$image->drawStepChart();
$image->drawLegend(640, 20, ['Style' => LEGEND_NOBORDER, 'Mode' => LEGEND_HORIZONTAL]);
$filename = $this->tester->getOutputPathForChart('drawZone.png');
$image->render($filename);
$image->stroke();
$this->tester->seeFileFound($filename);
}
}