]> jspc29.x-matter.uni-frankfurt.de Git - coral.git/commitdiff
added ruler to analysis canvas, improved selection highlighting, can now load json...
authorMichael Wiebusch <m.wiebusch@gsi.de>
Mon, 10 Aug 2015 15:47:05 +0000 (17:47 +0200)
committerMichael Wiebusch <m.wiebusch@gsi.de>
Mon, 10 Aug 2015 15:47:05 +0000 (17:47 +0200)
user_interface/coral_scanner.pm
user_interface/selection.css
user_interface/selector.html
user_interface/selector.js

index b3ef2459345bad88f238bfb7dba81e77fe260173..350556b98687dfbc22ef5f0a635117f751a810ad 100644 (file)
@@ -726,6 +726,7 @@ sub compile_report {
   my $dump = "./report/".$timestamp."_".$scan_name.".dump";
   
   my $csv = "./report/".$timestamp."_".$scan_name.".csv";
+  my $json = "./report/".$timestamp."_".$scan_name.".json";
   my $svg = "./report/".$timestamp."_".$scan_name.".svg";
   my $xls = $csv.".xls";
   
@@ -734,6 +735,10 @@ sub compile_report {
   print DUMP Dumper($scan);
   close(DUMP);
   
+  open(JSON,"> $json") or die "cannot open $json for writing \n";
+  print JSON encode_json($scan);
+  close(JSON);
+  
   $self->scan_to_ascii(tofile => $csv);
   $self->scan_to_svg(svg_file => $svg);
   system("./csv2xls.sh $csv");
@@ -747,7 +752,7 @@ sub compile_report {
   
   $self->{report}->email(
     text => $mailtext,
-    attachments => join(",",($csv,$svg,$xls,$storable,$dump))
+    attachments => join(",",($csv,$svg,$xls,$storable,$dump,$json))
   );
   
   return " ";
index 8fe6c2991cc7950d4a55db8a1859bfb455b9c448..7d028dd7bc138f750c873bdee1a5b133915e2321 100644 (file)
   overflow-x:scroll;
 }*/
 
-#controls {
+#notepad,#controls,#file_selection {
 
    position:relative;
    padding:20px;
 /*    top: 400px; */
 /*    left: 60px; */
-   width: 800px;
+   width: 960px;
 /*    height: 300px; */
    border:1px solid #d3d3d3;
 
 }
 
-#notepad {
-
-   position:relative;
-   padding:20px;
-/*    top: 500px; */
-/*    left: 100px; */
-   width: 800px;
-/*    height: 300px; */
-   border:1px solid #d3d3d3;
-
-}
 
index 8b0c1c3012d9c1311e7f46c44acf41b25813976c..95bfa7783fe42302d687acc21f39c5d4ee8e38c1 100644 (file)
@@ -9,6 +9,7 @@
   <script src="./selector.js"></script>
   <script src="./statistics.js"></script>
   
+  <link rel="stylesheet" type="text/css" href="styles.css">
   <link rel="stylesheet" type="text/css" href="jquery-ui.css">
   <link rel="stylesheet" type="text/css" href="selection.css">
   
   
   </head>
   <body>
-  <h1>Coral Analysis</h1>
+  <h2>Coral Analysis</h2>
 <!--  <p id='pout' >text, text text, text</p>
   <p>Canvas:</p> -->
+  <div id='file_selection' class='isBox' >
+    <table><tr>
+      <td>
+        <input type="button" id="btn_last_scan" value="load last scan" />
+      </td>
+      <td>
+        or
+      </td>
+      <td>
+        <input type="file" id="files" name="file" />
+      </td>
+    </tr></table>
+    <table>
+      <tr>
+        <td>Scan name:</td>
+        <td id='scan_name'></td>
+      </tr>
+      <tr>
+        <td>Scan description:</td>
+        <td id='scan_desc'></td>
+      </tr>
+      <tr>
+        <td>Scan start:</td>
+        <td id='start_timestamp'></td>
+      </tr>
+      <tr>
+        <td>Scan stop:</td>
+        <td id='stop_timestamp'></td>
+      </tr>
+      <tr>
+        <td>Scan duration:</td>
+        <td id='duration'></td>
+      </tr>
+    </table>
+  </div>
   <div id='compound_canvas' class='isBox' >
     <canvas id="myCanvas" width="1000" height="200">
     Your browser does not support the HTML5 canvas tag.
index 6367e26ffb5061e88c37dab24f482daf0865899d..6f2314f54e2e82e72cc4526f447315edd360625a 100644 (file)
@@ -6,7 +6,7 @@ var contrast_max;
 
 var canvas_offset = 0;
 
-var selection_color = [180,180,255];
+var selection_color = [220,220,255,0,0,196];
 
 
 var my_subset = {};
