From cfc14ade2ae448140cb2d4f9b447d797cfb9476a Mon Sep 17 00:00:00 2001 From: Knut Sveidqvist Date: Sat, 5 Oct 2019 10:02:58 +0200 Subject: [PATCH] #945 Some more cleanup focusing on stateDb --- src/diagrams/state/parser/stateDiagram.jison | 1 - src/diagrams/state/shapes.js | 1 + src/diagrams/state/stateDb.js | 18 ++------------- src/diagrams/state/stateRenderer.js | 23 ++------------------ 4 files changed, 5 insertions(+), 38 deletions(-) diff --git a/src/diagrams/state/parser/stateDiagram.jison b/src/diagrams/state/parser/stateDiagram.jison index 8ae1bbf44..9ab2d24db 100644 --- a/src/diagrams/state/parser/stateDiagram.jison +++ b/src/diagrams/state/parser/stateDiagram.jison @@ -126,7 +126,6 @@ statement | COMPOSIT_STATE STRUCT_START document STRUCT_STOP { console.warn('Adding document for state without id ', $1); - // yy.addDocument('noId'); $$={ stmt: 'state', id: $1, type: 'default', description: '', doc: $3 } } | STATE_DESCR AS ID { $$={id: $3, type: 'default', description: $1.trim()};} diff --git a/src/diagrams/state/shapes.js b/src/diagrams/state/shapes.js index c7a08d7ae..4eb372eed 100644 --- a/src/diagrams/state/shapes.js +++ b/src/diagrams/state/shapes.js @@ -1,6 +1,7 @@ import * as d3 from 'd3'; import idCache from './id-cache.js'; import stateDb from './stateDb'; +import utils from '../../utils'; console.warn('ID cache', idCache); diff --git a/src/diagrams/state/stateDb.js b/src/diagrams/state/stateDb.js index 76bae029c..266de58d4 100644 --- a/src/diagrams/state/stateDb.js +++ b/src/diagrams/state/stateDb.js @@ -11,16 +11,10 @@ const getRootDoc = () => rootDoc; const extract = doc => { const res = { states: [], relations: [] }; clear(); + doc.forEach(item => { if (item.stmt === 'state') { - // if (item.doc) { - // addState(item.id, 'composit'); - // addDocument(item.id); - // extract(item.doc); - // currentDocument = currentDocument.parent; - // } else { addState(item.id, item.type, item.doc); - // } } if (item.stmt === 'relation') { addRelation(item.state1.id, item.state2.id, item.description); @@ -81,12 +75,7 @@ export const clear = function() { export const getState = function(id) { return currentDocument.states[id]; }; -export const addDocument = id => { - console.warn(currentDocument, documents); - currentDocument.documents[id] = newDoc(); - currentDocument.documents[id].parent = currentDocument; - currentDocument = currentDocument.documents[id]; -}; + export const getStates = function() { return currentDocument.states; }; @@ -94,8 +83,6 @@ export const logDocuments = function() { console.warn('Documents = ', documents); }; export const getRelations = function() { - // const relations1 = [{ id1: 'start1', id2: 'state1' }, { id1: 'state1', id2: 'exit1' }]; - // return relations; return currentDocument.relations; }; @@ -162,7 +149,6 @@ export default { lineType, relationType, logDocuments, - addDocument, getRootDoc, setRootDoc, extract diff --git a/src/diagrams/state/stateRenderer.js b/src/diagrams/state/stateRenderer.js index 83c394fe3..0f7ca8d38 100644 --- a/src/diagrams/state/stateRenderer.js +++ b/src/diagrams/state/stateRenderer.js @@ -61,7 +61,6 @@ const insertMarkers = function(elem) { export const draw = function(text, id) { parser.yy.clear(); parser.parse(text); - stateDb.logDocuments(); logger.info('Rendering diagram ' + text); // /// / Fetch the default direction, use TD if none was found @@ -124,7 +123,7 @@ const renderDoc = (doc, diagram, parentId) => { }); } - // // Default to assigning a new object as a label for each new edge. + // Default to assigning a new object as a label for each new edge. graph.setDefaultEdgeLabel(function() { return {}; }); @@ -146,15 +145,13 @@ const renderDoc = (doc, diagram, parentId) => { .append('g') .attr('id', stateDef.id) .attr('class', 'classGroup'); - node = renderDoc2(stateDef.doc, sub, stateDef.id); + node = renderDoc(stateDef.doc, sub, stateDef.id); sub = addIdAndBox(sub, stateDef); let boxBounds = sub.node().getBBox(); node.width = boxBounds.width; node.height = boxBounds.height + 10; transformationLog[stateDef.id] = { y: 35 }; - // node.x = boxBounds.y; - // node.y = boxBounds.x; } else { node = drawState(diagram, stateDef, graph); } @@ -163,21 +160,6 @@ const renderDoc = (doc, diagram, parentId) => { // metadata about the node. In this case we're going to add labels to each of // our nodes. graph.setNode(node.id, node); - // if (parentId) { - // console.warn('apa1 P>', node.id, parentId); - // // graph.setParent(node.id, parentId); - // } - // graph.setNode(node.id + 'note', nodeAppendix); - - // let parent = 'p1'; - // if (node.id === 'XState1') { - // parent = 'p2'; - // } - - // graph.setParent(node.id, parent); - // graph.setParent(node.id + 'note', parent); - - // logger.info('Org height: ' + node.height); } console.info('Count=', graph.nodeCount()); @@ -192,7 +174,6 @@ const renderDoc = (doc, diagram, parentId) => { console.warn(getGraphId(relation.id1), relation.id2, { relation: relation }); - // graph.setEdge(getGraphId(relation.id1), getGraphId(relation.id2)); }); dagre.layout(graph);