| 30 | | function calc_tickscale($max_value,$min_ticks,$max_labels) |
| 31 | | { |
| 32 | | //First see how many labels we can get in |
| 33 | | $tickscale=pow(10,floor(log($max_value,10))); |
| 34 | | while($max_value/$tickscale*10<=$max_labels) |
| 35 | | $tickscale/=10; |
| 36 | | //That's as far as we can break up the labels for powers of 10. |
| 37 | | //Maybe we can break it up by 5 or 2 |
| 38 | | $ticks=$max_value/$tickscale; |
| 39 | | $divisions=1; |
| 40 | | if($ticks*5<=$max_labels) |
| 41 | | $divisions=5; |
| 42 | | else if($ticks*2<=$max_labels) |
| 43 | | $divisions=2; |
| 44 | | $tickscale/=$divisions; |
| 45 | | $ticks*=$divisions; |
| 46 | | |
| 47 | | //Label interval is how many ticks to have before a label |
| 48 | | $label_interval=1; |
| 49 | | if($ticks*$divisions<$min_ticks&&$divisions!=1) |
| 50 | | { |
| 51 | | //the tickscale needs to be broken up more for the ticks |
| 52 | | //(but not labels). Gotta undo the last factor then for the ticks. |
| 53 | | $label_interval=10/$divisions; |
| 54 | | $tickscale/=10/$divisions; |
| 55 | | } |
| 56 | | |
| 57 | | //Do we still need to break the ticks up more? |
| 58 | | while($max_value/$tickscale<$min_ticks) |
| 59 | | { |
| 60 | | if($max_value/$tickscale*2>=$min_ticks) |
| 61 | | { |
| 62 | | $label_interval*=2; |
| 63 | | $tickscale/=2; |
| 64 | | break; |
| 65 | | } |
| 66 | | if($max_value/$tickscale*5>=$min_ticks) |
| 67 | | { |
| 68 | | $label_interval*=5; |
| 69 | | $tickscale/=5; |
| 70 | | break; |
| 71 | | } |
| 72 | | $label_interval*=10; |
| 73 | | $tickscale/=10; |
| 74 | | } |
| 75 | | return array($tickscale,$label_interval); |
| 76 | | } |
| 77 | | |
| 78 | | //Request arguments |
| 79 | | |
| 80 | | if(isset($_REQUEST['plot'])) |
| 81 | | $plottype = $_REQUEST['plot']; |
| 82 | | else |
| 83 | | $plottype = 'EvsYield'; |
| 84 | | if(isset($_REQUEST['log'])) |
| 85 | | $log = $_REQUEST['log']; |
| 86 | | else |
| 87 | | $log = 0; |
| 88 | | if(isset($_REQUEST['selected'])) |
| 89 | | $selected = $_REQUEST['selected']; |
| 90 | | else |
| 91 | | $selected = ''; |
| 92 | | $categorizations=array(array(""=>0),array("Metals"=>0,"Polymers"=>1,"Ceramics"=>2,"Fibers"=>1)); |
| 93 | | if(isset($_REQUEST['categorization'])) |
| 94 | | $categorization=$categorizations[$_REQUEST['categorization']]; |
| 95 | | else |
| 96 | | $categorization=$categorizations[0]; |
| 97 | | |
| 98 | | |
| 99 | | |
| 100 | | if(isset($_REQUEST["numvars"])){ |
| 101 | | $numvars=$_REQUEST['numvars']; |
| 102 | | } |
| 103 | | |
| 104 | | $matstring = ""; |
| 105 | | $property_listx = array(); |
| 106 | | $property_listy = array(); |
| 107 | | for($i=1;$i<=4;$i++){ |
| 108 | | if(isset($_REQUEST["propname".$i])){ |
| 109 | | $propname[$i]=$_REQUEST['propname'.$i]; |
| 110 | | } |
| 111 | | if(isset($_REQUEST["xpow".$i])){ |
| 112 | | $xpow[$i]=$_REQUEST['xpow'.$i]; |
| 113 | | } |
| 114 | | if(isset($_REQUEST["ypow".$i])){ |
| 115 | | $ypow[$i]=$_REQUEST['ypow'.$i]; |
| 116 | | } |
| 117 | | |
| 118 | | if($xpow[$i] != 0){ |
| 119 | | $property_listx["$propname[$i]"] = "$xpow[$i]"; |
| 120 | | } |
| 121 | | if($ypow[$i] != 0){ |
| 122 | | $property_listy["$propname[$i]"] = "$ypow[$i]"; |
| 123 | | } |
| 124 | | |
| 125 | | } |
| 126 | | // print_r($ypow); |
| 127 | | // echo "<br><br>"; |
| 128 | | // print_r($property_listx); |
| 129 | | // echo "<br><br>"; |
| 130 | | // print_r($property_listy); |
| 131 | | |
| 132 | | |
| 133 | | |
| 134 | | |
| 135 | | //get the values from the database with these function |
| 136 | | if($plottype == "free") |
| 137 | | list($valuesX, $valuesY, $names, $xlabel, $ylabel, $categories) = db_get_plot_single_values($property_listx, $property_listy, $log, $categorization); |
| 138 | | else |
| 139 | | list($valuesX, $valuesY, $names, $xlabel, $ylabel, $categories) = db_get_plot_values($plottype, $log, $categorization); |
| 140 | | |
| 141 | | |
| 142 | | |
| 143 | | // print_r($valuesX); |
| 144 | | // echo "<br>"; |
| 145 | | // print_r($valuesY); |
| 146 | | |
| 147 | | // return; |
| 148 | | |
| 169 | | $category_colors=array(ImageColorAllocate($image, 0, 0, 255),ImageColorAllocate($image, 255, 0, 0),ImageColorAllocate($image, 0, 255, 0)); |
| 170 | | $selected_color = ImageColorAllocate($image, 255, 255, 255); |
| | 50 | $category_raw_colors=array(array(0, 0, 255),array(255, 0, 0),array(0, 255, 0),array(255,255,255)); |
| | 51 | $category_colors=array(); |
| | 52 | for($index=0; $index<count($category_raw_colors)-1; $index++) |
| | 53 | { |
| | 54 | $raw_color=$category_raw_colors[$index]; |
| | 55 | $category_colors[$index]=ImageColorAllocate($image,$raw_color[0],$raw_color[1],$raw_color[2]); |
| | 56 | } |
| | 57 | $raw_color=$category_raw_colors[$index]; |
| | 58 | $selected_color=ImageColorAllocate($image,$raw_color[0],$raw_color[1],$raw_color[2]); |