nabil6391 / graphview

Flutter GraphView is used to display data in graph structures. It can display Tree layout, Directed and Layered graph. Useful for Family Tree, Hierarchy View.
MIT License
420 stars 114 forks source link

Do not accept Strings as keys for nodes and edges #44

Closed bubnenkoff closed 2 years ago

bubnenkoff commented 3 years ago

My data is not int-based. Because some of real data have leading zero. The graphview crush on next data:

    var json = {
      "nodes": [
        {"id": "01", "label": 'circle'},
        {"id": "02", "label": 'ellipse'},
        {"id": "03", "label": 'database'},
        {"id": "04", "label": 'box'},
        {"id": "05", "label": 'diamond'},
        {"id": "06", "label": 'dot'},
        {"id": "07", "label": 'square'},
        {"id": "08", "label": 'triangle'},
      ],
      "edges": [
        {"from": "01", "to": "02"},
        {"from": "02", "to": "03"},
        {"from": "02", "to": "04"},
        {"from": "02", "to": "05"},
        {"from": "05", "to": "06"},
        {"from": "05", "to": "07"},
        {"from": "06", "to": "08"}
      ]
    };

error:

    The following TypeErrorImpl was thrown building GraphView$(dirty, state: _GraphViewState#a4f6c):
Expected a value of type 'int', but got one of type 'String'

I tried change to:

var a = node.key!.value.toString();

But got error:

Node{position: Offset(0.0, 0.0), key: [<1>], _size: Size(77.0, 48.0)} is not connected to primary ancestor
Node{position: Offset(0.0, 0.0), key: [<2>], _size: Size(77.0, 48.0)} is not connected to primary ancestor
nabil6391 commented 3 years ago

Hm, I might have to give ability to create keys using strings.

nabil6391 commented 2 years ago

This is now released in 1.0.0 . Have a look

RottenSchnitzel commented 1 year ago

Is there anything required to do that? I get a type 'String' is not a subtype of type 'int?' in type cast error.

The function looks like this:

@override
void initState() {
  final node0 = Node.Id("0");
  final node1 = Node.Id("1");
  graph.addEdge(node0, node1);
  builder
    ..siblingSeparation = (10)
    ..levelSeparation = (50)
    ..subtreeSeparation = (100)
    ..orientation = (BuchheimWalkerConfiguration.ORIENTATION_LEFT_RIGHT);
}