Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add EdgeStyle new param with new features #29

Merged
merged 1 commit into from
Jun 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,3 +63,11 @@
## [1.1.2] - May 12, 2023

* Fixed complexity bug with node relations detection.

## [1.2.0] - Jun 25, 2024

* Added new `EdgeStyle` param with options for edges customization, like border-radius and like style.
* Changed `PaintBuilder` to `EdgeStyleBuilder`, paint selection is now a part of `EdgeStyleBuilder`.
* Changed `PathBuilder` to accept `EdgeStyle style` param as an argument.
* Edges gestures hit-box rework.

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ class _MyHomePageState extends State<MyHomePage> {
* Ability to add overlays.
* Ability to add edge text or `Widget` labels.
* Ability to provide custom paint builder to graph edges.
* Ability to customize arrows.
* Ability to customize arrows and lines.


## License
Expand Down
28 changes: 15 additions & 13 deletions example/lib/custom_edges.dart
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ class CustomEdgesPageState extends State<CustomEdgesPage> {
cellPadding: const EdgeInsets.all(14),
contactEdgesDistance: 5.0,
orientation: MatrixOrientation.Vertical,
pathBuilder: customEdgePathBuilder,
centered: false,
onEdgeTapDown: (details, edge) {
print("${edge.from.id}->${edge.to.id}");
Expand All @@ -77,18 +76,31 @@ class CustomEdgesPageState extends State<CustomEdgesPage> {
),
);
},
paintBuilder: (edge) {
styleBuilder: (edge) {
var p = Paint()
..color = Colors.blueGrey
..style = PaintingStyle.stroke
..strokeCap = StrokeCap.round
..strokeJoin = StrokeJoin.round
..strokeWidth = 2;
LineStyle lineStyle = LineStyle.solid;
switch (edge.from.id) {
case "U":
lineStyle = LineStyle.dotted;
break;
case "C":
lineStyle = LineStyle.dashed;
break;
case "M":
lineStyle = LineStyle.dashDotted;
break;
}
if ((selected[edge.from.id] ?? false) &&
(selected[edge.to.id] ?? false)) {
p.color = Colors.red;
}
return p;
return EdgeStyle(
lineStyle: lineStyle, borderRadius: 40, linePaint: p);
},
onNodeTapDown: (_, node, __) {
_onItemSelected(node.id);
Expand All @@ -99,13 +111,3 @@ class CustomEdgesPageState extends State<CustomEdgesPage> {
);
}
}

Path customEdgePathBuilder(NodeInput from, NodeInput to,
List<List<double>> points, EdgeArrowType arrowType) {
var path = Path();
path.moveTo(points[0][0], points[0][1]);
points.sublist(1).forEach((p) {
path.lineTo(p[0], p[1]);
});
return path;
}
13 changes: 7 additions & 6 deletions example/lib/digimon.dart
Original file line number Diff line number Diff line change
Expand Up @@ -229,11 +229,11 @@ class DigimonPageState extends State<DigimonPage>
children: [
Text(
_currentNodeInfo!.data.title,
style: Theme.of(context).textTheme.headline6,
style: Theme.of(context).textTheme.titleSmall,
),
Text(
"Level: ${_currentNodeInfo!.data.level}",
style: Theme.of(context).textTheme.subtitle2,
style: Theme.of(context).textTheme.titleMedium,
),
],
),
Expand Down Expand Up @@ -278,16 +278,17 @@ class DigimonPageState extends State<DigimonPage>
child: DirectGraph(
list: imagePreset,
defaultCellSize: const Size(100.0, 100.0),
cellPadding: const EdgeInsets.symmetric(horizontal: 25, vertical: 5),
cellPadding:
const EdgeInsets.symmetric(horizontal: 25, vertical: 5),
contactEdgesDistance: 5.0,
orientation: MatrixOrientation.Horizontal,
clipBehavior: Clip.none,
centered: true,
minScale: .1,
maxScale: 3,
overlayBuilder:
(BuildContext context, List<NodeInput> nodes, List<Edge> edges) =>
_buildOverlay(context, nodes, edges),
overlayBuilder: (BuildContext context, List<NodeInput> nodes,
List<Edge> edges) =>
_buildOverlay(context, nodes, edges),
onCanvasTap: _onCanvasTap,
onNodeTapUp: _onNodeTap,
nodeBuilder: (BuildContext context, NodeInput node) => FittedBox(
Expand Down
34 changes: 17 additions & 17 deletions example/lib/flowchart.dart
Original file line number Diff line number Diff line change
Expand Up @@ -75,18 +75,18 @@ class FlowchartPageState extends State<FlowchartPage> {
constraints: BoxConstraints(minWidth: screenSize.width),
child: Center(
child: DirectGraph(
list: list,
defaultCellSize: const Size(250.0, 100.0),
cellPadding:
const EdgeInsets.symmetric(vertical: 30, horizontal: 5),
contactEdgesDistance: 0,
orientation: MatrixOrientation.Vertical,
nodeBuilder: (BuildContext context, NodeInput node) => Padding(
padding: const EdgeInsets.all(5), child: _buildNode(node)),
centered: true,
minScale: .1,
maxScale: 1,
),
list: list,
defaultCellSize: const Size(250.0, 100.0),
cellPadding:
const EdgeInsets.symmetric(vertical: 30, horizontal: 5),
contactEdgesDistance: 0,
orientation: MatrixOrientation.Vertical,
nodeBuilder: (BuildContext context, NodeInput node) => Padding(
padding: const EdgeInsets.all(5), child: _buildNode(node)),
centered: true,
minScale: .1,
maxScale: 1,
),
),
),
),
Expand All @@ -113,7 +113,7 @@ class Start extends StatelessWidget {
child: Center(
child: Text(
data.text,
style: Theme.of(context).textTheme.subtitle2,
style: Theme.of(context).textTheme.titleMedium,
),
),
);
Expand All @@ -138,7 +138,7 @@ class Document extends StatelessWidget {
child: Center(
child: Text(
data.text,
style: Theme.of(context).textTheme.subtitle2,
style: Theme.of(context).textTheme.titleMedium,
),
),
);
Expand All @@ -163,7 +163,7 @@ class Process extends StatelessWidget {
child: Center(
child: Text(
data.text,
style: Theme.of(context).textTheme.subtitle2,
style: Theme.of(context).textTheme.titleMedium,
),
),
);
Expand Down Expand Up @@ -198,7 +198,7 @@ class Decision extends StatelessWidget {
child: Center(
child: Text(
data.text,
style: Theme.of(context).textTheme.subtitle2,
style: Theme.of(context).textTheme.titleMedium,
),
),
)
Expand All @@ -225,7 +225,7 @@ class End extends StatelessWidget {
child: Center(
child: Text(
data.text,
style: Theme.of(context).textTheme.subtitle2,
style: Theme.of(context).textTheme.titleMedium,
),
),
);
Expand Down
12 changes: 7 additions & 5 deletions example/lib/labels.dart
Original file line number Diff line number Diff line change
Expand Up @@ -64,18 +64,20 @@ class LabelsPageState extends State<LabelsPage> {
child: Text(
style: Theme.of(context)
.textTheme
.bodyText2!
.bodyMedium!
.copyWith(
backgroundColor: Theme.of(context)
.backgroundColor),
.colorScheme
.surface),
"${edge.from.id}=>${edge.to.id}"))
: Text(
style: Theme.of(context)
.textTheme
.bodyText2!
.bodyMedium!
.copyWith(
backgroundColor:
Theme.of(context).backgroundColor),
backgroundColor: Theme.of(context)
.colorScheme
.surface),
"${edge.from.id}=>${edge.to.id}"),
)),
centered: _isCentered,
Expand Down
5 changes: 3 additions & 2 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,9 @@ class _MyAppState extends State<MyApp> {
return MaterialApp(
title: 'Flutter Graphite',
theme: ThemeData(
primarySwatch: Colors.teal,
backgroundColor: Colors.white,
colorScheme: ColorScheme.fromSwatch(
primarySwatch: Colors.teal, backgroundColor: Colors.white)
.copyWith(surface: Colors.white),
),
home: FlowchartPage(bottomBar: _buildBottomBar),
routes: <String, WidgetBuilder>{
Expand Down
11 changes: 6 additions & 5 deletions example/macos/Runner.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
archiveVersion = 1;
classes = {
};
objectVersion = 51;
objectVersion = 54;
objects = {

/* Begin PBXAggregateTarget section */
Expand Down Expand Up @@ -182,7 +182,7 @@
isa = PBXProject;
attributes = {
LastSwiftUpdateCheck = 0920;
LastUpgradeCheck = 1300;
LastUpgradeCheck = 1510;
ORGANIZATIONNAME = "";
TargetAttributes = {
33CC10EC2044A3C60003C045 = {
Expand Down Expand Up @@ -235,6 +235,7 @@
/* Begin PBXShellScriptBuildPhase section */
3399D490228B24CF009A79C7 /* ShellScript */ = {
isa = PBXShellScriptBuildPhase;
alwaysOutOfDate = 1;
buildActionMask = 2147483647;
files = (
);
Expand Down Expand Up @@ -344,7 +345,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
MACOSX_DEPLOYMENT_TARGET = 10.11;
MACOSX_DEPLOYMENT_TARGET = 10.14;
MTL_ENABLE_DEBUG_INFO = NO;
SDKROOT = macosx;
SWIFT_COMPILATION_MODE = wholemodule;
Expand Down Expand Up @@ -423,7 +424,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
MACOSX_DEPLOYMENT_TARGET = 10.11;
MACOSX_DEPLOYMENT_TARGET = 10.14;
MTL_ENABLE_DEBUG_INFO = YES;
ONLY_ACTIVE_ARCH = YES;
SDKROOT = macosx;
Expand Down Expand Up @@ -470,7 +471,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
MACOSX_DEPLOYMENT_TARGET = 10.11;
MACOSX_DEPLOYMENT_TARGET = 10.14;
MTL_ENABLE_DEBUG_INFO = NO;
SDKROOT = macosx;
SWIFT_COMPILATION_MODE = wholemodule;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1300"
LastUpgradeVersion = "1510"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
Loading
Loading