Skip to content

Commit 2b51590

Browse files
committed
interface update
1 parent 38a8586 commit 2b51590

File tree

9 files changed

+421
-45
lines changed

9 files changed

+421
-45
lines changed

package.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,13 @@
33
"version": "0.1.0",
44
"private": true,
55
"dependencies": {
6+
"@emotion/react": "^11.10.6",
7+
"@emotion/styled": "^11.10.6",
8+
"@fortawesome/fontawesome-svg-core": "^6.4.0",
9+
"@fortawesome/free-solid-svg-icons": "^6.4.0",
10+
"@fortawesome/react-fontawesome": "^0.2.0",
11+
"@mui/icons-material": "^5.11.16",
12+
"@mui/material": "^5.12.0",
613
"@testing-library/jest-dom": "^5.16.5",
714
"@testing-library/react": "^13.4.0",
815
"@testing-library/user-event": "^13.5.0",
@@ -16,6 +23,8 @@
1623
"react-draggable": "^4.4.5",
1724
"react-mathjax": "^1.0.1",
1825
"react-scripts": "5.0.1",
26+
"react-select": "^5.7.2",
27+
"react-zoom-pan-pinch": "^3.0.7",
1928
"typescript": "^4.9.5",
2029
"web-vitals": "^2.1.4"
2130
},

src/App.css

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,36 @@
3232
from {
3333
transform: rotate(0deg);
3434
}
35+
3536
to {
3637
transform: rotate(360deg);
3738
}
3839
}
40+
41+
.InferenceArea {
42+
text-align: center;
43+
align-items: center;
44+
justify-content: center;
45+
display: flex;
46+
width: 100%;
47+
height: 100%;
48+
}
49+
50+
51+
.App,
52+
#root,
53+
body,
54+
html {
55+
height: 100%;
56+
width: 100%;
57+
}
58+
59+
.main {
60+
display: flex;
61+
flex-direction: row;
62+
position: absolute;
63+
top: 30%;
64+
left: 30%;
65+
/* transform: translate(-50%, -50%); */
66+
right: 50%;
67+
}

src/App.tsx

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
11
import './App.css';
2-
import { TreeWrapper } from './components/TreeWrapper';
3-
import { calculus as color_calculus } from './logic/calculi/color';
4-
5-
const calculus = color_calculus;
2+
import { InferenceInterface } from './components/InferenceInterface';
63

74
function App() {
85
return (
96
<div className="App">
10-
<TreeWrapper calculus={calculus} init={"Brown"} />
7+
<InferenceInterface />
118
</div>
129
);
1310
}

src/components/InferenceInterface.tsx

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
import { TreeWrapper } from '../components/TreeWrapper';
2+
// import { calculus as color_calculus } from './logic/calculi/color';
3+
import * as color from "../logic/calculi/color";
4+
import * as type_conversion from "../logic/calculi/type_conversion";
5+
import * as expr_ty from "../logic/calculi/static_semantics_expr";
6+
import * as stmt_ty from "../logic/calculi/static_semantics_stmt";
7+
import * as hoare from "../logic/calculi/hoare";
8+
import { StringDispatchRenderer } from '../logic/syntax/renderer';
9+
import React, { useContext } from 'react';
10+
import { TransformComponent, TransformWrapper } from 'react-zoom-pan-pinch';
11+
12+
const calculus = color.calculus;
13+
const renderer = new StringDispatchRenderer();
14+
const goal = "Brown";
15+
16+
// const calculus = expr_ty.calculus;
17+
// const type_renderer = new StringDispatchRenderer()
18+
// .registerAppDispatcher(expr_ty.app_renderer).registerConstDispatcher(expr_ty.const_renderer);
19+
// const goal = "typed(Γ, BinOp(Minus, BinOp(Plus,Indir(x),y), 1), ?type)";
20+
21+
export function InferenceInterface() {
22+
23+
let initial_scale = 1.0;
24+
25+
if (window.location.search) {
26+
const urlParams = new URLSearchParams(window.location.search);
27+
const scale = urlParams.get('scale');
28+
if (scale) {
29+
initial_scale = parseFloat(scale);
30+
}
31+
}
32+
33+
// const context = useContext(AppContext)
34+
const [isMoveable, setIsMoveable] = React.useState<boolean>(false);
35+
36+
const onDrag = () => {
37+
setIsMoveable(true)
38+
//etc
39+
}
40+
const onStop = () => {
41+
setIsMoveable(false)
42+
//etc
43+
}
44+
45+
return (
46+
47+
<TransformWrapper
48+
initialScale={initial_scale}
49+
disabled={isMoveable}
50+
minScale={.25}
51+
maxScale={1.5}
52+
limitToBounds={false}
53+
// onPanning={updateXarrow}
54+
// onZoom={updateXarrow}
55+
pinch={{ step: 5 }}
56+
>
57+
58+
<TransformComponent
59+
contentClass='main'
60+
wrapperStyle={{
61+
height: '100vh', width: '100vw'
62+
}}>
63+
{/* <div> */}
64+
<div className='InferenceArea'>
65+
<TreeWrapper
66+
init={goal}
67+
calculus={calculus} renderer={renderer}
68+
onDrag={onDrag} onStop={onStop}
69+
// onClick={onInteracting} onEndClick={onInteractingEnd}
70+
// onClick={onDrag} onEndClick={onStop}
71+
/>
72+
</div>
73+
{/* </div> */}
74+
75+
</TransformComponent>
76+
</TransformWrapper >
77+
);
78+
}

