{"id":29400938,"url":"https://github.com/nabil6391/graphview","last_synced_at":"2025-07-10T15:03:53.346Z","repository":{"id":43732135,"uuid":"286422972","full_name":"nabil6391/graphview","owner":"nabil6391","description":"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.","archived":false,"fork":false,"pushed_at":"2024-04-12T13:07:09.000Z","size":708,"stargazers_count":408,"open_issues_count":36,"forks_count":113,"subscribers_count":11,"default_branch":"master","last_synced_at":"2024-06-19T17:50:59.621Z","etag":null,"topics":["algorithm","cluster","clustering-algorithm","dart","family-tree","flutter","graph","graph-structures","graph-view","graphview","hierarchy","hierarchy-viewer","mindmap","tree","tree-structure","treeview","widget"],"latest_commit_sha":null,"homepage":"","language":"Dart","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/nabil6391.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":null,"patreon":null,"open_collective":null,"ko_fi":null,"tidelift":null,"community_bridge":null,"liberapay":null,"issuehunt":null,"otechie":null,"custom":["https://www.paypal.me/nabil6391"]}},"created_at":"2020-08-10T08:46:32.000Z","updated_at":"2024-05-23T13:58:17.000Z","dependencies_parsed_at":"2022-08-12T10:42:13.995Z","dependency_job_id":"e878efc4-e8f8-470d-84ec-4bfa5cba0264","html_url":"https://github.com/nabil6391/graphview","commit_stats":{"total_commits":164,"total_committers":6,"mean_commits":"27.333333333333332","dds":0.2621951219512195,"last_synced_commit":"5d3f6e8de11bf66005b6fede5be6651983ae7f72"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/nabil6391/graphview","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nabil6391%2Fgraphview","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nabil6391%2Fgraphview/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nabil6391%2Fgraphview/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nabil6391%2Fgraphview/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nabil6391","download_url":"https://codeload.github.com/nabil6391/graphview/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nabil6391%2Fgraphview/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":264594944,"owners_count":23634268,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["algorithm","cluster","clustering-algorithm","dart","family-tree","flutter","graph","graph-structures","graph-view","graphview","hierarchy","hierarchy-viewer","mindmap","tree","tree-structure","treeview","widget"],"created_at":"2025-07-10T15:02:16.145Z","updated_at":"2025-07-10T15:03:53.333Z","avatar_url":"https://github.com/nabil6391.png","language":"Dart","readme":"GraphView\n===========\nGet it from \n[![pub package](https://img.shields.io/pub/v/graphview.svg)](https://pub.dev/packages/graphview)\n[![pub points](https://badges.bar/graphview/pub%20points)](https://pub.dev/packages/graphview/score) \n[![popularity](https://badges.bar/graphview/popularity)](https://pub.dev/packages/graphview/score)\n[![likes](https://badges.bar/graphview/likes)](https://pub.dev/packages/graphview/score) |\n\nFlutter GraphView is used to display data in graph structures. It can display Tree layout, Directed and Layered graph. Useful for Family Tree, Hierarchy View.\n\n![alt Example](https://media.giphy.com/media/Wsd5Uwm72UBZKXb77s/giphy.gif \"Force Directed Graph\")\n![alt Example](https://media.giphy.com/media/jQ7fdMc5HmyQRoikaK/giphy.gif \"Tree\")\n![alt Example](image/LayeredGraph.png \"Layered Graph Example\")\n\nOverview\n========\nThe library is designed to support different graph layouts and currently works excellent with small graphs.\n\nYou can have a look at the flutter web implementation here:\nhttp://graphview.surge.sh/\n\nLayouts\n======\n### Tree\nUses Walker's algorithm with Buchheim's runtime improvements (`BuchheimWalkerAlgorithm` class). Supports different orientations. All you have to do is using the `BuchheimWalkerConfiguration.orientation` with either `ORIENTATION_LEFT_RIGHT`, `ORIENTATION_RIGHT_LEFT`, `ORIENTATION_TOP_BOTTOM` and\n`ORIENTATION_BOTTOM_TOP` (default). Furthermore parameters like sibling-, level-, subtree separation can be set.\n\nUseful for: Family Tree, Hierarchy View, Flutter Widget Tree, \n### Directed graph\nDirected graph drawing by simulating attraction/repulsion forces. For this the algorithm by Fruchterman and Reingold (`FruchtermanReingoldAlgorithm` class) was implemented.\n\nUseful for: Social network, Mind Map, Cluster, Graphs, Intercity Road Network,\n\n### Layered graph\nAlgorithm from Sugiyama et al. for drawing multilayer graphs, taking advantage of the hierarchical structure of the graph (SugiyamaAlgorithm class). You can also set the parameters for node and level separation using the SugiyamaConfiguration. Supports different orientations. All you have to do is using the `SugiyamaConfiguration.orientation` with either `ORIENTATION_LEFT_RIGHT`, `ORIENTATION_RIGHT_LEFT`, `ORIENTATION_TOP_BOTTOM` and `ORIENTATION_BOTTOM_TOP` (default).\n\nUseful for: Hierarchical Graph which it can have weird edges/multiple paths\n\nUsage\n======\n\nCurrently GraphView must be used together with a Zoom Engine like [InteractiveViewer](https://api.flutter.dev/flutter/widgets/InteractiveViewer-class.html). To change the zoom values just use the different attributes described in the InteractiveViewer class.\n\nTo create a graph, we need to instantiate the `Graph` class. Then we need to pass the layout and also optional the edge renderer.\n\n```dart\nvoid main() {\n  runApp(MyApp());\n}\n\nclass MyApp extends StatelessWidget {\n  @override\n  Widget build(BuildContext context) =\u003e MaterialApp(\n        home: TreeViewPage(),\n      );\n}\n\nclass TreeViewPage extends StatefulWidget {\n  @override\n  _TreeViewPageState createState() =\u003e _TreeViewPageState();\n}\n\nclass _TreeViewPageState extends State\u003cTreeViewPage\u003e {\n  @override\n  Widget build(BuildContext context) {\n    return Scaffold(\n        body: Column(\n      mainAxisSize: MainAxisSize.max,\n      children: [\n        Wrap(\n          children: [\n            Container(\n              width: 100,\n              child: TextFormField(\n                initialValue: builder.siblingSeparation.toString(),\n                decoration: InputDecoration(labelText: \"Sibling Separation\"),\n                onChanged: (text) {\n                  builder.siblingSeparation = int.tryParse(text) ?? 100;\n                  this.setState(() {});\n                },\n              ),\n            ),\n            Container(\n              width: 100,\n              child: TextFormField(\n                initialValue: builder.levelSeparation.toString(),\n                decoration: InputDecoration(labelText: \"Level Separation\"),\n                onChanged: (text) {\n                  builder.levelSeparation = int.tryParse(text) ?? 100;\n                  this.setState(() {});\n                },\n              ),\n            ),\n            Container(\n              width: 100,\n              child: TextFormField(\n                initialValue: builder.subtreeSeparation.toString(),\n                decoration: InputDecoration(labelText: \"Subtree separation\"),\n                onChanged: (text) {\n                  builder.subtreeSeparation = int.tryParse(text) ?? 100;\n                  this.setState(() {});\n                },\n              ),\n            ),\n            Container(\n              width: 100,\n              child: TextFormField(\n                initialValue: builder.orientation.toString(),\n                decoration: InputDecoration(labelText: \"Orientation\"),\n                onChanged: (text) {\n                  builder.orientation = int.tryParse(text) ?? 100;\n                  this.setState(() {});\n                },\n              ),\n            ),\n            ElevatedButton(\n              onPressed: () {\n                final node12 = Node.Id(r.nextInt(100));\n                var edge = graph.getNodeAtPosition(r.nextInt(graph.nodeCount()));\n                print(edge);\n                graph.addEdge(edge, node12);\n                setState(() {});\n              },\n              child: Text(\"Add\"),\n            )\n          ],\n        ),\n        Expanded(\n          child: InteractiveViewer(\n              constrained: false,\n              boundaryMargin: EdgeInsets.all(100),\n              minScale: 0.01,\n              maxScale: 5.6,\n              child: GraphView(\n                graph: graph,\n                algorithm: BuchheimWalkerAlgorithm(builder, TreeEdgeRenderer(builder)),\n                paint: Paint()\n                  ..color = Colors.green\n                  ..strokeWidth = 1\n                  ..style = PaintingStyle.stroke,\n                builder: (Node node) {\n                  // I can decide what widget should be shown here based on the id\n                  var a = node.key.value as int;\n                  return rectangleWidget(a);\n                },\n              )),\n        ),\n      ],\n    ));\n  }\n\n  Random r = Random();\n\n  Widget rectangleWidget(int a) {\n    return InkWell(\n      onTap: () {\n        print('clicked');\n      },\n      child: Container(\n          padding: EdgeInsets.all(16),\n          decoration: BoxDecoration(\n            borderRadius: BorderRadius.circular(4),\n            boxShadow: [\n              BoxShadow(color: Colors.blue[100], spreadRadius: 1),\n            ],\n          ),\n          child: Text('Node ${a}')),\n    );\n  }\n\n  final Graph graph = Graph()..isTree = true;\n  BuchheimWalkerConfiguration builder = BuchheimWalkerConfiguration();\n\n  @override\n  void initState() {\n    final node1 = Node.Id(1);\n    final node2 = Node.Id(2);\n    final node3 = Node.Id(3);\n    final node4 = Node.Id(4);\n    final node5 = Node.Id(5);\n    final node6 = Node.Id(6);\n    final node8 = Node.Id(7);\n    final node7 = Node.Id(8);\n    final node9 = Node.Id(9);\n    final node10 = Node.Id(10);  \n    final node11 = Node.Id(11);\n    final node12 = Node.Id(12);\n\n    graph.addEdge(node1, node2);\n    graph.addEdge(node1, node3, paint: Paint()..color = Colors.red);\n    graph.addEdge(node1, node4, paint: Paint()..color = Colors.blue);\n    graph.addEdge(node2, node5);\n    graph.addEdge(node2, node6);\n    graph.addEdge(node6, node7, paint: Paint()..color = Colors.red);\n    graph.addEdge(node6, node8, paint: Paint()..color = Colors.red);\n    graph.addEdge(node4, node9);\n    graph.addEdge(node4, node10, paint: Paint()..color = Colors.black);\n    graph.addEdge(node4, node11, paint: Paint()..color = Colors.red);\n    graph.addEdge(node11, node12);\n\n    builder\n      ..siblingSeparation = (100)\n      ..levelSeparation = (150)\n      ..subtreeSeparation = (150)\n      ..orientation = (BuchheimWalkerConfiguration.ORIENTATION_TOP_BOTTOM);\n  }\n}\n```\n### Using builder mechanism to build Nodes\nYou can use any widget inside the node:\n\n```dart\nNode node = Node.Id(fromNodeId) ;\n\nbuilder: (Node node) {\n                  // I can decide what widget should be shown here based on the id\n                  var a = node.key.value as int;\n                  if(a ==2)\n                    return rectangleWidget(a);\n                  else \n                    return circleWidget(a);\n                },\n```\n\n### Using Paint to color and line thickness\nYou can specify the edge color and thickness by using a custom paint\n\n```dart\n\ngetGraphView() {\n        return GraphView(\n                graph: graph,\n                algorithm: SugiyamaAlgorithm(builder),\n                paint: Paint()..color = Colors.green..strokeWidth = 1..style = PaintingStyle.stroke,\n              );\n}\n```\n\n### Color Edges individually \nAdd an additional parameter paint. Applicable for ArrowEdgeRenderer for now.\n\n```dart\nvar a = Node();\nvar b = Node();\n graph.addEdge(a, b, paint: Paint()..color = Colors.red);\n```\n\n### Add focused Node\nYou can focus on a specific node. This will allow scrolling to that node in the future, but for now , using it we can drag a node with realtime updates in force directed graph\n\n```dart\n onPanUpdate: (details) {\n        var x = details.globalPosition.dx;\n        var y = details.globalPosition.dy;\n        setState(() {\n          builder.setFocusedNode(graph.getNodeAtPosition(i));\n          graph.getNodeAtPosition(i).position = Offset(x,y);\n        });\n      },\n```\n\n### Add drag nodes feature with animation\nThe code is there but not enabled yet due to dart null safety migration being more important\n\n### Extract info from any json to Graph Object\nNow its a bit easy to use Ids to extract info from any json to Graph Object\n\nFor example, if the json is like this:\n```dart\nvar json = {\n   \"nodes\": [\n     {\"id\": 1, \"label\": 'circle'},\n     {\"id\": 2, \"label\": 'ellipse'},\n     {\"id\": 3, \"label\": 'database'},\n     {\"id\": 4, \"label\": 'box'},\n     {\"id\": 5, \"label\": 'diamond'},\n     {\"id\": 6, \"label\": 'dot'},\n     {\"id\": 7, \"label\": 'square'},\n     {\"id\": 8, \"label\": 'triangle'},\n   ],\n   \"edges\": [\n     {\"from\": 1, \"to\": 2},\n     {\"from\": 2, \"to\": 3},\n     {\"from\": 2, \"to\": 4},\n     {\"from\": 2, \"to\": 5},\n     {\"from\": 5, \"to\": 6},\n     {\"from\": 5, \"to\": 7},\n     {\"from\": 6, \"to\": 8}\n   ]\n };\n```\n\nStep 1, add the edges by using ids\n```dart\n  edges.forEach((element) {\n      var fromNodeId = element['from'];\n      var toNodeId = element['to'];\n      graph.addEdge(Node.Id(fromNodeId), Node.Id(toNodeId));\n    });\n```\n\nStep 2: Then using builder and find the nodeValues from the json using id and then set the value of that.\n\n```dart\n builder: (Node node) {\n                  // I can decide what widget should be shown here based on the id\n                  var a = node.key.value as int;\n                  var nodes = json['nodes'];\n                  var nodeValue = nodes.firstWhere((element) =\u003e element['id'] == a);\n                  return rectangleWidget(nodeValue['label'] as String);\n                },\n```\n\n### Using any widget inside the Node (Deprecated)\nYou can use any widget inside the node:\n\n```dart\nNode node = Node(getNodeText);\n\ngetNodeText() {\n    return Container(\n        padding: EdgeInsets.all(16),\n        decoration: BoxDecoration(\n          borderRadius: BorderRadius.circular(4),\n          boxShadow: [\n            BoxShadow(color: Colors.blue[100], spreadRadius: 1),\n          ],\n        ),\n        child: Text(\"Node ${n++}\"));\n  }\n```\nExamples\n========\n#### Rooted Tree\n![alt Example](image/TopDownTree.png \"Tree Example\")\n\n#### Rooted Tree (Bottom to Top)\n![alt Example](image/BottomTopTree.png \"Tree Example\")\n\n#### Rooted Tree (Left to Right)\n![alt Example](image/LeftRightTree.png \"Tree Example\")\n\n#### Rooted Tree (Right to Left)\n![alt Example](image/RightLeftTree.png \"Tree Example\")\n\n#### Directed Graph\n![alt Example](image/Graph.png \"Directed Graph Example\")\n![alt Example](https://media.giphy.com/media/eNuoOOcbvWlRmJjkDZ/giphy.gif \"Force Directed Graph\")\n\n#### Layered Graph\n![alt Example](image/LayeredGraph.png \"Layered Graph Example\")\n\nInspirations\n========\nThis library is basically a dart representation of the excellent Android Library [GraphView](https://github.com/Team-Blox/GraphView) by Team-Blox\n\nI would like to thank them for open sourcing their code for which reason I was able to port their code to dart and use for flutter.\n\nFuture Works\n========\n\n- [x] Add nodeOnTap\n- [x] Add Layered Graph\n- [] Use a builder pattern to draw items on demand.\n- [] Animations\n- [] Dynamic Node Position update for directed graph\n\n\nLicense\n=======\n\nMIT License\n\nCopyright (c) 2020 Nabil Mosharraf\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.","funding_links":["https://www.paypal.me/nabil6391"],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnabil6391%2Fgraphview","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnabil6391%2Fgraphview","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnabil6391%2Fgraphview/lists"}