Skip to content

Commit

Permalink
Adjustments
Browse files Browse the repository at this point in the history
  • Loading branch information
knsv committed Apr 30, 2021
1 parent 1e6ed7b commit d8d6248
Show file tree
Hide file tree
Showing 6 changed files with 80 additions and 29 deletions.
61 changes: 48 additions & 13 deletions cypress/platform/knsv.html
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
class T TestSub
linkStyle 0,1 color:orange, stroke: orange;
</div>
<div class="mermaid2" style="width: 100%; height: 20%;">
<div class="mermaid" style="width: 100%; height: 20%;">
stateDiagram-v2
[*] --> Off
Off --> On
Expand Down Expand Up @@ -103,27 +103,62 @@

</div>
<div class="mermaid2" style="width: 100%; height: 20%;">
state
stateDiagram-v2
state "Not Shooting State" as NotShooting {
state "Idle mode" as Idle
state "Configuring mode" as Configuring
[*] --> Idle
Idle : this is a string
Idle : this is another string
Idle --> Configuring : EvConfig
Configuring --> Idle : EvConfig
}

</div>
<div class="mermaid" style="width: 100%; height: 20%;">
stateDiagram
state S1 {
sub1 -->sub2
}
state S2 {
sub4
}
S1 --> S2
sub1 --> sub4
<div class="mermaid2" style="width: 100%; height: 20%;">
stateDiagram-v2
[*] --> Off
Off --> On
On --> Select
Select --> Washing
Washing --> Finished
Finished --> [*]
state Select
{
state "Program 1" as Prg1
[*] --> Prg1
Prg1 --> [*]
[*] --> Prg2
Prg2 --> [*]
[*] --> Prg3
Prg3 --> [*]
}

