-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes Diagrama del autómata. Poner el dibujo. Que se vaya poniendo en…
… rojo. #9
- Loading branch information
Showing
9 changed files
with
816 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
|
||
|
||
import React from "react"; | ||
import { unsubscribeToUIUpdates } from "../../../lib/core"; | ||
import { Row, Col, Text } from "atomize"; | ||
import { subscribeToUIUpdates, getCore } from "../../../lib/core/index"; | ||
|
||
import I18n from "../../../components/i18n"; | ||
import mermaid from "mermaid"; | ||
|
||
const baseDiagram = `stateDiagram-v2 | ||
classDef yellowFill fill:#f0c40094,color:black,font-weight:bold,stroke-width:2px,stroke:yellow | ||
classDef orangeBorder stroke:orange,stroke-width:2px,stroke-dasharray:5 | ||
[*] --> S0 | ||
S0 --> S1 : XXX | ||
S11 --> S1 : XXX | ||
S10 --> S0 : XXX | ||
S2 --> S6 : XXX | ||
S6 --> S7 : 00X | ||
S9 --> S0 : XXX | ||
S7 --> S0 : XXX | ||
S6 --> S9 : 01X | ||
S1 --> S2 : 0XX | ||
S2 --> S10 : 10X | ||
S1 --> S11 : 111 | ||
`; | ||
|
||
async function renderAutomata(node: Element, text: string = baseDiagram) { | ||
node.removeAttribute("data-processed"); | ||
node.innerHTML = text; | ||
await mermaid.run().catch(e => e); // ignore errors | ||
} | ||
|
||
export default function AutomataNode({ data }: { data: any }) { | ||
const mermaidContainerRef = React.useRef<HTMLDivElement>(null); | ||
|
||
async function onUIUpdate(this: any) { | ||
const nextStateNumber = getCore().get_next_state(); | ||
const currentStateNumber = getCore().get_state(); | ||
|
||
const diagramTxt = `${baseDiagram}\n class S${currentStateNumber} yellowFill\n class S${nextStateNumber} orangeBorder`; | ||
|
||
if (mermaidContainerRef.current) { | ||
await renderAutomata(mermaidContainerRef.current, diagramTxt); | ||
} | ||
} | ||
|
||
async function initialize() { | ||
mermaid.initialize({ | ||
startOnLoad: false, | ||
theme: "default", | ||
}); | ||
mermaid.contentLoaded(); | ||
|
||
if (mermaidContainerRef.current) { | ||
await renderAutomata(mermaidContainerRef.current); | ||
} | ||
} | ||
|
||
React.useEffect(() => { | ||
subscribeToUIUpdates(onUIUpdate); | ||
initialize(); | ||
|
||
return () => { | ||
unsubscribeToUIUpdates(onUIUpdate); | ||
}; | ||
// eslint-disable-next-line react-hooks/exhaustive-deps | ||
}, []); | ||
|
||
|
||
return ( | ||
<div | ||
style={{ | ||
height: data.height || 300, | ||
overflow: "auto", | ||
width: data.width || 220, | ||
padding: 8, | ||
backgroundColor: "#f5f5f5", | ||
}} | ||
className="pretty-shadow" | ||
> | ||
<Row> | ||
<Col size="100%"> | ||
<Text tag="h4" textSize="display4"> | ||
<I18n k={data.labelKey} /> | ||
</Text> | ||
</Col> | ||
</Row> | ||
<Row> | ||
<Col size="100%"> | ||
<div className="mermaid" ref={mermaidContainerRef}></div> | ||
</Col> | ||
</Row> | ||
</div> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.