Compare commits

..

8 Commits

17 changed files with 162 additions and 608 deletions

View File

@@ -1,5 +0,0 @@
---
'mermaid': minor
---
feat: Add support for aggregation relationships in ER diagram

View File

@@ -38,6 +38,8 @@ jobs:
options: --user 1001
steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
with:
fetch-depth: 0
- uses: pnpm/action-setup@a7487c7e89a18df4991f7f222e4898a00d66ddda # v4.1.0
- name: Setup Node.js
uses: actions/setup-node@1d0ff469b7ec7b3cb9d8673fde0c81c44821de2a # v4.2.0
@@ -55,6 +57,7 @@ jobs:
if: ${{ steps.cache-snapshot.outputs.cache-hit != 'true' }}
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
with:
fetch-depth: 0
ref: ${{ env.targetHash }}
- name: Install dependencies
@@ -83,6 +86,8 @@ jobs:
containers: [1, 2, 3, 4, 5]
steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
with:
fetch-depth: 0
- uses: pnpm/action-setup@a7487c7e89a18df4991f7f222e4898a00d66ddda # v4.1.0
# uses version from "packageManager" field in package.json
@@ -137,13 +142,118 @@ jobs:
SPLIT_INDEX: ${{ strategy.job-index }}
SPLIT_FILE: 'cypress/timings.json'
VITEST_COVERAGE: true
- name: Debug coverage generation
if: ${{ steps.cypress.conclusion == 'success' }}
run: |
echo "Checking if coverage files were generated:"
ls -la coverage/ || echo "No coverage directory"
ls -la coverage/cypress/ || echo "No coverage/cypress directory"
echo "Looking for any .info files:"
find . -name "*.info" -type f | head -10 || echo "No .info files found"
- name: Prepare coverage artifacts
if: ${{ steps.cypress.conclusion == 'success' }}
run: |
mkdir -p coverage/cypress
if [ -f coverage/cypress/coverage-final.json ]; then
cp coverage/cypress/coverage-final.json coverage/cypress/coverage-final-${{ matrix.containers }}.json
echo "Created coverage-final-${{ matrix.containers }}.json"
ls -la coverage/cypress/coverage-final-${{ matrix.containers }}.json
else
echo "Error: coverage/cypress/coverage-final.json not found"
exit 1
fi
- name: Upload e2e coverage artifact
if: ${{ steps.cypress.conclusion == 'success' }}
uses: actions/upload-artifact@v4
with:
name: e2e-coverage-${{ matrix.containers }}
path: coverage/cypress/coverage-final-${{ matrix.containers }}.json
coverage-merge:
runs-on: ubuntu-latest
needs: e2e
steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
with:
fetch-depth: 0
- uses: pnpm/action-setup@a7487c7e89a18df4991f7f222e4898a00d66ddda # v4.1.0
- name: Setup Node.js
uses: actions/setup-node@1d0ff469b7ec7b3cb9d8673fde0c81c44821de2a # v4.2.0
with:
node-version-file: '.node-version'
- name: Download e2e coverage shards
uses: actions/download-artifact@v4
with:
pattern: e2e-coverage-*
path: coverage/e2e-shards
merge-multiple: true
- name: Debug downloaded artifacts
run: |
echo "Contents of coverage/e2e-shards:"
find coverage/e2e-shards -type f -name "*.info" | head -20
echo "All files in coverage/e2e-shards:"
ls -la coverage/e2e-shards/
echo "Directory structure:"
find coverage/e2e-shards -type f | head -20
echo "Looking for coverage-final.json files:"
find coverage/e2e-shards -name "coverage-final.json" | head -20
- name: Install dependencies for merging
run: pnpm install --frozen-lockfile
env:
CYPRESS_CACHE_FOLDER: .cache/Cypress
- name: Prepare coverage files for merge script
run: |
mkdir -p coverage/vitest coverage/cypress
# Copy E2E coverage-final.json files to the structure expected by scripts/coverage.ts
for i in {1..5}; do
if [ -f "coverage/e2e-shards/coverage-final-$i.json" ]; then
cp "coverage/e2e-shards/coverage-final-$i.json" "coverage/cypress/coverage-final.json"
echo "Copied coverage-final-$i.json to cypress/"
break
fi
done
# Create a minimal but valid vitest coverage-final.json
echo '{"type":"Coverage","version":"1.1","data":{}}' > coverage/vitest/coverage-final.json
echo "Prepared coverage files:"
ls -la coverage/vitest/
ls -la coverage/cypress/
echo "Checking file contents:"
echo "Vitest coverage file:"
cat coverage/vitest/coverage-final.json
echo "Cypress coverage file:"
cat coverage/cypress/coverage-final.json
echo "Validating JSON files:"
if jq . coverage/vitest/coverage-final.json > /dev/null; then
echo "✓ Vitest coverage file is valid JSON"
else
echo "✗ Vitest coverage file is invalid JSON"
exit 1
fi
if jq . coverage/cypress/coverage-final.json > /dev/null; then
echo "✓ Cypress coverage file is valid JSON"
else
echo "✗ Cypress coverage file is invalid JSON"
exit 1
fi
- name: Generate LCOV from coverage data
run: |
mkdir -p coverage/combined
# Convert coverage-final.json to LCOV format using nyc
if [ -f coverage/cypress/coverage-final.json ]; then
echo "Converting Cypress coverage to LCOV..."
npx nyc report --reporter=lcov --report-dir=coverage/combined --cwd=. --temp-dir=coverage/cypress
echo "LCOV generation completed"
ls -la coverage/combined/
else
echo "No Cypress coverage file found"
exit 1
fi
- name: Upload Coverage to Codecov
uses: codecov/codecov-action@13ce06bfc6bbe3ecf90edbbf1bc32fe5978ca1d3 # v5.3.1
# Run step only pushes to develop and pull_requests
if: ${{ steps.cypress.conclusion == 'success' && (github.event_name == 'pull_request' || github.ref == 'refs/heads/develop')}}
if: ${{ github.event_name == 'pull_request' || github.ref == 'refs/heads/develop'}}
with:
files: coverage/cypress/lcov.info
files: coverage/combined/lcov.info
flags: e2e
name: mermaid-codecov
fail_ci_if_error: false

