add_colors can now be called with 1..n colors to add instead of just one.

This commit is contained in:
Andrew Tomaka 2011-10-26 15:47:16 -04:00
parent de288abfb7
commit 5c7dd6ba7f
2 changed files with 17 additions and 17 deletions

View file

@ -51,11 +51,7 @@ class Gantt {
**/ **/
function __construct() { function __construct() {
//add a default set of colors //add a default set of colors
$this->add_color('#FF8080'); $this->add_color('#FF8080','#99CCFF','#00FF00','#FF9900','#800080');
$this->add_color('#99CCFF');
$this->add_color('#00FF00');
$this->add_color('#FF9900');
$this->add_color('#800080');
} }
/** /**
@ -96,6 +92,7 @@ class Gantt {
} }
$columns = $this->find_last(); $columns = $this->find_last();
// probably should template this html sometime.
$this->html = '<table id="gantt">' . "\n"; $this->html = '<table id="gantt">' . "\n";
// create the header // create the header
@ -145,18 +142,21 @@ class Gantt {
/** /**
* Add a color to our list * Add a color to our list
* @param string hexadecimal color code * @param string hexadecimal color code, 1..n accepted
* @return bool whether or not the color was added
**/ **/
public function add_color($color) { public function add_color() {
$colors = func_get_args();
if(empty($colors)) return;
foreach($colors as $color) {
// the color was not properly formatted // the color was not properly formatted
if(preg_match('/^#(?:[0-9a-fA-F]{3}){1,2}$/',$color) == 0) return false; if(preg_match('/^#(?:[0-9a-fA-F]{3}){1,2}$/',$color) == 0) continue;
// color is already in the list // color is already in the list
if(in_array($color,$this->colors)) return false; if(in_array($color,$this->colors)) continue;
$this->colors[] = $color; $this->colors[] = $color;
}
return true;
} }
/** /**

View file

@ -31,9 +31,9 @@ include_once('Gantt.php');
$gnt = new Gantt(); $gnt = new Gantt();
$gnt->add_event('Event 1',0,1); $gnt->add_event('Event 1',1,1);
$gnt->add_event('Event 2',2,3); $gnt->add_event('Event 2',3,3);
$gnt->add_event('Event 3',2,4); $gnt->add_event('Event 3',3,4);
echo $gnt->render_html(); echo $gnt->render_html();