Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

node.fontSize value now overrides config.node.fontSize value #376

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions src/components/graph/graph.builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -206,8 +206,12 @@ function buildNodeProps(node, config, nodeCallbacks = {}, highlightedNode, highl
nodeSize.width;
}

const fontSize = highlight ? config.node.highlightFontSize : config.node.fontSize;
const dx = fontSize * t + offset / 100 + 1.5;
const fontSize = node.fontSize || config.node.fontSize;
const highlightFontSize = node.highlightFontSize || config.node.highlightFontSize;

const finalFontSize = highlight ? highlightFontSize : fontSize;
const dx = finalFontSize * t + offset / 100 + 1.5;

const svg = node.svg || config.node.svg;
const fontColor = node.fontColor || config.node.fontColor;

Expand All @@ -225,7 +229,7 @@ function buildNodeProps(node, config, nodeCallbacks = {}, highlightedNode, highl
dx,
fill,
fontColor,
fontSize: fontSize * t,
fontSize: finalFontSize * t,
fontWeight: highlight ? config.node.highlightFontWeight : config.node.fontWeight,
id: node.id,
label,
Expand Down
27 changes: 27 additions & 0 deletions test/graph/graph.builder.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -156,5 +156,32 @@ describe("Graph Helper", () => {
expect(props.stroke).toEqual("yellow");
});
});
describe("and no custom fontSize is set", () => {
test("should return the fontSize from the config in the props", () => {
const props = graphHelper.buildNodeProps(
that.node,
{ ...that.config, node: { ...that.config.node, fontSize: 10 } },
undefined,
undefined,
undefined,
1
);
expect(props.fontSize).toEqual(10);
});
});
describe("and custom fontSize is set to 6", () => {
test("should override the value of fontSize set in the props", () => {
const props = graphHelper.buildNodeProps(
{ ...that.node, fontSize: 6 },
{ ...that.config, node: { ...that.config.node, fontSize: 10 } },
undefined,
undefined,
undefined,
1
);

expect(props.fontSize).toEqual(6);
});
});
});
});