如何三次打破关联箭头

如何三次打破关联箭头

看看这个类图

\documentclass{article}
\usepackage{geometry}
\usepackage{graphicx}
\usepackage{amssymb}
\usepackage{amsmath}
\usepackage{amsthm}
\usepackage{empheq}
\usepackage{mdframed}
\usepackage{booktabs}
\usepackage{lipsum}
\usepackage{graphicx}
\usepackage{color}
\usepackage{psfrag}
\usepackage{pgfplots}
\usepackage{bm}
\usepackage{tikz}
\usepackage{tikz-uml}
\usetikzlibrary{positioning}


\begin{document}

\begin{figure}[h!]
\centering
\begin{tikzpicture}

    \umlclass[]{ApplicationController}
    {
        - application\_service: ApplicationService \\
        - issuer\_service: IssuerService \\
        - authorization\_handler: AuthorizationHandler \\
        - verification\_handler: VerificationHandler \\
        - did\_method\_handler: DidMethodHandler
    }
    {
        + handleApplicationReadRequest() \\
        + handleApplicationWrite()
    }

    \umlclass[below=0.8cm of ApplicationController]{ApplicationService}{}
    {
        + read() \\
        + write(data: str)
    }

    \umlclass[below=0.8cm of ApplicationService]{IssuerService}{}{}

    \umlclass[right=3.2cm of ApplicationController]{VerificationHandler}{}{}

    \umluniassoc[geometry=-|-, arm2=-5cm]{ApplicationController}{ApplicationService}
    \umluniassoc[geometry=-|-, arm2=-5cm]{ApplicationController}{IssuerService}

    \umlclass[below=1cm of VerificationHandler]{DidMethodHandler}{}{}

    \umlclass[below=1cm of DidMethodHandler]{AuthorizationHandler}{}{}

    \umlinterface[below=1cm of AuthorizationHandler]{SignatureVerificationStrategy}{}
    {
        + execute(p: ProofDTO, ...)
    }

    \umlclass[below=1cm of SignatureVerificationStrategy]{JwsVerificationStrategy}{}
    {
        + execute(p: JwsProofDTO, ...)
    }

    \umlimpl{JwsVerificationStrategy}{SignatureVerificationStrategy}

    \umluniassoc[geometry=-|-, arm1=3cm]{ApplicationController}{VerificationHandler}
    \umluniassoc[geometry=-|-, arm1=5cm]{ApplicationController}{DidMethodHandler}
    \umluniassoc[geometry=-|-, arm1=5cm]{ApplicationController}{AuthorizationHandler}
    \umluniassoc[geometry=-|-, arm1=5cm]{ApplicationController}{SignatureVerificationStrategy}


    \umlclass[below=0.8cm of IssuerService]{IssuerRepository}{}{}
    \umlclass[below=0.8cm of IssuerRepository]{CryptoMaterialRepository}{}{}

    \umluniassoc[geometry=-|-, arm2=4cm]{IssuerService}{IssuerRepository}

    \umluniassoc[geometry=-|-, arm1=3cm, arm2=-5cm]{VerificationHandler}{CryptoMaterialRepository}

\end{tikzpicture}
\end{figure}
    
\end{document}

我需要和之间的关联VerificationHandler,而CryptoMaterialRepository不是进入JwsVerificationStrategy类下。我无法三次打破箭头,我甚至不知道是否可以使用tikzuml

在此处输入图片描述

答案1

图表tikz-uml是常规的 TikZ 图片,其中包含许多预定义的框和箭头 UML 样式。除了这些样式之外,您还可以在预定义样式不够用的情况下使用标准 TikZ 绘图命令。

在这种情况下,你可以使用以下方式绘制路径\path围绕JwsVerificationStrategy框。这可以使用 tikzlibrary 相对轻松地完成。此库引入了指定添加到节点的坐标的calc语法。路径还使用线规范和($(node)+(x,y)$)x,y-||-框。这可以使用 tikzlibrary 相对轻松地先水平,再垂直先垂直,再水平分别。

现在的路径是VerificationHandler 水平垂直(JwsVerificationStrategy+右,下)水平(JwsVerificationStrategy+左,下)垂直水平 CryptoMaterialRepository. 在代码中:

\path[draw,-angle 45] (VerificationHandler) -| ($(JwsVerificationStrategy)+(3,-1.5)$) -- ($(JwsVerificationStrategy)+(-4,-1.5)$) |- (CryptoMaterialRepository);

完整的 MWE(请注意,我删除了一些不必要的包):

\documentclass{article}
\usepackage{tikz-uml}
\usepackage[left=1cm]{geometry}
\usetikzlibrary{calc,positioning}

\begin{document}

\begin{figure}[h!]
\centering
\begin{tikzpicture}

    \umlclass[]{ApplicationController}
    {
        - application\_service: ApplicationService \\
        - issuer\_service: IssuerService \\
        - authorization\_handler: AuthorizationHandler \\
        - verification\_handler: VerificationHandler \\
        - did\_method\_handler: DidMethodHandler
    }
    {
        + handleApplicationReadRequest() \\
        + handleApplicationWrite()
    }

    \umlclass[below=0.8cm of ApplicationController]{ApplicationService}{}
    {
        + read() \\
        + write(data: str)
    }

    \umlclass[below=0.8cm of ApplicationService]{IssuerService}{}{}

    \umlclass[right=3.2cm of ApplicationController]{VerificationHandler}{}{}

    \umluniassoc[geometry=-|-, arm2=-5cm]{ApplicationController}{ApplicationService}
    \umluniassoc[geometry=-|-, arm2=-5cm]{ApplicationController}{IssuerService}

    \umlclass[below=1cm of VerificationHandler]{DidMethodHandler}{}{}

    \umlclass[below=1cm of DidMethodHandler]{AuthorizationHandler}{}{}

    \umlinterface[below=1cm of AuthorizationHandler]{SignatureVerificationStrategy}{}
    {
        + execute(p: ProofDTO, ...)
    }

    \umlclass[below=1cm of SignatureVerificationStrategy]{JwsVerificationStrategy}{}
    {
        + execute(p: JwsProofDTO, ...)
    }

    \umlimpl{JwsVerificationStrategy}{SignatureVerificationStrategy}

    \umluniassoc[geometry=-|-, arm1=3cm]{ApplicationController}{VerificationHandler}
    \umluniassoc[geometry=-|-, arm1=5cm]{ApplicationController}{DidMethodHandler}
    \umluniassoc[geometry=-|-, arm1=5cm]{ApplicationController}{AuthorizationHandler}
    \umluniassoc[geometry=-|-, arm1=5cm]{ApplicationController}{SignatureVerificationStrategy}


    \umlclass[below=0.8cm of IssuerService]{IssuerRepository}{}{}
    \umlclass[below=0.8cm of IssuerRepository]{CryptoMaterialRepository}{}{}

    \umluniassoc[geometry=-|-, arm2=4cm]{IssuerService}{IssuerRepository}

    %\umluniassoc[geometry=-|-, arm1=3cm, arm2=-5cm]{VerificationHandler}{CryptoMaterialRepository}
    \path[draw,-angle 45] (VerificationHandler) -| ($(JwsVerificationStrategy)+(3,-1.5)$) -- ($(JwsVerificationStrategy)+(-4,-1.5)$) |- (CryptoMaterialRepository);

\end{tikzpicture}
\end{figure}
    
\end{document}

结果:

在此处输入图片描述

相关内容