Skip to content

Commit

Permalink
Merge pull request #310 from mgreminger/interp-plot-bug
Browse files Browse the repository at this point in the history
fix: fix interpolation function plotting bug
  • Loading branch information
mgreminger authored Dec 23, 2024
2 parents 43205e8 + 29226bc commit 306bd45
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 4 deletions.
6 changes: 2 additions & 4 deletions src/parser/LatexToSympy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1282,7 +1282,7 @@ export class LatexToSympy extends LatexParserVisitor<string | Statement | UnitBl
unitQueryArgument.sympy = newArguments[0].sympy;
} else {
// numerical lower limit without units, replace with unitless implicit param to prevent cancelling
unitQueryArgument.sympy = this.getUnitlessImplicitParam();
unitQueryArgument.sympy = this.getUnitlessImplicitParam(newArguments[0].sympy);
}

unitQueryArgument.params = this.params.slice(initialParamCursor);
Expand Down Expand Up @@ -2083,14 +2083,12 @@ export class LatexToSympy extends LatexParserVisitor<string | Statement | UnitBl
}
}

getUnitlessImplicitParam(value=1): string {
getUnitlessImplicitParam(valueString:string): string {
const newParamName = this.getNextParName();

const units = 'm/m';
const mathjsUnits = unit(units);

const valueString = value.toString();

let param: ImplicitParameter = {
name: newParamName,
units: units,
Expand Down
32 changes: 32 additions & 0 deletions tests/test_data_table.spec.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -1355,4 +1355,36 @@ test('Test data table user function exponent bug', async () => {

let content = await page.textContent(`#result-value-1`);
expect(content).toBe(String.raw`\begin{bmatrix} 2\left\lbrack m\right\rbrack \\ 4\left\lbrack m\right\rbrack \\ 8\left\lbrack m\right\rbrack \end{bmatrix}`);
});

test('Test linear interpolation with plotting', async () => {
const modifierKey = (await page.evaluate('window.modifierKey') )=== "metaKey" ? "Meta" : "Control";

await page.locator('#add-data-table-cell').click();

await page.locator('#data-table-input-1-0-0').click();

await page.keyboard.type('10');
await page.keyboard.press('Tab');
await page.keyboard.type('1');
await page.keyboard.press('Enter');

await page.keyboard.type('20');
await page.keyboard.press('Tab');
await page.keyboard.type('2');
await page.keyboard.press('Enter');

await page.keyboard.type('30');
await page.keyboard.press('Tab');
await page.keyboard.type('3');

await page.getByRole('button', { name: 'Add Interpolation' }).click();
await page.getByLabel('Copy function name to').click();

await page.locator('#cell-0 >> math-field.editable').type('(x,');
await page.locator('#cell-0 >> math-field.editable').press(modifierKey+'+v');
await page.locator('#cell-0 >> math-field.editable').type('(x)) for (10<=x<=30)=');

await page.waitForSelector('div.status-footer', {state: 'detached'});
await expect(page.locator('g.trace.scatter')).toBeVisible();
});

0 comments on commit 306bd45

Please sign in to comment.