mirror of
https://github.com/mermaid-js/mermaid.git
synced 2025-11-15 18:24:33 +01:00
fix: Ignore unknown arrow type values
Co-authored-by: Alois Klink <alois@aloisklink.com>
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
import type { SVG } from '../diagram-api/types.js';
|
import type { SVG } from '../diagram-api/types.js';
|
||||||
|
import { log } from '../logger.js';
|
||||||
import type { EdgeData } from '../types.js';
|
import type { EdgeData } from '../types.js';
|
||||||
/**
|
/**
|
||||||
* Adds SVG markers to a path element based on the arrow types specified in the edge.
|
* Adds SVG markers to a path element based on the arrow types specified in the edge.
|
||||||
@@ -24,6 +25,18 @@ export const addEdgeMarkers = (
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const arrowTypesMap = {
|
||||||
|
arrow_cross: 'cross',
|
||||||
|
arrow_point: 'point',
|
||||||
|
arrow_barb: 'barb',
|
||||||
|
arrow_circle: 'circle',
|
||||||
|
aggregation: 'aggregation',
|
||||||
|
extension: 'extension',
|
||||||
|
composition: 'composition',
|
||||||
|
dependency: 'dependency',
|
||||||
|
lollipop: 'lollipop',
|
||||||
|
} as const;
|
||||||
|
|
||||||
const addEdgeMarker = (
|
const addEdgeMarker = (
|
||||||
svgPath: SVG,
|
svgPath: SVG,
|
||||||
position: 'start' | 'end',
|
position: 'start' | 'end',
|
||||||
@@ -32,10 +45,13 @@ const addEdgeMarker = (
|
|||||||
id: string,
|
id: string,
|
||||||
diagramType: string
|
diagramType: string
|
||||||
) => {
|
) => {
|
||||||
if (arrowType.startsWith('arrow_')) {
|
const endMarkerType = arrowTypesMap[arrowType as keyof typeof arrowTypesMap];
|
||||||
arrowType = arrowType.replace('arrow_', '');
|
|
||||||
|
if (!endMarkerType) {
|
||||||
|
log.warn(`Unknown arrow type: ${arrowType}`);
|
||||||
|
return; // unknown arrow type, ignore
|
||||||
}
|
}
|
||||||
|
|
||||||
const suffix = position === 'start' ? 'Start' : 'End';
|
const suffix = position === 'start' ? 'Start' : 'End';
|
||||||
svgPath.attr(`marker-${position}`, `url(${url}#${id}_${diagramType}-${arrowType}${suffix})`);
|
svgPath.attr(`marker-${position}`, `url(${url}#${id}_${diagramType}-${endMarkerType}${suffix})`);
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user