-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a2702e4
commit dd5bfb3
Showing
12 changed files
with
238 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
packages/mermaid/src/rendering-util/rendering-elements/shapes/choice.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import intersect from '../intersect/index.js'; | ||
import type { Node } from '$root/rendering-util/types.d.ts'; | ||
import type { SVG } from '$root/diagram-api/types.js'; | ||
|
||
export const choice = (parent: SVG, node: Node) => { | ||
const shapeSvg = parent | ||
.insert('g') | ||
.attr('class', 'node default') | ||
.attr('id', node.domId || node.id); | ||
|
||
const s = 28; | ||
const points = [ | ||
{ x: 0, y: s / 2 }, | ||
{ x: s / 2, y: 0 }, | ||
{ x: 0, y: -s / 2 }, | ||
{ x: -s / 2, y: 0 }, | ||
]; | ||
|
||
const choice = shapeSvg.insert('polygon', ':first-child').attr( | ||
'points', | ||
points | ||
.map(function (d) { | ||
return d.x + ',' + d.y; | ||
}) | ||
.join(' ') | ||
); | ||
// center the circle around its coordinate | ||
choice.attr('class', 'state-start').attr('r', 7).attr('width', 28).attr('height', 28); | ||
node.width = 28; | ||
node.height = 28; | ||
|
||
node.intersect = function (point) { | ||
return intersect.circle(node, 14, point); | ||
}; | ||
|
||
return shapeSvg; | ||
}; |
51 changes: 51 additions & 0 deletions
51
packages/mermaid/src/rendering-util/rendering-elements/shapes/forkJoin.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import { log } from '$root/logger.js'; | ||
import { updateNodeBounds } from './util.js'; | ||
import intersect from '../intersect/index.js'; | ||
import type { Node } from '$root/rendering-util/types.d.ts'; | ||
import type { SVG } from '$root/diagram-api/types.js'; | ||
|
||
export const forkJoin = (parent: SVG, node: Node, dir: string) => { | ||
const shapeSvg = parent | ||
.insert('g') | ||
.attr('class', 'node default') | ||
.attr('id', node.domId || node.id); | ||
|
||
let width = 70; | ||
let height = 10; | ||
|
||
if (dir === 'LR') { | ||
width = 10; | ||
height = 70; | ||
} | ||
|
||
const shape = shapeSvg | ||
.append('rect') | ||
.attr('x', (-1 * width) / 2) | ||
.attr('y', (-1 * height) / 2) | ||
.attr('width', width) | ||
.attr('height', height) | ||
.attr('class', 'fork-join'); | ||
|
||
updateNodeBounds(node, shape); | ||
let nodeHeight = 0; | ||
let nodeWidth = 0; | ||
let nodePadding = 10; | ||
if (node.height) { | ||
nodeHeight = node.height; | ||
} | ||
if (node.width) { | ||
nodeWidth = node.width; | ||
} | ||
|
||
if (node.padding) { | ||
nodePadding = node.padding; | ||
} | ||
|
||
node.height = nodeHeight + nodePadding / 2; | ||
node.width = nodeWidth + nodePadding / 2; | ||
node.intersect = function (point) { | ||
return intersect.rect(node, point); | ||
}; | ||
|
||
return shapeSvg; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
packages/mermaid/src/rendering-util/rendering-elements/shapes/stateEnd.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { log } from '$root/logger.js'; | ||
import { updateNodeBounds } from './util.js'; | ||
import intersect from '../intersect/index.js'; | ||
import type { Node } from '$root/rendering-util/types.d.ts'; | ||
import type { SVG } from '$root/diagram-api/types.js'; | ||
|
||
export const stateEnd = (parent: SVG, node: Node) => { | ||
const shapeSvg = parent | ||
.insert('g') | ||
.attr('class', 'node default') | ||
.attr('id', node.domId || node.id); | ||
const innerCircle = shapeSvg.insert('circle', ':first-child'); | ||
const circle = shapeSvg.insert('circle', ':first-child'); | ||
|
||
circle.attr('class', 'state-start').attr('r', 7).attr('width', 14).attr('height', 14); | ||
|
||
innerCircle.attr('class', 'state-end').attr('r', 5).attr('width', 10).attr('height', 10); | ||
|
||
updateNodeBounds(node, circle); | ||
|
||
node.intersect = function (point) { | ||
return intersect.circle(node, 7, point); | ||
}; | ||
|
||
return shapeSvg; | ||
}; |
24 changes: 24 additions & 0 deletions
24
packages/mermaid/src/rendering-util/rendering-elements/shapes/stateStart.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { log } from '$root/logger.js'; | ||
import { updateNodeBounds } from './util.js'; | ||
import intersect from '../intersect/index.js'; | ||
import type { Node } from '$root/rendering-util/types.d.ts'; | ||
import type { SVG } from '$root/diagram-api/types.js'; | ||
|
||
export const stateStart = (parent: SVG, node: Node) => { | ||
const shapeSvg = parent | ||
.insert('g') | ||
.attr('class', 'node default') | ||
.attr('id', node.domId || node.id); | ||
const circle = shapeSvg.insert('circle', ':first-child'); | ||
|
||
// center the circle around its coordinate | ||
circle.attr('class', 'state-start').attr('r', 7).attr('width', 14).attr('height', 14); | ||
|
||
updateNodeBounds(node, circle); | ||
|
||
node.intersect = function (point) { | ||
return intersect.circle(node, 7, point); | ||
}; | ||
|
||
return shapeSvg; | ||
}; |
40 changes: 40 additions & 0 deletions
40
packages/mermaid/src/rendering-util/setupViewPortForSVG.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import { configureSvgSize } from '$root/setupGraphViewbox.js'; | ||
import type { SVG } from '$root/diagram-api/types.js'; | ||
import { log } from '$root/logger.js'; | ||
|
||
export const setupViewPortForSVG = ( | ||
svg: SVG, | ||
padding: number, | ||
cssDiagram: string, | ||
useMaxWidth: boolean | ||
) => { | ||
// Initialize the SVG element and set the diagram class | ||
svg.attr('class', cssDiagram); | ||
|
||
// Calculate the dimensions and position with padding | ||
const { width, height, x, y } = calculateDimensionsWithPadding(svg, padding); | ||
|
||
// Configure the size and aspect ratio of the SVG | ||
configureSvgSize(svg, height, width, useMaxWidth); | ||
|
||
// Update the viewBox to ensure all content is visible with padding | ||
const viewBox = createViewBox(x, y, width, height, padding); | ||
svg.attr('viewBox', viewBox); | ||
|
||
// Log the viewBox configuration for debugging | ||
log.debug(`viewBox configured: ${viewBox}`); | ||
}; | ||
|
||
const calculateDimensionsWithPadding = (svg: SVG, padding: number) => { | ||
const bounds = svg.node()?.getBBox() || { width: 0, height: 0, x: 0, y: 0 }; | ||
return { | ||
width: bounds.width + padding * 2, | ||
height: bounds.height + padding * 2, | ||
x: bounds.x, | ||
y: bounds.y, | ||
}; | ||
}; | ||
|
||
const createViewBox = (x: number, y: number, width: number, height: number, padding: number) => { | ||
return `${x - padding} ${y - padding} ${width} ${height}`; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters