-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat/refact: supported customize edge/vertex ui.
- Loading branch information
Showing
16 changed files
with
207 additions
and
75 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// Copyright (c) 2023- All flutter_graph_view authors. All rights reserved. | ||
// | ||
// This source code is licensed under Apache 2.0 License. | ||
|
||
import 'package:flutter/material.dart'; | ||
import 'package:flutter_graph_view/flutter_graph_view.dart'; | ||
|
||
/// The default edge shape impl. | ||
/// | ||
/// 默认使用 直线做边。 | ||
class EdgeLineShape extends EdgeShape { | ||
@override | ||
render(Edge edge, Canvas canvas, Paint paint, List<Paint> paintLayers) { | ||
paint.strokeWidth = edge.isHovered ? 3 : 1; | ||
|
||
var startPoint = Offset.zero; | ||
var endPoint = Offset(len(edge), 0); | ||
canvas.drawLine(startPoint, endPoint, paint); | ||
} | ||
|
||
@override | ||
void setPaint(Edge edge) { | ||
if (isWeaken(edge)) { | ||
edge.cpn!.paint = Paint()..color = Colors.white.withOpacity(0); | ||
} else { | ||
edge.cpn!.paint = Paint()..color = Colors.white; | ||
} | ||
} | ||
|
||
@override | ||
double height(Edge edge) { | ||
return 1.0; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
// Copyright (c) 2023- All flutter_graph_view authors. All rights reserved. | ||
// | ||
// This source code is licensed under Apache 2.0 License. | ||
|
||
import 'dart:ui'; | ||
|
||
import 'package:flutter_graph_view/core/util.dart'; | ||
import 'package:flutter_graph_view/flutter_graph_view.dart'; | ||
|
||
/// Used to customize the edge UI. | ||
/// | ||
/// 用于自定义边的UI | ||
abstract class EdgeShape { | ||
/// render the edge shape to canvas by data. | ||
/// | ||
/// 通过边数据将自定义的图形绘制到画布中。 | ||
render(Edge edge, Canvas canvas, Paint paint, List<Paint> paintLayers); | ||
|
||
/// compute the width of the shape from data, used for overlap and mouse event judgment. | ||
/// | ||
/// 通过数据来计算形状的宽,用于重叠与鼠标事件判断。 | ||
double width(Edge edge) { | ||
return len(edge); | ||
} | ||
|
||
/// compute the height of the shape from data, used for overlap and mouse event judgment. | ||
/// | ||
/// 通过数据计算形状的高,用于重叠与鼠标事件判断。 | ||
double height(Edge edge); | ||
|
||
/// compute the size of the shape from data, used for overlap and mouse event judgment. | ||
/// | ||
/// 通过数据计算形状的尺寸,用于重叠与鼠标事件判断。 | ||
Vector2 size(Edge edge) { | ||
return Vector2(width(edge), height(edge)); | ||
} | ||
|
||
/// update the paint from data. | ||
/// | ||
/// 根据数据更新画笔属性。 | ||
void setPaint(Edge edge); | ||
|
||
/// When some elements are activated and do not contain the current element. | ||
/// | ||
/// 当一些元素被激活且不包含当前元素 | ||
bool isWeaken(Edge edge) { | ||
var graph = edge.cpn!.gameRef.graph; | ||
return graph.hoverVertex != null && | ||
!graph.hoverVertex!.neighborEdges.contains(edge); | ||
} | ||
|
||
/// Compute the line length by two vertex. | ||
/// | ||
/// 通过两个节点的坐标,计算线的长度。 | ||
double len(Edge edge) => | ||
edge.end == null || edge.start.cpn == null || edge.end!.cpn == null | ||
? 10 | ||
: Util.distance(edge.start.cpn!.position, edge.end!.cpn!.position); | ||
|
||
/// Compute the shape angle by two vertex. | ||
/// | ||
/// 通过两个节点的坐标,获取线的旋转角度 | ||
double angle(Edge edge) { | ||
Offset offset = Offset( | ||
(edge.end == null | ||
? edge.start.cpn!.position.x | ||
: edge.end!.cpn!.position.x) - | ||
(edge.start.cpn!.position.x), | ||
(edge.end == null | ||
? edge.start.cpn!.position.y | ||
: edge.end!.cpn!.position.y) - | ||
(edge.start.cpn!.position.y), | ||
); | ||
|
||
return offset.direction; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.