Skip to content

Commit aa7d480

Browse files
lumos309martin-henz
authored andcommitted
Env visualiser (#541)
* Env visualiser * fixed formatting
1 parent f76af20 commit aa7d480

File tree

8 files changed

+2530
-5
lines changed

8 files changed

+2530
-5
lines changed

public/externalLibs/env_visualizer/ConcreteJs.js

Lines changed: 577 additions & 0 deletions
Large diffs are not rendered by default.

public/externalLibs/env_visualizer/visualizer - Copy.js

Lines changed: 890 additions & 0 deletions
Large diffs are not rendered by default.

public/externalLibs/env_visualizer/visualizer.js

Lines changed: 1022 additions & 0 deletions
Large diffs are not rendered by default.

public/externalLibs/index.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,11 @@ function loadAllLibs() {
3838
'/externalLibs/streams/stream.js',
3939
'/externalLibs/pe_library.js',
4040
'/externalLibs/assert_compiled.js',
41-
//inspector
42-
'/externalLibs/inspector/inspector.js'
41+
// inspector
42+
'/externalLibs/inspector/inspector.js',
43+
// env visualizer
44+
'/externalLibs/env_visualizer/ConcreteJS.js',
45+
'/externalLibs/env_visualizer/visualizer.js'
4346
]
4447

4548
for (var i = 0; i < files.length; i++) {

src/components/Playground.tsx

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { ExternalLibraryName } from './assessment/assessmentShape';
99
import Markdown from './commons/Markdown';
1010
import Workspace, { WorkspaceProps } from './workspace';
1111
import { SideContentTab } from './workspace/side-content';
12+
import EnvVisualizer from './workspace/side-content/EnvVisualizer';
1213
import Inspector from './workspace/side-content/Inspector';
1314
import ListVisualizer from './workspace/side-content/ListVisualizer';
1415

@@ -155,7 +156,7 @@ class Playground extends React.Component<IPlaygroundProps, PlaygroundState> {
155156
sideContentProps: {
156157
activeTab: this.props.activeTab,
157158
handleChangeActiveTab: this.props.handleChangeActiveTab,
158-
tabs: [playgroundIntroductionTab, listVisualizerTab, inspectorTab]
159+
tabs: [playgroundIntroductionTab, listVisualizerTab, inspectorTab, envVisualizerTab]
159160
}
160161
};
161162
return (
@@ -181,7 +182,7 @@ const playgroundIntroductionTab: SideContentTab = {
181182
};
182183

183184
const listVisualizerTab: SideContentTab = {
184-
label: 'List Visualizer',
185+
label: 'Data Visualizer',
185186
icon: IconNames.EYE_OPEN,
186187
body: <ListVisualizer />
187188
};
@@ -192,4 +193,10 @@ const inspectorTab: SideContentTab = {
192193
body: <Inspector />
193194
};
194195

196+
const envVisualizerTab: SideContentTab = {
197+
label: 'Env Visualizer',
198+
icon: IconNames.EYE_OPEN,
199+
body: <EnvVisualizer />
200+
};
201+
195202
export default Playground;
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import * as React from 'react';
2+
3+
class EnvVisualizer extends React.Component<{}, {}> {
4+
private $parent: HTMLElement | null;
5+
6+
public componentDidMount() {
7+
if (this.$parent) {
8+
(window as any).EnvVisualizer.init(this.$parent);
9+
}
10+
}
11+
12+
public render() {
13+
return <div ref={r => (this.$parent = r)} className="sa-env-visualizer pt-dark" />;
14+
}
15+
}
16+
17+
export default EnvVisualizer;

src/sagas/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import { externalLibraries } from '../reducers/externalLibraries';
1414
import { defaultEditorValue, IState, IWorkspaceState } from '../reducers/states';
1515
import { IVLE_KEY, USE_BACKEND } from '../utils/constants';
1616
import { showSuccessMessage, showWarningMessage } from '../utils/notification';
17-
import { highlightLine, inspectorUpdate } from '../utils/slangHelper';
17+
import { highlightLine, inspectorUpdate, visualiseEnv } from '../utils/slangHelper';
1818
import backendSaga from './backend';
1919

2020
function* mainSaga() {
@@ -312,6 +312,7 @@ function* updateInspector() {
312312
const start = lastDebuggerResult.context.runtime.nodes[0].loc.start.line - 1;
313313
const end = lastDebuggerResult.context.runtime.nodes[0].loc.end.line - 1;
314314
yield put(actions.highlightEditorLine([start, end], location));
315+
visualiseEnv(lastDebuggerResult);
315316
inspectorUpdate(lastDebuggerResult);
316317
} catch (e) {
317318
put(actions.highlightEditorLine([], location));

src/utils/slangHelper.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,14 @@ function visualiseList(list: any) {
8282
}
8383
}
8484

85+
export function visualiseEnv(context: Context) {
86+
if ((window as any).EnvVisualizer) {
87+
(window as any).EnvVisualizer.draw_env({ context });
88+
} else {
89+
throw new Error('Env visualizer is not enabled');
90+
}
91+
}
92+
8593
export function highlightLine(line: number) {
8694
if ((window as any).Inspector) {
8795
(window as any).Inspector.highlightClean();

0 commit comments

Comments
 (0)