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
424 stars 117 forks source link

Feature request: Create graph based on data entries and provide builder argument #11

Closed orestesgaolin closed 3 years ago

orestesgaolin commented 3 years ago

Hi, thanks for building and maintaining such a great package.

I wonder if it would be possible to allow generating a graph based on purely data classes and not widgets.

Here's what I mean. Now nodes need to be created with widgets as their arguments:

final node = Node(
  MyWidget(
    data: data,
  ),
  key: Key(data.id),
);
graph.addNode(node);

What I would love to see is to be able to just provide some data or id:

final node = NodeData(
  id: data.id
);
graph.addNode(node);

And then when creating a GraphView I would be able to provide builder:

GraphView(
  graph: graph,
  algorithm: g.BuchheimWalkerAlgorithm(
    g.BuchheimWalkerConfiguration(),
    g.TreeEdgeRenderer(builder),
  builder: (data){
    // I can decide what widget should be shown here
    return MyWidget(data: data);
  }
),

This would simplify populating graph data and would abstract Flutter/material dependencies

nabil6391 commented 3 years ago

@orestesgaolin its a good idea actually. But if someone wants to place a widget based on position or connections then it might be a bit of a problem. Any suggestions on that?

orestesgaolin commented 3 years ago

Hi there, I started to add this feature on my own. This will take some time to be runnable, but hopefully within few days I should be able to propose some change.

Do you mind if I change the code style a bit to be more aligned with Flutter libraries in general? E.g. file naming, objects instantiation etc.?

nabil6391 commented 3 years ago

I am ok with the changes and welcome PRs, it would be better if you can create one to change the Code Style first. If thats possible

nabil6391 commented 3 years ago

@orestesgaolin is there any time frame you can create the PR if possible

nabil6391 commented 3 years ago

@orestesgaolin I am working on this feature atm, do you think the id should be a ValueKey or a dynamic ?

nabil6391 commented 3 years ago

This has been implemented in version 0.7.0. Have a look