Skip to content

Commit

Permalink
feat: add note on the node
Browse files Browse the repository at this point in the history
  • Loading branch information
alswl committed May 4, 2024
1 parent f060e37 commit 2ec5814
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 0 deletions.
29 changes: 29 additions & 0 deletions src/nodes/er.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,20 @@ function registerER() {
},
true,
);
Graph.registerPortLayout(
'erNotePosition',
(portsPositionArgs) => {
return portsPositionArgs.map((_, index) => {
return {
position: {
x: 0,
y: 0,
},
};
});
},
true,
);

Graph.registerNode(
'er-rect',
Expand Down Expand Up @@ -48,6 +62,21 @@ function registerER() {
},
ports: {
groups: {
note: {
position: 'erNotePosition',
markup: [
{
tagName: 'text',
selector: 'note',
},
],
attrs: {
note: {
refX: 0,
refY: -LINE_HEIGHT,
},
},
},
list: {
position: 'erPortPosition',
markup: [
Expand Down
2 changes: 2 additions & 0 deletions src/pages/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ export default () => {
username varchar
role varchar
created_at timestamp
Note: 'User Table'
}
Table posts {
Expand Down
28 changes: 28 additions & 0 deletions src/parser/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,33 @@ function parseFieldToPort(
};
}

function parseNoteToPort(
note: string,
schemaName: string,
tableName: string,
): any {
return {
id: `${schemaName}-${tableName}-note`,
group: 'note',
attrs: {
note: {
text: note,
},
},
};
}

function parseTableToNode(table: Table, schemaName: string): any {
let fields: any[] = [];
for (let k = 0; k < table.fields.length; k++) {
const f = table.fields[k];
const field = parseFieldToPort(f, schemaName, table.name);
fields.push(field);
}
if (table.note) {
const note = parseNoteToPort(table.note, schemaName, table.name);
fields.push(note);
}
return {
id: `${schemaName}-${table.name}`,
shape: 'er-rect',
Expand All @@ -62,6 +82,14 @@ function parseRef(ref: Ref): any {
return {
id: ``,
shape: 'edge',
router: {
name: 'er',
args: {
offset: 16,
min: 4,
direction: 'H',
},
},
source: {
cell: `${sSchemaName}-${source.tableName}`,
port: `${sSchemaName}-${source.tableName}-${sourceFieldName}`,
Expand Down

0 comments on commit 2ec5814

Please sign in to comment.