Skip to content

Commit

Permalink
Merge pull request #213 from mgreminger/scatter-plot
Browse files Browse the repository at this point in the history
feat: scatter plot implementation (WIP)
  • Loading branch information
mgreminger authored Nov 14, 2023
2 parents 1a3a5e3 + 505594e commit b21f4c8
Show file tree
Hide file tree
Showing 15 changed files with 2,310 additions and 1,423 deletions.
306 changes: 278 additions & 28 deletions public/dimensional_analysis.py

Large diffs are not rendered by default.

13 changes: 9 additions & 4 deletions src/App.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@
const apiUrl = window.location.origin;
const currentVersion = 20231031;
const currentVersion = 20231113;
const tutorialHash = "fFjTsnFoSQMLwcvteVoNtL";
const termsVersion = 20230608;
Expand All @@ -101,12 +101,16 @@
const exampleSheets = [
{
path: `/${tutorialHash}`,
title: "Introduction to EngineeringPaper"
title: "Introduction to EngineeringPaper"
},
{
path: "/TxAftUqQCmXKNPX5XGBUy8",
path: "/wVCe8d9RNA3rfmMbyTsjA9",
title: "Plotting and Functions"
},
{
path: "/po9iiQkryxWq8saRPS7EYk",
title: "Scatter Plots"
},
{
path: "/DeP4bqfF2H5VbRJz3Nd9Re",
title: "Equation Solving"
Expand Down Expand Up @@ -793,7 +797,8 @@
}
} else if (cell instanceof PlotCell) {
for (const mathField of cell.mathFields) {
if (mathField.statement.type === "query" && mathField.statement.isRange) {
if ( (mathField.statement.type === "query" && mathField.statement.isRange) ||
mathField.statement.type === "scatterQuery") {
mathField.statement.cellNum = cellNum;
}
statements.push(mathField.statement);
Expand Down
6 changes: 3 additions & 3 deletions src/MathCell.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,7 @@
};
}
if ( statement.units_valid &&
statement.units ) {
if ( statement.units ) {
// unit conversion required to user supplied units
resultUnitsLatex = statement.unitsLatex;
resultUnits = statement.units;
Expand Down Expand Up @@ -211,7 +210,8 @@
}
$: if(mathCell.mathField.statement) {
if("isRange" in mathCell.mathField.statement && mathCell.mathField.statement.isRange) {
if(("isRange" in mathCell.mathField.statement && mathCell.mathField.statement.isRange) ||
mathCell.mathField.statement.type === "scatterQuery") {
// user entered range into a math cell, turn this cell into a plot cell
$cells = [...$cells.slice(0,index), new PlotCell(mathCell), ...$cells.slice(index+1)];
}
Expand Down
94 changes: 51 additions & 43 deletions src/PlotCell.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -89,14 +89,15 @@
let userInputUnits: string | undefined;
let userInputUnitsLatex: string | undefined;
if (plotCell.mathFields[0].statement?.type === "query" && plotCell.mathFields[0].statement.isRange) {
if ((plotCell.mathFields[0].statement?.type === "query" && plotCell.mathFields[0].statement.isRange) ||
plotCell.mathFields[0].statement?.type === "scatterQuery") {
// use input units from first plot statement
userInputUnits = plotCell.mathFields[0].statement.input_units;
userInputUnitsLatex = plotCell.mathFields[0].statement.input_units_latex;
userInputUnits = plotCell.mathFields[0].statement.inputUnits;
userInputUnitsLatex = plotCell.mathFields[0].statement.inputUnitsLatex;
}
for (const [j, statement] of plotCell.mathFields.map((field) => field.statement).entries()) {
if ($results[index] && $results[index][j] &&
statement && statement.type === "query" &&
statement && (statement.type === "query" || statement.type === "scatterQuery") &&
$results[index][j].plot) {
for (const data of ($results[index][j] as PlotResult).data) {
data.unitsMismatch = true;
Expand All @@ -121,7 +122,7 @@
}
// convert outputs if units provided
if (statement.units && statement.units_valid) {
if (statement.units) {
const userOutputUnits = statement.units;
const userOutputUnitsLatex = statement.unitsLatex;
Expand Down Expand Up @@ -183,7 +184,7 @@
x: result.data[0].displayInput,
y: result.data[0].displayOutput,
type: "scatter",
mode: "lines",
mode: result.data[0].isScatter && !result.data[0].asLines ? "markers" : "lines",
text: result.data[0].outputName,
hoverinfo: "x+y+text",
name: `$ ${result.data[0].outputNameLatex ?? result.data[0].outputName} $ `,
Expand Down Expand Up @@ -520,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
11 changes: 11 additions & 0 deletions src/Updates.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,17 @@ import { modifierKey } from "./stores";
}
</style>

<em>November 13, 2023</em>
<h4>New Scatter Plotting Feature</h4>
<p>
Scatter plots are now supported by EngineeringPaper.xyz. Scatter plotting
leverages the recently added ability to define vectors. See the
<a href="https://engineeringpaper.xyz/po9iiQkryxWq8saRPS7EYk" target="_blank">
Scatter Plotting Tutorial</a> for details.
</p>

<br>

<em>October 31, 2023</em>
<h4>New <em>ceil</em>, <em>floor</em>, and <em>round</em> Functions Have Been Added</h4>
<p>
Expand Down
2 changes: 2 additions & 0 deletions src/parser/LatexLexer.g4
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ TRANSPOSE: '^{\\mathrm{T}}' ;

BACKSLASH: '\\' ;

AS_LINES: 'as' (' ' | '\\:')+ 'line' [s]? ;

CMD_SIN: 'sin' ;
CMD_COS: 'cos' ;
CMD_TAN: 'tan' ;
Expand Down
Loading

0 comments on commit b21f4c8

Please sign in to comment.