state Washing {
state Using_Prg1 {
[*] --> P1Step1
P1Step1 --> P1Step2
P1Step2 --> P1Step3
P1Step3 --> [*]
}
state Using_Prg2 {
[*] --> P2Step1
P2Step1 --> P2Step2
P2Step2 --> P2Step3
P2Step3 --> [*]
}

state Using_Prg3 {
[*] --> Step1
Step1 --> Step2
Step2 --> [*]
}
[*] --> Using_Prg1
[*] --> Using_Prg2
[*] --> Using_Prg3
Using_Prg1 --> [*]
Using_Prg2 --> [*]
Using_Prg3 --> [*]
}
</div>
<div class="mermaid2" style="width: 100%; height: 20%;">
requirementDiagram
Expand Down
1 change: 1 addition & 0 deletions src/dagre-wrapper/createLabel.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ function addHtmlLabel(node) {

const createLabel = (_vertexText, style, isTitle, isNode) => {
let vertexText = _vertexText || '';
if (typeof vertexText === 'object') vertexText = vertexText[0];
if (getConfig().flowchart.htmlLabels) {
// TODO: addHtmlLabel accepts a labelStyle. Do we possibly have that?
vertexText = vertexText.replace(/\\n|\n/g, '<br />');
Expand Down
6 changes: 3 additions & 3 deletions src/dagre-wrapper/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { log } from '../logger';
const recursiveRender = (_elem, graph, diagramtype, parentCluster) => {
log.info('Graph in recursive render: XXX', graphlib.json.write(graph), parentCluster);
const dir = graph.graph().rankdir;
log.warn('Dir in recursive render - dir:', dir);
log.trace('Dir in recursive render - dir:', dir);

const elem = _elem.insert('g').attr('class', 'root'); // eslint-disable-line
if (!graph.nodes()) {
Expand All @@ -26,7 +26,7 @@ const recursiveRender = (_elem, graph, diagramtype, parentCluster) => {
log.info('Recursive render XXX', graph.nodes());
}
if (graph.edges().length > 0) {
log.info('Recursive edges', graph.edge(graph.edges()[0]));
log.trace('Recursive edges', graph.edge(graph.edges()[0]));
}
const clusters = elem.insert('g').attr('class', 'clusters'); // eslint-disable-line
const edgePaths = elem.insert('g').attr('class', 'edgePaths');
Expand All @@ -43,7 +43,7 @@ const recursiveRender = (_elem, graph, diagramtype, parentCluster) => {
log.info('Setting data for cluster XXX (', v, ') ', data, parentCluster);
graph.setNode(parentCluster.id, data);
if (!graph.parent(v)) {
log.warn('Setting parent', v, parentCluster.id);
log.trace('Setting parent', v, parentCluster.id);
graph.setParent(v, parentCluster.id, data);
}
}
Expand Down
14 changes: 11 additions & 3 deletions src/dagre-wrapper/mermaid-graphlib.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export const clear = () => {
const isDecendant = (id, ancenstorId) => {
// if (id === ancenstorId) return true;

log.debug(
log.trace(
'In isDecendant',
ancenstorId,
' ',
Expand Down Expand Up @@ -354,17 +354,25 @@ export const extractor = (graph, depth) => {
log.warn(
'Cluster without external connections, without a parent and with children',
node,
depth
depth,
clusterDb[node].clusterData.dir
);

const graphSettings = graph.graph();
let dir = graphSettings.rankdir === 'TB' ? 'LR' : 'TB';
if (clusterDb[node]) {
if (clusterDb[node].clusterData && clusterDb[node].clusterData.dir) {
dir = clusterDb[node].clusterData.dir;
log.warn('Fixing dir', clusterDb[node].clusterData.dir, dir);
}
}

const clusterGraph = new graphlib.Graph({
multigraph: true,
compound: true
})
.setGraph({
rankdir: graphSettings.rankdir === 'TB' ? 'LR' : 'TB', // Todo: set proper spacing
rankdir: dir, // Todo: set proper spacing
nodesep: 50,
ranksep: 50,
marginx: 8,
Expand Down
14 changes: 10 additions & 4 deletions src/dagre-wrapper/nodes.js
Original file line number Diff line number Diff line change
Expand Up @@ -319,12 +319,18 @@ const rectWithTitle = (parent, node) => {

const label = shapeSvg.insert('g').attr('class', 'label');

const text2prim = node.labelText.flat ? node.labelText.flat() : node.labelText;
const text2 = typeof text2prim === 'object' ? text2prim[0] : text2prim;
const text2 = node.labelText.flat ? node.labelText.flat() : node.labelText;
// const text2 = typeof text2prim === 'object' ? text2prim[0] : text2prim;

log.info('Label text', text2);
let title = '';
if (typeof text2 === 'object') {
title = text2[0];
} else {
title = text2;
}
log.info('Label text abc79', title, text2, typeof text2 === 'object');

const text = label.node().appendChild(createLabel(text2, node.labelStyle, true, true));
const text = label.node().appendChild(createLabel(title, node.labelStyle, true, true));
let bbox;
if (getConfig().flowchart.htmlLabels) {
const div = text.children[0];
Expand Down
13 changes: 7 additions & 6 deletions src/diagrams/state/stateRenderer-v2.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,13 +96,14 @@ const setupNode = (g, parent, node, altFlag) => {
const nodeData = {
labelStyle: '',
shape: nodeDb[node.id].shape,
labelText:
typeof nodeDb[node.id].description === 'object'
? nodeDb[node.id].description[0]
: nodeDb[node.id].description,
labelText: nodeDb[node.id].description,
// typeof nodeDb[node.id].description === 'object'
// ? nodeDb[node.id].description[0]
// : nodeDb[node.id].description,
classes: nodeDb[node.id].classes, //classStr,
style: '', //styles.style,
id: node.id,
dir: altFlag ? 'LR' : 'TB',
domId: 'state-' + node.id + '-' + cnt,
type: nodeDb[node.id].type,
padding: 15 //getConfig().flowchart.padding
Expand Down Expand Up @@ -167,12 +168,12 @@ const setupNode = (g, parent, node, altFlag) => {

if (parent) {
if (parent.id !== 'root') {
log.info('Setting node ', node.id, ' to be child of its parent ', parent.id);
log.trace('Setting node ', node.id, ' to be child of its parent ', parent.id);
g.setParent(node.id, parent.id);
}
}
if (node.doc) {
log.info('Adding nodes children ');
log.trace('Adding nodes children ');
setupDoc(g, node, node.doc, !altFlag);
}
};
Expand Down

0 comments on commit d8d6248

Please sign in to comment.