mirror of
https://github.com/mermaid-js/mermaid.git
synced 2025-09-19 15:30:03 +02:00
Make undefined text not display
This commit is contained in:
@@ -61,12 +61,12 @@ const setDirection = (dir: string) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const getInitialRequirement = (): Requirement => ({
|
const getInitialRequirement = (): Requirement => ({
|
||||||
id: '',
|
requirement_id: '',
|
||||||
text: '',
|
text: '',
|
||||||
risk: RiskLevel.LOW_RISK as RiskLevel,
|
risk: '' as RiskLevel,
|
||||||
verifyMethod: VerifyType.VERIFY_ANALYSIS as VerifyType,
|
verifyMethod: '' as VerifyType,
|
||||||
name: '',
|
name: '',
|
||||||
type: RequirementType.REQUIREMENT as RequirementType,
|
type: '' as RequirementType,
|
||||||
cssStyles: [],
|
cssStyles: [],
|
||||||
classes: ['default'],
|
classes: ['default'],
|
||||||
});
|
});
|
||||||
@@ -101,7 +101,7 @@ const addRequirement = (name: string, type: RequirementType) => {
|
|||||||
requirements.set(name, {
|
requirements.set(name, {
|
||||||
name,
|
name,
|
||||||
type,
|
type,
|
||||||
id: latestRequirement.id,
|
requirement_id: latestRequirement.requirement_id,
|
||||||
text: latestRequirement.text,
|
text: latestRequirement.text,
|
||||||
risk: latestRequirement.risk,
|
risk: latestRequirement.risk,
|
||||||
verifyMethod: latestRequirement.verifyMethod,
|
verifyMethod: latestRequirement.verifyMethod,
|
||||||
@@ -118,7 +118,7 @@ const getRequirements = () => requirements;
|
|||||||
|
|
||||||
const setNewReqId = (id: string) => {
|
const setNewReqId = (id: string) => {
|
||||||
if (latestRequirement !== undefined) {
|
if (latestRequirement !== undefined) {
|
||||||
latestRequirement.id = id;
|
latestRequirement.requirement_id = id;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -262,6 +262,7 @@ const getData = () => {
|
|||||||
const edges: Edge[] = [];
|
const edges: Edge[] = [];
|
||||||
for (const requirement of requirements.values()) {
|
for (const requirement of requirements.values()) {
|
||||||
const node = requirement as unknown as Node;
|
const node = requirement as unknown as Node;
|
||||||
|
node.id = requirement.name;
|
||||||
node.cssStyles = requirement.cssStyles;
|
node.cssStyles = requirement.cssStyles;
|
||||||
node.cssClasses = requirement.classes.join(' ');
|
node.cssClasses = requirement.classes.join(' ');
|
||||||
node.shape = 'requirementBox';
|
node.shape = 'requirementBox';
|
||||||
@@ -285,8 +286,8 @@ const getData = () => {
|
|||||||
const isContains = relation.type === Relationships.CONTAINS;
|
const isContains = relation.type === Relationships.CONTAINS;
|
||||||
const edge: Edge = {
|
const edge: Edge = {
|
||||||
id: `${relation.src}-${relation.dst}-${counter}`,
|
id: `${relation.src}-${relation.dst}-${counter}`,
|
||||||
start: requirements.get(relation.src)?.id ?? elements.get(relation.src)?.name,
|
start: requirements.get(relation.src)?.name ?? elements.get(relation.src)?.name,
|
||||||
end: requirements.get(relation.dst)?.id ?? elements.get(relation.dst)?.name,
|
end: requirements.get(relation.dst)?.name ?? elements.get(relation.dst)?.name,
|
||||||
label: `<<${relation.type}>>`,
|
label: `<<${relation.type}>>`,
|
||||||
classes: 'relationshipLine',
|
classes: 'relationshipLine',
|
||||||
style: ['fill:none', isContains ? '' : 'stroke-dasharray: 10,7'],
|
style: ['fill:none', isContains ? '' : 'stroke-dasharray: 10,7'],
|
||||||
|
@@ -13,7 +13,7 @@ export type VerifyType = 'Analysis' | 'Demonstration' | 'Inspection' | 'Test';
|
|||||||
export interface Requirement {
|
export interface Requirement {
|
||||||
name: string;
|
name: string;
|
||||||
type: RequirementType;
|
type: RequirementType;
|
||||||
id: string;
|
requirement_id: string;
|
||||||
text: string;
|
text: string;
|
||||||
risk: RiskLevel;
|
risk: RiskLevel;
|
||||||
verifyMethod: VerifyType;
|
verifyMethod: VerifyType;
|
||||||
|
@@ -55,28 +55,29 @@ export async function requirementBox<T extends SVGGraphicsElement>(
|
|||||||
if (isRequirementNode) {
|
if (isRequirementNode) {
|
||||||
const idHeight = await addText(
|
const idHeight = await addText(
|
||||||
shapeSvg,
|
shapeSvg,
|
||||||
`Id: ${requirementNode.id}`,
|
`${requirementNode.requirement_id ? `Id: ${requirementNode.requirement_id}` : ''}`,
|
||||||
accumulativeHeight,
|
accumulativeHeight,
|
||||||
node.labelStyle
|
node.labelStyle
|
||||||
);
|
);
|
||||||
|
|
||||||
accumulativeHeight += idHeight;
|
accumulativeHeight += idHeight;
|
||||||
const textHeight = await addText(
|
const textHeight = await addText(
|
||||||
shapeSvg,
|
shapeSvg,
|
||||||
`Text: ${requirementNode.text}`,
|
`${requirementNode.text ? `Text: ${requirementNode.text}` : ''}`,
|
||||||
accumulativeHeight,
|
accumulativeHeight,
|
||||||
node.labelStyle
|
node.labelStyle
|
||||||
);
|
);
|
||||||
accumulativeHeight += textHeight;
|
accumulativeHeight += textHeight;
|
||||||
const riskHeight = await addText(
|
const riskHeight = await addText(
|
||||||
shapeSvg,
|
shapeSvg,
|
||||||
`Risk: ${requirementNode.risk}`,
|
`${requirementNode.risk ? `Risk: ${requirementNode.risk}` : ''}`,
|
||||||
accumulativeHeight,
|
accumulativeHeight,
|
||||||
node.labelStyle
|
node.labelStyle
|
||||||
);
|
);
|
||||||
accumulativeHeight += riskHeight;
|
accumulativeHeight += riskHeight;
|
||||||
await addText(
|
await addText(
|
||||||
shapeSvg,
|
shapeSvg,
|
||||||
`Verification: ${requirementNode.verifyMethod}`,
|
`${requirementNode.verifyMethod ? `Verification: ${requirementNode.verifyMethod}` : ''}`,
|
||||||
accumulativeHeight,
|
accumulativeHeight,
|
||||||
node.labelStyle
|
node.labelStyle
|
||||||
);
|
);
|
||||||
@@ -84,14 +85,14 @@ export async function requirementBox<T extends SVGGraphicsElement>(
|
|||||||
// Element
|
// Element
|
||||||
const typeHeight = await addText(
|
const typeHeight = await addText(
|
||||||
shapeSvg,
|
shapeSvg,
|
||||||
`Type: ${elementNode.type ? elementNode.type : 'Not specified'}`,
|
`${elementNode.type ? `Type: ${elementNode.type}` : ''}`,
|
||||||
accumulativeHeight,
|
accumulativeHeight,
|
||||||
node.labelStyle
|
node.labelStyle
|
||||||
);
|
);
|
||||||
accumulativeHeight += typeHeight;
|
accumulativeHeight += typeHeight;
|
||||||
await addText(
|
await addText(
|
||||||
shapeSvg,
|
shapeSvg,
|
||||||
`Doc Ref: ${elementNode.docRef ? elementNode.docRef : 'None'}`,
|
`${elementNode.docRef ? `Doc Ref: ${elementNode.docRef}` : ''}`,
|
||||||
accumulativeHeight,
|
accumulativeHeight,
|
||||||
node.labelStyle
|
node.labelStyle
|
||||||
);
|
);
|
||||||
@@ -176,6 +177,9 @@ async function addText<T extends SVGGraphicsElement>(
|
|||||||
yOffset: number,
|
yOffset: number,
|
||||||
style = ''
|
style = ''
|
||||||
) {
|
) {
|
||||||
|
if (inputText === '') {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
const textEl = parentGroup.insert('g').attr('class', 'label').attr('style', style);
|
const textEl = parentGroup.insert('g').attr('class', 'label').attr('style', style);
|
||||||
const config = getConfig();
|
const config = getConfig();
|
||||||
const useHtmlLabels = config.htmlLabels ?? true;
|
const useHtmlLabels = config.htmlLabels ?? true;
|
||||||
|
Reference in New Issue
Block a user