diff --git a/d2layouts/d2sequence/sequence_diagram.go b/d2layouts/d2sequence/sequence_diagram.go index b08a89a6f..c0f3727ee 100644 --- a/d2layouts/d2sequence/sequence_diagram.go +++ b/d2layouts/d2sequence/sequence_diagram.go @@ -267,12 +267,7 @@ func (sd *sequenceDiagram) routeMessages() { } if message.Attributes.Label.Value != "" { - if isLeftToRight { - message.LabelPosition = go2.Pointer(string(label.OutsideTopCenter)) - } else { - // the label will be placed above the message because the orientation is based on the edge normal vector - message.LabelPosition = go2.Pointer(string(label.OutsideBottomCenter)) - } + message.LabelPosition = go2.Pointer(string(label.InsideMiddleCenter)) } } } diff --git a/d2renderers/d2svg/d2svg.go b/d2renderers/d2svg/d2svg.go index 692db2cca..e46a0fb79 100644 --- a/d2renderers/d2svg/d2svg.go +++ b/d2renderers/d2svg/d2svg.go @@ -337,26 +337,15 @@ func pathData(connection d2target.Connection, idToShape map[string]d2target.Shap return strings.Join(path, " ") } -func labelMask(id string, connection d2target.Connection, labelTL, tl, br *geo.Point) string { - width := br.X - tl.X - height := br.Y - tl.Y - return strings.Join([]string{ - fmt.Sprintf(``, - id, tl.X, tl.Y, width, height, - ), - fmt.Sprintf(``, - tl.X, tl.Y, width, height, - ), - fmt.Sprintf(``, - labelTL.X, labelTL.Y, - connection.LabelWidth, - connection.LabelHeight, - ), - ``, - }, "\n") +func makeLabelMask(connection d2target.Connection, labelTL, tl, br *geo.Point) string { + return fmt.Sprintf(``, + labelTL.X, labelTL.Y, + connection.LabelWidth, + connection.LabelHeight, + ) } -func drawConnection(writer io.Writer, connection d2target.Connection, markers map[string]struct{}, idToShape map[string]d2target.Shape) { +func drawConnection(writer io.Writer, connection d2target.Connection, markers map[string]struct{}, idToShape map[string]d2target.Shape) (labelMask string) { fmt.Fprintf(writer, ``, escapeText(connection.ID)) var markerStart string if connection.SrcArrow != d2target.NoArrowhead { @@ -387,7 +376,6 @@ func drawConnection(writer io.Writer, connection d2target.Connection, markers ma } var labelTL *geo.Point - var mask string if connection.Label != "" { labelTL = connection.GetLabelTopLeft() labelTL.X = math.Round(labelTL.X) @@ -420,18 +408,15 @@ func drawConnection(writer io.Writer, connection d2target.Connection, markers ma br.X = math.Max(br.X, labelTL.X+float64(connection.LabelWidth)) br.Y = math.Max(br.Y, labelTL.Y+float64(connection.LabelHeight)) - maskID := fmt.Sprintf("mask-%s", hash(connection.ID)) - fmt.Fprint(writer, labelMask(maskID, connection, labelTL, tl, br)) - mask = fmt.Sprintf(`mask="url(#%s)" `, maskID) + labelMask = makeLabelMask(connection, labelTL, tl, br) } } - fmt.Fprintf(writer, ``, + fmt.Fprintf(writer, ``, pathData(connection, idToShape), connectionStyle(connection), markerStart, markerEnd, - mask, ) if connection.Label != "" { @@ -476,6 +461,7 @@ func drawConnection(writer io.Writer, connection d2target.Connection, markers ma fmt.Fprint(writer, renderArrowheadLabel(connection, connection.DstLabel, position, size, size)) } fmt.Fprintf(writer, ``) + return } func renderArrowheadLabel(connection d2target.Connection, text string, position, width, height float64) string { @@ -955,7 +941,7 @@ func embedFonts(buf *bytes.Buffer) { // TODO minify output at end func Render(diagram *d2target.Diagram) ([]byte, error) { buf := &bytes.Buffer{} - _, _ = setViewbox(buf, diagram) + w, h := setViewbox(buf, diagram) buf.WriteString(fmt.Sprintf(`abc abc abc abc ab ab ab ab acbd acbd acbd acbd ab - +ab hello + -helloab - +ab hello + -hellorectanglesquarepageparallelogramdocumentcylinderqueuepackagestepcalloutstored_datapersondiamondovalcirclehexagoncloud rectanglesquarepageparallelogramdocumentcylinderqueuepackagestepcalloutstored_datapersondiamondovalcirclehexagoncloud rectanglesquarepageparallelogramdocumentcylinderqueuepackagestepcalloutstored_datapersondiamondovalcirclehexagoncloud rectanglesquarepageparallelogramdocumentcylinderqueuepackagestepcalloutstored_datapersondiamondovalcirclehexagoncloud rectanglesquarepageparallelogramdocumentcylinderqueuepackagestepcalloutstored_datapersondiamondovalcirclehexagoncloud rectanglesquarepageparallelogramdocumentcylinderqueuepackagestepcalloutstored_datapersondiamondovalcirclehexagoncloud rectanglesquarepageparallelogramdocumentcylinderqueuepackagestepcalloutstored_datapersondiamondovalcirclehexagoncloud rectanglesquarepageparallelogramdocumentcylinderqueuepackagestepcalloutstored_datapersondiamondovalcirclehexagoncloud cba * cba * cba * cba * ab - +ab To err is human, to moo bovine1* + -To err is human, to moo bovine1*ab - +ab To err is human, to moo bovine1* + -To err is human, to moo bovine1*abcdefghijklmno abcdefghijklmno abcdefghijklmno abcdefghijklmno aaadddeeebbbccc - +aaadddeeebbbccc111 222 + -111 - -222aaadddeeebbbccc - +aaadddeeebbbccc111 222 + -111 - -222aabbllmm

nn

oocciikkdd

gg

hhjj

ee

-
ff - +ff1122 334455667788 + -11 - -22 - -33 - -44 - -55 - -66 - -77 - -88aabbllmm

nn

oocciikkdd

gg

hhjj

ee

-
ff - +ff1122 334455667788 + -11 - -22 - -33 - -44 - -55 - -66 - -77 - -88abcd abcd abcd abcd abc abc abc abc acfbdhg acfbdhg acfbdhg acfbdhg agdfbhec agdfbhec agdfbhec agdfbhec abcdefghijklmnopq abcdefghijklmnopq abcdefghijklmnopq abcdefghijklmnopq finallyatreeandnodessomemoremanythenhereyouhavehierarchyanotherofnestingtreesatreeinsidehierarchyroot finallyatreeandnodessomemoremanythenhereyouhavehierarchyanotherofnestingtreesatreeinsidehierarchyroot finallyatreeandnodessomemoremanythenhereyouhavehierarchyanotherofnestingtreesatreeinsidehierarchyroot finallyatreeandnodessomemoremanythenhereyouhavehierarchyanotherofnestingtreesatreeinsidehierarchyroot bacde21345abcde bacde21345abcde bacde21345abcde bacde21345abcde alphabeta - +alphabeta gamma + -gammaalphabeta - +alphabeta gamma + -gammasize XSsize Ssize Msize Lsize XLsize XXLsize XXXLcustom 8custom 12custom 18custom 21custom 64 - +size XSsize Ssize Msize Lsize XLsize XXLsize XXXLcustom 8custom 12custom 18custom 21custom 64 custom 10custom 15custom 48 + -custom 10 - -custom 15 - -custom 48size XSsize Ssize Msize Lsize XLsize XXLsize XXXLcustom 8custom 12custom 18custom 21custom 64 - +size XSsize Ssize Msize Lsize XLsize XXLsize XXXLcustom 8custom 12custom 18custom 21custom 64 custom 10custom 15custom 48 + -custom 10 - -custom 15 - -custom 48ab ab ab ab aabbccddllffwwyynniijjkkssuurmeemmmmgghhzzooppqqrrttvvxxabac - +aabbccddllffwwyynniijjkkssuurmeemmmmgghhzzooppqqrrttvvxxabac 123456 + -1 - -2 - -3 - -4 - -5 - -6aabbccddllffwwyynniijjkkssuurmeemmmmgghhzzooppqqrrttvvxxabac - +aabbccddllffwwyynniijjkkssuurmeemmmmgghhzzooppqqrrttvvxxabac 123456 + -1 - -2 - -3 - -4 - -5 - -6abcdefghiqrjmnoszaabbeeffggklptuwxyccddv abcdefghiqrjmnoszaabbeeffggklptuwxyccddv abcdefghiqrjmnoszaabbeeffggklptuwxyccddv abcdefghiqrjmnoszaabbeeffggklptuwxyccddv mixed togethersugarsolution - +mixed togethersugarsolution we get + -we getmixed togethersugarsolution - +mixed togethersugarsolution we get + -we get

Markdown: Syntax

-
ab

Markdown: Syntax

-
ab

code

-
ab

code

-
ab abcdefghijklmnopqrstuvw abcdefghijklmnopqrstuvw abcdefghijklmnopqrstuvw abcdefghijklmnopqrstuvw abcdefghijklmnopqrstu abcdefghijklmnopqrstu abcdefghijklmnopqrstu abcdefghijklmnopqrstu Foo Baz12hello Foo Baz12hello Foo Baz12hello Foo Baz12hello acdefgbh acdefgbh acdefgbh acdefgbh topabcbottomstartend topabcbottomstartend topabcbottomstartend topabcbottomstartend xyz - +xyz hello + -helloxyz - +xyz hello + -helloscoreritemResponseitemessayRubricconceptitemOutcome scoreritemResponseitemessayRubricconceptitemOutcome scoreritemResponseitemessayRubricconceptitemOutcome scoreritemResponseitemessayRubricconceptitemOutcome 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 ResponseAlicelinebreakerBobdbqueueanoddservicewithanameinmultiple 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 ResponseAlicelinebreakerBobdbqueueanoddservicewithanameinmultiple 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) + + + + + + + + + + + + + + + + + + + + + + + + + +acbl1l2c1l2c3l2c2l3c1l3c2l4bacacbabcc1c2c3abc acbl1l2c1l2c3l2c2l3c1l3c2l4bacacbabcc1c2c3abc acbl1l2c1l2c3l2c2l3c1l3c2l4bacacbabcc1c2c3abc acbl1l2c1l2c3l2c2l3c1l3c2l4bacacbabcc1c2c3abc AKHIALFLGAMSTNAZCANVNMUTARLAMOOKTXORCOKSNEWYCTMANYRIDEMDNJPANCSCIDMTWAILINIAMIKYWIOHMNSDVAWVMENHVTNDAKHIALFLGAMSTNAZCANVNMUTARLAMOOKTXORCOKSNEWYCTMANYRIDEMDNJPANCSCIDMTWAILINIAMIKYWIOHMNSDVAWVMENHVTNDAKHIALFLGAMSTNAZCANVNMUTARLAMOOKTXORCOKSNEWYCTMANYRIDEMDNJPANCSCIDMTWAILINIAMIKYWIOHMNSDVAWVMENHVTNDAKHIALFLGAMSTNAZCANVNMUTARLAMOOKTXORCOKSNEWYCTMANYRIDEMDNJPANCSCIDMTWAILINIAMIKYWIOHMNSDVAWVMENHVTNDcontainerfirstsecond - +containerfirstsecond 1->2c->2 + -1->2 - -c->2containerfirstsecond - +containerfirstsecond 1->2c->2 + -1->2 - -c->2eightsixteenthirty twosixty fourninety nine - +eightsixteenthirty twosixty fourninety nine twelvetwenty fourforty eighteighty one + -twelve - -twenty four - -forty eight - -eighty oneeightsixteenthirty twosixty fourninety nine - +eightsixteenthirty twosixty fourninety nine twelvetwenty fourforty eighteighty one + -twelve - -twenty four - -forty eight - -eighty oneab - +ab Thereoncewasaverytalledgelabel + -Thereoncewasaverytalledgelabelab - +ab Thereoncewasaverytalledgelabel + -Thereoncewasaverytalledgelabel