Skip to content

Commit

Permalink
Add Interactive Viewer and PathBuilder Func
Browse files Browse the repository at this point in the history
  • Loading branch information
lempiy committed Aug 28, 2020
1 parent 2ee9557 commit 8b9f5d3
Show file tree
Hide file tree
Showing 10 changed files with 161 additions and 230 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,9 @@
## [0.1.1] - July 18, 2020.

* Code style fixes.

## [0.2.0] - August 29, 2020.

* Ability to scale & pan graph through Interactive Widget.
* Removed ScrollDirection enum (replaced ScrollViews with Interactive Widget).
* Added ability to customize path shape with pathBuilder param.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class _MyHomePageState extends State<MyHomePage> {
## Features
* Nodes and edge gesture events.
* Ability provide graph building direction (horizontal or vertical).
* Ability provide scrolling direction (horizontal, vertical, both or none).
* Ability to scale & pan graph through Interactive Widget.
* Ability to provide custom builder to node widget.
* Ability to provide custom paint builder to graph edges.
* Ability to customize arrows.
Expand Down
13 changes: 13 additions & 0 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import 'dart:ui';
import 'dart:math' as math;

import 'package:flutter/material.dart';
import 'package:graphite/core/matrix.dart';
import 'package:graphite/core/typings.dart';
Expand Down Expand Up @@ -129,6 +132,7 @@ class _CustomPageState extends State<CustomPage> {
cellPadding: 14.0,
contactEdgesDistance: 5.0,
orientation: MatrixOrientation.Vertical,
pathBuilder: customEdgePathBuilder,
builder: (ctx, node) {
return Card(
child: Center(
Expand Down Expand Up @@ -184,3 +188,12 @@ final Map<String, WidgetBuilder> routes = <String, WidgetBuilder>{
'/home': (BuildContext context) => BasicPage(),
'/complex': (BuildContext context) => CustomPage(),
};

Path customEdgePathBuilder(List<List<double>> points) {
var path = Path();
path.moveTo(points[0][0], points[0][1]);
points.sublist(1).forEach((p) {
path.lineTo(p[0], p[1]);
});
return path;
}
98 changes: 28 additions & 70 deletions example/pubspec.lock
Original file line number Diff line number Diff line change
@@ -1,20 +1,6 @@
# Generated by pub
# See https://dart.dev/tools/pub/glossary#lockfile
packages:
archive:
dependency: transitive
description:
name: archive
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.13"
args:
dependency: transitive
description:
name: args
url: "https://pub.dartlang.org"
source: hosted
version: "1.6.0"
arrow_path:
dependency: transitive
description:
Expand All @@ -28,49 +14,56 @@ packages:
name: async
url: "https://pub.dartlang.org"
source: hosted
version: "2.4.1"
version: "2.4.2"
boolean_selector:
dependency: transitive
description:
name: boolean_selector
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.0"
charcode:
characters:
dependency: transitive
description:
name: charcode
name: characters
url: "https://pub.dartlang.org"
source: hosted
version: "1.1.3"
collection:
version: "1.0.0"
charcode:
dependency: transitive
description:
name: collection
name: charcode
url: "https://pub.dartlang.org"
source: hosted
version: "1.14.12"
convert:
version: "1.1.3"
clock:
dependency: transitive
description:
name: convert
name: clock
url: "https://pub.dartlang.org"
source: hosted
version: "2.1.1"
crypto:
version: "1.0.1"
collection:
dependency: transitive
description:
name: crypto
name: collection
url: "https://pub.dartlang.org"
source: hosted
version: "2.1.4"
version: "1.14.13"
cupertino_icons:
dependency: "direct main"
description:
name: cupertino_icons
url: "https://pub.dartlang.org"
source: hosted
version: "0.1.3"
fake_async:
dependency: transitive
description:
name: fake_async
url: "https://pub.dartlang.org"
source: hosted
version: "1.1.0"
flutter:
dependency: "direct main"
description: flutter
Expand All @@ -87,21 +80,14 @@ packages:
path: ".."
relative: true
source: path
version: "0.0.1"
image:
dependency: transitive
description:
name: image
url: "https://pub.dartlang.org"
source: hosted
version: "2.1.12"
version: "0.1.1"
matcher:
dependency: transitive
description:
name: matcher
url: "https://pub.dartlang.org"
source: hosted
version: "0.12.6"
version: "0.12.8"
meta:
dependency: transitive
description:
Expand All @@ -115,28 +101,7 @@ packages:
name: path
url: "https://pub.dartlang.org"
source: hosted
version: "1.6.4"
petitparser:
dependency: transitive
description:
name: petitparser
url: "https://pub.dartlang.org"
source: hosted
version: "2.4.0"
quiver:
dependency: transitive
description:
name: quiver
url: "https://pub.dartlang.org"
source: hosted
version: "2.1.3"
rxdart:
dependency: transitive
description:
name: rxdart
url: "https://pub.dartlang.org"
source: hosted
version: "0.23.1"
version: "1.7.0"
sky_engine:
dependency: transitive
description: flutter
Expand All @@ -155,7 +120,7 @@ packages:
name: stack_trace
url: "https://pub.dartlang.org"
source: hosted
version: "1.9.3"
version: "1.9.5"
stream_channel:
dependency: transitive
description:
Expand Down Expand Up @@ -183,34 +148,27 @@ packages:
name: test_api
url: "https://pub.dartlang.org"
source: hosted
version: "0.2.15"
version: "0.2.17"
touchable:
dependency: transitive
description:
name: touchable
url: "https://pub.dartlang.org"
source: hosted
version: "0.1.6"
version: "0.1.8"
typed_data:
dependency: transitive
description:
name: typed_data
url: "https://pub.dartlang.org"
source: hosted
version: "1.1.6"
version: "1.2.0"
vector_math:
dependency: transitive
description:
name: vector_math
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.8"
xml:
dependency: transitive
description:
name: xml
url: "https://pub.dartlang.org"
source: hosted
version: "3.6.1"
sdks:
dart: ">=2.6.0 <3.0.0"
dart: ">=2.9.0-14.0.dev <3.0.0"
65 changes: 13 additions & 52 deletions lib/graphite.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,13 @@ export 'package:graphite/graphite_edges_painter.dart';
export 'package:graphite/graphite_cell.dart';
export 'package:graphite/core/typings.dart';

enum ScrollDirections { none, vertical, horizontal, both }

class DirectGraph extends StatefulWidget {
const DirectGraph(
{@required this.list,
@required this.cellWidth,
@required this.cellPadding,
Key key,
this.scrollDirection = ScrollDirections.both,
this.onEdgeTapDown,
this.edgePaintStyleForTouch,
this.onEdgeTapUp,
Expand Down Expand Up @@ -57,17 +55,21 @@ class DirectGraph extends StatefulWidget {
this.contactEdgesDistance = 5.0,
this.orientation = MatrixOrientation.Horizontal,
this.tipAngle = math.pi * 0.1,
this.tipLength = 10.0})
this.tipLength = 10.0,
this.maxScale = 3.5,
this.minScale = 0.25,
this.pathBuilder})
: super(key: key);

final double cellWidth;
final double cellPadding;
final List<NodeInput> list;
final ScrollDirections scrollDirection;
final double contactEdgesDistance;
final MatrixOrientation orientation;
final double tipLength;
final double tipAngle;
final double maxScale;
final double minScale;

// Node
final NodeCellBuilder builder;
Expand Down Expand Up @@ -96,6 +98,7 @@ class DirectGraph extends StatefulWidget {

// Edge
final EdgePaintBuilder paintBuilder;
final EdgePathBuilder pathBuilder;

final GestureEdgeTapDownCallback onEdgeTapDown;
final PaintingStyle edgePaintStyleForTouch;
Expand Down Expand Up @@ -124,6 +127,7 @@ class DirectGraph extends StatefulWidget {
}

class _DirectGraphState extends State<DirectGraph> {

Graph toGraph(List<NodeInput> list) {
return Graph(list: list);
}
Expand Down Expand Up @@ -171,43 +175,10 @@ class _DirectGraphState extends State<DirectGraph> {
onEdgePanUpdate: widget.onEdgePanUpdate,
onEdgePanDown: widget.onEdgePanDown,
onEdgeSecondaryTapDown: widget.onEdgeSecondaryTapDown,
onEdgeSecondaryTapUp: widget.onEdgeSecondaryTapUp);
}

Widget scrollBoth(BuildContext context, Matrix mtx) {
return NotificationListener<OverscrollIndicatorNotification>(
onNotification: (OverscrollIndicatorNotification overScroll) {
overScroll.disallowGlow();
return false;
},
child: SingleChildScrollView(
scrollDirection: Axis.horizontal,
child: Container(
child: SingleChildScrollView(
scrollDirection: Axis.vertical,
child: getRoot(context, mtx),
),
),
),
);
}

Widget scrollOne(BuildContext context, Matrix mtx, Axis axis) {
return NotificationListener<OverscrollIndicatorNotification>(
onNotification: (OverscrollIndicatorNotification overScroll) {
overScroll.disallowGlow();
return false;
},
child: SingleChildScrollView(
scrollDirection: axis,
child: getRoot(context, mtx),
),
);
}

Widget scrollNone(BuildContext context, Matrix mtx) {
return Container(
child: getRoot(context, mtx),
onEdgeSecondaryTapUp: widget.onEdgeSecondaryTapUp,
minScale: widget.minScale,
maxScale: widget.maxScale,
pathBuilder: widget.pathBuilder,
);
}

Expand All @@ -218,16 +189,6 @@ class _DirectGraphState extends State<DirectGraph> {
if (widget.orientation == MatrixOrientation.Vertical) {
mtx = mtx.rotate();
}
switch (widget.scrollDirection) {
case ScrollDirections.none:
return SafeArea(child: scrollNone(context, mtx));
case ScrollDirections.vertical:
return SafeArea(child: scrollOne(context, mtx, Axis.vertical));
case ScrollDirections.horizontal:
return SafeArea(child: scrollOne(context, mtx, Axis.horizontal));
case ScrollDirections.both:
return SafeArea(child: scrollBoth(context, mtx));
}
return null;
return getRoot(context, mtx);
}
}
Loading

0 comments on commit 8b9f5d3

Please sign in to comment.