8000 [graphology-canvas] render() ignores everything in settings argument except for width and height · Issue #542 · graphology/graphology · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

[graphology-canvas] render() ignores everything in settings argument except for width and height #542

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

Open
thSoft opened this issue Apr 25, 2025 · 1 comment
Labels

Comments

@thSoft
Copy link
thSoft commented Apr 25, 2025

render calls refineSettings which looks like this:

exports.refineSettings = function refineSettings(settings) {
  settings = settings || {};

  var dimensions = {
    width: settings.width,
    height: settings.height
  };

  if (dimensions.width && !dimensions.height)
    dimensions.height = dimensions.width;

  if (dimensions.height && !dimensions.width)
    dimensions.width = dimensions.height;

  settings = resolveDefaults(settings, dimensions);
  settings = resolveDefaults(settings, DEFAULTS);

  if (!settings.width && !settings.height)
    throw new Error(
      'graphology-canvas: need at least a valid width or height!'
    );

  return settings;
};

Before executing the settings = resolveDefaults(settings, dimensions); line, the value of the settings argument is:

{
  width: 300,
  height: 200,
  nodes: {
    defaultColor: "#0000ff",
    reducer: (_, node)=>{
      const attributes = graph.getNodeAttributes(node);
      const position = nodePositions.get(node);
      const attributeStrings = Object.entries(attributes).filter(([_, value])=>value !== undefined && value !== null).map(([key, value])=>`${key}: ${JSON.stringify(value)}`).join("\n");
      return {
          x: position?.x ?? 0,
          y: position?.y ?? 0,
          size: 20,
          label: `${characters[node]?.name || node}\n${attributeStrings}`,
          color: attributes.dead ? "#ff0000" : "#0000ff"
      };
    },
  },
  edges: {
    defaultColor: "#000000",
  },
}

After executing it, it becomes:

{
  width: 300,
  height: 200,
}
@Yomguithereal
Copy link
Member

Reading the way the resolveDefaults function works, it seems you are right indeed. DEFAULTS resolution should happen before using the dimensions to merge. This could should be refactored to avoid the problem you demonstrate. Do you want to contribute a fix?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants
0