Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
cells.forEach(cell => {
const state = graph.view.getState(cell)
if (state != null) {
let label = graph.getLabel(state.cell)
if (typeof label === 'string') {
if (graph.isHtmlLabel(cell)) {
if (util.getBoolean(state.style, 'nl2Br', true)) {
label = label.replace(/\n/g, '').replace(//g, '\n')
// Removes HTML tags
const temp = document.createElement('div')
temp.innerHTML = label
label = util.extractTextWithWhitespace(temp.childNodes as any)
}
} else {
// Converts HTML tags to text
label = util.escape(label)
if (util.getBoolean(state.style, 'nl2Br', true)) {
// Converts newlines in plain text to breaks in HTML
// to match the plain text output
label = label.replace(/\n/g, '<br>')
}
}
graph.updateLabel(cell, label)
getLabelMargins(rect: Rectangle) {
if (util.getBoolean(this.style, 'boundedLbl', false)) {
const w = rect.width
const h = rect.height
if (
this.direction == null ||
this.direction === 'east' ||
this.direction === 'west'
) {
const dy = getFactor(this.style, this.factor, h)
return new Rectangle(rect.x, rect.y + dy, w, h - 2 * dy)
}
const dx = getFactor(this.style, this.factor, w)
return new Rectangle(rect.x + dx, rect.y, w - 2 * dx, h)
}
getLabelMargins(rect: Rectangle) {
if (util.getBoolean(this.style, 'boundedLbl', false)) {
const dy = getFactor(this.style, this.factor, rect.height)
return new Rectangle(0, 0, 0, dy)
}
return null
}
getLabelMargins(rect: Rectangle) {
if (util.getBoolean(this.style, 'boundedLbl', false)) {
const s = util.getNumber(this.style, 'factor', this.factor) * this.scale
return new Rectangle(s, s, 0, 0)
}
return null
}