src/components/Tree.tsx

Lines changed: 46 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,19 @@
11
import { calculus, ruleByName, applyRuleFull } from "../logic/inference/inference_rules";
2+
import { parse } from "../logic/syntax/parser";
23
import { StringDispatchRenderer } from "../logic/syntax/renderer";
34
import { Expr, getVars } from "../logic/syntax/syntactic_logic";
4-
import { Subst } from "../logic/unification/unification";
5+
import { Subst, applySubst } from "../logic/unification/unification";
56

6-
export interface Tree {
7-
conclusion: string;
8-
assumptions: Tree[];
7+
export interface GenericTree<T> {
8+
conclusion: T;
9+
assumptions: GenericTree<T>[];
910
rule?: string;
1011
};
1112

12-
export function goal_tree(conclusion: string): Tree {
13+
export type Tree = GenericTree<Expr>;
14+
export type StringTree = GenericTree<string>;
15+
16+
export function goal_tree(conclusion: Expr): Tree {
1317
return {
1418
conclusion: conclusion,
1519
assumptions: [],
@@ -39,3 +43,40 @@ export function applyNamedRule(calc: calculus, name: string, goal: Expr): [Expr[
3943
}
4044
return [premises, goal_subst];
4145
}
46+
47+
export function applyTreeSubst(tree: Tree, subst: Subst): Tree {
48+
return {
49+
conclusion: applySubst(subst, tree.conclusion),
50+
assumptions: tree.assumptions.map(a => applyTreeSubst(a, subst)),
51+
rule: tree.rule,
52+
};
53+
}
54+
55+
// deep copy of tree
56+
export function copyTree(tree: Tree): Tree {
57+
return {
58+
conclusion: tree.conclusion,
59+
assumptions: tree.assumptions.map(a => copyTree(a)),
60+
rule: tree.rule,
61+
};
62+
}
63+
64+
export function isClosed(tree: Tree): boolean {
65+
return tree.rule !== undefined && tree.assumptions.every(a => isClosed(a));
66+
}
67+
68+
export function stringTreeToTree(tree: StringTree): Tree {
69+
return {
70+
conclusion: parse(tree.conclusion),
71+
assumptions: tree.assumptions.map(a => stringTreeToTree(a)),
72+
rule: tree.rule,
73+
};
74+
}
75+
76+
export function treeToStringTree(tree: Tree): StringTree {
77+
return {
78+
conclusion: debugRenderer.render(tree.conclusion),
79+
assumptions: tree.assumptions.map(a => treeToStringTree(a)),
80+
rule: tree.rule,
81+
};
82+
}

0 commit comments

Comments
 (0)