123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507 |
- /**
- * Copyright (c) 2006-2015, JGraph Ltd
- * Copyright (c) 2006-2015, Gaudenz Alder
- */
- /**
- * Class: mxSwimlane
- *
- * Extends <mxShape> to implement a swimlane shape. This shape is registered
- * under <mxConstants.SHAPE_SWIMLANE> in <mxCellRenderer>. Use the
- * <mxConstants.STYLE_STYLE_STARTSIZE> to define the size of the title
- * region, <mxConstants.STYLE_SWIMLANE_FILLCOLOR> for the content area fill,
- * <mxConstants.STYLE_SEPARATORCOLOR> to draw an additional vertical separator
- * and <mxConstants.STYLE_SWIMLANE_LINE> to hide the line between the title
- * region and the content area. The <mxConstants.STYLE_HORIZONTAL> affects
- * the orientation of this shape, not only its label.
- *
- * Constructor: mxSwimlane
- *
- * Constructs a new swimlane shape.
- *
- * Parameters:
- *
- * bounds - <mxRectangle> that defines the bounds. This is stored in
- * <mxShape.bounds>.
- * fill - String that defines the fill color. This is stored in <fill>.
- * stroke - String that defines the stroke color. This is stored in <stroke>.
- * strokewidth - Optional integer that defines the stroke width. Default is
- * 1. This is stored in <strokewidth>.
- */
- function mxSwimlane(bounds, fill, stroke, strokewidth)
- {
- mxShape.call(this);
- this.bounds = bounds;
- this.fill = fill;
- this.stroke = stroke;
- this.strokewidth = (strokewidth != null) ? strokewidth : 1;
- };
- /**
- * Extends mxShape.
- */
- mxUtils.extend(mxSwimlane, mxShape);
- /**
- * Variable: imageSize
- *
- * Default imagewidth and imageheight if an image but no imagewidth
- * and imageheight are defined in the style. Value is 16.
- */
- mxSwimlane.prototype.imageSize = 16;
- /**
- * Function: isRoundable
- *
- * Adds roundable support.
- */
- mxSwimlane.prototype.isRoundable = function(c, x, y, w, h)
- {
- return true;
- };
- /**
- * Function: getTitleSize
- *
- * Returns the title size.
- */
- mxSwimlane.prototype.getTitleSize = function()
- {
- return Math.max(0, mxUtils.getValue(this.style, mxConstants.STYLE_STARTSIZE, mxConstants.DEFAULT_STARTSIZE));
- };
- /**
- * Function: getLabelBounds
- *
- * Returns the bounding box for the label.
- */
- mxSwimlane.prototype.getLabelBounds = function(rect)
- {
- var start = this.getTitleSize();
- var bounds = new mxRectangle(rect.x, rect.y, rect.width, rect.height);
- var horizontal = this.isHorizontal();
-
- var flipH = mxUtils.getValue(this.style, mxConstants.STYLE_FLIPH, 0) == 1;
- var flipV = mxUtils.getValue(this.style, mxConstants.STYLE_FLIPV, 0) == 1;
-
- // East is default
- var shapeVertical = (this.direction == mxConstants.DIRECTION_NORTH ||
- this.direction == mxConstants.DIRECTION_SOUTH);
- var realHorizontal = horizontal == !shapeVertical;
-
- var realFlipH = !realHorizontal && flipH != (this.direction == mxConstants.DIRECTION_SOUTH ||
- this.direction == mxConstants.DIRECTION_WEST);
- var realFlipV = realHorizontal && flipV != (this.direction == mxConstants.DIRECTION_SOUTH ||
- this.direction == mxConstants.DIRECTION_WEST);
- // Shape is horizontal
- if (!shapeVertical)
- {
- var tmp = Math.min(bounds.height, start * this.scale);
- if (realFlipH || realFlipV)
- {
- bounds.y += bounds.height - tmp;
- }
- bounds.height = tmp;
- }
- else
- {
- var tmp = Math.min(bounds.width, start * this.scale);
-
- if (realFlipH || realFlipV)
- {
- bounds.x += bounds.width - tmp;
- }
- bounds.width = tmp;
- }
-
- return bounds;
- };
- /**
- * Function: getGradientBounds
- *
- * Returns the bounding box for the gradient box for this shape.
- */
- mxSwimlane.prototype.getGradientBounds = function(c, x, y, w, h)
- {
- var start = this.getTitleSize();
-
- if (this.isHorizontal())
- {
- start = Math.min(start, h);
- return new mxRectangle(x, y, w, start);
- }
- else
- {
- start = Math.min(start, w);
- return new mxRectangle(x, y, start, h);
- }
- };
- /**
- * Function: getSwimlaneArcSize
- *
- * Returns the arcsize for the swimlane.
- */
- mxSwimlane.prototype.getSwimlaneArcSize = function(w, h, start)
- {
- if (mxUtils.getValue(this.style, mxConstants.STYLE_ABSOLUTE_ARCSIZE, 0) == '1')
- {
- return Math.min(w / 2, Math.min(h / 2, mxUtils.getValue(this.style,
- mxConstants.STYLE_ARCSIZE, mxConstants.LINE_ARCSIZE) / 2));
- }
- else
- {
- var f = mxUtils.getValue(this.style, mxConstants.STYLE_ARCSIZE, mxConstants.RECTANGLE_ROUNDING_FACTOR * 100) / 100;
- return start * f * 3;
- }
- };
- /**
- * Function: isHorizontal
- *
- * Paints the swimlane vertex shape.
- */
- mxSwimlane.prototype.isHorizontal = function()
- {
- return mxUtils.getValue(this.style, mxConstants.STYLE_HORIZONTAL, 1) == 1;
- };
- /**
- * Function: paintVertexShape
- *
- * Paints the swimlane vertex shape.
- */
- mxSwimlane.prototype.paintVertexShape = function(c, x, y, w, h)
- {
- var start = this.getTitleSize();
- var fill = mxUtils.getValue(this.style, mxConstants.STYLE_SWIMLANE_FILLCOLOR, mxConstants.NONE);
- var swimlaneLine = mxUtils.getValue(this.style, mxConstants.STYLE_SWIMLANE_LINE, 1) == 1;
- var r = 0;
-
- if (this.isHorizontal())
- {
- start = Math.min(start, h);
- }
- else
- {
- start = Math.min(start, w);
- }
-
- c.translate(x, y);
-
- if (!this.isRounded)
- {
- this.paintSwimlane(c, x, y, w, h, start, fill, swimlaneLine);
- }
- else
- {
- r = this.getSwimlaneArcSize(w, h, start);
- r = Math.min(((this.isHorizontal()) ? h : w) - start, Math.min(start, r));
- this.paintRoundedSwimlane(c, x, y, w, h, start, r, fill, swimlaneLine);
- }
-
- var sep = mxUtils.getValue(this.style, mxConstants.STYLE_SEPARATORCOLOR, mxConstants.NONE);
- this.paintSeparator(c, x, y, w, h, start, sep);
- if (this.image != null)
- {
- var bounds = this.getImageBounds(x, y, w, h);
- c.image(bounds.x - x, bounds.y - y, bounds.width, bounds.height,
- this.image, false, false, false);
- }
-
- if (this.glass)
- {
- c.setShadow(false);
- this.paintGlassEffect(c, 0, 0, w, start, r);
- }
- };
- /**
- * Function: paintSwimlane
- *
- * Paints the swimlane vertex shape.
- */
- mxSwimlane.prototype.paintSwimlane = function(c, x, y, w, h, start, fill, swimlaneLine)
- {
- c.begin();
-
- var events = true;
-
- if (this.style != null)
- {
- events = mxUtils.getValue(this.style, mxConstants.STYLE_POINTER_EVENTS, '1') == '1';
- }
-
- if (!events && (this.fill == null || this.fill == mxConstants.NONE))
- {
- c.pointerEvents = false;
- }
-
- if (this.isHorizontal())
- {
- c.moveTo(0, start);
- c.lineTo(0, 0);
- c.lineTo(w, 0);
- c.lineTo(w, start);
- c.fillAndStroke();
- if (start < h)
- {
- if (fill == mxConstants.NONE || !events)
- {
- c.pointerEvents = false;
- }
-
- if (fill != mxConstants.NONE)
- {
- c.setFillColor(fill);
- }
-
- c.begin();
- c.moveTo(0, start);
- c.lineTo(0, h);
- c.lineTo(w, h);
- c.lineTo(w, start);
-
- if (fill == mxConstants.NONE)
- {
- c.stroke();
- }
- else
- {
- c.fillAndStroke();
- }
- }
- }
- else
- {
- c.moveTo(start, 0);
- c.lineTo(0, 0);
- c.lineTo(0, h);
- c.lineTo(start, h);
- c.fillAndStroke();
-
- if (start < w)
- {
- if (fill == mxConstants.NONE || !events)
- {
- c.pointerEvents = false;
- }
-
- if (fill != mxConstants.NONE)
- {
- c.setFillColor(fill);
- }
-
- c.begin();
- c.moveTo(start, 0);
- c.lineTo(w, 0);
- c.lineTo(w, h);
- c.lineTo(start, h);
-
- if (fill == mxConstants.NONE)
- {
- c.stroke();
- }
- else
- {
- c.fillAndStroke();
- }
- }
- }
-
- if (swimlaneLine)
- {
- this.paintDivider(c, x, y, w, h, start, fill == mxConstants.NONE);
- }
- };
- /**
- * Function: paintRoundedSwimlane
- *
- * Paints the swimlane vertex shape.
- */
- mxSwimlane.prototype.paintRoundedSwimlane = function(c, x, y, w, h, start, r, fill, swimlaneLine)
- {
- c.begin();
-
- var events = true;
-
- if (this.style != null)
- {
- events = mxUtils.getValue(this.style, mxConstants.STYLE_POINTER_EVENTS, '1') == '1';
- }
-
- if (!events && (this.fill == null || this.fill == mxConstants.NONE))
- {
- c.pointerEvents = false;
- }
-
- if (this.isHorizontal())
- {
- c.moveTo(w, start);
- c.lineTo(w, r);
- c.quadTo(w, 0, w - Math.min(w / 2, r), 0);
- c.lineTo(Math.min(w / 2, r), 0);
- c.quadTo(0, 0, 0, r);
- c.lineTo(0, start);
- c.fillAndStroke();
-
- if (start < h)
- {
- if (fill == mxConstants.NONE || !events)
- {
- c.pointerEvents = false;
- }
-
- if (fill != mxConstants.NONE)
- {
- c.setFillColor(fill);
- }
-
- c.begin();
- c.moveTo(0, start);
- c.lineTo(0, h - r);
- c.quadTo(0, h, Math.min(w / 2, r), h);
- c.lineTo(w - Math.min(w / 2, r), h);
- c.quadTo(w, h, w, h - r);
- c.lineTo(w, start);
-
- if (fill == mxConstants.NONE)
- {
- c.stroke();
- }
- else
- {
- c.fillAndStroke();
- }
- }
- }
- else
- {
- c.moveTo(start, 0);
- c.lineTo(r, 0);
- c.quadTo(0, 0, 0, Math.min(h / 2, r));
- c.lineTo(0, h - Math.min(h / 2, r));
- c.quadTo(0, h, r, h);
- c.lineTo(start, h);
- c.fillAndStroke();
- if (start < w)
- {
- if (fill == mxConstants.NONE || !events)
- {
- c.pointerEvents = false;
- }
-
- if (fill != mxConstants.NONE)
- {
- c.setFillColor(fill);
- }
-
- c.begin();
- c.moveTo(start, h);
- c.lineTo(w - r, h);
- c.quadTo(w, h, w, h - Math.min(h / 2, r));
- c.lineTo(w, Math.min(h / 2, r));
- c.quadTo(w, 0, w - r, 0);
- c.lineTo(start, 0);
-
- if (fill == mxConstants.NONE)
- {
- c.stroke();
- }
- else
- {
- c.fillAndStroke();
- }
- }
- }
- if (swimlaneLine)
- {
- this.paintDivider(c, x, y, w, h, start, fill == mxConstants.NONE);
- }
- };
- /**
- * Function: paintDivider
- *
- * Paints the divider between swimlane title and content area.
- */
- mxSwimlane.prototype.paintDivider = function(c, x, y, w, h, start, shadow)
- {
- if (!shadow)
- {
- c.setShadow(false);
- }
- c.begin();
-
- if (this.isHorizontal())
- {
- c.moveTo(0, start);
- c.lineTo(w, start);
- }
- else
- {
- c.moveTo(start, 0);
- c.lineTo(start, h);
- }
- c.stroke();
- };
- /**
- * Function: paintSeparator
- *
- * Paints the vertical or horizontal separator line between swimlanes.
- */
- mxSwimlane.prototype.paintSeparator = function(c, x, y, w, h, start, color)
- {
- if (color != mxConstants.NONE)
- {
- c.setStrokeColor(color);
- c.setDashed(true);
- c.begin();
-
- if (this.isHorizontal())
- {
- c.moveTo(w, start);
- c.lineTo(w, h);
- }
- else
- {
- c.moveTo(start, 0);
- c.lineTo(w, 0);
- }
-
- c.stroke();
- c.setDashed(false);
- }
- };
- /**
- * Function: getImageBounds
- *
- * Paints the swimlane vertex shape.
- */
- mxSwimlane.prototype.getImageBounds = function(x, y, w, h)
- {
- if (this.isHorizontal())
- {
- return new mxRectangle(x + w - this.imageSize, y, this.imageSize, this.imageSize);
- }
- else
- {
- return new mxRectangle(x, y, this.imageSize, this.imageSize);
- }
- };
- __mxOutput.mxSwimlane = typeof mxSwimlane !== 'undefined' ? mxSwimlane : undefined;
|