riedev_graph 0.1.1

A graph library #

This repository includes a graph data structure and some basic graph algorithms like depth and breath search.


//      1
//    /   \ 
//   2     3
//  / \   / \
// 4   5 6   7

var g = Graph<int, Edge<int>>(false/*No double edges between two nodes.*/);

g.addEdges([Edge(1, 2), 
            Edge(1, 3), 
            Edge(2, 4), 
            Edge(2, 5), 
            Edge(3, 6), 
            Edge(3, 7)]);

To export the graph you can use the class DotFile with a fluent interface. See the example below.

var dotFile = DotFile<int, Edge<int>>();
  
dotFile.addGraph(g, graphName: "BinaryGraph")
  .setFileName("binaryGraph.dot")
  .setNodeStyle(node: 1)
    .setColor("#328fa8")
    .setFillColor("#eb8934")
    .setShape(NodeShape.diamond)
    .setLabel((n, idx) => "Node: $idx")
    .apply()
  .setEdgeStyle()
    .setColor("#328fa8")
    .setShape(EdgeShape.dashed)
    .setLabel((e, sourceIdx, targetIdx) => "Edge: $sourceIdx -> $targetIdx")
    .apply()
  .export();

These example will create a binaryGraph.dot file. You can convert this file to a svg. Install Graphviz with brew install graphviz and use the command dot -Tsvg binaryGraph.dot -o outfile.svg

<br/><br/> <br/><br/>

Enjoy it 😃

v0.1.0 #

  • Add Graph class
  • Add DotFile class for export graph data structure as dot file
  • Add pre depth, post depth, breath search algorithms

v0.1.1 #

  • Add analysis_options.yaml file
  • Use dart doc comments
  • Move subGraph method from Graph class to createNewGraph.dart file

example/example.dart

import 'package:riedev_graph/dotFile.dart';
import 'package:riedev_graph/graph.dart';

void ExportGraphToDotFile() {

  var g = CreateBinaryGraph();
  var dotFile = DotFile<int, Edge<int>>();

  dotFile.addGraph(g, graphName: "BinaryGraph")
    .setFileName("binaryGraph.dot")
    .setNodeStyle()
      .setColor("#328fa8")
      .setFillColor("#eb8934")
      .setShape(NodeShape.diamond)
      .setLabel((n, idx) => "Node: $idx")
      .apply()
    .setEdgeStyle()
      .setColor("#328fa8")
      .setShape(EdgeShape.dashed)
      .setLabel((e, sourceIdx, targetIdx) => "Edge: $sourceIdx -> $targetIdx")
      .apply()
    .export();
}

/*
      1
    /   \ 
   2     3
  / \   / \
 4   5 6   7
*/
Graph<int, Edge<int>> CreateBinaryGraph() {
  var g = Graph<int, Edge<int>>(false/*No double edges between two nodes.*/);

  g.addEdges(
      [Edge(1, 2), Edge(1, 3), Edge(2, 4), Edge(2, 5), Edge(3, 6), Edge(3, 7)]);
  
  return g;
}

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  riedev_graph: ^0.1.1

2. Install it

You can install packages from the command line:

with pub:


$ pub get

with Flutter:


$ flutter pub get

Alternatively, your editor might support pub get or flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:riedev_graph/dotFile.dart';
import 'package:riedev_graph/graph.dart';
import 'package:riedev_graph/traversal/breathSearch.dart';
import 'package:riedev_graph/traversal/createNewGraph.dart';
import 'package:riedev_graph/traversal/dependencySearch.dart';
import 'package:riedev_graph/traversal/depthSearch.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
0
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
50
Learn more about scoring.

We analyzed this package on Aug 21, 2019, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.4.0
  • pana: 0.12.19

Platforms

Detected platforms: Flutter, other

Platform components identified in package: io.

Health suggestions

Format lib/graph.dart.

Run dartfmt to format lib/graph.dart.

Format lib/traversal/breathSearch.dart.

Run dartfmt to format lib/traversal/breathSearch.dart.

Format lib/traversal/dependencySearch.dart.

Run dartfmt to format lib/traversal/dependencySearch.dart.

Format lib/traversal/depthSearch.dart.

Run dartfmt to format lib/traversal/depthSearch.dart.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.0.0 <3.0.0
Dev dependencies
pedantic ^1.8.0
test ^1.5.3