Skip to content

Commit 732311d

Browse files
authored
Toggle Diagram Orientation (#47)
1 parent 2f61ba0 commit 732311d

5 files changed

Lines changed: 25 additions & 11 deletions

File tree

client/src/webview/mermaid.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import type { StateMachine } from "../types/fsm";
55
* @param sm
66
* @returns Mermaid diagram string
77
*/
8-
export function createMermaidDiagram(sm: StateMachine): string {
8+
export function createMermaidDiagram(sm: StateMachine, orientation: "LR" | "TB"): string {
99
if (!sm) return '';
1010

1111
const lines: string[] = [];
@@ -15,6 +15,7 @@ export function createMermaidDiagram(sm: StateMachine): string {
1515
lines.push(`title: ${sm.className}`);
1616
lines.push('---');
1717
lines.push('stateDiagram-v2');
18+
lines.push(` direction ${orientation}`);
1819

1920
// initial state
2021
lines.push(` [*] --> ${sm.initial}`);

client/src/webview/script.ts

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ export function getScript(vscode: any, document: any, window: any) {
2121
let expandedErrors = new Set<number>();
2222
let stateMachine: StateMachine | undefined;
2323
let selectedTab: NavTab = 'verification';
24+
let diagramOrientation: "LR" | "TB" = "TB";
2425

2526
// initial state
2627
root.innerHTML = renderLoading();
@@ -69,13 +70,21 @@ export function getScript(vscode: any, document: any, window: any) {
6970
}
7071

7172
// toggle show all diagnostics
72-
if (target.classList.contains('show-all-button')) {
73+
if (target.id === 'show-all-button') {
7374
e.stopPropagation();
7475
showAllDiagnostics = !showAllDiagnostics;
7576
updateView();
7677
return;
7778
}
7879

80+
// toggle diagram orientation
81+
if (target.id === 'diagram-orientation-btn') {
82+
e.stopPropagation();
83+
diagramOrientation = diagramOrientation === "TB" ? "LR" : "TB";
84+
updateView();
85+
return;
86+
}
87+
7988
// toggle show more/less for errors
8089
if (target.classList.contains('show-more-button')) {
8190
e.stopPropagation();
@@ -129,8 +138,8 @@ export function getScript(vscode: any, document: any, window: any) {
129138
if (selectedTab === 'verification') {
130139
root.innerHTML = renderVerificationView(diagnostics, showAllDiagnostics, currentFile, expandedErrors, selectedTab)
131140
} else {
132-
const diagram = createMermaidDiagram(stateMachine);
133-
root.innerHTML = renderStateMachineView(stateMachine, diagram, selectedTab);
141+
const diagram = createMermaidDiagram(stateMachine, diagramOrientation);
142+
root.innerHTML = renderStateMachineView(stateMachine, diagram, selectedTab, diagramOrientation);
134143
if (stateMachine) renderMermaidDiagram(document, window);
135144
}
136145
}

client/src/webview/styles.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -94,16 +94,16 @@ export function getStyles(): string {
9494
margin: 1rem 0;
9595
}
9696
.diagnostic-item {
97-
background-color: var(--vscode-textBlockQuote-background);
97+
background-color: var(--vscode-textCodeBlock-background);
9898
padding: 0.5rem 1rem;
9999
margin-bottom: 1rem;
100100
border-radius: 4px;
101101
}
102102
.error-item {
103-
border-left: 4px solid var(--vscode-errorForeground);
103+
border-left: 4px solid var(--vscode-editorError-foreground);
104104
}
105105
.warning-item {
106-
border-left: 4px solid #d4ac0d;
106+
border-left: 4px solid var(--vscode-editorWarning-foreground);
107107
}
108108
.section {
109109
margin-bottom: 1rem;
@@ -201,7 +201,8 @@ export function getStyles(): string {
201201
.show-more-button:hover {
202202
background-color: var(--vscode-editor-background);
203203
}
204-
.show-all-button {
204+
.underline-button {
205+
color: var(--vscode-foreground);
205206
text-align: center;
206207
font-size: 0.8rem;
207208
opacity: 0.6;
@@ -213,7 +214,7 @@ export function getStyles(): string {
213214
border: none;
214215
text-decoration: underline;
215216
}
216-
.show-all-button:hover {
217+
.underline-button:hover {
217218
background: none;
218219
}
219220
.extra-content {

client/src/webview/views/diagram.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
import type { StateMachine } from "../../types/fsm";
22
import { renderMainHeader, type NavTab } from "./sections";
33

4-
export function renderStateMachineView(sm: StateMachine, diagram: string, selectedTab: NavTab = 'state-machine'): string {
4+
export function renderStateMachineView(sm: StateMachine, diagram: string, selectedTab: NavTab = 'state-machine', orientation: "LR" | "TB"): string {
55
return /*html*/`
66
<div>
77
${renderMainHeader("", selectedTab)}
88
${sm ? /*html*/`
99
<div class="diagram-section">
10+
<button id="diagram-orientation-btn" class="underline-button">
11+
${orientation === "TB" ? `Show diagram horizontally` : `Show diagram vertically`}
12+
</button>
1013
<div class="diagram-container">
1114
<pre class="mermaid">${diagram}</pre>
1215
</div>

client/src/webview/views/verification/verification.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export function renderVerificationView(
2828
<p class="info">${infoMessage}</p>
2929
${
3030
diagnostics.length === 0 ? '' : /*html*/`
31-
<button class="show-all-button">
31+
<button id="show-all-button" class="underline-button">
3232
${showAll ? `Show file diagnostics` : `Show all diagnostics`}
3333
</button>
3434
`

0 commit comments

Comments
 (0)