mirror of
https://github.com/mermaid-js/mermaid.git
synced 2025-01-14 06:43:25 +08:00
WIP
This commit is contained in:
parent
ccdb803501
commit
836d3a87be
@ -26,6 +26,8 @@
|
||||
}
|
||||
.mermaid {
|
||||
border: 1px solid #ddd;
|
||||
margin: 10px;
|
||||
background: pink;
|
||||
}
|
||||
.mermaid2 {
|
||||
display: none;
|
||||
@ -38,6 +40,7 @@
|
||||
background-size: 20px 20px;
|
||||
background-position: 0 0, 10px 10px;
|
||||
background-repeat: repeat;
|
||||
border: 1px solid red;
|
||||
}
|
||||
.malware {
|
||||
position: fixed;
|
||||
@ -62,10 +65,13 @@
|
||||
<body>
|
||||
<pre id="diagram" class="mermaid">
|
||||
block-beta
|
||||
id1("Wide 1")
|
||||
%% id1("Wide 1")
|
||||
id2("2")
|
||||
id3("3")
|
||||
id4("A final one")
|
||||
block
|
||||
id3
|
||||
id4
|
||||
end
|
||||
%% id4("A final one")
|
||||
|
||||
</pre>
|
||||
<pre id="diagram" class="mermaid2">
|
||||
|
@ -325,17 +325,13 @@ const rect = async (parent, node) => {
|
||||
// const totalHeight = bbox.height + node.padding * 2;
|
||||
const totalWidth = node.positioned ? node.width : bbox.width + node.padding;
|
||||
const totalHeight = node.positioned ? node.height : bbox.height + node.padding;
|
||||
const x = node.positioned ? node.x - node.width / 2 - halfPadding : -bbox.width / 2 - halfPadding;
|
||||
const y = node.positioned
|
||||
? node.y - node.height / 2 - halfPadding
|
||||
: -bbox.height / 2 - halfPadding;
|
||||
const x = node.positioned ? -totalWidth / 2 : -bbox.width / 2 - halfPadding;
|
||||
const y = node.positioned ? -totalHeight / 2 : -bbox.height / 2 - halfPadding;
|
||||
rect
|
||||
.attr('class', 'basic label-container')
|
||||
.attr('style', node.style)
|
||||
.attr('rx', node.rx)
|
||||
.attr('ry', node.ry)
|
||||
// .attr('x', -bbox.width / 2 - node.padding)
|
||||
// .attr('y', -bbox.height / 2 - node.padding)
|
||||
.attr('x', x)
|
||||
.attr('y', y)
|
||||
.attr('width', totalWidth)
|
||||
@ -1030,8 +1026,8 @@ export const clear = () => {
|
||||
};
|
||||
|
||||
export const positionNode = (node) => {
|
||||
console.log('Node id = ', node.id);
|
||||
const el = nodeElems[node.id];
|
||||
|
||||
log.trace(
|
||||
'Transforming node',
|
||||
node.diff,
|
||||
|
@ -16,6 +16,7 @@ import type { Block } from './blockTypes.js';
|
||||
// import { diagram as BlockDiagram } from './blockDiagram.js';
|
||||
import { configureSvgSize } from '../../setupGraphViewbox.js';
|
||||
import { Uid } from '../../rendering-util/uid.js';
|
||||
import { pad } from 'lodash';
|
||||
|
||||
export const draw = async function (
|
||||
text: string,
|
||||
@ -42,19 +43,28 @@ export const draw = async function (
|
||||
const nodes = svg.insert('g').attr('class', 'block');
|
||||
await calculateBlockSizes(nodes, bl, db);
|
||||
const bounds = layout(db);
|
||||
console.log('Here blocks', bl);
|
||||
await insertBlocks(nodes, bl, db);
|
||||
|
||||
console.log('Here', bl);
|
||||
// console.log('Here', bl);
|
||||
|
||||
// Establish svg dimensions and get width and height
|
||||
//
|
||||
// const bounds = nodes.node().getBoundingClientRect();
|
||||
const height = bounds.height + 600;
|
||||
const width = bounds.width + 699;
|
||||
// const bounds2 = nodes.node().getBoundingClientRect();
|
||||
const bounds2 = bounds;
|
||||
const padding = 10;
|
||||
// Why, oh why ????
|
||||
const magicFactor = Math.max(1, Math.round(0.125 * (bounds2.width / bounds2.height)));
|
||||
const height = bounds2.height + magicFactor + 10;
|
||||
const width = bounds2.width + 10;
|
||||
const useMaxWidth = false;
|
||||
configureSvgSize(svg, height, width, useMaxWidth);
|
||||
console.log('Here Bounds', bounds);
|
||||
svg.attr('viewBox', `${bounds.x} ${bounds.y} ${bounds.width} ${bounds.height}`);
|
||||
console.log('Here Bounds', bounds, bounds2);
|
||||
svg.attr(
|
||||
'viewBox',
|
||||
`${bounds2.x - 5} ${bounds2.y - 5} ${bounds2.width + 10} ${bounds2.height + 10}`
|
||||
);
|
||||
// svg.attr('viewBox', `${-200} ${-200} ${400} ${400}`);
|
||||
|
||||
// Prepare data for construction based on diagObj.db
|
||||
// This must be a mutable object with `nodes` and `links` properties:
|
||||
|
@ -66,17 +66,17 @@ let maxY = 0;
|
||||
function findBounds(block: Block) {
|
||||
if (block.size) {
|
||||
const { x, y, width, height } = block.size;
|
||||
if (x - width < minX) {
|
||||
minX = x - width;
|
||||
if (x - width / 2 < minX) {
|
||||
minX = x - width / 2;
|
||||
}
|
||||
if (y - height < minY) {
|
||||
minY = y - height;
|
||||
if (y - height / 2 < minY) {
|
||||
minY = y - height / 2;
|
||||
}
|
||||
if (x > maxX) {
|
||||
maxX = x;
|
||||
if (x + width / 2 > maxX) {
|
||||
maxX = x + width / 2;
|
||||
}
|
||||
if (y > maxY) {
|
||||
maxY = y;
|
||||
if (y + height / 2 > maxY) {
|
||||
maxY = y + height / 2;
|
||||
}
|
||||
}
|
||||
if (block.children) {
|
||||
@ -90,13 +90,14 @@ export function layout(db: BlockDB) {
|
||||
const blocks = db.getBlocks();
|
||||
const root = { id: 'root', type: 'composite', children: blocks } as Block;
|
||||
layoutBLock(root, db);
|
||||
positionBlock(root, db);
|
||||
// positionBlock(root, db);
|
||||
|
||||
minX = 0;
|
||||
minY = 0;
|
||||
maxX = 0;
|
||||
maxY = 0;
|
||||
findBounds(root);
|
||||
console.log('Here maxX', maxX);
|
||||
const height = maxY - minY;
|
||||
const width = maxX - minX;
|
||||
return { x: minX, y: minY, width, height };
|
||||
|
@ -1,5 +1,5 @@
|
||||
import { getStylesFromArray } from '../../utils.js';
|
||||
import { insertNode } from '../../dagre-wrapper/nodes.js';
|
||||
import { insertNode, positionNode } from '../../dagre-wrapper/nodes.js';
|
||||
import { getConfig } from '../../config.js';
|
||||
import { ContainerElement } from 'd3';
|
||||
import type { Block } from './blockTypes.js';
|
||||
@ -146,6 +146,7 @@ export async function insertBlockPositioned(elem: any, block: any, db: any) {
|
||||
// Add the element to the DOM to size it
|
||||
const obj = db.getBlock(node.id);
|
||||
const nodeEl = await insertNode(elem, node);
|
||||
positionNode(node);
|
||||
}
|
||||
|
||||
export async function performOperations(
|
||||
|
Loading…
x
Reference in New Issue
Block a user