Skip to content

Commit

Permalink
5237 Replaced useRough by look
Browse files Browse the repository at this point in the history
  • Loading branch information
pbrolin47 committed Jun 12, 2024
1 parent 36e4fcf commit 1b5bd99
Show file tree
Hide file tree
Showing 24 changed files with 49 additions and 60 deletions.
9 changes: 4 additions & 5 deletions packages/mermaid/src/diagrams/flowchart/flowDb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -793,7 +793,7 @@ const addNodeFromVertex = (
parentDB: Map<string, string>,
subGraphDB: Map<string, boolean>,
config: any,
useRough: boolean
look: string
) => {
let parentId = parentDB.get(vertex.id);
let isGroup = subGraphDB.get(vertex.id) || false;
Expand All @@ -812,7 +812,7 @@ const addNodeFromVertex = (
dir: vertex.dir,
domId: vertex.domId,
isGroup,
useRough,
look,
});
}
};
Expand All @@ -822,7 +822,6 @@ export const getData = () => {
const nodes: Node[] = [];
const edges: Edge[] = [];

const useRough = config.look === 'handdrawn';
const subGraphs = getSubGraphs();
log.info('Subgraphs - APA12', subGraphs);
const parentDB = new Map<string, string>();
Expand All @@ -847,7 +846,7 @@ export const getData = () => {
shape: 'rect',
dir: subGraph.dir,
isGroup: true,
useRough,
look: config.look,
});
}

Expand All @@ -873,7 +872,7 @@ export const getData = () => {
arrowTypeEnd,
arrowheadStyle: 'fill: #333',
pattern: rawEdge.stroke,
useRough,
look: config.look,
};
console.log('rawEdge SPLIT', rawEdge, index);
edges.push(edge);
Expand Down
18 changes: 5 additions & 13 deletions packages/mermaid/src/diagrams/state/dataFetcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,16 +54,16 @@ export function stateDomId(itemId = '', counter = 0, type = '', typeSpacer = DOM
return `${DOMID_STATE}-${itemId}${typeStr}-${counter}`;
}