View File

@@ -10,6 +10,8 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
with:
fetch-depth: 0
- uses: pnpm/action-setup@a7487c7e89a18df4991f7f222e4898a00d66ddda # v4.1.0
# uses version from "packageManager" field in package.json
@@ -41,7 +43,6 @@ jobs:
- name: Verify out-of-tree build with TypeScript
run: |
pnpm test:check:tsc
- name: Upload Coverage to Codecov
uses: codecov/codecov-action@13ce06bfc6bbe3ecf90edbbf1bc32fe5978ca1d3 # v5.3.1
# Run step only pushes to develop and pull_requests

14
.nycrc Normal file
View File

@@ -0,0 +1,14 @@
{
"reporter": ["text", "lcov", "json", "html"],
"exclude": [
"node_modules/**/*",
"cypress/**/*",
"coverage/**/*",
"**/*.spec.js",
"**/*.spec.ts",
"**/*.test.js",
"**/*.test.ts"
],
"all": true,
"check-coverage": false
}

27
codecov.yml Normal file
View File

@@ -0,0 +1,27 @@
coverage:
status:
project:
default:
target: auto
threshold: 1%
patch:
default:
target: auto
threshold: 1%
comment:
layout: 'reach,diff,flags,tree'
behavior: default
require_changes: false
flags:
unit:
paths:
- packages/
e2e:
paths:
- packages/
# Wait for both unit and e2e coverage uploads before finalizing
notify:
after_n_builds: 2

View File

