【问题标题】:Style Multiple Links Mermaid JS样式多链接美人鱼 JS
【发布时间】:2021-09-27 20:04:05
【问题描述】:

Mermaid JS 中是否有任何方法可以命名链接并避免图表中的每个链接都必须有一个 linkStyle

例如,要获得下图中的红线和黑线,我的源代码如下所示,并且样式变得难以管理。

graph TD
    Bat(fa:fa-car-battery Batteries) -->|150a 50mm| ShutOff
    Bat -->|150a 50mm| Shunt

    ShutOff[Shut Off] -->|150a 50mm| BusPos[Bus Bar +]

    Shunt -->|150a 50mm| BusNeg[Bus Bar -]

    BusPos -->|40a| Fuse[Fuse Box]
    BusPos -->|?a| Old{Old Wiring}

    BusNeg -->|40a| Fuse

    Fuse -->|10a| USB(USB-C)
    Fuse -->|10a| USB
    Fuse -->|1.5a| Switch -->|1.5a| Wifi

    Wifi -->|1.5a| Fuse

    Fuse -->|10a| Cig1[Cigarette Lighter]
    Fuse -->|10a| Cig1 

    Fuse -->|10a| Cig2[Cigarette Lighter Near Bed]
    Fuse -->|10a| Cig2 

    BusNeg -->|?a| Old

    Solar --> SolarCont[Solar Controller]
    Solar --> SolarCont

    SolarCont --> BusNeg
    SolarCont --> BusPos

    linkStyle 0 stroke-width:2px,fill:none,stroke:red;
    linkStyle 1 stroke-width:2px,fill:none,stroke:black;
    linkStyle 2 stroke-width:2px,fill:none,stroke:red;
    linkStyle 3 stroke-width:2px,fill:none,stroke:black;
    linkStyle 4 stroke-width:2px,fill:none,stroke:red;
    linkStyle 5 stroke-width:2px,fill:none,stroke:red;
    linkStyle 6 stroke-width:2px,fill:none,stroke:black;
    linkStyle 7 stroke-width:2px,fill:none,stroke:black;
    linkStyle 8 stroke-width:2px,fill:none,stroke:red;
    linkStyle 9 stroke-width:2px,fill:none,stroke:red;
    linkStyle 10 stroke-width:2px,fill:none,stroke:red;
    linkStyle 11 stroke-width:2px,fill:none,stroke:black;
    linkStyle 12 stroke-width:2px,fill:none,stroke:red;
    linkStyle 13 stroke-width:2px,fill:none,stroke:black;
    linkStyle 14 stroke-width:2px,fill:none,stroke:red;
    linkStyle 15 stroke-width:2px,fill:none,stroke:black;
    linkStyle 16 stroke-width:2px,fill:none,stroke:black;
    linkStyle 17 stroke-width:2px,fill:none,stroke:red;
    linkStyle 18 stroke-width:2px,fill:none,stroke:black;
    linkStyle 19 stroke-width:2px,fill:none,stroke:black;

【问题讨论】:

    标签: mermaid


    【解决方案1】:

    您可以使用 id 列表而不是分别为每个 id 设置样式。 例如,

    graph TD
        Bat(fa:fa-car-battery Batteries) -->|150a 50mm| ShutOff
        Bat -->|150a 50mm| Shunt
    
        ShutOff[Shut Off] -->|150a 50mm| BusPos[Bus Bar +]
    
        Shunt -->|150a 50mm| BusNeg[Bus Bar -]
    
        BusPos -->|40a| Fuse[Fuse Box]
        BusPos -->|?a| Old{Old Wiring}
    
        BusNeg -->|40a| Fuse
    
        Fuse -->|10a| USB(USB-C)
        Fuse -->|10a| USB
        Fuse -->|1.5a| Switch -->|1.5a| Wifi
    
        Wifi -->|1.5a| Fuse
    
        Fuse -->|10a| Cig1[Cigarette Lighter]
        Fuse -->|10a| Cig1 
    
        Fuse -->|10a| Cig2[Cigarette Lighter Near Bed]
        Fuse -->|10a| Cig2 
    
        BusNeg -->|?a| Old
    
        Solar --> SolarCont[Solar Controller]
        Solar --> SolarCont
    
        SolarCont --> BusNeg
        SolarCont --> BusPos
    
        linkStyle 0,1,2,4,5,8,9 stroke-width:2px,fill:none,stroke:red;
        linkStyle 3,6,7 stroke-width:2px,fill:none,stroke:black;
        linkStyle 10 stroke-width:2px,fill:none,stroke:red;
        linkStyle 11 stroke-width:2px,fill:none,stroke:black;
        linkStyle 12 stroke-width:2px,fill:none,stroke:red;
        linkStyle 13 stroke-width:2px,fill:none,stroke:black;
        linkStyle 14 stroke-width:2px,fill:none,stroke:red;
        linkStyle 15 stroke-width:2px,fill:none,stroke:black;
        linkStyle 16 stroke-width:2px,fill:none,stroke:black;
        linkStyle 17 stroke-width:2px,fill:none,stroke:red;
        linkStyle 18 stroke-width:2px,fill:none,stroke:black;
        linkStyle 19 stroke-width:2px,fill:none,stroke:black;
    

    【讨论】:

    • 这并不理想,但这似乎是一个更好的选择! (我想知道为什么它没有记录在案!)
    猜你喜欢
    • 2017-06-17
    • 2018-12-24
    • 2019-06-16
    • 2022-11-07
    • 1970-01-01
    • 2022-12-14
    • 2019-01-09
    • 2018-10-22
    • 1970-01-01
    相关资源
    最近更新 更多