Skip to content
Open
Show file tree
Hide file tree
Changes from 9 commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
4bf5d97
Initial plan
Copilot Apr 21, 2026
3ccc55b
feat: add unary function parsing and tree rendering support
Copilot Apr 21, 2026
a4bc34b
chore: address validation feedback nits
Copilot Apr 21, 2026
dc650e9
Merge pull request #1 from psaegert/copilot/extend-expression-tree-un…
psaegert Apr 21, 2026
2a2c951
Initial plan
Copilot Apr 21, 2026
8c97921
Add custom # operators with inferred arity up to 3
Copilot Apr 21, 2026
b9bd520
Address review nits and finalize custom operator support
Copilot Apr 21, 2026
bf0c48c
Hide # prefix in node labels, fix font scaling, improve spacing
Copilot Apr 21, 2026
7be9762
Merge pull request #2 from psaegert/copilot/add-custom-operators-support
psaegert Apr 21, 2026
f1167f8
Initial plan
Copilot Apr 21, 2026
d3dc64b
feat: add export png control enter-to-generate and animation toggle
Copilot Apr 21, 2026
6e08d0f
Merge pull request #3 from psaegert/copilot/add-ux-improvements-expor…
psaegert Apr 21, 2026
555323e
Initial plan
Copilot Apr 21, 2026
7865c16
feat: implement minimal realtime UI with dark mode and sync tree rend…
Copilot Apr 21, 2026
66531e3
chore: add SRI for mathjs CDN script
Copilot Apr 21, 2026
0a10b82
Merge pull request #4 from psaegert/copilot/major-ux-ui-overhaul
psaegert Apr 21, 2026
2cefffe
Initial plan
Copilot Apr 21, 2026
193ddfe
Fix parser validation and add export popover with PNG/SVG options
Copilot Apr 21, 2026
84b0c94
Ensure SVG blob URL persists long enough for download
Copilot Apr 21, 2026
a712d36
Merge pull request #5 from psaegert/copilot/fix-a-plus-b-validation-bug
psaegert Apr 21, 2026
0a74059
Surface parser errors and display them between input and canvas
Copilot Apr 21, 2026
2a9c4d9
Remove now-unused isValidExpression/isValidTokens helpers
Copilot Apr 21, 2026
92a6631
Merge pull request #6 from psaegert/copilot/fix-expression-error-display
psaegert Apr 21, 2026
176a07d
Render node labels as LaTeX via KaTeX with graceful fallback
Copilot Apr 21, 2026
6b5a433
Address review: single-pass LaTeX escape, cleaner warm-cache + a11y
Copilot Apr 21, 2026
d857e5d
Merge pull request #7 from psaegert/copilot/add-latex-display-for-nodes
psaegert Apr 21, 2026
758c8d3
Require `#\name` for LaTeX symbols, sharpen canvas on HiDPI, pin cont…
Copilot Apr 21, 2026
4bc6207
Merge pull request #8 from psaegert/copilot/fix-latex-symbols-and-can…
psaegert Apr 21, 2026
c9f19ce
Fix mobile overlap and node text clipping
Copilot Apr 21, 2026
3d8dcc5
Merge pull request #9 from psaegert/copilot/fix-formatting-issues
psaegert Apr 21, 2026
dcd170b
Support numbers, quoted literals, and copy-to-clipboard actions
Copilot Apr 21, 2026
746f351
Address review: guard PNG fallback, skip all whitespace, note execCom…
Copilot Apr 21, 2026
2aa2f46
Merge pull request #10 from psaegert/copilot/fix-invalid-character-in…
psaegert Apr 21, 2026
5fd6653
Support "..." and $...$ literals as operator (non-leaf) nodes
Copilot Apr 21, 2026
83b7ab1
Consolidate custom/literal arity branch in getTokenArity
Copilot Apr 21, 2026
16597b7
Merge pull request #11 from psaegert/copilot/add-support-for-operator…
psaegert Apr 22, 2026
31bb7d5
Initial plan
Copilot Apr 22, 2026
1bb09bf
fix: crop PNG and SVG exports to tree bounds
Copilot Apr 22, 2026
08dafb1
chore: harden bounds traversal for missing children
Copilot Apr 22, 2026
e3b604a
refactor: share padded bounds size for export cropping
Copilot Apr 22, 2026
3b3ba5e
Merge pull request #12 from psaegert/copilot/crop-exported-image-content
psaegert Apr 22, 2026
266e362
docs: fork-aware README + footer credit to original, with screenshots
psaegert Jun 13, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,26 @@ With that in mind, and inspired on my lectures on the tree data structure I deci

