Skip to content

Commit 7104be8

Browse files
committed
Code issues improvement
1 parent 29d6d7b commit 7104be8

File tree

1 file changed

+47
-47
lines changed

1 file changed

+47
-47
lines changed

src/graph_imported_curves.js

Lines changed: 47 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -12,57 +12,57 @@ export function ImportedCurves(curvesChanged) {
1212
};
1313

1414
this.importCurvesFromCSV = function(files) {
15-
let importsLeft = maxImportCount - this._curvesData.length;
15+
let importsLeft = maxImportCount - this._curvesData.length;
1616

17-
for (const file of files) {
18-
if (importsLeft-- == 0) {
19-
break;
20-
}
21-
const reader = new FileReader();
22-
reader.onload = function (e) {
23-
try {
24-
const stringRows = e.target.result.split("\n");
25-
26-
const header = stringRows[0].split(",");
27-
if (header.length != 2 || header[0] != "x" || header[1] != "y") {
28-
throw new SyntaxError("Wrong curves CSV data format");
29-
}
17+
for (const file of files) {
18+
if (importsLeft-- == 0) {
19+
break;
20+
}
21+
const reader = new FileReader();
22+
reader.onload = function (e) {
23+
try {
24+
const stringRows = e.target.result.split("\n");
3025

31-
stringRows.shift();
32-
//remove bad last row
33-
if (stringRows.at(-1) == "") {
34-
stringRows.pop();
35-
}
26+
const header = stringRows[0].split(",");
27+
if (header.length != 2 || header[0] != "x" || header[1] != "y") {
28+
throw new SyntaxError("Wrong curves CSV data format");
29+
}
3630

37-
const curvesData = stringRows.map( function(row) {
38-
const data = row.split(","),
39-
x = parseFloat(data[0]),
40-
y = parseFloat(data[1]);
41-
_that.minX = Math.min(x, _that.minX);
42-
_that.maxX = Math.max(x, _that.maxX);
43-
_that.minY = Math.min(y, _that.minY);
44-
_that.maxY = Math.max(y, _that.maxY);
45-
return {
46-
x: x,
47-
y: y,
48-
};
49-
});
31+
stringRows.shift();
32+
//remove bad last row
33+
if (stringRows.at(-1) == "") {
34+
stringRows.pop();
35+
}
5036

51-
const curve = {
52-
name: file.name.split('.')[0],
53-
points: curvesData,
37+
const curvesData = stringRows.map( function(row) {
38+
const data = row.split(","),
39+
x = parseFloat(data[0]),
40+
y = parseFloat(data[1]);
41+
_that.minX = Math.min(x, _that.minX);
42+
_that.maxX = Math.max(x, _that.maxX);
43+
_that.minY = Math.min(y, _that.minY);
44+
_that.maxY = Math.max(y, _that.maxY);
45+
return {
46+
x: x,
47+
y: y,
5448
};
55-
_that._curvesData.push(curve);
56-
curvesChanged();
57-
} catch (e) {
58-
alert('Curves data import error: ' + e.message);
59-
return;
60-
}
61-
};
49+
});
6250

63-
reader.readAsText(file);
64-
}
65-
};
51+
const curve = {
52+
name: file.name.split('.')[0],
53+
points: curvesData,
54+
};
55+
_that._curvesData.push(curve);
56+
curvesChanged();
57+
} catch (e) {
58+
alert('Curves data import error: ' + e.message);
59+
return;
60+
}
61+
};
62+
63+
reader.readAsText(file);
64+
}
65+
};
6666

6767
this.addCurve = function(points, name) {
6868
this._curvesData.push({
@@ -76,7 +76,7 @@ export function ImportedCurves(curvesChanged) {
7676
this.maxY = Math.max(point.y, _that.maxY);
7777
}
7878
curvesChanged();
79-
}
79+
};
8080

8181
this.isNewCurve = function(name) {
8282
for (const curve of this._curvesData) {
@@ -85,7 +85,7 @@ export function ImportedCurves(curvesChanged) {
8585
}
8686
}
8787
return true;
88-
}
88+
};
8989

9090
this.removeCurves = function() {
9191
this._curvesData.length = 0;

0 commit comments

Comments
 (0)