1

I need to change the position of text written on top of aggregation relation in pgf-umlcd. Here is what I've written so far:

\begin{figure}[h]
    \centering
    \begin{tikzpicture}[show background grid]
    \begin{class}[text width=10cm]{StateSpace}{7,0}
        \attribute{- stateToActionSet: HashMap<State, HashMap<Action, Double>{}>}
        \operation{+ addState(s: State)}
        \operation{+ size()}
        \operation{+ updateQValueForAction(s: State, a: Action, qValue: Double)}
    \end{class}
    \begin{class}{State}{12,-5}
        \attribute{+ latency: Integer}
        \attribute{+ isLoadIncreasing: Boolean}
    \end{class}
    \begin{interface}{Action}{4,-5}
        \operation[0]{+ toString()}
    \end{interface}
    \begin{class}[text width=3cm]{NoAction}{0,-8}
        \implement{Action}
        \operation{+ toString()}
    \end{class}
    \begin{class}[text width=3cm]{ScaleIn}{4,-8}
        \implement{Action}
        \operation{+ toString()}
    \end{class}
    \begin{class}[text width=3cm]{ScaleOut}{8,-8}
        \implement{Action}
        \operation{+ toString()}
    \end{class}
    
    \aggregation{StateSpace}{states}{1..*}{State}
    \aggregation{StateSpace}{actionSet}{1..*}{Action}
    \end{tikzpicture}
    \caption{State Space Class Diagram}
\end{figure}

which results in: Text position

As you see, the text has been positioned on top of aggregation line. Is there any way to change it?

1 Answer 1

1

I'd like to argue that the simplest way will be to add these via plain TikZ methods.

\documentclass[tikz,border=3.14mm]{standalone}
\usepackage[simplified]{pgf-umlcd}
\begin{document}
    \begin{tikzpicture}[show background grid]
    \begin{class}[text width=10cm]{StateSpace}{7,0}
        \attribute{- stateToActionSet: HashMap<State, HashMap<Action, Double>{}>}
        \operation{+ addState(s: State)}
        \operation{+ size()}
        \operation{+ updateQValueForAction(s: State, a: Action, qValue: Double)}
    \end{class}
    \begin{class}{State}{12,-5}
        \attribute{+ latency: Integer}
        \attribute{+ isLoadIncreasing: Boolean}
    \end{class}
    \begin{interface}{Action}{4,-5}
        \operation[0]{+ toString()}
    \end{interface}
    \begin{class}[text width=3cm]{NoAction}{0,-8}
        \implement{Action}
        \operation{+ toString()}
    \end{class}
    \begin{class}[text width=3cm]{ScaleIn}{4,-8}
        \implement{Action}
        \operation{+ toString()}
    \end{class}
    \begin{class}[text width=3cm]{ScaleOut}{8,-8}
        \implement{Action}
        \operation{+ toString()}
    \end{class}
    \aggregation{StateSpace}{}{}{State}
    \aggregation{StateSpace}{}{}{Action}

    \path (StateSpace) -- (State) node[midway,sloped,above]{states}
    node[midway,sloped,below] {1..*};
    \path (StateSpace) -- (Action) node[midway,sloped,above]{actionSet}
    node[midway,sloped,below] {1..*};
    \end{tikzpicture}
\end{document}  

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.