Skip to content

Commit

Permalink
feat: display error messages for scatter plot errors
Browse files Browse the repository at this point in the history
Add tests for all scatter plot error paths and fix some scatter plot error issues
  • Loading branch information
mgreminger committed Nov 5, 2023
1 parent 4e91303 commit 98b6b51
Show file tree
Hide file tree
Showing 3 changed files with 230 additions and 41 deletions.
8 changes: 4 additions & 4 deletions public/dimensional_analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -1373,7 +1373,7 @@ def get_range_result(range_result: CombinedExpressionRange,
"outputNameLatex": custom_latex(sympify(range_result["outputName"])) }] }

def get_scatter_error_object(error_message: str) -> PlotResult:
return {"plot": True, "data": [{"isScatter": True, "numericOutput": True, "numericInput": True,
return {"plot": True, "data": [{"isScatter": True, "numericOutput": False, "numericInput": True,
"limitsUnitsMatch": True, "input": [], "output": [], "inputReversed": False,
"inputUnits": "", "inputUnitsLatex": "", "inputName": "", "inputNameLatex": "",
"outputUnits": "", "outputUnitsLatex": "", "outputName": "", "outputNameLatex": "",
Expand All @@ -1385,7 +1385,7 @@ def get_scatter_plot_result(combined_scatter: CombinedExpressionScatter,

if (is_not_matrix_result(scatter_x_values) and (is_matrix_result(scatter_y_values))) or \
(is_not_matrix_result(scatter_y_values) and (is_matrix_result(scatter_x_values))):
return get_scatter_error_object("Both the x and y values for a scatter need to be a scalar value or a vector")
return get_scatter_error_object("Both the x and y values need to be a scalar value or a vector")

if (is_matrix_result(scatter_x_values)) and (is_matrix_result(scatter_y_values)):
x_num_rows = len(scatter_x_values["results"])
Expand Down Expand Up @@ -1439,8 +1439,8 @@ def get_scatter_plot_result(combined_scatter: CombinedExpressionScatter,
if not y_values_all_real_and_finite:
return get_scatter_error_object("One or more y values does not evaluate to a finite real value")

if len(x_units_check) > 1 or \
(("Dimension Error" in x_units_check) or ("Exponent Not Dimensionless" in x_units_check)):
if len(y_units_check) > 1 or \
(("Dimension Error" in y_units_check) or ("Exponent Not Dimensionless" in y_units_check)):
return get_scatter_error_object("One or more of the y values has inconsistent units or a dimension error")

return {"plot": True, "data": [{"isScatter": True, "asLines": combined_scatter["asLines"],
Expand Down
81 changes: 44 additions & 37 deletions src/PlotCell.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -521,43 +521,50 @@
<span slot="tooltipText">{mathField.parsingErrorMessage}</span>
<Error class="error"/>
</TooltipIcon>
{:else if mathField.latex && $results[index] && $results[index][i]?.plot && !$results[index][i].data[0].numericInput}
<TooltipIcon direction="right" align="end">
<span slot="tooltipText">X-axis limits of plot do not evaluate to a number</span>
<Error class="error"/>
</TooltipIcon>
{:else if mathField.latex && $results[index] && $results[index][i]?.plot > 0 && !$results[index][i].data[0].limitsUnitsMatch}
<TooltipIcon direction="right" align="end">
<span slot="tooltipText">Units of the x-axis upper and lower limits do not match</span>
<Error class="error"/>
</TooltipIcon>
{:else if mathField.latex && $results[index] && $results[index][i]?.plot > 0 && !$results[index][i].data[0].numericOutput}
<TooltipIcon direction="right" align="end">
<span slot="tooltipText">Results of expression does not evaluate to finite and real numeric values</span>
<Error class="error"/>
</TooltipIcon>
{:else if mathField.latex && $results[index] && $results[index][i]?.plot > 0 && !unitsValid($results[index][i].data[0].displayInputUnits)}
<TooltipIcon direction="right" align="end">
<span slot="tooltipText">X-axis upper and/or lower limit dimension error{$results[index][i].data[0].asciiInputUnits === "Exponent Not Dimensionless" ? ": Exponent Not Dimensionless": ""}</span>
<Error class="error"/>
</TooltipIcon>
{:else if mathField.latex && $results[index] && $results[index][i]?.plot > 0 && !unitsValid($results[index][i].data[0].displayOutputUnits)}
<TooltipIcon direction="right" align="end">
<span slot="tooltipText">Y-axis dimension error{$results[index][i].data[0].asciiOutputUnits === "Exponent Not Dimensionless" ? ": Exponent Not Dimensionless": ""}</span>
<Error class="error"/>
</TooltipIcon>
{:else if mathField.latex && $results[index] && $results[index][i]?.plot > 0 && $results[index][i].data[0].unitsMismatch}
<TooltipIcon direction="right" align="end">
<span slot="tooltipText">
{ $results[index][i].data[0].unitsMismatchReason ? $results[index][i].data[0].unitsMismatchReason : "Units Mismatch" }
</span>
<Error class="error"/>
</TooltipIcon>
{:else if mathField.latex && $results[index] && $results[index][i]?.plot > 0 && $results[index][i].data[0].inputReversed}
<TooltipIcon direction="right" align="end">
<span slot="tooltipText">X-axis upper and lower limits are reversed</span>
<Error class="error"/>
</TooltipIcon>
{:else if mathField.latex && $results[index] && $results[index][i]?.plot}
{#if $results[index][i].data[0].scatterErrorMessage}
<TooltipIcon direction="right" align="end">
<span slot="tooltipText">{$results[index][i].data[0].scatterErrorMessage}</span>
<Error class="error"/>
</TooltipIcon>
{:else if !$results[index][i].data[0].numericInput}
<TooltipIcon direction="right" align="end">
<span slot="tooltipText">X-axis limits of plot do not evaluate to a number</span>
<Error class="error"/>
</TooltipIcon>
{:else if !$results[index][i].data[0].limitsUnitsMatch}
<TooltipIcon direction="right" align="end">
<span slot="tooltipText">Units of the x-axis upper and lower limits do not match</span>
<Error class="error"/>
</TooltipIcon>
{:else if !$results[index][i].data[0].numericOutput}
<TooltipIcon direction="right" align="end">
<span slot="tooltipText">Results of expression does not evaluate to finite and real numeric values</span>
<Error class="error"/>
</TooltipIcon>
{:else if !unitsValid($results[index][i].data[0].displayInputUnits)}
<TooltipIcon direction="right" align="end">
<span slot="tooltipText">X-axis upper and/or lower limit dimension error{$results[index][i].data[0].asciiInputUnits === "Exponent Not Dimensionless" ? ": Exponent Not Dimensionless": ""}</span>
<Error class="error"/>
</TooltipIcon>
{:else if !unitsValid($results[index][i].data[0].displayOutputUnits)}
<TooltipIcon direction="right" align="end">
<span slot="tooltipText">Y-axis dimension error{$results[index][i].data[0].asciiOutputUnits === "Exponent Not Dimensionless" ? ": Exponent Not Dimensionless": ""}</span>
<Error class="error"/>
</TooltipIcon>
{:else if $results[index][i].data[0].unitsMismatch}
<TooltipIcon direction="right" align="end">
<span slot="tooltipText">
{ $results[index][i].data[0].unitsMismatchReason ? $results[index][i].data[0].unitsMismatchReason : "Units Mismatch" }
</span>
<Error class="error"/>
</TooltipIcon>
{:else if $results[index][i].data[0].inputReversed}
<TooltipIcon direction="right" align="end">
<span slot="tooltipText">X-axis upper and lower limits are reversed</span>
<Error class="error"/>
</TooltipIcon>
{/if}
{/if}
</div>

Expand Down
182 changes: 182 additions & 0 deletions tests/test_plotting.spec.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -404,4 +404,186 @@ test('Make sure second curve is plotted if first plot has error', async ({ brows
await page.locator('text=Copy Data').click();
await page.locator('text=Copied!').waitFor({state: "attached", timeout: 1000});

});

test('test scatter plot x-y scalar vector mismatch', async ({ browserName }) => {

await page.setLatex(0, String.raw`x=\begin{bmatrix}1\\ 2\end{bmatrix},\:y=2`);

await page.locator('#add-plot-cell').click();
await page.setLatex(1, String.raw`x,y=`, 0);

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

await page.locator('#plot-expression-1-0 >> text=Both the x and y values need to be a scalar value or a vector').waitFor({state: 'attached', timeout: 1000});

});

test('test scatter plot x-y scalar vector size mismatch', async ({ browserName }) => {

await page.setLatex(0, String.raw`x=\begin{bmatrix}1\\ 2\end{bmatrix},\:y=\begin{bmatrix}1\\ 2\\ 3\end{bmatrix}`);

await page.locator('#add-plot-cell').click();
await page.setLatex(1, String.raw`x,y=`, 0);

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

await page.locator('#plot-expression-1-0 >> text=Both the x and y values need to be either column or row vectors of the same size').waitFor({state: 'attached', timeout: 1000});

});

test('test scatter plot x matrix but not vector', async ({ browserName }) => {

await page.setLatex(0, String.raw`x=\begin{bmatrix}1 & 1\\ 2 & 2\end{bmatrix},\:y=\begin{bmatrix}1\\ 2\end{bmatrix}`);

await page.locator('#add-plot-cell').click();
await page.setLatex(1, String.raw`x,y=`, 0);

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

await page.locator('#plot-expression-1-0 >> text=Both the x and y values need to be either column or row vectors of the same size').waitFor({state: 'attached', timeout: 1000});

});

test('test scatter plot y matrix but not vector', async ({ browserName }) => {

await page.setLatex(0, String.raw`x=\begin{bmatrix}1\\ 2\end{bmatrix},\:y=\begin{bmatrix}1 & 1\\ 2 & 2\end{bmatrix}`);

await page.locator('#add-plot-cell').click();
await page.setLatex(1, String.raw`x,y=`, 0);

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

await page.locator('#plot-expression-1-0 >> text=Both the x and y values need to be either column or row vectors of the same size').waitFor({state: 'attached', timeout: 1000});

});

test('test scatter plot x not a number', async ({ browserName }) => {

await page.setLatex(0, String.raw`x=\begin{bmatrix}1\\ a\end{bmatrix},\:y=\begin{bmatrix}1\\ 2\end{bmatrix}`);

await page.locator('#add-plot-cell').click();
await page.setLatex(1, String.raw`x,y=`, 0);

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

await page.locator('#plot-expression-1-0 >> text=One or more x values does not evaluate to a finite real value').waitFor({state: 'attached', timeout: 1000});

});

test('test scatter plot y not a number', async ({ browserName }) => {

await page.setLatex(0, String.raw`x=\begin{bmatrix}1\\ 2\end{bmatrix},\:y=\begin{bmatrix}1\\ a\end{bmatrix}`);

await page.locator('#add-plot-cell').click();
await page.setLatex(1, String.raw`x,y=`, 0);

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

await page.locator('#plot-expression-1-0 >> text=One or more y values does not evaluate to a finite real value').waitFor({state: 'attached', timeout: 1000});

});

test('test scatter plot x not finite', async ({ browserName }) => {

await page.setLatex(0, String.raw`x=\begin{bmatrix}1\\ \frac10\end{bmatrix},\:y=\begin{bmatrix}1\\ 2\end{bmatrix}`);

await page.locator('#add-plot-cell').click();
await page.setLatex(1, String.raw`x,y=`, 0);

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

await page.locator('#plot-expression-1-0 >> text=One or more x values does not evaluate to a finite real value').waitFor({state: 'attached', timeout: 1000});

});

test('test scatter plot y not finite', async ({ browserName }) => {

await page.setLatex(0, String.raw`x=\begin{bmatrix}1\\ 2\end{bmatrix},\:y=\begin{bmatrix}1\\ \frac10\end{bmatrix}`);

await page.locator('#add-plot-cell').click();
await page.setLatex(1, String.raw`x,y=`, 0);

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

await page.locator('#plot-expression-1-0 >> text=One or more y values does not evaluate to a finite real value').waitFor({state: 'attached', timeout: 1000});

});

test('test scatter plot x not real', async ({ browserName }) => {

await page.setLatex(0, String.raw`x=\begin{bmatrix}1\\ i\end{bmatrix},\:y=\begin{bmatrix}1\\ 3\end{bmatrix}`);

await page.locator('#add-plot-cell').click();
await page.setLatex(1, String.raw`x,y=`, 0);

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

await page.locator('#plot-expression-1-0 >> text=One or more x values does not evaluate to a finite real value').waitFor({state: 'attached', timeout: 1000});

});

test('test scatter plot y not real', async ({ browserName }) => {

await page.setLatex(0, String.raw`x=\begin{bmatrix}1\\ 2\end{bmatrix},\:y=\begin{bmatrix}1\\ i\end{bmatrix}`);

await page.locator('#add-plot-cell').click();
await page.setLatex(1, String.raw`x,y=`, 0);

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

await page.locator('#plot-expression-1-0 >> text=One or more y values does not evaluate to a finite real value').waitFor({state: 'attached', timeout: 1000});

});

test('test scatter plot x has dimension error', async ({ browserName }) => {

await page.setLatex(0, String.raw`x=\begin{bmatrix}1\\ 2+1\left\lbrack in\right\rbrack\end{bmatrix},\:y=\begin{bmatrix}1\\ 2\end{bmatrix}`);

await page.locator('#add-plot-cell').click();
await page.setLatex(1, String.raw`x,y=`, 0);

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

await page.locator('#plot-expression-1-0 >> text=One or more of the x values has inconsistent units or a dimension error').waitFor({state: 'attached', timeout: 1000});

});

test('test scatter plot y has dimension error', async ({ browserName }) => {

await page.setLatex(0, String.raw`x=\begin{bmatrix}1\\ 2\end{bmatrix},\:y=\begin{bmatrix}1\\ 2+1\left\lbrack in\right\rbrack\end{bmatrix}`);

await page.locator('#add-plot-cell').click();
await page.setLatex(1, String.raw`x,y=`, 0);

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

await page.locator('#plot-expression-1-0 >> text=One or more of the y values has inconsistent units or a dimension error').waitFor({state: 'attached', timeout: 1000});

});

test('test scatter plot x has inconsistent units', async ({ browserName }) => {

await page.setLatex(0, String.raw`x=\begin{bmatrix}1\\ 2\left\lbrack in\right\rbrack\end{bmatrix},\:y=\begin{bmatrix}1\\ 2\end{bmatrix}`);

await page.locator('#add-plot-cell').click();
await page.setLatex(1, String.raw`x,y=`, 0);

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

await page.locator('#plot-expression-1-0 >> text=One or more of the x values has inconsistent units or a dimension error').waitFor({state: 'attached', timeout: 1000});

});

test('test scatter plot y has inconsistent units', async ({ browserName }) => {

await page.setLatex(0, String.raw`x=\begin{bmatrix}1\\ 2\end{bmatrix},\:y=\begin{bmatrix}1\\ 2\left\lbrack in\right\rbrack\end{bmatrix}`);

await page.locator('#add-plot-cell').click();
await page.setLatex(1, String.raw`x,y=`, 0);

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

await page.locator('#plot-expression-1-0 >> text=One or more of the y values has inconsistent units or a dimension error').waitFor({state: 'attached', timeout: 1000});

});

0 comments on commit 98b6b51

Please sign in to comment.