graph_explorer 1.0.0 copy "graph_explorer: ^1.0.0" to clipboard
graph_explorer: ^1.0.0 copied to clipboard

A versatile library for generating and analyzing graphs with support for JSON and ASCIIArtTree.

graph_explorer #

pub package Null Safety Codecov Dart CI GitHub Tag New Commits Last Commits Pull Requests Code size License

A versatile library for generating and analyzing graphs with support for JSON and ASCIIArtTree.

Usage #

import 'dart:convert';
import 'package:graph_explorer/graph_explorer.dart';

void main() async {
  var graph = Graph<String>();

  graph.node('a').getOrAddOutput('b')
    ..addOutput('c')
    ..addOutput('d');

  graph.node('c').addOutput('f');
  graph.node('d').getOrAddOutput('e').addOutput('f');

  var result = await graph.scanPathsFrom('a', 'f', findAll: true);

  print("Paths from `a` to `f`:");
  for (var p in result.paths) {
    var lStr = p.toListOfString();
    print('- $lStr');
  }

  var shortest = result.paths.shortestPaths().toListOfStringPaths();
  print('\nShortest paths:');
  for (var p in shortest) {
    print('- $p');
  }

  var tree = graph.toTree();

  print('\nGraph to Tree:');
  print(_encodeJsonPretty(tree));

  var asciiArtTree = graph.toASCIIArtTree();
  print('\nGraph to ASCII Art Tree:');
  print(asciiArtTree.generate());
}

String _encodeJsonPretty(dynamic json) =>
    JsonEncoder.withIndent('  ').convert(json);

Output:

Paths from `a` to `f`:
- [a, b, c, f]
- [a, b, d, e, f]

Shortest paths:
- [a, b, c, f]

Graph to Tree:
{
  "a": {
    "b": {
      "c": {
        "f": {}
      },
      "d": {
        "e": {
          "f": "f"
        }
      }
    }
  }
}

Graph to ASCII Art Tree:
a
└─┬─ b
  ├─┬─ c
  │ └──> f
  └─┬─ d
    └─┬─ e
      └──> f ººº

Features and bugs #

Please file feature requests and bugs at the issue tracker.

Author #

Graciliano M. Passos: gmpassos@GitHub.

Don't be shy, show some love, and become our GitHub Sponsor. Your support means the world to us, and it keeps the code caffeinated! ☕✨

Thanks a million! 🚀😄

License #

Dart free & open-source license.

2
likes
0
pub points
51%
popularity

Publisher

unverified uploader

A versatile library for generating and analyzing graphs with support for JSON and ASCIIArtTree.

Repository (GitHub)
View/report issues

License

unknown (LICENSE)

Dependencies

ascii_art_tree, collection

More

Packages that depend on graph_explorer