3
require_once($ADEI_ROOTDIR . "/classes/jpgraph.php");
5
abstract class BASEHistogramView extends VIEW {
6
function __construct(REQUEST $req = NULL, $options) {
7
parent::__construct($req, $options);
9
$this->num_bins = $this->GetOption('bins', array(0));
10
$this->min_width = $this->GetOption('min_width', 300);
11
$this->min_height = $this->GetOption('min_height', 300);
14
function GetHistOptions() {
16
foreach ($this->num_bins as $bin) {
17
array_push($bins, array("value" => $bin, "label" => ($bin?$bin:"Auto")));
20
$checkboxNorm = array("label" => _("Normalize"), "id" => "hist_norm");
21
if ($this->req->GetProp("view_hist_norm", 0)) $checkboxNorm["checked"] = "checked";
23
$checkboxGFit = array("label" => _("Gaussian Fit"), "id" => "hist_fit");
24
if ($this->req->GetProp("view_hist_fit", 0)) $checkboxGFit["checked"] = "checked";
27
array("select" => array("id" => "bins" , "label" => _("Bins"), "options" => $bins)),
28
array("xml"=>"<br/>"),
29
array("checkbox" => $checkboxNorm),
30
array("checkbox" => $checkboxGFit),
34
function GetHistView(&$x) {
38
throw new ADEIException(translate("No data found"));
40
$tmp_file = ADEI::GetTmpFile();
42
$width = $this->width;
43
$height = $this->height;
45
$bins = $this->req->GetProp("view_bins", 0);
46
if (!$bins) $bins = ceil(sqrt(sizeof($x)));
48
$norm = $this->req->GetProp("view_hist_norm", 0);
49
$fit = $this->req->GetProp("view_hist_fit", 0);
53
$step = ($max - $min) / $bins;
55
$coef = $norm?(1/($step * sizeof($x))):1;
57
$h = array_fill(0, $bins, 0);
58
foreach ($x as $val) {
59
$idx = ($val - $min)/$step;
60
if ($idx == $bins) $idx--;
65
for($i = 0 ; $i < $bins ; $i++)
66
array_push($t, sprintf("%3.1e", $min + $i*$step));
68
$graph = new Graph($width,$height);
69
$graph->SetTickDensity(TICKD_SPARSE, TICKD_SPARSE);
70
$graph->img->SetMargin(55,5,10,20);
72
$graph->SetScale("textlin");
73
$graph->xaxis->SetPos("min");
74
$graph->yaxis->SetPos("min");
75
$graph->xaxis->SetFont(FF_ARIAL,FS_NORMAL,8);
76
$graph->yaxis->SetFont(FF_ARIAL,FS_NORMAL,8);
77
$graph->xaxis->title->SetFont(FF_ARIAL,FS_BOLD);
78
$graph->yaxis->title->SetFont(FF_ARIAL,FS_BOLD);
80
if($bins > 8) $graph->xaxis->SetTextLabelInterval(ceil(($bins / 6)));
81
$graph->xaxis->SetTickLabels($t);
83
$bplot = new BarPlot($h);
88
$graph->yaxis->scale->SetGrace(14);
90
$mean = array_sum($x)/sizeof($x);
91
$stddev = stats_standard_deviation($x);
92
$var = stats_variance($x);
94
$re = 100 * $sigma/$mean;
98
$median = $x[(sizeof($x) - 1)/2];
100
$median = ($x[sizeof($x)/2 - 1] + $x[sizeof($x)/2])/2;
106
if ($norm) $coef = (1/(sqrt(2 * pi() * $var)));
107
else $coef = ((sizeof($x)*$step)/(sqrt(2 * pi() * $var)));
110
for($i = 0; $i <= $bins; $i++) {
111
$offset = $i * $step;
112
$y = $coef * exp(-pow($min + $offset - $mean, 2)/(2*$var));
113
array_push($xdata, $i);
114
array_push($ydata, $y);
115
$xi2 += (pow($y - $h[$i], 2)) / $y;
119
$lineplot = new LinePlot($ydata , $xdata);
120
$graph->Add($lineplot);
123
$char_sigma = SymChar::Get('sigma', false);
125
$graph->Stroke("$TMP_PATH/$tmp_file");
129
array("img" => array("id" => $tmp_file)),
130
array("info" => array(
131
array("title"=>_("Bins"), "value" => $bins),
132
array("title"=>_("First Bin"), "value" => $min),
133
array("title"=>_("Last Bin"), "value" => $min + $bins * $step),
134
array("title"=>_("Mean"), "value" => $mean),
135
array("title"=>_("Median"), "value" => $median),
136
array("title"=>_("StdDev"), "value" => $stddev),
137
array("title"=>_("Sigma"), "value" => $sigma),
138
array("title"=>_("RE"), "value" => ($re . "%")),
142
array_push($res[1]["info"], array("title"=>_("xi2"), "value" => $xi2));
147
"img" => array("id" => $tmp_file)
b'\\ No newline at end of file'