From a4740b5ffa8dc3c9ed233067fdf6a4c25686b8bf Mon Sep 17 00:00:00 2001 From: CorvusYe Date: Wed, 1 Feb 2023 08:22:20 +0800 Subject: [PATCH] feat: add legend in graph. --- CHANGELOG.md | 4 ++++ lib/core/options/style/graph_style.dart | 21 +++++++++++++-------- 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a1560ef..d280d3b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,10 @@ +## 0.0.1+9 +- feat: create random color for tag. + ## 0.0.1+8 - feat(convert): cache the edge names and vertex tags in graph. - feat: support customize background. +- feat(options style): support assigning colors to vertexes through tags (name or index). ## 0.0.1+7 - feat: supported customize vertex ui. diff --git a/lib/core/options/style/graph_style.dart b/lib/core/options/style/graph_style.dart index bf7cfd1..6a19217 100644 --- a/lib/core/options/style/graph_style.dart +++ b/lib/core/options/style/graph_style.dart @@ -46,14 +46,7 @@ class GraphStyle { List 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]; - } + Color? color = colorByTag(tag, allTags); if (color != null) { colors.add(color); } @@ -65,6 +58,18 @@ class GraphStyle { return colors; } + Color? colorByTag(String tag, List allTags) { + Color? color; + if (tagColor != null) { + color = tagColor![tag]; + } + if (color == null) { + var idx = allTags.indexOf(tag); + if (idx < tagColorByIndex.length) color = tagColorByIndex[idx]; + } + return color; + } + /// when there is not color matched in [tagColor] on [tagColorByIndex], return random color. /// /// 当在 [tagColor] 与 [tagColorByIndex] 中匹配不到颜色时,返回随机颜色