From 21caa3eb727d056ef424df0c76afa5069290d105 Mon Sep 17 00:00:00 2001
From: Sidharth Vinod
Date: Mon, 3 Oct 2022 11:50:42 +0800
Subject: [PATCH 001/129] chore: Auto build docs if only src/docs is changed
---
.github/workflows/lint.yml | 32 ++++++++++++++++++++++++++++++++
1 file changed, 32 insertions(+)
diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml
index 44e2f4cb1..c84632264 100644
--- a/.github/workflows/lint.yml
+++ b/.github/workflows/lint.yml
@@ -19,6 +19,16 @@ jobs:
node-version: [16.x]
steps:
- uses: actions/checkout@v3
+ if: ${{ github.event_name == 'pull_request' }}
+ with:
+ fetch-depth: 2
+ repository: ${{ github.event.pull_request.head.repo.full_name }}
+ ref: ${{ github.event.pull_request.head.ref }}
+
+ - uses: actions/checkout@v3
+ if: ${{ github.event_name != 'pull_request' }}
+ with:
+ fetch-depth: 2
- name: Setup Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
@@ -38,5 +48,27 @@ jobs:
- name: Run Linting
run: yarn lint
+ - name: Run changed-files using the fork point of a pull request
+ id: changed-files-fork-point
+ uses: tj-actions/changed-files@v29
+ with:
+ use_fork_point: 'true'
+ files: |
+ src/docs/*
+
+ - name: Run step if any file(s) in the docs folder change
+ if: steps.changed-files-fork-point.outputs.only_modified == 'true'
+ run: |
+ echo "Only files in the src/docs folder has changed."
+ echo "List all the files that have changed: ${{ steps.changed-files-specific.outputs.all_changed_files }}"
+ yarn docs:build
+
+ - name: Commit changes
+ uses: EndBug/add-and-commit@v9
+ if: steps.changed-files-fork-point.outputs.only_modified == 'true'
+ with:
+ message: 'Update docs'
+ add: 'docs/*'
+
- name: Verify Docs
run: yarn docs:verify
From 058f1c2edf4908f0bbb63e955bee6e6e359f7caf Mon Sep 17 00:00:00 2001
From: Sidharth Vinod
Date: Mon, 3 Oct 2022 11:55:33 +0800
Subject: [PATCH 002/129] chore: Update docs path
---
.github/workflows/lint.yml | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml
index aa80e5c6e..13b2c4ebe 100644
--- a/.github/workflows/lint.yml
+++ b/.github/workflows/lint.yml
@@ -54,7 +54,7 @@ jobs:
with:
use_fork_point: 'true'
files: |
- src/docs/*
+ packages/mermaid/src/docs/*
- name: Run step if any file(s) in the docs folder change
if: steps.changed-files-fork-point.outputs.only_modified == 'true'
@@ -68,7 +68,7 @@ jobs:
if: steps.changed-files-fork-point.outputs.only_modified == 'true'
with:
message: 'Update docs'
- add: 'docs/*'
+ add: 'packages/mermaid/docs/*'
- name: Verify Docs
run: pnpm run docs:verify
From 8d9800c72709206a182db190df5b4e0447d79aa4 Mon Sep 17 00:00:00 2001
From: Sidharth Vinod
Date: Mon, 3 Oct 2022 11:57:19 +0800
Subject: [PATCH 003/129] fix(docs): Test auto commit
---
packages/mermaid/src/docs/classDiagram.md | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/packages/mermaid/src/docs/classDiagram.md b/packages/mermaid/src/docs/classDiagram.md
index f46d3689c..51383fb6a 100644
--- a/packages/mermaid/src/docs/classDiagram.md
+++ b/packages/mermaid/src/docs/classDiagram.md
@@ -1,7 +1,8 @@
# Class diagrams
> "In software engineering, a class diagram in the Unified Modeling Language (UML) is a type of static structure diagram that describes the structure of a system by showing the system's classes, their attributes, operations (or methods), and the relationships among objects."
-> Wikipedia
+>
+> -Wikipedia
The class diagram is the main building block of object-oriented modeling. It is used for general conceptual modeling of the structure of the application, and for detailed modeling to translate the models into programming code. Class diagrams can also be used for data modeling. The classes in a class diagram represent both the main elements, interactions in the application, and the classes to be programmed.
From d367e832bed51bd60204316f1765f4df2e863619 Mon Sep 17 00:00:00 2001
From: Sidharth Vinod
Date: Mon, 3 Oct 2022 12:00:59 +0800
Subject: [PATCH 004/129] fix(docs): Test auto commit
---
.github/workflows/lint.yml | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml
index 13b2c4ebe..c0b0a7f28 100644
--- a/.github/workflows/lint.yml
+++ b/.github/workflows/lint.yml
@@ -21,9 +21,9 @@ jobs:
- uses: actions/checkout@v3
if: ${{ github.event_name == 'pull_request' }}
with:
+ # repository: ${{ github.event.pull_request.head.repo.full_name }}
+ # ref: ${{ github.event.pull_request.head.ref }}
fetch-depth: 2
- repository: ${{ github.event.pull_request.head.repo.full_name }}
- ref: ${{ github.event.pull_request.head.ref }}
- uses: actions/checkout@v3
if: ${{ github.event_name != 'pull_request' }}
From 75db08a60c944e749b5fac5558dc49725fbe858f Mon Sep 17 00:00:00 2001
From: Sidharth Vinod
Date: Mon, 3 Oct 2022 12:05:48 +0800
Subject: [PATCH 005/129] fix(docs): Test auto commit
---
.github/workflows/lint.yml | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml
index c0b0a7f28..fc1121c71 100644
--- a/.github/workflows/lint.yml
+++ b/.github/workflows/lint.yml
@@ -57,7 +57,7 @@ jobs:
packages/mermaid/src/docs/*
- name: Run step if any file(s) in the docs folder change
- if: steps.changed-files-fork-point.outputs.only_modified == 'true'
+ if: steps.changed-files-fork-point.outputs.any_modified == 'true'
run: |
echo "Only files in the src/docs folder has changed."
echo "List all the files that have changed: ${{ steps.changed-files-specific.outputs.all_changed_files }}"
@@ -65,7 +65,7 @@ jobs:
- name: Commit changes
uses: EndBug/add-and-commit@v9
- if: steps.changed-files-fork-point.outputs.only_modified == 'true'
+ if: steps.changed-files-fork-point.outputs.any_modified == 'true'
with:
message: 'Update docs'
add: 'packages/mermaid/docs/*'
From 1d8d677d81570628545437ff2adb487dc6c0d51e Mon Sep 17 00:00:00 2001
From: Sidharth Vinod
Date: Mon, 3 Oct 2022 14:03:44 +0800
Subject: [PATCH 006/129] fix: File location
---
.github/workflows/lint.yml | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml
index fc1121c71..6ca6b3519 100644
--- a/.github/workflows/lint.yml
+++ b/.github/workflows/lint.yml
@@ -55,6 +55,7 @@ jobs:
use_fork_point: 'true'
files: |
packages/mermaid/src/docs/*
+ packages/mermaid/src/docs.mts
- name: Run step if any file(s) in the docs folder change
if: steps.changed-files-fork-point.outputs.any_modified == 'true'
@@ -68,7 +69,7 @@ jobs:
if: steps.changed-files-fork-point.outputs.any_modified == 'true'
with:
message: 'Update docs'
- add: 'packages/mermaid/docs/*'
+ add: 'docs/*'
- name: Verify Docs
run: pnpm run docs:verify
From 3bae25fe6b353d3621ab4e68d3eee47b47ed8305 Mon Sep 17 00:00:00 2001
From: Sidharth Vinod
Date: Mon, 3 Oct 2022 14:15:28 +0800
Subject: [PATCH 007/129] split lint docs action
---
.github/workflows/lint-docs.yml | 63 +++++++++++++++++++++++++++++++++
.github/workflows/lint.yml | 33 -----------------
2 files changed, 63 insertions(+), 33 deletions(-)
create mode 100644 .github/workflows/lint-docs.yml
diff --git a/.github/workflows/lint-docs.yml b/.github/workflows/lint-docs.yml
new file mode 100644
index 000000000..68bda942a
--- /dev/null
+++ b/.github/workflows/lint-docs.yml
@@ -0,0 +1,63 @@
+name: Lint Docs
+
+on:
+ pull_request:
+ types:
+ - opened
+ - synchronize
+ - ready_for_review
+
+permissions:
+ contents: write
+
+jobs:
+ lint:
+ runs-on: ubuntu-latest
+ strategy:
+ matrix:
+ node-version: [16.x]
+ steps:
+ - uses: actions/checkout@v3
+ if: ${{ github.event_name == 'pull_request' }}
+ with:
+ repository: ${{ github.event.pull_request.head.repo.full_name }}
+ ref: ${{ github.event.pull_request.head.ref }}
+ fetch-depth: 0
+
+ - uses: pnpm/action-setup@v2
+ # uses version from "packageManager" field in package.json
+
+ - name: Setup Node.js ${{ matrix.node-version }}
+ uses: actions/setup-node@v3
+ with:
+ cache: pnpm
+ node-version: ${{ matrix.node-version }}
+
+ - name: Install Packages
+ run: |
+ pnpm install --frozen-lockfile
+ env:
+ CYPRESS_CACHE_FOLDER: .cache/Cypress
+
+ - name: Run changed-files using the fork point of a pull request
+ id: changed-files-fork-point
+ uses: tj-actions/changed-files@v29
+ with:
+ use_fork_point: 'true'
+ files: |
+ packages/mermaid/src/docs/*
+ packages/mermaid/src/docs.mts
+
+ - name: Run step if any file(s) in the docs folder change
+ if: steps.changed-files-fork-point.outputs.any_modified == 'true'
+ run: |
+ echo "Only files in the src/docs folder has changed."
+ echo "List all the files that have changed: ${{ steps.changed-files-specific.outputs.all_changed_files }}"
+ yarn docs:build
+
+ - name: Commit changes
+ uses: EndBug/add-and-commit@v9
+ if: steps.changed-files-fork-point.outputs.any_modified == 'true'
+ with:
+ message: 'Update docs'
+ add: 'docs/*'
diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml
index 6ca6b3519..dd2f7aa3b 100644
--- a/.github/workflows/lint.yml
+++ b/.github/workflows/lint.yml
@@ -19,16 +19,6 @@ jobs:
node-version: [16.x]
steps:
- uses: actions/checkout@v3
- if: ${{ github.event_name == 'pull_request' }}
- with:
- # repository: ${{ github.event.pull_request.head.repo.full_name }}
- # ref: ${{ github.event.pull_request.head.ref }}
- fetch-depth: 2
-
- - uses: actions/checkout@v3
- if: ${{ github.event_name != 'pull_request' }}
- with:
- fetch-depth: 2
- uses: pnpm/action-setup@v2
# uses version from "packageManager" field in package.json
@@ -48,28 +38,5 @@ jobs:
- name: Run Linting
run: pnpm run lint
- - name: Run changed-files using the fork point of a pull request
- id: changed-files-fork-point
- uses: tj-actions/changed-files@v29
- with:
- use_fork_point: 'true'
- files: |
- packages/mermaid/src/docs/*
- packages/mermaid/src/docs.mts
-
- - name: Run step if any file(s) in the docs folder change
- if: steps.changed-files-fork-point.outputs.any_modified == 'true'
- run: |
- echo "Only files in the src/docs folder has changed."
- echo "List all the files that have changed: ${{ steps.changed-files-specific.outputs.all_changed_files }}"
- yarn docs:build
-
- - name: Commit changes
- uses: EndBug/add-and-commit@v9
- if: steps.changed-files-fork-point.outputs.any_modified == 'true'
- with:
- message: 'Update docs'
- add: 'docs/*'
-
- name: Verify Docs
run: pnpm run docs:verify
From 8d6af3dfedd7fb564e889496db6e2e12e1eec012 Mon Sep 17 00:00:00 2001
From: Sidharth Vinod
Date: Mon, 3 Oct 2022 14:21:54 +0800
Subject: [PATCH 008/129] split lint docs action
---
.github/workflows/lint-docs.yml | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/.github/workflows/lint-docs.yml b/.github/workflows/lint-docs.yml
index 68bda942a..60faeda31 100644
--- a/.github/workflows/lint-docs.yml
+++ b/.github/workflows/lint-docs.yml
@@ -20,8 +20,8 @@ jobs:
- uses: actions/checkout@v3
if: ${{ github.event_name == 'pull_request' }}
with:
- repository: ${{ github.event.pull_request.head.repo.full_name }}
- ref: ${{ github.event.pull_request.head.ref }}
+ # repository: ${{ github.event.pull_request.head.repo.full_name }}
+ # ref: ${{ github.event.pull_request.head.ref }}
fetch-depth: 0
- uses: pnpm/action-setup@v2
@@ -49,7 +49,7 @@ jobs:
packages/mermaid/src/docs.mts
- name: Run step if any file(s) in the docs folder change
- if: steps.changed-files-fork-point.outputs.any_modified == 'true'
+ if: steps.changed-files-fork-point.outputs.only_modified == 'true'
run: |
echo "Only files in the src/docs folder has changed."
echo "List all the files that have changed: ${{ steps.changed-files-specific.outputs.all_changed_files }}"
@@ -57,7 +57,7 @@ jobs:
- name: Commit changes
uses: EndBug/add-and-commit@v9
- if: steps.changed-files-fork-point.outputs.any_modified == 'true'
+ if: steps.changed-files-fork-point.outputs.only_modified == 'true'
with:
message: 'Update docs'
add: 'docs/*'
From 9c5c85d34ac1777a93b8e80b15720a5fccbeb57c Mon Sep 17 00:00:00 2001
From: Sidharth Vinod
Date: Mon, 3 Oct 2022 14:24:51 +0800
Subject: [PATCH 009/129] Run doc lint only if files changed
---
.github/workflows/lint-docs.yml | 33 ++++++++++++++++++---------------
1 file changed, 18 insertions(+), 15 deletions(-)
diff --git a/.github/workflows/lint-docs.yml b/.github/workflows/lint-docs.yml
index 60faeda31..734363a22 100644
--- a/.github/workflows/lint-docs.yml
+++ b/.github/workflows/lint-docs.yml
@@ -24,21 +24,6 @@ jobs:
# ref: ${{ github.event.pull_request.head.ref }}
fetch-depth: 0
- - uses: pnpm/action-setup@v2
- # uses version from "packageManager" field in package.json
-
- - name: Setup Node.js ${{ matrix.node-version }}
- uses: actions/setup-node@v3
- with:
- cache: pnpm
- node-version: ${{ matrix.node-version }}
-
- - name: Install Packages
- run: |
- pnpm install --frozen-lockfile
- env:
- CYPRESS_CACHE_FOLDER: .cache/Cypress
-
- name: Run changed-files using the fork point of a pull request
id: changed-files-fork-point
uses: tj-actions/changed-files@v29
@@ -48,6 +33,24 @@ jobs:
packages/mermaid/src/docs/*
packages/mermaid/src/docs.mts
+ - uses: pnpm/action-setup@v2
+ if: steps.changed-files-fork-point.outputs.only_modified == 'true'
+ # uses version from "packageManager" field in package.json
+
+ - name: Setup Node.js ${{ matrix.node-version }}
+ uses: actions/setup-node@v3
+ if: steps.changed-files-fork-point.outputs.only_modified == 'true'
+ with:
+ cache: pnpm
+ node-version: ${{ matrix.node-version }}
+
+ - name: Install Packages
+ if: steps.changed-files-fork-point.outputs.only_modified == 'true'
+ run: |
+ pnpm install --frozen-lockfile
+ env:
+ CYPRESS_CACHE_FOLDER: .cache/Cypress
+
- name: Run step if any file(s) in the docs folder change
if: steps.changed-files-fork-point.outputs.only_modified == 'true'
run: |
From 0a547e524e1b6f9b98489a847670dea6733d10ab Mon Sep 17 00:00:00 2001
From: Sidharth Vinod
Date: Mon, 3 Oct 2022 14:30:46 +0800
Subject: [PATCH 010/129] Run doc lint only if files changed
---
.github/workflows/lint-docs.yml | 12 ++++++------
1 file changed, 6 insertions(+), 6 deletions(-)
diff --git a/.github/workflows/lint-docs.yml b/.github/workflows/lint-docs.yml
index 734363a22..20caab6f0 100644
--- a/.github/workflows/lint-docs.yml
+++ b/.github/workflows/lint-docs.yml
@@ -18,17 +18,17 @@ jobs:
node-version: [16.x]
steps:
- uses: actions/checkout@v3
- if: ${{ github.event_name == 'pull_request' }}
- with:
- # repository: ${{ github.event.pull_request.head.repo.full_name }}
- # ref: ${{ github.event.pull_request.head.ref }}
- fetch-depth: 0
+ # if: ${{ github.event_name == 'pull_request' }}
+ # with:
+ # fetch-depth: 0
+ # repository: ${{ github.event.pull_request.head.repo.full_name }}
+ # ref: ${{ github.event.pull_request.head.ref }}
- name: Run changed-files using the fork point of a pull request
id: changed-files-fork-point
uses: tj-actions/changed-files@v29
with:
- use_fork_point: 'true'
+ # use_fork_point: 'true'
files: |
packages/mermaid/src/docs/*
packages/mermaid/src/docs.mts
From 455c61b2cf38fd8c9739a3b97029cb935574c168 Mon Sep 17 00:00:00 2001
From: Sidharth Vinod
Date: Mon, 3 Oct 2022 14:41:52 +0800
Subject: [PATCH 011/129] Run doc lint only if files changed
---
.github/workflows/lint-docs.yml | 24 ++++++++++--------------
1 file changed, 10 insertions(+), 14 deletions(-)
diff --git a/.github/workflows/lint-docs.yml b/.github/workflows/lint-docs.yml
index 20caab6f0..312de8b1c 100644
--- a/.github/workflows/lint-docs.yml
+++ b/.github/workflows/lint-docs.yml
@@ -18,41 +18,37 @@ jobs:
node-version: [16.x]
steps:
- uses: actions/checkout@v3
- # if: ${{ github.event_name == 'pull_request' }}
- # with:
- # fetch-depth: 0
- # repository: ${{ github.event.pull_request.head.repo.full_name }}
- # ref: ${{ github.event.pull_request.head.ref }}
+ with:
+ repository: ${{ github.event.pull_request.head.repo.full_name }}
+ ref: ${{ github.event.pull_request.head.ref }}
- - name: Run changed-files using the fork point of a pull request
- id: changed-files-fork-point
+ - name: Check if source docs are changed
+ id: changed-docs
uses: tj-actions/changed-files@v29
with:
- # use_fork_point: 'true'
files: |
packages/mermaid/src/docs/*
packages/mermaid/src/docs.mts
- uses: pnpm/action-setup@v2
- if: steps.changed-files-fork-point.outputs.only_modified == 'true'
- # uses version from "packageManager" field in package.json
+ if: steps.changed-docs.outputs.only_modified == 'true'
- name: Setup Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
- if: steps.changed-files-fork-point.outputs.only_modified == 'true'
+ if: steps.changed-docs.outputs.only_modified == 'true'
with:
cache: pnpm
node-version: ${{ matrix.node-version }}
- name: Install Packages
- if: steps.changed-files-fork-point.outputs.only_modified == 'true'
+ if: steps.changed-docs.outputs.only_modified == 'true'
run: |
pnpm install --frozen-lockfile
env:
CYPRESS_CACHE_FOLDER: .cache/Cypress
- name: Run step if any file(s) in the docs folder change
- if: steps.changed-files-fork-point.outputs.only_modified == 'true'
+ if: steps.changed-docs.outputs.only_modified == 'true'
run: |
echo "Only files in the src/docs folder has changed."
echo "List all the files that have changed: ${{ steps.changed-files-specific.outputs.all_changed_files }}"
@@ -60,7 +56,7 @@ jobs:
- name: Commit changes
uses: EndBug/add-and-commit@v9
- if: steps.changed-files-fork-point.outputs.only_modified == 'true'
+ if: steps.changed-docs.outputs.only_modified == 'true'
with:
message: 'Update docs'
add: 'docs/*'
From 563c51d4311f1ff8b159355f8553905348d4b86a Mon Sep 17 00:00:00 2001
From: Sidharth Vinod
Date: Mon, 3 Oct 2022 14:49:35 +0800
Subject: [PATCH 012/129] Get base sha from PR
---
.github/workflows/lint-docs.yml | 12 ++++++++++++
1 file changed, 12 insertions(+)
diff --git a/.github/workflows/lint-docs.yml b/.github/workflows/lint-docs.yml
index 312de8b1c..d9f0ddae0 100644
--- a/.github/workflows/lint-docs.yml
+++ b/.github/workflows/lint-docs.yml
@@ -22,10 +22,22 @@ jobs:
repository: ${{ github.event.pull_request.head.repo.full_name }}
ref: ${{ github.event.pull_request.head.ref }}
+ - name: Get branch name
+ id: branch-name
+ uses: tj-actions/branch-names@v5
+
+ - uses: nrwl/last-successful-commit-action@v1
+ id: last_successful_commit_pull_request
+ with:
+ branch: ${{ steps.branch-name.outputs.base_ref_branch }}
+ workflow_id: 'lint-docs.yml'
+ github_token: ${{ secrets.GITHUB_TOKEN }}
+
- name: Check if source docs are changed
id: changed-docs
uses: tj-actions/changed-files@v29
with:
+ base_sha: ${{ steps.last_successful_commit_pull_request.outputs.commit_hash }}
files: |
packages/mermaid/src/docs/*
packages/mermaid/src/docs.mts
From d05fd25339fd4be4237a60a7710f8abc0d46b868 Mon Sep 17 00:00:00 2001
From: Sidharth Vinod
Date: Tue, 15 Nov 2022 23:59:17 +0530
Subject: [PATCH 013/129] Fix #3799: Remove `type` from package.json
---
packages/mermaid/package.json | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/packages/mermaid/package.json b/packages/mermaid/package.json
index 9cbc695b1..f8ff46325 100644
--- a/packages/mermaid/package.json
+++ b/packages/mermaid/package.json
@@ -1,11 +1,10 @@
{
"name": "mermaid",
- "version": "9.2.2",
+ "version": "9.2.3-rc.1",
"description": "Markdownish syntax for generating flowcharts, sequence diagrams, class diagrams, gantt charts and git graphs.",
"main": "./dist/mermaid.min.js",
"module": "./dist/mermaid.core.mjs",
"types": "./dist/mermaid.d.ts",
- "type": "commonjs",
"exports": {
".": {
"require": "./dist/mermaid.min.js",
From 3358406e685e22e7621a0e4851ac0ff02ad21f19 Mon Sep 17 00:00:00 2001
From: Sidharth Vinod
Date: Wed, 16 Nov 2022 00:06:47 +0530
Subject: [PATCH 014/129] fix: release-preview-publish.yml
---
.github/workflows/release-preview-publish.yml | 16 +++++++++++-----
1 file changed, 11 insertions(+), 5 deletions(-)
diff --git a/.github/workflows/release-preview-publish.yml b/.github/workflows/release-preview-publish.yml
index 2b2ff559b..da12cb5cc 100644
--- a/.github/workflows/release-preview-publish.yml
+++ b/.github/workflows/release-preview-publish.yml
@@ -10,21 +10,27 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
+
+ - uses: pnpm/action-setup@v2
+
- name: Setup Node.js
uses: actions/setup-node@v3
with:
+ cache: pnpm
node-version: 18.x
- - name: Install Yarn
- run: npm i yarn --global
+
+ - name: Install Packages
+ run: |
+ pnpm install --frozen-lockfile
+ env:
+ CYPRESS_CACHE_FOLDER: .cache/Cypress
- name: Install Json
run: npm i json --global
- - name: Install Packages
- run: yarn install --frozen-lockfile
-
- name: Publish
run: |
+ cd packages/mermaid
PREVIEW_VERSION=8
VERSION=$(echo ${{github.ref}} | tail -c +20)-preview.$PREVIEW_VERSION
echo $VERSION
From 8d96518092ce582cbce38c391d2cb760eb33ecef Mon Sep 17 00:00:00 2001
From: "Ashley Engelund (weedySeaDragon @ github)"
Date: Tue, 15 Nov 2022 13:47:16 -0800
Subject: [PATCH 015/129] accessibility.js -> ts; + set aria-roledescription;
add spec
---
packages/mermaid/src/accessibility.js | 29 ---------
packages/mermaid/src/accessibility.spec.ts | 73 ++++++++++++++++++++++
packages/mermaid/src/accessibility.ts | 45 +++++++++++++
3 files changed, 118 insertions(+), 29 deletions(-)
delete mode 100644 packages/mermaid/src/accessibility.js
create mode 100644 packages/mermaid/src/accessibility.spec.ts
create mode 100644 packages/mermaid/src/accessibility.ts
diff --git a/packages/mermaid/src/accessibility.js b/packages/mermaid/src/accessibility.js
deleted file mode 100644
index c59ba270c..000000000
--- a/packages/mermaid/src/accessibility.js
+++ /dev/null
@@ -1,29 +0,0 @@
-/**
- * This method will add a basic title and description element to a chart. The yy parser will need to
- * respond to getAccTitle and getAccDescription, where the title is the title element on the chart,
- * which is generally not displayed and the accDescription is the description element on the chart,
- * which is never displayed.
- *
- * The following charts display their title as a visual and accessibility element: gantt
- *
- * @param yy_parser
- * @param svg
- * @param id
- */
-export default function addSVGAccessibilityFields(yy_parser, svg, id) {
- if (typeof svg.insert === 'undefined') {
- return;
- }
-
- let title_string = yy_parser.getAccTitle();
- let description = yy_parser.getAccDescription();
- svg.attr('role', 'img').attr('aria-labelledby', 'chart-title-' + id + ' chart-desc-' + id);
- svg
- .insert('desc', ':first-child')
- .attr('id', 'chart-desc-' + id)
- .text(description);
- svg
- .insert('title', ':first-child')
- .attr('id', 'chart-title-' + id)
- .text(title_string);
-}
diff --git a/packages/mermaid/src/accessibility.spec.ts b/packages/mermaid/src/accessibility.spec.ts
new file mode 100644
index 000000000..29a2f125d
--- /dev/null
+++ b/packages/mermaid/src/accessibility.spec.ts
@@ -0,0 +1,73 @@
+// Spec/tests for accessibility
+
+import { setA11yDiagramInfo, addSVGa11yTitleDescription } from './accessibility';
+
+import { MockedD3 } from './tests/MockedD3';
+
+const fauxSvgNode = new MockedD3();
+
+const MockedDiagramDb = {
+ getAccTitle: vi.fn().mockReturnValue('the title'),
+ getAccDescription: vi.fn().mockReturnValue('the description'),
+};
+
+describe('setA11yDiagramInfo', () => {
+ it('sets the aria-roledescription to the diagram type', () => {
+ // @ts-ignore Required to easily handle the d3 select types
+ const svg_attr_spy = vi.spyOn(fauxSvgNode, 'attr').mockReturnValue(fauxSvgNode);
+ setA11yDiagramInfo(fauxSvgNode, 'flowchart');
+ expect(svg_attr_spy).toHaveBeenCalledWith('aria-roledescription', 'flowchart');
+ });
+});
+
+describe('addSVGa11yTitleDescription', () => {
+ const testDiagramDb = MockedDiagramDb;
+ const givenId = 'theBaseId';
+
+ describe('with the given svg d3 object:', () => {
+ it('does nothing if there is no insert defined', () => {
+ const noInsertSvg = {
+ attr: vi.fn(),
+ };
+ const noInsert_attr_spy = vi.spyOn(noInsertSvg, 'attr').mockReturnValue(noInsertSvg);
+ addSVGa11yTitleDescription(testDiagramDb, noInsertSvg, givenId);
+ expect(noInsert_attr_spy).not.toHaveBeenCalled();
+ });
+
+ it('sets aria-labelledby to the title id and the description id inserted as children', () => {
+ // @ts-ignore Required to easily handle the d3 select types
+ const svg_attr_spy = vi.spyOn(fauxSvgNode, 'attr').mockReturnValue(fauxSvgNode);
+ addSVGa11yTitleDescription(testDiagramDb, fauxSvgNode, givenId);
+ expect(svg_attr_spy).toHaveBeenCalledWith(
+ 'aria-labelledby',
+ `chart-title-${givenId} chart-desc-${givenId}`
+ );
+ });
+
+ it('inserts a title tag as the first child with the text set to the accTitle returned by the diagram db', () => {
+ const faux_title = new MockedD3();
+ const svg_insert_spy = vi.spyOn(fauxSvgNode, 'insert').mockReturnValue(faux_title);
+ // @ts-ignore Required to easily handle the d3 select types
+ const title_attr_spy = vi.spyOn(faux_title, 'attr').mockReturnValue(faux_title);
+ const title_text_spy = vi.spyOn(faux_title, 'text');
+
+ addSVGa11yTitleDescription(testDiagramDb, fauxSvgNode, givenId);
+ expect(svg_insert_spy).toHaveBeenCalledWith('title', ':first-child');
+ expect(title_attr_spy).toHaveBeenCalledWith('id', `chart-title-` + givenId);
+ expect(title_text_spy).toHaveBeenNthCalledWith(2, 'the title');
+ });
+
+ it('inserts a desc tag as the 2nd child with the text set to accDescription returned by the diagram db', () => {
+ const faux_desc = new MockedD3();
+ const svg_insert_spy = vi.spyOn(fauxSvgNode, 'insert').mockReturnValue(faux_desc);
+ // @ts-ignore Required to easily handle the d3 select types
+ const desc_attr_spy = vi.spyOn(faux_desc, 'attr').mockReturnValue(faux_desc);
+ const desc_text_spy = vi.spyOn(faux_desc, 'text');
+
+ addSVGa11yTitleDescription(testDiagramDb, fauxSvgNode, givenId);
+ expect(svg_insert_spy).toHaveBeenCalledWith('desc', ':first-child');
+ expect(desc_attr_spy).toHaveBeenCalledWith('id', `chart-desc-` + givenId);
+ expect(desc_text_spy).toHaveBeenNthCalledWith(1, 'the description');
+ });
+ });
+});
diff --git a/packages/mermaid/src/accessibility.ts b/packages/mermaid/src/accessibility.ts
new file mode 100644
index 000000000..246a88f66
--- /dev/null
+++ b/packages/mermaid/src/accessibility.ts
@@ -0,0 +1,45 @@
+/**
+ * Accessibility (a11y) functions, types, helpers
+ *
+ */
+
+// This is just a convenience alias to make it clear the type is a d3 object. (It's easier to make it 'any' instead of the comple typing set in d3)
+type D3object = any;
+
+/**
+ * Set the accessibility (a11y) information for the svg d3 object using the given diagram type
+ * Note that the svg element role _should_ be mapped to a 'graphics-document' by default. Thus we don't set it here, but can set it in the future if needed.
+ * @param svg - d3 object that contains the SVG HTML element
+ * @param diagramType - diagram name for to the aria-roledescription
+ */
+export function setA11yDiagramInfo(svg: D3object, diagramType: string) {
+ svg.attr('aria-roledescription', diagramType);
+}
+
+/**
+ * This method will add a basic title and description element to a chart. The yy parser will need to
+ * respond to getAccTitle and getAccDescription,
+ * where the accessible title is the title element on the chart.
+ *
+ * Note that the accessible title is generally _not_ displayed
+ * and the accessible description is never displayed.
+ *
+ *
+ * The following charts display their title as a visual and accessibility element: gantt. TODO fix this
+ *
+ * @param diagramDb - the 'db' object/module for a diagram. Must respond to getAccTitle() and getAccDescription()
+ * @param svg - the d3 object that represents the svg element
+ * @param baseId - the id to use as the base for the title and description
+ */
+export function addSVGa11yTitleDescription(diagramDb: any, svg: D3object, baseId: string) {
+ if (typeof svg.insert === 'undefined') {
+ return;
+ }
+
+ const titleId = 'chart-title-' + baseId;
+ const descId = 'chart-desc-' + baseId;
+
+ svg.attr('aria-labelledby', titleId + ' ' + descId);
+ svg.insert('desc', ':first-child').attr('id', descId).text(diagramDb.getAccDescription());
+ svg.insert('title', ':first-child').attr('id', titleId).text(diagramDb.getAccTitle());
+}
From 0d9566dd711374a35fc872f4a327d4a518dfd04b Mon Sep 17 00:00:00 2001
From: "Ashley Engelund (weedySeaDragon @ github)"
Date: Tue, 15 Nov 2022 13:48:35 -0800
Subject: [PATCH 016/129] diagrams: use a11y title,desc specific method (was
renamed)
---
packages/mermaid/src/diagrams/c4/c4Renderer.js | 4 ++--
packages/mermaid/src/diagrams/class/classRenderer-v2.js | 4 ++--
packages/mermaid/src/diagrams/class/classRenderer.js | 4 ++--
packages/mermaid/src/diagrams/er/erRenderer.js | 4 ++--
packages/mermaid/src/diagrams/flowchart/flowRenderer-v2.js | 4 ++--
packages/mermaid/src/diagrams/flowchart/flowRenderer.js | 4 ++--
packages/mermaid/src/diagrams/gantt/ganttRenderer.js | 4 ++--
packages/mermaid/src/diagrams/git/gitGraphRenderer.js | 4 ++--
packages/mermaid/src/diagrams/pie/pieRenderer.js | 4 ++--
.../mermaid/src/diagrams/requirement/requirementRenderer.js | 4 ++--
packages/mermaid/src/diagrams/sequence/sequenceRenderer.ts | 4 +++-
packages/mermaid/src/diagrams/state/stateRenderer-v2.js | 4 ++--
packages/mermaid/src/diagrams/state/stateRenderer.js | 4 ++--
packages/mermaid/src/diagrams/user-journey/journeyRenderer.ts | 3 ++-
14 files changed, 29 insertions(+), 26 deletions(-)
diff --git a/packages/mermaid/src/diagrams/c4/c4Renderer.js b/packages/mermaid/src/diagrams/c4/c4Renderer.js
index a9072346a..a2d7813c6 100644
--- a/packages/mermaid/src/diagrams/c4/c4Renderer.js
+++ b/packages/mermaid/src/diagrams/c4/c4Renderer.js
@@ -8,7 +8,7 @@ import * as configApi from '../../config';
import assignWithDepth from '../../assignWithDepth';
import { wrapLabel, calculateTextWidth, calculateTextHeight } from '../../utils';
import { configureSvgSize } from '../../setupGraphViewbox';
-import addSVGAccessibilityFields from '../../accessibility';
+import { addSVGa11yTitleDescription } from '../../accessibility';
let globalBoundaryMaxX = 0,
globalBoundaryMaxY = 0;
@@ -676,7 +676,7 @@ export const draw = function (_text, id, _version, diagObj) {
(height + extraVertForTitle)
);
- addSVGAccessibilityFields(parser.yy, diagram, id);
+ addSVGa11yTitleDescription(parser.yy, diagram, id);
log.debug(`models:`, box);
};
diff --git a/packages/mermaid/src/diagrams/class/classRenderer-v2.js b/packages/mermaid/src/diagrams/class/classRenderer-v2.js
index fbc2e4833..75e7cdafb 100644
--- a/packages/mermaid/src/diagrams/class/classRenderer-v2.js
+++ b/packages/mermaid/src/diagrams/class/classRenderer-v2.js
@@ -7,7 +7,7 @@ import { curveLinear } from 'd3';
import { interpolateToCurve, getStylesFromArray } from '../../utils';
import { setupGraphViewbox } from '../../setupGraphViewbox';
import common from '../common/common';
-import addSVGAccessibilityFields from '../../accessibility';
+import { addSVGa11yTitleDescription } from '../../accessibility';
let idCache = {};
@@ -452,7 +452,7 @@ export const draw = function (text, id, _version, diagObj) {
}
}
- addSVGAccessibilityFields(diagObj.db, svg, id);
+ addSVGa11yTitleDescription(diagObj.db, svg, id);
// If node has a link, wrap it in an anchor SVG object.
// const keys = Object.keys(classes);
// keys.forEach(function(key) {
diff --git a/packages/mermaid/src/diagrams/class/classRenderer.js b/packages/mermaid/src/diagrams/class/classRenderer.js
index 23b586192..4e4b31a82 100644
--- a/packages/mermaid/src/diagrams/class/classRenderer.js
+++ b/packages/mermaid/src/diagrams/class/classRenderer.js
@@ -5,7 +5,7 @@ import { log } from '../../logger';
import svgDraw from './svgDraw';
import { configureSvgSize } from '../../setupGraphViewbox';
import { getConfig } from '../../config';
-import addSVGAccessibilityFields from '../../accessibility';
+import { addSVGa11yTitleDescription } from '../../accessibility';
let idCache = {};
const padding = 20;
@@ -272,7 +272,7 @@ export const draw = function (text, id, _version, diagObj) {
const vBox = `${svgBounds.x - padding} ${svgBounds.y - padding} ${width} ${height}`;
log.debug(`viewBox ${vBox}`);
diagram.attr('viewBox', vBox);
- addSVGAccessibilityFields(diagObj.db, diagram, id);
+ addSVGa11yTitleDescription(diagObj.db, diagram, id);
};
export default {
diff --git a/packages/mermaid/src/diagrams/er/erRenderer.js b/packages/mermaid/src/diagrams/er/erRenderer.js
index 323bb4607..f29eb44d7 100644
--- a/packages/mermaid/src/diagrams/er/erRenderer.js
+++ b/packages/mermaid/src/diagrams/er/erRenderer.js
@@ -5,7 +5,7 @@ import { getConfig } from '../../config';
import { log } from '../../logger';
import erMarkers from './erMarkers';
import { configureSvgSize } from '../../setupGraphViewbox';
-import addSVGAccessibilityFields from '../../accessibility';
+import { addSVGa11yTitleDescription } from '../../accessibility';
import { parseGenericTypes } from '../common/common';
import { v4 as uuid4 } from 'uuid';
@@ -657,7 +657,7 @@ export const draw = function (text, id, _version, diagObj) {
svg.attr('viewBox', `${svgBounds.x - padding} ${svgBounds.y - padding} ${width} ${height}`);
- addSVGAccessibilityFields(diagObj.db, svg, id);
+ addSVGa11yTitleDescription(diagObj.db, svg, id);
}; // draw
/**
diff --git a/packages/mermaid/src/diagrams/flowchart/flowRenderer-v2.js b/packages/mermaid/src/diagrams/flowchart/flowRenderer-v2.js
index 6b7c4c1bf..a5f991a86 100644
--- a/packages/mermaid/src/diagrams/flowchart/flowRenderer-v2.js
+++ b/packages/mermaid/src/diagrams/flowchart/flowRenderer-v2.js
@@ -10,7 +10,7 @@ import { log } from '../../logger';
import common, { evaluate } from '../common/common';
import { interpolateToCurve, getStylesFromArray } from '../../utils';
import { setupGraphViewbox } from '../../setupGraphViewbox';
-import addSVGAccessibilityFields from '../../accessibility';
+import { addSVGa11yTitleDescription } from '../../accessibility';
const conf = {};
export const setConf = function (cnf) {
@@ -431,7 +431,7 @@ export const draw = function (text, id, _version, diagObj) {
const svg = root.select(`[id="${id}"]`);
// Adds title and description to the flow chart
- addSVGAccessibilityFields(diagObj.db, svg, id);
+ addSVGa11yTitleDescription(diagObj.db, svg, id);
// Run the renderer. This is what draws the final graph.
const element = root.select('#' + id + ' g');
diff --git a/packages/mermaid/src/diagrams/flowchart/flowRenderer.js b/packages/mermaid/src/diagrams/flowchart/flowRenderer.js
index c403b7fe3..e9069ff4d 100644
--- a/packages/mermaid/src/diagrams/flowchart/flowRenderer.js
+++ b/packages/mermaid/src/diagrams/flowchart/flowRenderer.js
@@ -8,7 +8,7 @@ import common, { evaluate } from '../common/common';
import { interpolateToCurve, getStylesFromArray } from '../../utils';
import { setupGraphViewbox } from '../../setupGraphViewbox';
import flowChartShapes from './flowChartShapes';
-import addSVGAccessibilityFields from '../../accessibility';
+import { addSVGa11yTitleDescription } from '../../accessibility';
const conf = {};
export const setConf = function (cnf) {
@@ -418,7 +418,7 @@ export const draw = function (text, id, _version, diagObj) {
const svg = root.select(`[id="${id}"]`);
// Adds title and description to the flow chart
- addSVGAccessibilityFields(diagObj.db, svg, id);
+ addSVGa11yTitleDescription(diagObj.db, svg, id);
// Run the renderer. This is what draws the final graph.
const element = root.select('#' + id + ' g');
diff --git a/packages/mermaid/src/diagrams/gantt/ganttRenderer.js b/packages/mermaid/src/diagrams/gantt/ganttRenderer.js
index 9501dd024..dc92be1f0 100644
--- a/packages/mermaid/src/diagrams/gantt/ganttRenderer.js
+++ b/packages/mermaid/src/diagrams/gantt/ganttRenderer.js
@@ -19,7 +19,7 @@ import {
import common from '../common/common';
import { getConfig } from '../../config';
import { configureSvgSize } from '../../setupGraphViewbox';
-import addSVGAccessibilityFields from '../../accessibility';
+import { addSVGa11yTitleDescription } from '../../accessibility';
export const setConf = function () {
log.debug('Something is calling, setConf, remove the call');
@@ -116,7 +116,7 @@ export const draw = function (text, id, version, diagObj) {
.attr('y', conf.titleTopMargin)
.attr('class', 'titleText');
- addSVGAccessibilityFields(diagObj.db, svg, id);
+ addSVGa11yTitleDescription(diagObj.db, svg, id);
/**
* @param tasks
diff --git a/packages/mermaid/src/diagrams/git/gitGraphRenderer.js b/packages/mermaid/src/diagrams/git/gitGraphRenderer.js
index 71698a500..c9e02a1e4 100644
--- a/packages/mermaid/src/diagrams/git/gitGraphRenderer.js
+++ b/packages/mermaid/src/diagrams/git/gitGraphRenderer.js
@@ -1,7 +1,7 @@
import { select } from 'd3';
import { getConfig, setupGraphViewbox } from '../../diagram-api/diagramAPI';
import { log } from '../../logger';
-import addSVGAccessibilityFields from '../../accessibility';
+import { addSVGa11yTitleDescription } from '../../accessibility';
let allCommitsDict = {};
@@ -513,7 +513,7 @@ export const draw = function (txt, id, ver, diagObj) {
const diagram = select(`[id="${id}"]`);
// Adds title and description to the flow chart
- addSVGAccessibilityFields(diagObj.db, diagram, id);
+ addSVGa11yTitleDescription(diagObj.db, diagram, id);
drawCommits(diagram, allCommitsDict, false);
if (gitGraphConfig.showBranches) {
diff --git a/packages/mermaid/src/diagrams/pie/pieRenderer.js b/packages/mermaid/src/diagrams/pie/pieRenderer.js
index 6cbb99fa3..daddfda86 100644
--- a/packages/mermaid/src/diagrams/pie/pieRenderer.js
+++ b/packages/mermaid/src/diagrams/pie/pieRenderer.js
@@ -3,7 +3,7 @@ import { select, scaleOrdinal, pie as d3pie, arc } from 'd3';
import { log } from '../../logger';
import { configureSvgSize } from '../../setupGraphViewbox';
import * as configApi from '../../config';
-import addSVGAccessibilityFields from '../../accessibility';
+import { addSVGa11yTitleDescription } from '../../accessibility';
let conf = configApi.getConfig();
@@ -53,7 +53,7 @@ export const draw = (txt, id, _version, diagObj) => {
const diagram = root.select('#' + id);
configureSvgSize(diagram, height, width, conf.pie.useMaxWidth);
- addSVGAccessibilityFields(diagObj.db, diagram, id);
+ addSVGa11yTitleDescription(diagObj.db, diagram, id);
// Set viewBox
elem.setAttribute('viewBox', '0 0 ' + width + ' ' + height);
diff --git a/packages/mermaid/src/diagrams/requirement/requirementRenderer.js b/packages/mermaid/src/diagrams/requirement/requirementRenderer.js
index 79d67e76e..60f456f0b 100644
--- a/packages/mermaid/src/diagrams/requirement/requirementRenderer.js
+++ b/packages/mermaid/src/diagrams/requirement/requirementRenderer.js
@@ -6,7 +6,7 @@ import { configureSvgSize } from '../../setupGraphViewbox';
import common from '../common/common';
import markers from './requirementMarkers';
import { getConfig } from '../../config';
-import addSVGAccessibilityFields from '../../accessibility';
+import { addSVGa11yTitleDescription } from '../../accessibility';
let conf = {};
let relCnt = 0;
@@ -364,7 +364,7 @@ export const draw = (text, id, _version, diagObj) => {
svg.attr('viewBox', `${svgBounds.x - padding} ${svgBounds.y - padding} ${width} ${height}`);
// Adds title and description to the requirements diagram
- addSVGAccessibilityFields(diagObj.db, svg, id);
+ addSVGa11yTitleDescription(diagObj.db, svg, id);
};
export default {
diff --git a/packages/mermaid/src/diagrams/sequence/sequenceRenderer.ts b/packages/mermaid/src/diagrams/sequence/sequenceRenderer.ts
index fa943d658..bf8a512c1 100644
--- a/packages/mermaid/src/diagrams/sequence/sequenceRenderer.ts
+++ b/packages/mermaid/src/diagrams/sequence/sequenceRenderer.ts
@@ -9,9 +9,11 @@ import * as configApi from '../../config';
import assignWithDepth from '../../assignWithDepth';
import utils from '../../utils';
import { configureSvgSize } from '../../setupGraphViewbox';
-import addSVGAccessibilityFields from '../../accessibility';
+import { addSVGa11yTitleDescription } from '../../accessibility';
import Diagram from '../../Diagram';
+// FIXME insert a11y title and desc
+
let conf = {};
export const bounds = {
diff --git a/packages/mermaid/src/diagrams/state/stateRenderer-v2.js b/packages/mermaid/src/diagrams/state/stateRenderer-v2.js
index 1011fb6b1..d6bc821c4 100644
--- a/packages/mermaid/src/diagrams/state/stateRenderer-v2.js
+++ b/packages/mermaid/src/diagrams/state/stateRenderer-v2.js
@@ -5,7 +5,7 @@ import { render } from '../../dagre-wrapper/index.js';
import { log } from '../../logger';
import { configureSvgSize } from '../../setupGraphViewbox';
import common from '../common/common';
-import addSVGAccessibilityFields from '../../accessibility';
+import { addSVGa11yTitleDescription } from '../../accessibility';
import {
DEFAULT_DIAGRAM_DIRECTION,
DEFAULT_NESTED_DOC_DIR,
@@ -481,7 +481,7 @@ export const draw = function (text, id, _version, diag) {
label.insertBefore(rect, label.firstChild);
// }
}
- addSVGAccessibilityFields(diag.db, svg, id);
+ addSVGa11yTitleDescription(diag.db, svg, id);
};
export default {
diff --git a/packages/mermaid/src/diagrams/state/stateRenderer.js b/packages/mermaid/src/diagrams/state/stateRenderer.js
index 73717a645..b69d1aaee 100644
--- a/packages/mermaid/src/diagrams/state/stateRenderer.js
+++ b/packages/mermaid/src/diagrams/state/stateRenderer.js
@@ -6,7 +6,7 @@ import common from '../common/common';
import { drawState, addTitleAndBox, drawEdge } from './shapes';
import { getConfig } from '../../config';
import { configureSvgSize } from '../../setupGraphViewbox';
-import addSVGAccessibilityFields from '../../accessibility';
+import { addSVGa11yTitleDescription } from '../../accessibility';
// TODO Move conf object to main conf in mermaidAPI
let conf;
@@ -97,7 +97,7 @@ export const draw = function (text, id, _version, diagObj) {
'viewBox',
`${bounds.x - conf.padding} ${bounds.y - conf.padding} ` + width + ' ' + height
);
- addSVGAccessibilityFields(diagObj.db, diagram, id);
+ addSVGa11yTitleDescription(diagObj.db, diagram, id);
};
const getLabelWidth = (text) => {
return text ? text.length * conf.fontSizeFactor : 1;
diff --git a/packages/mermaid/src/diagrams/user-journey/journeyRenderer.ts b/packages/mermaid/src/diagrams/user-journey/journeyRenderer.ts
index 3880a243a..5a2c1283d 100644
--- a/packages/mermaid/src/diagrams/user-journey/journeyRenderer.ts
+++ b/packages/mermaid/src/diagrams/user-journey/journeyRenderer.ts
@@ -3,7 +3,8 @@ import { select } from 'd3';
import svgDraw from './svgDraw';
import { getConfig } from '../../config';
import { configureSvgSize } from '../../setupGraphViewbox';
-import addSVGAccessibilityFields from '../../accessibility';
+import { addSVGa11yTitleDescription } from '../../accessibility';
+// FIXME insert a11y title and desc
export const setConf = function (cnf) {
const keys = Object.keys(cnf);
From d99707641b33908d87bb18896a3945213f165c08 Mon Sep 17 00:00:00 2001
From: "Ashley Engelund (weedySeaDragon @ github)"
Date: Tue, 15 Nov 2022 13:49:05 -0800
Subject: [PATCH 017/129] add "roledescription" to cSpell list of words (as in
'aria-roledescription')
---
cSpell.json | 1 +
1 file changed, 1 insertion(+)
diff --git a/cSpell.json b/cSpell.json
index 08fce1d1c..3398361f4 100644
--- a/cSpell.json
+++ b/cSpell.json
@@ -60,6 +60,7 @@
"podlite",
"ranksep",
"redmine",
+ "roledescription",
"sandboxed",
"setupgraphviewbox",
"shiki",
From 1ad63d5b0b7a410fd9a1809c14bd95c1b0d927d7 Mon Sep 17 00:00:00 2001
From: Sidharth Vinod
Date: Wed, 16 Nov 2022 09:49:41 +0530
Subject: [PATCH 018/129] chore: Add working directory
---
.github/workflows/release-preview-publish.yml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/.github/workflows/release-preview-publish.yml b/.github/workflows/release-preview-publish.yml
index da12cb5cc..f5b70eedd 100644
--- a/.github/workflows/release-preview-publish.yml
+++ b/.github/workflows/release-preview-publish.yml
@@ -29,8 +29,8 @@ jobs:
run: npm i json --global
- name: Publish
+ working-directory: ./packages/mermaid
run: |
- cd packages/mermaid
PREVIEW_VERSION=8
VERSION=$(echo ${{github.ref}} | tail -c +20)-preview.$PREVIEW_VERSION
echo $VERSION
From 503114c0eb76f1b3776fd7b5ac6007eac0c64060 Mon Sep 17 00:00:00 2001
From: Sidharth Vinod
Date: Wed, 16 Nov 2022 10:22:37 +0530
Subject: [PATCH 019/129] fix: Add commit count to release preview
---
.github/workflows/release-preview-publish.yml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/.github/workflows/release-preview-publish.yml b/.github/workflows/release-preview-publish.yml
index f5b70eedd..8bcfbc357 100644
--- a/.github/workflows/release-preview-publish.yml
+++ b/.github/workflows/release-preview-publish.yml
@@ -31,7 +31,7 @@ jobs:
- name: Publish
working-directory: ./packages/mermaid
run: |
- PREVIEW_VERSION=8
+ PREVIEW_VERSION=$(git log --oneline "origin/$GITHUB_REF_NAME" ^"origin/master" | wc -l)
VERSION=$(echo ${{github.ref}} | tail -c +20)-preview.$PREVIEW_VERSION
echo $VERSION
npm version --no-git-tag-version --allow-same-version $VERSION
From 1d828fe8be8ee818c35df0a2c3dfe153d8d83e5a Mon Sep 17 00:00:00 2001
From: Sidharth Vinod
Date: Wed, 16 Nov 2022 10:27:42 +0530
Subject: [PATCH 020/129] fix: Add commit count to release preview
---
.github/workflows/release-preview-publish.yml | 2 ++
1 file changed, 2 insertions(+)
diff --git a/.github/workflows/release-preview-publish.yml b/.github/workflows/release-preview-publish.yml
index 8bcfbc357..f910c67b7 100644
--- a/.github/workflows/release-preview-publish.yml
+++ b/.github/workflows/release-preview-publish.yml
@@ -10,6 +10,8 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
+ - run: |
+ git fetch --no-tags --prune --depth=1 origin +refs/heads/master:refs/remotes/origin/master
- uses: pnpm/action-setup@v2
From 52ee234c0fec0dc2a00e78844c193963d0359d7c Mon Sep 17 00:00:00 2001
From: Sidharth Vinod
Date: Wed, 16 Nov 2022 10:31:07 +0530
Subject: [PATCH 021/129] fix: Fetch depth
---
.github/workflows/release-preview-publish.yml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/.github/workflows/release-preview-publish.yml b/.github/workflows/release-preview-publish.yml
index f910c67b7..ff57b4f58 100644
--- a/.github/workflows/release-preview-publish.yml
+++ b/.github/workflows/release-preview-publish.yml
@@ -11,7 +11,7 @@ jobs:
steps:
- uses: actions/checkout@v3
- run: |
- git fetch --no-tags --prune --depth=1 origin +refs/heads/master:refs/remotes/origin/master
+ git fetch --no-tags --prune --depth=0 origin +refs/heads/master:refs/remotes/origin/master
- uses: pnpm/action-setup@v2
From e05e0f8ae35e7e6c1739a68b76361637aea9b18e Mon Sep 17 00:00:00 2001
From: Sidharth Vinod
Date: Wed, 16 Nov 2022 10:31:49 +0530
Subject: [PATCH 022/129] fix: Fetch depth
---
.github/workflows/release-preview-publish.yml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/.github/workflows/release-preview-publish.yml b/.github/workflows/release-preview-publish.yml
index ff57b4f58..e9c4e46a3 100644
--- a/.github/workflows/release-preview-publish.yml
+++ b/.github/workflows/release-preview-publish.yml
@@ -11,7 +11,7 @@ jobs:
steps:
- uses: actions/checkout@v3
- run: |
- git fetch --no-tags --prune --depth=0 origin +refs/heads/master:refs/remotes/origin/master
+ git fetch --no-tags --prune origin +refs/heads/master:refs/remotes/origin/master
- uses: pnpm/action-setup@v2
From 2092330eec603abfd673cf782762f217bd8b5e5c Mon Sep 17 00:00:00 2001
From: Sidharth Vinod
Date: Wed, 16 Nov 2022 11:30:58 +0530
Subject: [PATCH 023/129] fix: Fetch depth
---
.github/workflows/release-preview-publish.yml | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/.github/workflows/release-preview-publish.yml b/.github/workflows/release-preview-publish.yml
index e9c4e46a3..5f4936ab6 100644
--- a/.github/workflows/release-preview-publish.yml
+++ b/.github/workflows/release-preview-publish.yml
@@ -10,8 +10,8 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- - run: |
- git fetch --no-tags --prune origin +refs/heads/master:refs/remotes/origin/master
+ with:
+ fetch-depth: 0
- uses: pnpm/action-setup@v2
From 03a11e103ec119660bf2e6b3a3294464591d0935 Mon Sep 17 00:00:00 2001
From: "Ashley Engelund (weedySeaDragon @ github)"
Date: Thu, 17 Nov 2022 12:19:31 -0800
Subject: [PATCH 024/129] (minor) fix typo
---
cypress/integration/rendering/stateDiagram-v2.spec.js | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/cypress/integration/rendering/stateDiagram-v2.spec.js b/cypress/integration/rendering/stateDiagram-v2.spec.js
index 5b43c890c..adba68ed2 100644
--- a/cypress/integration/rendering/stateDiagram-v2.spec.js
+++ b/cypress/integration/rendering/stateDiagram-v2.spec.js
@@ -328,7 +328,7 @@ describe('State diagram', () => {
}
);
});
- it('v2 it should be possibel to use a choice', () => {
+ it('v2 it should be possible to use a choice', () => {
imgSnapshotTest(
`
stateDiagram-v2
From 4d7496b8dd74a758186e54745e1d05dfc66a2000 Mon Sep 17 00:00:00 2001
From: "Ashley Engelund (weedySeaDragon @ github)"
Date: Thu, 17 Nov 2022 12:21:45 -0800
Subject: [PATCH 025/129] add error checking (empty diagramType, title, desc)
to a11y methods
---
packages/mermaid/src/accessibility.spec.ts | 219 +++++++++++++++------
packages/mermaid/src/accessibility.ts | 59 +++---
2 files changed, 194 insertions(+), 84 deletions(-)
diff --git a/packages/mermaid/src/accessibility.spec.ts b/packages/mermaid/src/accessibility.spec.ts
index 29a2f125d..7336284fe 100644
--- a/packages/mermaid/src/accessibility.spec.ts
+++ b/packages/mermaid/src/accessibility.spec.ts
@@ -1,73 +1,172 @@
-// Spec/tests for accessibility
-
+import { MockedD3 } from './tests/MockedD3';
import { setA11yDiagramInfo, addSVGa11yTitleDescription } from './accessibility';
-import { MockedD3 } from './tests/MockedD3';
+describe('accessibility', () => {
+ const fauxSvgNode = new MockedD3();
-const fauxSvgNode = new MockedD3();
-
-const MockedDiagramDb = {
- getAccTitle: vi.fn().mockReturnValue('the title'),
- getAccDescription: vi.fn().mockReturnValue('the description'),
-};
-
-describe('setA11yDiagramInfo', () => {
- it('sets the aria-roledescription to the diagram type', () => {
- // @ts-ignore Required to easily handle the d3 select types
- const svg_attr_spy = vi.spyOn(fauxSvgNode, 'attr').mockReturnValue(fauxSvgNode);
- setA11yDiagramInfo(fauxSvgNode, 'flowchart');
- expect(svg_attr_spy).toHaveBeenCalledWith('aria-roledescription', 'flowchart');
- });
-});
-
-describe('addSVGa11yTitleDescription', () => {
- const testDiagramDb = MockedDiagramDb;
- const givenId = 'theBaseId';
-
- describe('with the given svg d3 object:', () => {
- it('does nothing if there is no insert defined', () => {
- const noInsertSvg = {
- attr: vi.fn(),
- };
- const noInsert_attr_spy = vi.spyOn(noInsertSvg, 'attr').mockReturnValue(noInsertSvg);
- addSVGa11yTitleDescription(testDiagramDb, noInsertSvg, givenId);
- expect(noInsert_attr_spy).not.toHaveBeenCalled();
- });
-
- it('sets aria-labelledby to the title id and the description id inserted as children', () => {
- // @ts-ignore Required to easily handle the d3 select types
+ describe('setA11yDiagramInfo', () => {
+ it('sets the aria-roledescription to the diagram type', () => {
+ // @ts-ignore Required to easily handle the d3 select types
const svg_attr_spy = vi.spyOn(fauxSvgNode, 'attr').mockReturnValue(fauxSvgNode);
- addSVGa11yTitleDescription(testDiagramDb, fauxSvgNode, givenId);
- expect(svg_attr_spy).toHaveBeenCalledWith(
- 'aria-labelledby',
- `chart-title-${givenId} chart-desc-${givenId}`
- );
+ setA11yDiagramInfo(fauxSvgNode, 'flowchart');
+ expect(svg_attr_spy).toHaveBeenCalledWith('aria-roledescription', 'flowchart');
});
- it('inserts a title tag as the first child with the text set to the accTitle returned by the diagram db', () => {
- const faux_title = new MockedD3();
- const svg_insert_spy = vi.spyOn(fauxSvgNode, 'insert').mockReturnValue(faux_title);
+ it('does nothing if the diagram type is empty', () => {
// @ts-ignore Required to easily handle the d3 select types
- const title_attr_spy = vi.spyOn(faux_title, 'attr').mockReturnValue(faux_title);
- const title_text_spy = vi.spyOn(faux_title, 'text');
-
- addSVGa11yTitleDescription(testDiagramDb, fauxSvgNode, givenId);
- expect(svg_insert_spy).toHaveBeenCalledWith('title', ':first-child');
- expect(title_attr_spy).toHaveBeenCalledWith('id', `chart-title-` + givenId);
- expect(title_text_spy).toHaveBeenNthCalledWith(2, 'the title');
+ const svg_attr_spy = vi.spyOn(fauxSvgNode, 'attr').mockReturnValue(fauxSvgNode);
+ setA11yDiagramInfo(fauxSvgNode, '');
+ expect(svg_attr_spy).not.toHaveBeenCalled();
});
+ });
- it('inserts a desc tag as the 2nd child with the text set to accDescription returned by the diagram db', () => {
- const faux_desc = new MockedD3();
- const svg_insert_spy = vi.spyOn(fauxSvgNode, 'insert').mockReturnValue(faux_desc);
- // @ts-ignore Required to easily handle the d3 select types
- const desc_attr_spy = vi.spyOn(faux_desc, 'attr').mockReturnValue(faux_desc);
- const desc_text_spy = vi.spyOn(faux_desc, 'text');
+ describe('addSVGa11yTitleDescription', () => {
+ const givenId = 'theBaseId';
- addSVGa11yTitleDescription(testDiagramDb, fauxSvgNode, givenId);
- expect(svg_insert_spy).toHaveBeenCalledWith('desc', ':first-child');
- expect(desc_attr_spy).toHaveBeenCalledWith('id', `chart-desc-` + givenId);
- expect(desc_text_spy).toHaveBeenNthCalledWith(1, 'the description');
+ describe('with the given svg d3 object:', () => {
+ it('does nothing if there is no insert defined', () => {
+ const noInsertSvg = {
+ attr: vi.fn(),
+ };
+ const noInsert_attr_spy = vi.spyOn(noInsertSvg, 'attr').mockReturnValue(noInsertSvg);
+ addSVGa11yTitleDescription(noInsertSvg, 'some title', 'some desc', givenId);
+ expect(noInsert_attr_spy).not.toHaveBeenCalled();
+ });
+
+ describe('given an a11y title', () => {
+ const a11yTitle = 'a11y title';
+
+ describe('given an a11y description', () => {
+ const a11yDesc = 'a11y description';
+
+ it('sets aria-labelledby to the title id and the description id inserted as children', () => {
+ // @ts-ignore Required to easily handle the d3 select types
+ const svg_attr_spy = vi.spyOn(fauxSvgNode, 'attr').mockReturnValue(fauxSvgNode);
+ addSVGa11yTitleDescription(fauxSvgNode, a11yTitle, a11yDesc, givenId);
+ expect(svg_attr_spy).toHaveBeenCalledWith(
+ 'aria-labelledby',
+ `chart-title-${givenId} chart-desc-${givenId}`
+ );
+ });
+
+ it('inserts a title tag as the first child with the text set to the accTitle given', () => {
+ const faux_title = new MockedD3();
+ const svg_insert_spy = vi.spyOn(fauxSvgNode, 'insert').mockReturnValue(faux_title);
+ // @ts-ignore Required to easily handle the d3 select types
+ const title_attr_spy = vi.spyOn(faux_title, 'attr').mockReturnValue(faux_title);
+ const title_text_spy = vi.spyOn(faux_title, 'text');
+
+ addSVGa11yTitleDescription(fauxSvgNode, a11yTitle, a11yDesc, givenId);
+ expect(svg_insert_spy).toHaveBeenCalledWith('desc', ':first-child');
+ expect(title_attr_spy).toHaveBeenCalledWith('id', `chart-desc-` + givenId);
+ expect(title_text_spy).toHaveBeenNthCalledWith(1, 'a11y description');
+ });
+
+ it('inserts a desc tag as the 2nd child with the text set to accDescription given', () => {
+ const faux_desc = new MockedD3();
+ const svg_insert_spy = vi.spyOn(fauxSvgNode, 'insert').mockReturnValue(faux_desc);
+ // @ts-ignore Required to easily handle the d3 select types
+ const desc_attr_spy = vi.spyOn(faux_desc, 'attr').mockReturnValue(faux_desc);
+ const desc_text_spy = vi.spyOn(faux_desc, 'text');
+
+ addSVGa11yTitleDescription(fauxSvgNode, a11yTitle, a11yDesc, givenId);
+ expect(svg_insert_spy).toHaveBeenCalledWith('desc', ':first-child');
+ expect(desc_attr_spy).toHaveBeenCalledWith('id', `chart-desc-` + givenId);
+ expect(desc_text_spy).toHaveBeenNthCalledWith(1, 'a11y description');
+ });
+ });
+
+ describe(`no a11y description`, () => {
+ const a11yDesc = undefined;
+
+ it('sets aria-labelledby to the title id inserted as a child', () => {
+ // @ts-ignore Required to easily handle the d3 select types
+ const svg_attr_spy = vi.spyOn(fauxSvgNode, 'attr').mockReturnValue(fauxSvgNode);
+ addSVGa11yTitleDescription(fauxSvgNode, a11yTitle, a11yDesc, givenId);
+ expect(svg_attr_spy).toHaveBeenCalledWith('aria-labelledby', `chart-title-${givenId}`);
+ });
+
+ it('inserts a title tag as the first child with the text set to the accTitle given', () => {
+ const faux_title = new MockedD3();
+ const svg_insert_spy = vi.spyOn(fauxSvgNode, 'insert').mockReturnValue(faux_title);
+ // @ts-ignore Required to easily handle the d3 select types
+ const title_attr_spy = vi.spyOn(faux_title, 'attr').mockReturnValue(faux_title);
+ const title_text_spy = vi.spyOn(faux_title, 'text');
+
+ addSVGa11yTitleDescription(fauxSvgNode, a11yTitle, a11yDesc, givenId);
+ expect(svg_insert_spy).toHaveBeenCalledWith('title', ':first-child');
+ expect(title_attr_spy).toHaveBeenCalledWith('id', `chart-title-` + givenId);
+ expect(title_text_spy).toHaveBeenNthCalledWith(1, 'a11y title');
+ });
+
+ it('no description tag is inserted', () => {
+ const faux_title = new MockedD3();
+ const svg_insert_spy = vi.spyOn(fauxSvgNode, 'insert').mockReturnValue(faux_title);
+ addSVGa11yTitleDescription(fauxSvgNode, a11yTitle, a11yDesc, givenId);
+ expect(svg_insert_spy).not.toHaveBeenCalledWith('desc', ':first-child');
+ });
+ });
+ });
+
+ describe('no a11y title', () => {
+ const a11yTitle = undefined;
+
+ describe('given an a11y description', () => {
+ const a11yDesc = 'a11y description';
+
+ it('no title tag inserted', () => {
+ const faux_title = new MockedD3();
+ const svg_insert_spy = vi.spyOn(fauxSvgNode, 'insert').mockReturnValue(faux_title);
+ addSVGa11yTitleDescription(fauxSvgNode, a11yTitle, a11yDesc, givenId);
+ expect(svg_insert_spy).not.toHaveBeenCalledWith('title', ':first-child');
+ });
+
+ it('sets aria-labelledby to the description id inserted as a child', () => {
+ // @ts-ignore Required to easily handle the d3 select types
+ const svg_attr_spy = vi.spyOn(fauxSvgNode, 'attr').mockReturnValue(fauxSvgNode);
+ addSVGa11yTitleDescription(fauxSvgNode, a11yTitle, a11yDesc, givenId);
+ expect(svg_attr_spy).toHaveBeenCalledWith('aria-labelledby', `chart-desc-${givenId}`);
+ });
+
+ it('inserts a desc tag as a child with the text set to accDescription given', () => {
+ const faux_desc = new MockedD3();
+ const svg_insert_spy = vi.spyOn(fauxSvgNode, 'insert').mockReturnValue(faux_desc);
+ // @ts-ignore Required to easily handle the d3 select types
+ const desc_attr_spy = vi.spyOn(faux_desc, 'attr').mockReturnValue(faux_desc);
+ const desc_text_spy = vi.spyOn(faux_desc, 'text');
+
+ addSVGa11yTitleDescription(fauxSvgNode, a11yTitle, a11yDesc, givenId);
+ expect(svg_insert_spy).toHaveBeenCalledWith('desc', ':first-child');
+ expect(desc_attr_spy).toHaveBeenCalledWith('id', `chart-desc-` + givenId);
+ expect(desc_text_spy).toHaveBeenNthCalledWith(1, 'a11y description');
+ });
+ });
+
+ describe('no a11y description', () => {
+ const a11yDesc = undefined;
+
+ it('no title tag inserted', () => {
+ const faux_title = new MockedD3();
+ const svg_insert_spy = vi.spyOn(fauxSvgNode, 'insert').mockReturnValue(faux_title);
+ addSVGa11yTitleDescription(fauxSvgNode, a11yTitle, a11yDesc, givenId);
+ expect(svg_insert_spy).not.toHaveBeenCalledWith('title', ':first-child');
+ });
+
+ it('no description tag inserted', () => {
+ const faux_desc = new MockedD3();
+ const svg_insert_spy = vi.spyOn(fauxSvgNode, 'insert').mockReturnValue(faux_desc);
+ addSVGa11yTitleDescription(fauxSvgNode, a11yTitle, a11yDesc, givenId);
+ expect(svg_insert_spy).not.toHaveBeenCalledWith('desc', ':first-child');
+ });
+
+ it('no aria-labelledby is set', () => {
+ // @ts-ignore Required to easily handle the d3 select types
+ const svg_attr_spy = vi.spyOn(fauxSvgNode, 'attr').mockReturnValue(fauxSvgNode);
+ addSVGa11yTitleDescription(fauxSvgNode, a11yTitle, a11yDesc, givenId);
+ expect(svg_attr_spy).not.toHaveBeenCalled();
+ });
+ });
+ });
});
});
});
diff --git a/packages/mermaid/src/accessibility.ts b/packages/mermaid/src/accessibility.ts
index 246a88f66..eff9a4edc 100644
--- a/packages/mermaid/src/accessibility.ts
+++ b/packages/mermaid/src/accessibility.ts
@@ -3,43 +3,54 @@
*
*/
-// This is just a convenience alias to make it clear the type is a d3 object. (It's easier to make it 'any' instead of the comple typing set in d3)
+import { isEmpty, compact } from 'lodash';
+
+// This is just a convenience alias to make it clear the type is a d3 object. (It's easier to make it 'any' instead of the complete typing set in d3)
type D3object = any;
/**
- * Set the accessibility (a11y) information for the svg d3 object using the given diagram type
- * Note that the svg element role _should_ be mapped to a 'graphics-document' by default. Thus we don't set it here, but can set it in the future if needed.
+ * Add aria-roledescription to the svg element to the diagramType
+ *
* @param svg - d3 object that contains the SVG HTML element
* @param diagramType - diagram name for to the aria-roledescription
*/
-export function setA11yDiagramInfo(svg: D3object, diagramType: string) {
- svg.attr('aria-roledescription', diagramType);
+export function setA11yDiagramInfo(svg: D3object, diagramType: string | null | undefined) {
+ if (!isEmpty(diagramType)) {
+ svg.attr('aria-roledescription', diagramType);
+ }
}
-
/**
- * This method will add a basic title and description element to a chart. The yy parser will need to
- * respond to getAccTitle and getAccDescription,
- * where the accessible title is the title element on the chart.
+ * Add an accessible title and/or description element to a chart.
+ * The title is usually not displayed and the description is never displayed.
*
- * Note that the accessible title is generally _not_ displayed
- * and the accessible description is never displayed.
+ * The following charts display their title as a visual and accessibility element: gantt
*
- *
- * The following charts display their title as a visual and accessibility element: gantt. TODO fix this
- *
- * @param diagramDb - the 'db' object/module for a diagram. Must respond to getAccTitle() and getAccDescription()
- * @param svg - the d3 object that represents the svg element
- * @param baseId - the id to use as the base for the title and description
+ * @param svg - d3 node to insert the a11y title and desc info
+ * @param a11yTitle - a11y title. null and undefined are meaningful: means to skip it
+ * @param a11yDesc - a11y description. null and undefined are meaningful: means to skip it
+ * @param baseId - id used to construct the a11y title and description id
*/
-export function addSVGa11yTitleDescription(diagramDb: any, svg: D3object, baseId: string) {
+export function addSVGa11yTitleDescription(
+ svg: D3object,
+ a11yTitle: string | null | undefined,
+ a11yDesc: string | null | undefined,
+ baseId: string
+) {
if (typeof svg.insert === 'undefined') {
return;
}
- const titleId = 'chart-title-' + baseId;
- const descId = 'chart-desc-' + baseId;
-
- svg.attr('aria-labelledby', titleId + ' ' + descId);
- svg.insert('desc', ':first-child').attr('id', descId).text(diagramDb.getAccDescription());
- svg.insert('title', ':first-child').attr('id', titleId).text(diagramDb.getAccTitle());
+ const titleId = a11yTitle ? 'chart-title-' + baseId : null;
+ const descId = a11yDesc ? 'chart-desc-' + baseId : null;
+ if (a11yTitle || a11yDesc) {
+ svg.attr('aria-labelledby', compact([titleId, descId]).join(' '));
+ if (a11yDesc) {
+ svg.insert('desc', ':first-child').attr('id', descId).text(a11yDesc);
+ }
+ if (a11yTitle) {
+ svg.insert('title', ':first-child').attr('id', titleId).text(a11yTitle);
+ }
+ } else {
+ return;
+ }
}
From 8a3c4f64b2d05a8173a879474c3e139d0be3fb0b Mon Sep 17 00:00:00 2001
From: "Ashley Engelund (weedySeaDragon @ github)"
Date: Thu, 17 Nov 2022 12:23:01 -0800
Subject: [PATCH 026/129] MockedD3: node() return Element; add selectAll()
---
packages/mermaid/src/tests/MockedD3.ts | 24 ++++++++++++++++++++++--
1 file changed, 22 insertions(+), 2 deletions(-)
diff --git a/packages/mermaid/src/tests/MockedD3.ts b/packages/mermaid/src/tests/MockedD3.ts
index d7c16b3a8..24cb9043f 100644
--- a/packages/mermaid/src/tests/MockedD3.ts
+++ b/packages/mermaid/src/tests/MockedD3.ts
@@ -1,12 +1,18 @@
/**
* This is a mocked/stubbed version of the d3 Selection type. Each of the main functions are all
* mocked (via vi.fn()) so you can track if they have been called, etc.
+ *
+ * Note that node() returns a HTML Element with tag 'svg'. It is an empty element (no innerHTML, no children, etc).
+ * This potentially allows testing of mermaidAPI render().
*/
+
export class MockedD3 {
public attribs = new Map();
public id: string | undefined = '';
_children: MockedD3[] = [];
+ _containingHTMLdoc = new Document();
+
constructor(givenId = 'mock-id') {
this.id = givenId;
}
@@ -29,6 +35,11 @@ export class MockedD3 {
return new MockedD3(cleanId);
});
+ // This has the same implementation as select(). (It calls it.)
+ selectAll = vi.fn().mockImplementation(({ select_str = '' }): MockedD3 => {
+ return this.select(select_str);
+ });
+
append = vi
.fn()
.mockImplementation(function (this: MockedD3, type: string, id = '' + '-appended'): MockedD3 {
@@ -87,9 +98,18 @@ export class MockedD3 {
this.attribs.set('text', attrValue);
return this;
}
- // NOTE: Arbitrarily returns an empty object. The return value could be something different with a mockReturnValue() or mockImplementation()
- public node = vi.fn().mockReturnValue({});
+ // NOTE: Returns a HTML ELement with tag 'svg' that has _another_ 'svg' element child.
+ // This allows different tests to succeed -- some need a top level 'svg' and some need a 'svg' element to be the firstChild
+ // Real implementation returns an HTML Element
+ public node = vi.fn().mockImplementation(() => {
+ const topElem = this._containingHTMLdoc.createElement('svg');
+ const elem_svgChild = this._containingHTMLdoc.createElement('svg'); // another svg element
+ topElem.appendChild(elem_svgChild);
+ return topElem;
+ });
+
+ // TODO Is this correct? shouldn't it return a list of HTML Elements?
nodes = vi.fn().mockImplementation(function (this: MockedD3): MockedD3[] {
return this._children;
});
From 1fc02940ae9fbb8c3f6ad892bd7202eed20638e8 Mon Sep 17 00:00:00 2001
From: "Ashley Engelund (weedySeaDragon @ github)"
Date: Thu, 17 Nov 2022 12:24:16 -0800
Subject: [PATCH 027/129] move mocks specific to only seq spec files out of
global d3 mock
---
.../diagrams/sequence/sequenceDiagram.spec.js | 54 +++++++++++++++++++
.../src/diagrams/sequence/svgDraw.spec.js | 28 +++++++++-
2 files changed, 81 insertions(+), 1 deletion(-)
diff --git a/packages/mermaid/src/diagrams/sequence/sequenceDiagram.spec.js b/packages/mermaid/src/diagrams/sequence/sequenceDiagram.spec.js
index 9422a5f37..6395940b0 100644
--- a/packages/mermaid/src/diagrams/sequence/sequenceDiagram.spec.js
+++ b/packages/mermaid/src/diagrams/sequence/sequenceDiagram.spec.js
@@ -1,8 +1,62 @@
+import { vi } from 'vitest';
+
import * as configApi from '../../config';
import mermaidAPI from '../../mermaidAPI';
import Diagram from '../../Diagram';
import { addDiagrams } from '../../diagram-api/diagram-orchestration';
+
+/**
+ * Sequence diagrams require their own very special version of a mocked d3 module
+ * diagrams/sequence/svgDraw uses statements like this with d3 nodes: (note the [0][0])
+ *
+ * // in drawText(...)
+ * textHeight += (textElem._groups || textElem)[0][0].getBBox().height;
+ */
+vi.mock('d3', () => {
+ const NewD3 = function () {
+ function returnThis() {
+ return this;
+ }
+ return {
+ append: function () {
+ return NewD3();
+ },
+ lower: returnThis,
+ attr: returnThis,
+ style: returnThis,
+ text: returnThis,
+ // [0][0] (below) is required by drawText() in packages/mermaid/src/diagrams/sequence/svgDraw.js
+ 0: {
+ 0: {
+ getBBox: function () {
+ return {
+ height: 10,
+ width: 20,
+ };
+ },
+ },
+ },
+ };
+ };
+
+ return {
+ select: function () {
+ return new NewD3();
+ },
+
+ selectAll: function () {
+ return new NewD3();
+ },
+
+ curveBasis: 'basis',
+ curveLinear: 'linear',
+ curveCardinal: 'cardinal',
+ };
+});
+// -------------------------------
+
addDiagrams();
+
/**
* @param conf
* @param key
diff --git a/packages/mermaid/src/diagrams/sequence/svgDraw.spec.js b/packages/mermaid/src/diagrams/sequence/svgDraw.spec.js
index 580dafe89..8e5f5f32b 100644
--- a/packages/mermaid/src/diagrams/sequence/svgDraw.spec.js
+++ b/packages/mermaid/src/diagrams/sequence/svgDraw.spec.js
@@ -1,5 +1,31 @@
+import { vi } from 'vitest';
import svgDraw from './svgDraw';
-import { MockD3 } from 'd3';
+
+// This is the only place that uses this mock
+export const MockD3 = (name, parent) => {
+ const children = [];
+ const elem = {
+ get __children() {
+ return children;
+ },
+ get __name() {
+ return name;
+ },
+ get __parent() {
+ return parent;
+ },
+ };
+ elem.append = (name) => {
+ const mockElem = MockD3(name, elem);
+ children.push(mockElem);
+ return mockElem;
+ };
+ elem.lower = vi.fn(() => elem);
+ elem.attr = vi.fn(() => elem);
+ elem.text = vi.fn(() => elem);
+ elem.style = vi.fn(() => elem);
+ return elem;
+};
describe('svgDraw', function () {
describe('drawRect', function () {
From 1ad537bc4d44025a361546aa45a8291a248b4049 Mon Sep 17 00:00:00 2001
From: "Ashley Engelund (weedySeaDragon @ github)"
Date: Thu, 17 Nov 2022 12:24:58 -0800
Subject: [PATCH 028/129] d3 mock: use MockedD3; remove sequence specific mock
code
---
__mocks__/d3.ts | 59 +++----------------------------------------------
1 file changed, 3 insertions(+), 56 deletions(-)
diff --git a/__mocks__/d3.ts b/__mocks__/d3.ts
index 67f09b6f4..af35020c5 100644
--- a/__mocks__/d3.ts
+++ b/__mocks__/d3.ts
@@ -1,67 +1,14 @@
// @ts-nocheck TODO: Fix TS
-import { vi } from 'vitest';
-
-const NewD3 = function () {
- /**
- *
- */
- function returnThis() {
- return this;
- }
- return {
- append: function () {
- return NewD3();
- },
- lower: returnThis,
- attr: returnThis,
- style: returnThis,
- text: returnThis,
- 0: {
- 0: {
- getBBox: function () {
- return {
- height: 10,
- width: 20,
- };
- },
- },
- },
- };
-};
+import { MockedD3 } from '../packages/mermaid/src/tests/MockedD3';
export const select = function () {
- return new NewD3();
+ return new MockedD3();
};
export const selectAll = function () {
- return new NewD3();
+ return new MockedD3();
};
export const curveBasis = 'basis';
export const curveLinear = 'linear';
export const curveCardinal = 'cardinal';
-
-export const MockD3 = (name, parent) => {
- const children = [];
- const elem = {
- get __children() {
- return children;
- },
- get __name() {
- return name;
- },
- get __parent() {
- return parent;
- },
- };
- elem.append = (name) => {
- const mockElem = MockD3(name, elem);
- children.push(mockElem);
- return mockElem;
- };
- elem.lower = vi.fn(() => elem);
- elem.attr = vi.fn(() => elem);
- elem.text = vi.fn(() => elem);
- elem.style = vi.fn(() => elem);
- return elem;
-};
From f62c5d9698d8738b7058ec8834c5d62e677d9178 Mon Sep 17 00:00:00 2001
From: "Ashley Engelund (weedySeaDragon @ github)"
Date: Thu, 17 Nov 2022 12:25:14 -0800
Subject: [PATCH 029/129] add diagram renderer mocks
---
__mocks__/c4Renderer.js | 21 +++++++++++++++++++++
__mocks__/classRenderer-v2.js | 16 ++++++++++++++++
__mocks__/classRenderer.js | 13 +++++++++++++
__mocks__/erRenderer.js | 16 ++++++++++++++++
__mocks__/flowRenderer-v2.js | 24 ++++++++++++++++++++++++
__mocks__/ganttRenderer.js | 16 ++++++++++++++++
__mocks__/gitGraphRenderer.js | 13 +++++++++++++
__mocks__/journeyRenderer.js | 15 +++++++++++++++
__mocks__/pieRenderer.js | 13 +++++++++++++
__mocks__/requirementRenderer.js | 13 +++++++++++++
__mocks__/sequenceRenderer.js | 23 +++++++++++++++++++++++
__mocks__/stateRenderer-v2.js | 22 ++++++++++++++++++++++
12 files changed, 205 insertions(+)
create mode 100644 __mocks__/c4Renderer.js
create mode 100644 __mocks__/classRenderer-v2.js
create mode 100644 __mocks__/classRenderer.js
create mode 100644 __mocks__/erRenderer.js
create mode 100644 __mocks__/flowRenderer-v2.js
create mode 100644 __mocks__/ganttRenderer.js
create mode 100644 __mocks__/gitGraphRenderer.js
create mode 100644 __mocks__/journeyRenderer.js
create mode 100644 __mocks__/pieRenderer.js
create mode 100644 __mocks__/requirementRenderer.js
create mode 100644 __mocks__/sequenceRenderer.js
create mode 100644 __mocks__/stateRenderer-v2.js
diff --git a/__mocks__/c4Renderer.js b/__mocks__/c4Renderer.js
new file mode 100644
index 000000000..576d5d863
--- /dev/null
+++ b/__mocks__/c4Renderer.js
@@ -0,0 +1,21 @@
+/**
+ * Mocked C4Context diagram renderer
+ */
+
+import { vi } from 'vitest';
+
+export const drawPersonOrSystemArray = vi.fn();
+export const drawBoundary = vi.fn();
+
+export const setConf = vi.fn();
+
+export const draw = vi.fn().mockImplementation(() => {
+ return '';
+});
+
+export default {
+ drawPersonOrSystemArray,
+ drawBoundary,
+ setConf,
+ draw,
+};
diff --git a/__mocks__/classRenderer-v2.js b/__mocks__/classRenderer-v2.js
new file mode 100644
index 000000000..1ad95806f
--- /dev/null
+++ b/__mocks__/classRenderer-v2.js
@@ -0,0 +1,16 @@
+/**
+ * Mocked class diagram v2 renderer
+ */
+
+import { vi } from 'vitest';
+
+export const setConf = vi.fn();
+
+export const draw = vi.fn().mockImplementation(() => {
+ return '';
+});
+
+export default {
+ setConf,
+ draw,
+};
diff --git a/__mocks__/classRenderer.js b/__mocks__/classRenderer.js
new file mode 100644
index 000000000..1c20de4b1
--- /dev/null
+++ b/__mocks__/classRenderer.js
@@ -0,0 +1,13 @@
+/**
+ * Mocked class diagram renderer
+ */
+
+import { vi } from 'vitest';
+
+export const draw = vi.fn().mockImplementation(() => {
+ return '';
+});
+
+export default {
+ draw,
+};
diff --git a/__mocks__/erRenderer.js b/__mocks__/erRenderer.js
new file mode 100644
index 000000000..845d641f7
--- /dev/null
+++ b/__mocks__/erRenderer.js
@@ -0,0 +1,16 @@
+/**
+ * Mocked er diagram renderer
+ */
+
+import { vi } from 'vitest';
+
+export const setConf = vi.fn();
+
+export const draw = vi.fn().mockImplementation(() => {
+ return '';
+});
+
+export default {
+ setConf,
+ draw,
+};
diff --git a/__mocks__/flowRenderer-v2.js b/__mocks__/flowRenderer-v2.js
new file mode 100644
index 000000000..89cc86031
--- /dev/null
+++ b/__mocks__/flowRenderer-v2.js
@@ -0,0 +1,24 @@
+/**
+ * Mocked flow (flowchart) diagram v2 renderer
+ */
+
+import { vi } from 'vitest';
+
+export const setConf = vi.fn();
+export const addVertices = vi.fn();
+export const addEdges = vi.fn();
+export const getClasses = vi.fn().mockImplementation(() => {
+ return {};
+});
+
+export const draw = vi.fn().mockImplementation(() => {
+ return '';
+});
+
+export default {
+ setConf,
+ addVertices,
+ addEdges,
+ getClasses,
+ draw,
+};
diff --git a/__mocks__/ganttRenderer.js b/__mocks__/ganttRenderer.js
new file mode 100644
index 000000000..957249832
--- /dev/null
+++ b/__mocks__/ganttRenderer.js
@@ -0,0 +1,16 @@
+/**
+ * Mocked gantt diagram renderer
+ */
+
+import { vi } from 'vitest';
+
+export const setConf = vi.fn();
+
+export const draw = vi.fn().mockImplementation(() => {
+ return '';
+});
+
+export default {
+ setConf,
+ draw,
+};
diff --git a/__mocks__/gitGraphRenderer.js b/__mocks__/gitGraphRenderer.js
new file mode 100644
index 000000000..1daa82ca4
--- /dev/null
+++ b/__mocks__/gitGraphRenderer.js
@@ -0,0 +1,13 @@
+/**
+ * Mocked git (graph) diagram renderer
+ */
+
+import { vi } from 'vitest';
+
+export const draw = vi.fn().mockImplementation(() => {
+ return '';
+});
+
+export default {
+ draw,
+};
diff --git a/__mocks__/journeyRenderer.js b/__mocks__/journeyRenderer.js
new file mode 100644
index 000000000..2bc77c0b1
--- /dev/null
+++ b/__mocks__/journeyRenderer.js
@@ -0,0 +1,15 @@
+/**
+ * Mocked pie (picChart) diagram renderer
+ */
+
+import { vi } from 'vitest';
+export const setConf = vi.fn();
+
+export const draw = vi.fn().mockImplementation(() => {
+ return '';
+});
+
+export default {
+ setConf,
+ draw,
+};
diff --git a/__mocks__/pieRenderer.js b/__mocks__/pieRenderer.js
new file mode 100644
index 000000000..317c69901
--- /dev/null
+++ b/__mocks__/pieRenderer.js
@@ -0,0 +1,13 @@
+/**
+ * Mocked pie (picChart) diagram renderer
+ */
+
+import { vi } from 'vitest';
+
+export const draw = vi.fn().mockImplementation(() => {
+ return '';
+});
+
+export default {
+ draw,
+};
diff --git a/__mocks__/requirementRenderer.js b/__mocks__/requirementRenderer.js
new file mode 100644
index 000000000..48d8997ac
--- /dev/null
+++ b/__mocks__/requirementRenderer.js
@@ -0,0 +1,13 @@
+/**
+ * Mocked requirement diagram renderer
+ */
+
+import { vi } from 'vitest';
+
+export const draw = vi.fn().mockImplementation(() => {
+ return '';
+});
+
+export default {
+ draw,
+};
diff --git a/__mocks__/sequenceRenderer.js b/__mocks__/sequenceRenderer.js
new file mode 100644
index 000000000..11080c6bb
--- /dev/null
+++ b/__mocks__/sequenceRenderer.js
@@ -0,0 +1,23 @@
+/**
+ * Mocked sequence diagram renderer
+ */
+
+import { vi } from 'vitest';
+
+export const bounds = vi.fn();
+export const drawActors = vi.fn();
+export const drawActorsPopup = vi.fn();
+
+export const setConf = vi.fn();
+
+export const draw = vi.fn().mockImplementation(() => {
+ return '';
+});
+
+export default {
+ bounds,
+ drawActors,
+ drawActorsPopup,
+ setConf,
+ draw,
+};
diff --git a/__mocks__/stateRenderer-v2.js b/__mocks__/stateRenderer-v2.js
new file mode 100644
index 000000000..a2d103b50
--- /dev/null
+++ b/__mocks__/stateRenderer-v2.js
@@ -0,0 +1,22 @@
+/**
+ * Mocked state diagram v2 renderer
+ */
+
+import { vi } from 'vitest';
+
+export const setConf = vi.fn();
+export const getClasses = vi.fn().mockImplementation(() => {
+ return {};
+});
+export const stateDomId = vi.fn().mockImplementation(() => {
+ return 'mocked-stateDiagram-stateDomId';
+});
+export const draw = vi.fn().mockImplementation(() => {
+ return '';
+});
+
+export default {
+ setConf,
+ getClasses,
+ draw,
+};
From 29efc116f340bc85fa670035b8d411ca957de3fe Mon Sep 17 00:00:00 2001
From: "Ashley Engelund (weedySeaDragon @ github)"
Date: Thu, 17 Nov 2022 12:27:17 -0800
Subject: [PATCH 030/129] put a11y into mermaidAPI render; add render spec
(mock diagram renderers etc)
---
docs/community/newDiagram.md | 4 +-
docs/config/setup/modules/mermaidAPI.md | 20 +++---
packages/mermaid/src/mermaidAPI.spec.ts | 96 +++++++++++++++++++++++--
packages/mermaid/src/mermaidAPI.ts | 15 +++-
4 files changed, 118 insertions(+), 17 deletions(-)
diff --git a/docs/community/newDiagram.md b/docs/community/newDiagram.md
index da86f9838..e49dd3749 100644
--- a/docs/community/newDiagram.md
+++ b/docs/community/newDiagram.md
@@ -214,7 +214,9 @@ The functions for setting title and description are provided by a common module.
clear as commonClear,
} from '../../commonDb';
-For rendering the accessibility tags you have again an existing function you can use.
+Starting with Mermaid version, the accessibility tags are inserted into the SVG element in the `render` function in mermaidAPI.
+
+In version \_\_\_ and before, you need to insert the accessibility tags in your renderer:
**In the renderer:**
diff --git a/docs/config/setup/modules/mermaidAPI.md b/docs/config/setup/modules/mermaidAPI.md
index 0acfe4f97..baa4a939c 100644
--- a/docs/config/setup/modules/mermaidAPI.md
+++ b/docs/config/setup/modules/mermaidAPI.md
@@ -80,7 +80,7 @@ mermaid.initialize(config);
#### Defined in
-[mermaidAPI.ts:949](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/mermaidAPI.ts#L949)
+[mermaidAPI.ts:960](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/mermaidAPI.ts#L960)
## Functions
@@ -111,7 +111,7 @@ Return the last node appended
#### Defined in
-[mermaidAPI.ts:292](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/mermaidAPI.ts#L292)
+[mermaidAPI.ts:294](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/mermaidAPI.ts#L294)
---
@@ -137,7 +137,7 @@ the cleaned up svgCode
#### Defined in
-[mermaidAPI.ts:243](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/mermaidAPI.ts#L243)
+[mermaidAPI.ts:245](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/mermaidAPI.ts#L245)
---
@@ -163,7 +163,7 @@ the string with all the user styles
#### Defined in
-[mermaidAPI.ts:170](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/mermaidAPI.ts#L170)
+[mermaidAPI.ts:172](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/mermaidAPI.ts#L172)
---
@@ -186,7 +186,7 @@ the string with all the user styles
#### Defined in
-[mermaidAPI.ts:220](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/mermaidAPI.ts#L220)
+[mermaidAPI.ts:222](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/mermaidAPI.ts#L222)
---
@@ -213,7 +213,7 @@ with an enclosing block that has each of the cssClasses followed by !important;
#### Defined in
-[mermaidAPI.ts:154](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/mermaidAPI.ts#L154)
+[mermaidAPI.ts:156](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/mermaidAPI.ts#L156)
---
@@ -233,7 +233,7 @@ with an enclosing block that has each of the cssClasses followed by !important;
#### Defined in
-[mermaidAPI.ts:128](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/mermaidAPI.ts#L128)
+[mermaidAPI.ts:130](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/mermaidAPI.ts#L130)
---
@@ -253,7 +253,7 @@ with an enclosing block that has each of the cssClasses followed by !important;
#### Defined in
-[mermaidAPI.ts:99](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/mermaidAPI.ts#L99)
+[mermaidAPI.ts:101](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/mermaidAPI.ts#L101)
---
@@ -279,7 +279,7 @@ Put the svgCode into an iFrame. Return the iFrame code
#### Defined in
-[mermaidAPI.ts:271](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/mermaidAPI.ts#L271)
+[mermaidAPI.ts:273](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/mermaidAPI.ts#L273)
---
@@ -305,4 +305,4 @@ Remove any existing elements from the given document
#### Defined in
-[mermaidAPI.ts:343](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/mermaidAPI.ts#L343)
+[mermaidAPI.ts:345](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/mermaidAPI.ts#L345)
diff --git a/packages/mermaid/src/mermaidAPI.spec.ts b/packages/mermaid/src/mermaidAPI.spec.ts
index 786b163c4..fcc547546 100644
--- a/packages/mermaid/src/mermaidAPI.spec.ts
+++ b/packages/mermaid/src/mermaidAPI.spec.ts
@@ -1,6 +1,38 @@
'use strict';
import { vi } from 'vitest';
+// -------------------------------------
+// Mocks and mocking
+
+import { MockedD3 } from './tests/MockedD3';
+
+// Note: If running this directly from within an IDE, the mocks directory must be at packages/mermaid/mocks
+vi.mock('d3');
+vi.mock('dagre-d3');
+
+// mermaidAPI.spec.ts:
+import * as accessibility from './accessibility'; // Import it this way so we can use spyOn(accessibility,...)
+vi.mock('./accessibility', () => ({
+ setA11yDiagramInfo: vi.fn(),
+ addSVGa11yTitleDescription: vi.fn(),
+}));
+
+// Mock the renderers specifically so we can test render(). Need to mock draw() for each renderer
+vi.mock('./diagrams/c4/c4Renderer');
+vi.mock('./diagrams/class/classRenderer');
+vi.mock('./diagrams/class/classRenderer-v2');
+vi.mock('./diagrams/er/erRenderer');
+vi.mock('./diagrams/flowchart/flowRenderer-v2');
+vi.mock('./diagrams/git/gitGraphRenderer');
+vi.mock('./diagrams/gantt/ganttRenderer');
+vi.mock('./diagrams/user-journey/journeyRenderer');
+vi.mock('./diagrams/pie/pieRenderer');
+vi.mock('./diagrams/requirement/requirementRenderer');
+vi.mock('./diagrams/sequence/sequenceRenderer');
+vi.mock('./diagrams/state/stateRenderer-v2');
+
+// -------------------------------------
+
import mermaid from './mermaid';
import { MermaidConfig } from './config.type';
@@ -37,7 +69,10 @@ vi.mock('stylis', () => {
});
import { compile, serialize } from 'stylis';
-import { MockedD3 } from './tests/MockedD3';
+/**
+ * @see https://vitest.dev/guide/mocking.html Mock part of a module
+ * To investigate how to mock just some methods from a module - call the actual implementation and then mock others, e.g. so they can be spied on
+ */
// -------------------------------------------------------------------------------------
@@ -335,7 +370,8 @@ describe('mermaidAPI', function () {
const htmlElements = ['> *', 'span'];
it('creates CSS styles for every style and textStyle in every classDef', () => {
- // @todo TODO Can't figure out how to spy on the cssImportantStyles method. That would be a much better approach than manually checking the result
+ // @todo TODO Can't figure out how to spy on the cssImportantStyles method.
+ // That would be a much better approach than manually checking the result
const styles = createCssStyles(mocked_config, graphType, classDefs);
htmlElements.forEach((htmlElement) => {
@@ -373,7 +409,7 @@ describe('mermaidAPI', function () {
const htmlElements = ['rect', 'polygon', 'ellipse', 'circle'];
it('creates CSS styles for every style and textStyle in every classDef', () => {
- // @todo TODO Can't figure out how to spy on the cssImportantStyles method. That would be a much better approach than manually checking the result
+ // TODO Can't figure out how to spy on the cssImportantStyles method. That would be a much better approach than manually checking the result.
const styles = createCssStyles(mocked_config_no_htmlLabels, graphType, classDefs);
htmlElements.forEach((htmlElement) => {
@@ -510,7 +546,7 @@ describe('mermaidAPI', function () {
expect(config.testLiteral).toBe(true);
});
- it('copies a an object into the configuration', function () {
+ it('copies an object into the configuration', function () {
const orgConfig: any = mermaidAPI.getConfig();
expect(orgConfig.testObject).toBe(undefined);
@@ -616,6 +652,7 @@ describe('mermaidAPI', function () {
expect(mermaidAPI.defaultConfig['logLevel']).toBe(5);
});
});
+
describe('dompurify config', function () {
it('allows dompurify config to be set', function () {
mermaidAPI.initialize({ dompurifyConfig: { ADD_ATTR: ['onclick'] } });
@@ -623,6 +660,7 @@ describe('mermaidAPI', function () {
expect(mermaidAPI!.getConfig()!.dompurifyConfig!.ADD_ATTR).toEqual(['onclick']);
});
});
+
describe('parse', function () {
mermaid.parseError = undefined; // ensure it parseError undefined
it('throws for an invalid definition (with no mermaid.parseError() defined)', function () {
@@ -646,4 +684,54 @@ describe('mermaidAPI', function () {
expect(mermaidAPI.parse('graph TD;A--x|text including URL space|B;')).toEqual(true);
});
});
+
+ describe('render', () => {
+ // These are more like integration tests right now because nothing is mocked.
+ // But it is faster that a cypress test and there's no real reason to actually evaluate an image pixel by pixel.
+
+ // render(id, text, cb?, svgContainingElement?)
+
+ // Test all diagram types. Note that old flowchart 'graph' type will invoke the flowRenderer-v2. (See the flowchart v2 detector.)
+ // We have to have both the specific textDiagramType and the expected type name because the expected type may be slightly different than was is put in the diagram text (ex: in -v2 diagrams)
+ const diagramTypesAndExpectations = [
+ { textDiagramType: 'C4Context', expectedType: 'c4' },
+ { textDiagramType: 'classDiagram', expectedType: 'classDiagram' },
+ { textDiagramType: 'classDiagram-v2', expectedType: 'classDiagram' },
+ { textDiagramType: 'erDiagram', expectedType: 'er' },
+ { textDiagramType: 'graph', expectedType: 'flowchart-v2' },
+ { textDiagramType: 'flowchart', expectedType: 'flowchart-v2' },
+ { textDiagramType: 'gitGraph', expectedType: 'gitGraph' },
+ { textDiagramType: 'gantt', expectedType: 'gantt' },
+ { textDiagramType: 'journey', expectedType: 'journey' },
+ { textDiagramType: 'pie', expectedType: 'pie' },
+ { textDiagramType: 'requirementDiagram', expectedType: 'requirement' },
+ { textDiagramType: 'sequenceDiagram', expectedType: 'sequence' },
+ { textDiagramType: 'stateDiagram-v2', expectedType: 'stateDiagram' },
+ ];
+
+ describe('accessibility', () => {
+ const id = 'mermaid-fauxId';
+ const a11yTitle = 'a11y title';
+ const a11yDescr = 'a11y description';
+
+ diagramTypesAndExpectations.forEach((testedDiagram) => {
+ describe(`${testedDiagram.textDiagramType}`, () => {
+ const diagramType = testedDiagram.textDiagramType;
+ const diagramText = `${diagramType}\n accTitle: ${a11yTitle}\n accDescr: ${a11yDescr}\n`;
+ const expectedDiagramType = testedDiagram.expectedType;
+
+ it('aria-roledscription is set to the diagram type, addSVGa11yTitleDescription is called', () => {
+ const a11yDiagramInfo_spy = vi.spyOn(accessibility, 'setA11yDiagramInfo');
+ const a11yTitleDesc_spy = vi.spyOn(accessibility, 'addSVGa11yTitleDescription');
+ mermaidAPI.render(id, diagramText);
+ expect(a11yDiagramInfo_spy).toHaveBeenCalledWith(
+ expect.anything(),
+ expectedDiagramType
+ );
+ expect(a11yTitleDesc_spy).toHaveBeenCalled();
+ });
+ });
+ });
+ });
+ });
});
diff --git a/packages/mermaid/src/mermaidAPI.ts b/packages/mermaid/src/mermaidAPI.ts
index 0df1da305..18076b488 100644
--- a/packages/mermaid/src/mermaidAPI.ts
+++ b/packages/mermaid/src/mermaidAPI.ts
@@ -29,6 +29,8 @@ import utils, { directiveSanitizer } from './utils';
import DOMPurify from 'dompurify';
import { MermaidConfig } from './config.type';
import { evaluate } from './diagrams/common/common';
+import { setA11yDiagramInfo, addSVGa11yTitleDescription } from './accessibility';
+
import { isEmpty } from 'lodash';
// diagram names that support classDef statements
@@ -487,12 +489,13 @@ const render = function (
parseEncounteredException = error;
}
- // Get the temporary div element containing the svg
+ // Get the temporary div element containing the svg (the parent HTML Element)
const element = root.select(enclosingDivID_selector).node();
const graphType = diag.type;
// -------------------------------------------------------------------------------
// Create and insert the styles (user styles, theme styles, config styles)
+ // These are dealing with HTML Elements, not d3 nodes.
// Insert an element into svg. This is where we put the styles
const svg = element.firstChild;
@@ -509,6 +512,7 @@ const render = function (
idSelector
);
+ // svg is a HTML element (not a d3 node)
const style1 = document.createElement('style');
style1.innerHTML = `${idSelector} ` + rules;
svg.insertBefore(style1, firstChild);
@@ -522,6 +526,13 @@ const render = function (
throw e;
}
+ // This is the d3 node for the svg element
+ const svgNode = root.select(`${enclosingDivID_selector} svg`);
+ setA11yDiagramInfo(svgNode, graphType);
+ const a11yTitle = diag.db.getAccTitle !== undefined ? diag.db.getAccTitle() : null;
+ const a11yDescr = diag.db.getAccDescription !== undefined ? diag.db.getAccDescription() : null;
+ addSVGa11yTitleDescription(svgNode, a11yTitle, a11yDescr, svgNode.attr('id'));
+
// -------------------------------------------------------------------------------
// Clean up SVG code
root.select(`[id="${id}"]`).selectAll('foreignobject > *').attr('xmlns', XMLNS_XHTML_STD);
@@ -763,7 +774,7 @@ const renderAsync = async function (
attachFunctions();
// -------------------------------------------------------------------------------
- // Remove the temporary element if appropriate
+ // Remove the temporary HTML element if appropriate
const tmpElementSelector = isSandboxed ? iFrameID_selector : enclosingDivID_selector;
const node = select(tmpElementSelector).node();
if (node && 'remove' in node) {
From 0adc6a6112bca1d6461eb85ae7603b7fa7b3287f Mon Sep 17 00:00:00 2001
From: "Ashley Engelund (weedySeaDragon @ github)"
Date: Thu, 17 Nov 2022 12:28:11 -0800
Subject: [PATCH 031/129] remove a11y from individual diagrams; now happens in
mermaidAPI render
---
cypress/integration/rendering/gantt.spec.js | 32 ---------
.../integration/rendering/requirement.spec.js | 65 -------------------
.../mermaid/src/diagrams/c4/c4Renderer.js | 2 -
.../src/diagrams/class/classRenderer-v2.js | 2 -
.../src/diagrams/class/classRenderer.js | 2 -
.../mermaid/src/diagrams/er/erRenderer.js | 3 -
.../src/diagrams/er/parser/erDiagram.spec.js | 16 -----
.../src/diagrams/flowchart/flowRenderer-v2.js | 4 --
.../src/diagrams/flowchart/flowRenderer.js | 4 --
.../src/diagrams/gantt/ganttRenderer.js | 3 -
.../src/diagrams/git/gitGraphRenderer.js | 4 --
.../mermaid/src/diagrams/pie/pieRenderer.js | 2 -
.../requirement/requirementRenderer.js | 3 -
.../src/diagrams/sequence/sequenceRenderer.ts | 4 --
.../src/diagrams/state/stateRenderer-v2.js | 2 -
.../src/diagrams/state/stateRenderer.js | 2 -
.../diagrams/user-journey/journeyRenderer.ts | 4 --
17 files changed, 154 deletions(-)
diff --git a/cypress/integration/rendering/gantt.spec.js b/cypress/integration/rendering/gantt.spec.js
index b75e682c6..c0156eee3 100644
--- a/cypress/integration/rendering/gantt.spec.js
+++ b/cypress/integration/rendering/gantt.spec.js
@@ -310,38 +310,6 @@ describe('Gantt diagram', () => {
);
});
- it('should render accessibility tags', function () {
- const expectedTitle = 'Gantt Diagram';
- const expectedAccDescription = 'Tasks for Q4';
- renderGraph(
- `
- gantt
- accTitle: ${expectedTitle}
- accDescr: ${expectedAccDescription}
- dateFormat YYYY-MM-DD
- section Section
- A task :a1, 2014-01-01, 30d
- `,
- {}
- );
- cy.get('svg').should((svg) => {
- const el = svg.get(0);
- const children = Array.from(el.children);
-
- const titleEl = children.find(function (node) {
- return node.tagName === 'title';
- });
- const descriptionEl = children.find(function (node) {
- return node.tagName === 'desc';
- });
-
- expect(titleEl).to.exist;
- expect(titleEl.textContent).to.equal(expectedTitle);
- expect(descriptionEl).to.exist;
- expect(descriptionEl.textContent).to.equal(expectedAccDescription);
- });
- });
-
it('should render a gantt diagram with tick is 15 minutes', () => {
imgSnapshotTest(
`
diff --git a/cypress/integration/rendering/requirement.spec.js b/cypress/integration/rendering/requirement.spec.js
index be27f39fa..0bf9014bf 100644
--- a/cypress/integration/rendering/requirement.spec.js
+++ b/cypress/integration/rendering/requirement.spec.js
@@ -46,69 +46,4 @@ describe('Requirement diagram', () => {
);
cy.get('svg');
});
-
- it('should render accessibility tags', function () {
- const expectedTitle = 'Gantt Diagram';
- const expectedAccDescription = 'Tasks for Q4';
- renderGraph(
- `
- requirementDiagram
- accTitle: ${expectedTitle}
- accDescr: ${expectedAccDescription}
-
- requirement test_req {
- id: 1
- text: the test text.
- risk: high
- verifymethod: test
- }
-
- functionalRequirement test_req2 {
- id: 1.1
- text: the second test text.
- risk: low
- verifymethod: inspection
- }
-
- performanceRequirement test_req3 {
- id: 1.2
- text: the third test text.
- risk: medium
- verifymethod: demonstration
- }
-
- element test_entity {
- type: simulation
- }
-
- element test_entity2 {
- type: word doc
- docRef: reqs/test_entity
- }
-
-
- test_entity - satisfies -> test_req2
- test_req - traces -> test_req2
- test_req - contains -> test_req3
- test_req <- copies - test_entity2
- `,
- {}
- );
- cy.get('svg').should((svg) => {
- const el = svg.get(0);
- const children = Array.from(el.children);
-
- const titleEl = children.find(function (node) {
- return node.tagName === 'title';
- });
- const descriptionEl = children.find(function (node) {
- return node.tagName === 'desc';
- });
-
- expect(titleEl).to.exist;
- expect(titleEl.textContent).to.equal(expectedTitle);
- expect(descriptionEl).to.exist;
- expect(descriptionEl.textContent).to.equal(expectedAccDescription);
- });
- });
});
diff --git a/packages/mermaid/src/diagrams/c4/c4Renderer.js b/packages/mermaid/src/diagrams/c4/c4Renderer.js
index a2d7813c6..580abbccc 100644
--- a/packages/mermaid/src/diagrams/c4/c4Renderer.js
+++ b/packages/mermaid/src/diagrams/c4/c4Renderer.js
@@ -8,7 +8,6 @@ import * as configApi from '../../config';
import assignWithDepth from '../../assignWithDepth';
import { wrapLabel, calculateTextWidth, calculateTextHeight } from '../../utils';
import { configureSvgSize } from '../../setupGraphViewbox';
-import { addSVGa11yTitleDescription } from '../../accessibility';
let globalBoundaryMaxX = 0,
globalBoundaryMaxY = 0;
@@ -676,7 +675,6 @@ export const draw = function (_text, id, _version, diagObj) {
(height + extraVertForTitle)
);
- addSVGa11yTitleDescription(parser.yy, diagram, id);
log.debug(`models:`, box);
};
diff --git a/packages/mermaid/src/diagrams/class/classRenderer-v2.js b/packages/mermaid/src/diagrams/class/classRenderer-v2.js
index 75e7cdafb..9c7002aa4 100644
--- a/packages/mermaid/src/diagrams/class/classRenderer-v2.js
+++ b/packages/mermaid/src/diagrams/class/classRenderer-v2.js
@@ -7,7 +7,6 @@ import { curveLinear } from 'd3';
import { interpolateToCurve, getStylesFromArray } from '../../utils';
import { setupGraphViewbox } from '../../setupGraphViewbox';
import common from '../common/common';
-import { addSVGa11yTitleDescription } from '../../accessibility';
let idCache = {};
@@ -452,7 +451,6 @@ export const draw = function (text, id, _version, diagObj) {
}
}
- addSVGa11yTitleDescription(diagObj.db, svg, id);
// If node has a link, wrap it in an anchor SVG object.
// const keys = Object.keys(classes);
// keys.forEach(function(key) {
diff --git a/packages/mermaid/src/diagrams/class/classRenderer.js b/packages/mermaid/src/diagrams/class/classRenderer.js
index 4e4b31a82..b66222ccc 100644
--- a/packages/mermaid/src/diagrams/class/classRenderer.js
+++ b/packages/mermaid/src/diagrams/class/classRenderer.js
@@ -5,7 +5,6 @@ import { log } from '../../logger';
import svgDraw from './svgDraw';
import { configureSvgSize } from '../../setupGraphViewbox';
import { getConfig } from '../../config';
-import { addSVGa11yTitleDescription } from '../../accessibility';
let idCache = {};
const padding = 20;
@@ -272,7 +271,6 @@ export const draw = function (text, id, _version, diagObj) {
const vBox = `${svgBounds.x - padding} ${svgBounds.y - padding} ${width} ${height}`;
log.debug(`viewBox ${vBox}`);
diagram.attr('viewBox', vBox);
- addSVGa11yTitleDescription(diagObj.db, diagram, id);
};
export default {
diff --git a/packages/mermaid/src/diagrams/er/erRenderer.js b/packages/mermaid/src/diagrams/er/erRenderer.js
index f29eb44d7..ac32a0287 100644
--- a/packages/mermaid/src/diagrams/er/erRenderer.js
+++ b/packages/mermaid/src/diagrams/er/erRenderer.js
@@ -5,7 +5,6 @@ import { getConfig } from '../../config';
import { log } from '../../logger';
import erMarkers from './erMarkers';
import { configureSvgSize } from '../../setupGraphViewbox';
-import { addSVGa11yTitleDescription } from '../../accessibility';
import { parseGenericTypes } from '../common/common';
import { v4 as uuid4 } from 'uuid';
@@ -656,8 +655,6 @@ export const draw = function (text, id, _version, diagObj) {
configureSvgSize(svg, height, width, conf.useMaxWidth);
svg.attr('viewBox', `${svgBounds.x - padding} ${svgBounds.y - padding} ${width} ${height}`);
-
- addSVGa11yTitleDescription(diagObj.db, svg, id);
}; // draw
/**
diff --git a/packages/mermaid/src/diagrams/er/parser/erDiagram.spec.js b/packages/mermaid/src/diagrams/er/parser/erDiagram.spec.js
index eb738fe4b..6131f7697 100644
--- a/packages/mermaid/src/diagrams/er/parser/erDiagram.spec.js
+++ b/packages/mermaid/src/diagrams/er/parser/erDiagram.spec.js
@@ -337,22 +337,6 @@ describe('when parsing ER diagram it...', function () {
expect(erDb.getAccDescription()).toBe('this graph is about stuff');
});
- it('should allow for a accessibility title and multi line description (accDescr)', function () {
- const teacherRole = 'is teacher of';
- const line1 = `TEACHER }o--o{ STUDENT : "${teacherRole}"`;
-
- erDiagram.parser.parse(
- `erDiagram
- accTitle: graph title
- accDescr {
- this graph is about stuff
- }\n
- ${line1}`
- );
- expect(erDb.getAccTitle()).toBe('graph title');
- expect(erDb.getAccDescription()).toBe('this graph is about stuff');
- });
-
it('should allow more than one relationship between the same two entities', function () {
const line1 = 'CAR ||--o{ PERSON : "insured for"';
const line2 = 'CAR }o--|| PERSON : "owned by"';
diff --git a/packages/mermaid/src/diagrams/flowchart/flowRenderer-v2.js b/packages/mermaid/src/diagrams/flowchart/flowRenderer-v2.js
index a5f991a86..437c5a120 100644
--- a/packages/mermaid/src/diagrams/flowchart/flowRenderer-v2.js
+++ b/packages/mermaid/src/diagrams/flowchart/flowRenderer-v2.js
@@ -10,7 +10,6 @@ import { log } from '../../logger';
import common, { evaluate } from '../common/common';
import { interpolateToCurve, getStylesFromArray } from '../../utils';
import { setupGraphViewbox } from '../../setupGraphViewbox';
-import { addSVGa11yTitleDescription } from '../../accessibility';
const conf = {};
export const setConf = function (cnf) {
@@ -430,9 +429,6 @@ export const draw = function (text, id, _version, diagObj) {
// Set up an SVG group so that we can translate the final graph.
const svg = root.select(`[id="${id}"]`);
- // Adds title and description to the flow chart
- addSVGa11yTitleDescription(diagObj.db, svg, id);
-
// Run the renderer. This is what draws the final graph.
const element = root.select('#' + id + ' g');
render(element, g, ['point', 'circle', 'cross'], 'flowchart', id);
diff --git a/packages/mermaid/src/diagrams/flowchart/flowRenderer.js b/packages/mermaid/src/diagrams/flowchart/flowRenderer.js
index e9069ff4d..69eb8a9f3 100644
--- a/packages/mermaid/src/diagrams/flowchart/flowRenderer.js
+++ b/packages/mermaid/src/diagrams/flowchart/flowRenderer.js
@@ -8,7 +8,6 @@ import common, { evaluate } from '../common/common';
import { interpolateToCurve, getStylesFromArray } from '../../utils';
import { setupGraphViewbox } from '../../setupGraphViewbox';
import flowChartShapes from './flowChartShapes';
-import { addSVGa11yTitleDescription } from '../../accessibility';
const conf = {};
export const setConf = function (cnf) {
@@ -417,9 +416,6 @@ export const draw = function (text, id, _version, diagObj) {
// Set up an SVG group so that we can translate the final graph.
const svg = root.select(`[id="${id}"]`);
- // Adds title and description to the flow chart
- addSVGa11yTitleDescription(diagObj.db, svg, id);
-
// Run the renderer. This is what draws the final graph.
const element = root.select('#' + id + ' g');
render(element, g);
diff --git a/packages/mermaid/src/diagrams/gantt/ganttRenderer.js b/packages/mermaid/src/diagrams/gantt/ganttRenderer.js
index dc92be1f0..9840cede4 100644
--- a/packages/mermaid/src/diagrams/gantt/ganttRenderer.js
+++ b/packages/mermaid/src/diagrams/gantt/ganttRenderer.js
@@ -19,7 +19,6 @@ import {
import common from '../common/common';
import { getConfig } from '../../config';
import { configureSvgSize } from '../../setupGraphViewbox';
-import { addSVGa11yTitleDescription } from '../../accessibility';
export const setConf = function () {
log.debug('Something is calling, setConf, remove the call');
@@ -116,8 +115,6 @@ export const draw = function (text, id, version, diagObj) {
.attr('y', conf.titleTopMargin)
.attr('class', 'titleText');
- addSVGa11yTitleDescription(diagObj.db, svg, id);
-
/**
* @param tasks
* @param pageWidth
diff --git a/packages/mermaid/src/diagrams/git/gitGraphRenderer.js b/packages/mermaid/src/diagrams/git/gitGraphRenderer.js
index c9e02a1e4..fdd07059c 100644
--- a/packages/mermaid/src/diagrams/git/gitGraphRenderer.js
+++ b/packages/mermaid/src/diagrams/git/gitGraphRenderer.js
@@ -1,7 +1,6 @@
import { select } from 'd3';
import { getConfig, setupGraphViewbox } from '../../diagram-api/diagramAPI';
import { log } from '../../logger';
-import { addSVGa11yTitleDescription } from '../../accessibility';
let allCommitsDict = {};
@@ -512,9 +511,6 @@ export const draw = function (txt, id, ver, diagObj) {
const diagram = select(`[id="${id}"]`);
- // Adds title and description to the flow chart
- addSVGa11yTitleDescription(diagObj.db, diagram, id);
-
drawCommits(diagram, allCommitsDict, false);
if (gitGraphConfig.showBranches) {
drawBranches(diagram, branches);
diff --git a/packages/mermaid/src/diagrams/pie/pieRenderer.js b/packages/mermaid/src/diagrams/pie/pieRenderer.js
index daddfda86..d02f97f3f 100644
--- a/packages/mermaid/src/diagrams/pie/pieRenderer.js
+++ b/packages/mermaid/src/diagrams/pie/pieRenderer.js
@@ -3,7 +3,6 @@ import { select, scaleOrdinal, pie as d3pie, arc } from 'd3';
import { log } from '../../logger';
import { configureSvgSize } from '../../setupGraphViewbox';
import * as configApi from '../../config';
-import { addSVGa11yTitleDescription } from '../../accessibility';
let conf = configApi.getConfig();
@@ -53,7 +52,6 @@ export const draw = (txt, id, _version, diagObj) => {
const diagram = root.select('#' + id);
configureSvgSize(diagram, height, width, conf.pie.useMaxWidth);
- addSVGa11yTitleDescription(diagObj.db, diagram, id);
// Set viewBox
elem.setAttribute('viewBox', '0 0 ' + width + ' ' + height);
diff --git a/packages/mermaid/src/diagrams/requirement/requirementRenderer.js b/packages/mermaid/src/diagrams/requirement/requirementRenderer.js
index 60f456f0b..9b5675adf 100644
--- a/packages/mermaid/src/diagrams/requirement/requirementRenderer.js
+++ b/packages/mermaid/src/diagrams/requirement/requirementRenderer.js
@@ -6,7 +6,6 @@ import { configureSvgSize } from '../../setupGraphViewbox';
import common from '../common/common';
import markers from './requirementMarkers';
import { getConfig } from '../../config';
-import { addSVGa11yTitleDescription } from '../../accessibility';
let conf = {};
let relCnt = 0;
@@ -363,8 +362,6 @@ export const draw = (text, id, _version, diagObj) => {
configureSvgSize(svg, height, width, conf.useMaxWidth);
svg.attr('viewBox', `${svgBounds.x - padding} ${svgBounds.y - padding} ${width} ${height}`);
- // Adds title and description to the requirements diagram
- addSVGa11yTitleDescription(diagObj.db, svg, id);
};
export default {
diff --git a/packages/mermaid/src/diagrams/sequence/sequenceRenderer.ts b/packages/mermaid/src/diagrams/sequence/sequenceRenderer.ts
index bf8a512c1..356b1d4c4 100644
--- a/packages/mermaid/src/diagrams/sequence/sequenceRenderer.ts
+++ b/packages/mermaid/src/diagrams/sequence/sequenceRenderer.ts
@@ -9,11 +9,8 @@ import * as configApi from '../../config';
import assignWithDepth from '../../assignWithDepth';
import utils from '../../utils';
import { configureSvgSize } from '../../setupGraphViewbox';
-import { addSVGa11yTitleDescription } from '../../accessibility';
import Diagram from '../../Diagram';
-// FIXME insert a11y title and desc
-
let conf = {};
export const bounds = {
@@ -906,7 +903,6 @@ export const draw = function (_text: string, id: string, _version: string, diagO
(height + extraVertForTitle)
);
- addSVGAccessibilityFields(diagObj.db, diagram, id);
log.debug(`models:`, bounds.models);
};
diff --git a/packages/mermaid/src/diagrams/state/stateRenderer-v2.js b/packages/mermaid/src/diagrams/state/stateRenderer-v2.js
index e3255bc65..ca0cf039c 100644
--- a/packages/mermaid/src/diagrams/state/stateRenderer-v2.js
+++ b/packages/mermaid/src/diagrams/state/stateRenderer-v2.js
@@ -5,7 +5,6 @@ import { render } from '../../dagre-wrapper/index.js';
import { log } from '../../logger';
import { configureSvgSize } from '../../setupGraphViewbox';
import common from '../common/common';
-import { addSVGa11yTitleDescription } from '../../accessibility';
import {
DEFAULT_DIAGRAM_DIRECTION,
DEFAULT_NESTED_DOC_DIR,
@@ -472,7 +471,6 @@ export const draw = function (text, id, _version, diag) {
label.insertBefore(rect, label.firstChild);
// }
}
- addSVGa11yTitleDescription(diag.db, svg, id);
};
export default {
diff --git a/packages/mermaid/src/diagrams/state/stateRenderer.js b/packages/mermaid/src/diagrams/state/stateRenderer.js
index b69d1aaee..e4e882106 100644
--- a/packages/mermaid/src/diagrams/state/stateRenderer.js
+++ b/packages/mermaid/src/diagrams/state/stateRenderer.js
@@ -6,7 +6,6 @@ import common from '../common/common';
import { drawState, addTitleAndBox, drawEdge } from './shapes';
import { getConfig } from '../../config';
import { configureSvgSize } from '../../setupGraphViewbox';
-import { addSVGa11yTitleDescription } from '../../accessibility';
// TODO Move conf object to main conf in mermaidAPI
let conf;
@@ -97,7 +96,6 @@ export const draw = function (text, id, _version, diagObj) {
'viewBox',
`${bounds.x - conf.padding} ${bounds.y - conf.padding} ` + width + ' ' + height
);
- addSVGa11yTitleDescription(diagObj.db, diagram, id);
};
const getLabelWidth = (text) => {
return text ? text.length * conf.fontSizeFactor : 1;
diff --git a/packages/mermaid/src/diagrams/user-journey/journeyRenderer.ts b/packages/mermaid/src/diagrams/user-journey/journeyRenderer.ts
index 5a2c1283d..f3b6acb25 100644
--- a/packages/mermaid/src/diagrams/user-journey/journeyRenderer.ts
+++ b/packages/mermaid/src/diagrams/user-journey/journeyRenderer.ts
@@ -3,8 +3,6 @@ import { select } from 'd3';
import svgDraw from './svgDraw';
import { getConfig } from '../../config';
import { configureSvgSize } from '../../setupGraphViewbox';
-import { addSVGa11yTitleDescription } from '../../accessibility';
-// FIXME insert a11y title and desc
export const setConf = function (cnf) {
const keys = Object.keys(cnf);
@@ -122,8 +120,6 @@ export const draw = function (text, id, version, diagObj) {
diagram.attr('viewBox', `${box.startx} -25 ${width} ${height + extraVertForTitle}`);
diagram.attr('preserveAspectRatio', 'xMinYMin meet');
diagram.attr('height', height + extraVertForTitle + 25);
-
- addSVGAccessibilityFields(diagObj.db, diagram, id);
};
export const bounds = {
From 4fb4aa417cb5633e81ce49c1b87d7a695f49a56e Mon Sep 17 00:00:00 2001
From: "Ashley Engelund (weedySeaDragon @ github)"
Date: Thu, 17 Nov 2022 15:45:28 -0800
Subject: [PATCH 032/129] doc: revise A11y: fix multi-line ex, +describedby,
alpha sort examples
---
docs/community/newDiagram.md | 46 +-
docs/config/accessibility.md | 409 +++++++++++-------
.../mermaid/src/docs/config/accessibility.md | 257 ++++++-----
3 files changed, 417 insertions(+), 295 deletions(-)
diff --git a/docs/community/newDiagram.md b/docs/community/newDiagram.md
index e49dd3749..288af42cd 100644
--- a/docs/community/newDiagram.md
+++ b/docs/community/newDiagram.md
@@ -14,8 +14,8 @@ This would be to define a jison grammar for the new diagram type. That should st
For instance:
-- the flowchart starts with the keyword graph.
-- the sequence diagram starts with the keyword sequenceDiagram
+- the flowchart starts with the keyword _graph_
+- the sequence diagram starts with the keyword _sequenceDiagram_
#### Store data found during parsing
@@ -61,6 +61,11 @@ Place the renderer in the diagram folder.
### Step 3: Detection of the new diagram type
The second thing to do is to add the capability to detect the new new diagram to type to the detectType in utils.js. The detection should return a key for the new diagram type.
+[This key will be used to as the aria roledescription](#aria-roledescription), so it should be a word that clearly describes the diagram type.
+For example, if your new diagram use a UML deployment diagram, a good key would be "UMLDeploymentDiagram" because assistive technologies such as a screen reader
+would voice that as "U-M-L Deployment diagram." Another good key would be "deploymentDiagram" because that would be voiced as "Deployment Diagram." A bad key would be "deployment" because that would not sufficiently describe the diagram.
+
+Note that the diagram type key does not have to be the same as the diagram keyword chosen for the [grammar](#grammar), but it is helpful if they are the same.
### Step 4: The final piece - triggering the rendering
@@ -168,17 +173,23 @@ It is probably a good idea to keep the handling similar to this in your new diag
## Accessibility
-The syntax for adding title and description looks like this:
+Mermaid automatically adds the following accessibility information for the diagram SVG HTML element:
- accTitle: The title
- accDescr: The description
+- aria-roledescription
+- accessible title
+- accessible description
- accDescr {
- Syntax for a description text
- written on multiple lines.
- }
+### aria-roledescription
-In a similar way to the directives the jison syntax are quite similar between the diagrams.
+The aria-roledescription is automatically set to [the diagram type](#step-3--detection-of-the-new-diagram-type) and inserted into the SVG element.
+
+See [the definition of aria-roledescription](https://www.w3.org/TR/wai-aria-1.1/#aria-roledescription) in [the Accessible Rich Internet Applications W3 standard.](https://www.w3.org/WAI/standards-guidelines/aria/)
+
+### accessible title and description
+
+The syntax for accessible titles and descriptions is described in [the Accessibility documenation section.](../config/accessibility.md)
+
+In a similar way to the directives, the jison syntax are quite similar between the diagrams.
```jison
@@ -214,20 +225,7 @@ The functions for setting title and description are provided by a common module.
clear as commonClear,
} from '../../commonDb';
-Starting with Mermaid version, the accessibility tags are inserted into the SVG element in the `render` function in mermaidAPI.
-
-In version \_\_\_ and before, you need to insert the accessibility tags in your renderer:
-
-**In the renderer:**
-
-```js
-import addSVGAccessibilityFields from '../../accessibility';
-
-/* ... */
-
-// Adds title and description to the flow chart
-addSVGAccessibilityFields(parser.yy, svg, id);
-```
+The accessibility title and description are inserted into the SVG element in the `render` function in mermaidAPI.
## Theming
diff --git a/docs/config/accessibility.md b/docs/config/accessibility.md
index 8fa4aa3ac..e5b96670e 100644
--- a/docs/config/accessibility.md
+++ b/docs/config/accessibility.md
@@ -10,118 +10,169 @@
Now with Mermaid library in much wider use, we have started to work towards more accessible features, based on the feedback from the community.
-To begin with, we have added a new feature to Mermaid library, which is to support accessibility options, **Accessibility Title** and **Accessibility Description**.
+Adding accessibility means that the rich information communicated by visual diagrams can be made available to those using assistive technologies (and of course to search engines).
+[Read more about Accessible Rich Internet Applications and the W3 standards.](https://www.w3.org/WAI/standards-guidelines/aria/)
-This support for accessibility options is available for all the diagrams/chart types. Also, we have tired to keep the same format for the accessibility options, so that it is easy to understand and maintain.
+Mermaid will automatically insert the [aria-roledescription](#aria-roledescription) and, if provided in the diagram text by the diagram author, the [accessible title and description.](#accessible-title-and-description)
-## Defining Accessibility Options
+### aria-roledescription
-### Single line accessibility values
+The [aria-roledescription](https://www.w3.org/TR/wai-aria-1.1/#aria-roledescription) for the SVG HTML element is set to the diagram type key. (Note this may be slightly different than the keyword used for the diagram in the diagram text.)
-The diagram authors can now add the accessibility options in the diagram definition, using the `accTitle` and `accDescr` keywords, where each keyword is followed by `:` and the string value for title and description like:
+For example: The diagram type key for a state diagram is "stateDiagram". Here (a part of) the HTML of the SVG tag that shows the automatically inserted aria-roledscription set to "stateDiagram". _(Note that some of the SVG attributes and the SVG contents are omitted for clarity.):_
-- `accTitle: "Your Accessibility Title"` or
-- `accDescr: "Your Accessibility Description"`
+```html
+
+```
-**When these two options are defined, they will add a corresponding `` and `` tag in the SVG.**
+### Accessible Title and Description
-Let us take a look at the following example with a flowchart diagram:
+Support for accessible titles and descriptions is available for all diagrams/chart types. We have tried to keep the same keywords and format for all diagrams so that it is easy to understand and maintain.
+
+The accessible title and description will add `` and `` elements within the SVG element and the [aria-labelledby](https://www.w3.org/TR/wai-aria/#aria-labelledby) and [aria-describedby](https://www.w3.org/TR/wai-aria/#aria-describedby) attributes in the SVG tag.
+
+Here is HTML that is generated, showing that the SVG element is labelled by the accessible title (id = `chart-title-mermaid-1668725057758`)
+and described by the accessible description (id = `chart-desc-mermaid-1668725057758` );
+and the accessible title element (text = "This is the accessible title")
+and the accessible description element (text = "This is an accessible description").
+
+_(Note that some of the SVG attributes and the SVG contents are omitted for clarity.)_
+
+```html
+
+```
+
+Details for the syntax follow.
+
+#### accessible title
+
+The **accessible title** is specified with the **accTitle** _keyword_, followed by a colon (`:`), and the string value for the title.
+The string value ends at the end of the line. (It can only be a single line.)
+
+Ex: `accTitle: This is a single line title`
+
+See [the accTitle and accDescr usage examples](#acctitle-and-accdescr-usage-examples) for how this can be used in a diagram and the resulting HTML generated.
+
+#### accessible description
+
+An accessible description can be 1 line long (a single line) or many lines long.
+
+The **single line accessible description** is specified with the **accDescr** _keyword_, followed by a colon (`:`), followed by the string value for the description.
+
+Ex: `accDescr: This is a single line description.`
+
+A **multiple line accessible description** _does not have a colon (`:`) after the accDescr keyword_ and is surrounded by curly brackets (`{}`).
+
+Ex:
+
+ accDescr { The official Bob's Burgers corporate processes that are used
+ for making very, very big decisions.
+ This is actually a very simple flow: see the big decision and then make the big decision.}
+
+See [the accTitle and accDescr usage examples](#acctitle-and-accdescr-usage-examples) for how this can be used in a diagram and the resulting HTML generated.
+
+#### accTitle and accDescr Usage Examples
+
+- Flowchart with the accessible title "Big Decisions" and the single-line accessible description "Bob's Burgers process for making big decisions"
```mermaid-example
- graph LR
- accTitle: Big decisions
- accDescr: Flow chart of the decision making process
- A[Hard] -->|Text| B(Round)
- B --> C{Decision}
- C -->|One| D[Result 1]
-
+ graph LR
+ accTitle: Big Decisions
+ accDescr: Bob's Burgers process for making big decisions
+ A[Identify Big Descision] --> B{Make Big Decision}
+ B --> D[Be done]
```
```mermaid
- graph LR
- accTitle: Big decisions
- accDescr: Flow chart of the decision making process
- A[Hard] -->|Text| B(Round)
- B --> C{Decision}
- C -->|One| D[Result 1]
-
+ graph LR
+ accTitle: Big Decisions
+ accDescr: Bob's Burgers process for making big decisions
+ A[Identify Big Descision] --> B{Make Big Decision}
+ B --> D[Be done]
```
-See in the code snippet above, the `accTitle` and `accDescr` are defined in the diagram definition. They result in the following tags in SVG code:
+Here is the HTML generated for the SVG element: _(Note that some of the SVG attributes and the SVG contents are omitted for clarity.):_
-
+```html
+
+```
-### Multi-line Accessibility title/description
-
-You can also define the accessibility options in a multi-line format, where the keyword is followed by opening curly bracket `{` and then multiple lines, followed by a closing `}`.
-
-`accTitle: My single line title value` (**_single line format_**)
-
-vs
-
-`accDescr: { My multi-line description of the diagram }` (**_multi-line format_**)
-
-Let us look at it in the following example, with same flowchart:
+- Flowchart with the accessible title "Bob's Burger's Making Big Decisions" and the multiple line accessible description "The official Bob's Burgers corporate processes that are used
+ for making very, very big decisions.
+ This is actually a very simple flow: identify the big decision and then make the big decision."
```mermaid-example
- graph LR
- accTitle: Big decisions
-
+ graph LR
+ accTitle: Bob's Burger's Making Big Decisions
accDescr {
- My multi-line description
- of the diagram
- }
-
- A[Hard] -->|Text| B(Round)
- B --> C{Decision}
- C -->|One| D[Result 1]
-
+ The official Bob's Burgers corporate processes that are used
+ for making very, very big decisions.
+ This is actually a very simple flow: identify the big decision and then make the big decision.
+ }
+ A[Identify Big Descision] --> B{Make Big Decision}
+ B --> D[Be done]
```
```mermaid
- graph LR
- accTitle: Big decisions
-
+ graph LR
+ accTitle: Bob's Burger's Making Big Decisions
accDescr {
- My multi-line description
- of the diagram
- }
-
- A[Hard] -->|Text| B(Round)
- B --> C{Decision}
- C -->|One| D[Result 1]
-
+ The official Bob's Burgers corporate processes that are used
+ for making very, very big decisions.
+ This is actually a very simple flow: identify the big decision and then make the big decision.
+ }
+ A[Identify Big Descision] --> B{Make Big Decision}
+ B --> D[Be done]
```
-See in the code snippet above, the `accTitle` and `accDescr` are defined in the diagram definition. They result in the following tags in SVG code:
+Here is the HTML generated for the SVG element: _(Note that some of the SVG attributes and the SVG contents are omitted for clarity.):_
-
-
-### Sample Code Snippet for other diagram types
-
-#### Sequence Diagram
-
-```mermaid-example
- sequenceDiagram
- accTitle: My Sequence Diagram
- accDescr: My Sequence Diagram Description
-
- Alice->>John: Hello John, how are you?
- John-->>Alice: Great!
- Alice-)John: See you later!
+```html
+
```
-```mermaid
- sequenceDiagram
- accTitle: My Sequence Diagram
- accDescr: My Sequence Diagram Description
+#### Sample Code Snippets for other diagram types
- Alice->>John: Hello John, how are you?
- John-->>Alice: Great!
- Alice-)John: See you later!
-```
-
-#### Class Diagram
+##### Class Diagram
```mermaid-example
classDiagram
@@ -139,27 +190,7 @@ See in the code snippet above, the `accTitle` and `accDescr` are defined in the
Vehicle <|-- Car
```
-#### State Diagram
-
-```mermaid-example
- stateDiagram
- accTitle: My State Diagram
- accDescr: My State Diagram Description
-
- s1 --> s2
-
-```
-
-```mermaid
- stateDiagram
- accTitle: My State Diagram
- accDescr: My State Diagram Description
-
- s1 --> s2
-
-```
-
-#### Entity Relationship Diagram
+##### Entity Relationship Diagram
```mermaid-example
erDiagram
@@ -183,41 +214,7 @@ See in the code snippet above, the `accTitle` and `accDescr` are defined in the
```
-#### User Journey Diagram
-
-```mermaid-example
- journey
- accTitle: My User Journey Diagram
- accDescr: My User Journey Diagram Description
-
- title My working day
- section Go to work
- Make tea: 5: Me
- Go upstairs: 3: Me
- Do work: 1: Me, Cat
- section Go home
- Go downstairs: 5: Me
- Sit down: 5: Me
-
-```
-
-```mermaid
- journey
- accTitle: My User Journey Diagram
- accDescr: My User Journey Diagram Description
-
- title My working day
- section Go to work
- Make tea: 5: Me
- Go upstairs: 3: Me
- Do work: 1: Me, Cat
- section Go home
- Go downstairs: 5: Me
- Sit down: 5: Me
-
-```
-
-#### Gantt Chart
+##### Gantt Chart
```mermaid-example
gantt
@@ -251,7 +248,45 @@ See in the code snippet above, the `accTitle` and `accDescr` are defined in the
```
-#### Pie Chart
+##### Gitgraph
+
+```mermaid-example
+ gitGraph
+ accTitle: My Gitgraph Accessibility Title
+ accDescr: My Gitgraph Accessibility Description
+
+ commit
+ commit
+ branch develop
+ checkout develop
+ commit
+ commit
+ checkout main
+ merge develop
+ commit
+ commit
+
+```
+
+```mermaid
+ gitGraph
+ accTitle: My Gitgraph Accessibility Title
+ accDescr: My Gitgraph Accessibility Description
+
+ commit
+ commit
+ branch develop
+ checkout develop
+ commit
+ commit
+ checkout main
+ merge develop
+ commit
+ commit
+
+```
+
+##### Pie Chart
```mermaid-example
pie
@@ -279,7 +314,7 @@ See in the code snippet above, the `accTitle` and `accDescr` are defined in the
```
-#### Requirement Diagram
+##### Requirement Diagram
```mermaid-example
requirementDiagram
@@ -321,40 +356,78 @@ See in the code snippet above, the `accTitle` and `accDescr` are defined in the
```
-#### Gitgraph
+##### Sequence Diagram
```mermaid-example
- gitGraph
- accTitle: My Gitgraph Accessibility Title
- accDescr: My Gitgraph Accessibility Description
+ sequenceDiagram
+ accTitle: My Sequence Diagram
+ accDescr: My Sequence Diagram Description
- commit
- commit
- branch develop
- checkout develop
- commit
- commit
- checkout main
- merge develop
- commit
- commit
+ Alice->>John: Hello John, how are you?
+ John-->>Alice: Great!
+ Alice-)John: See you later!
+```
+
+```mermaid
+ sequenceDiagram
+ accTitle: My Sequence Diagram
+ accDescr: My Sequence Diagram Description
+
+ Alice->>John: Hello John, how are you?
+ John-->>Alice: Great!
+ Alice-)John: See you later!
+```
+
+##### State Diagram
+
+```mermaid-example
+ stateDiagram
+ accTitle: My State Diagram
+ accDescr: My State Diagram Description
+
+ s1 --> s2
```
```mermaid
- gitGraph
- accTitle: My Gitgraph Accessibility Title
- accDescr: My Gitgraph Accessibility Description
+ stateDiagram
+ accTitle: My State Diagram
+ accDescr: My State Diagram Description
- commit
- commit
- branch develop
- checkout develop
- commit
- commit
- checkout main
- merge develop
- commit
- commit
+ s1 --> s2
+
+```
+
+##### User Journey Diagram
+
+```mermaid-example
+ journey
+ accTitle: My User Journey Diagram
+ accDescr: My User Journey Diagram Description
+
+ title My working day
+ section Go to work
+ Make tea: 5: Me
+ Go upstairs: 3: Me
+ Do work: 1: Me, Cat
+ section Go home
+ Go downstairs: 5: Me
+ Sit down: 5: Me
+
+```
+
+```mermaid
+ journey
+ accTitle: My User Journey Diagram
+ accDescr: My User Journey Diagram Description
+
+ title My working day
+ section Go to work
+ Make tea: 5: Me
+ Go upstairs: 3: Me
+ Do work: 1: Me, Cat
+ section Go home
+ Go downstairs: 5: Me
+ Sit down: 5: Me
```
diff --git a/packages/mermaid/src/docs/config/accessibility.md b/packages/mermaid/src/docs/config/accessibility.md
index ade20a839..5545ce1bc 100644
--- a/packages/mermaid/src/docs/config/accessibility.md
+++ b/packages/mermaid/src/docs/config/accessibility.md
@@ -4,83 +4,121 @@
Now with Mermaid library in much wider use, we have started to work towards more accessible features, based on the feedback from the community.
-To begin with, we have added a new feature to Mermaid library, which is to support accessibility options, **Accessibility Title** and **Accessibility Description**.
+Adding accessibility means that the rich information communicated by visual diagrams can be made available to those using assistive technologies (and of course to search engines).
+[Read more about Accessible Rich Internet Applications and the W3 standards.](https://www.w3.org/WAI/standards-guidelines/aria/)
-This support for accessibility options is available for all the diagrams/chart types. Also, we have tired to keep the same format for the accessibility options, so that it is easy to understand and maintain.
+Mermaid will automatically insert the [aria-roledescription](#aria-roledescription) and, if provided in the diagram text by the diagram author, the [accessible title and description.](#accessible-title-and-description)
-## Defining Accessibility Options
+### aria-roledescription
-### Single line accessibility values
+The [aria-roledescription](https://www.w3.org/TR/wai-aria-1.1/#aria-roledescription) for the SVG HTML element is set to the diagram type key. (Note this may be slightly different than the keyword used for the diagram in the diagram text.)
-The diagram authors can now add the accessibility options in the diagram definition, using the `accTitle` and `accDescr` keywords, where each keyword is followed by `:` and the string value for title and description like:
+For example: The diagram type key for a state diagram is "stateDiagram". Here (a part of) the HTML of the SVG tag that shows the automatically inserted aria-roledscription set to "stateDiagram". _(Note that some of the SVG attributes and the SVG contents are omitted for clarity.):_
+```html
+