25 public static $PIE=
'PIE';
26 public static $HISTO=
'HISTO';
27 public static $LINES=
'LINES';
28 public static $BAR=
'BAR';
34 public function __construct($sType,$iWidth=null,$iHeight=null){
35 $this->iWidth=$iWidth;
36 $this->iHeight=$iHeight;
38 if($sType==self::$PIE){
40 }
else if($sType==self::$HISTO){
42 }
else if($sType==self::$LINES){
44 }
else if($sType==self::$BAR){
47 throw new Exception(
'sType non reconnu, attendu: (PIE,HISTO,LINES,BAR)');
57 $this->oChart->setData($tData);
66 return $this->oChart->show();
69 public function addGroup($sLabel,$sColor){
70 $this->oChart->addGroup($sLabel,$sColor);
72 public function addPoint($x,$y){
73 $this->oChart->addPoint($x,$y);
76 public function setMarginLeft($x){
77 $this->oChart->setMarginLeft($x);
79 public function setMaxX($x){
80 $this->oChart->setMaxX($x);
82 public function setMinX($x){
83 $this->oChart->setMinX($x);
85 public function setMaxY($x){
86 $this->oChart->setMaxY($x);
88 public function setMinY($x){
89 $this->oChart->setMinY($x);
91 public function addMarkerY($y,$color=
'#ccc'){
92 $this->oChart->addMarkerY($y,$color);
94 public function setPaddingX($padding){
95 $this->oChart->setPaddingX($padding);
97 public function setPaddingY($padding){
98 $this->oChart->setPaddingY($padding);
100 public function setGridY($y,$color){
101 $this->oChart->setGridY($y,$color);
103 public function setTextSizeLegend($size){
104 $this->oChart->setTextSizeLegend($size);
106 public function setCoordLegend($x,$y){
107 $this->oChart->setCoordLegend($x,$y);
109 public function setStepX($stepX){
110 $this->oChart->setStepX($stepX);
112 public function setStepY($stepY){
113 $this->oChart->setStepY($stepY);
124 public static $uid=0;
133 protected $iMarginLeft;
139 protected $tMarkerY=array();
146 protected $textsizeLegend;
148 protected $legendX=200;
149 protected $legendY=50;
151 protected $stepX=null;
152 protected $stepY=null;
154 public function __construct($iWidth=null,$iHeight=null){
155 $this->iWidth=$iWidth;
156 $this->iHeight=$iHeight;
166 $this->
id=
'canvasPluginChart'.self::$uid;
168 $this->iMarginLeft=0;
169 $this->textsizeLegend=12;
173 public function setData($tData){
176 public function setColorTab($tColor){
177 $this->tColor=$tColor;
179 public function setMarginLeft($iMarginLeft){
180 $this->iMarginLeft=$iMarginLeft;
182 public function setMaxX($iMaxX){
185 public function setMinX($iMinX){
188 public function setMaxY($iMaxX){
191 public function setMinY($iMinX){
194 public function addMarkerY($y,$color=
'#444'){
195 $this->tMarkerY[]=array($y,$color);
197 public function setPaddingX($padding){
198 $this->paddingX=$padding;
200 public function setPaddingY($padding){
201 $this->paddingY=$padding;
203 public function setGridY($y,$color){
204 $this->gridY=array($y,$color);
206 public function setTextSizeLegend($size){
207 $this->textsizeLegend=$size;
209 public function setCoordLegend($x,$y){
214 public function setStepX($stepX){
217 public function setStepY($stepY){
222 public function loadCanvas(){
226 public function startScript(){
228 $this->sSvg.=
'<svg width="'.$this->iWidth.
'px" height="'.$this->iHeight.
'px"> ';
230 $this->sSvg.=
'<style>
237 public function endScript(){
238 $this->sSvg.=
'</svg>';
241 protected function rect($x,$y,$iWidth,$iHeight,$sColor,$alt=null){
242 $this->sSvg.=
'<rect class="chartRect" id="rect'.$x.$y.
'" x="'.$x.
'" y="'.$y.
'" ';
243 $this->sSvg.=
'width="'.$iWidth.
'" height="'.$iHeight.
'" style="fill:'.$sColor.
'">';
244 $this->sSvg.=
'<title>'.$alt.
'</title>';
245 $this->sSvg.=
'</rect>';
251 protected function partPie($x,$y,$diameter,$degStart,$degEnd,$sColor){
252 $this->sHtml.=
'context.fillStyle="'.$sColor.
'";'.
"\n";
253 $this->sHtml.=
'context.beginPath(); '.
"\n";
254 $this->sHtml.=
'context.arc('.$x.
','.$y.
','.$diameter.
','.$degStart.
','.$degEnd.
');'.
"\n";
255 $this->sHtml.=
'context.lineTo('.$x.
','.$y.
');'.
"\n";
256 $this->sHtml.=
'context.fill();'.
"\n";
260 $this->sSvg.=
'<path d="M'.$x.
','.$y.
' L10,10 A'.$x+($diameter/2).
','.$y+($diameter/2).
' 0 0,1 z" ';
261 $this->sSvg.=
'fill="'.$sColor.
'" />';
264 protected function text($x,$y,$sText,$sColor=
'black',$font=
'10px arial'){
265 $this->sHtml.=
'context.font="'.$font.
'";'.
"\n";
266 $this->sHtml.=
'context.fillStyle="'.$sColor.
'"; '.
"\n";
267 $this->sHtml.=
'context.fillText("'.$sText.
'",'.$x.
','.$y.
');'.
"\n";
269 $this->sSvg.=
'<text x="'.$x.
'" y="'.$y.
'" fill="'.$sColor.
'">'.$sText.
'</text>';
272 protected function lineFromTo($x,$y,$x2,$y2,$sColor=
'black',$opacity=1){
274 $this->sSvg.=
'<line x1="'.$x.
'" y1="'.$y.
'" x2="'.$x2.
'" y2="'.$y2.
'" ';
275 $this->sSvg.=
'style="stroke:'.$sColor.
';stroke-width:2" stroke-opacity="'.$opacity.
'" />';
280 public function show(){
283 foreach($this->tData as $tLine){
284 list($sLabel,$iValue)=$tLine;
289 $this->startScript();
291 $diameter=($this->iWidth/4)-10;
301 $this->sHtml.=
'context.beginPath(); '.
"\n";
302 $this->sHtml.=
'context.arc('.$x.
','.$y.
','.$diameter.
',0,Math.PI*2);'.
"\n";
306 foreach($this->tData as $j => $tLine){
307 list($sLabel,$iValue)=$tLine;
309 $pct=($iValue/$iTotal);
310 $degEnd=$pct*$degTotal;
315 $this->partPie($x,$y,$diameter,$degStart,$degEnd,$this->tColor[$j]);
321 foreach($this->tData as $i => $tLine){
322 list($sLabel,$iValue)=$tLine;
325 $y=$i*20+$this->legendY;
327 $this->rect($x,$y-8,10,10,$this->tColor[$i]);
328 $this->text($x+16,$y,$sLabel.
': '.$tPct[$i].
'%',
'#000',$this->textsizeLegend);
334 return "pas encore disponible";
344 public function show(){
346 foreach($this->tData as $tLine){
347 list($sLabel,$iValue)=$tLine;
349 if($iValue > $this->iMax){
353 $iWidthBar=($this->iWidth-200)/count($this->tData);
354 $iWidthBar=$iWidthBar*0.8;
356 $this->startScript();
359 foreach($this->tData as $j=> $tLine){
360 list($sLabel,$iValue)=$tLine;
362 $iHeight=(($iValue/$this->iMax)*($this->iHeight-24));
364 $this->rect($j*($iWidthBar+3),$this->iHeight-$iHeight,($iWidthBar),$iHeight,$this->tColor[$j],$iValue);
371 foreach($this->tData as $j => $tDetail){
375 $y=$i*20+$this->legendY;
377 $this->rect($x,$y-8,10,10,$this->tColor[$j]);
378 $this->text($x+16,$y,$sLabel,
'#000',$this->textsizeLegend);
383 $this->lineFromTo(0,0,0,$this->iHeight);
384 $this->lineFromTo(0,$this->iHeight,$this->iWidth-200,$this->iHeight);
398 public function show(){
408 foreach($this->tData as $sGroup => $tDetail){
409 foreach($tDetail[
'tPoint'] as $tPoint){
420 if($iMinX==
'' or $iMinX > $x){
423 if($iMinY==
'' or $iMinY > $y){
441 if($this->iMinY!=null){
445 if($this->paddingX ){
446 $iMinX-=$this->paddingX;
447 $iMaxX+=$this->paddingX;
449 if($this->paddingY ){
450 $iMinY-=$this->paddingY;
451 $iMaxY+=$this->paddingY;
454 $this->startScript();
456 $iHeight=$this->iHeight-10;
457 $iWidth=$this->iWidth-200-$this->iMarginLeft;
460 $step=$this->gridY[0];
461 $color=$this->gridY[1];
463 for($y=$iMinY;$y<$iMaxY;$y+=$step){
465 $y2=(1-($y-$iMinY)/($iMaxY-$iMinY))*$iHeight;
466 $this->lineFromTo($this->iMarginLeft,$y2,$this->iWidth-200,$y2,$color,0.5 );
472 foreach($this->tMarkerY as $tLineY){
474 list($y,$color)=$tLineY;
475 $y=(1-($y-$iMinY)/($iMaxY-$iMinY))*$iHeight;
477 $this->lineFromTo($this->iMarginLeft,$y,$this->iWidth-200,$y,$color,0.5 );
481 foreach($this->tData as $sGroup => $tDetail){
484 foreach($tDetail[
'tPoint'] as $j => $tPoint){
488 $x2=(($x-$iMinX)/($iMaxX-$iMinX))*$iWidth+$this->iMarginLeft;
489 $y2=(1-($y-$iMinY)/($iMaxY-$iMinY))*$iHeight;
501 $this->rect($x3,$y3,6,6,$tDetail[
'color'],$y);
504 $this->lineFromTo($lastX,$lastY,$x2,$y2,$tDetail[
'color']);
518 foreach($this->tData as $sGroup => $tDetail){
522 $y=$i*20+$this->legendY;
524 $this->rect($x,$y-8,10,10,$tDetail[
'color']);
525 $this->text($x+16,$y,$sLabel,
'#000',$this->textsizeLegend);
531 $this->lineFromTo($this->iMarginLeft,0,$this->iMarginLeft,$this->iHeight-10);
532 $this->lineFromTo($this->iMarginLeft,$this->iHeight-10,$this->iWidth-200,$this->iHeight-10);
536 if($this->stepX !== null){
537 for($x=($iMinX);$x<$iMaxX;$x+=$this->stepX){
538 $x2=(($x-$iMinX)/($iMaxX-$iMinX))*$iWidth+$this->iMarginLeft;
540 $this->lineFromTo($x2,($this->iHeight-10),$x2,($this->iHeight-5) );
542 $this->text($x2+2,($this->iHeight),$x);
545 $this->text(0,$this->iHeight,$iMinX);
547 $this->text($this->iWidth-200,$this->iHeight,$iMaxX);
551 if($this->stepY !== null){
552 for($y=($iMinY);$y<$iMaxY;$y+=$this->stepY){
553 $y2=(1-($y-$iMinY)/($iMaxY-$iMinY))*$iHeight;
555 $this->lineFromTo($this->iMarginLeft-5,$y2,$this->iMarginLeft,$y2 );
557 $this->text(0,$y2,$y);
560 $this->text(0,10,$iMaxY);
561 $this->text(0,$this->iHeight-10 ,$iMinY);
571 public function addGroup($sLabel,$sColor){
572 $this->tmpGroup=$sLabel;
574 $this->tData[$this->tmpGroup][
'label']=$sLabel;
575 $this->tData[$this->tmpGroup][
'color']=$sColor;
577 public function addPoint($x,$y){
578 $this->tData[$this->tmpGroup][
'tPoint'][]=array($x,$y);
589 public function show(){
598 foreach($this->tData as $sGroup => $tDetail){
599 foreach($tDetail[
'tPoint'] as $tPoint){
610 if($iMinX==
'' or $iMinX > $x){
613 if($iMinY==
'' or $iMinY > $y){
630 if($this->iMinY!=null){
634 if($this->paddingX ){
635 $iMinX-=$this->paddingX;
636 $iMaxX+=$this->paddingX;
638 if($this->paddingY ){
639 $iMinY-=$this->paddingY;
640 $iMaxY+=$this->paddingY;
643 $this->startScript();
645 $iHeight=$this->iHeight-10;
646 $iWidth=$this->iWidth-200-$this->iMarginLeft-(4);
649 $step=$this->gridY[0];
650 $color=$this->gridY[1];
652 for($y=$iMinY;$y<$iMaxY;$y+=$step){
654 $y2=(1-($y-$iMinY)/($iMaxY-$iMinY))*$iHeight;
655 $this->lineFromTo($this->iMarginLeft,$y2,$this->iWidth-200,$y2,$color,0.5 );
661 foreach($this->tMarkerY as $tLineY){
663 list($y,$color)=$tLineY;
664 $y=(1-($y-$iMinY)/($iMaxY-$iMinY))*$iHeight;
666 $this->lineFromTo($this->iMarginLeft,$y,$this->iWidth-200,$y,$color,0.5 );
672 foreach($this->tData as $sGroup => $tDetail){
675 foreach($tDetail[
'tPoint'] as $tPoint){
679 $x2=(($x-$iMinX)/($iMaxX-$iMinX))*$iWidth+$this->iMarginLeft;
680 $y2=(1-($y-$iMinY)/($iMaxY-$iMinY))*$iHeight;
692 $this->rect($x3+($k*8),$y3,6,$iHeight-$y3,$tDetail[
'color'],$y);
706 foreach($this->tData as $sGroup => $tDetail){
710 $y=$i*20+$this->legendY;
712 $this->rect($x,$y-8,10,10,$tDetail[
'color']);
713 $this->text($x+16,$y,$sLabel,
'#000',$this->textsizeLegend);
719 $this->lineFromTo($this->iMarginLeft,0,$this->iMarginLeft,$this->iHeight-10);
720 $this->lineFromTo($this->iMarginLeft,$this->iHeight-10,$this->iWidth-200,$this->iHeight-10);
724 if($this->stepX !== null){
725 for($x=($iMinX);$x<$iMaxX;$x+=$this->stepX){
726 $x2=(($x-$iMinX)/($iMaxX-$iMinX))*$iWidth+$this->iMarginLeft;
728 $this->lineFromTo($x2,($this->iHeight-10),$x2,($this->iHeight-5) );
730 $this->text($x2+2,($this->iHeight),$x);
733 $this->text(0,$this->iHeight,$iMinX);
735 $this->text($this->iWidth-200,$this->iHeight,$iMaxX);
739 if($this->stepY !== null){
740 for($y=($iMinY);$y<$iMaxY;$y+=$this->stepY){
741 $y2=(1-($y-$iMinY)/($iMaxY-$iMinY))*$iHeight;
743 $this->lineFromTo($this->iMarginLeft-5,$y2,$this->iMarginLeft,$y2 );
745 $this->text(0,$y2,$y);
748 $this->text(0,10,$iMaxY);
749 $this->text(0,$this->iHeight-10 ,$iMinY);
759 public function addGroup($sLabel,$sColor){
760 $this->tmpGroup=$sLabel;
762 $this->tData[$this->tmpGroup][
'label']=$sLabel;
763 $this->tData[$this->tmpGroup][
'color']=$sColor;
765 public function addPoint($x,$y){
766 $this->tData[$this->tmpGroup][
'tPoint'][]=array($x,$y);