1169- break out getRows

Moved getRows function from `state/stateRenderer.js` and `state/shapes.js` into `common/common.js`. Broke out section into small one line functions for replacing line breaks, then moved the `sanitize` function from `utils.js` to this new module as there is shared functionality
This commit is contained in:
Justin Greywolf
2020-02-21 13:49:05 -08:00
parent 5ccca5e329
commit 6d74c5663f
6 changed files with 51 additions and 42 deletions

View File

@@ -3,6 +3,7 @@ import dagre from 'dagre';
import graphlib from 'graphlib';
import { logger } from '../../logger';
import stateDb from './stateDb';
import common from '../common/common';
import { parser } from './parser/stateDiagram';
// import idCache from './id-cache';
import { drawState, addTitleAndBox, drawEdge } from './shapes';
@@ -99,14 +100,6 @@ const getLabelWidth = text => {
return text ? text.length * conf.fontSizeFactor : 1;
};
/* TODO: REMOVE DUPLICATION, SEE SHAPES */
const getRows = s => {
if (!s) return 1;
let str = s.replace(/<br\s*\/?>/gi, '#br#');
str = str.replace(/\\n/g, '#br#');
return str.split('#br#');
};
const renderDoc = (doc, diagram, parentId, altBkg) => {
// // Layout graph, Create a new directed graph
const graph = new graphlib.Graph({
@@ -239,7 +232,7 @@ const renderDoc = (doc, diagram, parentId, altBkg) => {
{
relation: relation,
width: getLabelWidth(relation.title),
height: conf.labelHeight * getRows(relation.title).length,
height: conf.labelHeight * common.getRows(relation.title).length,
labelpos: 'c'
},
'id' + cnt