Skip to content

Commit 4bc3292

Browse files
committed
update
1 parent 1cfd7df commit 4bc3292

File tree

5 files changed

+121
-243
lines changed

5 files changed

+121
-243
lines changed

src/js/dataOp.js

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,7 @@ function copyThis() {
99

1010
function pasteThis() {
1111
var [t1, t2] = JSON.parse(copyVar);
12-
if(!t1.every((v,i)=>v===data[th_in][col.y][i])){
13-
alertElec("Copy paste between different data set is not supported!")
14-
return;
15-
}
12+
if(!t1.every((v,i)=>v===data[th_in][col.y][i])) alertElec("Copy paste between different data set is not supported!")
1613
saveOldData();
1714
data[th_in][col.y] = t1
1815
data[th_in][col.z] = t2
@@ -21,7 +18,6 @@ function pasteThis() {
2118

2219

2320
function swapData() {
24-
if (!swapperIsOn) return;
2521
saveOldData();
2622
for (let i of index) [data[th_in][col.z][i], data[th_in][col.s][i]] = [data[th_in][col.s][i], data[th_in][col.z][i]]
2723
endJobs({minimal:false})
@@ -43,10 +39,10 @@ function moveReflect(right, mirror){
4339
function repeatMirror() {
4440
last = parseFloat($("#einp").val());
4541
times = parseFloat($("#etime").val());
46-
if(!last|!times) { showStatus('Invalid inputs.'); return}
42+
if(!last|!times) alertElec('Invalid inputs.')
4743
mirror = $("#repSel")[0].selectedIndex;
4844

49-
if(! data.every(e=>e[col.y].includes(last))){ alertElec("Endpoint must exist !!!"); return}
45+
if(! data.every(e=>e[col.y].includes(last))) alertElec("Endpoint must exist !!!")
5046

5147
data = repeatMirrorData(data, col.y, last, times, mirror)
5248
endJobs({startdrag:true,minimal:false})
@@ -56,23 +52,18 @@ function repeatMirror() {
5652

5753

5854
function dataFiller() {
59-
start= parseFloat($("#fstart").val());
60-
stop = parseFloat($("#fend").val());
61-
step = parseFloat($("#fstep").val());
55+
let start= parseFloat($("#fstart").val());
56+
let stop = parseFloat($("#fend").val());
57+
let step = parseFloat($("#fstep").val());
58+
let allowRegression = $("#expSel")[0].selectedIndex ? true : false;
6259
if(document.getElementById('gridSel').selectedIndex) {
63-
if(step != parseInt(step)) {
64-
alertElec("Number of grid must be integer")
65-
}
60+
if(step != parseInt(step)) alertElec("Number of grid must be integer")
6661
step = (stop-start)/(step -1)
6762
}
6863

69-
if(isNaN(start)|isNaN(step)|!step) { showStatus('Invalid inputs.'); return}
70-
let allowRegression = $("#expSel")[0].selectedIndex ? true : false;
64+
if(isNaN(start)|isNaN(step)|!step) alertElec('Invalid inputs.')
7165

72-
if(!data[0][col.y].every((i,j,k)=> j==0 ? true:i>k[j-1])){
73-
alertElec('Monotonically increasing values required for interpolation.')
74-
return
75-
}
66+
if(!data[0][col.y].every((i,j,k)=> j==0 ? true:i>k[j-1])) alertElec('Monotonically increasing values required for interpolation.')
7667

7768
data = fillMissingGrid(data, ddd, col, allowRegression, start, stop, step )
7869
endJobs({startdrag:true,minimal:false})
@@ -170,12 +161,21 @@ function autoSmooth() {
170161
let ind = index.filter((i)=>i<dpsx.length)
171162
if(!ind.length) throw {ty:'sS', msg: "No data points selected."}
172163
if(ind.includes(0) || ind.includes(dpsx.length-1)) throw {ty:'sS', msg: "Can't apply mooving average at endpoints"}
173-
for (let i of ind) dpsy[i] = (dpsy[i - 1] + dpsy[i] + dpsy[i + 1]) / 3.0
164+
// for (let i of ind) dpsy[i] = (dpsy[i - 1] + dpsy[i] + dpsy[i + 1]) / 3.0
165+
for (let i of ind) dpsy[i] = _mv( dpsx.slice(i-1,i+2),dpsy.slice(i-1,i+2)) // for uneven grid
174166
data[th_in][col.z] = dpsy;
175167
endJobs({serVerUpdate:false})
176168
} catch(e){
177169
e.ty=='sS' ? showStatus(e.msg) : console.error(e.stack)
178170
}
171+
function _mv(xx,yy){
172+
// xx and yy should be a length of 3
173+
h = xx[1] - xx[0]
174+
hp= xx[2] - xx[1]
175+
val = ( yy[0]/h + yy[2]/hp )/( 1.0/h + 1.0/hp)
176+
177+
return (yy[1]+val)/2.0
178+
}
179179
}
180180

181181

@@ -193,7 +193,7 @@ function setValue(val){
193193
saveOldData();
194194
let value = parseFloat(val);
195195
if (isNaN(value) ) return;
196-
for (let ind of index) data[th_in][col.z][ind] = value;
196+
for (let i of index) data[th_in][col.z][i] = value;
197197
endJobs()
198198
}
199199

0 commit comments

Comments
 (0)