const setupDoc = (parentParsedItem, doc, diagramStates, nodes, edges, altFlag, useRough, look) => {
const setupDoc = (parentParsedItem, doc, diagramStates, nodes, edges, altFlag, look) => {
// graphItemCount = 0;
log.trace('items', doc);
doc.forEach((item) => {
switch (item.stmt) {
case STMT_STATE:
dataFetcher(parentParsedItem, item, diagramStates, nodes, edges, altFlag, useRough, look);
dataFetcher(parentParsedItem, item, diagramStates, nodes, edges, altFlag, look);
break;
case DEFAULT_STATE_TYPE:
dataFetcher(parentParsedItem, item, diagramStates, nodes, edges, altFlag, useRough, look);
dataFetcher(parentParsedItem, item, diagramStates, nodes, edges, altFlag, look);
break;
case STMT_RELATION:
{
Expand All @@ -73,8 +73,7 @@ const setupDoc = (parentParsedItem, doc, diagramStates, nodes, edges, altFlag, u
diagramStates,
nodes,
edges,
altFlag,
useRough,
altFlag,,
look
);
dataFetcher(
Expand All @@ -84,7 +83,6 @@ const setupDoc = (parentParsedItem, doc, diagramStates, nodes, edges, altFlag, u
nodes,
edges,
altFlag,
useRough,
look
);
const edgeData = {
Expand All @@ -101,7 +99,6 @@ const setupDoc = (parentParsedItem, doc, diagramStates, nodes, edges, altFlag, u
labelType: G_EDGE_LABELTYPE,
thickness: G_EDGE_THICKNESS,
classes: CSS_EDGE,
useRough,
look,
};
edges.push(edgeData);
Expand Down Expand Up @@ -232,7 +229,6 @@ export const dataFetcher = (
nodes,
edges,
altFlag,
useRough,
look
) => {
const itemId = parsedItem.id;
Expand Down Expand Up @@ -324,7 +320,6 @@ export const dataFetcher = (
padding: 8,
rx: 10,
ry: 10,
useRough,
look,
};

Expand Down Expand Up @@ -354,7 +349,6 @@ export const dataFetcher = (
type: newNode.type,
isGroup: newNode.type === 'group',
padding: 0, //getConfig().flowchart.padding
useRough,
look,
position: parsedItem.note.position,
};
Expand All @@ -369,7 +363,6 @@ export const dataFetcher = (
type: 'group',
isGroup: true,
padding: 16, //getConfig().flowchart.padding
useRough,
look,
position: parsedItem.note.position,
};
Expand Down Expand Up @@ -410,7 +403,6 @@ export const dataFetcher = (
labelpos: G_EDGE_LABELPOS,
labelType: G_EDGE_LABELTYPE,
thickness: G_EDGE_THICKNESS,
useRough,
look,
});
} else {
Expand All @@ -419,7 +411,7 @@ export const dataFetcher = (
}
if (parsedItem.doc) {
log.trace('Adding nodes children ');
setupDoc(parsedItem, parsedItem.doc, diagramStates, nodes, edges, !altFlag, useRough, look);
setupDoc(parsedItem, parsedItem.doc, diagramStates, nodes, edges, !altFlag, look);
}
};

Expand Down
3 changes: 1 addition & 2 deletions packages/mermaid/src/diagrams/state/stateDb.js
Original file line number Diff line number Diff line change
Expand Up @@ -228,10 +228,9 @@ const extract = (_doc) => {

const diagramStates = getStates();
const config = getConfig();
const useRough = config.look === 'handdrawn';
const look = config.look;
resetDataFetching();
dataFetcher(undefined, getRootDocV2(), diagramStates, nodes, edges, true, useRough, look);
dataFetcher(undefined, getRootDocV2(), diagramStates, nodes, edges, true, look);
};

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ const rect = (parent, node) => {
const siteConfig = getConfig();
const { themeVariables, handdrawnSeed } = siteConfig;
const { clusterBkg, clusterBorder } = themeVariables;
let { useRough } = node;

// Add outer g element
const shapeSvg = parent.insert('g').attr('class', 'cluster').attr('id', node.id);
Expand Down Expand Up @@ -60,7 +59,7 @@ const rect = (parent, node) => {

log.trace('Data ', node, JSON.stringify(node));
let rect;
if (useRough) {
if (node.look === 'handdrawn') {
// @ts-ignore TODO: Fix rough typings
const rc = rough.svg(shapeSvg);
const options = userNodeOverrides(node, {
Expand Down Expand Up @@ -223,7 +222,7 @@ const roundedWithTitle = (parent, node) => {

// add the rect
let rect;
if (node.useRough) {
if (node.look === 'handdrawn') {
const isAlt = node.cssClasses.includes('statediagram-cluster-alt');
const rc = rough.svg(shapeSvg);
const roughOuterNode =
Expand Down Expand Up @@ -305,7 +304,7 @@ const divider = (parent, node) => {
const y = node.y - node.height / 2;
const width = node.width + padding;
const height = node.height + padding;
if (node.useRough) {
if (node.look === 'handdrawn') {
const rc = rough.svg(shapeSvg);
const roughNode = rc.rectangle(x, y, width, height, {
fill: 'lightgrey',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -592,11 +592,10 @@ export const insertEdge = function (elem, edge, clusterDb, diagramType, startNod
default:
strokeClasses += ' edge-pattern-solid';
}
let useRough = edge.useRough;
let svgPath;
let path = '';
let linePath = lineFunction(lineData);
if (useRough) {
if (edge.look === 'handdrawn') {
const rc = rough.svg(elem);
const ld = Object.assign([], lineData);
// const svgPathNode = rc.path(lineFunction(ld.splice(0, ld.length-1)), {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export const choice = (parent: SVG, node: Node) => {
];

let choice;
if (node.useRough) {
if (node.look === 'handdrawn') {
// @ts-ignore TODO: Fix rough typings
const rc = rough.svg(shapeSvg);
const pointArr = points.map(function (d) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ export const circle = async (parent: SVGAElement, node: Node): Promise<SVGAEleme

const radius = bbox.width / 2 + halfPadding;
let circleElem;
const { cssStyles, useRough } = node;
const { cssStyles } = node;

if (useRough) {
if (node.look === 'handdrawn') {
// @ts-ignore - rough is not typed
const rc = rough.svg(shapeSvg);
const options = userNodeOverrides(node, {});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@ export const cylinder = async (parent: SVGAElement, node: Node) => {
const h = bbox.height + ry + node.padding;

let cylinder: d3.Selection<SVGPathElement | SVGGElement, unknown, null, undefined>;
const { cssStyles, useRough } = node;
const { cssStyles } = node;

if (useRough) {
if (node.look === 'handdrawn') {
// @ts-ignore - rough is not typed
const rc = rough.svg(shapeSvg);
const outerPathData = createOuterCylinderPathD(0, 0, w, h, rx, ry);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ export const doublecircle = async (parent: SVGAElement, node: Node): Promise<SVG
const innerRadius = bbox.width / 2 + halfPadding;

let circleGroup;
const { cssStyles, useRough } = node;
const { cssStyles } = node;

if (useRough) {
if (node.look === 'handdrawn') {
// @ts-ignore - rough is not typed
const rc = rough.svg(shapeSvg);
const outerOptions = userNodeOverrides(node, { roughness: 0.2, strokeWidth: 2.5 });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@ export const drawRect = async (parent: SVGAElement, node: Node, options: RectOpt

let rect;
let { rx, ry } = node;
const { cssStyles, useRough } = node;
const { cssStyles } = node;

//use options rx, ry overrides if present
if (options && options.rx && options.ry) {
rx = options.rx;
ry = options.ry;
}

if (useRough) {
if (node.look === 'handdrawn') {
// @ts-ignore TODO: Fix rough typings
const rc = rough.svg(shapeSvg);
const options = userNodeOverrides(node, {});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export const forkJoin = (parent: SVG, node: Node, dir: string) => {
const y = (-1 * height) / 2;

let shape;
if (node.useRough) {
if (node.look === 'handdrawn') {
// @ts-ignore TODO: Fix rough typings
const rc = rough.svg(shapeSvg);
const roughNode = rc.rectangle(x, y, width, height, solidStateFill(lineColor));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@ export const hexagon = async (parent: SVGAElement, node: Node): Promise<SVGAElem
];

let polygon: d3.Selection<SVGPolygonElement | SVGGElement, unknown, null, undefined>;
const { cssStyles, useRough } = node;
const { cssStyles } = node;

if (useRough) {
if (node.look === 'handdrawn') {
// @ts-ignore - rough is not typed
const rc = rough.svg(shapeSvg);
const options = userNodeOverrides(node, {});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ export const inv_trapezoid = async (parent: SVGAElement, node: Node): Promise<SV
];

let polygon: d3.Selection<SVGPolygonElement | SVGGElement, unknown, null, undefined>;
const { cssStyles, useRough } = node;
const { cssStyles } = node;

if (useRough) {
if (node.look === 'handdrawn') {
// @ts-ignore - rough is not typed
const rc = rough.svg(shapeSvg);
const options = userNodeOverrides(node, {});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ export const lean_left = async (parent: SVGAElement, node: Node): Promise<SVGAEl
];

let polygon: d3.Selection<SVGPolygonElement | SVGGElement, unknown, null, undefined>;
const { cssStyles, useRough } = node;
const { cssStyles } = node;

if (useRough) {
if (node.look === 'handdrawn') {
// @ts-ignore - rough is not typed
const rc = rough.svg(shapeSvg);
const options = userNodeOverrides(node, {});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ export const lean_right = async (parent: SVGAElement, node: Node): Promise<SVGAE
];

let polygon: d3.Selection<SVGPolygonElement | SVGGElement, unknown, null, undefined>;
const { cssStyles, useRough } = node;
const { cssStyles } = node;

if (useRough) {
if (node.look === 'handdrawn') {
// @ts-ignore - rough is not typed
const rc = rough.svg(shapeSvg);
const options = userNodeOverrides(node, {});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@ export const note = async (parent: SVGAElement, node: Node) => {
);

log.info('Classes = ', node.cssClasses);
const { cssStyles, useRough } = node;
const { cssStyles } = node;
let rect;
const totalWidth = bbox.width + node.padding;
const totalHeight = bbox.height + node.padding;
const x = -bbox.width / 2 - halfPadding;
const y = -bbox.height / 2 - halfPadding;

if (useRough) {
if (node.look === 'handdrawn') {
// add the rect
// @ts-ignore TODO: Fix rough typings
const rc = rough.svg(shapeSvg);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ export const question = async (parent: SVGAElement, node: Node): Promise<SVGAEle
];

let polygon: d3.Selection<SVGPolygonElement | SVGGElement, unknown, null, undefined>;
const { cssStyles, useRough } = node;
const { cssStyles } = node;

if (useRough) {
if (node.look === 'handdrawn') {
// @ts-ignore - rough is not typed
const rc = rough.svg(shapeSvg);
const options = userNodeOverrides(node, {});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ export const rect_left_inv_arrow = async (
];

let polygon;
const { cssStyles, useRough } = node;
const { cssStyles } = node;

if (useRough) {
if (node.look === 'handdrawn') {
// @ts-ignore - rough is not typed
const rc = rough.svg(shapeSvg);
const options = userNodeOverrides(node, {});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ export const stadium = async (parent: SVGAElement, node: Node) => {
const w = bbox.width + h / 4 + node.padding;

let rect;
const { cssStyles, useRough } = node;
if (useRough) {
const { cssStyles } = node;
if (node.look === 'handdrawn') {
// @ts-ignore - rough is not typed
const rc = rough.svg(shapeSvg);
const options = userNodeOverrides(node, {});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export const stateEnd = (parent: SVG, node: Node) => {

let circle;
let innerCircle;
if (node.useRough) {
if (node.look === 'handdrawn') {
// @ts-ignore TODO: Fix rough typings
const rc = rough.svg(shapeSvg);
const roughNode = rc.circle(0, 0, 14, { ...solidStateFill(lineColor), roughness: 0.5 });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export const stateStart = (parent: SVG, node: Node) => {
.attr('id', node.domId || node.id);

let circle;
if (node.useRough) {
if (node.look === 'handdrawn') {
// @ts-ignore TODO: Fix rough typings
const rc = rough.svg(shapeSvg);
const roughNode = rc.circle(0, 0, 14, solidStateFill(lineColor));
Expand Down
Loading

0 comments on commit 1b5bd99

Please sign in to comment.