mirror of
https://github.com/mermaid-js/mermaid.git
synced 2025-09-15 13:29:40 +02:00
added sequence numbers
This commit is contained in:
@@ -33,7 +33,9 @@ const conf = {
|
|||||||
activationWidth: 10,
|
activationWidth: 10,
|
||||||
|
|
||||||
// text placement as: tspan | fo | old only text as before
|
// text placement as: tspan | fo | old only text as before
|
||||||
textPlacement: 'tspan'
|
textPlacement: 'tspan',
|
||||||
|
|
||||||
|
showSequenceNumbers: false
|
||||||
}
|
}
|
||||||
|
|
||||||
export const bounds = {
|
export const bounds = {
|
||||||
@@ -203,7 +205,7 @@ const drawNote = function (elem, startx, verticalPos, msg, forceWidth) {
|
|||||||
* @param txtCenter
|
* @param txtCenter
|
||||||
* @param msg
|
* @param msg
|
||||||
*/
|
*/
|
||||||
const drawMessage = function (elem, startx, stopx, verticalPos, msg) {
|
const drawMessage = function (elem, startx, stopx, verticalPos, msg, nodeIndex) {
|
||||||
const g = elem.append('g')
|
const g = elem.append('g')
|
||||||
const txtCenter = startx + (stopx - startx) / 2
|
const txtCenter = startx + (stopx - startx) / 2
|
||||||
|
|
||||||
@@ -259,6 +261,18 @@ const drawMessage = function (elem, startx, stopx, verticalPos, msg) {
|
|||||||
if (msg.type === parser.yy.LINETYPE.SOLID_CROSS || msg.type === parser.yy.LINETYPE.DOTTED_CROSS) {
|
if (msg.type === parser.yy.LINETYPE.SOLID_CROSS || msg.type === parser.yy.LINETYPE.DOTTED_CROSS) {
|
||||||
line.attr('marker-end', 'url(' + url + '#crosshead)')
|
line.attr('marker-end', 'url(' + url + '#crosshead)')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// add node number
|
||||||
|
if (conf.showSequenceNumbers) {
|
||||||
|
line.attr('marker-start', 'url(' + url + '#nodenumber)')
|
||||||
|
g.append('text')
|
||||||
|
.attr('x', startx - 4)
|
||||||
|
.attr('y', verticalPos + 5)
|
||||||
|
.attr('font-family', 'sans-serif')
|
||||||
|
.attr('font-size', '16px')
|
||||||
|
.attr('class', 'nodeNumber')
|
||||||
|
.text(nodeIndex + 1)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export const drawActors = function (diagram, actors, actorKeys, verticalPos) {
|
export const drawActors = function (diagram, actors, actorKeys, verticalPos) {
|
||||||
@@ -331,6 +345,7 @@ export const draw = function (text, id) {
|
|||||||
// The arrow head definition is attached to the svg once
|
// The arrow head definition is attached to the svg once
|
||||||
svgDraw.insertArrowHead(diagram)
|
svgDraw.insertArrowHead(diagram)
|
||||||
svgDraw.insertArrowCrossHead(diagram)
|
svgDraw.insertArrowCrossHead(diagram)
|
||||||
|
svgDraw.insertNodeNumber(diagram)
|
||||||
|
|
||||||
function activeEnd (msg, verticalPos) {
|
function activeEnd (msg, verticalPos) {
|
||||||
const activationData = bounds.endActivation(msg)
|
const activationData = bounds.endActivation(msg)
|
||||||
@@ -346,7 +361,7 @@ export const draw = function (text, id) {
|
|||||||
// const lastMsg
|
// const lastMsg
|
||||||
|
|
||||||
// Draw the messages/signals
|
// Draw the messages/signals
|
||||||
messages.forEach(function (msg) {
|
messages.forEach(function (msg, nodeIndex) {
|
||||||
let loopData
|
let loopData
|
||||||
switch (msg.type) {
|
switch (msg.type) {
|
||||||
case parser.yy.LINETYPE.NOTE:
|
case parser.yy.LINETYPE.NOTE:
|
||||||
@@ -440,7 +455,7 @@ export const draw = function (text, id) {
|
|||||||
stopx = toBounds[toIdx]
|
stopx = toBounds[toIdx]
|
||||||
|
|
||||||
const verticalPos = bounds.getVerticalPos()
|
const verticalPos = bounds.getVerticalPos()
|
||||||
drawMessage(diagram, startx, stopx, verticalPos, msg)
|
drawMessage(diagram, startx, stopx, verticalPos, msg, nodeIndex)
|
||||||
const allBounds = fromBounds.concat(toBounds)
|
const allBounds = fromBounds.concat(toBounds)
|
||||||
bounds.insert(Math.min.apply(null, allBounds), verticalPos, Math.max.apply(null, allBounds), verticalPos)
|
bounds.insert(Math.min.apply(null, allBounds), verticalPos, Math.max.apply(null, allBounds), verticalPos)
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
@@ -181,6 +181,23 @@ export const insertArrowHead = function (elem) {
|
|||||||
.append('path')
|
.append('path')
|
||||||
.attr('d', 'M 0,0 V 4 L6,2 Z') // this is actual shape for arrowhead
|
.attr('d', 'M 0,0 V 4 L6,2 Z') // this is actual shape for arrowhead
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* Setup node number. The result is appended to the svg.
|
||||||
|
*/
|
||||||
|
export const insertNodeNumber = function (elem) {
|
||||||
|
elem.append('defs').append('marker')
|
||||||
|
.attr('id', 'nodenumber')
|
||||||
|
.attr('refX', 15)
|
||||||
|
.attr('refY', 15)
|
||||||
|
.attr('markerWidth', 60)
|
||||||
|
.attr('markerHeight', 40)
|
||||||
|
.attr('orient', 'auto')
|
||||||
|
.append('circle')
|
||||||
|
.attr('cx', 15)
|
||||||
|
.attr('cy', 15)
|
||||||
|
.attr('r', 10)
|
||||||
|
// .style("fill", '#f00');
|
||||||
|
}
|
||||||
/**
|
/**
|
||||||
* Setup arrow head and define the marker. The result is appended to the svg.
|
* Setup arrow head and define the marker. The result is appended to the svg.
|
||||||
*/
|
*/
|
||||||
@@ -307,6 +324,7 @@ export default {
|
|||||||
drawActivation,
|
drawActivation,
|
||||||
drawLoop,
|
drawLoop,
|
||||||
insertArrowHead,
|
insertArrowHead,
|
||||||
|
insertNodeNumber,
|
||||||
insertArrowCrossHead,
|
insertArrowCrossHead,
|
||||||
getTextObj,
|
getTextObj,
|
||||||
getNoteRect
|
getNoteRect
|
||||||
|
@@ -153,7 +153,13 @@ const config = {
|
|||||||
* **useMaxWidth** - when this flag is set the height and width is set to 100% and is then scaling with the
|
* **useMaxWidth** - when this flag is set the height and width is set to 100% and is then scaling with the
|
||||||
* available space if not the absolute space required is used
|
* available space if not the absolute space required is used
|
||||||
*/
|
*/
|
||||||
useMaxWidth: true
|
useMaxWidth: true,
|
||||||
|
|
||||||
|
/**
|
||||||
|
* **showSequenceNumbers** - this will show the node numbers
|
||||||
|
*/
|
||||||
|
showSequenceNumbers: false
|
||||||
|
|
||||||
},
|
},
|
||||||
|
|
||||||
/** ### gantt
|
/** ### gantt
|
||||||
|
@@ -30,6 +30,7 @@ $labelBoxBorderColor: $actorBorder;
|
|||||||
$labelTextColor: $mainContrastColor;
|
$labelTextColor: $mainContrastColor;
|
||||||
$noteBorderColor: $border2;
|
$noteBorderColor: $border2;
|
||||||
$noteBkgColor: #fff5ad;
|
$noteBkgColor: #fff5ad;
|
||||||
|
$nodeNumberColor: white;
|
||||||
|
|
||||||
/* Gantt chart variables */
|
/* Gantt chart variables */
|
||||||
|
|
||||||
|
@@ -28,6 +28,7 @@ $labelBoxBorderColor: $actorBorder;
|
|||||||
$labelTextColor: $actorTextColor;
|
$labelTextColor: $actorTextColor;
|
||||||
$noteBorderColor: $border2;
|
$noteBorderColor: $border2;
|
||||||
$noteBkgColor: #fff5ad;
|
$noteBkgColor: #fff5ad;
|
||||||
|
$nodeNumberColor: white;
|
||||||
|
|
||||||
/* Gantt chart variables */
|
/* Gantt chart variables */
|
||||||
|
|
||||||
|
@@ -29,6 +29,7 @@ $labelBoxBorderColor: #326932;
|
|||||||
$labelTextColor: $actorTextColor;
|
$labelTextColor: $actorTextColor;
|
||||||
$noteBorderColor: $border2;
|
$noteBorderColor: $border2;
|
||||||
$noteBkgColor: #fff5ad;
|
$noteBkgColor: #fff5ad;
|
||||||
|
$nodeNumberColor: white;
|
||||||
|
|
||||||
/* Gantt chart variables */
|
/* Gantt chart variables */
|
||||||
|
|
||||||
|
@@ -33,6 +33,7 @@ $labelBoxBorderColor: $actorBorder;
|
|||||||
$labelTextColor: white;
|
$labelTextColor: white;
|
||||||
$noteBorderColor: darken($note, 60%);
|
$noteBorderColor: darken($note, 60%);
|
||||||
$noteBkgColor: $note;
|
$noteBkgColor: $note;
|
||||||
|
$nodeNumberColor: white;
|
||||||
|
|
||||||
/* Gantt chart variables */
|
/* Gantt chart variables */
|
||||||
|
|
||||||
|
@@ -29,6 +29,14 @@ text.actor {
|
|||||||
fill: $signalColor;
|
fill: $signalColor;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.nodeNumber {
|
||||||
|
fill: $nodeNumberColor;
|
||||||
|
}
|
||||||
|
|
||||||
|
#nodenumber {
|
||||||
|
fill: $signalColor;
|
||||||
|
}
|
||||||
|
|
||||||
#crosshead path {
|
#crosshead path {
|
||||||
fill: $signalColor !important;
|
fill: $signalColor !important;
|
||||||
stroke: $signalColor !important;
|
stroke: $signalColor !important;
|
||||||
|
Reference in New Issue
Block a user