42 if( !isset($this->extraColors) ){
47 $this->extraColors =
$tmp;
64 public function key(){
73 return isset( $this->colors[$this->position] );
79 if( is_null($offset) ){
80 $this->colors[] = $value;
82 $this->colors[$offset] = $value;
87 if( isset($this->colors[$offset]) ){
88 return $this->colors[$offset];
93 if( (isset($this->extraColors)) AND (isset($this->extraColors[$offset-
sizeof($this->colors)])) ){
94 return $this->extraColors[$offset->sizeof($this->colors)];
105 if( isset( $this->colors[$this->position] ) ){
111 if( isset( $this->extraColors[
sizeof($this->colors) - $this->position] ) ){
132 if( !( ($h >= 0) AND ($h <= 360) ) ){
133 throw new exception(
"HSV error, H is not between 0 and 360");
135 if( !( ($s >= 0) AND ($s <= 1) ) ){
136 throw new exception(
"HSV error, S is not between 0 and 1");
138 if( !( ($v >= 0) AND ($v <= 1) ) ){
139 throw new exception(
"HSV error, V is not between 0 and 1");
146 $q = $v*(1- ($s*$f) );
147 $t = $v*(1- $s*(1-$f) );
149 if( ($hi == 0) OR ($hi == 6) ){
150 $rgb = array($v,
$t,$p);
151 }
else if( $hi == 1 ){
152 $rgb = array($q,$v,$p);
153 }
else if( $hi == 2 ){
154 $rgb = array($p,$v,
$t);
155 }
else if( $hi == 3 ){
156 $rgb = array($p,$q,$v);
157 }
else if( $hi == 4 ){
158 $rgb = array(
$t,$p,$v);
159 }
else if( $hi == 5 ){
160 $rgb = array($v,$p,$q);
174 if(
sizeof($rgb) == 3 ){
175 foreach( $rgb as &
$c ){
176 if( ($c >= 0) AND ($c <= 1) ){
180 throw new exception(
"rgb value $c is not between 0 and 1" );
184 throw new exception(
"rgb array has not exactly 3 values" );
201 return "#{$color[0]}{$color[1]}{$color[2]}";
213 return "rgba({$r},{$g},{$b},{$a})";
222 $phi_inv = 0.618033988749895;
236 $phi_inv = 0.618033988749895;
263 while(
sizeof($hues) < $num ){
269 foreach( $hues as $hue ){
270 $b = $hue + $thresold;
271 $b2 = $hue - $thresold;
272 if( ($h>$b) OR ($h<$b2) ){
279 $okk = (!in_array(
false,$ok));
284 if( $last !=
false ){
285 $b = $last + $thresold2;
286 $b2 = $last - $thresold2;
287 if( !(($h>$b) OR ($h<$b2)) ){
293 if(
sizeof($hues) == 0 ){
306 if($tries >= $maxTries ){
330 $c = $this->
rgb2html($rgb[0],$rgb[1],$rgb[2]);
331 echo
"<div style='display:inline-block;width:3em;height:3em;background-color:$c'> </div>";
332 if( ((
$i%10) == 0) ){
339 echo
"<p>Found $n colors from $num requested, using thresold1=$thr1 and thresold2=$thr2</p>";
364 $this->colors[] = array(220,220,220);
365 $this->colors[] = array(151,187,205);
366 $this->colors[] = array(151,160,205);
367 $this->colors[] = array(169,151,205);
368 $this->colors[] = array(196,151,205);
369 $this->colors[] = array(205,151,187);
370 $this->colors[] = array(205,151,160);
371 $this->colors[] = array(205,169,151);
372 $this->colors[] = array(205,196,151);
373 $this->colors[] = array(187,205,151);
374 $this->colors[] = array(160,205,151);
375 $this->colors[] = array(151,205,169);
376 $this->colors[] = array(151,205,196);
377 $this->colors[] = array(63,169,221);
378 $this->colors[] = array(63,90,221);
379 $this->colors[] = array(116,63,221);
380 $this->colors[] = array(195,63,221);
381 $this->colors[] = array(221,63,169);
382 $this->colors[] = array(221,63,90);
383 $this->colors[] = array(221,116,63);
384 $this->colors[] = array(221,195,63);
385 $this->colors[] = array(169,221,63);
386 $this->colors[] = array(90,221,63);
387 $this->colors[] = array(63,221,116);
388 $this->colors[] = array(63,221,195);
394 for(
$i=0 ;
$i<$n ; ++
$i ){
395 $c = $this->colors->getRGBA(
$i,1);
397 echo
"<div style='display:inline-block;width:3em;height:3em;background-color:$c'> </div>";
398 if( ((
$i%12) == 0) ){
408 if( ($name ==
"width") OR ($name ==
"height") ){
409 if( is_numeric($value) ){
410 $this->
config[$name] = $value;
416 if( ($name ==
"width") OR ($name ==
"height") ){
417 if( isset($this->
config[$name]) ){
418 return $this->
config[$name];
426 if( $name ==
"colors" ){
431 public function __set($name,$value){
432 if( $name ==
"colors" ){
442 $r = rand(100000,1000000000);
443 $id = md5( serialize($this->data).
$r );
447 echo
"<canvas id='$id' width='{$width}' height='{$height}'></canvas>";
448 echo
"<script type='text/javascript'>";
451 echo
"var ctx = document.getElementById('$id').getContext('2d');";
452 echo
"var myNewChart = new Chart(ctx).$method(data);";
476 foreach( $this->data[
"labels"] as $lab){
477 $labels_str .=
'"'.$lab.
'"'.
',';
479 $labels_str = trim($labels_str,
",");
480 $labels_str = $labels_str.
"]";
485 foreach( $this->data[
"datasets"] as $set ){
488 $color = $this->colors->getRGBA(
$c,1);
489 $color2 = $this->colors->getRGBA(
$c,0.75);
490 $set_str .=
'fillColor : "'.$color2.
'",';
491 $set_str .=
'strokeColor : "'.$color.
'",';
493 $set_str .=
'data : ';
495 foreach( $set as $d ){
498 $set_str = trim($set_str,
",");
501 $datasets_str .= $set_str;
504 $datasets_str = trim($datasets_str,
",");
509 labels : '.$labels_str.
',
510 datasets : [ '.$datasets_str.
' ]
516 $r = rand(100000,1000000000);
517 $id = md5( serialize($this->data).
$r );
530 echo
"<canvas id='$id' width='{$width}' height='{$height}'></canvas>";
531 echo
"<script type='text/javascript'>";
547 echo
"var conf = {};";
548 echo
"var ctx = document.getElementById('$id').getContext('2d');";
549 echo
"var myNewChart = new Chart(ctx).Bar(data,conf);";
576 foreach( $this->data[
"labels"] as $lab){
577 $labels_str .=
'"'.$lab.
'"'.
',';
579 $labels_str = trim($labels_str,
",");
580 $labels_str = $labels_str.
"]";
585 foreach( $this->data[
"datasets"] as $set ){
588 $color = $this->colors->getRGBA(
$c,1);
589 $color2 = $this->colors->getRGBA(
$c,0.75);
590 $set_str .=
'fillColor : "'.$color.
'",';
591 $set_str .=
'strokeColor : "'.$color2.
'",';
592 $set_str .=
'pointColor : "'.$color.
'",';
593 $set_str .=
'pointStrokeColor : "#FFF",';
595 $set_str .=
'data : ';
597 foreach( $set as $d ){
600 $set_str = trim($set_str,
",");
603 $datasets_str .= $set_str;
606 $datasets_str = trim($datasets_str,
",");
611 labels : '.$labels_str.
',
612 datasets : [ '.$datasets_str.
' ]
640 $this->data_js =
'var data = [';
641 foreach( $this->data as $d){
642 $color = $this->colors->getRGBA(
$c,1);
644 $this->data_js .=
'{';
645 $this->data_js .=
'value: ';
646 $this->data_js .= $d;
647 $this->data_js .=
',color: ';
648 $this->data_js .=
'"'.$color.
'"';
649 $this->data_js .=
'},';
652 $this->data_js = trim($this->data_js,
",");
653 $this->data_js .=
'];';
677 $this->data_js =
'var data = [';
678 foreach( $this->data as $d){
679 $color = $this->colors->getRGBA(
$c,1);
681 $this->data_js .=
'{';
682 $this->data_js .=
'value: ';
683 $this->data_js .= $d;
684 $this->data_js .=
',color: ';
685 $this->data_js .=
'"'.$color.
'"';
686 $this->data_js .=
'},';
689 $this->data_js = trim($this->data_js,
",");
690 $this->data_js .=
'];';