Skip to content

Commit

Permalink
- small refactor for loading charts via factory
Browse files Browse the repository at this point in the history
  • Loading branch information
szymach committed Jun 12, 2014
1 parent 897fec1 commit 4c9923d
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 12 deletions.
21 changes: 14 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ to functions.

- Added a factory service for loading the classes.

- Moved all constants to a single file 'src/Resources/data/configuration.php'. This file is *required*
- Moved all constants to a single file 'src/Resources/data/constants.php'. This file is *required*
for the library to function. If you use the factory class, the file is loaded automatically.

How to install it?
Expand All @@ -36,7 +36,7 @@ For composer installation, add:
> },
to your composer.json file and update your dependencies. After that, all
classes are available under "CpChart\Classes" namespace (or "CpChart\Services")
classes are available under "CpChart\Classes" namespace or "CpChart\Services"
for the factory.

How to use it?
Expand All @@ -61,11 +61,16 @@ or use the provided factory. An example below.
// create the image and set the data
$myPicture = $factory->newImage(700, 230, $myData);
$myPicture->setGraphArea(60, 40, 670, 190);
$myPicture->setFontProperties(array(
"FontName"=>"Forgotte.ttf",
"FontSize"=>11)
$myPicture->setFontProperties(
array(
"FontName" => "Forgotte.ttf",
"FontSize" => 11
)
);
// creating a pie chart - notice that you specify the type of chart, not class name
$pieChart = $factory->newChart("pie", $myPicture, $myData);

// do the drawing
$myPicture->drawScale();
$myPicture->drawSplineChart();
Expand All @@ -86,9 +91,11 @@ than the default, you need to add the full path to the file (ex. __DIR__.'/folde

Changelog
=========
1.0 Stable version with basic functionality
1.0 Stable version with basic functionality.

1.1 Added factory service.

1.1 Added factory service
1.1.1 Changed chart loading via factory a bit (see class annotations)

References
==========
Expand Down
5 changes: 3 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@
"license": "MIT",
"type": "project",
"description": "Port of \"pChart\" library into PHP5 standards with composer.phar support.",
"keywords": ["pChart","composer","statistics","charts", "c-pChart", "pchart"],
"keywords": ["pChart","composer","statistics","charts", "c-pChart", "c-pchart", "pchart"],
"homepage": "https://github.com/szymach/c-pchart",
"autoload": {
"psr-4": { "CpChart\\": "src/" }
},
"require": {
"php": ">=5.3.3"
}
},
"version": "1.1.1"
}
6 changes: 3 additions & 3 deletions src/Services/pChartFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,17 @@ class pChartFactory
* pBubble, pPie, pScatter, pStock, pSurface and pIndicator. Otherwise the
* pChartObject and pDataObject parameters are redundant.
*
* @param string $chartName - name of the class to be loaded
* @param string $chartType - type of the chart to be loaded (for example 'pie', not 'pPie')
* @param \CpChart\Classes\pImage $pChartObject
* @param \CpChart\Classes\pData $pDataObject
* @return \CpChart\Classes\$chartName
*/
public function newChart(
$chartName,
$chartType,
pImage $pChartObject = null,
pData $pDataObject = null
) {
$className = $this->namespace.$chartName;
$className = $this->namespace.'p'.ucfirst($chartType);
return new $className($pChartObject, $pDataObject);
}

Expand Down

0 comments on commit 4c9923d

Please sign in to comment.