|
var mxIsElectron = navigator.userAgent != null && |
|
navigator.userAgent.toLowerCase().indexOf(' electron/') > -1; |
|
var GOOGLE_APPS_MAX_AREA = 25000000; |
|
var GOOGLE_SHEET_MAX_AREA = 1048576; |
|
|
|
|
|
Editor.initMath((remoteMath? 'https://app.diagrams.net/' : '') + 'math/MathJax.js'); |
|
|
|
function render(data) |
|
{ |
|
var autoScale = false; |
|
|
|
if (data.scale == 'auto') |
|
{ |
|
autoScale = true; |
|
data.scale = 1; |
|
} |
|
|
|
|
|
|
|
document.body.innerText = ''; |
|
var container = document.createElement('div'); |
|
container.id = 'graph'; |
|
container.style.width = '100%'; |
|
container.style.height = '100%'; |
|
document.body.appendChild(container); |
|
|
|
var graph = new Graph(container); |
|
data.border = parseInt(data.border) || 0; |
|
data.w = parseFloat(data.w) || 0; |
|
data.h = parseFloat(data.h) || 0; |
|
data.scale = parseFloat(data.scale) || 1; |
|
|
|
var extras = null; |
|
|
|
try |
|
{ |
|
extras = JSON.parse(data.extras); |
|
} |
|
catch (e) |
|
{ |
|
try |
|
{ |
|
extras = JSON.parse(decodeURIComponent(data.extras)); |
|
} |
|
catch (e) |
|
{ |
|
|
|
} |
|
} |
|
|
|
var gridColor = null; |
|
|
|
if (extras != null && extras.grid != null) |
|
{ |
|
graph.gridSize = extras.grid.size; |
|
graph.view.gridSteps = extras.grid.steps; |
|
gridColor = extras.grid.color; |
|
} |
|
|
|
if (extras != null && extras.diagramLanguage != null) |
|
{ |
|
Graph.diagramLanguage = extras.diagramLanguage; |
|
Graph.translateDiagram = true; |
|
} |
|
|
|
|
|
if (data.xml.substring(0, 5) == 'iVBOR' || (extras != null && extras.isPng)) |
|
{ |
|
data.xml = Editor.extractGraphModelFromPng('data:image/png;base64,' + data.xml); |
|
} |
|
|
|
|
|
if (data.xml.substring(0, 11) == '<#document>') |
|
{ |
|
data.xml = data.xml.substring(11, data.xml.length - 12); |
|
} |
|
|
|
|
|
var doc = mxUtils.parseXml(data.xml); |
|
var node = Editor.extractGraphModel(doc.documentElement, true); |
|
|
|
if (node == null) |
|
{ |
|
|
|
try |
|
{ |
|
electron.sendMessage('render-finished', null); |
|
} |
|
catch(e) |
|
{ |
|
console.log(e); |
|
} |
|
|
|
return graph; |
|
} |
|
|
|
var xmlDoc = node.ownerDocument; |
|
var origXmlDoc = xmlDoc; |
|
var diagrams = null; |
|
var from = 0; |
|
|
|
function getFileXml(uncompressed) |
|
{ |
|
var xml = mxUtils.getXml(origXmlDoc); |
|
EditorUi.prototype.createUi = function(){}; |
|
EditorUi.prototype.addTrees = function(){}; |
|
EditorUi.prototype.updateActionStates = function(){}; |
|
var editorUi = new EditorUi(); |
|
var tmpFile = new LocalFile(editorUi, xml); |
|
editorUi.setCurrentFile(tmpFile); |
|
editorUi.setFileData(xml); |
|
return editorUi.createFileData(editorUi.getXmlFileData(null, null, uncompressed)); |
|
}; |
|
|
|
if (mxIsElectron && data.format == 'xml') |
|
{ |
|
try |
|
{ |
|
electron.sendMessage('xml-data', getFileXml(data.uncompressed)); |
|
} |
|
catch(e) |
|
{ |
|
electron.sendMessage('xml-data-error'); |
|
} |
|
|
|
return; |
|
} |
|
|
|
|
|
if (xmlDoc.documentElement.nodeName == 'mxfile') |
|
{ |
|
diagrams = xmlDoc.documentElement.getElementsByTagName('diagram'); |
|
} |
|
|
|
|
|
if (extras != null && extras.globalVars != null) |
|
{ |
|
graph.globalVars = extras.globalVars; |
|
} |
|
|
|
|
|
|
|
|
|
var graphGetLinkForCell = graph.getLinkForCell; |
|
|
|
graph.getLinkForCell = function(cell) |
|
{ |
|
var link = graphGetLinkForCell.apply(this, arguments); |
|
|
|
if (link != null && this.isCustomLink(link)) |
|
{ |
|
link = null; |
|
} |
|
|
|
return link; |
|
}; |
|
|
|
|
|
|
|
|
|
var cellRendererRedrawLabelShape = graph.cellRenderer.redrawLabelShape; |
|
|
|
graph.cellRenderer.redrawLabelShape = function(shape) |
|
{ |
|
cellRendererRedrawLabelShape.apply(this, arguments); |
|
|
|
if (shape.node != null) |
|
{ |
|
var links = shape.node.getElementsByTagName('a'); |
|
|
|
for (var i = 0; i < links.length; i++) |
|
{ |
|
var href = links[i].getAttribute('href'); |
|
|
|
if (href != null && graph.isCustomLink(href)) |
|
{ |
|
links[i].setAttribute('href', '#'); |
|
} |
|
} |
|
} |
|
}; |
|
|
|
var preview = null; |
|
var waitCounter = 1; |
|
var bounds; |
|
var pageId; |
|
var expScale; |
|
|
|
var cache = new Object(); |
|
var math = false; |
|
|
|
|
|
function decrementWaitCounter() |
|
{ |
|
if (--waitCounter < 1) |
|
{ |
|
|
|
|
|
document.fonts.ready.then(function() |
|
{ |
|
var doneDiv = document.createElement("div"); |
|
var pageCount = diagrams != null? diagrams.length : 1; |
|
doneDiv.id = 'LoadingComplete'; |
|
doneDiv.style.display = 'none'; |
|
doneDiv.setAttribute('bounds', JSON.stringify(bounds)); |
|
doneDiv.setAttribute('page-id', pageId); |
|
doneDiv.setAttribute('scale', expScale); |
|
doneDiv.setAttribute('pageCount', pageCount); |
|
document.body.appendChild(doneDiv); |
|
|
|
|
|
if (mxIsElectron) |
|
{ |
|
try |
|
{ |
|
electron.registerMsgListener('get-svg-data', (arg) => |
|
{ |
|
graph.mathEnabled = math; |
|
|
|
var bg = graph.background; |
|
|
|
if (bg == mxConstants.NONE) |
|
{ |
|
bg = null; |
|
} |
|
|
|
var svgRoot = graph.getSvg(bg, 1, 0, false, null, true, null, null, null); |
|
|
|
if (graph.shadowVisible) |
|
{ |
|
graph.addSvgShadow(svgRoot); |
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (math) |
|
{ |
|
Editor.prototype.addMathCss(svgRoot); |
|
} |
|
|
|
function doSend() |
|
{ |
|
var editable = data.embedXml == '1'; |
|
|
|
if (editable) |
|
{ |
|
svgRoot.setAttribute('content', getFileXml()); |
|
} |
|
|
|
electron.sendMessage('svg-data', Graph.xmlDeclaration + '\n' + ((editable) ? Graph.svgFileComment + '\n' : '') + |
|
Graph.svgDoctype + '\n' + mxUtils.getXml(svgRoot)); |
|
}; |
|
|
|
if (data.embedImages == '1') |
|
{ |
|
var tmpEditor = new Editor(); |
|
tmpEditor.convertImages(svgRoot, doSend); |
|
} |
|
else |
|
{ |
|
doSend(); |
|
} |
|
}); |
|
|
|
|
|
electron.sendMessage('render-finished', {bounds: JSON.stringify(bounds), pageCount: pageCount}); |
|
} |
|
catch(e) |
|
{ |
|
console.log(e); |
|
} |
|
} |
|
}); |
|
} |
|
}; |
|
|
|
function waitForImages(tagName, attributeName) |
|
{ |
|
var imgs = document.body.getElementsByTagName(tagName); |
|
waitCounter += imgs.length; |
|
|
|
for (var i = 0; i < imgs.length; i++) |
|
{ |
|
|
|
var src = imgs[i].getAttribute(attributeName); |
|
|
|
if (src != null && src.length > 0 && cache[src] == null) |
|
{ |
|
cache[src] = new Image(); |
|
cache[src].onload = decrementWaitCounter; |
|
cache[src].onerror = decrementWaitCounter; |
|
cache[src].src = src; |
|
} |
|
else |
|
{ |
|
decrementWaitCounter(); |
|
} |
|
} |
|
}; |
|
|
|
|
|
|
|
var editorDoMathJaxRender = Editor.doMathJaxRender; |
|
|
|
Editor.doMathJaxRender = function(container) |
|
{ |
|
editorDoMathJaxRender.apply(this, arguments); |
|
|
|
window.setTimeout(function() |
|
{ |
|
window.MathJax.Hub.Queue(function () |
|
{ |
|
decrementWaitCounter(); |
|
}); |
|
}, 0); |
|
}; |
|
|
|
|
|
function renderMath(elt) |
|
{ |
|
if (math && Editor.MathJaxRender != null) |
|
{ |
|
waitCounter++; |
|
Editor.MathJaxRender(elt); |
|
} |
|
}; |
|
|
|
function loadExtFonts(extFonts) |
|
{ |
|
try |
|
{ |
|
extFonts = extFonts.split('|').map(function(ef) |
|
{ |
|
var parts = ef.split('^'); |
|
return {name: parts[0], url: parts[1]}; |
|
}); |
|
} |
|
catch(e) |
|
{ |
|
|
|
return; |
|
} |
|
|
|
waitCounter += extFonts.length; |
|
|
|
|
|
for (var i = 0; i < extFonts.length; i++) |
|
{ |
|
if (extFonts[i].url.indexOf(Editor.GOOGLE_FONTS) == 0) |
|
{ |
|
var link = document.createElement('link'); |
|
|
|
link.setAttribute('rel', 'stylesheet'); |
|
link.setAttribute('charset', 'UTF-8'); |
|
link.setAttribute('type', 'text/css'); |
|
|
|
link.onload = decrementWaitCounter; |
|
link.onerror = decrementWaitCounter; |
|
|
|
link.setAttribute('href', extFonts[i].url); |
|
var head = document.getElementsByTagName('head')[0]; |
|
head.appendChild(link); |
|
} |
|
else |
|
{ |
|
|
|
if (extFonts[i].url.indexOf(PROXY_URL) == 0 && PROXY_URL.indexOf('http') == -1) |
|
{ |
|
var href = window.location.href; |
|
href = href.substring(0, href.lastIndexOf('/') + 1); |
|
extFonts[i].url = href + extFonts[i].url; |
|
} |
|
|
|
var font = new FontFace(extFonts[i].name, 'url(' + extFonts[i].url + ')'); |
|
|
|
font.load().then(function(loadedFont) |
|
{ |
|
document.fonts.add(loadedFont); |
|
decrementWaitCounter(); |
|
}).catch(decrementWaitCounter); |
|
} |
|
} |
|
}; |
|
|
|
function renderGrid() |
|
{ |
|
if (gridColor == null) return; |
|
|
|
var view = graph.view; |
|
var gridImage = btoa(unescape(encodeURIComponent(view.createSvgGrid(gridColor)))); |
|
gridImage = 'url(' + 'data:image/svg+xml;base64,' + gridImage + ')'; |
|
var phase = graph.gridSize * view.gridSteps * view.scale; |
|
|
|
var x0 = 0; |
|
var y0 = 0; |
|
|
|
if (view.backgroundPageShape != null) |
|
{ |
|
var bds = view.getBackgroundPageBounds(); |
|
|
|
x0 = 1 + bds.x; |
|
y0 = 1 + bds.y; |
|
} |
|
|
|
|
|
var position = -Math.round(phase - mxUtils.mod(view.translate.x * view.scale - x0, phase)) + 'px ' + |
|
-Math.round(phase - mxUtils.mod(view.translate.y * view.scale - y0, phase)) + 'px'; |
|
|
|
var pages = document.querySelectorAll('[id^=mxPage]'); |
|
|
|
var cssTxt = 'margin: 0;padding: 0;background-image: ' + gridImage + ';background-position: ' + position; |
|
document.body.style.cssText = cssTxt; |
|
|
|
for (var i = 0; i < pages.length; i++) |
|
{ |
|
pages[i].style.cssText = cssTxt; |
|
} |
|
}; |
|
|
|
var origAddFont = Graph.addFont; |
|
|
|
Graph.addFont = function(name, url) |
|
{ |
|
waitCounter++; |
|
return origAddFont.call(this, name, url, decrementWaitCounter); |
|
}; |
|
|
|
function renderPage() |
|
{ |
|
|
|
math |= xmlDoc.documentElement.getAttribute('math') == '1'; |
|
|
|
|
|
var extFonts = xmlDoc.documentElement.getAttribute('extFonts'); |
|
|
|
if (extFonts) |
|
{ |
|
loadExtFonts(extFonts); |
|
} |
|
|
|
|
|
graph.foldingEnabled = false; |
|
graph.setEnabled(false); |
|
|
|
|
|
var bgImg = xmlDoc.documentElement.getAttribute('backgroundImage'); |
|
|
|
if (bgImg != null) |
|
{ |
|
bgImg = JSON.parse(bgImg); |
|
graph.setBackgroundImage(new mxImage(bgImg.src, bgImg.width, |
|
bgImg.height, bgImg.x, bgImg.y)); |
|
} |
|
|
|
|
|
var codec = new mxCodec(xmlDoc); |
|
var model = graph.getModel(); |
|
codec.decode(xmlDoc.documentElement, model); |
|
|
|
var bg; |
|
|
|
if (data.format == 'pdf') |
|
{ |
|
if (data.bg == 'none') |
|
{ |
|
bg = null; |
|
} |
|
else |
|
{ |
|
bg = xmlDoc.documentElement.getAttribute('background'); |
|
|
|
if (bg == 'none' || !bg) |
|
{ |
|
bg = '#ffffff'; |
|
} |
|
} |
|
} |
|
else |
|
{ |
|
|
|
bg = (data.bg != null && data.bg.length > 0) ? |
|
data.bg : xmlDoc.documentElement.getAttribute('background'); |
|
|
|
|
|
if (bg == 'none' || bg == '') |
|
{ |
|
bg = null; |
|
} |
|
|
|
|
|
if (bg == null && data.format != 'gif' && data.format != 'png' && data.format != 'svg') |
|
{ |
|
bg = '#ffffff'; |
|
} |
|
} |
|
|
|
|
|
if (bg != null) |
|
{ |
|
document.body.style.backgroundColor = bg; |
|
} |
|
|
|
|
|
if (extras != null && ((extras.layers != null && extras.layers.length > 0) || |
|
(extras.layerIds != null && extras.layerIds.length > 0))) |
|
{ |
|
var childCount = model.getChildCount(model.root); |
|
|
|
|
|
for (var i = 0; i < childCount; i++) |
|
{ |
|
model.setVisible(model.getChildAt(model.root, i), false); |
|
} |
|
|
|
if (extras.layerIds != null) |
|
{ |
|
for (var i = 0; i < extras.layerIds.length; i++) |
|
{ |
|
model.setVisible(model.getCell(extras.layerIds[i]), true); |
|
} |
|
} |
|
else |
|
{ |
|
for (var i = 0; i < extras.layers.length; i++) |
|
{ |
|
var layer = model.getChildAt(model.root, extras.layers[i]); |
|
|
|
if (layer != null) |
|
{ |
|
model.setVisible(layer, true); |
|
} |
|
} |
|
} |
|
} |
|
|
|
|
|
graph.pdfPageVisible = false; |
|
|
|
|
|
if (data.print || (data.format == 'pdf' && xmlDoc.documentElement.getAttribute('page') == '1' && data.w == 0 && data.h == 0 && data.scale == 1)) |
|
{ |
|
|
|
var printScale = 1; |
|
|
|
if (data.print) |
|
{ |
|
document.title = data.fileTitle; |
|
|
|
var gb = graph.getGraphBounds(); |
|
printScale = data.pageScale; |
|
|
|
if (isNaN(printScale)) |
|
{ |
|
printScale = 1; |
|
} |
|
|
|
if (data.fit) |
|
{ |
|
var h = parseInt(data.sheetsAcross); |
|
var v = parseInt(data.sheetsDown); |
|
|
|
data.scale = Math.min((data.pageHeight * v) / (gb.height / graph.view.scale), |
|
(data.pageWidth * h) / (gb.width / graph.view.scale)); |
|
} |
|
else |
|
{ |
|
data.scale = data.scale / graph.pageScale; |
|
|
|
if (isNaN(data.scale)) |
|
{ |
|
printScale = 1 / graph.pageScale; |
|
} |
|
} |
|
} |
|
|
|
var pw = data.pageWidth || xmlDoc.documentElement.getAttribute('pageWidth'); |
|
var ph = data.pageHeight || xmlDoc.documentElement.getAttribute('pageHeight'); |
|
graph.pdfPageVisible = true; |
|
|
|
if (pw != null && ph != null) |
|
{ |
|
graph.pageFormat = new mxRectangle(0, 0, parseFloat(pw), parseFloat(ph)); |
|
} |
|
|
|
var ps = data.pageScale || xmlDoc.documentElement.getAttribute('pageScale'); |
|
|
|
if (ps != null) |
|
{ |
|
graph.pageScale = ps; |
|
} |
|
|
|
graph.getPageSize = function() |
|
{ |
|
return new mxRectangle(0, 0, this.pageFormat.width * this.pageScale, |
|
this.pageFormat.height * this.pageScale); |
|
}; |
|
|
|
graph.getPageLayout = function() |
|
{ |
|
var size = this.getPageSize(); |
|
var bounds = this.getGraphBounds(); |
|
|
|
if (bounds.width == 0 || bounds.height == 0) |
|
{ |
|
return new mxRectangle(0, 0, 1, 1); |
|
} |
|
else |
|
{ |
|
|
|
var x = Math.ceil(bounds.x / this.view.scale - this.view.translate.x); |
|
var y = Math.ceil(bounds.y / this.view.scale - this.view.translate.y); |
|
var w = Math.floor(bounds.width / this.view.scale); |
|
var h = Math.floor(bounds.height / this.view.scale); |
|
|
|
var x0 = Math.floor(x / size.width); |
|
var y0 = Math.floor(y / size.height); |
|
var w0 = Math.ceil((x + w) / size.width) - x0; |
|
var h0 = Math.ceil((y + h) / size.height) - y0; |
|
|
|
return new mxRectangle(x0, y0, w0, h0); |
|
} |
|
}; |
|
|
|
|
|
graph.view.getBackgroundPageBounds = function() |
|
{ |
|
var layout = this.graph.getPageLayout(); |
|
var page = this.graph.getPageSize(); |
|
|
|
return new mxRectangle(this.scale * (this.translate.x + layout.x * page.width), |
|
this.scale * (this.translate.y + layout.y * page.height), |
|
this.scale * layout.width * page.width, |
|
this.scale * layout.height * page.height); |
|
}; |
|
} |
|
|
|
if (!graph.pdfPageVisible) |
|
{ |
|
var b = graph.getGraphBounds(); |
|
|
|
|
|
if (data.w > 0 || data.h > 0) |
|
{ |
|
var s = 1; |
|
|
|
if (data.w > 0 && data.h > 0) |
|
{ |
|
s = Math.min(data.w / b.width, data.h / b.height); |
|
} |
|
else if (data.w > 0) |
|
{ |
|
s = data.w / b.width; |
|
} |
|
else |
|
{ |
|
s = data.h / b.height; |
|
} |
|
|
|
graph.view.scaleAndTranslate(s, |
|
Math.floor(data.border / s - Math.floor(b.x)), |
|
Math.floor(data.border / s - Math.floor(b.y))); |
|
} |
|
else |
|
{ |
|
var s = data.scale; |
|
|
|
if (autoScale) |
|
{ |
|
var pageWidth = (extras != null && extras.pageWidth != null) ? extras.pageWidth : 800; |
|
|
|
if (b.width < pageWidth & b.height < 1.5 * pageWidth) |
|
{ |
|
s = 4; |
|
} |
|
else if (b.width < 2 * pageWidth & b.height < 3 * pageWidth) |
|
{ |
|
s = 3; |
|
} |
|
else if (b.width < 4 * pageWidth && b.height < 6 * pageWidth) |
|
{ |
|
s = 2; |
|
} |
|
|
|
if (extras != null && extras.isGoogleSheet != null) |
|
{ |
|
GOOGLE_APPS_MAX_AREA = GOOGLE_SHEET_MAX_AREA; |
|
} |
|
|
|
|
|
if (b.width * s * b.height * s > GOOGLE_APPS_MAX_AREA) |
|
{ |
|
|
|
s = Math.sqrt(GOOGLE_APPS_MAX_AREA / (b.width * b.height)) - 0.01; |
|
} |
|
} |
|
|
|
graph.view.scaleAndTranslate(s, |
|
Math.floor(data.border - Math.floor(b.x)), |
|
Math.floor(data.border - Math.floor(b.y))); |
|
} |
|
} |
|
else |
|
{ |
|
|
|
data.border = 0; |
|
|
|
|
|
var layout = graph.getPageLayout(); |
|
var page = graph.getPageSize(); |
|
var dx = layout.x * page.width; |
|
var dy = layout.y * page.height; |
|
|
|
if (dx != 0 || dy != 0) |
|
{ |
|
graph.view.setTranslate(Math.floor(-dx), Math.floor(-dy)); |
|
} |
|
} |
|
|
|
|
|
bounds = (graph.pdfPageVisible) ? graph.view.getBackgroundPageBounds() : graph.getGraphBounds(); |
|
bounds.width = Math.ceil(bounds.width + data.border) + 1; |
|
bounds.height = Math.ceil(bounds.height + data.border) + 1; |
|
|
|
|
|
if (bounds.width <= 1 && bounds.height <= 1) |
|
{ |
|
bounds.width = 2; |
|
bounds.height = 2; |
|
} |
|
|
|
expScale = graph.view.scale || 1; |
|
|
|
|
|
if (graph.pdfPageVisible) |
|
{ |
|
var pf = graph.pageFormat || mxConstants.PAGE_FORMAT_A4_PORTRAIT; |
|
var scale = data.print? data.scale : 1 / graph.pageScale; |
|
var autoOrigin = (data.print && data.fit != null) ? data.fit : false; |
|
var border = 0; |
|
|
|
|
|
var gb = graph.getGraphBounds(); |
|
var x0 = 0; |
|
var y0 = 0; |
|
|
|
|
|
pf = mxRectangle.fromRectangle(pf); |
|
pf.width = Math.ceil(pf.width * printScale) + 1; |
|
pf.height = Math.ceil(pf.height * printScale) + 1; |
|
scale *= printScale; |
|
|
|
|
|
if (!autoOrigin) |
|
{ |
|
var layout = graph.getPageLayout(); |
|
x0 -= layout.x * pf.width; |
|
y0 -= layout.y * pf.height; |
|
} |
|
|
|
if (preview == null) |
|
{ |
|
preview = new mxPrintPreview(graph, scale, pf, border, x0, y0); |
|
preview.printBackgroundImage = true; |
|
preview.autoOrigin = autoOrigin; |
|
preview.backgroundColor = bg; |
|
|
|
preview.open(null, window); |
|
graph.container.parentNode.removeChild(graph.container); |
|
} |
|
else |
|
{ |
|
preview.backgroundColor = bg; |
|
preview.autoOrigin = autoOrigin; |
|
preview.appendGraph(graph, scale, x0, y0); |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bounds = new mxRectangle(0, 0, pf.width, pf.height); |
|
} |
|
else |
|
{ |
|
var bgImg = graph.backgroundImage; |
|
|
|
if (bgImg != null) |
|
{ |
|
var t = graph.view.translate; |
|
var s = graph.view.scale; |
|
|
|
bounds.add(new mxRectangle( |
|
(t.x + bgImg.x) * s, (t.y + bgImg.y) * s, |
|
bgImg.width * s, bgImg.height * s)); |
|
|
|
if (t.x < 0 || t.y < 0) |
|
{ |
|
graph.view.setTranslate(t.x < 0? -bgImg.x * s : t.x, t.y < 0? -bgImg.y * s : t.y); |
|
bounds.x = 0.5; |
|
bounds.y = 0.5; |
|
} |
|
} |
|
|
|
|
|
|
|
if (data.format != 'pdf' && mxClient.IS_SVG && xmlDoc.documentElement.getAttribute('shadow') == '1') |
|
{ |
|
graph.addSvgShadow(graph.view.canvas.ownerSVGElement, null, true); |
|
graph.setShadowVisible(true); |
|
bounds.width += 7; |
|
bounds.height += 7; |
|
} |
|
|
|
document.body.style.width = Math.ceil(bounds.x + bounds.width) + 'px'; |
|
document.body.style.height = Math.ceil(bounds.y + bounds.height) + 'px'; |
|
} |
|
}; |
|
|
|
if (diagrams != null && diagrams.length > 0) |
|
{ |
|
var to = diagrams.length - 1; |
|
|
|
|
|
if (!data.allPages) |
|
{ |
|
if (data.pageId != null) |
|
{ |
|
for (var i = 0; i < diagrams.length; i++) |
|
{ |
|
if (data.pageId == diagrams[i].getAttribute('id')) |
|
{ |
|
from = i; |
|
to = i; |
|
break; |
|
} |
|
} |
|
} |
|
else |
|
{ |
|
from = Math.max(0, Math.min(parseInt(data.from) || from, diagrams.length - 1)); |
|
to = parseInt(data.to); |
|
|
|
to = isNaN(to)? from : Math.max(from, Math.min(to, diagrams.length - 1)); |
|
} |
|
} |
|
|
|
|
|
|
|
|
|
var graphGetGlobalVariable = graph.getGlobalVariable; |
|
|
|
graph.getGlobalVariable = function(name) |
|
{ |
|
if (name == 'page') |
|
{ |
|
return (diagrams == null) ? 'Page-1' : |
|
(diagrams[from].getAttribute('name') || ('Page-' + (from + 1))); |
|
} |
|
else if (name == 'pagenumber') |
|
{ |
|
return from + 1; |
|
} |
|
|
|
return graphGetGlobalVariable.apply(this, arguments); |
|
}; |
|
|
|
for (var i = from; i <= to; i++) |
|
{ |
|
if (diagrams[i] != null) |
|
{ |
|
if (pageId == null) |
|
{ |
|
pageId = diagrams[i].getAttribute('id') |
|
} |
|
|
|
xmlDoc = Editor.parseDiagramNode(diagrams[i]); |
|
|
|
if (xmlDoc != null) |
|
{ |
|
xmlDoc = xmlDoc.ownerDocument; |
|
} |
|
|
|
graph.getModel().clear(); |
|
from = i; |
|
renderPage(); |
|
} |
|
} |
|
} |
|
else |
|
{ |
|
renderPage(); |
|
} |
|
|
|
if (fallbackFont) |
|
{ |
|
|
|
|
|
|
|
document.querySelectorAll('foreignObject div').forEach(d => d.style.fontFamily = (d.style.fontFamily || '') + ', ' + fallbackFont); |
|
} |
|
|
|
renderGrid(); |
|
|
|
waitForImages('image', 'xlink:href'); |
|
waitForImages('img', 'src'); |
|
renderMath(document.body); |
|
|
|
decrementWaitCounter(); |
|
|
|
return graph; |
|
}; |
|
|
|
|
|
if (mxIsElectron) |
|
{ |
|
try |
|
{ |
|
electron.registerMsgListener('render', (arg) => |
|
{ |
|
try |
|
{ |
|
render(arg); |
|
} |
|
catch(e) |
|
{ |
|
console.log(e); |
|
electron.sendMessage('render-finished', null); |
|
} |
|
}); |
|
} |
|
catch(e) |
|
{ |
|
console.log(e); |
|
} |
|
} |
|
|