-
Notifications
You must be signed in to change notification settings - Fork 8
/
create.histograms.php
80 lines (49 loc) · 2.21 KB
/
create.histograms.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
<?php
/**
* Render the csv file as an histogram
* @var unknown
*/
define('FPATH' , __DIR__.DIRECTORY_SEPARATOR."libs".DIRECTORY_SEPARATOR."pChart2.1.4");
include(FPATH."/class/pDraw.class.php");
include(FPATH."/class/pImage.class.php");
include(FPATH."/class/pData.class.php");
define('ADJDEBUG' , TRUE);
$prefix = "logos";
if(count($argv) > 1 ){
$prefix = $argv[1];
}
chdir($prefix); // change to the required dir
$currentDir = getcwd(); // where am i , test, validate or test
$folder = "folder.csv".DIRECTORY_SEPARATOR;
$output_folder = "folder.histogram".DIRECTORY_SEPARATOR;
//$outputDir = $currentDir.DIRECTORY_SEPARATOR.$outputKey;
$i= 0;
$allFiles = glob($folder."*.*", GLOB_NOSORT);
foreach( $allFiles as $aFile){
$pInfo = pathinfo($aFile);
$fPath = realpath($output_folder); // get thhe path to file
$newPath = $fPath.DIRECTORY_SEPARATOR.strtolower($pInfo['filename']).".png"; // rename to .csv first
$myData = new pData();
$Options["GotHeader"] = TRUE;
$Options["SkipColumns"] = array(0);
$Options["DefaultSerieName"] = strtolower($pInfo['filename']);
$myData->importFromCSV($aFile,$Options);
$myData->loadPalette(FPATH.DIRECTORY_SEPARATOR."palettes/blind.color",TRUE);
/* Create a pChart object and associate your dataset */
$myPicture = new pImage(700,230,$myData);
$myPicture->setFontProperties(array("FontName"=>FPATH."/fonts/verdana.ttf","FontSize"=>11));
$myPicture->drawText(280,30,strtolower($pInfo['filename']),array("R"=>32,"G"=>32,"B"=>32));
/* Choose a nice font */
$myPicture->setFontProperties(array("FontName"=>FPATH."/fonts/Forgotte.ttf","FontSize"=>11));
/* Define the boundaries of the graph area */
$myPicture->setGraphArea(60,40,670,190);
/* Draw the scale, keep everything automatic */
$scaleSettings = array("DrawSubTicks"=>FALSE,'RemoveXAxis'=>TRUE);
$myPicture->drawScale($scaleSettings);
/* Draw the scale, keep everything automatic */
$myPicture->drawBarChart(array("DisplayValues"=>FALSE,"DisplayColor"=>DISPLAY_AUTO,"Rounded"=>FALSE,"Surrounding"=>NULL,"OverrideSurrounding"=>FALSE,"Interleave"=>0));
$myPicture->autoOutput($newPath);
echo "Process - ",$i++,"\r";
unset($myData);
unset($myPicture);
}