Add a label to the edge of Flare

Source: Internet
Author: User
10:36:46 UTC

I have started using flare to visualize a simple graphs with nodes and edges-similar to the demo (layouts/tree ).

This simple code displays the tree structure but with any labels. I want to use the node name from the graphml file as the node name

Can anyone help me

Thanks

MRC

Public Function tutorial ()
{
Loaddata ();
}

Private function loaddata (): void
{

VaR DS: datasource = new datasource ("http: // localhost/deps-gml.xml", "graphml ");

VaR Loader: urlloader = Ds. Load ();
Loader. addeventlistener (event. Complete, function (EVT: Event): void {
VaR DS: DataSet = loader. Data as dataset;
Visualize (data. fromdataset (DS ));
});
}
Private function visualize (data: data): void
{

VaR FMT: textformat = new textformat ();
FMT. font = "Arial ";
FMT. size = 19;
FMT. Bold = false;

Vis = new visualization (data );
VIS. bounds = new rectangle (0, 0, 600,500 );

VIS. x = 100;
VIS. Y = 50
Addchild (VIS );

VaR LAN: labeler = new labeler ("data. nodes. Name", Data. nodes, FMT );
VIS. Operators. Add (LAN );
VIS. Operators. Add (New nodelinktreelayout ("toptobottom", 5, 10 ));

VIS. Update ();

}

  • Goosebumps4all

    12:20:00 UTC

    I guess

    VaR LAN: labeler = new labeler ("data. nodes. Name", Data. nodes, FMT );

    Shocould be

    VaR LAN: labeler = new labeler ("data. Name", Data. nodes, FMT );

    Hope that is it

    Cheers

    Martin

  • Cortinas

    12:39:21 UTC

    Thanks. I added the following and now I have labels ....

    VIS. Data. nodes. Visit (function (NS: nodesprite): void {
    NS. Data. Label = NS. Data. ID;
    });

    VaR LAN: labeler = new labeler ("data. Label", Data. nodes, FMT );
    VIS. Operators. Add (LAN );

  • Pall213

    13:58:14 UTC

    Hello all, just another similar question.

    What if I want to reach the value of the node? For example, there is a node like:
    ...
    <Node id = "node1"> somevalue </node>
    ...
    And I want to use that 'somevalue' as the label. How can I do that? And also how can I reach that value directly and assign it to a variable?

    I know these are probably very basic things for you, sorry.

  • Storycreator1

    14:32:35 UTC

    In the graphml format you have to write the value in a new sub-Tag:

    <Node id = "dm">
    <Data key = "value"> 50.0 </data>
    </Node>

    And before the <graph> tag you need to define this key
    <Key ID = "value" for = "Node" ATTR. Name = "yournamehere" ATTR. type = "double"/>

    (Of course you can use other names for the ID than "value ".)

    Now you can access the value in flare with "data. yournamehere ".

  • Pall213

    05:55:04 UTC

    OK, thank you for the answer. So I can use that "data. yournamehere" as a parameter to labeler and it'll work.

    But I still don't know how to assign that value to a variable, anyone can help? In other words,

    VaR S: String = what to write here?

  • Goosebumps4all

    09:17:08 UTC

    VaR S: String = anodesprite. Data. yournamehere;

    Where anodesprite is the nodesprite instance holding that value;

  • Pall213

    09:45:08 UTC

    Thank you very much, it works perfectly.

  • Pall213

    11:02:53 UTC

    OK so, I can use the key "name" in the data as the label for the node:

    VaR LAN: labeler = new labeler ("data. Name", Data. nodes, FMT );

    But what if I have another key (say "type") that I also want to show it in the label with the "name "? (So the label will look like "examplename, exampletype") is there any way to do this with the labeler? Or shoshould I just add a textfield to each node and write whatever I want to them?

  • Goosebumps4all

    12:59:51 UTC

    Http://flare.prefuse.org/api/flare/vis/operator/label/Labeler.html#Labeler ()

  • Pall213

    14:27:04 UTC

    OK, thank you. So I can use a function to determine the label. Another question though, is it possible to use more than one labelers for a node? If so, how?

  • Goosebumps4all

    16:17:31 UTC

    Well I wocould suggest adding two labelers to the operator list and lew.us know how it goes

  • Pall213

    06:43:36 UTC

    Well I tried adding two labelers but it doesn't seem to be working. The second one is always ignored. I also tried changing yoffset and verticalanchor values. Any ideas?

  • Goosebumps4all

    08:00:48 UTC

    Surprising, yet looking into the class revealed that it is due to fact how the labelers class stores the textfied, Which is per default in anodesprite. Props. Label

    Luckily this default flied can be customized, so far your second labeler you might do something like

    Labeler2.access = "props. label2 ";

    And work with this field for the case you do extra customizations for the texfield

    Hope that helps

    Martin

  • Pall213

    12:26:17 UTC

    Great. Thank you very much.

  • Amit4767

    10:47:23 UTC

    First of all I wowould like say thanks to all for helping me in giving label to node. Specially
    Cortinas (Cortinas.
    Can anybody please tell how can I give label to edge between two nodes.

  • Amit4767

    10:54:31 UTC

    VIS. Data. edges. Visit (function (NS: nodesprite): void {

    If (NS. Data. Label = "3 "){

    NS. Data. Label = "ASD ";
    } Else {

    NS. Data. Label = "Amit ";
    }

    });

    VaR lan1: labeler = new labeler ("data. Label", Data. edges, FMT );
    // Vis. Operators. Add (LAN );
    VIS. Operators. Add (lan1 );
    VIS. Operators. Add (OPT [idx]. OP );
    VIS. setoperator ("nodes", new propertyencoder (OPT [idx]. nodes, "nodes "));
    VIS. setoperator ("edges", new propertyencoder (OPT [idx]. edges, "edges "));

    I have tried same like in node but it showing nothing in the output

  • Amit4767

    12:26:12 UTC

    Hehe thnks alot guy I got the answer

    VaR mm: Int = 0;
    VIS. Data. edges. Visit (function (ES: edgesprite): void {
    Es. Data. Label = "edge" + mm ++;
    });
    VIS. Data. edges. Visit (function (ES: edgesprite): void {
    Es. addeventlistener (event. Render, updateedgelabelposition );
    });
    VaR Lae: labeler = new labeler ("data. Label", Data. edges, FMT, edgesprite, labeler. Layer );
    // Var lan1: labeler = new labeler ("data. Label", Data. edges, FMT );
    VIS. Operators. Add (LAN );

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.