Relationship labels are lost during SVG layout

Open
#710 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
62/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Active
Tech stack
haskell

Research direction

Start with src/Modelling/Auxiliary/Diagrams.hs around line 546, where the issue points to tangent vector calculation and normalization. Inspect how the SVG layout computes the label position for a nearly straight relationship segment and check the generated SVG for NaN values. Done when the “supports” label is rendered correctly and the SVG contains no NaN values for this task.

Written by the indexing model from the issue text.

Description

image

and its task instance:

NameCdErrorInstance
  { byName = True
  , classDiagram = AnnotatedClassDiagram
      { annotatedClasses =
        [ "ComputerSystem"
        , "Processor"
        , "QuadCoreProcessor"
        , "MultiCoreProcessor"
        , "InstructionSet"
        ]
      , annotatedRelationships =
        [ Annotation
            { annotated = Right (Association
                { associationName = "supports"
                , associationFrom = (LimitedLinking
                    { linking = "ComputerSystem", limits = ( 0, Nothing ) })
                , associationTo = (LimitedLinking
                    { linking = "InstructionSet", limits = ( 0, Just 1 ) })
                })
            , annotation = Relevant
                { contributingToProblem = False
                , listingPriority = 4
                , referenceUsing = DefiniteArticle
                }
            }
        , Annotation
            { annotated = Right (Composition
                { compositionName = "isComponentOf"
                , compositionPart = (LimitedLinking
                    { linking = "QuadCoreProcessor", limits = ( 0, Just 1 ) })
                , compositionWhole = (LimitedLinking
                    { linking = "ComputerSystem", limits = ( 1, Just 1 ) })
                })
            , annotation = Relevant
                { contributingToProblem = False
                , listingPriority = 1
                , referenceUsing = DefiniteArticle
                }
            }
        , Annotation
            { annotated = Right (Inheritance
                { subClass = "QuadCoreProcessor"
                , superClass = "MultiCoreProcessor"
                })
            , annotation = Relevant
                { contributingToProblem = False
                , listingPriority = 5
                , referenceUsing = DefiniteArticle
                }
            }
        , Annotation
            { annotated = Right (Association
                { associationName = "implements"
                , associationFrom = (LimitedLinking
                    { linking = "Processor", limits = ( 0, Nothing ) })
                , associationTo = (LimitedLinking
                    { linking = "InstructionSet", limits = ( 0, Just 1 ) })
                })
            , annotation = Relevant
                { contributingToProblem = False
                , listingPriority = 7
                , referenceUsing = DefiniteArticle
                }
            }
        , Annotation
            { annotated = Right (Inheritance
                { subClass = "MultiCoreProcessor", superClass = "Processor" })
            , annotation = Relevant
                { contributingToProblem = False
                , listingPriority = 6
                , referenceUsing = DefiniteArticle
                }
            }
        , Annotation
            { annotated = Right (Association
                { associationName = "integrates"
                , associationFrom = (LimitedLinking
                    { linking = "ComputerSystem", limits = ( 0, Nothing ) })
                , associationTo = (LimitedLinking
                    { linking = "Processor", limits = ( 0, Just 1 ) })
                })
            , annotation = Relevant
                { contributingToProblem = False
                , listingPriority = 3
                , referenceUsing = DefiniteArticle
                }
            }
        ]
      }
  , cdDrawSettings = CdDrawSettings
      { omittedDefaults = OmittedDefaultMultiplicities
          { aggregationWholeOmittedDefaultMultiplicity = Just ( 0, Nothing )
          , associationOmittedDefaultMultiplicity = Just ( 0, Nothing )
          , compositionWholeOmittedDefaultMultiplicity = Nothing
          }
      , printNames = True
      , printNavigations = True
      }
  , errorReasons = listToFM
      [ ( 'a'
        , ( False
          , Custom (listToFM
              [ ( English, "does not have any corresponding object diagram" )
              , ( German, "hat gar kein passendes Objektdiagramm" )
              ])
          )
        )
      , ( 'b'
        , ( False
          , Custom (listToFM
              [ ( English, "violates a requirement of the scenario" )
              , ( German, "h\228lt eine Vorgabe des Szenarios nicht ein" )
              ])
          )
        )
      , ( 'c'
        , ( False
          , Custom (listToFM
              [ ( English, "contains a syntax error" )
              , ( German, "enth\228lt einen Syntaxfehler" )
              ])
          )
        )
      , ( 'd'
        , ( True
          , Custom (listToFM
              [ ( English, "is fully correctly modelled" )
              , ( German, "ist vollst\228ndig richtig modelliert" )
              ])
          )
        )
      ]
  , showSolution = True
  , taskText =
    [ Paragraph
      [ Translated (listToFM
          [ ( English, "A student received the following scenario:" )
          , ( German
            , "Eine studierende Person hat folgendes Szenario erhalten:"
            )
          ])
      ]
    , Paragraph
      [ Translated (listToFM
          [ ( English
            , "Computer systems, processors, instruction sets, multi-core processors, and quad-core processors are the concepts involved. A multi-core processor is a kind of processor, and a quad-core processor is a kind of multi-core processor. A computer system owns a quad-core processor as a component. Each quad-core processor belongs to exactly one computer system, and each computer system contains at most one quad-core processor. A computer system supports an instruction set. Each computer system supports at most one instruction set, and each instruction set is supported by any number of computer systems. A processor implements an instruction set. Each processor implements at most one instruction set, and each instruction set is implemented by any number of processors. A computer system integrates a processor. Each computer system integrates at most one processor, and each processor is integrated into any number of computer systems."
            )
          , ( German
            , "Die beteiligten Konzepte sind Computersysteme, Prozessoren, Befehlss\228tze, Mehrkernprozessoren und Vierkernprozessoren. Ein Mehrkernprozessor ist ein Prozessor, und ein Vierkernprozessor ist ein Mehrkernprozessor. Ein Computersystem enth\228lt einen Vierkernprozessor als Bestandteil. Jeder Vierkernprozessor geh\246rt zu genau einem Computersystem, und jedes Computersystem enth\228lt h\246chstens einen Vierkernprozessor. Ein Computersystem unterst\252tzt einen Befehlssatz. Jedes Computersystem unterst\252tzt h\246chstens einen Befehlssatz, und jeder Befehlssatz wird von beliebig vielen Computersystemen unterst\252tzt. Ein Prozessor implementiert einen Befehlssatz. Jeder Prozessor implementiert h\246chstens einen Befehlssatz, und jeder Befehlssatz wird von beliebig vielen Prozessoren implementiert. Ein Computersystem integriert einen Prozessor. Jedes Computersystem integriert h\246chstens einen Prozessor, und jeder Prozessor wird in beliebig viele Computersysteme integriert."
            )
          ])
      ]
    , Paragraph
      [ Translated (listToFM
          [ ( English
            , "The student solved the task of creating a class diagram for this scenario in the following way:"
            )
          , ( German
            , "Die Aufgabe, ein Klassendiagramm f\252r dieses Szenario zu erstellen, hat die studierende Person folgenderma\223en gel\246st:"
            )
          ])
      ]
    , Paragraph
      [ Special IncorrectCd ]
    , Paragraph
      [ Translated (listToFM
          [ ( English
            , "It contains the following relationships between classes:"
            )
          , ( German
            , "Es enth\228lt die folgenden Beziehungen zwischen Klassen:"
            )
          ])
      ]
    , Paragraph
      [ Special RelationshipsList ]
    , Paragraph
      [ Translated (listToFM
          [ ( English
            , "Decide whether the student's class diagram models the scenario correctly and choose the reason which applies. If the class diagram does not fit the scenario, mention exactly the one relationship which has to be changed so that it fits. Otherwise, mention no relationship."
            )
          , ( German
            , "Entscheiden Sie, ob das Klassendiagramm der studierenden Person das Szenario korrekt modelliert, und w\228hlen Sie den zutreffenden Grund. Falls das Klassendiagramm nicht zum Szenario passt, nennen Sie genau die eine Beziehung, die ge\228ndert werden muss, damit es dem Szenario entspricht. Andernfalls nennen Sie keine Beziehung."
            )
          ])
      ]
    , Paragraph
      [ Translated (listToFM
          [ ( English, "Reasons available to choose from are:" )
          , ( German, "Gr\252nde, die hierf\252r zur Auswahl stehen, sind:" )
          ])
      ]
    , Paragraph
      [ Translated (listToFM
          [ ( English, "The class diagram ..." )
          , ( German, "Das Klassendiagramm ..." )
          ])
      ]
    , Paragraph
      [ Special ReasonsList ]
    ]
  , addTexts =
    [ Static (listToFM
        [ ( English, "" )
        , ( German
          , "Es wird empfohlen, sich (auch) die englische Version des Aufgabentextes anzusehen."
          )
        ])
    ]
  }

The label "supports" on the association between classes ComputerSystem and InstructionSet is not shown correctly.

I found there are some NaN values in the SVG file, so I guess there are some issues during layout. It is likely that the middle section of this relationship is nearly a straight line, which causes the tangent vector to be zero during the calculation at https://github.com/fmidue/modelling-tasks/blob/83adcee8114d4fbb36bcc383600ef89d1c9237b6/src/Modelling/Auxiliary/Diagrams.hs#L546. The subsequent normalization then results in a NaN value.

Dominant language
Haskell
Stars
0
Forks
3
Avg merge
2d 6h
Merged PRs (30d)
6

Getting set up

  • No Dockerfile or Docker Compose file
  • Has a pull request template
  • No contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from fmidue/modelling-tasks

All issues in fmidue/modelling-tasks

Similar issues

More Haskell issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.