Visit this [website](https://lnogueir.github.io/expression-tree-gen/) to simulate an expression yourself.

Supported syntax includes:
- Binary operators: `+`, `-`, `*`, `/`
- Single-letter variables: `a`-`z`
- Unary functions: `sin`, `cos`, `tan`, `log`, `ln`, `sqrt`, `exp`, `abs`
- Custom operators/functions:
- Arity 0: `#pi`
- Arity 1-3 (inferred): `#sign(a)`, `#add(a,b)`, `#clamp(x,a,b)`

Examples:
- `a+b`
- `sin(a)`
- `sin(a)+cos(b)`
- `sin(cos(a))`
- `sin(a+b)*cos(c)`
- `#pi`
- `#sign(a)`
- `#add(a,b)`
- `sin(#add(a,b))*#pi`
- `#clamp(x,a,b)`

## Credits:

* This [article](https://llimllib.github.io/pymag-trees/) which helped me a lot introducing me to Knuth's algorithm for the layout of the tree.
Expand Down
12 changes: 8 additions & 4 deletions canvas.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,13 @@
const SAMPLE_EXPRESSIONS = [
'(a + b)*c - (x - y)/z',
'(a * b) - c + z / x',
'sin(a)+cos(b)',
'sin(a+b)*cos(c)',
'sin(#add(a,b))*#pi',
'#clamp(x,#min(a,b),c)',
'x - y + (c / (a + b))',
'(a / y) + b - (c * x)',
'(a - b) * (c + d) / z',
'(a * b) - (x / y)'
'(a - b) * (c + d) / z'
]
var canvas = document.querySelector('canvas')
var c = canvas.getContext('2d')
Expand All @@ -18,7 +21,6 @@
var expression = document.getElementById('expression-input').value
if (typeof expression !== 'undefined' && null != expression) {
expression = expression.replace(/\s+/g, '')
expression = expression.toLowerCase()
var postfix = infixToPostfix(expression);
if (null !== postfix) {
try {
Expand Down Expand Up @@ -61,10 +63,12 @@ function displayErrorMessage() {
<div style="font-size:1.1em;text-align: left;margin:0px 0px 0px 60px;">
- You may only use these brackets ( ). <br/>
- Use * for multiplication and / for division. <br/>
- Supported unary functions: sin, cos, tan, log, ln, sqrt, exp, abs. <br/>
- Custom operators: #name, #name(arg), #name(arg1,arg2,arg3) (max arity 3). <br/>
- Valid operators and operands are:<br/>
<div style="margin-left: 10px;">
<i>Operators</i>: <b>[+ - * / ]</b><br/>
<i>Operands</i>: Any alphabetic letter.
<i>Operands</i>: Single letters a-z and custom operators.
</div>
</div>
`,
Expand Down
4 changes: 2 additions & 2 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<h1>Expression Tree Generator</h1>
<div class="inner-input-container" style="text-align: left;">
<span>Current Expression:</span>
<input type="text" class="name" id='expression-input' placeholder="e.g (x + y)*z - (t / w)">
<input type="text" class="name" id='expression-input' placeholder="e.g sin(#add(a,b))*#pi">
</div>

<div class="buttons">
Expand All @@ -46,4 +46,4 @@ <h1>Expression Tree Generator</h1>
<script src="infixToPostfix.js"></script>
<script src="canvas.js"></script>

</html>
</html>
Loading
Loading