maxGraph/javascript/examples/grapheditor/www/js/Sidebar.js

2200 lines
82 KiB
JavaScript
Raw Normal View History

2012-05-21 20:32:26 +00:00
/**
* Copyright (c) 2006-2012, JGraph Ltd
*/
/**
* Construcs a new sidebar for the given editor.
*/
function Sidebar(editorUi, container)
{
this.editorUi = editorUi;
this.container = container;
this.palettes = new Object();
this.showTooltips = true;
this.graph = new Graph(document.createElement('div'), null, null, this.editorUi.editor.graph.getStylesheet());
2013-05-23 16:14:48 +00:00
this.graph.resetViewOnRootChange = false;
2012-05-21 20:32:26 +00:00
this.graph.foldingEnabled = false;
2013-05-23 16:14:48 +00:00
this.graph.setConnectable(false);
2012-05-21 20:32:26 +00:00
this.graph.autoScroll = false;
this.graph.setTooltips(false);
this.graph.setEnabled(false);
2012-07-16 15:36:48 +00:00
2013-05-23 16:14:48 +00:00
// Container must be in the DOM for correct HTML rendering
this.graph.container.style.visibility = 'hidden';
this.graph.container.style.position = 'absolute';
document.body.appendChild(this.graph.container);
2013-06-28 19:07:06 +00:00
mxEvent.addListener(document, (mxClient.IS_POINTER) ? 'MSPointerUp' : 'mouseup', mxUtils.bind(this, function()
2012-05-21 20:32:26 +00:00
{
2013-06-28 19:07:06 +00:00
this.showTooltips = true;
}));
mxEvent.addListener(document, (mxClient.IS_POINTER) ? 'MSPointerDown' : 'mousedown', mxUtils.bind(this, function()
{
this.showTooltips = false;
this.hideTooltip();
}));
2012-05-21 20:32:26 +00:00
2013-06-28 19:07:06 +00:00
mxEvent.addListener(document, (mxClient.IS_POINTER) ? 'MSPointerMove' : 'mousemove', mxUtils.bind(this, function(evt)
{
var src = mxEvent.getSource(evt);
while (src != null)
2012-05-21 20:32:26 +00:00
{
2013-06-28 19:07:06 +00:00
if (src == this.currentElt)
2012-05-21 20:32:26 +00:00
{
2013-06-28 19:07:06 +00:00
return;
2012-05-21 20:32:26 +00:00
}
2013-06-28 19:07:06 +00:00
src = src.parentNode;
}
this.hideTooltip();
}));
2012-05-21 20:32:26 +00:00
2013-06-28 19:07:06 +00:00
// Handles mouse leaving the window
mxEvent.addListener(document, (mxClient.IS_POINTER) ? 'MSPointerOut' : 'mouseout', mxUtils.bind(this, function(evt)
{
if (evt.toElement == null && evt.relatedTarget == null)
2012-05-21 20:32:26 +00:00
{
2013-06-28 19:07:06 +00:00
this.hideTooltip();
}
}));
// Enables tooltips after scroll
mxEvent.addListener(container, 'scroll', mxUtils.bind(this, function()
{
this.showTooltips = true;
}));
2012-05-21 20:32:26 +00:00
this.init();
// Pre-fetches tooltip image
new Image().src = IMAGE_PATH + '/tooltip.png';
};
/**
* Adds all palettes to the sidebar.
*/
Sidebar.prototype.init = function()
{
var dir = STENCIL_PATH;
this.addGeneralPalette(true);
2014-04-13 06:49:20 +00:00
this.addConnectionPalette(false);
this.addAdvancedPalette(true);
2012-05-21 20:32:26 +00:00
this.addStencilPalette('basic', mxResources.get('basic'), dir + '/basic.xml',
2014-11-10 09:02:21 +00:00
';whiteSpace=wrap;html=1;fillColor=#ffffff;strokeColor=#000000;strokeWidth=2');
2012-05-21 20:32:26 +00:00
this.addStencilPalette('arrows', mxResources.get('arrows'), dir + '/arrows.xml',
2014-11-10 09:02:21 +00:00
';whiteSpace=wrap;html=1;fillColor=#ffffff;strokeColor=#000000;strokeWidth=2');
2012-12-18 13:09:38 +00:00
this.addUmlPalette(false);
this.addBpmnPalette(dir, false);
this.addStencilPalette('flowchart', 'Flowchart', dir + '/flowchart.xml',
2014-11-10 09:02:21 +00:00
';whiteSpace=wrap;html=1;fillColor=#ffffff;strokeColor=#000000;strokeWidth=2');
2012-05-21 20:32:26 +00:00
this.addImagePalette('clipart', mxResources.get('clipart'), dir + '/clipart/', '_128x128.png',
['Earth_globe', 'Empty_Folder', 'Full_Folder', 'Gear', 'Lock', 'Software', 'Virus', 'Email',
'Database', 'Router_Icon', 'iPad', 'iMac', 'Laptop', 'MacBook', 'Monitor_Tower', 'Printer',
'Server_Tower', 'Workstation', 'Firewall_02', 'Wireless_Router_N', 'Credit_Card',
'Piggy_Bank', 'Graph', 'Safe', 'Shopping_Cart', 'Suit1', 'Suit2', 'Suit3', 'Pilot1',
'Worker1', 'Soldier1', 'Doctor1', 'Tech1', 'Security1', 'Telesales1']);
};
/**
* Specifies if tooltips should be visible. Default is true.
*/
2013-06-28 19:07:06 +00:00
Sidebar.prototype.enableTooltips = true;
2012-05-21 20:32:26 +00:00
/**
* Specifies the delay for the tooltip. Default is 16 px.
*/
Sidebar.prototype.tooltipBorder = 16;
/**
* Specifies the delay for the tooltip. Default is 300 ms.
*/
Sidebar.prototype.tooltipDelay = 300;
/**
* Specifies the URL of the gear image.
*/
2012-06-14 12:43:20 +00:00
Sidebar.prototype.gearImage = STENCIL_PATH + '/clipart/Gear_128x128.png';
2012-05-21 20:32:26 +00:00
/**
* Specifies the width of the thumbnails.
*/
2014-04-13 06:49:20 +00:00
Sidebar.prototype.thumbWidth = 36;
2012-05-21 20:32:26 +00:00
/**
* Specifies the height of the thumbnails.
*/
2014-04-13 06:49:20 +00:00
Sidebar.prototype.thumbHeight = 36;
2013-05-23 16:14:48 +00:00
/**
* Specifies the padding for the thumbnails. Default is 3.
*/
2014-04-13 06:49:20 +00:00
Sidebar.prototype.thumbPadding = (document.documentMode >= 5) ? 0 : 1;
/**
* Specifies the delay for the tooltip. Default is 3 px.
*/
Sidebar.prototype.thumbBorder = 2;
2013-05-23 16:14:48 +00:00
/**
* Specifies the size of the sidebar titles.
*/
Sidebar.prototype.sidebarTitleSize = 9;
/**
* Specifies if titles in the sidebar should be enabled.
*/
2014-05-05 08:30:00 +00:00
Sidebar.prototype.sidebarTitles = false;
2013-05-23 16:14:48 +00:00
/**
* Specifies if titles in the tooltips should be enabled.
*/
Sidebar.prototype.tooltipTitles = true;
2012-05-21 20:32:26 +00:00
2014-01-31 14:27:56 +00:00
/**
* Specifies if titles in the tooltips should be enabled.
*/
Sidebar.prototype.maxTooltipWidth = 400;
/**
* Specifies if titles in the tooltips should be enabled.
*/
Sidebar.prototype.maxTooltipHeight = 400;
2012-05-21 20:32:26 +00:00
/**
* Adds all palettes to the sidebar.
*/
2014-05-05 08:30:00 +00:00
Sidebar.prototype.showTooltip = function(elt, cells, w, h, title, showLabel, dx, dy)
2012-05-21 20:32:26 +00:00
{
if (this.enableTooltips && this.showTooltips)
{
if (this.currentElt != elt)
{
if (this.thread != null)
{
window.clearTimeout(this.thread);
this.thread = null;
}
var show = mxUtils.bind(this, function()
{
// Lazy creation of the DOM nodes and graph instance
if (this.tooltip == null)
{
this.tooltip = document.createElement('div');
2012-06-14 12:43:20 +00:00
this.tooltip.className = 'geSidebarTooltip';
2012-07-16 15:36:48 +00:00
document.body.appendChild(this.tooltip);
2012-05-21 20:32:26 +00:00
this.graph2 = new Graph(this.tooltip, null, null, this.editorUi.editor.graph.getStylesheet());
this.graph2.resetViewOnRootChange = false;
this.graph2.foldingEnabled = false;
this.graph2.autoScroll = false;
this.graph2.setTooltips(false);
this.graph2.setConnectable(false);
this.graph2.setEnabled(false);
2013-05-23 16:14:48 +00:00
if (!mxClient.IS_SVG)
{
this.graph2.view.canvas.style.position = 'relative';
}
2012-05-21 20:32:26 +00:00
this.tooltipImage = mxUtils.createImage(IMAGE_PATH + '/tooltip.png');
2014-07-25 06:48:01 +00:00
this.tooltipImage.className = 'geSidebarTooltipImage';
2012-05-21 20:32:26 +00:00
this.tooltipImage.style.position = 'absolute';
this.tooltipImage.style.width = '14px';
this.tooltipImage.style.height = '27px';
2012-07-16 15:36:48 +00:00
2012-12-18 13:09:38 +00:00
document.body.appendChild(this.tooltipImage);
2012-05-21 20:32:26 +00:00
}
2014-01-31 14:27:56 +00:00
this.graph2.model.clear();
2014-05-05 08:30:00 +00:00
this.graph2.view.setTranslate(this.tooltipBorder + dx, this.tooltipBorder + dy);
2014-01-31 14:27:56 +00:00
if (w > this.maxTooltipWidth || h > this.maxTooltipHeight)
{
this.graph2.view.scale = Math.round(Math.min(this.maxTooltipWidth / w, this.maxTooltipHeight / h) * 100) / 100;
}
else
{
this.graph2.view.scale = 1;
}
2012-12-18 13:09:38 +00:00
this.tooltip.style.display = 'block';
2013-05-23 16:14:48 +00:00
this.graph2.labelsVisible = (showLabel == null || showLabel);
2012-05-21 20:32:26 +00:00
this.graph2.addCells(cells);
var bounds = this.graph2.getGraphBounds();
2013-05-23 16:14:48 +00:00
var width = bounds.width + 2 * this.tooltipBorder;
var height = bounds.height + 2 * this.tooltipBorder;
2012-05-21 20:32:26 +00:00
2012-07-20 10:35:30 +00:00
if (mxClient.IS_QUIRKS)
2012-05-21 20:32:26 +00:00
{
width += 4;
height += 4;
2013-05-23 16:14:48 +00:00
this.tooltip.style.overflow = 'hidden';
2012-05-21 20:32:26 +00:00
}
2013-05-23 16:14:48 +00:00
else
{
this.tooltip.style.overflow = 'visible';
}
2012-05-21 20:32:26 +00:00
this.tooltipImage.style.visibility = 'visible';
this.tooltip.style.width = width + 'px';
2013-05-23 16:14:48 +00:00
// Adds title for entry
if (this.tooltipTitles && title != null && title.length > 0)
{
if (this.tooltipTitle == null)
{
this.tooltipTitle = document.createElement('div');
this.tooltipTitle.style.borderTop = '1px solid gray';
this.tooltipTitle.style.textAlign = 'center';
this.tooltipTitle.style.width = '100%';
// Oversize titles are cut-off currently. Should make tooltip wider later.
this.tooltipTitle.style.overflow = 'hidden';
if (mxClient.IS_SVG)
{
this.tooltipTitle.style.paddingTop = '2px';
}
else
{
this.tooltipTitle.style.position = 'absolute';
this.tooltipTitle.style.paddingTop = '6px';
}
this.tooltip.appendChild(this.tooltipTitle);
}
else
{
this.tooltipTitle.innerHTML = '';
}
this.tooltipTitle.style.display = '';
mxUtils.write(this.tooltipTitle, title);
2014-05-05 08:30:00 +00:00
var ddy = this.tooltipTitle.offsetHeight + 10;
height += ddy;
2013-05-23 16:14:48 +00:00
if (mxClient.IS_SVG)
{
2014-05-05 08:30:00 +00:00
this.tooltipTitle.style.marginTop = (-ddy) + 'px';
2013-05-23 16:14:48 +00:00
}
else
{
height -= 6;
2014-05-05 08:30:00 +00:00
this.tooltipTitle.style.top = (height - ddy) + 'px';
2013-05-23 16:14:48 +00:00
}
}
else if (this.tooltipTitle != null && this.tooltipTitle.parentNode != null)
{
this.tooltipTitle.style.display = 'none';
}
2012-05-21 20:32:26 +00:00
this.tooltip.style.height = height + 'px';
2013-05-23 16:14:48 +00:00
var x0 = -Math.min(0, bounds.x - this.tooltipBorder);
var y0 = -Math.min(0, bounds.y - this.tooltipBorder);
2012-05-21 20:32:26 +00:00
var left = this.container.clientWidth + this.editorUi.splitSize + 3;
var top = Math.max(0, (this.container.offsetTop + elt.offsetTop - this.container.scrollTop - height / 2 + 16));
2013-05-23 16:14:48 +00:00
if (mxClient.IS_SVG)
{
this.graph2.view.canvas.setAttribute('transform', 'translate(' + x0 + ',' + y0 + ')');
}
else
{
this.graph2.view.drawPane.style.left = x0 + 'px';
this.graph2.view.drawPane.style.top = y0 + 'px';
}
2012-05-21 20:32:26 +00:00
// Workaround for ignored position CSS style in IE9
// (changes to relative without the following line)
this.tooltip.style.position = 'absolute';
this.tooltip.style.left = left + 'px';
this.tooltip.style.top = top + 'px';
this.tooltipImage.style.left = (left - 13) + 'px';
this.tooltipImage.style.top = (top + height / 2 - 13) + 'px';
});
if (this.tooltip != null && this.tooltip.style.display != 'none')
{
show();
}
else
{
this.thread = window.setTimeout(show, this.tooltipDelay);
}
this.currentElt = elt;
}
}
};
/**
* Hides the current tooltip.
*/
Sidebar.prototype.hideTooltip = function()
{
if (this.thread != null)
{
window.clearTimeout(this.thread);
this.thread = null;
}
if (this.tooltip != null)
{
this.tooltip.style.display = 'none';
this.tooltipImage.style.visibility = 'hidden';
this.currentElt = null;
}
};
/**
* Adds the general palette to the sidebar.
*/
Sidebar.prototype.addGeneralPalette = function(expand)
{
2014-11-10 09:02:21 +00:00
// Rearranged based on usage data from
// https://s3-eu-west-1.amazonaws.com/uploads-eu.hipchat.com/38308/267398/LpNxVqkMjKH61jP/shapefreq12hours.txt
2013-06-28 19:07:06 +00:00
this.addPalette('general', mxResources.get('general'), (expand != null) ? expand : true, mxUtils.bind(this, function(content)
2012-05-21 20:32:26 +00:00
{
2014-11-10 09:02:21 +00:00
content.appendChild(this.createVertexTemplate('whiteSpace=wrap;html=1;', 120, 60, '', 'Rectangle', true));
content.appendChild(this.createVertexTemplate('rounded=1;whiteSpace=wrap;html=1;', 120, 60, '', 'Rounded Rectangle', true));
content.appendChild(this.createVertexTemplate('ellipse;whiteSpace=wrap;html=1;', 80, 80, '', 'Circle', true));
// Explicit strokecolor/fillcolor=none is a workaround to maintain transparent background regardless of current style
content.appendChild(this.createVertexTemplate('text;html=1;strokeColor=none;fillColor=none;align=center;verticalAlign=middle;whiteSpace=wrap;overflow=hidden;',
60, 30, 'Text', 'Text', true));
2014-04-13 06:49:20 +00:00
2014-11-10 09:02:21 +00:00
content.appendChild(this.createVertexTemplate('shape=ext;double=1;whiteSpace=wrap;html=1;', 120, 60, '', 'Double Rectangle', true));
content.appendChild(this.createVertexTemplate('shape=ext;double=1;rounded=1;whiteSpace=wrap;html=1;', 120, 60, '', 'Double Rounded Rectangle', true));
content.appendChild(this.createVertexTemplate('ellipse;shape=doubleEllipse;whiteSpace=wrap;html=1;', 80, 80, '', 'Double Ellipse', true));
content.appendChild(this.createVertexTemplate('rhombus;whiteSpace=wrap;html=1;', 80, 80, '', 'Rhombus', true));
content.appendChild(this.createVertexTemplate('shape=umlActor;verticalLabelPosition=bottom;verticalAlign=top;html=1;', 30, 60, '', 'Actor', true));
content.appendChild(this.createVertexTemplate('shape=curlyBracket;whiteSpace=wrap;html=1;rounded=1;', 20, 120, '', 'Curly Bracket', true));
content.appendChild(this.createVertexTemplate('line;html=1;', 160, 10, '', 'Horizontal Line', true));
content.appendChild(this.createVertexTemplate('line;direction=south;html=1;', 10, 160, '', 'Vertical Line', true));
content.appendChild(this.createVertexTemplate('shape=parallelogram;whiteSpace=wrap;html=1;', 120, 60, '', 'Parallelogram', true));
content.appendChild(this.createVertexTemplate('triangle;whiteSpace=wrap;html=1;', 60, 80, '', 'Triangle', true));
content.appendChild(this.createVertexTemplate('shape=cylinder;whiteSpace=wrap;html=1;', 60, 80, '', 'Cylinder', true));
content.appendChild(this.createVertexTemplate('shape=hexagon;perimeter=hexagonPerimeter;whiteSpace=wrap;html=1;', 120, 80, '', 'Hexagon', true));
content.appendChild(this.createVertexTemplate('shape=process;whiteSpace=wrap;html=1;', 120, 60, '', 'Process', true));
content.appendChild(this.createVertexTemplate('ellipse;shape=cloud;whiteSpace=wrap;html=1;', 120, 80, '', 'Cloud', true));
content.appendChild(this.createVertexTemplate('shape=document;whiteSpace=wrap;html=1;', 120, 80, '', 'Document', true));
content.appendChild(this.createVertexTemplate('shape=internalStorage;whiteSpace=wrap;html=1;', 80, 80, '', 'Internal Storage', true));
content.appendChild(this.createVertexTemplate('shape=cube;whiteSpace=wrap;html=1;', 120, 80, '', 'Cube', true));
content.appendChild(this.createVertexTemplate('shape=step;whiteSpace=wrap;html=1;', 120, 80, '', 'Step', true));
content.appendChild(this.createVertexTemplate('shape=trapezoid;whiteSpace=wrap;html=1;', 120, 60, '', 'Trapezoid', true));
content.appendChild(this.createVertexTemplate('shape=tape;whiteSpace=wrap;html=1;', 120, 100, '', 'Tape', true));
content.appendChild(this.createVertexTemplate('shape=note;whiteSpace=wrap;html=1;', 80, 100, '', 'Note', true));
content.appendChild(this.createVertexTemplate('shape=folder;whiteSpace=wrap;html=1;', 120, 120, '', 'Folder', true));
content.appendChild(this.createVertexTemplate('shape=message;whiteSpace=wrap;html=1;', 60, 40, '', 'Message', true));
content.appendChild(this.createVertexTemplate('shape=card;whiteSpace=wrap;html=1;', 80, 100, '', 'Card', true));
content.appendChild(this.createVertexTemplate('shape=singleArrow;direction=west;whiteSpace=wrap;html=1;', 100, 60, '', 'Arrow Left', true));
content.appendChild(this.createVertexTemplate('shape=singleArrow;whiteSpace=wrap;html=1;', 100, 60, '', 'Arrow Right', true));
content.appendChild(this.createVertexTemplate('shape=singleArrow;direction=north;whiteSpace=wrap;html=1;', 60, 100, '', 'Arrow Up', true));
content.appendChild(this.createVertexTemplate('shape=singleArrow;direction=south;whiteSpace=wrap;html=1;', 60, 100, '', 'Arrow Down', true));
2012-05-21 20:32:26 +00:00
}));
};
2014-04-13 06:49:20 +00:00
/**
* Adds the container palette to the sidebar.
*/
Sidebar.prototype.addConnectionPalette = function(dir, expand)
{
this.addPalette('connections', mxResources.get('connection'), (expand != null) ? expand : false, mxUtils.bind(this, function(content)
{
this.addConnectionShapes(dir, content);
}));
};
/**
* Adds the container palette to the sidebar.
*/
Sidebar.prototype.addConnectionShapes = function(dir, content)
{
2014-11-10 09:02:21 +00:00
content.appendChild(this.createEdgeTemplate('endArrow=none;html=1;', 100, 100, '', 'Line', true));
content.appendChild(this.createEdgeTemplate('endArrow=none;dashed=1;html=1;', 100, 100, '', 'Dashed Line', true));
content.appendChild(this.createEdgeTemplate('endArrow=none;html=1;dashed=1;dashPattern=1 4', 100, 100, '', 'Dotted Line', true));
content.appendChild(this.createEdgeTemplate('endArrow=classic;html=1;', 100, 100, '', 'Connection', true));
2014-04-13 06:49:20 +00:00
2014-11-10 09:02:21 +00:00
var cells = [new mxCell('', new mxGeometry(0, 0, 100, 100), 'curved=1;endArrow=classic;html=1;')];
2014-04-13 06:49:20 +00:00
cells[0].geometry.setTerminalPoint(new mxPoint(0, 100), true);
cells[0].geometry.setTerminalPoint(new mxPoint(100, 0), false);
cells[0].geometry.points = [new mxPoint(100, 100), new mxPoint(0, 0)];
cells[0].geometry.relative = true;
cells[0].edge = true;
content.appendChild(this.createEdgeTemplateFromCells(cells, 100, 100, 'Curve', true));
2014-11-10 09:02:21 +00:00
content.appendChild(this.createEdgeTemplate('edgeStyle=elbowEdgeStyle;elbow=horizontal;endArrow=classic;html=1;', 100, 100, '', 'Horizontal Elbow', true));
content.appendChild(this.createEdgeTemplate('edgeStyle=elbowEdgeStyle;elbow=vertical;endArrow=classic;html=1;', 100, 100, '', 'Vertical Elbow', true));
content.appendChild(this.createEdgeTemplate('edgeStyle=entityRelationEdgeStyle;endArrow=classic;html=1;', 100, 100, '', 'Entity Relation', true));
content.appendChild(this.createEdgeTemplate('edgeStyle=segmentEdgeStyle;endArrow=classic;html=1;', 100, 100, '', 'Manual Line', true));
2014-07-25 06:48:01 +00:00
2014-11-10 09:02:21 +00:00
var cells = [new mxCell('', new mxGeometry(0, 0, 100, 100), 'edgeStyle=orthogonalEdgeStyle;endArrow=classic;html=1;')];
2014-07-25 06:48:01 +00:00
cells[0].geometry.setTerminalPoint(new mxPoint(0, 100), true);
cells[0].geometry.setTerminalPoint(new mxPoint(100, 0), false);
cells[0].geometry.points = [new mxPoint(30, 100), new mxPoint(30, 50), new mxPoint(70, 50), new mxPoint(70, 0)];
cells[0].geometry.relative = true;
cells[0].edge = true;
content.appendChild(this.createEdgeTemplateFromCells(cells, 100, 100, 'Automatic Line', true));
2014-11-10 09:02:21 +00:00
content.appendChild(this.createEdgeTemplate('shape=link;html=1;', 100, 100, '', 'Link', true));
content.appendChild(this.createEdgeTemplate('arrow;html=1;', 100, 100, '', 'Arrow', true));
2014-04-13 06:49:20 +00:00
};
/**
* Adds the container palette to the sidebar.
*/
Sidebar.prototype.addAdvancedPalette = function(dir, expand)
{
this.addPalette('advanced', mxResources.get('advanced'), (expand != null) ? expand : false, mxUtils.bind(this, function(content)
{
this.addAdvancedShapes(dir, content);
}));
};
/**
* Adds the container palette to the sidebar.
*/
Sidebar.prototype.addAdvancedShapes = function(dir, content)
{
2014-11-10 09:02:21 +00:00
content.appendChild(this.createVertexTemplate('text;html=1;spacing=5;spacingTop=-20;whiteSpace=wrap;overflow=hidden;', 190, 120,
'<h1>Heading</h1><p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</p>', 'Textbox', true));
content.appendChild(this.createVertexTemplate('text;html=1;whiteSpace=wrap;verticalAlign=middle;overflow=hidden;', 100, 80,
'<ul><li>Value 1</li><li>Value 2</li><li>Value 3</li></ul>', 'Unordered list', true));
content.appendChild(this.createVertexTemplate('text;html=1;whiteSpace=wrap;verticalAlign=middle;overflow=hidden;', 100, 80,
'<ol><li>Value 1</li><li>Value 2</li><li>Value 3</li></ol>', 'Ordered list', true));
content.appendChild(this.createVertexTemplate('text;html=1;strokeColor=#c0c0c0;overflow=fill;', 180, 180,
'<table border="0" width="100%" height="100%" style="width:100%;height:100%;border-collapse:collapse;">' +
'<tr><td align="center">Value 1</td><td align="center">Value 2</td><td align="center">Value 3</td></tr>' +
'<tr><td align="center">Value 4</td><td align="center">Value 5</td><td align="center">Value 6</td></tr>' +
'<tr><td align="center">Value 7</td><td align="center">Value 8</td><td align="center">Value 9</td></tr></table>', 'Table 1', true));
content.appendChild(this.createVertexTemplate('text;html=1;overflow=fill;', 180, 180,
'<table border="1" width="100%" height="100%" style="width:100%;height:100%;border-collapse:collapse;">' +
'<tr><td align="center">Value 1</td><td align="center">Value 2</td><td align="center">Value 3</td></tr>' +
'<tr><td align="center">Value 4</td><td align="center">Value 5</td><td align="center">Value 6</td></tr>' +
'<tr><td align="center">Value 7</td><td align="center">Value 8</td><td align="center">Value 9</td></tr></table>', 'Table 2', true));
content.appendChild(this.createVertexTemplate('text;html=1;overflow=fill;', 160, 180,
'<table border="1" width="100%" height="100%" cellpadding="4" style="width:100%;height:100%;border-collapse:collapse;">' +
'<tr><th align="center"><b>Title</b></th></tr>' +
'<tr><td align="center">Section 1.1\nSection 1.2\nSection 1.3</td></tr>' +
'<tr><td align="center">Section 2.1\nSection 2.2\nSection 2.3</td></tr></table>', 'Table 3', true));
2014-07-25 06:48:01 +00:00
2014-11-10 09:02:21 +00:00
// For fun: Bootstrap template, Problem: Text flow in jumbotron paragraph
/*content.appendChild(this.createVertexTemplate('text;html=1;overflow=fill;', 100, 100,
'<html><head><link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css"><link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap-theme.min.css">' +
'</head><body><div class="jumbotron"><div class="container"><h1>Bootstrap starter template</h1>' +
'<p>This is a template for a simple marketing or informational website. It includes a large callout called a jumbotron and three supporting pieces of content. Use it as a starting point to create something more unique.</p>' +
'<p><a class="btn btn-primary btn-lg" role="button">Learn more &raquo;</a></p></div></div>' +
'<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script><script src="//netdna.bootstrapcdn.com/bootstrap/3.1.1/js/bootstrap.min.js"></script></body></html>', 'IFrame', true));*/
2014-07-25 06:48:01 +00:00
2014-11-10 09:02:21 +00:00
var linkCell = new mxCell('Link', new mxGeometry(0, 0, 60, 40), 'text;html=1;align=center;verticalAlign=middle;fontColor=#0000EE;fontStyle=4;');
linkCell.vertex = true;
this.graph.setLinkForCell(linkCell, 'https://www.draw.io');
content.appendChild(this.createVertexTemplateFromCells([linkCell], 60, 40, 'Link', true));
content.appendChild(this.createVertexTemplate('shape=image;html=1;verticalLabelPosition=bottom;verticalAlign=top;imageAspect=1;aspect=fixed;image=' + this.gearImage, 52, 61, '', 'Fixed Image', false));
content.appendChild(this.createVertexTemplate('shape=image;html=1;verticalLabelPosition=bottom;verticalAlign=top;imageAspect=0;image=' + this.gearImage, 50, 60, '', 'Stretched Image', false));
content.appendChild(this.createVertexTemplate('icon;html=1;image=' + this.gearImage, 60, 60, 'Icon', 'Icon', false));
content.appendChild(this.createVertexTemplate('whiteSpace=wrap;html=1;label;image=' + this.gearImage, 140, 60, 'Label', 'Label', true));
content.appendChild(this.createVertexTemplate('shape=xor;whiteSpace=wrap;html=1;', 60, 80, '', 'Exclusive Or', true));
content.appendChild(this.createVertexTemplate('shape=or;whiteSpace=wrap;html=1;', 60, 80, '', 'Or', true));
content.appendChild(this.createVertexTemplate('shape=dataStorage;whiteSpace=wrap;html=1;', 100, 80, '', 'Data Storage', true));
content.appendChild(this.createVertexTemplate('shape=tapeData;whiteSpace=wrap;html=1;perimeter=ellipsePerimeter;', 80, 80, '', 'Tape Data', true));
content.appendChild(this.createVertexTemplate('shape=manualInput;whiteSpace=wrap;html=1;', 80, 80, '', 'Manual Input', true));
content.appendChild(this.createVertexTemplate('shape=loopLimit;whiteSpace=wrap;html=1;', 100, 80, '', 'Loop Limit', true));
content.appendChild(this.createVertexTemplate('shape=offPageConnector;whiteSpace=wrap;html=1;', 80, 80, '', 'Off Page Connector', true));
2014-07-25 06:48:01 +00:00
2014-11-10 09:02:21 +00:00
content.appendChild(this.createVertexTemplate('shape=delay;whiteSpace=wrap;html=1;', 80, 40, '', 'Delay', true));
content.appendChild(this.createVertexTemplate('shape=display;whiteSpace=wrap;html=1;', 80, 40, '', 'Display', true));
content.appendChild(this.createVertexTemplate('shape=doubleArrow;whiteSpace=wrap;html=1;', 100, 60, '', 'Double Arrow', true));
content.appendChild(this.createVertexTemplate('shape=doubleArrow;direction=south;whiteSpace=wrap;html=1;', 60, 100, '', 'Double Arrow Vertical', true));
content.appendChild(this.createVertexTemplate('shape=actor;whiteSpace=wrap;html=1;', 40, 60, '', 'User', true));
content.appendChild(this.createVertexTemplate('shape=cross;whiteSpace=wrap;html=1;', 80, 80, '', 'Cross', true));
content.appendChild(this.createVertexTemplate('shape=corner;whiteSpace=wrap;html=1;', 80, 80, '', 'Corner', true));
content.appendChild(this.createVertexTemplate('shape=tee;whiteSpace=wrap;html=1;', 80, 80, '', 'Tee', true));
content.appendChild(this.createVertexTemplate('swimlane;whiteSpace=wrap;html=1;', 200, 200, 'Container', 'Container', true));
content.appendChild(this.createVertexTemplate('swimlane;swimlaneLine=0;whiteSpace=wrap;html=1;', 200, 200, 'Container', 'Container w/o Separator', true));
content.appendChild(this.createVertexTemplate('swimlane;swimlaneFillColor=#ffffff;whiteSpace=wrap;html=1;', 200, 200, 'Container', 'Filled Container', true));
content.appendChild(this.createVertexTemplate('swimlane;swimlaneLine=0;swimlaneFillColor=#ffffff;whiteSpace=wrap;html=1;', 200, 200, 'Container', 'Filled Container w/o Separator', true));
2014-04-13 06:49:20 +00:00
};
2012-05-21 20:32:26 +00:00
/**
* Adds the general palette to the sidebar.
*/
Sidebar.prototype.addUmlPalette = function(expand)
{
this.addPalette('uml', 'UML', expand || false, mxUtils.bind(this, function(content)
{
2013-05-23 16:14:48 +00:00
content.appendChild(this.createVertexTemplate('', 110, 50, 'Object', 'Object', true));
2012-05-21 20:32:26 +00:00
var classCell = new mxCell('<p style="margin:0px;margin-top:4px;text-align:center;">' +
'<b>Class</b></p>' +
'<hr/><div style="height:2px;"></div><hr/>', new mxGeometry(0, 0, 140, 60),
2014-11-10 09:02:21 +00:00
'verticalAlign=top;align=left;overflow=fill;fontSize=12;fontFamily=Helvetica;html=1;');
2012-05-21 20:32:26 +00:00
classCell.vertex = true;
2013-05-23 16:14:48 +00:00
content.appendChild(this.createVertexTemplateFromCells([classCell], 140, 60, 'Class 1', true));
2012-05-21 20:32:26 +00:00
var classCell = new mxCell('<p style="margin:0px;margin-top:4px;text-align:center;">' +
'<b>Class</b></p>' +
'<hr/><p style="margin:0px;margin-left:4px;">+ field: Type</p><hr/>' +
'<p style="margin:0px;margin-left:4px;">+ method(): Type</p>', new mxGeometry(0, 0, 160, 90),
2014-11-10 09:02:21 +00:00
'verticalAlign=top;align=left;overflow=fill;fontSize=12;fontFamily=Helvetica;html=1;');
2012-05-21 20:32:26 +00:00
classCell.vertex = true;
2013-05-23 16:14:48 +00:00
content.appendChild(this.createVertexTemplateFromCells([classCell], 160, 90, 'Class 2', true));
2012-05-21 20:32:26 +00:00
var classCell = new mxCell('<p style="margin:0px;margin-top:4px;text-align:center;">' +
'<i>&lt;&lt;Interface&gt;&gt;</i><br/><b>Interface</b></p>' +
'<hr/><p style="margin:0px;margin-left:4px;">+ field1: Type<br/>' +
'+ field2: Type</p>' +
'<hr/><p style="margin:0px;margin-left:4px;">' +
'+ method1(Type): Type<br/>' +
'+ method2(Type, Type): Type</p>', new mxGeometry(0, 0, 190, 140),
2014-11-10 09:02:21 +00:00
'verticalAlign=top;align=left;overflow=fill;fontSize=12;fontFamily=Helvetica;html=1;');
2012-05-21 20:32:26 +00:00
classCell.vertex = true;
2013-05-23 16:14:48 +00:00
content.appendChild(this.createVertexTemplateFromCells([classCell], 190, 140, 'Interface', true));
2012-05-21 20:32:26 +00:00
var classCell = new mxCell('Module', new mxGeometry(0, 0, 120, 60),
'shape=component;align=left;spacingLeft=36');
classCell.vertex = true;
2013-05-23 16:14:48 +00:00
content.appendChild(this.createVertexTemplateFromCells([classCell], 120, 60, 'Module', true));
2012-05-21 20:32:26 +00:00
2014-10-09 13:52:12 +00:00
var classCell = new mxCell('&lt;&lt;component&gt;&gt;<br/><b>Component</b>', new mxGeometry(0, 0, 180, 90), 'overflow=fill;html=1;');
classCell.vertex = true;
var classCell1 = new mxCell('', new mxGeometry(1, 0, 20, 20), 'shape=component;jettyWidth=8;jettyHeight=4;');
classCell1.vertex = true;
classCell1.geometry.relative = true;
classCell1.geometry.offset = new mxPoint(-27, 7);
classCell.insert(classCell1);
2013-05-23 16:14:48 +00:00
content.appendChild(this.createVertexTemplateFromCells([classCell], 180, 90, 'Component', true));
2012-05-21 20:32:26 +00:00
2014-10-09 13:52:12 +00:00
var classCell = new mxCell('<p style="margin:0px;margin-top:6px;text-align:center;"><b>Component</b></p>' +
2014-11-10 09:02:21 +00:00
'<hr/><p style="margin:0px;margin-left:8px;">+ Attribute1: Type<br/>+ Attribute2: Type</p>', new mxGeometry(0, 0, 180, 90),
'align=left;overflow=fill;html=1;');
2012-05-21 20:32:26 +00:00
classCell.vertex = true;
2014-11-10 09:02:21 +00:00
var classCell1 = new mxCell('', new mxGeometry(1, 0, 20, 20), 'shape=component;jettyWidth=8;jettyHeight=4;html=1;');
2014-10-09 13:52:12 +00:00
classCell1.vertex = true;
classCell1.geometry.relative = true;
classCell1.geometry.offset = new mxPoint(-23, 3);
classCell.insert(classCell1);
2013-05-23 16:14:48 +00:00
content.appendChild(this.createVertexTemplateFromCells([classCell], 180, 90, 'Component with Attributes', true));
2012-05-21 20:32:26 +00:00
var cardCell = new mxCell('Block', new mxGeometry(0, 0, 180, 120),
2014-11-10 09:02:21 +00:00
'verticalAlign=top;align=left;spacingTop=8;spacingLeft=2;spacingRight=12;shape=cube;size=10;direction=south;fontStyle=4;html=1;');
2012-05-21 20:32:26 +00:00
cardCell.vertex = true;
2013-05-23 16:14:48 +00:00
content.appendChild(this.createVertexTemplateFromCells([cardCell], 180, 120, 'Block', true));
2012-05-21 20:32:26 +00:00
2014-11-10 09:02:21 +00:00
content.appendChild(this.createVertexTemplate('shape=folder;fontStyle=1;spacingTop=10;tabWidth=40;tabHeight=14;tabPosition=left;html=1;', 70, 50,
2013-05-23 16:14:48 +00:00
'package', 'Package', true));
2012-05-21 20:32:26 +00:00
var classCell = new mxCell('<p style="margin:0px;margin-top:4px;text-align:center;text-decoration:underline;">' +
'<b>Object:Type</b></p><hr/>' +
'<p style="margin:0px;margin-left:8px;">field1 = value1<br/>field2 = value2<br>field3 = value3</p>',
new mxGeometry(0, 0, 160, 90),
2014-11-10 09:02:21 +00:00
'verticalAlign=top;align=left;overflow=fill;fontSize=12;fontFamily=Helvetica;html=1;');
2012-05-21 20:32:26 +00:00
classCell.vertex = true;
2013-05-23 16:14:48 +00:00
content.appendChild(this.createVertexTemplateFromCells([classCell], 160, 90, 'Object', true));
2014-10-30 08:08:05 +00:00
2014-11-10 09:02:21 +00:00
content.appendChild(this.createVertexTemplate('shape=lollipop;direction=south;html=1;', 30, 10, '', 'Provided Interface', true));
content.appendChild(this.createVertexTemplate('shape=requires;direction=north;html=1;', 30, 20, '', 'Required Interface', true));
2014-10-30 08:08:05 +00:00
2014-02-27 11:22:13 +00:00
var tableCell = new mxCell('<div style="box-sizing:border-box;width:100%;background:#e4e4e4;margin:1px;padding:2px;">Tablename</div><table style="width:100%;">' +
2013-05-23 16:14:48 +00:00
'<tr><td>PK</td><td style="padding:2px;">uniqueId</td></tr>' +
'<tr><td>FK1</td><td style="padding:2px;">foreignKey</td></tr>' +
'<tr><td></td><td style="padding:2px;">fieldname</td></tr>' +
2014-11-10 09:02:21 +00:00
'</table>', new mxGeometry(0, 0, 180, 90), 'verticalAlign=top;align=left;overflow=fill;html=1;');
2012-05-21 20:32:26 +00:00
tableCell.vertex = true;
2013-05-23 16:14:48 +00:00
content.appendChild(this.createVertexTemplateFromCells([tableCell], 180, 90, 'Entity', true));
2014-11-10 09:02:21 +00:00
content.appendChild(this.createVertexTemplate('shape=umlActor;verticalLabelPosition=bottom;verticalAlign=top;html=1;', 40, 80, 'Actor', 'Actor', false));
content.appendChild(this.createVertexTemplate('ellipse;whiteSpace=wrap;html=1;', 140, 70, 'Use Case', 'Use Case', true));
2012-05-21 20:32:26 +00:00
var cardCell = new mxCell('', new mxGeometry(0, 0, 30, 30),
2014-11-10 09:02:21 +00:00
'ellipse;html=1;shape=startState;fillColor=#000000;strokeColor=#ff0000;');
2012-05-21 20:32:26 +00:00
cardCell.vertex = true;
2014-11-10 09:02:21 +00:00
var assoc2 = new mxCell('', new mxGeometry(0, 0, 0, 0), 'edgeStyle=elbowEdgeStyle;elbow=horizontal;html=1;verticalAlign=bottom;endArrow=open;endSize=8;strokeColor=#ff0000;');
2014-10-30 08:08:05 +00:00
assoc2.geometry.setTerminalPoint(new mxPoint(15, 80), false);
assoc2.geometry.relative = true;
2012-05-21 20:32:26 +00:00
assoc2.edge = true;
cardCell.insertEdge(assoc2, true);
2014-10-30 08:08:05 +00:00
content.appendChild(this.createVertexTemplateFromCells([cardCell, assoc2], 30, 90, 'Start', true));
2012-05-21 20:32:26 +00:00
var cardCell = new mxCell('Activity', new mxGeometry(0, 0, 120, 40),
2014-11-10 09:02:21 +00:00
'rounded=1;whiteSpace=wrap;html=1;arcSize=40;fillColor=#ffffc0;strokeColor=#ff0000;');
2012-05-21 20:32:26 +00:00
cardCell.vertex = true;
2014-11-10 09:02:21 +00:00
var assoc2 = new mxCell('', new mxGeometry(0, 0, 0, 0), 'edgeStyle=elbowEdgeStyle;elbow=horizontal;html=1;verticalAlign=bottom;endArrow=open;endSize=8;strokeColor=#ff0000;');
2012-05-21 20:32:26 +00:00
assoc2.geometry.setTerminalPoint(new mxPoint(60, 80), false);
2014-10-30 08:08:05 +00:00
assoc2.geometry.relative = true;
2012-05-21 20:32:26 +00:00
assoc2.edge = true;
cardCell.insertEdge(assoc2, true);
2014-10-30 08:08:05 +00:00
content.appendChild(this.createVertexTemplateFromCells([cardCell, assoc2], 120, 90, 'Activity', true));
2012-05-21 20:32:26 +00:00
var cardCell = new mxCell('<div style="margin-top:8px;"><b>Composite State</b><hr/>Subtitle</div>', new mxGeometry(0, 0, 160, 60),
2014-11-10 09:02:21 +00:00
'rounded=1;arcSize=40;overflow=fill;whiteSpace=wrap;html=1;verticalAlign=top;fillColor=#ffffc0;strokeColor=#ff0000;');
2012-05-21 20:32:26 +00:00
cardCell.vertex = true;
2014-11-10 09:02:21 +00:00
var assoc2 = new mxCell('', new mxGeometry(0, 0, 0, 0), 'edgeStyle=elbowEdgeStyle;elbow=horizontal;html=1;verticalAlign=bottom;endArrow=open;endSize=8;strokeColor=#ff0000;');
2012-05-21 20:32:26 +00:00
assoc2.geometry.setTerminalPoint(new mxPoint(80, 100), false);
2014-10-30 08:08:05 +00:00
assoc2.geometry.relative = true;
2012-05-21 20:32:26 +00:00
assoc2.edge = true;
cardCell.insertEdge(assoc2, true);
2014-10-30 08:08:05 +00:00
content.appendChild(this.createVertexTemplateFromCells([cardCell, assoc2], 160, 110, 'Composite State', true));
2012-05-21 20:32:26 +00:00
var cardCell = new mxCell('Condition', new mxGeometry(0, 0, 80, 40),
2014-11-10 09:02:21 +00:00
'rhombus;whiteSpace=wrap;html=1;fillColor=#ffffc0;strokeColor=#ff0000;');
2012-05-21 20:32:26 +00:00
cardCell.vertex = true;
2014-11-10 09:02:21 +00:00
var assoc1 = new mxCell('no', new mxGeometry(0, 0, 0, 0), 'edgeStyle=elbowEdgeStyle;elbow=horizontal;html=1;align=left;verticalAlign=bottom;endArrow=open;endSize=8;strokeColor=#ff0000;');
2012-05-21 20:32:26 +00:00
assoc1.geometry.setTerminalPoint(new mxPoint(120, 20), false);
assoc1.geometry.relative = true;
assoc1.geometry.x = -1;
assoc1.edge = true;
cardCell.insertEdge(assoc1, true);
2014-11-10 09:02:21 +00:00
var assoc2 = new mxCell('yes', new mxGeometry(0, 0, 0, 0), 'edgeStyle=elbowEdgeStyle;elbow=horizontal;html=1;align=left;verticalAlign=top;endArrow=open;endSize=8;strokeColor=#ff0000;');
2012-05-21 20:32:26 +00:00
assoc2.geometry.setTerminalPoint(new mxPoint(40, 80), false);
assoc2.geometry.relative = true;
assoc2.geometry.x = -1;
assoc2.edge = true;
cardCell.insertEdge(assoc2, true);
2014-10-30 08:08:05 +00:00
content.appendChild(this.createVertexTemplateFromCells([cardCell, assoc1, assoc2], 120, 90, 'Condition', true));
2012-05-21 20:32:26 +00:00
var cardCell = new mxCell('', new mxGeometry(0, 0, 200, 10),
2014-11-10 09:02:21 +00:00
'shape=line;html=1;strokeWidth=6;strokeColor=#ff0000;');
2012-05-21 20:32:26 +00:00
cardCell.vertex = true;
2014-11-10 09:02:21 +00:00
var assoc2 = new mxCell('', new mxGeometry(0, 0, 0, 0), 'edgeStyle=elbowEdgeStyle;elbow=horizontal;html=1;verticalAlign=bottom;endArrow=open;endSize=8;strokeColor=#ff0000;');
2012-05-21 20:32:26 +00:00
assoc2.geometry.setTerminalPoint(new mxPoint(100, 50), false);
2014-10-30 08:08:05 +00:00
assoc2.geometry.relative = true;
2012-05-21 20:32:26 +00:00
assoc2.edge = true;
cardCell.insertEdge(assoc2, true);
2014-10-30 08:08:05 +00:00
content.appendChild(this.createVertexTemplateFromCells([cardCell, assoc2], 200, 60, 'Fork/Join', true));
2012-05-21 20:32:26 +00:00
2014-11-10 09:02:21 +00:00
content.appendChild(this.createVertexTemplate('ellipse;html=1;shape=endState;fillColor=#000000;strokeColor=#ff0000', 30, 30, '', 'End', true));
2013-07-12 07:09:46 +00:00
2014-11-10 09:02:21 +00:00
var umlLifeline = new mxCell(':Object', new mxGeometry(0, 0, 100, 300), 'shape=umlLifeline;perimeter=lifelinePerimeter;whiteSpace=wrap;html=1;');
2013-07-12 07:09:46 +00:00
umlLifeline.vertex = true;
2012-05-21 20:32:26 +00:00
2013-07-12 07:09:46 +00:00
content.appendChild(this.createVertexTemplateFromCells([umlLifeline], 100, 300, 'Lifeline', true));
2012-05-21 20:32:26 +00:00
2014-11-10 09:02:21 +00:00
var classCell1 = new mxCell('', new mxGeometry(100, 0, 20, 70), 'html=1;');
2012-05-21 20:32:26 +00:00
classCell1.vertex = true;
2014-11-10 09:02:21 +00:00
var assoc1 = new mxCell('invoke', new mxGeometry(0, 0, 0, 0), 'edgeStyle=elbowEdgeStyle;elbow=vertical;html=1;verticalAlign=bottom;endArrow=block;');
2012-05-21 20:32:26 +00:00
assoc1.geometry.setTerminalPoint(new mxPoint(0, 0), true);
2014-10-30 08:08:05 +00:00
assoc1.geometry.relative = true;
2012-05-21 20:32:26 +00:00
assoc1.edge = true;
classCell1.insertEdge(assoc1, false);
2013-05-23 16:14:48 +00:00
content.appendChild(this.createVertexTemplateFromCells([classCell1, assoc1], 120, 70, 'Invocation', true));
2012-05-21 20:32:26 +00:00
2014-11-10 09:02:21 +00:00
var classCell1 = new mxCell('', new mxGeometry(100, 0, 20, 70), 'html=1;');
2012-05-21 20:32:26 +00:00
classCell1.vertex = true;
2014-11-10 09:02:21 +00:00
var assoc1 = new mxCell('invoke', new mxGeometry(0, 0, 0, 0), 'edgeStyle=elbowEdgeStyle;elbow=vertical;html=1;verticalAlign=bottom;endArrow=block;');
2012-05-21 20:32:26 +00:00
assoc1.geometry.setTerminalPoint(new mxPoint(0, 0), true);
2014-10-30 08:08:05 +00:00
assoc1.geometry.relative = true;
2012-05-21 20:32:26 +00:00
assoc1.edge = true;
classCell1.insertEdge(assoc1, false);
2014-11-10 09:02:21 +00:00
var assoc2 = new mxCell('return', new mxGeometry(0, 0, 0, 0), 'edgeStyle=elbowEdgeStyle;elbow=vertical;html=1;verticalAlign=bottom;dashed=1;endArrow=open;endSize=8;');
2012-05-21 20:32:26 +00:00
assoc2.geometry.setTerminalPoint(new mxPoint(0, 70), false);
2014-10-30 08:08:05 +00:00
assoc2.geometry.relative = true;
2012-05-21 20:32:26 +00:00
assoc2.edge = true;
classCell1.insertEdge(assoc2, true);
2014-11-10 09:02:21 +00:00
var assoc3 = new mxCell('invoke', new mxGeometry(0, 0, 0, 0), 'edgeStyle=elbowEdgeStyle;elbow=vertical;html=1;align=left;endArrow=open;');
2014-10-30 08:08:05 +00:00
assoc3.geometry.relative = true;
2012-05-21 20:32:26 +00:00
assoc3.edge = true;
classCell1.insertEdge(assoc3, true);
classCell1.insertEdge(assoc3, false);
2013-05-23 16:14:48 +00:00
content.appendChild(this.createVertexTemplateFromCells([classCell1, assoc1, assoc2, assoc3], 120, 70, 'Synchronous Invocation', true));
2012-05-21 20:32:26 +00:00
2014-11-10 09:02:21 +00:00
var assoc = new mxCell('name', new mxGeometry(0, 0, 0, 0), 'endArrow=block;endFill=1;html=1;edgeStyle=orthogonalEdgeStyle;align=left;verticalAlign=top;');
2012-05-21 20:32:26 +00:00
assoc.geometry.setTerminalPoint(new mxPoint(0, 0), true);
assoc.geometry.setTerminalPoint(new mxPoint(160, 0), false);
assoc.geometry.relative = true;
assoc.geometry.x = -1;
assoc.edge = true;
2014-11-10 09:02:21 +00:00
var sourceLabel = new mxCell('1', new mxGeometry(-1, 0, 0, 0), 'resizable=0;html=1;align=left;verticalAlign=bottom;labelBackgroundColor=#ffffff;fontSize=10;');
2012-05-21 20:32:26 +00:00
sourceLabel.geometry.relative = true;
sourceLabel.setConnectable(false);
sourceLabel.vertex = true;
assoc.insert(sourceLabel);
2013-05-23 16:14:48 +00:00
content.appendChild(this.createEdgeTemplateFromCells([assoc], 160, 0, 'Relation', true));
2012-05-21 20:32:26 +00:00
2014-11-10 09:02:21 +00:00
var assoc = new mxCell('', new mxGeometry(0, 0, 0, 0), 'endArrow=none;html=1;edgeStyle=orthogonalEdgeStyle;');
2012-05-21 20:32:26 +00:00
assoc.geometry.setTerminalPoint(new mxPoint(0, 0), true);
assoc.geometry.setTerminalPoint(new mxPoint(160, 0), false);
2014-10-30 08:08:05 +00:00
assoc.geometry.relative = true;
2012-05-21 20:32:26 +00:00
assoc.edge = true;
2014-11-10 09:02:21 +00:00
var sourceLabel = new mxCell('parent', new mxGeometry(-1, 0, 0, 0), 'resizable=0;html=1;align=left;verticalAlign=bottom;labelBackgroundColor=#ffffff;fontSize=10;');
2012-05-21 20:32:26 +00:00
sourceLabel.geometry.relative = true;
sourceLabel.setConnectable(false);
sourceLabel.vertex = true;
assoc.insert(sourceLabel);
2014-11-10 09:02:21 +00:00
var targetLabel = new mxCell('child', new mxGeometry(1, 0, 0, 0), 'resizable=0;html=1;align=right;verticalAlign=bottom;labelBackgroundColor=#ffffff;fontSize=10;');
2012-05-21 20:32:26 +00:00
targetLabel.geometry.relative = true;
targetLabel.setConnectable(false);
targetLabel.vertex = true;
assoc.insert(targetLabel);
2013-05-23 16:14:48 +00:00
content.appendChild(this.createEdgeTemplateFromCells([assoc], 160, 0, 'Association 1', true));
2012-05-21 20:32:26 +00:00
2014-11-10 09:02:21 +00:00
var assoc = new mxCell('1', new mxGeometry(0, 0, 0, 0), 'endArrow=open;html=1;endSize=12;startArrow=diamondThin;startSize=14;startFill=0;edgeStyle=orthogonalEdgeStyle;align=left;verticalAlign=bottom;');
2012-05-21 20:32:26 +00:00
assoc.geometry.setTerminalPoint(new mxPoint(0, 0), true);
assoc.geometry.setTerminalPoint(new mxPoint(160, 0), false);
assoc.geometry.relative = true;
assoc.geometry.x = -1;
assoc.edge = true;
2013-06-28 19:07:06 +00:00
content.appendChild(this.createEdgeTemplateFromCells([assoc], 160, 0, 'Aggregation', true));
2014-11-10 09:02:21 +00:00
var assoc = new mxCell('1', new mxGeometry(0, 0, 0, 0), 'endArrow=open;html=1;endSize=12;startArrow=diamondThin;startSize=14;startFill=1;edgeStyle=orthogonalEdgeStyle;align=left;verticalAlign=bottom;');
2013-06-28 19:07:06 +00:00
assoc.geometry.setTerminalPoint(new mxPoint(0, 0), true);
assoc.geometry.setTerminalPoint(new mxPoint(160, 0), false);
assoc.geometry.relative = true;
assoc.geometry.x = -1;
assoc.edge = true;
2012-05-21 20:32:26 +00:00
2013-05-23 16:14:48 +00:00
content.appendChild(this.createEdgeTemplateFromCells([assoc], 160, 0, 'Composition', true));
2012-05-21 20:32:26 +00:00
2014-11-10 09:02:21 +00:00
var assoc = new mxCell('Relation', new mxGeometry(0, 0, 0, 0), 'endArrow=open;html=1;endSize=12;startArrow=diamondThin;startSize=14;startFill=0;edgeStyle=orthogonalEdgeStyle;');
2012-05-21 20:32:26 +00:00
assoc.geometry.setTerminalPoint(new mxPoint(0, 0), true);
assoc.geometry.setTerminalPoint(new mxPoint(160, 0), false);
2014-10-30 08:08:05 +00:00
assoc.geometry.relative = true;
2012-05-21 20:32:26 +00:00
assoc.edge = true;
2014-11-10 09:02:21 +00:00
var sourceLabel = new mxCell('0..n', new mxGeometry(-1, 0, 0, 0), 'resizable=0;html=1;align=left;verticalAlign=top;labelBackgroundColor=#ffffff;fontSize=10;');
2012-05-21 20:32:26 +00:00
sourceLabel.geometry.relative = true;
sourceLabel.setConnectable(false);
sourceLabel.vertex = true;
assoc.insert(sourceLabel);
2014-11-10 09:02:21 +00:00
var targetLabel = new mxCell('1', new mxGeometry(1, 0, 0, 0), 'resizable=0;html=1;align=right;verticalAlign=top;labelBackgroundColor=#ffffff;fontSize=10;');
2012-05-21 20:32:26 +00:00
targetLabel.geometry.relative = true;
targetLabel.setConnectable(false);
targetLabel.vertex = true;
assoc.insert(targetLabel);
2013-05-23 16:14:48 +00:00
content.appendChild(this.createEdgeTemplateFromCells([assoc], 160, 0, 'Relation', true));
2012-05-21 20:32:26 +00:00
2014-11-10 09:02:21 +00:00
var assoc = new mxCell('Use', new mxGeometry(0, 0, 0, 0), 'endArrow=open;endSize=12;dashed=1;html=1;');
2012-05-21 20:32:26 +00:00
assoc.geometry.setTerminalPoint(new mxPoint(0, 0), true);
assoc.geometry.setTerminalPoint(new mxPoint(160, 0), false);
2014-10-30 08:08:05 +00:00
assoc.geometry.relative = true;
2012-05-21 20:32:26 +00:00
assoc.edge = true;
2013-05-23 16:14:48 +00:00
content.appendChild(this.createEdgeTemplateFromCells([assoc], 160, 0, 'Dependency', true));
2012-05-21 20:32:26 +00:00
2014-11-10 09:02:21 +00:00
var assoc = new mxCell('Extends', new mxGeometry(0, 0, 0, 0), 'endArrow=block;endSize=16;endFill=0;html=1;');
2012-05-21 20:32:26 +00:00
assoc.geometry.setTerminalPoint(new mxPoint(0, 0), true);
assoc.geometry.setTerminalPoint(new mxPoint(160, 0), false);
2014-10-30 08:08:05 +00:00
assoc.geometry.relative = true;
2012-05-21 20:32:26 +00:00
assoc.edge = true;
2013-05-23 16:14:48 +00:00
content.appendChild(this.createEdgeTemplateFromCells([assoc], 160, 0, 'Generalization'));
2012-05-21 20:32:26 +00:00
2014-11-10 09:02:21 +00:00
var assoc = new mxCell('', new mxGeometry(0, 0, 0, 0), 'endArrow=block;startArrow=block;endFill=1;startFill=1;html=1;');
2012-05-21 20:32:26 +00:00
assoc.geometry.setTerminalPoint(new mxPoint(0, 0), true);
assoc.geometry.setTerminalPoint(new mxPoint(160, 0), false);
2014-10-30 08:08:05 +00:00
assoc.geometry.relative = true;
2012-05-21 20:32:26 +00:00
assoc.edge = true;
2013-05-23 16:14:48 +00:00
content.appendChild(this.createEdgeTemplateFromCells([assoc], 160, 0, 'Association 2'));
2012-05-21 20:32:26 +00:00
}));
};
/**
* Adds the BPMN library to the sidebar.
*/
Sidebar.prototype.addBpmnPalette = function(dir, expand)
{
2013-05-23 16:14:48 +00:00
this.addPalette('bpmn', 'BPMN ' + mxResources.get('general'), false, mxUtils.bind(this, function(content)
{
2014-11-10 09:02:21 +00:00
content.appendChild(this.createVertexTemplate('shape=ext;rounded=1;html=1;', 120, 80, 'Task', 'Process', true));
content.appendChild(this.createVertexTemplate('shape=ext;rounded=1;html=1;double=1;', 120, 80, 'Transaction', 'Transaction', true));
content.appendChild(this.createVertexTemplate('shape=ext;rounded=1;html=1;dashed=1;dashPattern=1 4;', 120, 80, 'Event\nSub-Process', 'Event Sub-Process', true));
content.appendChild(this.createVertexTemplate('shape=ext;rounded=1;html=1;strokeWidth=3;', 120, 80, 'Call Activity', 'Call Activity', true));
2013-05-23 16:14:48 +00:00
2014-11-10 09:02:21 +00:00
var classCell = new mxCell('Sub-Process', new mxGeometry(0, 0, 120, 80), 'html=1;rounded=1');
2014-10-09 13:52:12 +00:00
classCell.vertex = true;
2014-11-10 09:02:21 +00:00
var classCell1 = new mxCell('', new mxGeometry(0.5, 1, 14, 14), 'html=1;shape=plus;');
2014-10-09 13:52:12 +00:00
classCell1.vertex = true;
classCell1.geometry.relative = true;
classCell1.geometry.offset = new mxPoint(-7, -14);
classCell.insert(classCell1);
2012-05-21 20:32:26 +00:00
2014-10-09 13:52:12 +00:00
content.appendChild(this.createVertexTemplateFromCells([classCell], 120, 80, 'Sub-Process', true));
2014-11-10 09:02:21 +00:00
var classCell = new mxCell('Receive', new mxGeometry(0, 0, 120, 80), 'html=1;rounded=1;');
2014-10-09 13:52:12 +00:00
classCell.vertex = true;
2014-11-10 09:02:21 +00:00
var classCell1 = new mxCell('', new mxGeometry(0, 0, 20, 14), 'html=1;shape=message;');
2014-10-09 13:52:12 +00:00
classCell1.vertex = true;
classCell1.geometry.relative = true;
classCell1.geometry.offset = new mxPoint(7, 7);
classCell.insert(classCell1);
content.appendChild(this.createVertexTemplateFromCells([classCell], 120, 80, 'Receive Task', true));
2014-11-10 09:02:21 +00:00
var classCell = new mxCell('User', new mxGeometry(0, 0, 120, 80), 'html=1;rounded=1;');
2014-10-09 13:52:12 +00:00
classCell.vertex = true;
2014-11-10 09:02:21 +00:00
var classCell1 = new mxCell('', new mxGeometry(0, 0, 14, 14), 'html=1;shape=actor;');
2014-10-09 13:52:12 +00:00
classCell1.vertex = true;
classCell1.geometry.relative = true;
classCell1.geometry.offset = new mxPoint(7, 7);
classCell.insert(classCell1);
2014-11-10 09:02:21 +00:00
var classCell1 = new mxCell('', new mxGeometry(0.5, 1, 14, 14), 'html=1;shape=plus;');
classCell1.vertex = true;
classCell1.geometry.relative = true;
classCell1.geometry.offset = new mxPoint(-7, -14);
classCell.insert(classCell1);
2014-10-09 13:52:12 +00:00
content.appendChild(this.createVertexTemplateFromCells([classCell], 120, 80, 'User Task', true));
2014-11-10 09:02:21 +00:00
var classCell = new mxCell('Process', new mxGeometry(0, 0, 120, 80), 'html=1;rounded=1;');
2013-05-23 16:14:48 +00:00
classCell.vertex = true;
2014-11-10 09:02:21 +00:00
var classCell1 = new mxCell('', new mxGeometry(1, 1, 30, 30), 'shape=mxgraph.bpmn.timer_start;perimeter=ellipsePerimeter;html=1;');
2013-05-23 16:14:48 +00:00
classCell1.vertex = true;
classCell1.geometry.relative = true;
classCell1.geometry.offset = new mxPoint(-40, -15);
classCell.insert(classCell1);
2014-11-10 09:02:21 +00:00
content.appendChild(this.createVertexTemplateFromCells([classCell], 120, 95, 'Attached Timer Event 1 ', true));
var classCell = new mxCell('Process', new mxGeometry(0, 0, 120, 80), 'html=1;rounded=1;');
classCell.vertex = true;
var classCell1 = new mxCell('', new mxGeometry(1, 0, 30, 30), 'shape=mxgraph.bpmn.timer_start;perimeter=ellipsePerimeter;html=1;');
classCell1.vertex = true;
classCell1.geometry.relative = true;
classCell1.geometry.offset = new mxPoint(-15, 10);
classCell.insert(classCell1);
2013-05-23 16:14:48 +00:00
2014-11-10 09:02:21 +00:00
content.appendChild(this.createVertexTemplateFromCells([classCell], 135, 80, 'Attached Timer Event 2', true));
2013-05-23 16:14:48 +00:00
2014-11-10 09:02:21 +00:00
content.appendChild(this.createVertexTemplate('swimlane;html=1;horizontal=0;startSize=20', 320, 240, 'Pool', 'Pool', true));
content.appendChild(this.createVertexTemplate('swimlane;html=1;horizontal=0;swimlaneFillColor=white;swimlaneLine=0;', 300, 120, 'Lane', 'Lane', true));
2013-05-23 16:14:48 +00:00
2014-11-10 09:02:21 +00:00
content.appendChild(this.createVertexTemplate('shape=hexagon;html=1;perimeter=hexagonPerimeter;', 60, 50, '', 'Conversation', true));
content.appendChild(this.createVertexTemplate('shape=hexagon;html=1;perimeter=hexagonPerimeter;strokeWidth=4', 60, 50, '', 'Call Conversation', true));
var classCell = new mxCell('', new mxGeometry(0, 0, 40, 30), 'shape=message;html=1;fillColor=#000000;strokeColor=#ffffff;strokeWidth=2;');
classCell.vertex = true;
content.appendChild(this.createVertexTemplateFromCells([classCell], 40, 30, 'Send Task', true));
2013-05-23 16:14:48 +00:00
2014-11-10 09:02:21 +00:00
var classCell = new mxCell('', new mxGeometry(0, 0, 40, 30), 'shape=message;html=1;');
2013-05-23 16:14:48 +00:00
classCell.vertex = true;
2014-11-10 09:02:21 +00:00
content.appendChild(this.createVertexTemplateFromCells([classCell], 40, 30, 'Receive Task', true));
2013-05-23 16:14:48 +00:00
2014-11-10 09:02:21 +00:00
var classCell = new mxCell('', new mxGeometry(0, 0, 14, 14), 'shape=plus;html=1;');
2013-05-23 16:14:48 +00:00
classCell.connectable = false;
classCell.vertex = true;
content.appendChild(this.createVertexTemplateFromCells([classCell], 14, 14, 'Sub-Process Marker', true));
2014-11-10 09:02:21 +00:00
var classCell = new mxCell('', new mxGeometry(0, 0, 14, 14), 'shape=parallelMarker;html=1;');
classCell.vertex = true;
2013-05-23 16:14:48 +00:00
2014-11-10 09:02:21 +00:00
content.appendChild(this.createVertexTemplateFromCells([classCell], 14, 14, 'Parallel MI Marker', true));
var classCell = new mxCell('', new mxGeometry(0, 0, 14, 14), 'shape=parallelMarker;direction=south;html=1;');
classCell.vertex = true;
content.appendChild(this.createVertexTemplateFromCells([classCell], 14, 14, 'Sequential MI Marker', true));
var assoc = new mxCell('', new mxGeometry(0, 0, 0, 0), 'endArrow=block;endFill=1;endSize=6;html=1;');
2013-05-23 16:14:48 +00:00
assoc.geometry.setTerminalPoint(new mxPoint(0, 0), true);
assoc.geometry.setTerminalPoint(new mxPoint(100, 0), false);
2014-10-30 08:08:05 +00:00
assoc.geometry.relative = true;
2013-05-23 16:14:48 +00:00
assoc.edge = true;
content.appendChild(this.createEdgeTemplateFromCells([assoc], 100, 0, 'Sequence Flow', true));
2014-11-10 09:02:21 +00:00
var assoc = new mxCell('', new mxGeometry(0, 0, 0, 0), 'startArrow=dash;startSize=8;endArrow=block;endFill=1;endSize=6;html=1;');
2013-05-23 16:14:48 +00:00
assoc.geometry.setTerminalPoint(new mxPoint(0, 0), true);
assoc.geometry.setTerminalPoint(new mxPoint(100, 0), false);
2014-10-30 08:08:05 +00:00
assoc.geometry.relative = true;
2013-05-23 16:14:48 +00:00
assoc.edge = true;
content.appendChild(this.createEdgeTemplateFromCells([assoc], 100, 0, 'Default Flow', true));
2014-11-10 09:02:21 +00:00
var assoc = new mxCell('', new mxGeometry(0, 0, 0, 0), 'startArrow=diamondThin;startFill=0;startSize=14;endArrow=block;endFill=1;endSize=6;html=1;');
2013-05-23 16:14:48 +00:00
assoc.geometry.setTerminalPoint(new mxPoint(0, 0), true);
assoc.geometry.setTerminalPoint(new mxPoint(100, 0), false);
2014-10-30 08:08:05 +00:00
assoc.geometry.relative = true;
2013-05-23 16:14:48 +00:00
assoc.edge = true;
content.appendChild(this.createEdgeTemplateFromCells([assoc], 100, 0, 'Conditional Flow', true));
2014-11-10 09:02:21 +00:00
var assoc = new mxCell('', new mxGeometry(0, 0, 0, 0), 'startArrow=oval;startFill=0;startSize=7;endArrow=block;endFill=0;endSize=10;dashed=1;html=1;');
2013-05-23 16:14:48 +00:00
assoc.geometry.setTerminalPoint(new mxPoint(0, 0), true);
assoc.geometry.setTerminalPoint(new mxPoint(100, 0), false);
2014-10-30 08:08:05 +00:00
assoc.geometry.relative = true;
2013-05-23 16:14:48 +00:00
assoc.edge = true;
content.appendChild(this.createEdgeTemplateFromCells([assoc], 100, 0, 'Message Flow 1'));
2014-11-10 09:02:21 +00:00
var assoc = new mxCell('', new mxGeometry(0, 0, 0, 0), 'startArrow=oval;startFill=0;startSize=7;endArrow=block;endFill=0;endSize=10;dashed=1;html=1;');
2013-05-23 16:14:48 +00:00
assoc.geometry.setTerminalPoint(new mxPoint(0, 0), true);
assoc.geometry.setTerminalPoint(new mxPoint(100, 0), false);
2014-10-30 08:08:05 +00:00
assoc.geometry.relative = true;
2013-05-23 16:14:48 +00:00
assoc.edge = true;
2014-11-10 09:02:21 +00:00
var sourceLabel = new mxCell('', new mxGeometry(0, 0, 20, 14), 'shape=message;html=1;');
2013-05-23 16:14:48 +00:00
sourceLabel.geometry.relative = true;
sourceLabel.setConnectable(false);
sourceLabel.vertex = true;
sourceLabel.geometry.offset = new mxPoint(-10, -7);
assoc.insert(sourceLabel);
content.appendChild(this.createEdgeTemplateFromCells([assoc], 100, 0, 'Message Flow 2', true));
2014-11-10 09:02:21 +00:00
var assoc = new mxCell('', new mxGeometry(0, 0, 0, 0), 'shape=link;html=1;');
2013-05-23 16:14:48 +00:00
assoc.geometry.setTerminalPoint(new mxPoint(0, 0), true);
assoc.geometry.setTerminalPoint(new mxPoint(100, 0), false);
2014-10-30 08:08:05 +00:00
assoc.geometry.relative = true;
2013-05-23 16:14:48 +00:00
assoc.edge = true;
content.appendChild(this.createEdgeTemplateFromCells([assoc], 100, 0, 'Link', true));
}));
2012-05-21 20:32:26 +00:00
};
/**
* Creates and returns the given title element.
*/
Sidebar.prototype.createTitle = function(label)
{
var elt = document.createElement('a');
elt.setAttribute('href', 'javascript:void(0);');
2013-11-11 12:31:46 +00:00
elt.setAttribute('title', label);
2012-06-14 12:43:20 +00:00
elt.className = 'geTitle';
2012-05-21 20:32:26 +00:00
mxUtils.write(elt, label);
return elt;
};
/**
* Creates a thumbnail for the given cells.
*/
2014-05-05 08:30:00 +00:00
Sidebar.prototype.createThumb = function(cells, width, height, parent, title, showLabel, showTitle)
2012-05-21 20:32:26 +00:00
{
2013-05-23 16:14:48 +00:00
this.graph.labelsVisible = (showLabel == null || showLabel);
this.graph.view.scaleAndTranslate(1, 0, 0);
2012-05-21 20:32:26 +00:00
this.graph.addCells(cells);
var bounds = this.graph.getGraphBounds();
2014-03-14 13:24:50 +00:00
var s = Math.floor(Math.min((width - 2 * this.thumbBorder) / bounds.width, (height - 2 * this.thumbBorder)
/ bounds.height) * 100) / 100;
2014-04-13 06:49:20 +00:00
this.graph.view.scaleAndTranslate(s, Math.floor((width - bounds.width * s) / 2 / s - bounds.x),
Math.floor((height - bounds.height * s) / 2 / s - bounds.y));
2012-05-21 20:32:26 +00:00
var node = null;
// For supporting HTML labels in IE9 standards mode the container is cloned instead
2013-05-23 16:14:48 +00:00
if (this.graph.dialect == mxConstants.DIALECT_SVG && !mxClient.NO_FO)
2012-05-21 20:32:26 +00:00
{
node = this.graph.view.getCanvas().ownerSVGElement.cloneNode(true);
}
2013-05-23 16:14:48 +00:00
// LATER: Check if deep clone can be used for quirks if container in DOM
else
2012-07-16 15:36:48 +00:00
{
node = this.graph.container.cloneNode(false);
node.innerHTML = this.graph.container.innerHTML;
}
2012-05-21 20:32:26 +00:00
this.graph.getModel().clear();
2013-05-23 16:14:48 +00:00
// Catch-all event handling
if (mxClient.IS_IE6)
{
parent.style.backgroundImage = 'url(' + this.editorUi.editor.transparentImage + ')';
}
2012-05-21 20:32:26 +00:00
node.style.position = 'relative';
2013-05-23 16:14:48 +00:00
node.style.overflow = 'hidden';
2012-05-21 20:32:26 +00:00
node.style.cursor = 'pointer';
2014-03-14 13:24:50 +00:00
node.style.left = this.thumbBorder + 'px';
node.style.top = this.thumbBorder + 'px';
2012-05-21 20:32:26 +00:00
node.style.width = width + 'px';
node.style.height = height + 'px';
2013-05-23 16:14:48 +00:00
node.style.visibility = '';
2013-01-16 09:00:09 +00:00
node.style.minWidth = '';
node.style.minHeight = '';
2012-05-21 20:32:26 +00:00
parent.appendChild(node);
2013-05-23 16:14:48 +00:00
// Adds title for sidebar entries
2014-05-05 08:30:00 +00:00
if (this.sidebarTitles && title != null && showTitle != false)
2013-05-23 16:14:48 +00:00
{
var border = (mxClient.IS_QUIRKS) ? 2 * this.thumbPadding + 2: 0;
parent.style.height = (this.thumbHeight + border + this.sidebarTitleSize + 8) + 'px';
var div = document.createElement('div');
div.style.fontSize = this.sidebarTitleSize + 'px';
2014-05-05 08:30:00 +00:00
div.style.color = '#303030';
2013-05-23 16:14:48 +00:00
div.style.textAlign = 'center';
div.style.whiteSpace = 'nowrap';
if (mxClient.IS_IE)
{
div.style.height = (this.sidebarTitleSize + 12) + 'px';
}
div.style.paddingTop = '4px';
mxUtils.write(div, title);
parent.appendChild(div);
}
2014-05-05 08:30:00 +00:00
return bounds;
2012-05-21 20:32:26 +00:00
};
/**
* Creates and returns a new palette item for the given image.
*/
2014-05-05 08:30:00 +00:00
Sidebar.prototype.createItem = function(cells, title, showLabel, showTitle, width, height)
2012-05-21 20:32:26 +00:00
{
var elt = document.createElement('a');
elt.setAttribute('href', 'javascript:void(0);');
2012-06-14 12:43:20 +00:00
elt.className = 'geItem';
2013-01-16 09:00:09 +00:00
elt.style.overflow = 'hidden';
2014-04-13 06:49:20 +00:00
var border = (mxClient.IS_QUIRKS) ? 8 + 2 * this.thumbPadding : 2 * this.thumbBorder;
2013-05-23 16:14:48 +00:00
elt.style.width = (this.thumbWidth + border) + 'px';
elt.style.height = (this.thumbHeight + border) + 'px';
elt.style.padding = this.thumbPadding + 'px';
2012-05-21 20:32:26 +00:00
// Blocks default click action
mxEvent.addListener(elt, 'click', function(evt)
{
mxEvent.consume(evt);
});
2014-05-05 08:30:00 +00:00
var bounds = this.createThumb(cells, this.thumbWidth, this.thumbHeight, elt, title, showLabel, showTitle);
var dx = 0;
var dy = 0;
if (cells.length > 1 || cells[0].vertex)
{
dx = (bounds.width - width - 1) / 2;
dy = (bounds.height - height - 1) / 2;
var ds = this.createDragSource(elt, this.createDropHandler(cells, true, dx, dy),
2014-10-09 13:52:12 +00:00
this.createDragPreview(bounds.width - 1, bounds.height - 1), cells);
2014-05-05 08:30:00 +00:00
this.addClickHandler(elt, ds, cells);
// Uses guides for vertices only if enabled in graph
ds.isGuidesEnabled = mxUtils.bind(this, function()
{
return this.editorUi.editor.graph.graphHandler.guidesEnabled;
});
}
else if (cells[0] != null && cells[0].edge)
{
2014-10-03 12:49:36 +00:00
var ds = this.createDragSource(elt, this.createDropHandler(cells, false, dx, dy),
2014-10-30 08:08:05 +00:00
this.createDragPreview(width, height), cells);
2014-10-03 12:49:36 +00:00
this.addClickHandler(elt, ds, cells);
2014-05-05 08:30:00 +00:00
}
// Shows a tooltip with the rendered cell
if (!mxClient.IS_IOS)
{
mxEvent.addGestureListeners(elt, null, mxUtils.bind(this, function(evt)
{
if (mxEvent.isMouseEvent(evt))
{
this.showTooltip(elt, cells, bounds.width, bounds.height, title, showLabel, dx, dy);
}
}));
}
2012-05-21 20:32:26 +00:00
return elt;
};
2014-10-03 12:49:36 +00:00
/**
* Creates a drop handler for inserting the given cells.
*/
Sidebar.prototype.updateShapes = function(source, targets)
{
var graph = this.editorUi.editor.graph;
var result = [];
graph.model.beginUpdate();
try
{
2014-10-09 13:52:12 +00:00
var cellStyle = graph.getModel().getStyle(source);
// Lists the styles to carry over from the existing shape
var styles = ['shadow', 'dashed', 'dashPattern', 'fontFamily', 'fontSize', 'fontColor', 'align', 'startArrow',
'startFill', 'startSize', 'endArrow', 'endFill', 'endSize', 'strokeColor', 'strokeWidth',
'fillColor', 'gradientColor', 'html', 'part', 'childLayout'];
2014-10-03 12:49:36 +00:00
for (var i = 0; i < targets.length; i++)
{
var targetCell = targets[i];
2014-10-09 13:52:12 +00:00
if ((graph.getModel().isVertex(targetCell) == graph.getModel().isVertex(source)) ||
(graph.getModel().isEdge(targetCell) == graph.getModel().isEdge(source)))
2014-10-03 12:49:36 +00:00
{
2014-10-09 13:52:12 +00:00
var state = graph.view.getState(targetCell);
2014-10-30 08:08:05 +00:00
var style = (state != null) ? state.style : graph.getCellStyle(targets[i]);
2014-10-03 12:49:36 +00:00
2014-10-09 13:52:12 +00:00
graph.getModel().setStyle(targetCell, cellStyle);
if (style != null)
2014-10-03 12:49:36 +00:00
{
2014-10-09 13:52:12 +00:00
for (var j = 0; j < styles.length; j++)
{
var value = style[styles[j]];
if (value != null)
{
graph.setCellStyles(styles[j], value, [targetCell]);
}
}
2014-10-03 12:49:36 +00:00
}
2014-10-09 13:52:12 +00:00
result.push(targetCell);
2014-10-03 12:49:36 +00:00
}
}
}
finally
{
graph.model.endUpdate();
}
return result;
};
2012-05-21 20:32:26 +00:00
/**
* Creates a drop handler for inserting the given cells.
*/
2014-05-05 08:30:00 +00:00
Sidebar.prototype.createDropHandler = function(cells, allowSplit, dx, dy)
2012-05-21 20:32:26 +00:00
{
2014-06-11 13:13:38 +00:00
return mxUtils.bind(this, function(graph, evt, target, x, y)
2012-05-21 20:32:26 +00:00
{
2013-05-23 16:14:48 +00:00
if (graph.isEnabled())
2012-05-21 20:32:26 +00:00
{
2013-05-23 16:14:48 +00:00
cells = graph.getImportableCells(cells);
2012-05-21 20:32:26 +00:00
2013-05-23 16:14:48 +00:00
if (cells.length > 0)
2012-05-21 20:32:26 +00:00
{
2014-01-22 17:31:30 +00:00
var validDropTarget = (target != null) ? graph.isValidDropTarget(target, cells, evt) : false;
2013-05-23 16:14:48 +00:00
var select = null;
2014-10-03 12:49:36 +00:00
2013-05-23 16:14:48 +00:00
if (target != null && !validDropTarget)
{
target = null;
}
2014-06-11 13:13:38 +00:00
graph.model.beginUpdate();
try
2013-05-23 16:14:48 +00:00
{
2014-10-03 12:49:36 +00:00
x = Math.round(x + dx);
y = Math.round(y + dy);
2014-06-11 13:13:38 +00:00
// Splits the target edge or inserts into target group
if (allowSplit && graph.isSplitEnabled() && graph.isSplitTarget(target, cells, evt))
{
2014-10-03 12:49:36 +00:00
graph.splitEdge(target, cells, null, x, y);
2014-06-11 13:13:38 +00:00
select = cells;
}
else if (cells.length > 0)
{
2014-10-03 12:49:36 +00:00
select = graph.importCells(cells, x, y, target);
2014-06-11 13:13:38 +00:00
}
2014-10-09 13:52:12 +00:00
this.editorUi.fireEvent(new mxEventObject('cellsInserted', 'cells', select));
2013-05-23 16:14:48 +00:00
}
2014-06-11 13:13:38 +00:00
finally
2013-05-23 16:14:48 +00:00
{
2014-06-11 13:13:38 +00:00
graph.model.endUpdate();
2013-05-23 16:14:48 +00:00
}
2014-07-25 06:48:01 +00:00
if (select != null && select.length > 0)
{
graph.scrollCellToVisible(select[0]);
graph.setSelectionCells(select);
}
2012-05-21 20:32:26 +00:00
}
2013-11-11 12:31:46 +00:00
mxEvent.consume(evt);
2012-05-21 20:32:26 +00:00
}
2014-06-11 13:13:38 +00:00
});
2012-05-21 20:32:26 +00:00
};
/**
* Creates and returns a preview element for the given width and height.
*/
Sidebar.prototype.createDragPreview = function(width, height)
{
var elt = document.createElement('div');
elt.style.border = '1px dashed black';
elt.style.width = width + 'px';
elt.style.height = height + 'px';
return elt;
};
/**
* Creates a drag source for the given element.
*/
2014-10-30 08:08:05 +00:00
Sidebar.prototype.dropAndConnect = function(source, targets, direction, dropCellIndex)
2012-05-21 20:32:26 +00:00
{
2014-10-30 08:08:05 +00:00
var geo = this.getDropAndConnectGeometry(source, targets[dropCellIndex], direction, targets.length > 1);
2014-10-09 13:52:12 +00:00
if (geo != null)
{
var graph = this.editorUi.editor.graph;
2014-11-10 09:02:21 +00:00
// Targets without the new edge for selection
var tmp = [];
2014-10-09 13:52:12 +00:00
graph.model.beginUpdate();
try
{
var sourceGeo = graph.getCellGeometry(source);
2014-10-30 08:08:05 +00:00
var geo2 = graph.getCellGeometry(targets[dropCellIndex]);
targets = graph.importCells(targets, geo.x - geo2.x, geo.y - geo2.y, (graph.model.isEdge(source) ||
(sourceGeo != null && !sourceGeo.relative)) ? graph.model.getParent(source) : null);
2014-11-10 09:02:21 +00:00
tmp = targets;
2014-10-30 08:08:05 +00:00
if (graph.model.isEdge(source))
{
// LATER: Push new terminal out radially from edge start point
graph.model.setTerminal(source, targets[dropCellIndex], direction == mxConstants.DIRECTION_NORTH);
}
else if (graph.model.isEdge(targets[dropCellIndex]))
{
graph.model.setTerminal(targets[dropCellIndex], source, true);
geo2 = graph.getCellGeometry(targets[dropCellIndex]);
geo2.setTerminalPoint(geo.getTerminalPoint(false), false);
}
else
{
geo2 = graph.getCellGeometry(targets[dropCellIndex]);
var dx = geo.x - geo2.x;
var dy = geo.y - geo2.y;
geo.x = geo2.x;
geo.y = geo2.y;
graph.model.setGeometry(targets[dropCellIndex], geo);
graph.cellsMoved(targets, dx, dy, null, null, true);
2014-11-10 09:02:21 +00:00
tmp = targets.slice();
targets.push(graph.insertEdge(null, null, '', source, targets[dropCellIndex],
this.editorUi.createCurrentEdgeStyle()));
2014-10-30 08:08:05 +00:00
}
this.editorUi.fireEvent(new mxEventObject('cellsInserted', 'cells', targets));
2014-10-09 13:52:12 +00:00
}
finally
{
graph.model.endUpdate();
}
2014-11-10 09:02:21 +00:00
graph.setSelectionCells(tmp);
2014-10-09 13:52:12 +00:00
}
};
/**
* Creates a drag source for the given element.
*/
2014-10-30 08:08:05 +00:00
Sidebar.prototype.getDropAndConnectGeometry = function(source, target, direction, keepSize)
2014-10-09 13:52:12 +00:00
{
var graph = this.editorUi.editor.graph;
var view = graph.view;
var geo = graph.getCellGeometry(source);
var geo2 = graph.getCellGeometry(target);
if (geo != null && geo2 != null)
{
geo2 = geo2.clone();
2014-10-30 08:08:05 +00:00
if (graph.model.isEdge(source))
2014-10-09 13:52:12 +00:00
{
2014-10-30 08:08:05 +00:00
var state = graph.view.getState(source);
var pts = state.absolutePoints;
var p0 = pts[0];
var pe = pts[pts.length - 1];
if (direction == mxConstants.DIRECTION_NORTH)
{
geo2.x = (p0.x - view.translate.x) / view.scale - geo2.width / 2;
geo2.y = (p0.y - view.translate.y) / view.scale - geo2.height / 2;
}
else
{
geo2.x = (pe.x - view.translate.x) / view.scale - geo2.width / 2;
geo2.y = (pe.y - view.translate.y) / view.scale - geo2.height / 2;
}
2014-10-09 13:52:12 +00:00
}
2014-10-30 08:08:05 +00:00
else
2014-10-09 13:52:12 +00:00
{
2014-10-30 08:08:05 +00:00
if (geo.relative)
{
var state = graph.view.getState(source);
geo = geo.clone();
geo.x = (state.x - view.translate.x) / view.scale;
geo.y = (state.y - view.translate.y) / view.scale;
}
var length = Math.min(80, geo.height);
// Maintains edge length
if (graph.model.isEdge(target) && geo2.getTerminalPoint(true) != null && geo2.getTerminalPoint(false) != null)
{
var p0 = geo2.getTerminalPoint(true);
var pe = geo2.getTerminalPoint(false);
var dx = pe.x - p0.x;
var dy = pe.y - p0.y;
length = Math.sqrt(dx * dx + dy * dy);
geo2.x = geo.getCenterX();
geo2.y = geo.getCenterY();
geo2.width = 1;
geo2.height = 1;
if (direction == mxConstants.DIRECTION_NORTH)
{
geo2.height = length
geo2.y = geo.y - length;
geo2.setTerminalPoint(new mxPoint(geo2.x, geo2.y), false);
}
else if (direction == mxConstants.DIRECTION_EAST)
{
geo2.width = length
geo2.x = geo.x + geo.width;
geo2.setTerminalPoint(new mxPoint(geo2.x + geo2.width, geo2.y), false);
}
else if (direction == mxConstants.DIRECTION_SOUTH)
{
geo2.height = length
geo2.y = geo.y + geo.height;
geo2.setTerminalPoint(new mxPoint(geo2.x, geo2.y + geo2.height), false);
}
else if (direction == mxConstants.DIRECTION_WEST)
{
geo2.width = length
geo2.x = geo.x - length;
geo2.setTerminalPoint(new mxPoint(geo2.x, geo2.y), false);
}
}
else
{
// Try match size or ignore if width or height < 45 which
// is considered special enough to be ignored here
if (!keepSize && geo2.width > 45 && geo2.height > 45)
{
geo2.width = geo2.width * (geo.height / geo2.height);
geo2.height = geo.height;
}
geo2.x = geo.x + geo.width / 2 - geo2.width / 2;
geo2.y = geo.y + geo.height / 2 - geo2.height / 2;
if (direction == mxConstants.DIRECTION_NORTH)
{
geo2.y = geo2.y - geo.height / 2 - geo2.height / 2 - length;
}
else if (direction == mxConstants.DIRECTION_EAST)
{
geo2.x = geo2.x + geo.width / 2 + geo2.width / 2 + length;
}
else if (direction == mxConstants.DIRECTION_SOUTH)
{
geo2.y = geo2.y + geo.height / 2 + geo2.height / 2 + length;
}
else if (direction == mxConstants.DIRECTION_WEST)
{
geo2.x = geo2.x - geo.width / 2 - geo2.width / 2 - length;
}
}
2014-10-09 13:52:12 +00:00
}
}
return geo2;
};
/**
* Creates a drag source for the given element.
*/
Sidebar.prototype.createDragSource = function(elt, dropHandler, preview, cells)
{
2014-10-30 08:08:05 +00:00
// Checks if the cells contain any vertices
var freeSourceEdge = null;
var firstVertex = null;
for (var i = 0; i < cells.length; i++)
{
if (firstVertex == null && this.editorUi.editor.graph.model.isVertex(cells[i]))
{
firstVertex = i;
}
else if (freeSourceEdge == null && this.editorUi.editor.graph.model.isEdge(cells[i]) &&
this.editorUi.editor.graph.model.getTerminal(cells[i], true) == null)
{
freeSourceEdge = i;
}
if (firstVertex != null && freeSourceEdge != null)
{
break;
}
}
2014-10-09 13:52:12 +00:00
var dragSource = mxUtils.makeDraggable(elt, this.editorUi.editor.graph, mxUtils.bind(this, function(graph, evt, target, x, y)
{
2014-11-10 09:02:21 +00:00
if (cells != null && currentStyleTarget != null && activeArrow == styleTarget)
{
var tmp = graph.isCellSelected(currentStyleTarget.cell) ? graph.getSelectionCells() : [currentStyleTarget.cell];
var updatedCells = this.updateShapes(cells[firstVertex], tmp);
graph.setSelectionCells(updatedCells);
}
else if (cells != null && activeArrow != null && currentTargetState != null && activeArrow != styleTarget)
2014-10-09 13:52:12 +00:00
{
2014-10-30 08:08:05 +00:00
var index = (graph.model.isEdge(currentTargetState.cell) || freeSourceEdge == null) ? firstVertex : freeSourceEdge;
this.dropAndConnect(currentTargetState.cell, cells, direction, index);
2014-10-09 13:52:12 +00:00
}
else
{
dropHandler.apply(this, arguments);
}
}),
preview, 0, 0, this.editorUi.editor.graph.autoscroll, true, true);
// Stops dragging if cancel is pressed
this.editorUi.editor.graph.addListener(mxEvent.ESCAPE, function(sender, evt)
{
if (dragSource.isActive())
{
dragSource.reset();
}
});
2014-07-25 06:48:01 +00:00
2013-06-28 19:07:06 +00:00
// Overrides mouseDown to ignore popup triggers
var mouseDown = dragSource.mouseDown;
dragSource.mouseDown = function(evt)
{
2014-05-12 09:58:11 +00:00
if (!mxEvent.isPopupTrigger(evt) && !mxEvent.isMultiTouchEvent(evt))
2013-06-28 19:07:06 +00:00
{
mouseDown.apply(this, arguments);
}
};
2012-05-21 20:32:26 +00:00
2014-10-09 13:52:12 +00:00
// Workaround for event redirection via image tag in quirks and IE8
function createArrow(img)
{
var arrow = null;
if (mxClient.IS_IE && !mxClient.IS_SVG)
{
// Workaround for PNG images in IE6
if (mxClient.IS_IE6 && document.compatMode != 'CSS1Compat')
{
arrow = document.createElement(mxClient.VML_PREFIX + ':image');
arrow.setAttribute('src', img.src);
arrow.style.borderStyle = 'none';
}
else
{
arrow = document.createElement('div');
arrow.style.backgroundImage = 'url(' + img.src + ')';
arrow.style.backgroundPosition = 'center';
arrow.style.backgroundRepeat = 'no-repeat';
}
arrow.style.width = (img.width + 4) + 'px';
arrow.style.height = (img.height + 4) + 'px';
arrow.style.display = (mxClient.IS_QUIRKS) ? 'inline' : 'inline-block';
}
else
{
arrow = mxUtils.createImage(img.src);
if (touchStyle)
{
arrow.style.width = '29px';
arrow.style.height = '29px';
}
else
{
arrow.style.width = img.width + 'px';
arrow.style.height = img.height + 'px';
}
}
2014-11-10 09:02:21 +00:00
mxUtils.setOpacity(arrow, (img == this.refreshTarget) ? 30 : 20);
2014-10-09 13:52:12 +00:00
arrow.style.position = 'absolute';
arrow.style.cursor = 'crosshair';
return arrow;
};
var currentTargetState = null;
var currentStateHandle = null;
2014-11-10 09:02:21 +00:00
var currentStyleTarget = null;
2014-10-09 13:52:12 +00:00
var activeTarget = false;
var arrowUp = createArrow(this.triangleUp);
var arrowRight = createArrow(this.triangleRight);
var arrowDown = createArrow(this.triangleDown);
var arrowLeft = createArrow(this.triangleLeft);
2014-11-10 09:02:21 +00:00
var styleTarget = createArrow(this.refreshTarget);
2014-10-30 08:08:05 +00:00
var roundSource = createArrow(this.roundDrop);
var roundTarget = createArrow(this.roundDrop);
2014-10-09 13:52:12 +00:00
var arrowSpacing = 4;
var direction = mxConstants.DIRECTION_NORTH;
var activeArrow = null;
function checkArrow(x, y, bounds, arrow)
{
if (mxUtils.contains(bounds, x, y))
{
mxUtils.setOpacity(arrow, 100);
activeArrow = arrow;
}
else
{
2014-11-10 09:02:21 +00:00
mxUtils.setOpacity(arrow, (arrow == styleTarget) ? 30 : 20);
2014-10-09 13:52:12 +00:00
}
return bounds;
};
// Hides guides and preview if target is active
var sidebar = this;
var dsCreatePreviewElement = dragSource.createPreviewElement;
// Stores initial size of preview element
dragSource.createPreviewElement = function(graph)
{
var elt = dsCreatePreviewElement.apply(this, arguments);
this.previewElementWidth = elt.style.width;
this.previewElementHeight = elt.style.height;
return elt;
};
dragSource.dragOver = function(graph, evt)
{
mxDragSource.prototype.dragOver.apply(this, arguments);
if (this.currentGuide != null && activeArrow != null)
{
this.currentGuide.hide();
}
if (this.previewElement != null)
{
2014-11-10 09:02:21 +00:00
if (currentStyleTarget != null && activeArrow == styleTarget)
{
this.previewElement.style.left = currentStyleTarget.x + 'px';
this.previewElement.style.top = currentStyleTarget.y + 'px';
this.previewElement.style.width = currentStyleTarget.width + 'px';
this.previewElement.style.height = currentStyleTarget.height + 'px';
}
else if (currentTargetState != null && activeArrow != null)
2014-10-09 13:52:12 +00:00
{
var graph = sidebar.editorUi.editor.graph;
var view = graph.view;
2014-10-30 08:08:05 +00:00
var index = (graph.model.isEdge(currentTargetState.cell) || freeSourceEdge == null) ? firstVertex : freeSourceEdge;
var geo = sidebar.getDropAndConnectGeometry(currentTargetState.cell, cells[index], direction, cells.length > 1);
var geo2 = (!graph.model.isEdge(currentTargetState.cell)) ? graph.getCellGeometry(currentTargetState.cell) : null;
var geo3 = graph.getCellGeometry(cells[index]);
2014-10-09 13:52:12 +00:00
var parent = graph.model.getParent(currentTargetState.cell);
var dx = view.translate.x * view.scale;
var dy = view.translate.y * view.scale;
if (geo2 != null && !geo2.relative && graph.model.isVertex(parent))
{
var pState = view.getState(parent);
dx = pState.x;
dy = pState.y;
}
// Shows preview at drop location
2014-10-30 08:08:05 +00:00
this.previewElement.style.left = ((geo.x - geo3.x) * view.scale + dx) + 'px';
this.previewElement.style.top = ((geo.y - geo3.y) * view.scale + dy) + 'px';
if (cells.length == 1)
{
this.previewElement.style.width = (geo.width * view.scale) + 'px';
this.previewElement.style.height = (geo.height * view.scale) + 'px';
}
2014-10-09 13:52:12 +00:00
}
else
{
this.previewElement.style.width = this.previewElementWidth;
this.previewElement.style.height = this.previewElementHeight;
}
}
};
2012-05-21 20:32:26 +00:00
// Allows drop into cell only if target is a valid root
2014-10-09 13:52:12 +00:00
dragSource.getDropTarget = mxUtils.bind(this, function(graph, x, y, evt)
2012-05-21 20:32:26 +00:00
{
2014-11-10 09:02:21 +00:00
// Alt means no targets at all
2014-10-09 13:52:12 +00:00
// LATER: Show preview where result will go
var cell = (!mxEvent.isAltDown(evt) && cells != null) ? graph.getCellAt(x, y) : null;
var state = graph.view.getState(cell);
activeArrow = null;
var bbox = null;
2014-11-10 09:02:21 +00:00
// Shift means no style targets - containers are ignored to simplify the UX
if (state != null && graph.model.isVertex(state.cell) && !graph.isContainer(state.cell) && firstVertex != null && !mxEvent.isShiftDown(evt))
{
currentStyleTarget = state;
var tmp = new mxRectangle(currentStyleTarget.getCenterX() - this.refreshTarget.width / 2,
currentStyleTarget.getCenterY() - this.refreshTarget.height / 2, this.refreshTarget.width, this.refreshTarget.height);
styleTarget.style.left = Math.floor(tmp.x) + 'px';
styleTarget.style.top = Math.floor(tmp.y) + 'px';
if (styleTarget.parentNode == null)
{
graph.container.appendChild(styleTarget);
}
checkArrow(x, y, tmp, styleTarget);
}
// Does not reset on ignored edges
else if (currentStyleTarget == null || !mxUtils.contains(currentStyleTarget, x, y))
{
currentStyleTarget = null;
if (styleTarget.parentNode != null)
{
styleTarget.parentNode.removeChild(styleTarget);
}
}
else if (currentStyleTarget != null && styleTarget.parentNode != null)
{
// Sets active Arrow as side effect
checkArrow(x, y, new mxRectangle(currentStyleTarget.getCenterX() - this.refreshTarget.width / 2,
currentStyleTarget.getCenterY() - this.refreshTarget.height / 2, this.refreshTarget.width, this.refreshTarget.height),
styleTarget);
}
2012-05-21 20:32:26 +00:00
2014-10-09 13:52:12 +00:00
// Checks if inside bounds
2014-11-10 09:02:21 +00:00
if (activeTarget && currentTargetState != null && !mxEvent.isAltDown(evt) && activeArrow == null)
2014-10-09 13:52:12 +00:00
{
2014-10-30 08:08:05 +00:00
// LATER: Use hit-detection for edges
2014-10-09 13:52:12 +00:00
bbox = mxRectangle.fromRectangle(currentTargetState);
2014-10-30 08:08:05 +00:00
if (graph.model.isEdge(currentTargetState.cell))
{
var pts = currentTargetState.absolutePoints;
if (roundSource.parentNode != null)
{
var p0 = pts[0];
bbox.add(checkArrow(x, y, new mxRectangle(p0.x - this.roundDrop.width / 2,
p0.y - this.roundDrop.height / 2, this.roundDrop.width, this.roundDrop.height), roundSource));
}
if (roundTarget.parentNode != null)
{
var pe = pts[pts.length - 1];
bbox.add(checkArrow(x, y, new mxRectangle(pe.x - this.roundDrop.width / 2,
pe.y - this.roundDrop.height / 2,
this.roundDrop.width, this.roundDrop.height), roundTarget));
}
}
else
{
bbox.add(checkArrow(x, y, new mxRectangle(currentTargetState.getCenterX() - this.triangleUp.width / 2,
currentTargetState.y - this.triangleUp.height - arrowSpacing, this.triangleUp.width, this.triangleUp.height), arrowUp));
bbox.add(checkArrow(x, y, new mxRectangle(currentTargetState.x + currentTargetState.width + arrowSpacing,
currentTargetState.getCenterY() - this.triangleRight.height / 2,
this.triangleRight.width, this.triangleRight.height), arrowRight));
bbox.add(checkArrow(x, y, new mxRectangle(currentTargetState.getCenterX() - this.triangleDown.width / 2,
currentTargetState.y + currentTargetState.height + arrowSpacing,
this.triangleDown.width, this.triangleDown.height), arrowDown));
bbox.add(checkArrow(x, y, new mxRectangle(currentTargetState.x - this.triangleLeft.width - arrowSpacing,
currentTargetState.getCenterY() - this.triangleLeft.height / 2,
this.triangleLeft.width, this.triangleLeft.height), arrowLeft));
}
2014-10-09 13:52:12 +00:00
// Adds tolerance
2014-10-30 08:08:05 +00:00
if (bbox != null)
{
bbox.grow(10);
}
2014-10-09 13:52:12 +00:00
}
direction = mxConstants.DIRECTION_NORTH;
if (activeArrow == arrowRight)
{
direction = mxConstants.DIRECTION_EAST;
}
2014-10-30 08:08:05 +00:00
else if (activeArrow == arrowDown || activeArrow == roundTarget)
2014-10-09 13:52:12 +00:00
{
direction = mxConstants.DIRECTION_SOUTH;
}
else if (activeArrow == arrowLeft)
{
direction = mxConstants.DIRECTION_WEST;
}
2014-11-10 09:02:21 +00:00
if (currentStyleTarget != null && activeArrow == styleTarget)
{
state = currentStyleTarget;
}
2014-10-09 13:52:12 +00:00
if (currentTargetState != state && (bbox == null || !mxUtils.contains(bbox, x, y)))
{
activeTarget = false;
currentTargetState = state;
2014-10-30 08:08:05 +00:00
2014-11-10 09:02:21 +00:00
// Containers could be enabled here but it just makes the UX even more complex
2014-10-30 08:08:05 +00:00
var validTarget = (graph.model.isEdge(cell) && firstVertex != null) || (graph.model.isVertex(cell) &&
graph.isCellConnectable(cell) && !graph.isContainer(cell));
2014-10-09 13:52:12 +00:00
2014-10-30 08:08:05 +00:00
if (currentTargetState != null && validTarget)
2014-10-09 13:52:12 +00:00
{
2014-10-30 08:08:05 +00:00
var elts = [roundSource, roundTarget, arrowUp, arrowRight, arrowDown, arrowLeft];
2014-10-09 13:52:12 +00:00
2014-10-30 08:08:05 +00:00
for (var i = 0; i < elts.length; i++)
{
if (elts[i].parentNode != null)
{
elts[i].parentNode.removeChild(elts[i]);
}
}
2014-10-09 13:52:12 +00:00
2014-10-30 08:08:05 +00:00
if (graph.model.isEdge(cell))
{
var pts = state.absolutePoints;
2014-11-10 09:02:21 +00:00
if (pts != null)
2014-10-30 08:08:05 +00:00
{
2014-11-10 09:02:21 +00:00
var p0 = pts[0];
var pe = pts[pts.length - 1];
var tol = graph.tolerance;
var box = new mxRectangle(x - tol, y - tol, 2 * tol, 2 * tol);
roundSource.style.left = Math.floor(p0.x - this.roundDrop.width / 2) + 'px';
roundSource.style.top = Math.floor(p0.y - this.roundDrop.height / 2) + 'px';
roundTarget.style.left = Math.floor(pe.x - this.roundDrop.width / 2) + 'px';
roundTarget.style.top = Math.floor(pe.y - this.roundDrop.height / 2) + 'px';
if (graph.model.getTerminal(cell, true) == null)
{
graph.container.appendChild(roundSource);
}
if (graph.model.getTerminal(cell, false) == null)
{
graph.container.appendChild(roundTarget);
}
2014-10-30 08:08:05 +00:00
}
}
else
{
arrowUp.style.left = Math.floor(state.getCenterX() - this.triangleUp.width / 2) + 'px';
arrowUp.style.top = Math.floor(state.y - this.triangleUp.height - arrowSpacing) + 'px';
arrowRight.style.left = Math.floor(state.x + state.width + arrowSpacing) + 'px';
arrowRight.style.top = Math.floor(state.getCenterY() - this.triangleRight.height / 2) + 'px';
arrowDown.style.left = arrowUp.style.left
arrowDown.style.top = Math.floor(state.y + state.height + arrowSpacing) + 'px';
arrowLeft.style.left = Math.floor(state.x - this.triangleLeft.width - arrowSpacing) + 'px';
arrowLeft.style.top = arrowRight.style.top;
graph.container.appendChild(arrowUp);
graph.container.appendChild(arrowRight);
graph.container.appendChild(arrowDown);
graph.container.appendChild(arrowLeft);
}
2014-10-09 13:52:12 +00:00
// Hides handle for cell under mouse
if (state != null)
{
currentStateHandle = graph.selectionCellsHandler.getHandler(state.cell);
2014-10-30 08:08:05 +00:00
if (currentStateHandle != null && currentStateHandle.setHandlesVisible != null)
2014-10-09 13:52:12 +00:00
{
2014-10-30 08:08:05 +00:00
currentStateHandle.setHandlesVisible(false);
2014-10-09 13:52:12 +00:00
}
}
activeTarget = true;
}
2014-10-30 08:08:05 +00:00
else
2014-10-09 13:52:12 +00:00
{
2014-10-30 08:08:05 +00:00
var elts = [roundSource, roundTarget, arrowUp, arrowRight, arrowDown, arrowLeft];
for (var i = 0; i < elts.length; i++)
{
if (elts[i].parentNode != null)
{
elts[i].parentNode.removeChild(elts[i]);
}
}
2014-10-09 13:52:12 +00:00
}
}
if (!activeTarget && currentStateHandle != null)
{
2014-10-30 08:08:05 +00:00
currentStateHandle.setHandlesVisible(true);
2014-10-09 13:52:12 +00:00
}
// Handles drop target
2014-11-10 09:02:21 +00:00
var target = (!activeTarget && !mxEvent.isAltDown(evt) && !(currentStyleTarget != null && activeArrow == styleTarget)) ?
mxDragSource.prototype.getDropTarget.apply(this, arguments) : null;
2014-10-09 13:52:12 +00:00
2013-06-28 19:07:06 +00:00
if (target != null)
2012-05-21 20:32:26 +00:00
{
2013-06-28 19:07:06 +00:00
// Selects parent group as drop target
var model = graph.getModel();
if (!graph.isValidRoot(target) && model.isVertex(model.getParent(target)))
{
target = model.getParent(target);
}
2014-05-05 08:30:00 +00:00
if (graph.view.currentRoot == target || (!graph.isValidRoot(target) &&
graph.getModel().getChildCount(target) == 0))
2013-06-28 19:07:06 +00:00
{
target = null;
}
2012-05-21 20:32:26 +00:00
}
return target;
2014-10-09 13:52:12 +00:00
});
dragSource.stopDrag = function()
{
mxDragSource.prototype.stopDrag.apply(this, arguments);
2014-11-10 09:02:21 +00:00
var elts = [roundSource, roundTarget, styleTarget, arrowUp, arrowRight, arrowDown, arrowLeft];
2014-10-09 13:52:12 +00:00
2014-10-30 08:08:05 +00:00
for (var i = 0; i < elts.length; i++)
2014-10-09 13:52:12 +00:00
{
2014-10-30 08:08:05 +00:00
if (elts[i].parentNode != null)
{
elts[i].parentNode.removeChild(elts[i]);
}
2014-10-09 13:52:12 +00:00
}
if (currentTargetState != null && currentStateHandle != null)
{
currentStateHandle.reset();
}
currentStateHandle = null;
currentTargetState = null;
2014-11-10 09:02:21 +00:00
currentStyleTarget = null;
2014-10-09 13:52:12 +00:00
activeArrow = null;
2012-05-21 20:32:26 +00:00
};
return dragSource;
};
/**
* Adds a handler for inserting the cell with a single click.
*/
2014-10-03 12:49:36 +00:00
Sidebar.prototype.itemClicked = function(cells, ds, evt, elt)
2012-05-21 20:32:26 +00:00
{
var graph = this.editorUi.editor.graph;
2014-10-03 12:49:36 +00:00
if (mxEvent.isAltDown(evt))
{
if (!graph.isSelectionEmpty())
{
graph.setSelectionCells(this.updateShapes(cells[0], graph.getSelectionCells()));
}
}
else
{
var gs = graph.getGridSize();
var dx = graph.container.scrollLeft / graph.view.scale - graph.view.translate.x;
var dy = graph.container.scrollTop / graph.view.scale - graph.view.translate.y;
ds.drop(graph, evt, null, graph.snap(dx + gs), graph.snap(dy + gs));
}
2013-05-23 16:14:48 +00:00
};
/**
* Adds a handler for inserting the cell with a single click.
*/
Sidebar.prototype.addClickHandler = function(elt, ds, cells)
{
var graph = this.editorUi.editor.graph;
var oldMouseUp = ds.mouseUp;
2012-05-21 20:32:26 +00:00
var first = null;
2013-05-23 16:14:48 +00:00
mxEvent.addGestureListeners(elt, function(evt)
2012-05-21 20:32:26 +00:00
{
first = new mxPoint(mxEvent.getClientX(evt), mxEvent.getClientY(evt));
});
2013-05-23 16:14:48 +00:00
ds.mouseUp = mxUtils.bind(this, function(evt)
2012-05-21 20:32:26 +00:00
{
if (!mxEvent.isPopupTrigger(evt) && this.currentGraph == null && first != null)
{
var tol = graph.tolerance;
if (Math.abs(first.x - mxEvent.getClientX(evt)) <= tol &&
Math.abs(first.y - mxEvent.getClientY(evt)) <= tol)
{
2014-10-03 12:49:36 +00:00
this.itemClicked(cells, ds, evt, elt);
2012-05-21 20:32:26 +00:00
}
}
2013-05-23 16:14:48 +00:00
oldMouseUp.apply(ds, arguments);
2012-05-21 20:32:26 +00:00
first = null;
2013-05-23 16:14:48 +00:00
// Blocks tooltips on this element after single click
this.currentElt = elt;
});
2012-05-21 20:32:26 +00:00
};
/**
* Creates a drop handler for inserting the given cells.
*/
2014-05-05 08:30:00 +00:00
Sidebar.prototype.createVertexTemplate = function(style, width, height, value, title, showLabel, showTitle)
2012-05-21 20:32:26 +00:00
{
var cells = [new mxCell((value != null) ? value : '', new mxGeometry(0, 0, width, height), style)];
cells[0].vertex = true;
2014-05-05 08:30:00 +00:00
return this.createVertexTemplateFromCells(cells, width, height, title, showLabel, showTitle);
2012-05-21 20:32:26 +00:00
};
/**
* Creates a drop handler for inserting the given cells.
*/
2014-05-05 08:30:00 +00:00
Sidebar.prototype.createVertexTemplateFromCells = function(cells, width, height, title, showLabel, showTitle)
2012-05-21 20:32:26 +00:00
{
2014-05-05 08:30:00 +00:00
return this.createItem(cells, title, showLabel, showTitle, width, height);
2012-05-21 20:32:26 +00:00
};
/**
* Creates a drop handler for inserting the given cells.
*/
2013-05-23 16:14:48 +00:00
Sidebar.prototype.createEdgeTemplate = function(style, width, height, value, title, showLabel)
2012-05-21 20:32:26 +00:00
{
var cells = [new mxCell((value != null) ? value : '', new mxGeometry(0, 0, width, height), style)];
cells[0].geometry.setTerminalPoint(new mxPoint(0, height), true);
cells[0].geometry.setTerminalPoint(new mxPoint(width, 0), false);
2013-05-23 16:14:48 +00:00
cells[0].geometry.relative = true;
2012-05-21 20:32:26 +00:00
cells[0].edge = true;
2013-05-23 16:14:48 +00:00
return this.createEdgeTemplateFromCells(cells, width, height, title, showLabel);
2012-05-21 20:32:26 +00:00
};
/**
* Creates a drop handler for inserting the given cells.
*/
2013-05-23 16:14:48 +00:00
Sidebar.prototype.createEdgeTemplateFromCells = function(cells, width, height, title, showLabel)
2014-05-05 08:30:00 +00:00
{
return this.createItem(cells, title, showLabel, true, width, height);
2012-05-21 20:32:26 +00:00
};
/**
* Adds the given palette.
*/
Sidebar.prototype.addPalette = function(id, title, expanded, onInit)
{
var elt = this.createTitle(title);
this.container.appendChild(elt);
var div = document.createElement('div');
2012-06-14 12:43:20 +00:00
div.className = 'geSidebar';
2012-05-21 20:32:26 +00:00
if (expanded)
{
onInit(div);
onInit = null;
}
else
{
div.style.display = 'none';
}
this.addFoldingHandler(elt, div, onInit);
var outer = document.createElement('div');
outer.appendChild(div);
this.container.appendChild(outer);
// Keeps references to the DOM nodes
if (id != null)
{
this.palettes[id] = [elt, outer];
}
2014-05-05 08:30:00 +00:00
return div;
2012-05-21 20:32:26 +00:00
};
/**
* Create the given title element.
*/
Sidebar.prototype.addFoldingHandler = function(title, content, funct)
{
var initialized = false;
2013-06-28 19:07:06 +00:00
// Avoids mixed content warning in IE6-8
if (!mxClient.IS_IE || document.documentMode >= 8)
{
title.style.backgroundImage = (content.style.display == 'none') ?
'url(' + IMAGE_PATH + '/collapsed.gif)' : 'url(' + IMAGE_PATH + '/expanded.gif)';
}
2012-05-21 20:32:26 +00:00
title.style.backgroundRepeat = 'no-repeat';
2013-05-23 16:14:48 +00:00
title.style.backgroundPosition = '0% 50%';
2012-05-21 20:32:26 +00:00
mxEvent.addListener(title, 'click', function(evt)
{
if (content.style.display == 'none')
{
if (!initialized)
{
initialized = true;
if (funct != null)
{
2013-05-23 16:14:48 +00:00
// Wait cursor does not show up on Mac
title.style.cursor = 'wait';
var prev = title.innerHTML;
title.innerHTML = mxResources.get('loading') + '...';
window.setTimeout(function()
{
funct(content);
title.style.cursor = '';
title.innerHTML = prev;
}, 0);
2012-05-21 20:32:26 +00:00
}
}
title.style.backgroundImage = 'url(' + IMAGE_PATH + '/expanded.gif)';
content.style.display = 'block';
}
else
{
title.style.backgroundImage = 'url(' + IMAGE_PATH + '/collapsed.gif)';
content.style.display = 'none';
}
mxEvent.consume(evt);
});
};
/**
* Removes the palette for the given ID.
*/
Sidebar.prototype.removePalette = function(id)
{
var elts = this.palettes[id];
if (elts != null)
{
this.palettes[id] = null;
for (var i = 0; i < elts.length; i++)
{
this.container.removeChild(elts[i]);
}
return true;
}
return false;
};
/**
* Adds the given image palette.
*/
2013-05-23 16:14:48 +00:00
Sidebar.prototype.addImagePalette = function(id, title, prefix, postfix, items, titles)
2012-05-21 20:32:26 +00:00
{
this.addPalette(id, title, false, mxUtils.bind(this, function(content)
{
2013-05-23 16:14:48 +00:00
var showTitles = titles != null;
2012-05-21 20:32:26 +00:00
for (var i = 0; i < items.length; i++)
{
var icon = prefix + items[i] + postfix;
2014-11-10 09:02:21 +00:00
content.appendChild(this.createVertexTemplate('image;html=1;image=' + icon, 80, 80, '', (showTitles) ? titles[i] : null, showTitles));
2012-05-21 20:32:26 +00:00
}
}));
};
/**
* Adds the given stencil palette.
*/
Sidebar.prototype.addStencilPalette = function(id, title, stencilFile, style, ignore, onInit, scale)
{
scale = (scale != null) ? scale : 1;
this.addPalette(id, title, false, mxUtils.bind(this, function(content)
{
if (style == null)
{
style = '';
}
if (onInit != null)
{
onInit.call(this, content);
}
mxStencilRegistry.loadStencilSet(stencilFile, mxUtils.bind(this, function(packageName, stencilName, displayName, w, h)
{
if (ignore == null || mxUtils.indexOf(ignore, stencilName) < 0)
{
content.appendChild(this.createVertexTemplate('shape=' + packageName + stencilName.toLowerCase() + style,
2013-05-23 16:14:48 +00:00
Math.round(w * scale), Math.round(h * scale), '', stencilName.replace(/_/g, ' '), true));
2012-05-21 20:32:26 +00:00
}
}), true);
}));
};