diff --git a/d2layouts/d2sequence/constants.go b/d2layouts/d2sequence/constants.go index 676eb3d73..a64394d6e 100644 --- a/d2layouts/d2sequence/constants.go +++ b/d2layouts/d2sequence/constants.go @@ -6,7 +6,7 @@ const HORIZONTAL_PAD = 50. // leaves at least 25 units of space on the top/bottom when computing the space required between messages const VERTICAL_PAD = 50. -const MIN_ACTOR_DISTANCE = 250. +const MIN_ACTOR_DISTANCE = 70. const MIN_ACTOR_WIDTH = 150. diff --git a/d2layouts/d2sequence/sequence_diagram.go b/d2layouts/d2sequence/sequence_diagram.go index 3df170756..359109b47 100644 --- a/d2layouts/d2sequence/sequence_diagram.go +++ b/d2layouts/d2sequence/sequence_diagram.go @@ -33,7 +33,6 @@ type sequenceDiagram struct { lastMessage map[*d2graph.Object]*d2graph.Edge yStep float64 - actorXStep float64 maxActorHeight float64 verticalIndices map[string]int @@ -140,7 +139,6 @@ func newSequenceDiagram(objects []*d2graph.Object, messages []*d2graph.Edge) *se firstMessage: make(map[*d2graph.Object]*d2graph.Edge), lastMessage: make(map[*d2graph.Object]*d2graph.Edge), yStep: MIN_MESSAGE_DISTANCE, - actorXStep: MIN_ACTOR_DISTANCE, maxActorHeight: 0., verticalIndices: make(map[string]int), } @@ -189,15 +187,6 @@ func newSequenceDiagram(objects []*d2graph.Object, messages []*d2graph.Edge) *se sd.verticalIndices[message.AbsID()] = getEdgeEarliestLineNum(message) sd.yStep = math.Max(sd.yStep, float64(message.LabelDimensions.Height)) - // ensures that long labels, spanning over multiple actors, don't make for large gaps between actors - // by distributing the label length across the actors rank difference - rankDiff := math.Abs(float64(sd.objectRank[message.Src]) - float64(sd.objectRank[message.Dst])) - if rankDiff != 0 { - // rankDiff = 0 for self edges - distributedLabelWidth := float64(message.LabelDimensions.Width) / rankDiff - sd.actorXStep = math.Max(sd.actorXStep, distributedLabelWidth+HORIZONTAL_PAD) - - } sd.lastMessage[message.Src] = message if _, exists := sd.firstMessage[message.Src]; !exists { sd.firstMessage[message.Src] = message @@ -304,7 +293,7 @@ func (sd *sequenceDiagram) placeActors() { yOffset = sd.maxActorHeight - actor.Height } actor.TopLeft = geo.NewPoint(x, yOffset) - x += actor.Width + sd.actorXStep + x += actor.Width + MIN_ACTOR_DISTANCE } } diff --git a/e2etests/testdata/stable/sequence_diagram_all_shapes/dagre/board.exp.json b/e2etests/testdata/stable/sequence_diagram_all_shapes/dagre/board.exp.json index 32da45631..5de39d535 100644 --- a/e2etests/testdata/stable/sequence_diagram_all_shapes/dagre/board.exp.json +++ b/e2etests/testdata/stable/sequence_diagram_all_shapes/dagre/board.exp.json @@ -44,7 +44,7 @@ "id": "b", "type": "oval", "pos": { - "x": 410, + "x": 223, "y": 84 }, "width": 150, @@ -83,7 +83,7 @@ "id": "c", "type": "class", "pos": { - "x": 817, + "x": 443, "y": 50 }, "width": 241, @@ -133,7 +133,7 @@ "id": "d", "type": "cloud", "pos": { - "x": 1315, + "x": 754, "y": 108 }, "width": 179, @@ -172,7 +172,7 @@ "id": "e", "type": "code", "pos": { - "x": 1751, + "x": 1003, "y": 164 }, "width": 196, @@ -211,7 +211,7 @@ "id": "f", "type": "cylinder", "pos": { - "x": 2204, + "x": 1269, "y": 84 }, "width": 150, @@ -250,7 +250,7 @@ "id": "g", "type": "diamond", "pos": { - "x": 2611, + "x": 1489, "y": 85 }, "width": 150, @@ -289,7 +289,7 @@ "id": "h", "type": "document", "pos": { - "x": 3018, + "x": 1709, "y": 97 }, "width": 150, @@ -328,7 +328,7 @@ "id": "i", "type": "hexagon", "pos": { - "x": 3425, + "x": 1929, "y": 108 }, "width": 182, @@ -367,7 +367,7 @@ "id": "j", "type": "image", "pos": { - "x": 3864, + "x": 2181, "y": 63 }, "width": 150, @@ -417,7 +417,7 @@ "id": "k", "type": "oval", "pos": { - "x": 4271, + "x": 2401, "y": 97 }, "width": 150, @@ -456,7 +456,7 @@ "id": "l", "type": "package", "pos": { - "x": 4678, + "x": 2621, "y": 98 }, "width": 150, @@ -495,7 +495,7 @@ "id": "m", "type": "page", "pos": { - "x": 5085, + "x": 2841, "y": 108 }, "width": 175, @@ -534,7 +534,7 @@ "id": "n", "type": "parallelogram", "pos": { - "x": 5517, + "x": 3086, "y": 92 }, "width": 183, @@ -573,7 +573,7 @@ "id": "o", "type": "person", "pos": { - "x": 5957, + "x": 3339, "y": 55 }, "width": 154, @@ -612,7 +612,7 @@ "id": "p", "type": "queue", "pos": { - "x": 6368, + "x": 3563, "y": 108 }, "width": 161, @@ -651,7 +651,7 @@ "id": "q", "type": "rectangle", "pos": { - "x": 6786, + "x": 3794, "y": 69 }, "width": 165, @@ -690,7 +690,7 @@ "id": "r", "type": "step", "pos": { - "x": 7208, + "x": 4029, "y": 108 }, "width": 213, @@ -729,7 +729,7 @@ "id": "s", "type": "stored_data", "pos": { - "x": 7678, + "x": 4312, "y": 96 }, "width": 150, @@ -768,7 +768,7 @@ "id": "t", "type": "sql_table", "pos": { - "x": 8085, + "x": 4532, "y": 126 }, "width": 210, @@ -848,7 +848,7 @@ "y": 364 }, { - "x": 485, + "x": 298, "y": 364 } ], @@ -883,11 +883,11 @@ "labelPercentage": 0, "route": [ { - "x": 485, + "x": 298, "y": 494 }, { - "x": 937.5, + "x": 563.5, "y": 494 } ], @@ -922,11 +922,11 @@ "labelPercentage": 0, "route": [ { - "x": 937.5, + "x": 563.5, "y": 624 }, { - "x": 1404.5, + "x": 843.5, "y": 624 } ], @@ -961,11 +961,11 @@ "labelPercentage": 0, "route": [ { - "x": 1404.5, + "x": 843.5, "y": 754 }, { - "x": 1849, + "x": 1101, "y": 754 } ], @@ -1000,11 +1000,11 @@ "labelPercentage": 0, "route": [ { - "x": 1849, + "x": 1101, "y": 884 }, { - "x": 2279, + "x": 1344, "y": 884 } ], @@ -1039,11 +1039,11 @@ "labelPercentage": 0, "route": [ { - "x": 2279, + "x": 1344, "y": 1014 }, { - "x": 2686, + "x": 1564, "y": 1014 } ], @@ -1078,11 +1078,11 @@ "labelPercentage": 0, "route": [ { - "x": 2686, + "x": 1564, "y": 1144 }, { - "x": 3093, + "x": 1784, "y": 1144 } ], @@ -1117,11 +1117,11 @@ "labelPercentage": 0, "route": [ { - "x": 3093, + "x": 1784, "y": 1274 }, { - "x": 3516, + "x": 2020, "y": 1274 } ], @@ -1156,11 +1156,11 @@ "labelPercentage": 0, "route": [ { - "x": 3516, + "x": 2020, "y": 1404 }, { - "x": 3939, + "x": 2256, "y": 1404 } ], @@ -1195,11 +1195,11 @@ "labelPercentage": 0, "route": [ { - "x": 3939, + "x": 2256, "y": 1534 }, { - "x": 4346, + "x": 2476, "y": 1534 } ], @@ -1234,11 +1234,11 @@ "labelPercentage": 0, "route": [ { - "x": 4346, + "x": 2476, "y": 1664 }, { - "x": 4753, + "x": 2696, "y": 1664 } ], @@ -1273,11 +1273,11 @@ "labelPercentage": 0, "route": [ { - "x": 4753, + "x": 2696, "y": 1794 }, { - "x": 5172.5, + "x": 2928.5, "y": 1794 } ], @@ -1312,11 +1312,11 @@ "labelPercentage": 0, "route": [ { - "x": 5172.5, + "x": 2928.5, "y": 1924 }, { - "x": 5608.5, + "x": 3177.5, "y": 1924 } ], @@ -1351,11 +1351,11 @@ "labelPercentage": 0, "route": [ { - "x": 5608.5, + "x": 3177.5, "y": 2054 }, { - "x": 6034, + "x": 3416, "y": 2054 } ], @@ -1390,11 +1390,11 @@ "labelPercentage": 0, "route": [ { - "x": 6034, + "x": 3416, "y": 2184 }, { - "x": 6448.5, + "x": 3643.5, "y": 2184 } ], @@ -1429,11 +1429,11 @@ "labelPercentage": 0, "route": [ { - "x": 6448.5, + "x": 3643.5, "y": 2314 }, { - "x": 6868.5, + "x": 3876.5, "y": 2314 } ], @@ -1468,11 +1468,11 @@ "labelPercentage": 0, "route": [ { - "x": 6868.5, + "x": 3876.5, "y": 2444 }, { - "x": 7314.5, + "x": 4135.5, "y": 2444 } ], @@ -1507,11 +1507,11 @@ "labelPercentage": 0, "route": [ { - "x": 7314.5, + "x": 4135.5, "y": 2574 }, { - "x": 7753, + "x": 4387, "y": 2574 } ], @@ -1546,11 +1546,11 @@ "labelPercentage": 0, "route": [ { - "x": 7753, + "x": 4387, "y": 2704 }, { - "x": 8190, + "x": 4637, "y": 2704 } ], @@ -1624,11 +1624,11 @@ "labelPercentage": 0, "route": [ { - "x": 485, + "x": 298, "y": 234 }, { - "x": 485, + "x": 298, "y": 2834 } ], @@ -1663,11 +1663,11 @@ "labelPercentage": 0, "route": [ { - "x": 937.5, + "x": 563.5, "y": 234 }, { - "x": 937.5, + "x": 563.5, "y": 2834 } ], @@ -1702,11 +1702,11 @@ "labelPercentage": 0, "route": [ { - "x": 1404.5, + "x": 843.5, "y": 234 }, { - "x": 1404.5, + "x": 843.5, "y": 2834 } ], @@ -1741,11 +1741,11 @@ "labelPercentage": 0, "route": [ { - "x": 1849, + "x": 1101, "y": 234 }, { - "x": 1849, + "x": 1101, "y": 2834 } ], @@ -1780,11 +1780,11 @@ "labelPercentage": 0, "route": [ { - "x": 2279, + "x": 1344, "y": 234 }, { - "x": 2279, + "x": 1344, "y": 2834 } ], @@ -1819,11 +1819,11 @@ "labelPercentage": 0, "route": [ { - "x": 2686, + "x": 1564, "y": 234 }, { - "x": 2686, + "x": 1564, "y": 2834 } ], @@ -1858,11 +1858,11 @@ "labelPercentage": 0, "route": [ { - "x": 3093, + "x": 1784, "y": 234 }, { - "x": 3093, + "x": 1784, "y": 2834 } ], @@ -1897,11 +1897,11 @@ "labelPercentage": 0, "route": [ { - "x": 3516, + "x": 2020, "y": 234 }, { - "x": 3516, + "x": 2020, "y": 2834 } ], @@ -1936,11 +1936,11 @@ "labelPercentage": 0, "route": [ { - "x": 3939, + "x": 2256, "y": 239 }, { - "x": 3939, + "x": 2256, "y": 2834 } ], @@ -1975,11 +1975,11 @@ "labelPercentage": 0, "route": [ { - "x": 4346, + "x": 2476, "y": 234 }, { - "x": 4346, + "x": 2476, "y": 2834 } ], @@ -2014,11 +2014,11 @@ "labelPercentage": 0, "route": [ { - "x": 4753, + "x": 2696, "y": 234 }, { - "x": 4753, + "x": 2696, "y": 2834 } ], @@ -2053,11 +2053,11 @@ "labelPercentage": 0, "route": [ { - "x": 5172.5, + "x": 2928.5, "y": 234 }, { - "x": 5172.5, + "x": 2928.5, "y": 2834 } ], @@ -2092,11 +2092,11 @@ "labelPercentage": 0, "route": [ { - "x": 5608.5, + "x": 3177.5, "y": 234 }, { - "x": 5608.5, + "x": 3177.5, "y": 2834 } ], @@ -2131,11 +2131,11 @@ "labelPercentage": 0, "route": [ { - "x": 6034, + "x": 3416, "y": 239 }, { - "x": 6034, + "x": 3416, "y": 2834 } ], @@ -2170,11 +2170,11 @@ "labelPercentage": 0, "route": [ { - "x": 6448.5, + "x": 3643.5, "y": 234 }, { - "x": 6448.5, + "x": 3643.5, "y": 2834 } ], @@ -2209,11 +2209,11 @@ "labelPercentage": 0, "route": [ { - "x": 6868.5, + "x": 3876.5, "y": 234 }, { - "x": 6868.5, + "x": 3876.5, "y": 2834 } ], @@ -2248,11 +2248,11 @@ "labelPercentage": 0, "route": [ { - "x": 7314.5, + "x": 4135.5, "y": 234 }, { - "x": 7314.5, + "x": 4135.5, "y": 2834 } ], @@ -2287,11 +2287,11 @@ "labelPercentage": 0, "route": [ { - "x": 7753, + "x": 4387, "y": 234 }, { - "x": 7753, + "x": 4387, "y": 2834 } ], @@ -2326,11 +2326,11 @@ "labelPercentage": 0, "route": [ { - "x": 8190, + "x": 4637, "y": 234 }, { - "x": 8190, + "x": 4637, "y": 2834 } ], diff --git a/e2etests/testdata/stable/sequence_diagram_all_shapes/dagre/sketch.exp.svg b/e2etests/testdata/stable/sequence_diagram_all_shapes/dagre/sketch.exp.svg index ed4a6ea54..8cf3cf52b 100644 --- a/e2etests/testdata/stable/sequence_diagram_all_shapes/dagre/sketch.exp.svg +++ b/e2etests/testdata/stable/sequence_diagram_all_shapes/dagre/sketch.exp.svg @@ -2,7 +2,7 @@ a labelblabelsa class+ +public() bool +void- +private() int +voidcloudyyyy:= 5 := a + 7 -fmt.Printf("%d", b)cyldiadocssix cornersa random iconoverpackdocs pagetoohard o saysinglepersona queuea squarea step at a timedatausersid -int -name -varchar - result := callThisFunction(obj, 5) midthis sideother side - - - +fmt.Printf("%d", b)cyldiadocssix cornersa random iconoverpackdocs pagetoohard o saysinglepersona queuea squarea step at a timedatausersid +int +name +varchar + result := callThisFunction(obj, 5) midthis sideother side + + + a labelblabelsa class+ -public() bool -void- -private() int -voidcloudyyyy:= 5 +a labelblabelsa class+ +public() bool +void- +private() int +voidcloudyyyy:= 5 := a + 7 -fmt.Printf("%d", b)cyldiadocssix cornersa random iconoverpackdocs pagetoohard o saysinglepersona queuea squarea step at a timedatausersid -int -name -varchar - result := callThisFunction(obj, 5) midthis sideother side - - - +fmt.Printf("%d", b)cyldiadocssix cornersa random iconoverpackdocs pagetoohard o saysinglepersona queuea squarea step at a timedatausersid +int +name +varchar + result := callThisFunction(obj, 5) midthis sideother side + + + abcdggggroup 1group bchoonested guywhat would arnold saythis note lalaeyokayokay - - - - - +abcdggggroup 1group bchoonested guywhat would arnold saythis note lalaeyokayokay + + + + + abcdggggroup 1group bchoonested guywhat would arnold saythis note lalaeyokayokay - - - - - +abcdggggroup 1group bchoonested guywhat would arnold saythis note lalaeyokayokay + + + + + scoreritemResponseitemessayRubricconceptitemOutcome scoreritemResponseitemessayRubricconceptitemOutcome abcdexplanationanother explanationSome one who believes imaginary things appear right before your i's.The earth is like a tiny grain of sand, only much, much heavier okay - - +abcdexplanationanother explanationSome one who believes imaginary things appear right before your i's.The earth is like a tiny grain of sand, only much, much heavier okay + + abcdexplanationanother explanationSome one who believes imaginary things appear right before your i's.The earth is like a tiny grain of sand, only much, much heavier okay - - +abcdexplanationanother explanationSome one who believes imaginary things appear right before your i's.The earth is like a tiny grain of sand, only much, much heavier okay + + How this is renderedCLId2astd2compilerd2layoutd2exporterd2themesd2rendererd2sequencelayoutd2dagrelayoutmeasurements also take place 'How this is rendered: {...}'tokenized ASTcompile ASTobjects and edgesrun layout enginesrun engine on shape: sequence_diagram, temporarily removerun core engine on rest add back in sequence diagramsdiagram with correct positions and dimensionsexport diagram with chosen theme and rendererget theme stylesrender to SVGresulting SVG - - - - - - - - - - - - - - +How this is renderedCLId2astd2compilerd2layoutd2exporterd2themesd2rendererd2sequencelayoutd2dagrelayoutmeasurements also take place 'How this is rendered: {...}'tokenized ASTcompile ASTobjects and edgesrun layout enginesrun engine on shape: sequence_diagram, temporarily removerun core engine on rest add back in sequence diagramsdiagram with correct positions and dimensionsexport diagram with chosen theme and rendererget theme stylesrender to SVGresulting SVG + + + + + + + + + + + + + + How this is renderedCLId2astd2compilerd2layoutd2exporterd2themesd2rendererd2sequencelayoutd2dagrelayoutmeasurements also take place 'How this is rendered: {...}'tokenized ASTcompile ASTobjects and edgesrun layout enginesrun engine on shape: sequence_diagram, temporarily removerun core engine on rest add back in sequence diagramsdiagram with correct positions and dimensionsexport diagram with chosen theme and rendererget theme stylesrender to SVGresulting SVG - - - - - - - - - - - - - - +How this is renderedCLId2astd2compilerd2layoutd2exporterd2themesd2rendererd2sequencelayoutd2dagrelayoutmeasurements also take place 'How this is rendered: {...}'tokenized ASTcompile ASTobjects and edgesrun layout enginesrun engine on shape: sequence_diagram, temporarily removerun core engine on rest add back in sequence diagramsdiagram with correct positions and dimensionsexport diagram with chosen theme and rendererget theme stylesrender to SVGresulting SVG + + + + + + + + + + + + + + ab a self edge herebetween actorsto descendantto deeper descendantto parentactor - +ab a self edge herebetween actorsto descendantto deeper descendantto parentactor + - - - - - + + + + + ab a self edge herebetween actorsto descendantto deeper descendantto parentactor - +ab a self edge herebetween actorsto descendantto deeper descendantto parentactor + - - - - - + + + + + AlicelinebreakerBobdbqueueanoddservicewithanameinmultiple lines Authentication Requestmake request for something that is quite far away and requires a really long label to take all the space between the objectsvalidate credentialsAuthentication ResponseAnother authentication Requestdo it later storedAnother authentication Response - - - - - - - - - +AlicelinebreakerBobdbqueueanoddservicewithanameinmultiple lines Authentication Requestmake request for something that is quite far away and requires a really long label to take all the space between the objectsvalidate credentialsAuthentication ResponseAnother authentication Requestdo it later storedAnother authentication Response + + + + + + + + + AlicelinebreakerBobdbqueueanoddservicewithanameinmultiple lines Authentication Requestmake request for something that is quite far away and requires a really long label to take all the space between the objectsvalidate credentialsAuthentication ResponseAnother authentication Requestdo it later storedAnother authentication Response - - - - - - - - - +AlicelinebreakerBobdbqueueanoddservicewithanameinmultiple lines Authentication Requestmake request for something that is quite far away and requires a really long label to take all the space between the objectsvalidate credentialsAuthentication ResponseAnother authentication Requestdo it later storedAnother authentication Response + + + + + + + + + scoreritemResponseitemessayRubricconceptitemOutcome getItem() itemgetRubric()rubricapplyTo(essayResp)match(essayResponse)scorenewgetNormalMinimum()getNormalMaximum()setScore(score)setFeedback(missingConcepts) - - - - - - - - - - - - - +scoreritemResponseitemessayRubricconceptitemOutcome getItem() itemgetRubric()rubricapplyTo(essayResp)match(essayResponse)scorenewgetNormalMinimum()getNormalMaximum()setScore(score)setFeedback(missingConcepts) + + + + + + + + + + + + + scoreritemResponseitemessayRubricconceptitemOutcome getItem() itemgetRubric()rubricapplyTo(essayResp)match(essayResponse)scorenewgetNormalMinimum()getNormalMaximum()setScore(score)setFeedback(missingConcepts) - - - - - - - - - - - - - +scoreritemResponseitemessayRubricconceptitemOutcome getItem() itemgetRubric()rubricapplyTo(essayResp)match(essayResponse)scorenewgetNormalMinimum()getNormalMaximum()setScore(score)setFeedback(missingConcepts) + + + + + + + + + + + + + a_shapea_sequenceanotherfinallysequencesequencesequencescoreritemResponseitemessayRubricconceptitemOutcomescorerconceptessayRubricitemitemOutcomeitemResponsescoreritemResponseitemessayRubricconceptitemOutcome getItem()itemgetRubric()rubricapplyTo(essayResp)match(essayResponse)scorenewgetNormalMinimum()getNormalMaximum()setScore(score)setFeedback(missingConcepts)getItem()itemgetRubric()rubricapplyTo(essayResp)match(essayResponse)scorenewgetNormalMinimum()getNormalMaximum()setScore(score)setFeedback(missingConcepts) - - - - - - - - - - - - - - - - - - - - - - - - - +a_shapea_sequenceanotherfinallysequencesequencesequencescoreritemResponseitemessayRubricconceptitemOutcomescorerconceptessayRubricitemitemOutcomeitemResponsescoreritemResponseitemessayRubricconceptitemOutcome getItem()itemgetRubric()rubricapplyTo(essayResp)match(essayResponse)scorenewgetNormalMinimum()getNormalMaximum()setScore(score)setFeedback(missingConcepts)getItem()itemgetRubric()rubricapplyTo(essayResp)match(essayResponse)scorenewgetNormalMinimum()getNormalMaximum()setScore(score)setFeedback(missingConcepts) + + + + + + + + + + + + + + + + + + + + + + + + + a_shapea_sequenceanotherfinallysequencesequencesequencescoreritemResponseitemessayRubricconceptitemOutcomescorerconceptessayRubricitemitemOutcomeitemResponsescoreritemResponseitemessayRubricconceptitemOutcome getItem()itemgetRubric()rubricapplyTo(essayResp)match(essayResponse)scorenewgetNormalMinimum()getNormalMaximum()setScore(score)setFeedback(missingConcepts)getItem()itemgetRubric()rubricapplyTo(essayResp)match(essayResponse)scorenewgetNormalMinimum()getNormalMaximum()setScore(score)setFeedback(missingConcepts) - - - - - - - - - - - - - - - - - - - - - - - - - +a_shapea_sequenceanotherfinallysequencesequencesequencescoreritemResponseitemessayRubricconceptitemOutcomescorerconceptessayRubricitemitemOutcomeitemResponsescoreritemResponseitemessayRubricconceptitemOutcome getItem()itemgetRubric()rubricapplyTo(essayResp)match(essayResponse)scorenewgetNormalMinimum()getNormalMaximum()setScore(score)setFeedback(missingConcepts)getItem()itemgetRubric()rubricapplyTo(essayResp)match(essayResponse)scorenewgetNormalMinimum()getNormalMaximum()setScore(score)setFeedback(missingConcepts) + + + + + + + + + + + + + + + + + + + + + + + + +