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

how to add a label for every node ? #16

Closed
realcarlos opened this issue Dec 11, 2013 · 9 comments
Closed

how to add a label for every node ? #16

realcarlos opened this issue Dec 11, 2013 · 9 comments
Labels

Comments

@realcarlos
Copy link

Hi ,I want to add a string on every node, but with_labels just add the node's name in the circle ,how to make a label beside the circle ? and I also want to set different size for every circle , thank you very much .

@fkling
Copy link
Owner

fkling commented Dec 12, 2013

As you can see in https://github.com/fkling/JSNetworkX/wiki/Drawing-graphs, you can set the labels with the labels option:

labels (string|function|object):
If this option is not set and with_labels is true, the node itself is used as label.

If labels is a string, the label value is taken from each node data, with the key being the value of labels. I.e. G.node[n][labels].

If labels is a function, the label value is the return value of this function. The function is called for each node and is passed one argument. This argument is the same datum bound to each node element with D3.

If labels is an object, each node is looked up in the object and the value is taken as label, i.e. labels[node].

For different sizes, have a look at the Getting started tutorial, it shows an example and provides more information about drawing: http://felix-kling.de/JSNetworkX/getting_started.html#drawing

@realcarlos
Copy link
Author

Thank you for reply my question ,I read the wiki ,but could not find how to use Lables option,would you like give me a sample ?

@fkling
Copy link
Owner

fkling commented Dec 15, 2013

var G = jsnx.Graph();
G.add_node(1, {label: 'foo'});
G.add_node(2, {label: 'bar'});
G.add_node(3, {label: 'baz'});
G.add_edges_from([[1,2],[2,3]]);

jsnx.draw(G, {
    element: '#demo-canvas',
    with_labels: true,
    node_labels: 'label'
});

@realcarlos
Copy link
Author

OK, I see , thank you very much !!!

@fkling fkling closed this as completed Dec 15, 2013
@devpacdd
Copy link

devpacdd commented Jun 8, 2014

But this don't work:
node_labels: 'label',
don't make the label to the node and see the number.

@fkling
Copy link
Owner

fkling commented Jun 16, 2014

@adev-test : No, with_labels: true shows the labels. The node_labels option indicates which property to take as label from the data object, just as shown in my example

@WilHall
Copy link

WilHall commented Jan 20, 2015

For anyone reading this thread and wondering why @fkling 's suggestion isn't working - the option is labels not node_labels (he mentioned this is an earlier comment but the example is incorrect)

@fkling
Copy link
Owner

fkling commented Jan 20, 2015

@WilHall: 👍 That's what I get for using inconsistent option names. Corrected example:

var G = jsnx.Graph();
G.add_node(1, {label: 'foo'});
G.add_node(2, {label: 'bar'});
G.add_node(3, {label: 'baz'});
G.add_edges_from([[1,2],[2,3]]);

jsnx.draw(G, {
    element: '#demo-canvas',
    with_labels: true,
    labels: 'label'
});

@neetigyachahar
Copy link

neetigyachahar commented Nov 2, 2019

with-labels doesn't work anymore.
withLabels works.

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

5 participants