mirror of
https://github.com/mermaid-js/mermaid.git
synced 2025-10-12 02:29:37 +02:00
Merge pull request #2269 from Xstoudi/feature/field-classifier
Feature: field static classifier
This commit is contained in:
@@ -370,7 +370,21 @@ describe('Class diagram V2', () => {
|
|||||||
);
|
);
|
||||||
cy.get('svg');
|
cy.get('svg');
|
||||||
});
|
});
|
||||||
it('16: should handle the direction statemment with TB', () => {
|
|
||||||
|
it('16a: should render a simple class diagram with static field', () => {
|
||||||
|
imgSnapshotTest(
|
||||||
|
`
|
||||||
|
classDiagram-v2
|
||||||
|
Foo {
|
||||||
|
+String bar$
|
||||||
|
}
|
||||||
|
`,
|
||||||
|
{logLevel : 1, flowchart: { "htmlLabels": false },}
|
||||||
|
);
|
||||||
|
cy.get('svg');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('16b: should handle the direction statemnent with TB', () => {
|
||||||
imgSnapshotTest(
|
imgSnapshotTest(
|
||||||
`
|
`
|
||||||
classDiagram
|
classDiagram
|
||||||
@@ -394,55 +408,8 @@ describe('Class diagram V2', () => {
|
|||||||
);
|
);
|
||||||
cy.get('svg');
|
cy.get('svg');
|
||||||
});
|
});
|
||||||
it('17: should handle the direction statemment with BT', () => {
|
|
||||||
imgSnapshotTest(
|
|
||||||
`
|
|
||||||
classDiagram
|
|
||||||
direction BT
|
|
||||||
class Student {
|
|
||||||
-idCard : IdCard
|
|
||||||
}
|
|
||||||
class IdCard{
|
|
||||||
-id : int
|
|
||||||
-name : string
|
|
||||||
}
|
|
||||||
class Bike{
|
|
||||||
-id : int
|
|
||||||
-name : string
|
|
||||||
}
|
|
||||||
Student "1" --o "1" IdCard : carries
|
|
||||||
Student "1" --o "1" Bike : rides
|
|
||||||
|
|
||||||
`,
|
it('18: should handle the direction statemnent with LR', () => {
|
||||||
{logLevel : 1, flowchart: { "htmlLabels": false },}
|
|
||||||
);
|
|
||||||
cy.get('svg');
|
|
||||||
});
|
|
||||||
it('17: should handle the direction statemment with RL', () => {
|
|
||||||
imgSnapshotTest(
|
|
||||||
`
|
|
||||||
classDiagram
|
|
||||||
direction RL
|
|
||||||
class Student {
|
|
||||||
-idCard : IdCard
|
|
||||||
}
|
|
||||||
class IdCard{
|
|
||||||
-id : int
|
|
||||||
-name : string
|
|
||||||
}
|
|
||||||
class Bike{
|
|
||||||
-id : int
|
|
||||||
-name : string
|
|
||||||
}
|
|
||||||
Student "1" --o "1" IdCard : carries
|
|
||||||
Student "1" --o "1" Bike : rides
|
|
||||||
|
|
||||||
`,
|
|
||||||
{logLevel : 1, flowchart: { "htmlLabels": false },}
|
|
||||||
);
|
|
||||||
cy.get('svg');
|
|
||||||
});
|
|
||||||
it('18: should handle the direction statemment with LR', () => {
|
|
||||||
imgSnapshotTest(
|
imgSnapshotTest(
|
||||||
`
|
`
|
||||||
classDiagram
|
classDiagram
|
||||||
@@ -466,4 +433,52 @@ describe('Class diagram V2', () => {
|
|||||||
);
|
);
|
||||||
cy.get('svg');
|
cy.get('svg');
|
||||||
});
|
});
|
||||||
|
it('17a: should handle the direction statemnent with BT', () => {
|
||||||
|
imgSnapshotTest(
|
||||||
|
`
|
||||||
|
classDiagram
|
||||||
|
direction BT
|
||||||
|
class Student {
|
||||||
|
-idCard : IdCard
|
||||||
|
}
|
||||||
|
class IdCard{
|
||||||
|
-id : int
|
||||||
|
-name : string
|
||||||
|
}
|
||||||
|
class Bike{
|
||||||
|
-id : int
|
||||||
|
-name : string
|
||||||
|
}
|
||||||
|
Student "1" --o "1" IdCard : carries
|
||||||
|
Student "1" --o "1" Bike : rides
|
||||||
|
|
||||||
|
`,
|
||||||
|
{logLevel : 1, flowchart: { "htmlLabels": false },}
|
||||||
|
);
|
||||||
|
cy.get('svg');
|
||||||
|
});
|
||||||
|
it('17b: should handle the direction statemment with RL', () => {
|
||||||
|
imgSnapshotTest(
|
||||||
|
`
|
||||||
|
classDiagram
|
||||||
|
direction RL
|
||||||
|
class Student {
|
||||||
|
-idCard : IdCard
|
||||||
|
}
|
||||||
|
class IdCard{
|
||||||
|
-id : int
|
||||||
|
-name : string
|
||||||
|
}
|
||||||
|
class Bike{
|
||||||
|
-id : int
|
||||||
|
-name : string
|
||||||
|
}
|
||||||
|
Student "1" --o "1" IdCard : carries
|
||||||
|
Student "1" --o "1" Bike : rides
|
||||||
|
|
||||||
|
`,
|
||||||
|
{logLevel : 1, flowchart: { "htmlLabels": false },}
|
||||||
|
);
|
||||||
|
cy.get('svg');
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
@@ -228,10 +228,14 @@ To specify the visibility of a class member (i.e. any attribute or method), thes
|
|||||||
- `~` Package/Internal
|
- `~` Package/Internal
|
||||||
|
|
||||||
> _note_ you can also include additional _classifiers_ to a method definition by adding the following notations to the end of the method, i.e.: after the `()`:
|
> _note_ you can also include additional _classifiers_ to a method definition by adding the following notations to the end of the method, i.e.: after the `()`:
|
||||||
|
|
||||||
> - `*` Abstract e.g.: `someAbstractMethod()*`
|
> - `*` Abstract e.g.: `someAbstractMethod()*`
|
||||||
> - `$` Static e.g.: `someStaticMethod()$`
|
> - `$` Static e.g.: `someStaticMethod()$`
|
||||||
|
|
||||||
|
> _note_ you can also include additional _classifiers_ to a field definition by adding the following notations to the end of the field name:
|
||||||
|
> - `*` Static e.g.: `String someField$`
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
## Defining Relationship
|
## Defining Relationship
|
||||||
|
|
||||||
A relationship is a general term covering the specific types of logical connections found on class and object diagrams.
|
A relationship is a general term covering the specific types of logical connections found on class and object diagrams.
|
||||||
|
@@ -672,13 +672,21 @@ const class_box = (parent, node) => {
|
|||||||
}
|
}
|
||||||
const classAttributes = [];
|
const classAttributes = [];
|
||||||
node.classData.members.forEach((str) => {
|
node.classData.members.forEach((str) => {
|
||||||
let parsedText = parseMember(str).displayText;
|
const parsedInfo = parseMember(str);
|
||||||
|
let parsedText = parsedInfo.displayText;
|
||||||
if (getConfig().flowchart.htmlLabels) {
|
if (getConfig().flowchart.htmlLabels) {
|
||||||
parsedText = parsedText.replace(/</g, '<').replace(/>/g, '>');
|
parsedText = parsedText.replace(/</g, '<').replace(/>/g, '>');
|
||||||
}
|
}
|
||||||
const lbl = labelContainer
|
const lbl = labelContainer
|
||||||
.node()
|
.node()
|
||||||
.appendChild(createLabel(parsedText, node.labelStyle, true, true));
|
.appendChild(
|
||||||
|
createLabel(
|
||||||
|
parsedText,
|
||||||
|
parsedInfo.cssStyle ? parsedInfo.cssStyle : node.labelStyle,
|
||||||
|
true,
|
||||||
|
true
|
||||||
|
)
|
||||||
|
);
|
||||||
let bbox = lbl.getBBox();
|
let bbox = lbl.getBBox();
|
||||||
if (evaluate(getConfig().flowchart.htmlLabels)) {
|
if (evaluate(getConfig().flowchart.htmlLabels)) {
|
||||||
const div = lbl.children[0];
|
const div = lbl.children[0];
|
||||||
|
@@ -274,7 +274,7 @@ export const drawClass = function (elem, classDef, conf) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export const parseMember = function (text) {
|
export const parseMember = function (text) {
|
||||||
const fieldRegEx = /(\+|-|~|#)?(\w+)(~\w+~|\[\])?\s+(\w+)/;
|
const fieldRegEx = /^(\+|-|~|#)?(\w+)(~\w+~|\[\])?\s+(\w+) *(\*|\$)?$/;
|
||||||
const methodRegEx = /^([+|\-|~|#])?(\w+) *\( *(.*)\) *(\*|\$)? *(\w*[~|[\]]*\s*\w*~?)$/;
|
const methodRegEx = /^([+|\-|~|#])?(\w+) *\( *(.*)\) *(\*|\$)? *(\w*[~|[\]]*\s*\w*~?)$/;
|
||||||
|
|
||||||
let fieldMatch = text.match(fieldRegEx);
|
let fieldMatch = text.match(fieldRegEx);
|
||||||
@@ -290,6 +290,7 @@ export const parseMember = function (text) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const buildFieldDisplay = function (parsedText) {
|
const buildFieldDisplay = function (parsedText) {
|
||||||
|
let cssStyle = '';
|
||||||
let displayText = '';
|
let displayText = '';
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@@ -297,15 +298,17 @@ const buildFieldDisplay = function (parsedText) {
|
|||||||
let fieldType = parsedText[2] ? parsedText[2].trim() : '';
|
let fieldType = parsedText[2] ? parsedText[2].trim() : '';
|
||||||
let genericType = parsedText[3] ? parseGenericTypes(parsedText[3].trim()) : '';
|
let genericType = parsedText[3] ? parseGenericTypes(parsedText[3].trim()) : '';
|
||||||
let fieldName = parsedText[4] ? parsedText[4].trim() : '';
|
let fieldName = parsedText[4] ? parsedText[4].trim() : '';
|
||||||
|
let classifier = parsedText[5] ? parsedText[5].trim() : '';
|
||||||
|
|
||||||
displayText = visibility + fieldType + genericType + ' ' + fieldName;
|
displayText = visibility + fieldType + genericType + ' ' + fieldName;
|
||||||
|
cssStyle = parseClassifier(classifier);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
displayText = parsedText;
|
displayText = parsedText;
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
displayText: displayText,
|
displayText: displayText,
|
||||||
cssStyle: '',
|
cssStyle: cssStyle,
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -321,7 +324,6 @@ const buildMethodDisplay = function (parsedText) {
|
|||||||
let returnType = parsedText[5] ? ' : ' + parseGenericTypes(parsedText[5]).trim() : '';
|
let returnType = parsedText[5] ? ' : ' + parseGenericTypes(parsedText[5]).trim() : '';
|
||||||
|
|
||||||
displayText = visibility + methodName + '(' + parameters + ')' + returnType;
|
displayText = visibility + methodName + '(' + parameters + ')' + returnType;
|
||||||
|
|
||||||
cssStyle = parseClassifier(classifier);
|
cssStyle = parseClassifier(classifier);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
displayText = parsedText;
|
displayText = parsedText;
|
||||||
|
@@ -51,7 +51,7 @@ describe('class member Renderer, ', function () {
|
|||||||
expect(actual.cssStyle).toBe('');
|
expect(actual.cssStyle).toBe('');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should handle abstract classifier', function () {
|
it('should handle abstract method classifier', function () {
|
||||||
const str = 'foo()*';
|
const str = 'foo()*';
|
||||||
let actual = svgDraw.parseMember(str);
|
let actual = svgDraw.parseMember(str);
|
||||||
|
|
||||||
@@ -59,7 +59,7 @@ describe('class member Renderer, ', function () {
|
|||||||
expect(actual.cssStyle).toBe('font-style:italic;');
|
expect(actual.cssStyle).toBe('font-style:italic;');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should handle static classifier', function () {
|
it('should handle static method classifier', function () {
|
||||||
const str = 'foo()$';
|
const str = 'foo()$';
|
||||||
let actual = svgDraw.parseMember(str);
|
let actual = svgDraw.parseMember(str);
|
||||||
|
|
||||||
@@ -156,5 +156,13 @@ describe('class member Renderer, ', function () {
|
|||||||
expect(actual.displayText).toBe('List<int> ids');
|
expect(actual.displayText).toBe('List<int> ids');
|
||||||
expect(actual.cssStyle).toBe('');
|
expect(actual.cssStyle).toBe('');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should handle static field classifier', function () {
|
||||||
|
const str = 'String foo$';
|
||||||
|
let actual = svgDraw.parseMember(str);
|
||||||
|
|
||||||
|
expect(actual.displayText).toBe('String foo');
|
||||||
|
expect(actual.cssStyle).toBe('text-decoration:underline;');
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
Reference in New Issue
Block a user