@@ -14,13 +14,60 @@ var my_subset = {};
 var pixel_size = 10;
 
 $(document).ready(function(){
-  scan = get_scan_json();
-  $('#pout').html(scan.meta.scan_name);
+//   $('#pout').html(scan.meta.scan_name);
   
+  $('#files').val("");
   
+  $('#files').change(function(){
+    readBlob();
+  });
+  
+  $('#btn_last_scan').click(function(){
+    scan = get_scan_json();
+    init_widgets();
+  });
+  
+  $("#btn_clear_selection").click(function(){
+    clear_selection();
+  });
+  
+  
+  $("#btn_append_data").click(function(){
+    $("#textarea_notepad").val(
+      $("#textarea_notepad").val()+
+      $("#text_label").val()+"\t"+
+      $("#text_thickness").val()+"\t"+
+      $("#text_avg_dnsty").val()+"\t"+
+      $("#text_stdev_dnsty").val()+"\t"+
+      "\n"
+    );
+  });
+  $("#btn_clear_data").click(function(){
+    clear_notepad();
+  });
+  $('#text_thickness').change(function(){
+    calculate();
+  });
+  $('#text_k0').change(function(){
+    calculate();
+  });
+  
+  
+});
+
+
+
+function init_widgets(){
+   
   contrast_min = 0;
   contrast_max = scan.meta.unshadowed_counts/scan.meta.unshadowed_count_time*scan.meta.time_per_pixel;
   
+  
+  for( x in scan.meta){
+    $('#'+x).html(scan.meta[x]);
+  }
+  
 //   draw_scan();
 //   alert(false_color(30000,255,100,0));
   
@@ -44,24 +91,6 @@ $(document).ready(function(){
 //   $( "#amount" ).html( $( "#slider-range" ).slider( "values", 0 ) +
 //     " - " + $( "#slider-range" ).slider( "values", 1 ) );
 
-  $("#btn_clear_selection").click(function(){
-    clear_selection();
-  });
-  
-  
-  $("#btn_append_data").click(function(){
-    $("#textarea_notepad").val(
-      $("#textarea_notepad").val()+
-      $("#text_label").val()+"\t"+
-      $("#text_thickness").val()+"\t"+
-      $("#text_avg_dnsty").val()+"\t"+
-      $("#text_stdev_dnsty").val()+"\t"+
-      "\n"
-    );
-  });
-  $("#btn_clear_data").click(function(){
-    clear_notepad();
-  });
   
   
   $( "#canvas_slider" ).slider({
@@ -74,17 +103,12 @@ $(document).ready(function(){
     }
   });
   
-  $('#text_thickness').change(function(){
-    calculate();
-  });
-  $('#text_k0').change(function(){
-    calculate();
-  });
   
   clear_selection();
   clear_notepad();
   
-});
+}
+
 
 function clear_selection(){
   my_subset = {};
@@ -178,31 +202,62 @@ function draw_scan() {
   
   ctx.clearRect(0, 0, c.width, c.height);
   
+  
+  
   for (var i = 0; i < scan.meta.rows; i++) {
     for (var j = 0; j < scan.meta.cols; j++) {
       var value = scan.data[i][j];
       if (my_subset[i.toString()+"-"+j.toString()] == 1) {
-        ctx.fillStyle = false_color(value,selection_color[0],selection_color[1],selection_color[2]);
+        ctx.fillStyle = false_color(value,
+                                    selection_color[0],selection_color[1],selection_color[2],
+                                    selection_color[3],selection_color[4],selection_color[5]
+                                   );
       } else {
-        ctx.fillStyle = false_color(value,255,255,255);
+        ctx.fillStyle = false_color(value,255,255,255,0,0,0);
       }
       ctx.fillRect(i*pixel_size - canvas_offset, j*pixel_size, pixel_size, pixel_size);
       
     }
       //Do something
   }
+  var ruler_y_offset = 180;
+  ctx.fillStyle = "#000000";
+  for (var i = 0; i < 300; i+=1) {
+    var x = i*10-canvas_offset;
+    
+    if (i % 5 == 0) {
+    
+      ctx.beginPath();
+      ctx.moveTo(x,ruler_y_offset);
+      ctx.lineTo(x,ruler_y_offset + 20);
+      ctx.stroke();
+      ctx.font = "16px Arial";
+      if (i == 0) {
+        ctx.fillText("0 mm",x+5,ruler_y_offset+20);
+      } else {
+        ctx.fillText(i,x+5,ruler_y_offset+20);
+      }
+    } else {
+      ctx.beginPath();
+      ctx.moveTo(x,ruler_y_offset);
+      ctx.lineTo(x,ruler_y_offset + 4);
+      ctx.stroke();
+    }
+  }
   
   
   
 }
 
-function false_color(value,r,g,b) {
+function false_color(value,r,g,b,r2,g2,b2) {
   var ratio = (value - contrast_min)/(contrast_max-contrast_min);
   ratio = Math.max(ratio,0);
   ratio = Math.min(ratio,1);
-  var ro = Math.round(ratio*r).toString();
-  var go = Math.round(ratio*g).toString();
-  var bo = Math.round(ratio*b).toString();
+  
+  
+  var ro = Math.round(ratio*(r-r2)+r2).toString();
+  var go = Math.round(ratio*(g-g2)+g2).toString();
+  var bo = Math.round(ratio*(b-b2)+b2).toString();
   return "rgb("+ro+","+go+","+bo+")";
 }
 
@@ -227,6 +282,38 @@ function get_scan_json(){
 
 
 
+function readBlob(opt_startByte, opt_stopByte) {
+
+  var files = document.getElementById('files').files;
+  if (!files.length) {
+    alert('Please select a file!');
+    return;
+  }
+
+  var file = files[0];
+  var start = parseInt(opt_startByte) || 0;
+  var stop = parseInt(opt_stopByte) || file.size - 1;
+
+  var reader = new FileReader();
+
+  // If we use onloadend, we need to check the readyState.
+  reader.onloadend = function(evt) {
+    if (evt.target.readyState == FileReader.DONE) { // DONE == 2
+//       document.getElementById('byte_content').textContent = evt.target.result;
+      scan = JSON.parse(evt.target.result);
+      init_widgets();
+//       alert("scan loaded");
+//       draw_scan();
+//       document.getElementById('byte_range').textContent = 
+//           ['Read bytes: ', start + 1, ' - ', stop + 1,
+//             ' of ', file.size, ' byte file'].join('');
+    }
+  };
+
+  var blob = file.slice(start, stop + 1);
+  reader.readAsBinaryString(blob);
+}
+