-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdiagram.js
More file actions
227 lines (224 loc) · 6.49 KB
/
Copy pathdiagram.js
File metadata and controls
227 lines (224 loc) · 6.49 KB
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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
function inithistogram()
{
$('#histcalc').click(function(e) {
var calc = $('#bandselect').val();
if(calc==null)
{
alert("please select a band!");
}
else
{
var nrbins = $('#nrbins').val();
histogram(band2data(calc.toString()),nrbins);
}
});
}
function initspectrallibrary()
{
$('#loadlibrary').click(function(e) {
var library = $('#spectrallibrary').val();
if (library == "selectlibrary") {
alert("Please select one of the libraries before clicking on the load button.");
}
else
{
var libspectra = $('#selectspectra[name=' + library + ']').val();
if(libspectra == undefined)
{
// first load the corresponding js file
var file = 'speclib/' + library+'.js';
$.getScript(file)
.done(function(){
eval('data = ' + library + ';');
var html = '';
for (var key in data)
{
if(key != "Wavelength")
{
html += '<option value="' + key + '">' + key + '</option>';
}
}
var libraryselect = '<select name="' + library + '" id="selectspectra" size=1>' + html + '</select>';
$("#afterload").html(libraryselect);
})
.fail(function(){
alert("Error loading the file.");
});
}
else
{
var numbers = [];
eval('data = ' + library + ';');
wavelength = data["Wavelength"];
values = data[libspectra];
for(var i = 0; i < wavelength.length; i++){
numbers.push([wavelength[i], values[i]]);
}
var output = [];
var tempcolors = [];
for (i=0; i < pos; i++) {
output.push(hsdataset.point[i].spectrum);
tempcolors.push(colors[i]);
}
tempcolors.push("Black");
output.push(numbers);
spectrum_load(output,tempcolors,libspectra);
}
}
});
}
function spectrum_load(numbers,colors,title)
{
// Switch to SPECTRUM TAB and then plot the spectrum
switch_tabs($('.defaulttab'));
diagramplot.spectra = numbers;
$.jqplot.config.enablePlugins = true;
spectra = $.jqplot('chartPlace', numbers, {
title: title,
cursor: {
show: true,
zoom : true
},
highlighter : {
show : true
},
series: [{breakOnNull: true}],
seriesDefaults: {
renderer: $.jqplot.LineRenderer,
lineWidth: 1,
rendererOptions: {
smooth: true,
animation: {
show: true
}
},
showMarker: false,
pointLabels: {
show: false
}
},
axes: {
xaxis: {
pad: 1.1
},
yaxis: {
pad: 1.1
}
},
seriesColors: colors
});
spectra.replot();
}
function histdiagram(numbers)
{
// find the largest entry to determine the range of the plot
var n = Math.max.apply( null, numbers);
var mult = Math.pow(10, 2 - Math.floor(Math.log(n) / Math.LN10) - 1); //round to two s.f.
var n = Math.round(n * mult) / mult;
var largest = n * 1.1;
// Switch to HISTOGRAM TAB and then plot the histogram
diagramplot.histogram = numbers;
switch_tabs($('.histtab'));
$.jqplot.config.enablePlugins = true;
hist = $.jqplot('histPlace', [numbers], {
title: collection,
seriesDefaults:{
renderer: $.jqplot.BarRenderer,
rendererOptions: {
barMargin: 5
},
showMarker: false,
pointLabels: { show: false }
},
axes: {
xaxis: {
renderer: $.jqplot.CategoryAxisRenderer,
pad: 0
},
yaxis: {
min: 0,
max: largest
}
},
highlighter: {
sizeAdjust: 7.5
},
cursor: {
show: false
}
});
hist.replot();
}
function crossdiagram(numbers)
{
var nodata = dtmdataset.nodata;
// Switch to CROSS TAB and then plot the cross diagram
switch_tabs($('.crosstab'));
diagramplot.crosssection = numbers;
$.jqplot.config.enablePlugins = true;
cross = $.jqplot('crossPlace', numbers, {
title: 'Cross Section',
cursor: {
show: true,
zoom : true
},
highlighter : {
show : true
},
series: [{breakOnNull: true}],
seriesDefaults: {
renderer: $.jqplot.LineRenderer,
lineWidth: 1,
rendererOptions: {
smooth: true,
animation: {
show: true
}
},
showMarker: false,
pointLabels: {
show: false
}
}
});
cross.replot();
}
function histogramtocsv(numbers)
{
string = "BIN,COUNT\n";
for(var i = 0; i < numbers.length; i++)
{
j = i + 1;
string = string + j + "," + numbers[i] + "\n";
}
return string;
}
function spectrumtocsv(numbers)
{
headerstring = "WAVELENGTH,";
for(var i = 0; i < numbers.length; i++)
{
spectrumcolumn = "SPECTRUM" + (i + 1);
headerstring = headerstring + spectrumcolumn + ",";
}
string = headerstring + "\n";
for(var i = 0; i < numbers[0].length; i++)
{
string = string + numbers[0][i][0] + "," + numbers[0][i][1];
for(var j = 1; j < numbers.length; j++)
{
string = string + "," + numbers[j][i][1];
}
string = string + "\n";
}
return string;
}
function crosssectiontocsv(numbers)
{
string = "METER,ELEVATION\n";
for(var i = 0; i < numbers[0].length; i++)
{
string = string + numbers[0][i][0] + "," + numbers[0][i][1] + "\n";
}
return string;
}