-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(convert): cache the edge names and vertex tags in graph.
feat: support customize background.
- Loading branch information
Showing
15 changed files
with
181 additions
and
26 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
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,88 @@ | ||
// 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 'dart:math' as math; | ||
|
||
import 'package:flutter_graph_view/flutter_graph_view.dart'; | ||
|
||
/// The graph style configuration. | ||
/// | ||
/// 图的样式配置类。 | ||
class GraphStyle { | ||
/// [tagColor] is prior to [tagColorByIndex]. use [Vertex.tags] to get color in [vertexColors] | ||
/// | ||
/// [tagColor]的优先级比[tagColorByIndex]高。 | ||
/// 在[vertexColors]方法中使用[Vertex.tags]属性获取颜色 | ||
Map<String, Color>? tagColor; | ||
|
||
/// [tagColor] is prior to [tagColorByIndex]. use [Vertex.tags] to get color in [vertexColors] | ||
/// | ||
/// [tagColor]的优先级比[tagColorByIndex]高。 | ||
/// 在[vertexColors]方法中使用[Vertex.tags]属性获取颜色 | ||
late List<Color> tagColorByIndex = []; | ||
|
||
/// set elements color in [graph] | ||
/// | ||
/// 对[graph]中的元素设置颜色 | ||
void graphColor(Graph graph) { | ||
for (var vertex in graph.vertexes) { | ||
vertex.colors = vertexColors(vertex); | ||
} | ||
// TODO set edge color | ||
} | ||
|
||
/// get color list by [vertex]'s `tags`. | ||
/// | ||
/// 通过[vertex]中的`tags`属性获取颜色列表 | ||
List<Color> vertexColors(Vertex vertex) { | ||
var tags = vertex.tags; | ||
var allTags = vertex.cpn!.gameRef.graph.allTags; | ||
|
||
if (tags == null) { | ||
return defaultColor(); | ||
} | ||
List<Color> colors = []; | ||
|
||
for (var tag in tags) { | ||
Color? color; | ||
if (tagColor != null) { | ||
color = tagColor![tag]; | ||
} | ||
if (color == null) { | ||
var idx = allTags.indexOf(tag); | ||
if (idx < tagColorByIndex.length) color = tagColorByIndex[idx]; | ||
} | ||
if (color != null) { | ||
colors.add(color); | ||
} | ||
} | ||
|
||
if (colors.isEmpty) { | ||
return defaultColor(); | ||
} | ||
return colors; | ||
} | ||
|
||
/// when there is not color matched in [tagColor] on [tagColorByIndex], return random color. | ||
/// | ||
/// 当在 [tagColor] 与 [tagColorByIndex] 中匹配不到颜色时,返回随机颜色 | ||
var defaultColor = () { | ||
var r = math.Random(); | ||
return [ | ||
Color.fromRGBO( | ||
r.nextInt(160) + 80, | ||
r.nextInt(160) + 80, | ||
r.nextInt(160) + 80, | ||
1, | ||
), | ||
Color.fromRGBO( | ||
r.nextInt(160) + 80, | ||
r.nextInt(160) + 80, | ||
r.nextInt(160) + 80, | ||
1, | ||
), | ||
]; | ||
}; | ||
} |
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