This commit is contained in:
Knut Sveidqvist
2024-05-31 11:27:12 +02:00
parent 9855bdbaaa
commit 4266b2e4ca
5 changed files with 52 additions and 37 deletions

View File

@@ -54,16 +54,16 @@ export function stateDomId(itemId = '', counter = 0, type = '', typeSpacer = DOM
return `${DOMID_STATE}-${itemId}${typeStr}-${counter}`; return `${DOMID_STATE}-${itemId}${typeStr}-${counter}`;
} }
const setupDoc = (parentParsedItem, doc, diagramStates, nodes, edges, altFlag, useRough) => { const setupDoc = (parentParsedItem, doc, diagramStates, nodes, edges, altFlag, useRough, look) => {
// graphItemCount = 0; // graphItemCount = 0;
log.trace('items', doc); log.trace('items', doc);
doc.forEach((item) => { doc.forEach((item) => {
switch (item.stmt) { switch (item.stmt) {
case STMT_STATE: case STMT_STATE:
dataFetcher(parentParsedItem, item, diagramStates, nodes, edges, altFlag, useRough); dataFetcher(parentParsedItem, item, diagramStates, nodes, edges, altFlag, useRough, look);
break; break;
case DEFAULT_STATE_TYPE: case DEFAULT_STATE_TYPE:
dataFetcher(parentParsedItem, item, diagramStates, nodes, edges, altFlag, useRough); dataFetcher(parentParsedItem, item, diagramStates, nodes, edges, altFlag, useRough, look);
break; break;
case STMT_RELATION: case STMT_RELATION:
{ {
@@ -74,7 +74,8 @@ const setupDoc = (parentParsedItem, doc, diagramStates, nodes, edges, altFlag, u
nodes, nodes,
edges, edges,
altFlag, altFlag,
useRough useRough,
look
); );
dataFetcher( dataFetcher(
parentParsedItem, parentParsedItem,
@@ -83,7 +84,8 @@ const setupDoc = (parentParsedItem, doc, diagramStates, nodes, edges, altFlag, u
nodes, nodes,
edges, edges,
altFlag, altFlag,
useRough useRough,
look
); );
const edgeData = { const edgeData = {
id: 'edge' + graphItemCount, id: 'edge' + graphItemCount,
@@ -100,6 +102,7 @@ const setupDoc = (parentParsedItem, doc, diagramStates, nodes, edges, altFlag, u
thickness: G_EDGE_THICKNESS, thickness: G_EDGE_THICKNESS,
classes: CSS_EDGE, classes: CSS_EDGE,
useRough, useRough,
look,
}; };
edges.push(edgeData); edges.push(edgeData);
//g.setEdge(item.state1.id, item.state2.id, edgeData, graphItemCount); //g.setEdge(item.state1.id, item.state2.id, edgeData, graphItemCount);
@@ -210,7 +213,16 @@ function getClassesFromDbInfo(dbInfoItem) {
} }
} }
} }
export const dataFetcher = (parent, parsedItem, diagramStates, nodes, edges, altFlag, useRough) => { export const dataFetcher = (
parent,
parsedItem,
diagramStates,
nodes,
edges,
altFlag,
useRough,
look
) => {
const itemId = parsedItem.id; const itemId = parsedItem.id;
const classStr = getClassesFromDbInfo(diagramStates[itemId]); const classStr = getClassesFromDbInfo(diagramStates[itemId]);
@@ -301,6 +313,7 @@ export const dataFetcher = (parent, parsedItem, diagramStates, nodes, edges, alt
rx: 10, rx: 10,
ry: 10, ry: 10,
useRough, useRough,
look,
}; };
// Clear the label for dividers who have no description // Clear the label for dividers who have no description
@@ -330,6 +343,7 @@ export const dataFetcher = (parent, parsedItem, diagramStates, nodes, edges, alt
isGroup: newNode.type === 'group', isGroup: newNode.type === 'group',
padding: 0, //getConfig().flowchart.padding padding: 0, //getConfig().flowchart.padding
useRough, useRough,
look,
}; };
const groupData = { const groupData = {
labelStyle: '', labelStyle: '',
@@ -343,6 +357,7 @@ export const dataFetcher = (parent, parsedItem, diagramStates, nodes, edges, alt
isGroup: true, isGroup: true,
padding: 16, //getConfig().flowchart.padding padding: 16, //getConfig().flowchart.padding
useRough, useRough,
look,
}; };
graphItemCount++; graphItemCount++;
@@ -382,6 +397,7 @@ export const dataFetcher = (parent, parsedItem, diagramStates, nodes, edges, alt
labelType: G_EDGE_LABELTYPE, labelType: G_EDGE_LABELTYPE,
thickness: G_EDGE_THICKNESS, thickness: G_EDGE_THICKNESS,
useRough, useRough,
look,
}); });
} else { } else {
insertOrUpdateNode(nodes, nodeData); insertOrUpdateNode(nodes, nodeData);
@@ -389,6 +405,11 @@ export const dataFetcher = (parent, parsedItem, diagramStates, nodes, edges, alt
} }
if (parsedItem.doc) { if (parsedItem.doc) {
log.trace('Adding nodes children '); log.trace('Adding nodes children ');
setupDoc(parsedItem, parsedItem.doc, diagramStates, nodes, edges, !altFlag, useRough); setupDoc(parsedItem, parsedItem.doc, diagramStates, nodes, edges, !altFlag, useRough, look);
} }
}; };
export const reset = () => {
nodeDb = {};
graphItemCount = 0;
};

View File

@@ -11,7 +11,7 @@ import {
setDiagramTitle, setDiagramTitle,
getDiagramTitle, getDiagramTitle,
} from '../common/commonDb.js'; } from '../common/commonDb.js';
import { dataFetcher } from './dataFetcher.js'; import { dataFetcher, reset as resetDataFetching } from './dataFetcher.js';
import { import {
DEFAULT_DIAGRAM_DIRECTION, DEFAULT_DIAGRAM_DIRECTION,
@@ -583,6 +583,8 @@ export const getData = () => {
const diagramStates = getStates(); const diagramStates = getStates();
const config = getConfig(); const config = getConfig();
const useRough = config.look === 'handdrawn'; const useRough = config.look === 'handdrawn';
const look = config.look;
resetDataFetching();
dataFetcher(undefined, getRootDocV2(), diagramStates, nodes, edges, true, useRough); dataFetcher(undefined, getRootDocV2(), diagramStates, nodes, edges, true, useRough);
console.log('State Nodes XDX:', nodes); console.log('State Nodes XDX:', nodes);

View File

@@ -436,38 +436,34 @@ const fixCorners = function (lineData) {
// Find a new point on the line point 5 points back and push it to the new array // Find a new point on the line point 5 points back and push it to the new array
const newPrevPoint = findAdjacentPoint(prevPoint, cornerPoint, 5); const newPrevPoint = findAdjacentPoint(prevPoint, cornerPoint, 5);
const newNextPoint = findAdjacentPoint(nextPoint, cornerPoint, 5); const newNextPoint = findAdjacentPoint(nextPoint, cornerPoint, 5);
newLineData.push(newPrevPoint);
const xDiff = newNextPoint.x - newPrevPoint.x; const xDiff = newNextPoint.x - newPrevPoint.x;
const yDiff = newNextPoint.y - newPrevPoint.y; const yDiff = newNextPoint.y - newPrevPoint.y;
newLineData.push(newPrevPoint);
const a = Math.sqrt(2) * 2; const a = Math.sqrt(2) * 2;
let newCornerPoint = { x: cornerPoint.x, y: cornerPoint.y }; let newCornerPoint = { x: cornerPoint.x, y: cornerPoint.y };
if (Math.abs(nextPoint.x - prevPoint.x) > 10 && Math.abs(nextPoint.y - prevPoint.y) >= 10) { if (cornerPoint.x === newPrevPoint.x) {
console.log( // if (yDiff > 0) {
'Corner point fixing', newCornerPoint = {
Math.abs(nextPoint.x - prevPoint.x), x: xDiff < 0 ? newPrevPoint.x - 5 + a : newPrevPoint.x + 5 - a,
Math.abs(nextPoint.y - prevPoint.y) y: yDiff < 0 ? newPrevPoint.y - a : newPrevPoint.y + a,
); };
const r = 5; // } else {
if (cornerPoint.x === newPrevPoint.x) { // newCornerPoint = { x: newPrevPoint.x - a, y: newPrevPoint.y + a };
newCornerPoint = { // }
x: xDiff < 0 ? newPrevPoint.x - r + a : newPrevPoint.x + r - a,
y: yDiff < 0 ? newPrevPoint.y - a : newPrevPoint.y + a,
};
} else {
newCornerPoint = {
x: xDiff < 0 ? newPrevPoint.x - a : newPrevPoint.x + a,
y: yDiff < 0 ? newPrevPoint.y - r + a : newPrevPoint.y + r - a,
};
}
} else { } else {
console.log( // if (yDiff > 0) {
'Corner point skipping fixing', // newCornerPoint = { x: newPrevPoint.x - 5 + a, y: newPrevPoint.y + a };
Math.abs(nextPoint.x - prevPoint.x), // } else {
Math.abs(nextPoint.y - prevPoint.y) newCornerPoint = {
); x: xDiff < 0 ? newPrevPoint.x - a : newPrevPoint.x + a,
y: yDiff < 0 ? newPrevPoint.y - 5 + a : newPrevPoint.y + 5 - a,
};
// }
} }
// newLineData.push(cornerPoint);
newLineData.push(newCornerPoint, newNextPoint); newLineData.push(newCornerPoint, newNextPoint);
} else { } else {
newLineData.push(lineData[i]); newLineData.push(lineData[i]);
@@ -475,7 +471,6 @@ const fixCorners = function (lineData) {
} }
return newLineData; return newLineData;
}; };
/** /**
* Given a line, this function will return a new line where the corners are rounded. * Given a line, this function will return a new line where the corners are rounded.
* @param lineData * @param lineData

View File

@@ -36,6 +36,7 @@ const shapes = {
choice, choice,
note, note,
roundedRect, roundedRect,
rectWithTitle: roundedRect,
squareRect, squareRect,
stadium, stadium,
subroutine, subroutine,
@@ -57,9 +58,6 @@ export const insertNode = async (elem, node, dir) => {
let newEl; let newEl;
let el; let el;
if (node) {
console.log('BLA: rect node', JSON.stringify(node));
}
//special check for rect shape (with or without rounded corners) //special check for rect shape (with or without rounded corners)
if (node.shape === 'rect') { if (node.shape === 'rect') {
if (node.rx && node.ry) { if (node.rx && node.ry) {

View File

@@ -8,6 +8,5 @@ export const roundedRect = async (parent: SVGAElement, node: Node) => {
classes: '', classes: '',
} as RectOptions; } as RectOptions;
console.log('roundedRect XDX');
return drawRect(parent, node, options); return drawRect(parent, node, options);
}; };