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
415 stars 115 forks source link

edit the color of just some nodes, how I can do it? #77

Closed flutter87 closed 1 year ago

flutter87 commented 2 years ago

MY CODE class _TreeViewPageFromJsonState extends State { var json = { 'nodes': [ {'id': 1, 'label': 'circle'}, {'id': 2, 'label': 'ellipse'}, {'id': 3, 'label': 'database'}, ], 'edges': [ {'from': 1, 'to': 2}, {'from': 2, 'to': 3}, {'from': 1, 'to': 3}, ] }; ..... child: InteractiveViewer( .... child: GraphView( graph: graph, algorithm: BuchheimWalkerAlgorithm(builder, TreeEdgeRenderer(builder)), paint: Paint()
builder: (Node node) { var a = node.key!.value as int?; var nodes = json['nodes']!; var nodeValue = nodes.firstWhere((element) => element['id'] == a); return rectangleWidget(nodeValue['label'] as String?); ....

Widget rectangleWidget(String? a) { return Container( child: Text('${a}')), ); }

final Graph graph = Graph()..isTree = true; BuchheimWalkerConfiguration builder = BuchheimWalkerConfiguration();

@override void initState() { var edges = json['edges']!; edges.forEach((element) { var fromNodeId = element['from']; var toNodeId = element['to']; graph.addEdge(Node.Id(fromNodeId), Node.Id(toNodeId)); });

nabil6391 commented 2 years ago

you can pass the color as a parameter to the rectangleWidget

NehaKushwah993 commented 2 years ago

rectangleWidget() is providing the node, you can change it from there.