예제 #1
0
파일: data.php 프로젝트: hbrew/lasersdb
 public static function plotSpectra()
 {
     $plot = new Plot();
     $plot->xlabel("Wavelength (nm)");
     $spectra = new Spectra();
     $spectra->loadOptions();
     // Make material selection if it exists
     if (isset($_GET['selection'])) {
         $selection = json_decode(urldecode($_GET['selection']));
         // print_r($selection);
         $x = array();
         $y = array();
         $legend = array();
         foreach ($selection as $type => $name_array) {
             $plot->ylabel($type . " (cm^2)");
             foreach ($name_array as $name => $axis_array) {
                 $plot->title($name . " " . $type . " Vs. Wavelength");
                 $n = 0;
                 foreach ($axis_array as $axis => $range_array) {
                     // print_r($axis);
                     $legend[$n] = $axis . " axis";
                     $y[$legend[$n]] = array();
                     foreach ($range_array as $range => $empty) {
                         if (!$spectra->selectOptions($type, $name, $axis, $range)) {
                             $errors[] = new UserError("Options do not exist", 1);
                         }
                         if ($n == 0) {
                             // only need wavelengths once
                             $x = array_merge($x, $spectra->getWavelengths());
                         }
                         $y[$legend[$n]] = array_merge($y[$legend[$n]], $spectra->getSignals());
                         $spectra->clearSelection();
                     }
                     $n = $n + 1;
                 }
             }
         }
         $plot->setX($x);
         $plot->setY($y);
         $plot->legend($legend);
         // Output plot data
         echo $plot->getJson();
     } else {
         // Output materials list
         echo $spectra->getJson();
     }
 }