From 53465ea035635f4fff53b7f481e0116b139b1e10 Mon Sep 17 00:00:00 2001 From: Zachary Zhang Date: Thu, 13 Jun 2024 14:25:53 -0400 Subject: add LR vs TD graph detector --- src/client/views/nodes/DiagramBox.scss | 91 ++++++++++++++++++++++++++++++++++ src/client/views/nodes/DiagramBox.tsx | 63 +++++++++++++---------- 2 files changed, 128 insertions(+), 26 deletions(-) (limited to 'src') diff --git a/src/client/views/nodes/DiagramBox.scss b/src/client/views/nodes/DiagramBox.scss index 5b12c6f89..d73dd2a97 100644 --- a/src/client/views/nodes/DiagramBox.scss +++ b/src/client/views/nodes/DiagramBox.scss @@ -35,6 +35,97 @@ flex-direction: column; align-items: center; justify-content: center; + .contentCode{ + overflow: hidden; + display: flex; + justify-content: center; + align-items: center; + flex-direction:row; + padding:10px; + width:100%; + height:100%; + .topbar{ + .backButtonDrawing{ + padding: 5px 10px; + height:23px; + border-radius: 10px; + text-align: center; + padding:0; + width:50px; + font-size:10px; + position:absolute; + top:10px; + left:10px; + } + p{ + margin-left:60px + } + } + .search-bar { + overflow:hidden; + position:absolute; + top:0; + .backButton{ + text-align: center; + padding:0; + width:50px; + font-size:10px; + + } + .exampleButton{ + width:100px; + height:30px; + } + display: flex; + flex-wrap: wrap; + justify-content: space-between; + align-items: center; + width: 100%; + button { + padding: 5px 10px; + width:80px; + height:23px; + border-radius: 3px; + } + } + .exampleButtonContainer{ + display:flex; + flex-direction: column; + position: absolute; + top:37px; + right:30px; + width:50px; + z-index: 200; + button{ + width:70px; + margin:2px; + padding:0px; + height:15px; + border-radius: 3px; + } + } + textarea { + position:relative; + width:40%; + height: 100%; + height: calc(100% - 25px); + top:15px; + resize:none; + overflow: hidden; + } + .diagramBox{ + flex: 1; + display: flex; + justify-content: center; + align-items: center; + svg{ + position: relative; + top:25; + max-width: none !important; + height: calc(100% - 50px); + } + } + } .content { overflow: hidden; display: flex; diff --git a/src/client/views/nodes/DiagramBox.tsx b/src/client/views/nodes/DiagramBox.tsx index 08c889158..068c92e6b 100644 --- a/src/client/views/nodes/DiagramBox.tsx +++ b/src/client/views/nodes/DiagramBox.tsx @@ -203,6 +203,7 @@ export class DiagramBox extends ViewBoxAnnotatableComponent() { const rectangleArray = docArray.filter(doc => doc.title === 'rectangle' || doc.title === 'circle'); const lineArray = docArray.filter(doc => doc.title === 'line' || doc.title === 'stroke'); const textArray = docArray.filter(doc => doc.type === 'rich text'); + this.isLeftRightDiagram(docArray); const timeoutPromise = () => new Promise(resolve => { setTimeout(resolve, 0); @@ -212,7 +213,11 @@ export class DiagramBox extends ViewBoxAnnotatableComponent() { console.log(inkStrokeArray.length); console.log(lineArray.length); if (inkStrokeArray[0] && inkStrokeArray.length === lineArray.length) { - mermaidCode = 'graph TD;'; + if (this.isLeftRightDiagram(docArray)) { + mermaidCode = 'graph LR;'; + } else { + mermaidCode = 'graph TD;'; + } const inkingStrokeArray = inkStrokeArray.map(stroke => stroke?.ComponentView); for (let i = 0; i < rectangleArray.length; i++) { const rectangle = rectangleArray[i]; @@ -263,6 +268,29 @@ export class DiagramBox extends ViewBoxAnnotatableComponent() { } } } + isLeftRightDiagram = (docArray: Doc[]) => { + const filteredDocs = docArray.filter(doc => doc.title === 'rectangle' || doc.title === 'circle'); + const xDoc = filteredDocs.map(doc => doc.x) as number[]; + const minX = Math.min(...xDoc); + const xWidthDoc = filteredDocs.map(doc => { + if (typeof doc.x === 'number' && typeof doc.width === 'number') { + return doc.x + doc.width; + } + }) as number[]; + const maxX = Math.max(...xWidthDoc); + const yDoc = filteredDocs.map(doc => doc.y) as number[]; + const minY = Math.min(...yDoc); + const yHeightDoc = filteredDocs.map(doc => { + if (typeof doc.x === 'number' && typeof doc.width === 'number') { + return doc.x + doc.width; + } + }) as number[]; + const maxY = Math.max(...yHeightDoc); + if (maxX - minX > maxY - minY) { + return true; + } + return false; + }; testInkingStroke = () => { if (this.Document.data instanceof List) { const docArray: Doc[] = DocListCast(this.Document.data); @@ -295,10 +323,6 @@ export class DiagramBox extends ViewBoxAnnotatableComponent() { } return false; }; - autoResize(element: HTMLTextAreaElement): void { - element.style.height = '5px'; - element.style.height = element.scrollHeight + 'px'; - } drawingButton = () => { this.Document.menuState = 'drawing'; }; @@ -351,7 +375,7 @@ export class DiagramBox extends ViewBoxAnnotatableComponent() { -