Skip to content

Instantly share code, notes, and snippets.

@Shawn-Armstrong
Last active July 14, 2023 19:00
Show Gist options
  • Save Shawn-Armstrong/c9111b220e25a5b4b8e4b2c1d9284e1d to your computer and use it in GitHub Desktop.
Save Shawn-Armstrong/c9111b220e25a5b4b8e4b2c1d9284e1d to your computer and use it in GitHub Desktop.

#GitGub_mermaid.md

Overview

  • This document provides critical notes for useful Mermaid functionality within GitHub's markdown Syntax.
  • Daigrams are only visible after publishing the file; they cannot be viewed using the preview changes option.

Example 1

Usage

  graph TD;
      A("Instantiate resource")-->B("Perform first action");
      B --> C{"Did result satisfy condition?"};
      C -- no --> B;
      C -- yes --> F("Perform second action");

Output

  graph TD;
      A("Instantiate resource")-->B("Perform first action");
      B --> C{"Did result satisfy condition?"};
      C -- no --> B;
      C -- yes --> F("Perform second action");
Loading

Example 2

Usage

graph TD;

    subgraph Thread B
        A1("...") --> B1("Call testAndSet(lockValue)\n
        Make copy of current lock value\n
        Set lockValue to 1\n
        return copy")
        B1 --> C1{"Is copy == 0?"}
        C1 -- no --> B1
        C1 -- yes --> D1("Perform action in critical section")
        D1 --> E1("Set lockValue to 1")
    end

    subgraph Thread A
        A2("...") --> B2("Call testAndSet(lockValue)\nMake copy of current lock value\nSet lockValue to 1\nreturn copy")
        B2 --> C2{"Is copy == 0?"}
        C2 -- no --> B2
        C2 -- yes --> D2("Perform action in critical section")
        D2 --> E2("Set lockValue to 1")
    end

Output

graph TD;

    subgraph Thread B
        A1("...") -- approaching critical section --> B1("Call testAndSet(lockValue)<br/>Make copy of current lock value<br/>Set lockValue to 1<br/>return copy")
        B1 --> C1{"Is copy == 0?"}
        C1 -- no --> B1
        C1 -- yes --> D1("Perform action in critical section")
        D1 --> E1("Set lockValue to 1")
        E1 --> F1("...")
    end

    subgraph Thread A
        A2("...") -- approaching critical section --> B2("Call testAndSet(lockValue)<br/>Make copy of current lock value<br/>Set lockValue to 1<br/>return copy")
        B2 --> C2{"Is copy == 0?"}
        C2 -- no --> B2
        C2 -- yes --> D2("Perform action in critical section<br>")
        D2 --> E2("Set lockValue to 1")
        E2 --> F2("...")
    end
Loading
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment