mirror of
https://github.com/mermaid-js/mermaid.git
synced 2025-01-14 06:43:25 +08:00
make more RectData
required and remove optional assignment
This commit is contained in:
parent
541ee1eade
commit
99c1758490
@ -1,12 +1,12 @@
|
||||
export interface RectData {
|
||||
x?: number;
|
||||
y?: number;
|
||||
fill?: string;
|
||||
width?: number;
|
||||
height?: number;
|
||||
stroke?: string;
|
||||
x: number;
|
||||
y: number;
|
||||
fill: string;
|
||||
width: number;
|
||||
height: number;
|
||||
stroke: string;
|
||||
class?: string;
|
||||
color?: string | number;
|
||||
color?: string;
|
||||
rx?: number;
|
||||
ry?: number;
|
||||
attrs?: Record<string, string | number>;
|
||||
@ -44,7 +44,7 @@ export interface TextObject {
|
||||
rx: number;
|
||||
ry: number;
|
||||
tspan: boolean;
|
||||
valign: unknown;
|
||||
valign?: string;
|
||||
}
|
||||
|
||||
export type D3RectElement = d3.Selection<SVGRectElement, unknown, Element | null, unknown>;
|
||||
|
@ -15,24 +15,22 @@ import { lineBreakRegex } from './common.js';
|
||||
|
||||
export const drawRect = (element: SVG | Group, rectData: RectData): D3RectElement => {
|
||||
const rectElement: D3RectElement = element.append('rect');
|
||||
rectData.x !== undefined && rectElement.attr('x', rectData.x);
|
||||
rectData.y !== undefined && rectElement.attr('y', rectData.y);
|
||||
rectData.fill !== undefined && rectElement.attr('fill', rectData.fill);
|
||||
rectData.stroke !== undefined && rectElement.attr('stroke', rectData.stroke);
|
||||
rectData.width !== undefined && rectElement.attr('width', rectData.width);
|
||||
rectData.height !== undefined && rectElement.attr('height', rectData.height);
|
||||
rectElement.attr('x', rectData.x);
|
||||
rectElement.attr('y', rectData.y);
|
||||
rectElement.attr('fill', rectData.fill);
|
||||
rectElement.attr('stroke', rectData.stroke);
|
||||
rectElement.attr('width', rectData.width);
|
||||
rectElement.attr('height', rectData.height);
|
||||
rectData.rx !== undefined && rectElement.attr('rx', rectData.rx);
|
||||
rectData.ry !== undefined && rectElement.attr('ry', rectData.ry);
|
||||
|
||||
if (rectData.attrs !== undefined && rectData.attrs !== null) {
|
||||
if (rectData.attrs !== undefined) {
|
||||
for (const attrKey in rectData.attrs) {
|
||||
rectElement.attr(attrKey, rectData.attrs[attrKey]);
|
||||
}
|
||||
}
|
||||
|
||||
if (rectData.class !== undefined) {
|
||||
rectElement.attr('class', rectData.class);
|
||||
}
|
||||
rectData.class !== undefined && rectElement.attr('class', rectData.class);
|
||||
|
||||
return rectElement;
|
||||
};
|
||||
@ -117,15 +115,12 @@ export const getTextObj = (): TextObject => {
|
||||
y: 0,
|
||||
width: 100,
|
||||
height: 100,
|
||||
fill: undefined,
|
||||
anchor: undefined,
|
||||
'text-anchor': 'start',
|
||||
style: '#666',
|
||||
textMargin: 0,
|
||||
rx: 0,
|
||||
ry: 0,
|
||||
tspan: true,
|
||||
valign: undefined,
|
||||
};
|
||||
return testObject;
|
||||
};
|
||||
|
Loading…
x
Reference in New Issue
Block a user