From 99b1624b549c8d242c15afc1ab2ec83dd9975f86 Mon Sep 17 00:00:00 2001 From: monitor1394 Date: Wed, 20 Mar 2024 08:31:05 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=95=B0=E6=8D=AE=E5=9B=BE?= =?UTF-8?q?=E7=9A=84=E6=8A=98=E5=8F=A0=E5=92=8C=E5=B1=95=E5=BC=80=E6=94=AF?= =?UTF-8?q?=E6=8C=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Documentation~/en/api.md | 11 ++- Documentation~/zh/api.md | 11 ++- .../Internal/Data/{Graph.cs => GraphData.cs} | 75 ++++++++++++++++--- .../Data/{Graph.cs.meta => GraphData.cs.meta} | 2 +- Runtime/Serie/SerieDataContext.cs | 15 ++-- 5 files changed, 87 insertions(+), 27 deletions(-) rename Runtime/Internal/Data/{Graph.cs => GraphData.cs} (84%) rename Runtime/Internal/Data/{Graph.cs.meta => GraphData.cs.meta} (83%) diff --git a/Documentation~/en/api.md b/Documentation~/en/api.md index e9ee5cd8..4b9da63d 100644 --- a/Documentation~/en/api.md +++ b/Documentation~/en/api.md @@ -80,7 +80,7 @@ slug: /api - [EmphasisStyle](#emphasisstyle) - [EndLabelStyle](#endlabelstyle) - [FormatterHelper](#formatterhelper) -- [Graph](#graph) +- [GraphData](#graphdata) - [GraphEdge](#graphedge) - [GraphNode](#graphnode) - [GridCoord](#gridcoord) @@ -1410,7 +1410,7 @@ Configurations of emphasis state. |TrimAndReplaceLine()||public static string TrimAndReplaceLine(string content)| |TrimAndReplaceLine()||public static string TrimAndReplaceLine(StringBuilder sb)| -## Graph +## GraphData > class in XCharts.Runtime @@ -1424,6 +1424,8 @@ the data struct of graph. |Clear()||public void Clear()| |DeepFirstTraverse()||public void DeepFirstTraverse(GraphNode startNode, System.Action<GraphNode> onTraverse)| |EachNode()||public void EachNode(System.Action<GraphNode> onEach)| +|ExpandAllNodes()||public void ExpandAllNodes(bool flag, int level = -1)| +|ExpandNode()||public void ExpandNode(string nodeId, bool flag)| |GetDepthNodes()||public List<List<GraphNode>> GetDepthNodes()| |GetEdge()||public GraphEdge GetEdge(string nodeId1, string nodeId2)| |GetMaxDepth()||public int GetMaxDepth()| @@ -1433,7 +1435,7 @@ the data struct of graph. |GetNodeDepth()||public int GetNodeDepth(GraphNode node, int recursiveCount = 0)| |GetNodesTotalValue()||public static double GetNodesTotalValue(List<GraphNode> nodes)| |GetRootNodes()||public List<GraphNode> GetRootNodes()| -|Graph()||public Graph(bool directed)| +|GraphData()||public GraphData(bool directed)| |Refresh()||public void Refresh()| ## GraphEdge @@ -1454,7 +1456,10 @@ The node of graph. |public method|since|description| |--|--|--| +|Expand()||public void Expand(bool flag)| |GraphNode()||public GraphNode(string id, string name, int dataIndex)| +|IsAllInEdgesCollapsed()||public bool IsAllInEdgesCollapsed()| +|IsAnyInEdgesExpanded()||public bool IsAnyInEdgesExpanded()| |ToString()||public override string ToString()| ## GridCoord diff --git a/Documentation~/zh/api.md b/Documentation~/zh/api.md index cd862f3d..910ab3d5 100644 --- a/Documentation~/zh/api.md +++ b/Documentation~/zh/api.md @@ -80,7 +80,7 @@ slug: /api - [EmphasisStyle](#emphasisstyle) - [EndLabelStyle](#endlabelstyle) - [FormatterHelper](#formatterhelper) -- [Graph](#graph) +- [GraphData](#graphdata) - [GraphEdge](#graphedge) - [GraphNode](#graphnode) - [GridCoord](#gridcoord) @@ -1410,7 +1410,7 @@ DataZoom 组件 用于区域缩放,从而能自由关注细节的数据信息 |TrimAndReplaceLine()||public static string TrimAndReplaceLine(string content)| |TrimAndReplaceLine()||public static string TrimAndReplaceLine(StringBuilder sb)| -## Graph +## GraphData > class in XCharts.Runtime @@ -1424,6 +1424,8 @@ DataZoom 组件 用于区域缩放,从而能自由关注细节的数据信息 |Clear()||public void Clear()| |DeepFirstTraverse()||public void DeepFirstTraverse(GraphNode startNode, System.Action<GraphNode> onTraverse)| |EachNode()||public void EachNode(System.Action<GraphNode> onEach)| +|ExpandAllNodes()||public void ExpandAllNodes(bool flag, int level = -1)| +|ExpandNode()||public void ExpandNode(string nodeId, bool flag)| |GetDepthNodes()||public List<List<GraphNode>> GetDepthNodes()| |GetEdge()||public GraphEdge GetEdge(string nodeId1, string nodeId2)| |GetMaxDepth()||public int GetMaxDepth()| @@ -1433,7 +1435,7 @@ DataZoom 组件 用于区域缩放,从而能自由关注细节的数据信息 |GetNodeDepth()||public int GetNodeDepth(GraphNode node, int recursiveCount = 0)| |GetNodesTotalValue()||public static double GetNodesTotalValue(List<GraphNode> nodes)| |GetRootNodes()||public List<GraphNode> GetRootNodes()| -|Graph()||public Graph(bool directed)| +|GraphData()||public GraphData(bool directed)| |Refresh()||public void Refresh()| ## GraphEdge @@ -1454,7 +1456,10 @@ DataZoom 组件 用于区域缩放,从而能自由关注细节的数据信息 |API|版本|描述| |--|--|--| +|Expand()||public void Expand(bool flag)| |GraphNode()||public GraphNode(string id, string name, int dataIndex)| +|IsAllInEdgesCollapsed()||public bool IsAllInEdgesCollapsed()| +|IsAnyInEdgesExpanded()||public bool IsAnyInEdgesExpanded()| |ToString()||public override string ToString()| ## GridCoord diff --git a/Runtime/Internal/Data/Graph.cs b/Runtime/Internal/Data/GraphData.cs similarity index 84% rename from Runtime/Internal/Data/Graph.cs rename to Runtime/Internal/Data/GraphData.cs index 496301a3..b7ea07d8 100644 --- a/Runtime/Internal/Data/Graph.cs +++ b/Runtime/Internal/Data/GraphData.cs @@ -7,7 +7,7 @@ namespace XCharts.Runtime /// the data struct of graph. /// ||数据结构-图。 /// - public class Graph + public class GraphData { public bool directed; public List nodes = new List(); @@ -16,7 +16,7 @@ namespace XCharts.Runtime public Dictionary nodeMap = new Dictionary(); public Dictionary edgeMap = new Dictionary(); - public Graph(bool directed) + public GraphData(bool directed) { this.directed = directed; } @@ -108,7 +108,7 @@ namespace XCharts.Runtime // { // if (recursiveCount > 50) // { - // XLog.Error("Graph.GetNodeDeep(): recursiveCount > 50, maybe graph is ring"); + // XLog.Error("GraphData.GetNodeDeep(): recursiveCount > 50, maybe graph is ring"); // return; // } // if (node.inDegree == 0) @@ -129,7 +129,7 @@ namespace XCharts.Runtime { if (recursiveCount > 50) { - XLog.Error("Graph.GetNodeDeep(): recursiveCount > 50, maybe graph is ring"); + XLog.Error("GraphData.GetNodeDeep(): recursiveCount > 50, maybe graph is ring"); return 0; } int depth = 0; @@ -214,27 +214,27 @@ namespace XCharts.Runtime GraphNode node1, node2; if (!nodeMap.TryGetValue(nodeId1, out node1)) { - XLog.Warning("Graph.AddEdge(): " + nodeId1 + " not exist"); + XLog.Warning("GraphData.AddEdge(): " + nodeId1 + " not exist"); return null; } if (!nodeMap.TryGetValue(nodeId2, out node2)) { - XLog.Warning("Graph.AddEdge(): " + nodeId2 + " not exist"); + XLog.Warning("GraphData.AddEdge(): " + nodeId2 + " not exist"); return null; } if (node1 == null) { - XLog.Warning("Graph.AddEdge(): node1 is null"); + XLog.Warning("GraphData.AddEdge(): node1 is null"); return null; } if (node2 == null) { - XLog.Warning("Graph.AddEdge(): node2 is null"); + XLog.Warning("GraphData.AddEdge(): node2 is null"); return null; } if (node1 == node2) { - XLog.Warning("Graph.AddEdge(): node1 == node2"); + XLog.Warning("GraphData.AddEdge(): node1 == node2"); return null; } string edgeKey = nodeId1 + "_" + nodeId2; @@ -331,6 +331,26 @@ namespace XCharts.Runtime } } } + + public void ExpandNode(string nodeId, bool flag) + { + var node = GetNode(nodeId); + if (node != null) + { + node.Expand(flag); + } + } + + public void ExpandAllNodes(bool flag, int level = -1) + { + foreach (var node in nodes) + { + if (level < 0 || node.level == level) + { + node.Expand(flag); + } + } + } } /// @@ -344,10 +364,12 @@ namespace XCharts.Runtime public List edges = new List(); public List inEdges = new List(); public List outEdges = new List(); - public Graph hostGraph; + public GraphData hostGraph; public int dataIndex; public bool visited; public int depth = -1; + public bool expand = true; + public int level = 0; public GraphNode(string id, string name, int dataIndex) { @@ -388,6 +410,36 @@ namespace XCharts.Runtime { return name; } + + public bool IsAllInEdgesCollapsed() + { + if (inEdges.Count == 0) return false; + foreach (var edge in inEdges) + { + if (!edge.expand) return false; + } + return true; + } + + public bool IsAnyInEdgesExpanded() + { + if (inEdges.Count == 0) return true; + foreach (var edge in inEdges) + { + if (edge.expand) return true; + } + return false; + } + + public void Expand(bool flag) + { + if (expand == flag) return; + expand = flag; + foreach (var edge in outEdges) + { + edge.expand = flag; + } + } } /// @@ -400,11 +452,12 @@ namespace XCharts.Runtime public GraphNode node1; public GraphNode node2; public double value; - public Graph hostGraph; + public GraphData hostGraph; public List points = new List(); public float width; public bool highlight; + public bool expand = true; public GraphEdge(GraphNode node1, GraphNode node2, double value) { diff --git a/Runtime/Internal/Data/Graph.cs.meta b/Runtime/Internal/Data/GraphData.cs.meta similarity index 83% rename from Runtime/Internal/Data/Graph.cs.meta rename to Runtime/Internal/Data/GraphData.cs.meta index 67978019..bb2ee871 100644 --- a/Runtime/Internal/Data/Graph.cs.meta +++ b/Runtime/Internal/Data/GraphData.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 1d778205a63524227a09c7e5b0e8736f +guid: 9d8951dd10b1247c9baf8515b3a22771 MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/Runtime/Serie/SerieDataContext.cs b/Runtime/Serie/SerieDataContext.cs index d8a7e114..0e99efa0 100644 --- a/Runtime/Serie/SerieDataContext.cs +++ b/Runtime/Serie/SerieDataContext.cs @@ -59,16 +59,13 @@ namespace XCharts.Runtime /// Whether the data item is highlighted. /// ||该数据项是否被高亮,一般由鼠标悬停或图例悬停触发高亮。 /// - public bool highlight - { - get { return m_Highligth; } - set - { - m_Highligth = value; - } - } - private bool m_Highligth; + public bool highlight; public bool selected; + /// + /// the id of the node in the graph. + /// ||图中节点的id。 + /// + public string graphNodeId; public double inTotalValue; public double outTotalValue;