-
Notifications
You must be signed in to change notification settings - Fork 4
/
fitsviewer.js
158 lines (131 loc) · 5.57 KB
/
fitsviewer.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
/*
* Javascript FITS Viewer 0.1
* Copyright (c) 2010 Stuart Lowe http://lcogt.net/
*
* Licensed under the MPL http://www.mozilla.org/MPL/MPL-1.1.txt
*
* Requires:
* fits.js
* Jacob Seidelin's binaryajax.js from http://www.nihilogic.dk/labs/exif/
* excanvas.js
* jQuery
*/
function FitsViewer(input){
// Define some variables
this.version = "0.1";
this.id = "FITSViewer";
this.canvas = "FITSimage";
this.fits = new FITS(); // Define the FITS object
this.file = "";
this.stretches = ["linear","sqrt","cuberoot","log","loglog","sqrtlog"];
this.colors = ["grey","heat","A","B"];
// Check for support of various functions:
this.capability = {
// the File API support
file: (window.File && window.FileReader && window.FileList && window.Blob)
}
// Overwrite with variables passed to the function
if(input){
if(typeof input.stretch=="string") this.fits.stretch = input.stretch;
if(typeof input.file=="string") this.file = input.file;
if(typeof input.id=="string") this.id = input.id;
}
// Bind some events
this.fits.bind("click",function(e){
e.y = this.height - e.y
//var value =this.image[e.y*this.width+e.x];
//document.getElementById('status').innerHTML ='click=('+ e.x+','+e.y+')='+value;
}).bind("mousemove",function(e){
e.y = this.height - e.y
//var value =this.image[e.y*this.width+e.x];
//document.getElementById('status').innerHTML ='move=('+ e.x+','+e.y+')='+value;
}).bind("load",function(e){
//document.getElementById('bitpix').innerHTML = this.header.BITPIX;
//document.getElementById('depth').innerHTML = this.depth;
//document.getElementById('z').value = 0;
}).bind("load",{me:this},function(e){
this.draw(e.data.me.canvas)
$('#'+e.data.me.id+' .loader').hide();
});
// Build the viewer here
var html = 'File: <select class="file" name="FITS"><option selected>WFPC2u5780205r_c0fx.fits</option><option>l_e_20110215_205_1_1_1.fits</option><option>l_e_20110215_203_1_1_1.fits</option></select>';
html += 'Stretch function: <select class="stretch" name="stretch">';
for(i = 0 ; i < this.stretches.length ; i++){
html += '<option'+(this.stretches[i]== this.fits.stretch ? ' selected="selected"' : '')+'>'+this.stretches[i]+'</option>';
}
html += '</select>';
html += 'Color scheme: <select class="scale" name="scale">';
for(i = 0 ; i < this.colors.length ; i++){
html += '<option'+(this.colors[i]== this.fits.color ? ' selected="selected"' : '')+'>'+this.colors[i]+'</option>';
}
html += '</select>';
html += '<br /><canvas id="'+this.canvas+'"></canvas>';
html += '<ul id="list"></ul>';
$('#'+this.id+'').html(html);
this.imageUnderlay('Try dragging and dropping a FITS file into this box');
// Bind events
$('#'+this.id+' select.file').bind('change',{me:this}, function(e){
e.data.me.fits.load($(this).val());
});
$('#'+this.id+' select.stretch').bind('change',{me:this}, function(e){
e.data.me.fits.update($(this).val());
});
$('#'+this.id+' select.scale').bind('change',{me:this}, function(e){
e.data.me.fits.update({color:$(this).val()});
});
if(this.capability.file){
// We can use the HTML5 file capabilities. Yay!
// Setup the drag-n-drop listeners.
$('#'+this.canvas).bind("dragenter",function(e) {
e.stopPropagation();
e.preventDefault();
$(this).addClass("dragover");
}).bind("dragover",function(e) {
e.stopPropagation();
e.preventDefault();
}).bind("dragleave",function(e) {
e.stopPropagation();
e.preventDefault();
$(this).removeClass("dragover");
}).bind("drop",{me:this},function(e) {
e.stopPropagation();
e.preventDefault();
$(this).removeClass("dragover");
var files = e.originalEvent.dataTransfer.files; // FileList object.
// files is a FileList of File objects. List some properties.
var output = [];
output.push('<li><strong>', files[0].name, '</strong> (', files[0].type || 'n/a', ') - ',
files[0].size, ' bytes','</li>');
//files[0].lastModifiedDate.toLocaleDateString(), '</li>');
e.data.me.processFile(files[0].name)
document.getElementById('list').innerHTML = '<ul>' + output.join('') + '</ul>';
});
} else {
$('#'+this.id).prepend('<p>The File APIs are not fully supported in this browser. You are missing out on the awesome. :-(</p>');
}
/*
Frame <button onClick="fits.update({index:--(document.getElementById('z').value)})"><</button>
<input id="z" name="z" value="0" size=3 onChange="fits.update({index:this.value})">
<button onClick="fits.update({index:++(document.getElementById('z').value)})">></button> of <span id=depth></span>. Format: <span id=bitpix></span>.
<span id="status"></span>
<br>
*/
// Load an initial FITS file
if(this.file) this.fits.load(this.file);
}
FitsViewer.prototype.processFile = function(file){
this.imageOverlay('Loading '+file);
this.fits.load(file);
}
FitsViewer.prototype.imageUnderlay = function(txt){
var canvas = $('#'+this.canvas);
if($('#'+this.id+' .loader').length == 0) $('#'+this.id).append('<div class="loader"><div class="loader_inner">'+txt+'</div></div>');
else $('#'+this.id+' .loader').html(txt).show();
$('#'+this.id+' .loader').css({width:canvas.outerWidth(),height:canvas.outerHeight(),left:canvas.offset().left,top:canvas.offset().top,'z-index':-1});
}
FitsViewer.prototype.imageOverlay = function(txt){
var canvas = $('#'+this.canvas);
if($('#'+this.id+' .loader').length == 0) $('#'+this.id).append('<div class="loader"><div class="loader_inner">'+txt+'</div></div>');
else $('#'+this.id+' .loader').html(txt).show();
$('#'+this.id+' .loader').css({width:canvas.outerWidth(),height:canvas.outerHeight(),left:canvas.offset().left,top:canvas.offset().top,'z-index':1});
}