Skip to content

Commit

Permalink
Fixes for rendering tests
Browse files Browse the repository at this point in the history
  • Loading branch information
knsv committed Jul 20, 2022
1 parent 27cf500 commit 8681e78
Show file tree
Hide file tree
Showing 10 changed files with 81 additions and 54 deletions.
5 changes: 5 additions & 0 deletions cypress/fixtures/example.json
@@ -0,0 +1,5 @@
{
"name": "Using fixtures to represent data",
"email": "hello@cypress.io",
"body": "Fixtures are a great way to mock data for responses to routes"
}
3 changes: 2 additions & 1 deletion cypress/helpers/util.js
Expand Up @@ -42,7 +42,8 @@ export const imgSnapshotTest = (graphStr, _options, api = false, validation) =>
if (!options.fontSize) {
options.fontSize = '16px';
}
const useAppli = Cypress.env('useAppli');
// const useAppli = Cypress.env('useAppli');
const useAppli = false;
const branch = Cypress.env('codeBranch');
cy.log('Hello ' + useAppli ? 'Appli' : 'image-snapshot');
const name = (options.name || cy.state('runnable').fullTitle()).replace(/\s+/g, '-');
Expand Down
2 changes: 1 addition & 1 deletion cypress/integration/rendering/sequencediagram.spec.js
Expand Up @@ -80,7 +80,7 @@ context('Sequence diagram', () => {
loop Loopy
Bob->>Alice: Pasten
end `,
{}
{ wrap: true }
);
});
context('font settings', () => {
Expand Down
51 changes: 37 additions & 14 deletions cypress/platform/knsv.html
Expand Up @@ -64,7 +64,7 @@
commit
commit
</div>
<div class="mermaid" style="width: 50%;">
<div class="mermaid2" style="width: 50%;">
sequenceDiagram
title: My Sequence Diagram Title
accTitle: My Acc Sequence Diagram
Expand Down Expand Up @@ -218,20 +218,41 @@
}
</div>
<div class="mermaid" style="width: 100%;">
graph LR
A[[subroutine shape test]]
A -->|Get money| B[[Go shopping]]
B --> C[[Let me think...<br />Do I want something for work,<br />something to spend every free second with,<br />or something to get around?]]
C -->|One| D[[Laptop]]
C -->|Two| E[[iPhone]]
C -->|Three| F[[Car<br/>wroom wroom]]
click A "index.html#link-clicked" "link test"
click B testClick "click test"
classDef someclass fill:#f96;
class A someclass;
class C someclass;
%%{init: {'config': {'wrap': true }}}%%
sequenceDiagram
participant A as Extremely utterly long line of longness which had previously overflown the actor box as it is much longer than what it should be
A->>Bob: Hola
Bob-->A: Pasten !
</div>
<div class="mermaid2" style="width: 100%;">
gitGraph
commit id: "ZERO"
branch develop
commit id:"A"
checkout main
commit id:"ONE"
checkout develop
commit id:"B"
branch featureA
commit id:"FIX"
commit id: "FIX-2"
checkout main
commit id:"TWO"
cherry-pick id:"A"
commit id:"THREE"
cherry-pick id:"FIX"
checkout develop
commit id:"C"
merge featureA
</div>
<div class="mermaid2" style="width: 100%;">
flowchart TD
A[Christmas] -->|Get money| B(Go shopping)
B --> C{Let me think}
C -->|One| D[Laptop]
C -->|Two| E[iPhone]
C -->|Three| F[fa:fa-car Car]
</div> <div class="mermaid2" style="width: 100%;">
classDiagram
Animal "1" <|-- Duck
Animal <|-- Fish
Expand Down Expand Up @@ -292,7 +313,8 @@
htmlLabels: true,
},
sequence: {
mirrorActors: false,
// mirrorActors: false,'
wrap: false,
},
// gantt: { axisFormat: '%m/%d/%Y' },
// sequence: {
Expand All @@ -315,6 +337,7 @@
curve: 'cardinal',
// securityLevel: 'sandbox',
// themeVariables: {relationLabelColor: 'red'}
wrap: true,
});
function callback() {
alert('It worked');
Expand Down
41 changes: 17 additions & 24 deletions docs/Setup.md
Expand Up @@ -1429,15 +1429,6 @@ function _Default value: At default, will mirror Global Config_

Returns **[object][5]** The siteConfig

## parse

### Parameters

- `text`
- `dia`

Returns **any**

## getSiteConfig

## getSiteConfig
Expand Down Expand Up @@ -1480,21 +1471,6 @@ Returns **any** The currentConfig merged with the sanitized conf

Returns **any** The currentConfig

## sanitize

## sanitize

| Function | Description | Type | Values |
| -------- | -------------------------------------- | ----------- | ------ |
| sanitize | Sets the siteConfig to desired values. | Put Request | None |

Ensures options parameter does not attempt to override siteConfig secure keys **Notes**: modifies
options in-place

### Parameters

- `options` **any** The potential setConfig parameter

## render

Function that renders an svg with a graph from a chart definition. Usage example below.
Expand Down Expand Up @@ -1523,6 +1499,21 @@ $(function () {

Returns **any**

## sanitize

## sanitize

| Function | Description | Type | Values |
| -------- | -------------------------------------- | ----------- | ------ |
| sanitize | Sets the siteConfig to desired values. | Put Request | None |

Ensures options parameter does not attempt to override siteConfig secure keys **Notes**: modifies
options in-place

### Parameters

- `options` **any** The potential setConfig parameter

## addDirective

Pushes in a directive to the configuration
Expand All @@ -1533,6 +1524,8 @@ Pushes in a directive to the configuration

## reset

## reset

| Function | Description | Type | Required | Values |
| -------- | ---------------------------- | ----------- | -------- | ------ |
| reset | Resets currentConfig to conf | Put Request | Required | None |
Expand Down
21 changes: 11 additions & 10 deletions src/diagram-api/diagram-orchestration.js
Expand Up @@ -19,13 +19,14 @@ import gitGraphDetector from '../diagrams/git/gitGraphDetector';
// mindmapRenderer,
// mindmapDetector
// );
registerDiagram(
'gitGraph',
gitGraphParser,
gitGraphDb,
gitGraphRenderer,
undefined,
gitGraphDetector
);
const apa = { apa: 1 };
export default apa;
const addDiagrams = () => {
registerDiagram(
'gitGraph',
gitGraphParser,
gitGraphDb,
gitGraphRenderer,
undefined,
gitGraphDetector
);
};
export default addDiagrams;
2 changes: 1 addition & 1 deletion src/diagram-api/diagramAPI.js
Expand Up @@ -79,7 +79,7 @@ const diagrams = {
flowDb.setGen('gen-1');
},
},
flowchartV2: {
'flowchart-v2': {
db: flowDb,
renderer: flowRendererV2,
parser: flowParser,
Expand Down
2 changes: 1 addition & 1 deletion src/diagrams/sequence/sequenceDb.js
Expand Up @@ -19,7 +19,7 @@ const notes = [];
let diagramTitle = '';
let description = '';
let sequenceNumbersEnabled = false;
let wrapEnabled = false;
let wrapEnabled;

export const parseDirective = function (statement, context, type) {
mermaidAPI.parseDirective(this, statement, context, type);
Expand Down
5 changes: 4 additions & 1 deletion src/diagrams/sequence/svgDraw.js
Expand Up @@ -847,9 +847,12 @@ const _drawTextCandidateFunc = (function () {
function byTspan(content, g, x, y, width, height, textAttrs, conf) {
const { actorFontSize, actorFontFamily, actorFontWeight } = conf;

let _actorFontSize =
actorFontSize && actorFontSize.replace ? actorFontSize.replace('px', '') : actorFontSize;

const lines = content.split(common.lineBreakRegex);
for (let i = 0; i < lines.length; i++) {
const dy = i * actorFontSize - (actorFontSize * (lines.length - 1)) / 2;
const dy = i * _actorFontSize - (_actorFontSize * (lines.length - 1)) / 2;
const text = g
.append('text')
.attr('x', x + width / 2)
Expand Down
3 changes: 2 additions & 1 deletion src/mermaidAPI.js
Expand Up @@ -19,7 +19,7 @@ import { select } from 'd3';
import { compile, serialize, stringify } from 'stylis';
import pkg from '../package.json';
import * as configApi from './config';
import apa from './diagram-api/diagram-orchestration';
import addDiagrams from './diagram-api/diagram-orchestration';
import classDb from './diagrams/class/classDb';
import flowDb from './diagrams/flowchart/flowDb';
import flowRenderer from './diagrams/flowchart/flowRenderer';
Expand Down Expand Up @@ -515,6 +515,7 @@ function initialize(options) {

updateRendererConfigs(config);
setLogLevel(config.logLevel);
addDiagrams();
}

const mermaidAPI = Object.freeze({
Expand Down

0 comments on commit 8681e78

Please sign in to comment.