08-27-周三_17-09-29

This commit is contained in:
2025-08-27 17:10:05 +08:00
commit 86df397d8f
12735 changed files with 1145479 additions and 0 deletions

View File

@@ -0,0 +1,37 @@
import util from '../util'
function addHtmlLabel (root, node) {
const fo = root
.append('foreignObject')
.attr('width', '100000')
const div = fo
.append('xhtml:div')
div.attr('xmlns', 'http://www.w3.org/1999/xhtml')
const label = node.label
switch (typeof label) {
case 'function':
div.insert(label)
break
case 'object':
// Currently we assume this is a DOM object.
div.insert(function () { return label })
break
default: div.html(label)
}
util.applyStyle(div, node.labelStyle)
div.style('display', 'inline-block')
// Fix for firefox
div.style('white-space', 'nowrap')
const client = div[0][0].getBoundingClientRect()
fo
.attr('width', client.width)
.attr('height', client.height)
return fo
}
export default addHtmlLabel

37
node_modules/dagre-d3-renderer/lib/label/add-label.js generated vendored Normal file
View File

@@ -0,0 +1,37 @@
import addTextLabel from './add-text-label'
import addHtmlLabel from './add-html-label'
import addSVGLabel from './add-svg-label'
function addLabel (root, node, location) {
const label = node.label
const labelSvg = root.append('g')
// Allow the label to be a string, a function that returns a DOM element, or
// a DOM element itself.
if (node.labelType === 'svg') {
addSVGLabel(labelSvg, node)
} else if (typeof label !== 'string' || node.labelType === 'html') {
addHtmlLabel(labelSvg, node)
} else {
addTextLabel(labelSvg, node)
}
const labelBBox = labelSvg.node().getBBox()
let y
switch (location) {
case 'top':
y = (-node.height / 2)
break
case 'bottom':
y = (node.height / 2) - labelBBox.height
break
default:
y = (-labelBBox.height / 2)
}
labelSvg.attr('transform',
'translate(' + (-labelBBox.width / 2) + ',' + y + ')')
return labelSvg
}
export default addLabel

View File

@@ -0,0 +1,13 @@
import util from '../util'
function addSVGLabel (root, node) {
const domNode = root
domNode.node().appendChild(node.label)
util.applyStyle(domNode, node.labelStyle)
return domNode
}
export default addSVGLabel

View File

@@ -0,0 +1,45 @@
import util from '../util'
/*
* Attaches a text label to the specified root. Handles escape sequences.
*/
function addTextLabel (root, node) {
const domNode = root.append('text')
const lines = processEscapeSequences(node.label).split('\n')
for (let i = 0; i < lines.length; i += 1) {
domNode
.append('tspan')
.attr('xml:space', 'preserve')
.attr('dy', '1em')
.attr('x', '1')
.text(lines[i])
}
util.applyStyle(domNode, node.labelStyle)
return domNode
}
function processEscapeSequences (text) {
let newText = ''
let escaped = false
let ch = null
for (let i = 0; i < text.length; i += 1) {
ch = text[i]
if (escaped) {
switch (ch) {
case 'n': newText += '\n'; break
default: newText += ch
}
escaped = false
} else if (ch === '\\') {
escaped = true
} else {
newText += ch
}
}
return newText
}
export default addTextLabel