Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge branch 'master' of github.com:jywarren/spectral-workbench

  • Loading branch information...
commit 812dbd7a6446cab4f697ce1fe90b4b4ce52405d2 2 parents ab8774e + 782f609
@jywarren authored
View
18 webserver/app/controllers/spectrums_controller.rb
@@ -17,6 +17,10 @@ def index
# GET /spectrums/1.json
def show
@spectrum = Spectrum.find(params[:id])
+ if @spectrum.data == "" || @spectrum.data.nil?
+ @spectrum.data = @spectrum.extract_data
+ @spectrum.save
+ end
@comment = Comment.new
@spectrums = Spectrum.find(:all, :limit => 4, :order => "created_at DESC", :conditions => ["id != ?",@spectrum.id])
@@ -90,9 +94,9 @@ def create
:author => params[:spectrum][:author],
:photo => params[:photo]})
@spectrum.client_code = client_code if params[:client] || params[:uniq_id]
- puts params[:endWavelength]
- puts params[:startWavelength]
- # Calibrate
+
+ @spectrum.extract_data
+ @spectrum.scale_data(params[:endWavelength],params[:startWavelength])
else
@spectrum = Spectrum.new(params[:spectrum])
@@ -161,4 +165,12 @@ def comment
end
end
+ #def calibrate(x1,wavelength1,x2,wavelength2)
+ def calibrate
+ @spectrum = Spectrum.find(params[:id])
+ @spectrum.calibrate(params[:x1],params[:w1],params[:x2],params[:w2])
+ @spectrum.save
+ redirect_to "/spectra/show/"+@spectrum.id.to_s
+ end
+
end
View
25 webserver/app/models/spectrum.rb
@@ -33,14 +33,35 @@ def extract_data
pixels << '{wavelength:null,average:'+((r+g+b)/3).to_s+',r:'+r.to_s+',g:'+g.to_s+',b:'+b.to_s+'}'
end
- puts pixels
# save it internally
s = "{name:'"+self.title+"',lines: ["
s += pixels.join(',')
s += "]}"
self.data = s
- self.save
s
end
+ # {wavelength:null,average:0,r:0,g:0,b:0}
+ def scale_data(start_w,end_w)
+ d = ActiveSupport::JSON.decode(self.data)
+ i = 0
+ d['lines'].each do |line|
+ line['wavelength'] = (start_w + i*((end_w-start_w)*1.00/d['lines'].length))
+ i += 1
+ end
+ self.data = ActiveSupport::JSON.encode(d)
+ end
+
+ def calibrate(x1,wavelength1,x2,wavelength2)
+ d = ActiveSupport::JSON.decode(self.data)
+ i = 0
+ stepsize = ((wavelength2.to_f-wavelength1.to_f)*1.00/(x2.to_f-x1.to_f))
+ startwavelength = wavelength1.to_f-(stepsize*x1.to_f)
+ d['lines'].each do |line|
+ line['wavelength'] = startwavelength + i*stepsize
+ i += 1
+ end
+ self.data = ActiveSupport::JSON.encode(d)
+ end
+
end
View
9 webserver/app/views/sets/show.html.erb
@@ -38,11 +38,14 @@
lineWidth: 1,
},
},
- yaxis: { show: false },
+ yaxis: { show: true, min: 0, max: 100 },
xaxis: { show: scaled },
shadowSize: 0,
grid: {
- backgroundColor: "#eee"
+ clickable: true,
+ hoverable:true,
+ borderWidth: 0,
+ backgroundColor: "#eee"
},
// Palette "i eat the rainbow" by svartedauden on Colourlovers: http://www.colourlovers.com/palette/1630898/i_eat_the_rainbow, CC-BY-NC
colors: [ "#333333", "#E02130", "#FAB243", "#429867", "#2B5166" ]//, "#482344" ]
@@ -61,7 +64,7 @@
line.wavelength = index
scaled = false
}
- data[data.length-1].data.push([line.wavelength,line.average])
+ data[data.length-1].data.push([line.wavelength,line.average/2.55])
})
<% end %>
$.plot($("#graph"),data,options);
View
2  webserver/app/views/spectrums/_compare.html.erb
@@ -2,7 +2,7 @@
<div id="spectrum_<%= spectrum.id %>" class="spectrum comparison">
<img width="100px" src="<%= spectrum.photo.url(:thumb) %>" /><br />
<p><b><%= spectrum.title %></b></p>
-<a class="smallbutton" id="spectrum_btn_<%= spectrum.id %>" href="javascript:void(0);">Add [+]</a> <span id="scaledFlag_<%= spectrum.id %>"></span></p>
+<a class="smallbutton" id="spectrum_btn_<%= spectrum.id %>" href="javascript:void(0);">Add +</a> <span id="scaledFlag_<%= spectrum.id %>"></span></p>
<script>
<% if spectrum.data == "" %>
View
55 webserver/app/views/spectrums/show.html.erb
@@ -38,11 +38,7 @@
<div id="graph" style="width:827px;height:200px;"></div>
<script type="text/javascript">
- <% if @spectrum.data == "" || @spectrum.data.nil? %>
- spectrum = <%= @spectrum.extract_data %>
- <% else %>
- spectrum = <%= @spectrum.data.chomp(",") %>
- <% end %>
+ spectrum = <%= @spectrum.data %>
data = [{label: "<%= @spectrum.title %> = 0% ",data:[]}]
scaled = true
$.each(spectrum.lines,function(index,line) {
@@ -64,6 +60,7 @@
xaxis: { show: scaled },
shadowSize: 0,
grid: {
+ clickable: true,
hoverable:true,
borderWidth: 0,
backgroundColor: "#eee"
@@ -127,17 +124,46 @@
</script>
<div id="toolbar">
- <a id="createSet" class="smallbutton" style="display:none;" href="javascript:void(0);">Save as set [+]</a>
- <!--<a id="calibrate" class="smallbutton" href="javascript:void(0);">Calibrate</a>-->
-</div>
+ <p>
+ <small>Embed code: <input style="font-size:11px" id="embedcode" type="text" value="<iframe width='500px' height='400px' border='0' src='http://spectralworkbench.org/spectra/embed/<%= @spectrum.id %>'></iframe>" /></small>
+ <a id="createSet" class="smallbutton" style="display:none;" href="javascript:void(0);">Save as set +</a>
+ <a id="calibrate" class="smallbutton" href="javascript:void(0);">Calibrate</a>
+ <span id="toolbar_notification"></span>
+ </p>
+</div>
<script>
$('#createSet').click(function() {
window.location.href = "/sets/new/"+spectra.join(',')
})
+
+ // we could switch to "selection" http://people.iola.dk/olau/flot/examples/selection.html
$('#calibrate').click(function() {
-
+ $("#toolbar_notification").html("Click on the middle blue band (<a href='http://publiclaboratory.org/wiki/spectral-workbench-calibration'>Learn more</a>)")
+ // observe clicks to graph:
+ $("#graph").bind("plotclick", function (event, pos, item) {
+ console.log(pos.x)
+ second_calibration(pos.x,435.833)
+ // axis coordinates for other axes, if present, are in pos.x2, pos.x3, ...
+ });
+ })
+
+ function second_calibration(x1,w1) {
+ $("#toolbar_notification").html("Click on the bright green band")
+ // observe clicks to graph:
+ $("#graph").bind("plotclick", function (event, pos, item) {
+ complete_calibration(x1,w1,pos.x,546.074)
+ });
+ }
+ function complete_calibration(x1,w1,x2,w2) {
+ $("#toolbar_notification").html("Calibrating...")
+ window.location.href = "/spectra/calibrate/<%= @spectrum.id %>?x1="+x1+"&w1="+w1+"&x2="+x2+"&w2="+w2
+ }
+
+ $('#embedcode').click(function() {
+ this.focus()
+ this.select()
})
</script>
@@ -150,17 +176,6 @@
<p class="description"><%= markdown(@spectrum.notes) if @spectrum.notes %></p>
<% if @spectrum.notes == "" %><p class="description"><i>None</i></p><% end %>
-<h3>// SHARE</h3>
-
-<p style="margin-top:0px;">Embed code: <input id="embedcode" type="text" value="<iframe width='500px' height='400px' border='0' src='http://spectralworkbench.org/spectra/embed/<%= @spectrum.id %>'></iframe>" /></p>
-
-<script>
-$('#embedcode').click(function() {
- this.focus()
- this.select()
-})
-</script>
-
<h3>// LICENSE</h3>
<p xmlns:dct="http://purl.org/dc/terms/" xmlns:vcard="http://www.w3.org/2001/vcard-rdf/3.0#">
View
12 webserver/public/stylesheets/style.css
@@ -254,13 +254,15 @@ a.smallbutton {
border:none;
}
#show #toolbar {
- height:18px;
+ height:22px;
padding:5px;
background:#ddd;
- border-top:3px solid #ddd;
}
-#show #toolbar a {
+#show #toolbar p {
+ margin:0;
font-size:11px;
+}
+#show #toolbar a.smallbutton {
padding:3px;
background:#555;
}
@@ -268,6 +270,10 @@ a.smallbutton {
background:#333;
color:#aaa;
}
+#show #toolbar #toolbar_notification {
+ font-size:11px;
+ padding-top:4px;
+}
#footer {
padding-bottom:30px;
Please sign in to comment.
Something went wrong with that request. Please try again.