Skip to content

Commit

Permalink
fix: fix issues with $effect in plot cell
Browse files Browse the repository at this point in the history
Change $effect to $derived.by
  • Loading branch information
mgreminger committed Dec 27, 2024
1 parent 47106de commit 03cd489
Show file tree
Hide file tree
Showing 37 changed files with 180 additions and 151 deletions.
8 changes: 4 additions & 4 deletions src/App.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@
// Used for testing to force new sheet even with unsaved changes.
// This is necessary since dismissing the unsaved changes dialog in playwright doesn't work after the first
// time it is requested.
(window as any).forceLoadBlankSheet = () => {$unsavedChange = false; loadBlankSheet();};
(window as any).forceLoadBlankSheet = async () => {$unsavedChange = false; await loadBlankSheet();};
// Used for testing to simplify the deleting of cells
// The two-step delete, delete and then delete the undo delete cell,
Expand Down Expand Up @@ -714,7 +714,7 @@
currentStateObject = null;
await resetSheet();
await tick();
addCell('math');
await addCell('math');
await tick();
$unsavedChange = false;
$autosaveNeeded = false;
Expand Down Expand Up @@ -788,9 +788,9 @@
}
}
function loadBlankSheet() {
async function loadBlankSheet() {
window.history.pushState(null, "", "/");
refreshSheet(); // pushState does not trigger onpopstate event
await refreshSheet(); // pushState does not trigger onpopstate event
}
function getResults(statementsAndSystems: string, myRefreshCount: BigInt,
Expand Down
1 change: 0 additions & 1 deletion src/CellList.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,6 @@
class="sheet-body"
bind:this={sheetBody}
>

{#each $cells as cell, i (cell.id)}
<li>
<ButtonBar {insertSheet} index={i} />
Expand Down
2 changes: 1 addition & 1 deletion src/Plot.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
Plotly
} = $props();
let plotElement = $state();
let plotElement;
let plotCreated = false;
let currentPlotPromise = null;
let mathJaxPassCompleted = false;
Expand Down
227 changes: 134 additions & 93 deletions src/PlotCell.svelte

Large diffs are not rendered by default.

12 changes: 4 additions & 8 deletions src/resultTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ export function isDataTableResult(result: Result | FiniteImagResult | MatrixResu
return "dataTableResult" in result && result.dataTableResult;
}

export function isPlotResult(result: Result | FiniteImagResult | MatrixResult | DataTableResult | PlotResult[]): result is PlotResult[] {
return result instanceof Array && result[0].plot;
}

export type PlotData = {
numericOutput: boolean;
numericInput: boolean;
Expand All @@ -78,14 +82,6 @@ export type PlotData = {
asLines?: boolean; // optional, only used for scatter plots
scatterErrorMessage?: string; // optional, only used for scatter plots
parametricErrorMessage?: string; // optional, only used for parametric plots
unitsMismatch?: boolean; // the rest of the optional properties are added in TS and not present in json from Python
displayInput?: number[];
displayInputUnits?: string;
asciiInputUnits?: string;
unitsMismatchReason?: string;
displayOutput?: number[];
displayOutputUnits?: string;
asciiOutputUnits?: string;
};

export type PlotResult = {
Expand Down
2 changes: 1 addition & 1 deletion tests/test_advanced_assignments.spec.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ let page;
test.beforeAll(async ({ browser }) => {page = await loadPyodide(browser, page);} );

// give each test a blank sheet to start with (this doesn't reload pyodide)
test.beforeEach(async () => newSheet(page));
test.beforeEach(async () => {await newSheet(page)});

test('Check parsing error handling with multiple assignments', async () => {
// syntax error with second entry
Expand Down
2 changes: 1 addition & 1 deletion tests/test_basic.spec.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ let page;
test.beforeAll(async ({ browser }) => {page = await loadPyodide(browser, page);} );

// give each test a blank sheet to start with (this doesn't reload pyodide)
test.beforeEach(async () => newSheet(page));
test.beforeEach(async () => {await newSheet(page)});

test('Test basic functionality', async () => {
// Test basic dimensional analysis and unit conversion
Expand Down
2 changes: 1 addition & 1 deletion tests/test_calc.spec.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ let page;
test.beforeAll(async ({ browser }) => {page = await loadPyodide(browser, page);} );

// give each test a blank sheet to start with (this doesn't reload pyodide)
test.beforeEach(async () => newSheet(page));
test.beforeEach(async () => {await newSheet(page)});


test('test basic calculus', async () => {
Expand Down
2 changes: 1 addition & 1 deletion tests/test_checkpoints.spec.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ let page;
test.beforeAll(async ({ browser }) => {page = await loadPyodide(browser, page);} );

// give each test a blank sheet to start with (this doesn't reload pyodide)
test.beforeEach(async () => newSheet(page));
test.beforeEach(async () => {await newSheet(page)});


test('Test autosave checkpoints', async ({ browserName }) => {
Expand Down
2 changes: 1 addition & 1 deletion tests/test_complex.spec.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ let page;
test.beforeAll(async ({ browser }) => {page = await loadPyodide(browser, page);} );

// give each test a blank sheet to start with (this doesn't reload pyodide)
test.beforeEach(async () => newSheet(page));
test.beforeEach(async () => {await newSheet(page)});


test('Imaginary numbers without units', async () => {
Expand Down
2 changes: 1 addition & 1 deletion tests/test_context_menu.spec.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ let page;
test.beforeAll(async ({ browser }) => {page = await loadPyodide(browser, page);} );

// give each test a blank sheet to start with (this doesn't reload pyodide)
test.beforeEach(async () => newSheet(page));
test.beforeEach(async () => {await newSheet(page)});


test('Context menu copy and select all', async () => {
Expand Down
2 changes: 1 addition & 1 deletion tests/test_custom_base_units.spec.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ let page;
test.beforeAll(async ({ browser }) => {page = await loadPyodide(browser, page);} );

// give each test a blank sheet to start with (this doesn't reload pyodide)
test.beforeEach(async () => newSheet(page));
test.beforeEach(async () => {await newSheet(page)});

test('Test custom base units for math cells', async () => {
await page.setLatex(0, String.raw`1\left\lbrack kg\right\rbrack=`);
Expand Down
2 changes: 1 addition & 1 deletion tests/test_data_table.spec.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ let page;
test.beforeAll(async ({ browser }) => {page = await loadPyodide(browser, page);} );

// give each test a blank sheet to start with (this doesn't reload pyodide)
test.beforeEach(async () => newSheet(page));
test.beforeEach(async () => {await newSheet(page)});

test('Test table assign no units', async () => {
await page.setLatex(0, String.raw`Col1=`);
Expand Down
2 changes: 1 addition & 1 deletion tests/test_ep_custom_units.spec.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ let page;
test.beforeAll(async ({ browser }) => {page = await loadPyodide(browser, page);} );

// give each test a blank sheet to start with (this doesn't reload pyodide)
test.beforeEach(async () => newSheet(page));
test.beforeEach(async () => {await newSheet(page)});

test('Test water viscosity from temperature and pressure', async () => {
const modifierKey = (await page.evaluate('window.modifierKey') )=== "metaKey" ? "Meta" : "Control";
Expand Down
2 changes: 1 addition & 1 deletion tests/test_fluid_properties.spec.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ let page;
test.beforeAll(async ({ browser }) => {page = await loadPyodide(browser, page);} );

// give each test a blank sheet to start with (this doesn't reload pyodide)
test.beforeEach(async () => newSheet(page));
test.beforeEach(async () => {await newSheet(page)});

test('Test water viscosity from temperature and pressure', async () => {
const modifierKey = (await page.evaluate('window.modifierKey') )=== "metaKey" ? "Meta" : "Control";
Expand Down
2 changes: 1 addition & 1 deletion tests/test_functions.spec.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ let page;
test.beforeAll(async ({ browser }) => {page = await loadPyodide(browser, page);} );

// give each test a blank sheet to start with (this doesn't reload pyodide)
test.beforeEach(async () => newSheet(page));
test.beforeEach(async () => {await newSheet(page)});


test('Test trigonometric functions', async () => {
Expand Down
2 changes: 1 addition & 1 deletion tests/test_generated_code.spec.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ let page;
test.beforeAll(async ({ browser }) => {page = await loadPyodide(browser, page);} );

// give each test a blank sheet to start with (this doesn't reload pyodide)
test.beforeEach(async () => newSheet(page));
test.beforeEach(async () => {await newSheet(page)});

test('Unitless function', async () => {
await page.setLatex(0, String.raw`y=x`);
Expand Down
2 changes: 1 addition & 1 deletion tests/test_insert_sheet.spec.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ let page;
test.beforeAll(async ({ browser }) => {page = await loadPyodide(browser, page);} );

// give each test a blank sheet to start with (this doesn't reload pyodide)
test.beforeEach(async () => newSheet(page));
test.beforeEach(async () => {await newSheet(page)});


test('Test sheet insertion', async ({ browserName }) => {
Expand Down
2 changes: 1 addition & 1 deletion tests/test_keyboard_shortcuts.spec.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ let page;
test.beforeAll(async ({ browser }) => {page = await loadPyodide(browser, page);} );

// give each test a blank sheet to start with (this doesn't reload pyodide)
test.beforeEach(async () => newSheet(page));
test.beforeEach(async () => {await newSheet(page)});


test('Test keyboard shortcuts', async ({ browserName }) => {
Expand Down
2 changes: 1 addition & 1 deletion tests/test_latex_scientific_notation.spec.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ let page;
test.beforeAll(async ({ browser }) => {page = await loadPyodide(browser, page);} );

// give each test a blank sheet to start with (this doesn't reload pyodide)
test.beforeEach(async () => newSheet(page));
test.beforeEach(async () => {await newSheet(page)});


test('Test basic latex scientific notation', async () => {
Expand Down
2 changes: 1 addition & 1 deletion tests/test_matrix_addition.spec.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ let page;
test.beforeAll(async ({ browser }) => {page = await loadPyodide(browser, page);} );

// give each test a blank sheet to start with (this doesn't reload pyodide)
test.beforeEach(async () => newSheet(page));
test.beforeEach(async () => {await newSheet(page)});

test('Matrix addition', async () => {
await page.setLatex(0, String.raw`\begin{bmatrix}a & b\\ c & d\end{bmatrix}+\begin{bmatrix}5 & 6\\ 7 & 8\end{bmatrix}=`);
Expand Down
2 changes: 1 addition & 1 deletion tests/test_matrix_calc.spec.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ let page;
test.beforeAll(async ({ browser }) => {page = await loadPyodide(browser, page);} );

// give each test a blank sheet to start with (this doesn't reload pyodide)
test.beforeEach(async () => newSheet(page));
test.beforeEach(async () => {await newSheet(page)});

test('Defininte integral', async () => {
await page.setLatex(0, String.raw`\int_0^1\left(\begin{bmatrix}x & x^2\\ x^3 & x^4\end{bmatrix}\right)\mathrm{d}\left(x\right)=`);
Expand Down
2 changes: 1 addition & 1 deletion tests/test_matrix_determinant.spec.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ let page;
test.beforeAll(async ({ browser }) => {page = await loadPyodide(browser, page);} );

// give each test a blank sheet to start with (this doesn't reload pyodide)
test.beforeEach(async () => newSheet(page));
test.beforeEach(async () => {await newSheet(page)});


test('Determinant of matrix literal using keyboard entry', async () => {
Expand Down
2 changes: 1 addition & 1 deletion tests/test_matrix_functions.spec.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ let page;
test.beforeAll(async ({ browser }) => {page = await loadPyodide(browser, page);} );

// give each test a blank sheet to start with (this doesn't reload pyodide)
test.beforeEach(async () => newSheet(page));
test.beforeEach(async () => {await newSheet(page)});


test('Norm of vector with symbolic entries using all three notations', async () => {
Expand Down
2 changes: 1 addition & 1 deletion tests/test_matrix_indexing.spec.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ let page;
test.beforeAll(async ({ browser }) => {page = await loadPyodide(browser, page);} );

// give each test a blank sheet to start with (this doesn't reload pyodide)
test.beforeEach(async () => newSheet(page));
test.beforeEach(async () => {await newSheet(page)});

test('Indexing square and nonsquare matrix literals', async () => {
await page.setLatex(0, String.raw`\begin{bmatrix}a & b\\ c & d\\ e & f\end{bmatrix}_{1,1}+\begin{bmatrix}a & b\\ c & d\end{bmatrix}_{1,2}+\begin{bmatrix}a & b & c\\ d & e & f\end{bmatrix}_{2,1}+\begin{bmatrix}a & b & c\\ d & e & f\end{bmatrix}_{2,3}=`);
Expand Down
2 changes: 1 addition & 1 deletion tests/test_matrix_inverse.spec.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ let page;
test.beforeAll(async ({ browser }) => {page = await loadPyodide(browser, page);} );

// give each test a blank sheet to start with (this doesn't reload pyodide)
test.beforeEach(async () => newSheet(page));
test.beforeEach(async () => {await newSheet(page)});

test('Matrix inverse numeric', async () => {
await page.setLatex(0, String.raw`\mathrm{inv}\left(\begin{bmatrix}2 & 3\\ 1 & 2\end{bmatrix}\right)=`);
Expand Down
2 changes: 1 addition & 1 deletion tests/test_matrix_keyboard.spec.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ let page;
test.beforeAll(async ({ browser }) => {page = await loadPyodide(browser, page);} );

// give each test a blank sheet to start with (this doesn't reload pyodide)
test.beforeEach(async () => newSheet(page));
test.beforeEach(async () => {await newSheet(page)});

test('Matrix inverse keyboard entry', async () => {
await page.locator('#cell-0 >> math-field.editable').type('1[m]*inv([2,2');
Expand Down
2 changes: 1 addition & 1 deletion tests/test_matrix_multiplication.spec.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ let page;
test.beforeAll(async ({ browser }) => {page = await loadPyodide(browser, page);} );

// give each test a blank sheet to start with (this doesn't reload pyodide)
test.beforeEach(async () => newSheet(page));
test.beforeEach(async () => {await newSheet(page)});

test('Square multiplication', async () => {
await page.setLatex(0, String.raw`\begin{bmatrix}a & b\\ c & d\end{bmatrix}\cdot\begin{bmatrix}5 & 6\\ 7 & 8\end{bmatrix}=`);
Expand Down
2 changes: 1 addition & 1 deletion tests/test_matrix_transpose.spec.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ let page;
test.beforeAll(async ({ browser }) => {page = await loadPyodide(browser, page);} );

// give each test a blank sheet to start with (this doesn't reload pyodide)
test.beforeEach(async () => newSheet(page));
test.beforeEach(async () => {await newSheet(page)});

test('Matrix transpose numeric using function', async () => {
await page.setLatex(0, String.raw`\mathrm{transpose}\left(\begin{bmatrix}1 & 2\\ 3 & 4\end{bmatrix}\right)=`);
Expand Down
2 changes: 1 addition & 1 deletion tests/test_number_format.spec.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ let page;
test.beforeAll(async ({ browser }) => {page = await loadPyodide(browser, page);} );

// give each test a blank sheet to start with (this doesn't reload pyodide)
test.beforeEach(async () => newSheet(page));
test.beforeEach(async () => {await newSheet(page)});

test('Test round trip full precision', async () => {
// enter 100 significant figures of pi to test round trip precision
Expand Down
2 changes: 1 addition & 1 deletion tests/test_piecewise_cell.spec.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ let page;
test.beforeAll(async ({ browser }) => {page = await loadPyodide(browser, page);} );

// give each test a blank sheet to start with (this doesn't reload pyodide)
test.beforeEach(async () => newSheet(page));
test.beforeEach(async () => {await newSheet(page)});


test('Test condition error messages', async ({ browserName }) => {
Expand Down
15 changes: 6 additions & 9 deletions tests/test_plotting.spec.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ let page;
test.beforeAll(async ({ browser }) => {page = await loadPyodide(browser, page);} );

// give each test a blank sheet to start with (this doesn't reload pyodide)
test.beforeEach(async () => newSheet(page));
test.beforeEach(async () => {await newSheet(page)});


test('Test plotting', async ({ browserName }) => {
Expand Down Expand Up @@ -108,21 +108,16 @@ test('Test plotting', async ({ browserName }) => {

// #72
test('Test plot dims with 0 start of range', async ({ browserName }) => {

// Change title
await page.getByRole('heading', { name: 'New Sheet' }).click({ clickCount: 3 });
await page.type('text=New Sheet', 'Title for testing purposes only, will be deleted from database automatically');

// test plot without units

await page.setLatex(0, String.raw`y=1\left[m\right]\cdot x`);
await page.click('#add-math-cell');
await page.setLatex(1, String.raw`y\left(0\le x\le 10\right)=\left[m\right]`);
await expect(page.locator('#cell-1 >> math-field.editable')).toBeVisible();
await expect(page.locator('div.plot-container')).toBeVisible();

await page.waitForSelector('.status-footer', { state: 'detached' });

await expect(() => page.locator('button:has-text("Units Mismatch")').waitFor({timeout: 1000 }))
.rejects.toThrow('Timeout');
.rejects.toThrow('Timeout');

});

Expand Down Expand Up @@ -213,6 +208,8 @@ test('Test plot number of points', async ({ browserName }) => {
}
await page.locator('math-field.editable').nth(2).type('y(0<=x<=1) with 2 points =');

await expect(page.locator('g.trace.scatter')).toBeVisible();

await page.waitForSelector('.status-footer', { state: 'detached' });
[download] = await Promise.all([
page.waitForEvent('download'),
Expand Down
2 changes: 1 addition & 1 deletion tests/test_single_char_scripts.spec.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ let page;
test.beforeAll(async ({ browser }) => {page = await loadPyodide(browser, page);} );

// give each test a blank sheet to start with (this doesn't reload pyodide)
test.beforeEach(async () => newSheet(page));
test.beforeEach(async () => {await newSheet(page)});


test('Test subscript and exponent latex variations', async () => {
Expand Down
2 changes: 1 addition & 1 deletion tests/test_syntax_error_messages.spec.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ let page;
test.beforeAll(async ({ browser }) => {page = await loadPyodide(browser, page);} );

// give each test a blank sheet to start with (this doesn't reload pyodide)
test.beforeEach(async () => newSheet(page));
test.beforeEach(async () => {await newSheet(page)});

test('Error message for empty subscript', async () => {
const modifierKey = (await page.evaluate('window.modifierKey') )=== "metaKey" ? "Meta" : "Control";
Expand Down
2 changes: 1 addition & 1 deletion tests/test_system_solve.spec.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ let page;
test.beforeAll(async ({ browser }) => {page = await loadPyodide(browser, page);} );

// give each test a blank sheet to start with (this doesn't reload pyodide)
test.beforeEach(async () => newSheet(page));
test.beforeEach(async () => {await newSheet(page)});


test('Test equation solving', async () => {
Expand Down
2 changes: 1 addition & 1 deletion tests/test_table_cell.spec.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ let page;
test.beforeAll(async ({ browser }) => {page = await loadPyodide(browser, page);} );

// give each test a blank sheet to start with (this doesn't reload pyodide)
test.beforeEach(async () => newSheet(page));
test.beforeEach(async () => {await newSheet(page)});


test('Test table types in math cells', async () => {
Expand Down
Loading

0 comments on commit 03cd489

Please sign in to comment.