From 0ae0bf318c8ee32808dc4251ad74ecb6c120231f Mon Sep 17 00:00:00 2001 From: Michael Wiebusch Date: Mon, 10 Aug 2015 17:47:05 +0200 Subject: [PATCH] added ruler to analysis canvas, improved selection highlighting, can now load json files from local hard disk --- user_interface/coral_scanner.pm | 7 +- user_interface/selection.css | 15 +--- user_interface/selector.html | 38 +++++++- user_interface/selector.js | 155 +++++++++++++++++++++++++------- 4 files changed, 166 insertions(+), 49 deletions(-) diff --git a/user_interface/coral_scanner.pm b/user_interface/coral_scanner.pm index b3ef245..350556b 100644 --- a/user_interface/coral_scanner.pm +++ b/user_interface/coral_scanner.pm @@ -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 " "; diff --git a/user_interface/selection.css b/user_interface/selection.css index 8fe6c29..7d028dd 100644 --- a/user_interface/selection.css +++ b/user_interface/selection.css @@ -59,27 +59,16 @@ 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; - -} diff --git a/user_interface/selector.html b/user_interface/selector.html index 8b0c1c3..95bfa77 100644 --- a/user_interface/selector.html +++ b/user_interface/selector.html @@ -9,6 +9,7 @@ + @@ -18,9 +19,44 @@ -

Coral Analysis

+

Coral Analysis

+
+ + + + +
+ + + or + + +
+ + + + + + + + + + + + + + + + + + + + + +
Scan name:
Scan description:
Scan start:
Scan stop:
Scan duration:
+
Your browser does not support the HTML5 canvas tag. diff --git a/user_interface/selector.js b/user_interface/selector.js index 6367e26..6f2314f 100644 --- a/user_interface/selector.js +++ b/user_interface/selector.js @@ -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); +} + -- 2.43.0