Skip to content

fix(node.icon): Allow Node.icon to inherit Node.size#2444

Open
hwelch-fle wants to merge 4 commits into
visjs:masterfrom
hwelch-fle:node-icon-size
Open

fix(node.icon): Allow Node.icon to inherit Node.size#2444
hwelch-fle wants to merge 4 commits into
visjs:masterfrom
hwelch-fle:node-icon-size

Conversation

@hwelch-fle

@hwelch-fle hwelch-fle commented Jun 1, 2026

Copy link
Copy Markdown

No AI used at any stage of this PR

Change option resolution order for Node to allow node icon size to inherit from node size

I tried to keep the resolution simple. Since icon.size is the only shape that uses a seperate size property, I had to unset the defaults in NodesHandler for both size and icon.size.

These options are resolved in NodeBase.setOptions now.

Old Icon Size Resolution:

<nodeobj>.icon.size -> <groupobj>.icon.size -> <network.nodes>.icon.size

New Icon Size Resolution:

(node->group->network.nodes).icon.size
--then--
(node->group->network.nodes).size
--then--
50

I'm not sure if it's better to have the size be inherited this way though:

node.icon.size -> node.size
--then--
group.icon.size -> group.size
--then--
network.icon.size -> network.size
--then--
50 

If the second option is more logical I will gladly ammend this PR to do it that way. I just figured that icon.size being directly set at any point should probably supercede the size fallbacks to prevent issues with existing setups.

This might also cause breaking changes if someone is setting size and leaving it set on an icon node because they saw no change. The fix would be to either remove the size key from the node or to set icon.size at any level of the config.

resolves #385

@hwelch-fle

hwelch-fle commented Jun 1, 2026

Copy link
Copy Markdown
Author

It does seem that two of the visual regression checks are failing, but that's expected since those have a size set on the node level with icon.size left undefined.

If we want to add this, but prevent regressions in networks created with the size unaware icons, we could maybe add a new inherit_size option to the network node icon options?

@hwelch-fle

hwelch-fle commented Jun 2, 2026

Copy link
Copy Markdown
Author

Additional commits should preserve original behavior and hide size inheriting behind a new inheritSize property.

Value add here is that currently, icons that are set in groups can't be dynamically sized without directly copying the group icon object to the node and updating the size.

This will allow you to use icons and drive the size the same way you drive the size of every other shape type.

Here's a sample graph that this would benefit

I wanted to set the icon groups based on file extension, then size the nodes based on line count, but the group icon size is set to 50 and overwrites the node size currently.

@hwelch-fle

Copy link
Copy Markdown
Author

If this is something that will be merged, we might want to do the same thing with icon.color too? I will also make those changes if you want.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Change selected node styles

1 participant