Skip to content

Commit

Permalink
(minor) fix ==; remove unused imports; fix typos; add comments
Browse files Browse the repository at this point in the history
  • Loading branch information
weedySeaDragon committed Sep 24, 2022
1 parent d328879 commit 481b5cd
Showing 1 changed file with 16 additions and 11 deletions.
27 changes: 16 additions & 11 deletions src/diagrams/er/erRenderer.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import graphlib from 'graphlib';
import { line, curveBasis, select } from 'd3';
// import erDb from './erDb';
// import erParser from './parser/erDiagram';
import dagre from 'dagre';
import { getConfig } from '../../config';
import { log } from '../../logger';
Expand Down Expand Up @@ -31,8 +29,10 @@ export const setConf = function (cnf) {
*
* @param groupNode The svg group node for the entity
* @param entityTextNode The svg node for the entity label text
* @param attributes An array of attributes defined for the entity (each attribute has a type and a name)
* @returns {object} The bounding box of the entity, after attributes have been added. The bounding box has a .width and .height
* @param attributes An array of attributes defined for the entity (each attribute has a type and a
* name)
* @returns {object} The bounding box of the entity, after attributes have been added. The bounding
* box has a .width and .height
*/
const drawAttributes = (groupNode, entityTextNode, attributes) => {
const heightPadding = conf.entityPadding / 3; // Padding internal to attribute boxes
Expand Down Expand Up @@ -288,7 +288,7 @@ const drawAttributes = (groupNode, entityTextNode, attributes) => {
heightOffset += attributeNode.height + heightPadding * 2;

// Flip the attribute style for row banding
attribStyle = attribStyle == 'attributeBoxOdd' ? 'attributeBoxEven' : 'attributeBoxOdd';
attribStyle = attribStyle === 'attributeBoxOdd' ? 'attributeBoxEven' : 'attributeBoxOdd';
});
} else {
// Ensure the entity box is a decent size without any attributes
Expand Down Expand Up @@ -382,9 +382,16 @@ const adjustEntities = function (svgNode, graph) {
);
}
});
return;
};

/**
* Construct a name for an edge based on the names of the 2 entities and the role (relationship)
* between them. Remove any spaces from it
*
* @param rel - A (parsed) relationship (e.g. one of the objects in the list returned by
* erDb.getRelationships)
* @returns {string}
*/
const getEdgeName = function (rel) {
return (rel.entityA + rel.roleA + rel.entityB).replace(/\s/g, '');
};
Expand All @@ -393,7 +400,7 @@ const getEdgeName = function (rel) {
* Add each relationship to the graph
*
* @param relationships The relationships to be added
* @param g The graph
* @param {Graph} g The graph
* @returns {Array} The array of relationships
*/
const addRelationships = function (relationships, g) {
Expand Down Expand Up @@ -535,8 +542,6 @@ const drawRelationshipFromLayout = function (svg, rel, g, insert, diagObj) {
.attr('height', labelBBox.height)
.attr('fill', 'white')
.attr('fill-opacity', '85%');

return;
};

/**
Expand All @@ -552,7 +557,7 @@ export const draw = function (text, id, _version, diagObj) {
log.info('Drawing ER diagram');
// diag.db.clear();
const securityLevel = getConfig().securityLevel;
// Handle root and Document for when rendering in sanbox mode
// Handle root and Document for when rendering in sandbox mode
let sandboxElement;
if (securityLevel === 'sandbox') {
sandboxElement = select('#i' + id);
Expand Down Expand Up @@ -581,7 +586,7 @@ export const draw = function (text, id, _version, diagObj) {
// 1. Create all the entities in the svg node at 0,0, but with the correct dimensions (allowing for text content)
// 2. Make sure they are all added to the graph
// 3. Add all the edges (relationships) to the graph as well
// 4. Let dagre do its magic to layout the graph. This assigns:
// 4. Let dagre do its magic to lay out the graph. This assigns:
// - the centre co-ordinates for each node, bearing in mind the dimensions and edge relationships
// - the path co-ordinates for each edge
// But it has no impact on the svg child nodes - the diagram remains with every entity rooted at 0,0
Expand Down

0 comments on commit 481b5cd

Please sign in to comment.