@@ -15,6 +15,13 @@ export default eyesPlugin(
setupNodeEvents(on, config) {
coverage(on, config);
cypressSplit(on, config);
// Ensure coverage generates LCOV format
on('task', {
coverage: () => {
return null;
},
});
on('before:browser:launch', (browser, launchOptions) => {
if (browser.name === 'chrome' && browser.isHeadless) {
launchOptions.args.push('--window-size=1440,1024', '--force-device-scale-factor=1');

View File

@@ -369,94 +369,4 @@ ORDER ||--|{ LINE-ITEM : contains
);
});
});
describe('Aggregation Relationships', () => {
it('should render basic aggregation relationships', () => {
imgSnapshotTest(
`
erDiagram
DEPARTMENT <> EMPLOYEE : contains
PROJECT <>.. TASK : manages
TEAM <> MEMBER : consists_of
`,
{ logLevel: 1 }
);
});
it('should render aggregation with entity attributes', () => {
imgSnapshotTest(
`
erDiagram
DEPARTMENT <> EMPLOYEE : contains
DEPARTMENT {
int id PK
string name
string location
}
EMPLOYEE {
int id PK
string name
int department_id FK
}
`,
{ logLevel: 1 }
);
});
it('should render aggregation with quoted labels', () => {
imgSnapshotTest(
`
erDiagram
UNIVERSITY <> COLLEGE : "has multiple"
COLLEGE <> DEPARTMENT : "contains"
DEPARTMENT <> FACULTY : "employs"
`,
{ logLevel: 1 }
);
});
it('should render mixed relationship types', () => {
imgSnapshotTest(
`
erDiagram
CUSTOMER ||--o{ ORDER : places
ORDER ||--|{ ORDER_ITEM : contains
PRODUCT <> ORDER_ITEM : "aggregated in"
WAREHOUSE <>.. PRODUCT : "stores"
`,
{ logLevel: 1 }
);
});
it('should render aggregation with entity aliases', () => {
imgSnapshotTest(
`
erDiagram
d[DEPARTMENT]
e[EMPLOYEE]
p[PROJECT]
t[TASK]
d <> e : contains
p <>.. t : manages
`,
{ logLevel: 1 }
);
});
it('should render complex aggregation scenarios', () => {
imgSnapshotTest(
`
erDiagram
COMPANY <> DEPARTMENT : owns
DEPARTMENT <> EMPLOYEE : contains
EMPLOYEE <> PROJECT : works_on
PROJECT <> TASK : consists_of
TASK <> SUBTASK : includes
`,
{ logLevel: 1 }
);
});
});
});

View File

