Skip to content

Commit

Permalink
feat: handle user update and resetting of input/output cols for inter…
Browse files Browse the repository at this point in the history
…polation
  • Loading branch information
mgreminger committed Jul 27, 2024
1 parent f009375 commit d3dd7ac
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 1 deletion.
3 changes: 3 additions & 0 deletions src/DataTableCell.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,10 @@
}
function handleInputOutputChange(defIndex: number) {
dataTableCell.setInterpolationFunctions();
$mathCellChanged = true;
$cells[index] = $cells[index];
}
function handleDeleteInterpoloationDef(defIndex: number) {
Expand Down
51 changes: 50 additions & 1 deletion src/cells/DataTableCell.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,23 @@ export default class DataTableCell extends BaseCell {
};
}

isInterpolationCol(column: number) {
const interpolationColSet = new Set();
for(const def of this.interpolationDefinitions) {
interpolationColSet.add(def.input);
interpolationColSet.add(def.output);
}

return interpolationColSet.has(column);
}

parseColumn(column: number) {
const isInterpolationCol = this.isInterpolationCol(column);

if (this.columnIsOutput[column]) {
if (isInterpolationCol) {
this.fixInterpolationCols();
}
return;
}

Expand Down Expand Up @@ -161,10 +176,13 @@ export default class DataTableCell extends BaseCell {
this.columnErrors[column] = "Error parsing column data, check that all column number entries are either decimal numbers or integer numbers";
this.columnStatements[column] = null;
}

} else {
this.columnStatements[column] = null;
}

if (isInterpolationCol) {
this.setInterpolationFunctions();
}
}

addRow() {
Expand Down Expand Up @@ -267,9 +285,40 @@ export default class DataTableCell extends BaseCell {
this.interpolationDefinitions = [...this.interpolationDefinitions.slice(0,index), ...this.interpolationDefinitions.slice(index+1)];
}

fixInterpolationCols() {
const dataCols = new Set(this.columnIsOutput.map((value, i) => value ? -1 : i).filter(value => value >= 0));
if (dataCols.size < 2) {
// not enough cols to perform interpolation
this.interpolationDefinitions = [];
return;
}

const firstValidCol = Array.from(dataCols)[0];

for (const def of this.interpolationDefinitions) {
if (!dataCols.has(def.input)) {
def.input = firstValidCol;
}
if (!dataCols.has(def.output)) {
def.output = firstValidCol;
}

if (def.input === def.output) {
for (const col of dataCols) {
if (col != def.output) {
def.output = col;
break;
}
}
}
}
}

setInterpolationFunctions() {
this.interpolationFunctions = [];

this.fixInterpolationCols();

for(const def of this.interpolationDefinitions) {
if (def.nameField.statement?.type !== "parameter") {
console.warn('Interpolation function name parsing error');
Expand Down

0 comments on commit d3dd7ac

Please sign in to comment.