DaveC426913
Programmer
I want to make a bar graah class, but I'm not sure how to make it OO and efficient.
I will supply
1] a multi-dimensioned array of data (col1(value, label, colour),col2(value, label, colour),etc)
3] Some application-wide parameters (font, etc.)
4] Some table-level style params (border:Y/N, vertical vs. horizontal orientation, xyoffset)
5] Some data-display-specific params (columnwidth, columngutter, horizontal-lines-every-number-of-units, etc.)
Below is a snippet of what I've got so far. It seems pretty inefficient in terms of what fucntinos and varaibles are available and how easy it is to set them or call them. I could use some advice.
How can I break out the various functions? IS there more than one function? i.e. this works:
function DrawGraph(1 brazillion parameters){ ... }
Of course, that's very awkward, not to mention the fact that it doesan't support default params.
Any advice?
The call:
$g = new BarGraph($colarray);
$g->Show(225,230);
The class:
class BarGraph{
function BarGraph($colarray){
}
function Show($height,$width,$orientation=0,$border=1,$orientation=0,$colwidth=20,$colgap=1){
global $colarray;
if (orientation==0){
//vertical bars
//constants
$innerboxoffset=25;
$xinitialoffset=5;
?>
<style>
.xlbl{ ... }
.ylbl{ ... }
.bar{ ... }
</style>
<!-- outer border -->
<div style="position: absolute; left: 100px; height: <?=$height?>px; width: <?=$width?>px; border: <?
if ($border=1){ echo " 1px solid gray;"; }
else{ echo " none;"; }
?> overflow: hidden;">
<!-- inner border -->
<div style="position: absolute; left: <?=$innerboxoffset?>px; top:5px; bottom: 15px; height: 202px; width:200px; border: 1px solid gray; overflow: hidden;">
<!-- bars -->
<? for ($col=1;$col<=sizeOf($colarray);$col++){?>
<div class="bar" style="left: <?=(($col-1)*($colwidth+$colgap)+$xinitialoffset)?>px; width: <?=$colwidth?>px; background-color: <?=$colarray[$col][colour]?>; top:<?=(200-$colarray[$col][value])?>px;"><?=$colarray[$col][value]?></div>
<?}?>
etc. etc.
I will supply
1] a multi-dimensioned array of data (col1(value, label, colour),col2(value, label, colour),etc)
3] Some application-wide parameters (font, etc.)
4] Some table-level style params (border:Y/N, vertical vs. horizontal orientation, xyoffset)
5] Some data-display-specific params (columnwidth, columngutter, horizontal-lines-every-number-of-units, etc.)
Below is a snippet of what I've got so far. It seems pretty inefficient in terms of what fucntinos and varaibles are available and how easy it is to set them or call them. I could use some advice.
How can I break out the various functions? IS there more than one function? i.e. this works:
function DrawGraph(1 brazillion parameters){ ... }
Of course, that's very awkward, not to mention the fact that it doesan't support default params.
Any advice?
The call:
$g = new BarGraph($colarray);
$g->Show(225,230);
The class:
class BarGraph{
function BarGraph($colarray){
}
function Show($height,$width,$orientation=0,$border=1,$orientation=0,$colwidth=20,$colgap=1){
global $colarray;
if (orientation==0){
//vertical bars
//constants
$innerboxoffset=25;
$xinitialoffset=5;
?>
<style>
.xlbl{ ... }
.ylbl{ ... }
.bar{ ... }
</style>
<!-- outer border -->
<div style="position: absolute; left: 100px; height: <?=$height?>px; width: <?=$width?>px; border: <?
if ($border=1){ echo " 1px solid gray;"; }
else{ echo " none;"; }
?> overflow: hidden;">
<!-- inner border -->
<div style="position: absolute; left: <?=$innerboxoffset?>px; top:5px; bottom: 15px; height: 202px; width:200px; border: 1px solid gray; overflow: hidden;">
<!-- bars -->
<? for ($col=1;$col<=sizeOf($colarray);$col++){?>
<div class="bar" style="left: <?=(($col-1)*($colwidth+$colgap)+$xinitialoffset)?>px; width: <?=$colwidth?>px; background-color: <?=$colarray[$col][colour]?>; top:<?=(200-$colarray[$col][value])?>px;"><?=$colarray[$col][value]?></div>
<?}?>
etc. etc.