@@ -169,164 +169,6 @@
</pre>
<hr />
<!-- Aggregation Examples -->
<h2>Aggregation Examples</h2>
<h3>Basic Aggregation (Solid Line)</h3>
<pre class="mermaid">
erDiagram
DEPARTMENT <> EMPLOYEE : contains
DEPARTMENT {
int id PK
string name
string location
}
EMPLOYEE {
int id PK
string name
int department_id FK
}
</pre>
<hr />
<h3>Dashed Aggregation</h3>
<pre class="mermaid">
erDiagram
PROJECT <>.. TASK : manages
PROJECT {
int id PK
string name
string description
}
TASK {
int id PK
string title
int project_id FK
}
</pre>
<hr />
<h3>Aggregation with Different Cardinalities</h3>
<pre class="mermaid">
erDiagram
COMPANY <> DEPARTMENT : owns
DEPARTMENT <> EMPLOYEE : contains
EMPLOYEE <> PROJECT : works_on
PROJECT <> TASK : consists_of
COMPANY {
int id PK
string name
}
DEPARTMENT {
int id PK
string name
int company_id FK
}
EMPLOYEE {
int id PK
string name
int department_id FK
}
PROJECT {
int id PK
string name
int employee_id FK
}
TASK {
int id PK
string title
int project_id FK
}
</pre>
<hr />
<h3>Two-way Aggregation</h3>
<pre class="mermaid">
erDiagram
TEAM <> MEMBER : consists_of
TEAM {
int id PK
string name
}
MEMBER {
int id PK
string name
int team_id FK
}
</pre>
<hr />
<h3>Complex Aggregation with Labels</h3>
<pre class="mermaid">
erDiagram
UNIVERSITY <> COLLEGE : "has multiple"
COLLEGE <> DEPARTMENT : "contains"
DEPARTMENT <> FACULTY : "employs"
FACULTY <> STUDENT : "teaches"
UNIVERSITY {
int id PK
string name
}
COLLEGE {
int id PK
string name
int university_id FK
}
DEPARTMENT {
int id PK
string name
int college_id FK
}
FACULTY {
int id PK
string name
int department_id FK
}
STUDENT {
int id PK
string name
int faculty_id FK
}
</pre>
<hr />
<h3>Mixed Relationship Types</h3>
<pre class="mermaid">
erDiagram
CUSTOMER ||--o{ ORDER : places
ORDER ||--|{ ORDER_ITEM : contains
PRODUCT <> ORDER_ITEM : "aggregated in"
WAREHOUSE <>.. PRODUCT : "stores"
CUSTOMER {
int id PK
string name
}
ORDER {
int id PK
int customer_id FK
date order_date
}
ORDER_ITEM {
int id PK
int order_id FK
int product_id FK
int quantity
}
PRODUCT {
int id PK
string name
int warehouse_id FK
}
WAREHOUSE {
int id PK
string name
}
</pre>
<hr />
<script type="module">
import mermaid from './mermaid.esm.mjs';
mermaid.initialize({

View File

@@ -209,42 +209,6 @@ erDiagram
PERSON many(0) optionally to 0+ NAMED-DRIVER : is
```
### Aggregation
Aggregation represents a "has-a" relationship where the part can exist independently of the whole. This is different from composition, where the part cannot exist without the whole. Aggregation relationships are rendered with hollow diamond markers at the endpoints.
| Value | Alias for | Description |
| :---: | :------------------: | ------------------------------ |
| <> | _aggregation_ | Basic aggregation (solid line) |
| <>.. | _aggregation-dashed_ | Dashed aggregation line |
**Examples:**
```mermaid-example
erDiagram
DEPARTMENT <> EMPLOYEE : contains
PROJECT <>.. TASK : manages
TEAM <> MEMBER : consists_of
```
```mermaid
erDiagram
DEPARTMENT <> EMPLOYEE : contains
PROJECT <>.. TASK : manages
TEAM <> MEMBER : consists_of
```
In these examples:
- `DEPARTMENT <> EMPLOYEE` shows that a department contains employees (aggregation)
- `PROJECT <>.. TASK` shows that a project manages tasks (dashed aggregation)
- `TEAM <> MEMBER` shows that a team consists of members (aggregation)
**Aggregation vs Association**
- **Aggregation** (`<>`): "Has-a" relationship where parts can exist independently
- **Association** (`||--`, `}o--`): General relationship between entities
### Attributes
Attributes can be defined for entities by specifying the entity name followed by a block containing multiple `type name` pairs, where a block is delimited by an opening `{` and a closing `}`. The attributes are rendered inside the entity boxes. For example:

View File

@@ -2,7 +2,6 @@ import { log } from '../../logger.js';
import { getConfig } from '../../diagram-api/diagramAPI.js';
import type { Edge, Node } from '../../rendering-util/types.js';
import type { EntityNode, Attribute, Relationship, EntityClass, RelSpec } from './erTypes.js';
import { AggregationType } from './erTypes.js';
import {
setAccTitle,
getAccTitle,
@@ -34,11 +33,6 @@ export class ErDB implements DiagramDB {
IDENTIFYING: 'IDENTIFYING',
};
private Aggregation = {
AGGREGATION: AggregationType.AGGREGATION,
AGGREGATION_DASHED: AggregationType.AGGREGATION_DASHED,
};
constructor() {
this.clear();
this.addEntity = this.addEntity.bind(this);
@@ -137,31 +131,6 @@ export class ErDB implements DiagramDB {
return this.relationships;
}
/**
* Validate aggregation relationship
* @param rSpec - The relationship specification to validate
* @returns boolean indicating if the aggregation relationship is valid
*/
public validateAggregationRelationship(rSpec: RelSpec): boolean {
const isAggregation =
rSpec.relType === this.Aggregation.AGGREGATION ||
rSpec.relType === this.Aggregation.AGGREGATION_DASHED;
if (!isAggregation) {
return false;
}
const validCardinalities = [
this.Cardinality.ZERO_OR_ONE,
this.Cardinality.ZERO_OR_MORE,
this.Cardinality.ONE_OR_MORE,
this.Cardinality.ONLY_ONE,
this.Cardinality.MD_PARENT,
];
return validCardinalities.includes(rSpec.cardA) && validCardinalities.includes(rSpec.cardB);
}
public getDirection() {
return this.direction;
}
@@ -279,17 +248,4 @@ export class ErDB implements DiagramDB {
public setDiagramTitle = setDiagramTitle;
public getDiagramTitle = getDiagramTitle;
public getConfig = () => getConfig().er;
// Getter methods for aggregation constants
public get AggregationConstants() {
return this.Aggregation;
}
public get CardinalityConstants() {
return this.Cardinality;
}
public get IdentificationConstants() {
return this.Identification;
}
}

View File

@@ -9,10 +9,6 @@ const ERMarkers = {
ZERO_OR_MORE_END: 'ZERO_OR_MORE_END',
MD_PARENT_END: 'MD_PARENT_END',
MD_PARENT_START: 'MD_PARENT_START',
AGGREGATION_START: 'AGGREGATION_START',
AGGREGATION_END: 'AGGREGATION_END',
AGGREGATION_DASHED_START: 'AGGREGATION_DASHED_START',
AGGREGATION_DASHED_END: 'AGGREGATION_DASHED_END',
};
/**
@@ -184,66 +180,6 @@ const insertMarkers = function (elem, conf) {
.attr('fill', 'none')
.attr('d', 'M21,18 Q39,0 57,18 Q39,36 21,18');
// Aggregation markers (hollow diamond)
elem
.append('defs')
.append('marker')
.attr('id', ERMarkers.AGGREGATION_START)
.attr('refX', 0)
.attr('refY', 9)
.attr('markerWidth', 20)
.attr('markerHeight', 18)
.attr('orient', 'auto')
.append('path')
.attr('stroke', conf.stroke)
.attr('fill', 'white')
.attr('d', 'M18,9 L9,0 L0,9 L9,18 Z');
elem
.append('defs')
.append('marker')
.attr('id', ERMarkers.AGGREGATION_END)
.attr('refX', 20)
.attr('refY', 9)
.attr('markerWidth', 20)
.attr('markerHeight', 18)
.attr('orient', 'auto')
.append('path')
.attr('stroke', conf.stroke)
.attr('fill', 'white')
.attr('d', 'M2,9 L11,0 L20,9 L11,18 Z');
// Dashed aggregation markers
elem
.append('defs')
.append('marker')
.attr('id', ERMarkers.AGGREGATION_DASHED_START)
.attr('refX', 0)
.attr('refY', 9)
.attr('markerWidth', 20)
.attr('markerHeight', 18)
.attr('orient', 'auto')
.append('path')
.attr('stroke', conf.stroke)
.attr('fill', 'white')
.attr('stroke-dasharray', '3,3')
.attr('d', 'M18,9 L9,0 L0,9 L9,18 Z');
elem
.append('defs')
.append('marker')
.attr('id', ERMarkers.AGGREGATION_DASHED_END)
.attr('refX', 20)
.attr('refY', 9)
.attr('markerWidth', 20)
.attr('markerHeight', 18)
.attr('orient', 'auto')
.append('path')
.attr('stroke', conf.stroke)
.attr('fill', 'white')
.attr('stroke-dasharray', '3,3')
.attr('d', 'M2,9 L11,0 L20,9 L11,18 Z');
return;
};

View File

@@ -448,11 +448,6 @@ const drawRelationshipFromLayout = function (svg, rel, g, insert, diagObj) {
svgPath.attr('stroke-dasharray', '8,8');
}
// Handle aggregation relationship styling
if (rel.relSpec.relType === diagObj.db.Aggregation.AGGREGATION_DASHED) {
svgPath.attr('stroke-dasharray', '8,8');
}
// TODO: Understand this better
let url = '';
if (conf.arrowMarkerAbsolute) {
@@ -508,15 +503,6 @@ const drawRelationshipFromLayout = function (svg, rel, g, insert, diagObj) {
break;
}
// Handle aggregation markers
if (
rel.relSpec.relType === diagObj.db.Aggregation.AGGREGATION ||
rel.relSpec.relType === diagObj.db.Aggregation.AGGREGATION_DASHED
) {
// Add aggregation marker at the start (entity B side)
svgPath.attr('marker-start', 'url(' + url + '#' + erMarkers.ERMarkers.AGGREGATION_START + ')');
}
// Now label the relationship
// Find the half-way point

View File

@@ -35,15 +35,3 @@ export interface EntityClass {
styles: string[];
textStyles: string[];
}
// Aggregation relationship types
export const AggregationType = {
AGGREGATION: 'AGGREGATION',
AGGREGATION_DASHED: 'AGGREGATION_DASHED',
} as const;
// Line types for aggregation
export const AggregationLineType = {
SOLID: 'SOLID',
DASHED: 'DASHED',
} as const;

View File

@@ -72,8 +72,6 @@ o\| return 'ZERO_OR_ONE';
o\{ return 'ZERO_OR_MORE';
\|\{ return 'ONE_OR_MORE';
\s*u return 'MD_PARENT';
"<>.." return 'AGGREGATION_DASHED';
"<>" return 'AGGREGATION';
\.\. return 'NON_IDENTIFYING';
\-\- return 'IDENTIFYING';
"to" return 'IDENTIFYING';
@@ -169,47 +167,6 @@ statement
| entityName SQS entityName SQE STYLE_SEPARATOR idList BLOCK_START BLOCK_STOP { yy.addEntity($1, $3); yy.setClass([$1], $6); }
| entityName SQS entityName SQE { yy.addEntity($1, $3); }
| entityName SQS entityName SQE STYLE_SEPARATOR idList { yy.addEntity($1, $3); yy.setClass([$1], $6); }
| entityName aggregationRelSpec entityName COLON role
{
yy.addEntity($1);
yy.addEntity($3);
yy.addRelationship($1, $5, $3, $2);
}
| entityName STYLE_SEPARATOR idList aggregationRelSpec entityName STYLE_SEPARATOR idList COLON role
{
yy.addEntity($1);
yy.addEntity($5);
yy.addRelationship($1, $9, $5, $4);
yy.setClass([$1], $3);
yy.setClass([$5], $7);
}
| entityName STYLE_SEPARATOR idList aggregationRelSpec entityName COLON role
{
yy.addEntity($1);
yy.addEntity($5);
yy.addRelationship($1, $7, $5, $4);
yy.setClass([$1], $3);
}
| entityName aggregationRelSpec entityName STYLE_SEPARATOR idList COLON role
{
yy.addEntity($1);
yy.addEntity($3);
yy.addRelationship($1, $7, $3, $2);
yy.setClass([$3], $5);
}
| entityName 'AGGREGATION' entityName COLON role
{
yy.addEntity($1);
yy.addEntity($3);
yy.addRelationship($1, $5, $3, { cardA: 'ZERO_OR_MORE', relType: 'AGGREGATION', cardB: 'ZERO_OR_MORE' });
}
| entityName 'AGGREGATION_DASHED' entityName COLON role
{
yy.addEntity($1);
yy.addEntity($3);
yy.addRelationship($1, $5, $3, { cardA: 'ZERO_OR_MORE', relType: 'AGGREGATION_DASHED', cardB: 'ZERO_OR_MORE' });
}
| title title_value { $$=$2.trim();yy.setAccTitle($$); }
| acc_title acc_title_value { $$=$2.trim();yy.setAccTitle($$); }
| acc_descr acc_descr_value { $$=$2.trim();yy.setAccDescription($$); }
@@ -315,17 +272,6 @@ relSpec
}
;
aggregationRelSpec
: 'AGGREGATION' cardinality cardinality
{
$$ = { cardA: $2, relType: $1, cardB: $3 };
}
| 'AGGREGATION_DASHED' cardinality cardinality
{
$$ = { cardA: $2, relType: $1, cardB: $3 };
}
;
cardinality
: 'ZERO_OR_ONE' { $$ = yy.Cardinality.ZERO_OR_ONE; }
| 'ZERO_OR_MORE' { $$ = yy.Cardinality.ZERO_OR_MORE; }
@@ -337,8 +283,6 @@ cardinality
relType
: 'NON_IDENTIFYING' { $$ = yy.Identification.NON_IDENTIFYING; }
| 'IDENTIFYING' { $$ = yy.Identification.IDENTIFYING; }
| 'AGGREGATION' { $$ = yy.Aggregation.AGGREGATION; }
| 'AGGREGATION_DASHED' { $$ = yy.Aggregation.AGGREGATION_DASHED; }
;
role

View File

@@ -1001,75 +1001,4 @@ describe('when parsing ER diagram it...', function () {
}
);
});
describe('aggregation relationships', function () {
it('should parse basic aggregation syntax', function () {
erDiagram.parser.parse('erDiagram\nDEPARTMENT <> EMPLOYEE : contains');
const rels = erDb.getRelationships();
expect(erDb.getEntities().size).toBe(2);
expect(rels.length).toBe(1);
expect(rels[0].relSpec.relType).toBe(erDb.Aggregation.AGGREGATION);
expect(rels[0].relSpec.cardA).toBe(erDb.Cardinality.ZERO_OR_MORE);
expect(rels[0].relSpec.cardB).toBe(erDb.Cardinality.ZERO_OR_MORE);
expect(rels[0].roleA).toBe('contains');
});
it('should parse dashed aggregation syntax', function () {
erDiagram.parser.parse('erDiagram\nPROJECT <>.. TASK : manages');
const rels = erDb.getRelationships();
expect(erDb.getEntities().size).toBe(2);
expect(rels.length).toBe(1);
expect(rels[0].relSpec.relType).toBe(erDb.Aggregation.AGGREGATION_DASHED);
expect(rels[0].relSpec.cardA).toBe(erDb.Cardinality.ZERO_OR_MORE);
expect(rels[0].relSpec.cardB).toBe(erDb.Cardinality.ZERO_OR_MORE);
expect(rels[0].roleA).toBe('manages');
});
it('should parse aggregation with quoted labels', function () {
erDiagram.parser.parse('erDiagram\nUNIVERSITY <> COLLEGE : "has multiple"');
const rels = erDb.getRelationships();
expect(erDb.getEntities().size).toBe(2);
expect(rels.length).toBe(1);
expect(rels[0].relSpec.relType).toBe(erDb.Aggregation.AGGREGATION);
expect(rels[0].roleA).toBe('has multiple');
});
it('should parse multiple aggregation relationships', function () {
erDiagram.parser.parse(
'erDiagram\nDEPARTMENT <> EMPLOYEE : contains\nPROJECT <>.. TASK : manages'
);
const rels = erDb.getRelationships();
expect(erDb.getEntities().size).toBe(4);
expect(rels.length).toBe(2);
expect(rels[0].relSpec.relType).toBe(erDb.Aggregation.AGGREGATION);
expect(rels[1].relSpec.relType).toBe(erDb.Aggregation.AGGREGATION_DASHED);
});
it('should parse aggregation with entity aliases', function () {
erDiagram.parser.parse('erDiagram\nd[DEPARTMENT]\ne[EMPLOYEE]\nd <> e : contains');
const rels = erDb.getRelationships();
expect(erDb.getEntities().size).toBe(2);
expect(rels.length).toBe(1);
expect(rels[0].relSpec.relType).toBe(erDb.Aggregation.AGGREGATION);
expect(erDb.getEntity('d').alias).toBe('DEPARTMENT');
expect(erDb.getEntity('e').alias).toBe('EMPLOYEE');
});
it('should validate aggregation relationships', function () {
erDiagram.parser.parse('erDiagram\nDEPARTMENT <> EMPLOYEE : contains');
const rels = erDb.getRelationships();
expect(erDb.validateAggregationRelationship(rels[0].relSpec)).toBe(true);
});
it('should handle mixed relationship types', function () {
erDiagram.parser.parse(
'erDiagram\nCUSTOMER ||--o{ ORDER : places\nPRODUCT <> ORDER_ITEM : "aggregated in"'
);
const rels = erDb.getRelationships();
expect(erDb.getEntities().size).toBe(4);
expect(rels.length).toBe(2);
expect(rels[0].relSpec.relType).toBe(erDb.Identification.IDENTIFYING);
expect(rels[1].relSpec.relType).toBe(erDb.Aggregation.AGGREGATION);
});
});
});

View File

@@ -68,32 +68,6 @@ const getStyles = (options: FlowChartStyleOptions) =>
stroke: ${options.lineColor} !important;
stroke-width: 1;
}
.aggregation {
stroke: ${options.lineColor};
stroke-width: 1;
fill: white;
}
.aggregation-dashed {
stroke: ${options.lineColor};
stroke-width: 1;
stroke-dasharray: 8,8;
fill: white;
}
.aggregation-marker {
fill: white !important;
stroke: ${options.lineColor} !important;
stroke-width: 1;
}
.aggregation-marker-dashed {
fill: white !important;
stroke: ${options.lineColor} !important;
stroke-width: 1;
stroke-dasharray: 3,3;
}
`;
export default getStyles;

View File

@@ -151,35 +151,6 @@ erDiagram
PERSON many(0) optionally to 0+ NAMED-DRIVER : is
```
### Aggregation
Aggregation represents a "has-a" relationship where the part can exist independently of the whole. This is different from composition, where the part cannot exist without the whole. Aggregation relationships are rendered with hollow diamond markers at the endpoints.
| Value | Alias for | Description |
| :---: | :------------------: | ------------------------------ |
| <> | _aggregation_ | Basic aggregation (solid line) |
| <>.. | _aggregation-dashed_ | Dashed aggregation line |
**Examples:**
```mermaid-example
erDiagram
DEPARTMENT <> EMPLOYEE : contains
PROJECT <>.. TASK : manages
TEAM <> MEMBER : consists_of
```
In these examples:
- `DEPARTMENT <> EMPLOYEE` shows that a department contains employees (aggregation)
- `PROJECT <>.. TASK` shows that a project manages tasks (dashed aggregation)
- `TEAM <> MEMBER` shows that a team consists of members (aggregation)
**Aggregation vs Association**
- **Aggregation** (`<>`): "Has-a" relationship where parts can exist independently
- **Association** (`||--`, `}o--`): General relationship between entities
### Attributes
Attributes can be defined for entities by specifying the entity name followed by a block containing multiple `type name` pairs, where a block is delimited by an opening `{` and a closing `}`. The attributes are rendered inside the entity boxes. For example: