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

Color Coding from Meta #16

Open
miklevin opened this issue Mar 14, 2024 · 3 comments
Open

Color Coding from Meta #16

miklevin opened this issue Mar 14, 2024 · 3 comments
Labels
app Queries regarding Cosmograph online app v1 Questions about Cosmograph v1

Comments

@miklevin
Copy link

miklevin commented Mar 14, 2024

This is maybe a bit weird, but another big win for relatively small effort. Here is my most common pattern in preparing a meta file for Cosmograph.app visualizations:

import pandas as pd
df = pd.read_csv("meta.csv")
df.rename(columns={df.columns[0]: 'id'}, inplace=True)
df["Color"] = "Green"
df.to_csv("meta-colored.csv", index=False)

The prior case I opened addresses the renaming of column 1 to id which I don't think I should have to do.

But this case is about simply adding a color column so I have a way of highlighting which nodes are being influenced by the meta data.

Use case: you have a frequency count and you set node size by meta:frequency. But there's not a frequency for every node, so some get sized by the meta data, and others use the default. And since everything is in the default purple color, the varying size becomes meaningless.

What I do in the above script simply adds a global color to the entire meta file, so things with meta data at all (regardless of the frequency count) get highlighted green. It is profoundly useful for making diagrams that look like medical images, telling the good nodes from the cancer.

Anyhow, I imagine implementation being something like an optional global meta color. It can be at the moment of import, or better still, it could be in Node appearance / node color by: metadata | Custom, with some way to set the custom color.

The lightest touch would be just to throw in a few custom colors in there like Red, Yellow, Green so there's no UI work. That would satisfy my needs, but adjusting the color with a slider would have huge emotional impact for my purposes.

Oh, and as a bonus, permit a color for things that do NOT have entries in the metadata. This is often the "cancer" that needs to be cut away. I will sometimes color-code that black.

@kolmakova
Copy link
Collaborator

Hi @miklevin! Have you tried to pass a custom function into nodeColoring config option? I think it should help with your case. You can use it like:

function customColoring(node, clickedNodeIdList) {
 // Define the default color and the global meta color
  const defaultColor = node.color;
  const globalMetaColor = '#00ff00'; // Green

  // Check if the current node has meta data
  if (metaData[node.id]) {
    return globalMetaColor;
  } else {
    return defaultColor;
  }
}

// Usage example:
config.nodeColor = (node) => customColoring(node);
cosmograph.setConfig(config)

You can do same thing with the nodeSize and link props.

@kolmakova
Copy link
Collaborator

Oh I got it, it's a question about Cosmograph.app, not Lib 😅. We can add an option for 'unknown' color in the sidebar, but I think it will be implemented only in the next global update of Cosmograph.app that we're planning soon.

@miklevin
Copy link
Author

Thanks. I look forward to it.

@kolmakova kolmakova added app Queries regarding Cosmograph online app v1 Questions about Cosmograph v1 labels Dec 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
app Queries regarding Cosmograph online app v1 Questions about Cosmograph v1
Projects
None yet
Development

No branches or pull requests

2 participants