Skip to content

Commit

Permalink
#2732 Regression fixes for accessibility
Browse files Browse the repository at this point in the history
  • Loading branch information
knsv committed May 6, 2022
1 parent da548f1 commit 65143a0
Show file tree
Hide file tree
Showing 12 changed files with 82 additions and 30 deletions.
4 changes: 2 additions & 2 deletions cypress/integration/rendering/gantt.spec.js
Expand Up @@ -298,8 +298,8 @@ describe('Gantt diagram', () => {
renderGraph(
`
gantt
title ${expectedTitle}
accDescription ${expectedAccDescription}
accTitle: ${expectedTitle}
accDescr: ${expectedAccDescription}
dateFormat YYYY-MM-DD
section Section
A task :a1, 2014-01-01, 30d
Expand Down
4 changes: 2 additions & 2 deletions cypress/integration/rendering/requirement.spec.js
Expand Up @@ -53,8 +53,8 @@ describe('Requirement diagram', () => {
renderGraph(
`
requirementDiagram
title ${expectedTitle}
accDescription ${expectedAccDescription}
accTitle: ${expectedTitle}
accDescr: ${expectedAccDescription}
requirement test_req {
id: 1
Expand Down
4 changes: 2 additions & 2 deletions cypress/integration/rendering/sequencediagram.spec.js
Expand Up @@ -658,7 +658,7 @@ context('Sequence diagram', () => {
expect(svg).to.have.attr('width', '100%');
expect(svg).to.have.attr('height');
const height = parseFloat(svg.attr('height'));
expect(height).to.be.within(920, 960);
expect(height).to.be.within(920, 971);
const style = svg.attr('style');
expect(style).to.match(/^max-width: [\d.]+px;$/);
const maxWidthValue = parseFloat(style.match(/[\d.]+/g).join(''));
Expand Down Expand Up @@ -697,7 +697,7 @@ context('Sequence diagram', () => {
cy.get('svg').should((svg) => {
const height = parseFloat(svg.attr('height'));
const width = parseFloat(svg.attr('width'));
expect(height).to.be.within(920, 960);
expect(height).to.be.within(920, 971);
// use within because the absolute value can be slightly different depending on the environment ±5%
expect(width).to.be.within(820 * 0.95, 820 * 1.05);
expect(svg).to.not.have.attr('style');
Expand Down
28 changes: 28 additions & 0 deletions cypress/integration/rendering/theme.spec.js
Expand Up @@ -36,6 +36,8 @@ describe('Pie Chart', () => {
imgSnapshotTest(
`
pie title Sports in Sweden
accTitle: This is a title
accDescr: This is a description
"Bandy" : 40
"Ice-Hockey" : 80
"Football" : 90
Expand All @@ -49,6 +51,8 @@ describe('Pie Chart', () => {
`
%%{init: { 'logLevel': 0} }%%
graph TD
accTitle: This is a title
accDescr: This is a description
A[Christmas] -->|Get money| B(Go shopping)
B --> C{Let me think}
B --> G[/Another/]
Expand All @@ -72,6 +76,9 @@ describe('Pie Chart', () => {
`
%%{init: { 'logLevel': 0, 'theme': '${theme}'} }%%
flowchart TD
accTitle: This is a title
accDescr: This is a description
A[Christmas] -->|Get money| B(Go shopping)
B --> C{Let me think}
B --> G[Another]
Expand All @@ -95,6 +102,9 @@ describe('Pie Chart', () => {
`
%%{init: { 'logLevel': 0, 'theme': '${theme}'} }%%
sequenceDiagram
accTitle: This is a title
accDescr: This is a description
autonumber
par Action 1
Alice->>John: Hello John, how are you?
Expand Down Expand Up @@ -122,6 +132,9 @@ describe('Pie Chart', () => {
`
%%{init: { 'logLevel': 0, 'theme': '${theme}'} }%%
classDiagram
accTitle: This is a title
accDescr: This is a description
Animal "*" <|-- "1" Duck
Animal "1" <|-- "10" Fish
Animal <|-- Zebra
Expand Down Expand Up @@ -168,6 +181,9 @@ describe('Pie Chart', () => {
`
%%{init: { 'logLevel': 0, 'theme': '${theme}'} }%%
stateDiagram
accTitle: This is a title
accDescr: This is a description
[*] --> Active
state Active {
Expand Down Expand Up @@ -200,6 +216,9 @@ stateDiagram
`
%%{init: { 'logLevel': 0, 'theme': '${theme}'} }%%
stateDiagram-v2
accTitle: This is a title
accDescr: This is a description
[*] --> Active
state Active {
Expand Down Expand Up @@ -231,6 +250,9 @@ stateDiagram-v2
imgSnapshotTest(
`
erDiagram
accTitle: This is a title
accDescr: This is a description
CUSTOMER }|..|{ DELIVERY-ADDRESS : has
CUSTOMER ||--o{ ORDER : places
CUSTOMER ||--o{ INVOICE : "liable for"
Expand All @@ -250,6 +272,9 @@ erDiagram
`
%%{init: { 'logLevel': 0, 'theme': '${theme}'} }%%
journey
accTitle: This is a title
accDescr: This is a description
title My working day
section Go to work
Make tea: 5: Me
Expand All @@ -268,6 +293,9 @@ erDiagram
imgSnapshotTest(
`
gantt
accTitle: This is a title
accDescr: This is a description
dateFormat :YYYY-MM-DD
title :Adding GANTT diagram functionality to mermaid
excludes :excludes the named dates/days from being included in a charted task..
Expand Down
4 changes: 2 additions & 2 deletions cypress/platform/gitgraph.html
Expand Up @@ -34,8 +34,8 @@ <h1>info below</h1>
"git0": "#550055"
} } }%%
gitGraph
accTitle: "Git Graph"
accDescr {
accTitle: "Git Graph"
accDescr {
Git Graph description.
Multiline description
}
Expand Down
33 changes: 17 additions & 16 deletions cypress/platform/knsv.html
Expand Up @@ -31,23 +31,24 @@


<div class="mermaid" style="width: 50%;">
graph LR
subgraph id1 [title is set]
A-->B
end
subgraph id2 [title]
E
end
sequenceDiagram
accTitle: This is a title
accDescr: This is a description

B-->C

subgraph id3
C-->D
end
class id3,id2,A redBg;
class id3,A whiteTxt;
classDef redBg fill:#622;
classDef whiteTxt color: white;
autonumber
par Action 1
Alice->>John: Hello John, how are you?
and Action 2
Alice->>Bob: Hello Bob, how are you?
end
Alice->>+John: Hello John, how are you?
Alice->>+John: John, can you hear me?
John-->>-Alice: Hi Alice, I can hear you!
Note right of John: John is perceptive
John-->>-Alice: I feel great!
loop Every minute
John-->Alice: Great!
end
</div>
<div class="mermaid2" style="width: 100%;">
journey
Expand Down
2 changes: 1 addition & 1 deletion src/diagrams/pie/parser/pie.jison
Expand Up @@ -69,7 +69,7 @@ line
statement
:
| txt value { yy.addSection($1,yy.cleanupValue($2)); }
| title title_value { $$=$2.trim();yy.setTitle($$); }
| title title_value { $$=$2.trim();yy.setPieTitle($$); }
| acc_title acc_title_value { $$=$2.trim();yy.setTitle($$); }
| acc_descr acc_descr_value { $$=$2.trim();yy.setAccDescription($$); }
| acc_descr_multiline_value { $$=$1.trim();yy.setAccDescription($$); } | section {yy.addSection($1.substr(8));$$=$1.substr(8);}
Expand Down
11 changes: 11 additions & 0 deletions src/diagrams/pie/pieDb.js
Expand Up @@ -52,6 +52,15 @@ const clear = function () {
commonClear();
};

export const setPieTitle = function (txt) {
let sanitizedText = common.sanitizeText(txt, configApi.getConfig());
title = sanitizedText;
};

export const getPieTitle = function () {
return title;
};

export default {
parseDirective,
getConfig: () => configApi.getConfig().pie,
Expand All @@ -61,6 +70,8 @@ export default {
clear,
setTitle,
getTitle,
setPieTitle,
getPieTitle,
setShowData,
getShowData,
getAccDescription,
Expand Down
2 changes: 1 addition & 1 deletion src/diagrams/pie/pieRenderer.js
Expand Up @@ -136,7 +136,7 @@ export const draw = (txt, id) => {

svg
.append('text')
.text(parser.yy.getTitle())
.text(parser.yy.getPieTitle())
.attr('x', 0)
.attr('y', -(height - 50) / 2)
.attr('class', 'pieTitleText');
Expand Down
4 changes: 2 additions & 2 deletions src/diagrams/sequence/parser/sequenceDiagram.jison
Expand Up @@ -136,8 +136,8 @@ statement
| link_statement 'NEWLINE'
| properties_statement 'NEWLINE'
| details_statement 'NEWLINE'
| title {yy.setTitle($1.substring(6));$$=$1.substring(6);}
| legacy_title {yy.setTitle($1.substring(7));$$=$1.substring(7);}
| title {yy.setDiagramTitle($1.substring(6));$$=$1.substring(6);}
| legacy_title {yy.setDiagramTitle($1.substring(7));$$=$1.substring(7);}
| acc_title acc_title_value { $$=$2.trim();yy.setTitle($$); }
| acc_descr acc_descr_value { $$=$2.trim();yy.setAccDescription($$); }
| acc_descr_multiline_value { $$=$1.trim();yy.setAccDescription($$); }
Expand Down
14 changes: 13 additions & 1 deletion src/diagrams/sequence/sequenceDb.js
Expand Up @@ -14,7 +14,7 @@ let prevActor = undefined;
let actors = {};
let messages = [];
const notes = [];
let title = '';
let diagramTitle = '';
let description = '';
let sequenceNumbersEnabled = false;
let wrapEnabled = false;
Expand Down Expand Up @@ -144,6 +144,7 @@ export const clear = function () {
actors = {};
messages = [];
sequenceNumbersEnabled = false;
diagramTitle = '';
commonClear();
};

Expand Down Expand Up @@ -330,6 +331,15 @@ export const getActorProperty = function (actor, key) {
return undefined;
};

export const setDiagramTitle = function (txt) {
let sanitizedText = sanitizeText(txt, configApi.getConfig());
diagramTitle = sanitizedText;
};

export const getDiagramTitle = function () {
return diagramTitle;
};

export const apply = function (param) {
if (param instanceof Array) {
param.forEach(function (item) {
Expand Down Expand Up @@ -441,6 +451,7 @@ export default {
getActorKeys,
getActorProperty,
getTitle,
getDiagramTitle,
parseDirective,
getConfig: () => configApi.getConfig().sequence,
clear,
Expand All @@ -450,6 +461,7 @@ export default {
PLACEMENT,
addNote,
setTitle,
setDiagramTitle,
apply,
setAccDescription,
getAccDescription,
Expand Down
2 changes: 1 addition & 1 deletion src/diagrams/sequence/sequenceRenderer.js
Expand Up @@ -612,7 +612,7 @@ export const draw = function (text, id) {
const actors = parser.yy.getActors();
const actorKeys = parser.yy.getActorKeys();
const messages = parser.yy.getMessages();
const title = parser.yy.getTitle();
const title = parser.yy.getDiagramTitle();

const maxMessageWidthPerActor = getMaxMessageWidthPerActor(actors, messages);
conf.height = calculateActorMargins(actors, maxMessageWidthPerActor);
Expand Down

0 comments on commit 65143a0

Please sign in to comment.