PageRenderTime 48ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 0ms

/common/lib/Form/Class.ElemGraph.inc.php

https://github.com/xrg/a2billing
PHP | 691 lines | 575 code | 73 blank | 43 comment | 65 complexity | 5c24e346c87e018c252e5f16fb93ae9d MD5 | raw file
Possible License(s): AGPL-1.0
  1. <?php
  2. require_once(DIR_COMMON."jpgraph_lib/jpgraph.php");
  3. /** This class collects data from other ElemBase objects through
  4. their RenderSpecial().
  5. */
  6. abstract class DataObj{
  7. public $code;
  8. public function DataObj($co){
  9. $this->code=$co;
  10. }
  11. abstract function debug($str);
  12. /** Get the data from that (db) row into the object.
  13. This is a generic way to parse a query result into
  14. the internal arrays of this structure. */
  15. abstract function PlotRow(array $row);
  16. /** Returns if the fetch query should feed this with raw data, too */
  17. public function NeedRaw() {
  18. return false;
  19. }
  20. /** Initialize some internal structures according to plot, query rows
  21. \param plot an array with plot settings. 'x', 'y' will be used
  22. \param res the provided query fields. An array with string names
  23. of each query row field.
  24. */
  25. abstract function prepare(array $plot, array $resfs);
  26. };
  27. /** Store in array the diff of x, end(array), by date mode
  28. This helps in date graphs, where we don't need to repeat the date
  29. all the time (noisy).
  30. */
  31. function putdiffX(array &$data, $new,$dateMode){
  32. if ($dateMode)
  33. $new = trim($new);
  34. if ($dateMode && !empty($data)){
  35. $lastdate = null;
  36. for($i = count($data);$i>0; $i--)
  37. if (($p = strpos($data[$i-1],' '))!==false){
  38. $lastdate = substr($data[$i-1],0,$p);
  39. break;
  40. }
  41. if (!empty($lastdate)){
  42. if (substr($new,0, strlen($lastdate)) == $lastdate)
  43. $new= substr($new,strlen($lastdate)+1);
  44. }
  45. }
  46. $data[] = $new;
  47. }
  48. /** Intermediate class for data that only has 2 or 3 dimensions */
  49. abstract class DataObjXY extends DataObj{
  50. protected $xkey;
  51. protected $xrkey;
  52. protected $ykey;
  53. protected $yrkey;
  54. public function prepare(array $plot, array $resfs){
  55. $this->xrkey = $this->xkey = $plot['x'];
  56. $this->yrkey = $this->ykey = $plot['y'];
  57. if (empty($this->xkey) || empty($this->ykey))
  58. throw new Exception('Cannot locate x/y keys in plot settings');
  59. if (!in_array($this->xkey,$resfs))
  60. throw new Exception('Query row doesn\'t have x data');
  61. if (!in_array($this->ykey,$resfs))
  62. throw new Exception('Query row doesn\'t have y data');
  63. if (in_array($this->xkey.'_raw',$resfs))
  64. $this->xrkey=$this->xkey.'_raw';
  65. if (in_array($this->ykey.'_raw',$resfs))
  66. $this->yrkey=$this->ykey.'_raw';
  67. }
  68. };
  69. abstract class DataObjX2Y extends DataObj{
  70. protected $xkey;
  71. protected $xrkey;
  72. protected $ykey;
  73. protected $yrkey;
  74. protected $x2key;
  75. protected $x2rkey;
  76. public function prepare(array $plot, array $resfs){
  77. $this->xrkey = $this->xkey = $plot['x'];
  78. $this->yrkey = $this->ykey = $plot['y'];
  79. $this->x2rkey = $this->x2key = $plot['x2'];
  80. if (isset($plot['x2t']))
  81. $this->x2key=$plot['x2t'];
  82. if (empty($this->xkey) || empty($this->x2key)|| empty($this->ykey))
  83. throw new Exception('Cannot locate x/y keys in plot settings');
  84. if (!in_array($this->xkey,$resfs))
  85. throw new Exception('Query row doesn\'t have x data');
  86. if (!in_array($this->ykey,$resfs))
  87. throw new Exception('Query row doesn\'t have y data');
  88. if (in_array($this->xkey.'_raw',$resfs))
  89. $this->xrkey=$this->xkey.'_raw';
  90. if (in_array($this->ykey.'_raw',$resfs))
  91. $this->yrkey=$this->ykey.'_raw';
  92. }
  93. };
  94. /** Debug version of parent, dumps the data */
  95. class DataObjXY_d extends DataObjXY {
  96. public function PlotRow(array $row){
  97. echo 'x='.htmlspecialchars($row[$this->xkey]).
  98. ', y='.htmlspecialchars($row[$this->ykey])." <br>\n";
  99. }
  100. public function debug($str){
  101. echo "$str<br>\n";
  102. }
  103. };
  104. /** Debug version of parent, dumps the data */
  105. class DataObjX2Y_d extends DataObjX2Y {
  106. public function PlotRow(array $row){
  107. echo 'x='.htmlspecialchars($row[$this->xkey]).
  108. ', x2='.htmlspecialchars($row[$this->x2key]).
  109. ', y='.htmlspecialchars($row[$this->ykey])." <br>\n";
  110. }
  111. public function debug($str){
  112. echo "$str<br>\n";
  113. }
  114. };
  115. class DataObjXYp extends DataObjXY {
  116. public $xdata=array();
  117. public $xrdata=array();
  118. public $ydata=array();
  119. public $yrdata=array();
  120. public function NeedRaw() {
  121. return true;
  122. }
  123. public function PlotRow(array $row){
  124. $this->xdata[]=$row[$this->xkey];
  125. $this->ydata[]=$row[$this->ykey];
  126. $this->xrdata[]=$row[$this->xrkey];
  127. $this->yrdata[]=$row[$this->yrkey];
  128. }
  129. public function debug($str){
  130. }
  131. };
  132. /** Class for data that only has many Y columns on one X */
  133. abstract class DataObjXYm extends DataObj{
  134. protected $xkey;
  135. protected $xrkey;
  136. protected $ykeys;
  137. protected $yrkeys;
  138. public function prepare(array $plot, array $resfs){
  139. $this->xrkey = $this->xkey = $plot['x'];
  140. $this->yrkeys = $this->ykeys = $plot['yr'];
  141. if (empty($this->xkey) || empty($this->ykeys))
  142. throw new Exception('Cannot locate x/y keys in plot settings');
  143. if (!in_array($this->xkey,$resfs))
  144. throw new Exception('Query row doesn\'t have x data');
  145. if (in_array($this->xkey.'_raw',$resfs))
  146. $this->xrkey=$this->xkey.'_raw';
  147. foreach ($this->ykeys as $n => $key){
  148. if (!in_array($key,$resfs))
  149. throw new Exception('Query row doesn\'t have y data for '.$key);
  150. if (in_array($key.'_raw',$resfs))
  151. $this->yrkeys[$n]=$key.'_raw';
  152. }
  153. }
  154. };
  155. /** A data object which holds sets of y-data in x2 groups
  156. */
  157. class DataObjX2Yp extends DataObjX2Y {
  158. public $xdata=array();
  159. public $xrdata=array();
  160. public $yzdata=array();
  161. public $x2data=array(); // assoc x2r ->x2 title
  162. public $dateMode = False;
  163. public function NeedRaw() {
  164. return true;
  165. }
  166. public function PlotRow(array $row){
  167. if (empty($this->xrdata) || (end($this->xrdata) != $row[$this->xrkey])){
  168. $this->xrdata[] = $row[$this->xrkey];
  169. putdiffX($this->xdata,$row[$this->xkey],$this->dateMode);
  170. }
  171. if (!isset($this->yzdata[$row[$this->x2rkey]])){
  172. $this->yzdata[$row[$this->x2rkey]]=array();
  173. $this->x2data[$row[$this->x2rkey]]=$row[$this->x2key];
  174. }
  175. end($this->xdata);
  176. $this->yzdata[$row[$this->x2rkey]][key($this->xdata)] = $row[$this->yrkey];
  177. foreach ($this->yzdata as $zkey => $yzdata){
  178. if (!isset($this->yzdata[$zkey][key($this->xdata)]))
  179. $this->yzdata[$zkey][key($this->xdata)] = 0;
  180. }
  181. }
  182. public function debug($str){
  183. }
  184. };
  185. class DataObjXYmp extends DataObjXYm {
  186. public $xdata=array();
  187. public $xrdata=array();
  188. public $ydata=null;
  189. public $yrdata=null;
  190. public $dateMode = False;
  191. public function NeedRaw() {
  192. return true;
  193. }
  194. public function PlotRow(array $row){
  195. putdiffX($this->xdata,$row[$this->xkey],$this->dateMode);
  196. $this->xrdata[]=$row[$this->xrkey];
  197. if ($this->ydata==null){
  198. $this->ydata=array();
  199. $this->yrdata=array();
  200. foreach($this->ykeys as $n => $key){
  201. $this->ydata[$n]=array();
  202. $this->yrdata[$n]=array();
  203. }
  204. }
  205. foreach($this->ykeys as $n => $key){
  206. $this->ydata[$n][]=$row[$key];
  207. $this->yrdata[$n][]=$row[$this->yrkeys[$n]];
  208. }
  209. }
  210. public function debug($str){
  211. }
  212. };
  213. class DataObjXYm_d extends DataObjXYm {
  214. private $first_row=false;
  215. public function PlotRow(array $row){
  216. /*if (!$this->first_row){
  217. echo " Ykeys: ".print_r($this->ykeys,true) .
  218. ", yrkeys=". print_r($this->yrkeys,true) ."<br>\n";
  219. $this->first_row=true;
  220. }*/
  221. echo 'x='.htmlspecialchars($row[$this->xkey]);
  222. foreach($this->ykeys as $n => $key)
  223. echo ", y".$n."=" . htmlspecialchars($row[$key]);
  224. echo " <br>\n";
  225. }
  226. public function debug($str){
  227. echo "$str<br>\n";
  228. }
  229. };
  230. /** A view that renders itself into a graph.
  231. This view will call some other view of the form, in order to fetch
  232. the data from it (using its RenderSpecial).
  233. */
  234. class GraphView extends FormView {
  235. public $view;
  236. public $code;
  237. public $parms = array();
  238. /** This will hold every style-related info. At first, the array
  239. is initted with some dummy default data, and then it will be overriden
  240. by setting the style of the graph */
  241. public $styles;
  242. public $gr_sty;
  243. function GraphView($vi, $co, $sty=null){
  244. $this->view=$vi;
  245. $this->code=$co;
  246. $this->gr_sty=$sty;
  247. }
  248. public function RenderHeaderGraph (&$form, &$robj){
  249. }
  250. public function RenderGraph (&$form, &$robj){
  251. // For debugging purposes
  252. $data = new DataObjXYp($this->code);
  253. print_r ($data);
  254. }
  255. /** Compute the stylesheet for this object.
  256. Unfortunately this has to be called later than the initializer, because
  257. default GRAPH_STYLES are defined in PP_graph.inc.php, much later than $this.
  258. */
  259. protected function apply_styles(){
  260. if (!empty($this->styles))
  261. return ; // already set, nothing to do.
  262. global $GRAPH_STYLES;
  263. $defaults = array( width => 500, height => 300,
  264. setscale => 'textlin', xsetgrace => 3, ysetgrace => 3,
  265. setframe => true, margin => array('35', '35', '15', '35'),
  266. rowcolor => false, bggradient => false,
  267. maxxticks => 20,
  268. colors =>array('red','blue','green','magenta','yellow'),
  269. 'accumplot-options' => array (
  270. color => array ('yellow@0.3', 'purple@0.3', 'green@0.3', 'blue@0.3', 'red@0.3')));
  271. if (!empty($this->gr_sty) && isset($GRAPH_STYLES[$this->gr_sty]))
  272. $sty2=$GRAPH_STYLES[$this->gr_sty];
  273. elseif (empty($this->gr_sty) && isset($GRAPH_STYLES[0]))
  274. $sty2=$GRAPH_STYLES[0];
  275. else $sty2=array();
  276. $this->styles=array_merge($defaults,$sty2,$this->parms);
  277. }
  278. public function RenderSpecial($rmode,&$form, &$robj){
  279. $this->apply_styles();
  280. if ($rmode=='create-graph'){
  281. $this -> RenderHeaderGraph($form, $robj);
  282. $this -> RenderHeadSpecial($form, $robj);
  283. }
  284. elseif ($rmode=='graph'){
  285. $this -> RenderGraph($form, $robj);
  286. }
  287. }
  288. public function RenderHeadSpecial(&$form, &$robj){
  289. //print_r ($this->styles);
  290. if (!empty($this->styles['setscale']))
  291. $robj->SetScale($this->styles['setscale']);
  292. if (is_array($this->styles['margin']) && count($this->styles['margin'])==4)
  293. $robj->SetMargin($this->styles['margin'][0],$this->styles['margin'][1],$this->styles['margin'][2],$this->styles['margin'][3]);
  294. if (!$this->styles['setframe'])
  295. $robj->SetFrame(false);
  296. if (! empty($form->views[$this->view]->plots[$this->code]['title'])){
  297. $robj->title->Set($form->views[$this->view]->plots[$this->code]['title']);
  298. $robj->title->SetFont(FF_DEJAVU);
  299. }
  300. if (! empty($form->views[$this->view]->plots[$this->code]['subtitles'])){
  301. $robj->tabtitle->Set($form->views[$this->view]->plots[$this->code]['subtitles']);
  302. $robj->tabtitle->SetWidth(TABTITLE_WIDTHFULL);
  303. $robj->tabtitle->SetFont(FF_DEJAVU);
  304. }
  305. if ($this->styles['bggradient'])
  306. if ($this->styles['bggradient']['show'])
  307. if (is_array($this->styles['bggradient']['params']) && count($this->styles['bggradient']['params'])==4){
  308. $robj->SetBackgroundGradient($this->styles['bggradient']['params'][0],
  309. $this->styles['bggradient']['params'][1],
  310. $this->styles['bggradient']['params'][2],
  311. $this->styles['bggradient']['params'][3]);
  312. }
  313. if (!empty($this->styles['chart-options']['xsetgrace']))
  314. $robj->yaxis->scale->SetGrace($this->styles['chart-options']['xsetgrace']);
  315. if (!empty($this->styles['chart-options']['ysetgrace']))
  316. $robj->yaxis->scale->SetGrace($this->styles['chart-options']['ysetgrace']);
  317. if ($this->styles['chart-options']['xgrid'])
  318. if ($this->styles['chart-options']['xgrid']['show'])
  319. if (is_array($this->styles['chart-options']['xgrid']['params'])){
  320. if (is_array($this->styles['chart-options']['xgrid']['params']['fill']))
  321. $robj->xgrid->SetFill(true, $this->styles['chart-options']['xgrid']['params']['fill'][0], $this->styles['chart-options']['xgrid']['params']['fill'][1]);
  322. if (!empty($this->styles['chart-options']['xgrid']['params']['color']))
  323. $robj->xgrid->SetColor($this->styles['chart-options']['xgrid']['params']['color']);
  324. if (!empty($this->styles['chart-options']['xgrid']['params']['linestyle']))
  325. $robj->xgrid->SetLineStyle($this->styles['chart-options']['xgrid']['params']['linestyle']);
  326. $robj->xgrid->Show(true);
  327. }
  328. if ($this->styles['chart-options']['ygrid'])
  329. if ($this->styles['chart-options']['ygrid']['show'])
  330. if (is_array($this->styles['chart-options']['ygrid']['params'])){
  331. if (is_array($this->styles['chart-options']['ygrid']['params']['fill']))
  332. $robj->ygrid->SetFill(true, $this->styles['chart-options']['ygrid']['params']['fill'][0], $this->styles['chart-options']['ygrid']['params']['fill'][1]);
  333. if (!empty($this->styles['chart-options']['ygrid']['params']['color']))
  334. $robj->ygrid->SetColor($this->styles['chart-options']['ygrid']['params']['color']);
  335. if (!empty($this->styles['chart-options']['ygrid']['params']['linestyle']))
  336. $robj->ygrid->SetLineStyle($this->styles['chart-options']['ygrid']['params']['linestyle']);
  337. $robj->ygrid->Show(true);
  338. }
  339. }
  340. /** For debugging purposes, this function simulates the
  341. graph procedure but only renders the results into html text */
  342. function Render(&$form){
  343. if(!$form->FG_DEBUG)
  344. return true;
  345. $this->apply_styles();
  346. ?>
  347. <div class="debug">
  348. Here we are: debugging FormDataView
  349. <br>
  350. <?php
  351. $graph=null;
  352. $this->RenderSpecial('create-graph',$form,$graph);
  353. if ($graph instanceof Graph)
  354. echo "Created a graph object <br>\n";
  355. unset($graph);
  356. echo "Using view ".$this->view.", code=".$this->code." <br>\n";
  357. if (!isset($form->views[$this->view])){
  358. echo "View doesn't exist!!\n";
  359. echo "</div>";
  360. return false;
  361. }
  362. ?>
  363. </div>
  364. <div class="debug">
  365. Style:
  366. <?= nl2br(htmlspecialchars(print_r($this->styles,true))) ?>
  367. </div>
  368. <div class="debug">
  369. <?php
  370. if ($this instanceof AccumBarView)
  371. $dobj=new DataObjX2Y_d($this->code);
  372. else if ($this instanceof Line2View)
  373. $dobj=new DataObjXYm_d($this->code);
  374. else
  375. $dobj=new DataObjXY_d($this->code);
  376. $form->views[$this->view]->RenderSpecial('get-data',$form,$dobj);
  377. ?>
  378. Render end.
  379. </div>
  380. <?php
  381. }
  382. };
  383. class LineView extends GraphView {
  384. public function RenderHeaderGraph (&$form, &$robj){
  385. require_once(DIR_COMMON."jpgraph_lib/jpgraph_line.php");
  386. $robj = new Graph($this->styles['width'],$this->styles['height'],"auto");
  387. $robj->legend->SetFont(FF_DEJAVU);
  388. }
  389. public function RenderGraph (&$form, &$robj){
  390. $data = new DataObjXYp($this->code);
  391. $form->views[$this->view]->RenderSpecial('get-data',$form,$data);
  392. if (! empty($this->styles['chart-options']['xlabelangle'])){
  393. $robj->xaxis->SetLabelAngle($this->styles['chart-options']['xlabelangle']);
  394. if ($this->styles['chart-options']['xlabelangle']<0)
  395. $robj->xaxis->SetLabelAlign('left');
  396. }
  397. {
  398. $font=$this->styles['chart-options']['xlabelfont'];
  399. if (empty($font))
  400. $font = FF_DEJAVU;
  401. $fontstyle= $this->styles['chart-options']['xlabelfontstyle'];
  402. if (empty($fontstyle))
  403. $fontstyle = FS_NORMAL;
  404. $fontsize= $this->styles['chart-options']['xlabelfontsize'];
  405. if (empty($fontsize))
  406. $fontsize = 8;
  407. $robj->xaxis->SetFont($font,$fontstyle,$fontsize);
  408. }
  409. $robj->xaxis->SetTickLabels($data->xdata);
  410. if (count($data->xdata)> $this->styles['maxxticks']+5)
  411. $robj->xaxis->SetTextTickInterval(count($data->xdata)/$this->styles['maxxticks']);
  412. $plot = new LinePlot($data->yrdata);
  413. // TODO: use ydata for y-labels
  414. if (! empty($this->styles['plot-options']['setfillcolor']))
  415. $plot->SetFillColor($this->styles['plot-options']['setfillcolor']);
  416. if (! empty($this->styles['plot-options']['setcolor']))
  417. $plot ->SetColor($this->styles['plot-options']['setcolor']);
  418. $robj->Add($plot);
  419. }
  420. };
  421. /** Multiple lines in one graph */
  422. class Line2View extends GraphView {
  423. public function RenderHeaderGraph (&$form, &$robj){
  424. require_once(DIR_COMMON."jpgraph_lib/jpgraph_line.php");
  425. $robj = new Graph($this->styles['width'],$this->styles['height'],"auto");
  426. $robj->legend->SetFont(FF_DEJAVU);
  427. }
  428. public function RenderGraph (&$form, &$robj){
  429. $data = new DataObjXYmp($this->code);
  430. if ($form->views[$this->view]->plots[$this->code]['x_datemode'])
  431. $data->dateMode=True;
  432. $form->views[$this->view]->RenderSpecial('get-data',$form,$data);
  433. $robj->xaxis->SetPos('auto');
  434. if (! empty($this->styles['chart-options']['xlabelangle'])){
  435. $robj->xaxis->SetLabelAngle($this->styles['chart-options']['xlabelangle']);
  436. if ($this->styles['chart-options']['xlabelangle']<0)
  437. $robj->xaxis->SetLabelAlign('left');
  438. }
  439. {
  440. $font=$this->styles['chart-options']['xlabelfont'];
  441. if (empty($font))
  442. $font = FF_DEJAVU;
  443. $fontstyle= $this->styles['chart-options']['xlabelfontstyle'];
  444. if (empty($fontstyle))
  445. $fontstyle = FS_NORMAL;
  446. $fontsize= $this->styles['chart-options']['xlabelfontsize'];
  447. if (empty($fontsize))
  448. $fontsize = 8;
  449. $robj->xaxis->SetFont($font,$fontstyle,$fontsize);
  450. }
  451. $robj->xaxis->SetTickLabels($data->xdata);
  452. if (count($data->xdata)> $this->styles['maxxticks']+5)
  453. $robj->xaxis->SetTextTickInterval(count($data->xdata)/$this->styles['maxxticks']);
  454. $fillcols= $this->styles['plot-options']['fillcolors'];
  455. if (empty($fillcols))
  456. $fillcols=array();
  457. $colors=$this->styles['plot-options']['linecolors'];
  458. if (empty($colors))
  459. $colors=array();
  460. $bplots=array();
  461. $yrkeys=$form->views[$this->view]->plots[$this->code]['yr'];
  462. foreach ($yrkeys as $n => $key){
  463. $bplots[] = new LinePlot($data->yrdata[$n]/*,$data->xrdata*/);
  464. // TODO: use ydata for y-labels
  465. if(!empty($fillcols[$n]))
  466. end($bplots)->SetFillColor($fillcols[$n]);
  467. if(!empty($colors[$n]))
  468. end($bplots)->SetColor($colors[$n]);
  469. //TODO: legend
  470. $robj->Add(end($bplots));
  471. }
  472. }
  473. };
  474. class BarView extends GraphView {
  475. public function RenderHeaderGraph (&$form, &$robj){
  476. require_once(DIR_COMMON."jpgraph_lib/jpgraph_bar.php");
  477. $robj = new Graph($this->styles['width'],$this->styles['height'],"auto");
  478. $robj->legend->SetFont(FF_DEJAVU);
  479. }
  480. public function RenderGraph (&$form, &$robj){
  481. $data = new DataObjXYp($this->code);
  482. $form->views[$this->view]->RenderSpecial('get-data',$form,$data);
  483. if (! empty($this->styles['chart-options']['xlabelangle'])){
  484. $robj->xaxis->SetLabelAngle($this->styles['chart-options']['xlabelangle']);
  485. if ($this->styles['chart-options']['xlabelangle']<0)
  486. $robj->xaxis->SetLabelAlign('left');
  487. }
  488. if (! empty($this->styles['chart-options']['xlabelfont']))
  489. $robj->xaxis->SetFont($this->styles['chart-options']['xlabelfont']);
  490. else
  491. $robj->xaxis->SetFont(FF_DEJAVU);
  492. $robj->xaxis->SetTickLabels($data->xdata);
  493. $plot = new BarPlot($data->yrdata);
  494. // TODO: use ydata for labels
  495. if (! empty($this->styles['plot-options']['setfillcolor']))
  496. $plot->SetFillColor($this->styles['plot-options']['setfillcolor']);
  497. if (! empty($this->styles['plot-options']['setcolor']))
  498. $plot ->SetColor($this->styles['plot-options']['setcolor']);
  499. $robj->Add($plot);
  500. }
  501. };
  502. // accumulated bar plots
  503. class AccumBarView extends GraphView {
  504. public function RenderHeaderGraph (&$form, &$robj){
  505. require_once(DIR_COMMON."jpgraph_lib/jpgraph_bar.php");
  506. $robj = new Graph($this->styles['width'],$this->styles['height'],"auto");
  507. $robj->legend->SetFont(FF_DEJAVU);
  508. }
  509. public function RenderGraph (&$form, &$robj){
  510. $data = new DataObjX2Yp($this->code);
  511. $form->views[$this->view]->RenderSpecial('get-data', $form, $data);
  512. if (! empty($this->styles['chart-options']['xlabelangle'])){
  513. $robj->xaxis->SetLabelAngle($this->styles['chart-options']['xlabelangle']);
  514. if ($this->styles['chart-options']['xlabelangle']<0)
  515. $robj->xaxis->SetLabelAlign('left');
  516. }
  517. if (! empty($this->styles['chart-options']['xlabelfont']))
  518. $robj->xaxis->SetFont($this->styles['chart-options']['xlabelfont']);
  519. else
  520. $robj->xaxis->SetFont(FF_DEJAVU);
  521. $robj->xaxis->SetTickLabels($data->xdata);
  522. $i=0;
  523. foreach($data->yzdata as $ykey => $ycol){
  524. $accplots[]= new BarPlot($ycol);
  525. if (is_array($this->styles['accumplot-options']['color']))
  526. end($accplots)->SetFillColor($this->styles['accumplot-options']['color'][$i++]);
  527. if (!empty($obj_leg->legend[$ykey]))
  528. end($accplots)->SetLegend($obj_leg->legend[$ykey]);
  529. else
  530. end($accplots)->SetLegend(_("(none)"));
  531. }
  532. $plot = new AccBarPlot($accplots);
  533. if (! empty($this->styles['plot-options']['setfillcolor']))
  534. $plot->SetFillColor($this->styles['plot-options']['setfillcolor']);
  535. if (! empty($this->styles['plot-options']['setcolor']))
  536. $plot ->SetColor($this->styles['plot-options']['setcolor']);
  537. $robj->Add($plot);
  538. }
  539. };
  540. class PieView extends GraphView {
  541. public function RenderHeaderGraph (&$form, &$robj){
  542. require_once(DIR_COMMON."jpgraph_lib/jpgraph_pie.php");
  543. require_once(DIR_COMMON."jpgraph_lib/jpgraph_pie3d.php");
  544. $robj = new PieGraph($this->styles['width'],$this->styles['height'],"auto");
  545. $robj->legend->SetFont(FF_DEJAVU);
  546. }
  547. public function RenderGraph (&$form, &$robj){
  548. $data = new DataObjXYp($this->code);
  549. $form->views[$this->view]->RenderSpecial('get-data',$form,$data);
  550. $pieplot = new PiePlot3D($data->yrdata);
  551. if (is_array($this->styles['pie-options'])){
  552. if (! empty($this->styles['pie-options']['explodeslice']))
  553. $pieplot->ExplodeSlice($this->styles['pie-options']['explodeslice']);
  554. if (! empty($this->styles['pie-options']['setcenter']))
  555. $pieplot->SetCenter($this->styles['pie-options']['setcenter']);
  556. }
  557. $pieplot->SetLegends(array_reverse($data->xdata));
  558. $robj->Add($pieplot);
  559. }
  560. };