Skip to content

Commit

Permalink
added size type checking variable for simplification, use logWarning
Browse files Browse the repository at this point in the history
  • Loading branch information
terahn committed Jul 2, 2020
1 parent 8048df2 commit 3c52d04
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
7 changes: 4 additions & 3 deletions src/components/graph/graph.builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ function buildNodeProps(node, config, nodeCallbacks = {}, highlightedNode, highl
const highlight =
node.highlighted ||
node.id === (highlightedLink && highlightedLink.source) ||
node.id === (highlightedLink && highlightedLink.target);
node.id === (highlightedLink && highlightedLink.target);
const opacity = _getNodeOpacity(node, highlightedNode, highlightedLink, config);

let fill = node.color || config.node.color;
Expand Down Expand Up @@ -203,8 +203,9 @@ function buildNodeProps(node, config, nodeCallbacks = {}, highlightedNode, highl
const nodeSize = node.size || config.node.size;

let offset;
const isSizeNumericValue = typeof nodeSize !== "object";

if (typeof nodeSize !== "object") {
if (isSizeNumericValue) {
offset = nodeSize;
} else if (labelPosition === "top" || labelPosition === "bottom") {
offset = nodeSize.height;
Expand Down Expand Up @@ -234,7 +235,7 @@ function buildNodeProps(node, config, nodeCallbacks = {}, highlightedNode, highl
opacity,
overrideGlobalViewGenerator: !node.viewGenerator && node.svg,
renderLabel: node.renderLabel || config.node.renderLabel,
size: typeof nodeSize !== "object" ? nodeSize * t : { height: nodeSize.height * t, width: nodeSize.width * t },
size: isSizeNumericValue ? nodeSize * t : { height: nodeSize.height * t, width: nodeSize.width * t },
stroke,
strokeWidth: strokeWidth * t,
svg,
Expand Down
10 changes: 6 additions & 4 deletions src/components/node/Node.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import React from "react";

import nodeHelper from "./node.helper";
import CONST from "./node.const";
import { logWarning } from "../../utils";

/**
* Node component is responsible for encapsulating node render.
Expand Down Expand Up @@ -96,15 +97,16 @@ export default class Node extends React.Component {
};

let size = this.props.size;
const isSizeNumericalValue = typeof size !== "object";

let gtx = this.props.cx,
gty = this.props.cy,
label = null,
node = null;

if (this.props.svg || this.props.viewGenerator) {
const height = typeof size === "object" ? size.height / 10 : size / 10;
const width = typeof size === "object" ? size.width / 10 : size / 10;
const height = isSizeNumericalValue ? size / 10 : size.height / 10;
const width = isSizeNumericalValue ? size / 10 : size.width / 10;
const tx = width / 2;
const ty = height / 2;
const transform = `translate(${tx},${ty})`;
Expand Down Expand Up @@ -134,8 +136,8 @@ export default class Node extends React.Component {
gtx -= tx;
gty -= ty;
} else {
if (typeof size === "object") {
console.warn("node.size should be a number when not using custom nodes.");
if (!isSizeNumericalValue) {
logWarning("node.size should be a number when not using custom nodes.");
size = CONST.DEFAULT_NODE_SIZE;
}
nodeProps.d = nodeHelper.buildSvgSymbol(size, this.props.type);
Expand Down

0 comments on commit 3c52d04

Please sign in to comment.