Skip to content

Commit 0ef767b

Browse files
committed
feats: enable decorator for vertex, custom properties in VertexComponent
dependency: upgrade flame to 1.7.0
1 parent 5452655 commit 0ef767b

13 files changed

+127
-74
lines changed

CHANGELOG.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1+
## 0.0.2
2+
- feat: enable decorator for vertex.
3+
- Remove the breath effect. To use the breath effect, please pass in BreatheDecorator() when creating the GraphAlgorithm object, such as:
4+
```dart
5+
FlutterGraphWidget(
6+
...
7+
algorithm: ForceDirected(BreatheDecorator()),
8+
...
9+
)
10+
```
11+
12+
- feat: adding custom properties to vertex components helps the algorithm create more effects.
13+
<!-- 将对flame的依赖升级到最新版本 -->
14+
- dependency: upgrade flame from 1.6.0 to 1.7.0
15+
16+
117
## 0.0.1+10
218
- feat: support multi line between two vertexes.
319
- enhance: optimized edge experience.

README-CN.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,25 +28,25 @@
2828

2929
![多边节点](https://foruda.gitee.com/images/1675837598136195029/03b27259_1043207.png "屏幕截图")
3030

31-
## Features
31+
## 特性
3232

33-
TODO:
3433
- [x] 数据转换器:用于将业务数据转换成组件可以接收的数据格式
3534
- [x] 节点定位:用于将节点合理排布在界面上
3635
- [x] 随机定位法 (example 中已给出样例).
3736
- [x] 力导向图法,雏形已实现
38-
- [x] 节点碰撞检测
37+
- [x] 支持定位算法装饰器
38+
- [x] 提供呼吸效果的自定义装饰器(可选特性)
3939
- [x] 提供数据面板的嵌入
4040
- [x] 提供样式配置
4141
- [ ] 提供更多交互能力
4242

43-
## Getting started
43+
## 如何开始
4444

4545
```sh
4646
flutter pub add flutter_graph_view
4747
```
4848

49-
## Usage
49+
## 用法
5050

5151
```dart
5252
// Copyright (c) 2023- All flutter_graph_view authors. All rights reserved.
@@ -85,10 +85,10 @@ void main() {
8585
});
8686
}
8787
88-
for (var i = 0; i < 20; i++) {
88+
for (var i = 0; i < 50; i++) {
8989
edges.add({
90-
'srcId': 'node${r.nextInt(vertexes.length)}',
91-
'dstId': 'node${r.nextInt(vertexes.length)}',
90+
'srcId': 'node1',
91+
'dstId': 'node2',
9292
'edgeName': 'edge${r.nextInt(3)}',
9393
'ranking': r.nextInt(DateTime.now().millisecond),
9494
});
@@ -103,7 +103,7 @@ void main() {
103103
home: Scaffold(
104104
body: FlutterGraphWidget(
105105
data: data,
106-
algorithm: ForceDirected(),
106+
algorithm: ForceDirected(BreatheDecorator()),
107107
convertor: MapConvertor(),
108108
options: Options()
109109
..graphStyle = (GraphStyle()

README.md

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
</a>
2323
</p>
2424

25-
Widgets for beautiful graphic data structures, such as force-oriented diagrams. (Under development.)
25+
Widgets for beautiful graphic data structures, such as force-oriented diagrams.
2626

2727
![image](https://user-images.githubusercontent.com/15630211/216155004-0d6dc826-c589-41cf-bf7c-a51685582c05.png)
2828

@@ -32,11 +32,12 @@ https://user-images.githubusercontent.com/15630211/214360687-93a3683c-0935-46bd-
3232

3333
## Features
3434

35-
TODO:
3635
- [x] Data converter: convert business data into graphic view data.
3736
- [x] Algorithm: calculate vertex layout.
3837
- [x] Force directed algorithm.
3938
- [x] Random algorithm (In example folder).
39+
- [x] Support algorithm decorator.
40+
- [x] Breathe decorator (optional).
4041
- [x] Data panel embedding.
4142
- [x] Style configuration.
4243
- [ ] More graphical interactions.
@@ -86,10 +87,10 @@ void main() {
8687
});
8788
}
8889
89-
for (var i = 0; i < 20; i++) {
90+
for (var i = 0; i < 50; i++) {
9091
edges.add({
91-
'srcId': 'node${r.nextInt(vertexes.length)}',
92-
'dstId': 'node${r.nextInt(vertexes.length)}',
92+
'srcId': 'node1',
93+
'dstId': 'node2',
9394
'edgeName': 'edge${r.nextInt(3)}',
9495
'ranking': r.nextInt(DateTime.now().millisecond),
9596
});
@@ -104,7 +105,7 @@ void main() {
104105
home: Scaffold(
105106
body: FlutterGraphWidget(
106107
data: data,
107-
algorithm: ForceDirected(),
108+
algorithm: ForceDirected(BreatheDecorator()),
108109
convertor: MapConvertor(),
109110
options: Options()
110111
..graphStyle = (GraphStyle()

example/lib/main.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ void main() {
5252
home: Scaffold(
5353
body: FlutterGraphWidget(
5454
data: data,
55-
algorithm: ForceDirected(),
55+
algorithm: ForceDirected(BreatheDecorator()),
5656
convertor: MapConvertor(),
5757
options: Options()
5858
..graphStyle = (GraphStyle()

example/pubspec.lock

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -6,65 +6,65 @@ packages:
66
description:
77
name: async
88
sha256: bfe67ef28df125b7dddcea62755991f807aa39a2492a23e1550161692950bbe0
9-
url: "https://pub.dev"
9+
url: "https://pub.flutter-io.cn"
1010
source: hosted
1111
version: "2.10.0"
1212
boolean_selector:
1313
dependency: transitive
1414
description:
1515
name: boolean_selector
1616
sha256: "6cfb5af12253eaf2b368f07bacc5a80d1301a071c73360d746b7f2e32d762c66"
17-
url: "https://pub.dev"
17+
url: "https://pub.flutter-io.cn"
1818
source: hosted
1919
version: "2.1.1"
2020
characters:
2121
dependency: transitive
2222
description:
2323
name: characters
2424
sha256: e6a326c8af69605aec75ed6c187d06b349707a27fbff8222ca9cc2cff167975c
25-
url: "https://pub.dev"
25+
url: "https://pub.flutter-io.cn"
2626
source: hosted
2727
version: "1.2.1"
2828
clock:
2929
dependency: transitive
3030
description:
3131
name: clock
3232
sha256: cb6d7f03e1de671e34607e909a7213e31d7752be4fb66a86d29fe1eb14bfb5cf
33-
url: "https://pub.dev"
33+
url: "https://pub.flutter-io.cn"
3434
source: hosted
3535
version: "1.1.1"
3636
collection:
3737
dependency: transitive
3838
description:
3939
name: collection
4040
sha256: cfc915e6923fe5ce6e153b0723c753045de46de1b4d63771530504004a45fae0
41-
url: "https://pub.dev"
41+
url: "https://pub.flutter-io.cn"
4242
source: hosted
4343
version: "1.17.0"
4444
cupertino_icons:
4545
dependency: "direct main"
4646
description:
4747
name: cupertino_icons
4848
sha256: e35129dc44c9118cee2a5603506d823bab99c68393879edb440e0090d07586be
49-
url: "https://pub.dev"
49+
url: "https://pub.flutter-io.cn"
5050
source: hosted
5151
version: "1.0.5"
5252
fake_async:
5353
dependency: transitive
5454
description:
5555
name: fake_async
5656
sha256: "511392330127add0b769b75a987850d136345d9227c6b94c96a04cf4a391bf78"
57-
url: "https://pub.dev"
57+
url: "https://pub.flutter-io.cn"
5858
source: hosted
5959
version: "1.3.1"
6060
flame:
6161
dependency: transitive
6262
description:
6363
name: flame
64-
sha256: "0c55f8d704f09536125c811a19d9aab7407dce245b2bfb507e84296c1c996202"
65-
url: "https://pub.dev"
64+
sha256: "2e9545698e75534e2bf79d542df604f6fb8de0184825ea5a5e1f781449054d70"
65+
url: "https://pub.flutter-io.cn"
6666
source: hosted
67-
version: "1.6.0"
67+
version: "1.7.0"
6868
flutter:
6969
dependency: "direct main"
7070
description: flutter
@@ -76,13 +76,13 @@ packages:
7676
path: ".."
7777
relative: true
7878
source: path
79-
version: "0.0.1+10"
79+
version: "0.0.2"
8080
flutter_lints:
8181
dependency: "direct dev"
8282
description:
8383
name: flutter_lints
8484
sha256: aeb0b80a8b3709709c9cc496cdc027c5b3216796bc0af0ce1007eaf24464fd4c
85-
url: "https://pub.dev"
85+
url: "https://pub.flutter-io.cn"
8686
source: hosted
8787
version: "2.0.1"
8888
flutter_test:
@@ -95,55 +95,55 @@ packages:
9595
description:
9696
name: js
9797
sha256: "5528c2f391ededb7775ec1daa69e65a2d61276f7552de2b5f7b8d34ee9fd4ab7"
98-
url: "https://pub.dev"
98+
url: "https://pub.flutter-io.cn"
9999
source: hosted
100100
version: "0.6.5"
101101
lints:
102102
dependency: transitive
103103
description:
104104
name: lints
105105
sha256: "5e4a9cd06d447758280a8ac2405101e0e2094d2a1dbdd3756aec3fe7775ba593"
106-
url: "https://pub.dev"
106+
url: "https://pub.flutter-io.cn"
107107
source: hosted
108108
version: "2.0.1"
109109
matcher:
110110
dependency: transitive
111111
description:
112112
name: matcher
113113
sha256: "16db949ceee371e9b99d22f88fa3a73c4e59fd0afed0bd25fc336eb76c198b72"
114-
url: "https://pub.dev"
114+
url: "https://pub.flutter-io.cn"
115115
source: hosted
116116
version: "0.12.13"
117117
material_color_utilities:
118118
dependency: transitive
119119
description:
120120
name: material_color_utilities
121121
sha256: d92141dc6fe1dad30722f9aa826c7fbc896d021d792f80678280601aff8cf724
122-
url: "https://pub.dev"
122+
url: "https://pub.flutter-io.cn"
123123
source: hosted
124124
version: "0.2.0"
125125
meta:
126126
dependency: transitive
127127
description:
128128
name: meta
129129
sha256: "6c268b42ed578a53088d834796959e4a1814b5e9e164f147f580a386e5decf42"
130-
url: "https://pub.dev"
130+
url: "https://pub.flutter-io.cn"
131131
source: hosted
132132
version: "1.8.0"
133133
ordered_set:
134134
dependency: transitive
135135
description:
136136
name: ordered_set
137137
sha256: "74b0454418f58c34c8e527d91fb1ef571297dbcd5d3b4e5f983dc884e39cdf85"
138-
url: "https://pub.dev"
138+
url: "https://pub.flutter-io.cn"
139139
source: hosted
140140
version: "5.0.0"
141141
path:
142142
dependency: transitive
143143
description:
144144
name: path
145145
sha256: db9d4f58c908a4ba5953fcee2ae317c94889433e5024c27ce74a37f94267945b
146-
url: "https://pub.dev"
146+
url: "https://pub.flutter-io.cn"
147147
source: hosted
148148
version: "1.8.2"
149149
sky_engine:
@@ -156,55 +156,55 @@ packages:
156156
description:
157157
name: source_span
158158
sha256: dd904f795d4b4f3b870833847c461801f6750a9fa8e61ea5ac53f9422b31f250
159-
url: "https://pub.dev"
159+
url: "https://pub.flutter-io.cn"
160160
source: hosted
161161
version: "1.9.1"
162162
stack_trace:
163163
dependency: transitive
164164
description:
165165
name: stack_trace
166166
sha256: c3c7d8edb15bee7f0f74debd4b9c5f3c2ea86766fe4178eb2a18eb30a0bdaed5
167-
url: "https://pub.dev"
167+
url: "https://pub.flutter-io.cn"
168168
source: hosted
169169
version: "1.11.0"
170170
stream_channel:
171171
dependency: transitive
172172
description:
173173
name: stream_channel
174174
sha256: "83615bee9045c1d322bbbd1ba209b7a749c2cbcdcb3fdd1df8eb488b3279c1c8"
175-
url: "https://pub.dev"
175+
url: "https://pub.flutter-io.cn"
176176
source: hosted
177177
version: "2.1.1"
178178
string_scanner:
179179
dependency: transitive
180180
description:
181181
name: string_scanner
182182
sha256: "556692adab6cfa87322a115640c11f13cb77b3f076ddcc5d6ae3c20242bedcde"
183-
url: "https://pub.dev"
183+
url: "https://pub.flutter-io.cn"
184184
source: hosted
185185
version: "1.2.0"
186186
term_glyph:
187187
dependency: transitive
188188
description:
189189
name: term_glyph
190190
sha256: a29248a84fbb7c79282b40b8c72a1209db169a2e0542bce341da992fe1bc7e84
191-
url: "https://pub.dev"
191+
url: "https://pub.flutter-io.cn"
192192
source: hosted
193193
version: "1.2.1"
194194
test_api:
195195
dependency: transitive
196196
description:
197197
name: test_api
198198
sha256: ad540f65f92caa91bf21dfc8ffb8c589d6e4dc0c2267818b4cc2792857706206
199-
url: "https://pub.dev"
199+
url: "https://pub.flutter-io.cn"
200200
source: hosted
201201
version: "0.4.16"
202202
vector_math:
203203
dependency: transitive
204204
description:
205205
name: vector_math
206206
sha256: "80b3257d1492ce4d091729e3a67a60407d227c27241d6927be0130c98e741803"
207-
url: "https://pub.dev"
207+
url: "https://pub.flutter-io.cn"
208208
source: hosted
209209
version: "2.1.4"
210210
sdks:
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import 'package:flutter_graph_view/core/graph_algorithm.dart';
2+
import 'package:flutter_graph_view/model/vertex.dart';
3+
import 'package:flutter_graph_view/model/graph.dart';
4+
import 'dart:math' as math;
5+
6+
/// Breathe Decorator
7+
/// 呼吸特效装饰器
8+
class BreatheDecorator extends GraphAlgorithm {
9+
BreatheDecorator([decorate]) : super(decorate);
10+
@override
11+
void onLoad(Vertex v) {
12+
v.cpn?.properties.putIfAbsent('breatheCount', () => 0);
13+
v.cpn?.properties.putIfAbsent('breatheDirect', math.Random().nextBool);
14+
v.cpn?.properties.putIfAbsent('breatheOffsetY', () => 0);
15+
}
16+
17+
setBreatheCount(Vertex v, int value) =>
18+
v.cpn!.properties['breatheCount'] = value;
19+
setBreatheDirect(Vertex v, bool value) =>
20+
v.cpn!.properties['breatheDirect'] = value;
21+
setBreatheOffsetY(Vertex v, int value) =>
22+
v.cpn!.properties['breatheOffsetY'] = value;
23+
24+
@override
25+
void compute(Vertex v, Graph graph) {
26+
if (v.cpn!.properties['breatheCount'] % 150 == 0) {
27+
v.cpn!.properties['breatheDirect'] = !v.cpn!.properties['breatheDirect'];
28+
v.cpn!.properties['breatheOffsetY'] =
29+
(v.cpn!.properties['breatheDirect'] ? 1 : -1) * .1;
30+
}
31+
if (v != graph.hoverVertex) {
32+
v.position.y += v.cpn!.properties['breatheOffsetY'];
33+
}
34+
v.cpn!.properties['breatheCount'] += 1;
35+
}
36+
}

lib/core/algorithm/force_directed.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import 'package:flutter_graph_view/flutter_graph_view.dart';
1313
/// 力导向图布局算法
1414
///
1515
class ForceDirected extends GraphAlgorithm {
16-
ForceDirected([decorate]) : super(decorate);
16+
ForceDirected([decorator]) : super(decorator);
1717

1818
@override
1919
void compute(

0 commit comments

Comments
 (0)