增加数据图的折叠和展开支持

This commit is contained in:
monitor1394
2024-03-20 08:31:05 +08:00
parent 113c3887ae
commit 99b1624b54
5 changed files with 87 additions and 27 deletions

View File

@@ -80,7 +80,7 @@ slug: /api
- [EmphasisStyle](#emphasisstyle) - [EmphasisStyle](#emphasisstyle)
- [EndLabelStyle](#endlabelstyle) - [EndLabelStyle](#endlabelstyle)
- [FormatterHelper](#formatterhelper) - [FormatterHelper](#formatterhelper)
- [Graph](#graph) - [GraphData](#graphdata)
- [GraphEdge](#graphedge) - [GraphEdge](#graphedge)
- [GraphNode](#graphnode) - [GraphNode](#graphnode)
- [GridCoord](#gridcoord) - [GridCoord](#gridcoord)
@@ -1410,7 +1410,7 @@ Configurations of emphasis state.
|TrimAndReplaceLine()||public static string TrimAndReplaceLine(string content)| |TrimAndReplaceLine()||public static string TrimAndReplaceLine(string content)|
|TrimAndReplaceLine()||public static string TrimAndReplaceLine(StringBuilder sb)| |TrimAndReplaceLine()||public static string TrimAndReplaceLine(StringBuilder sb)|
## Graph ## GraphData
> class in XCharts.Runtime > class in XCharts.Runtime
@@ -1424,6 +1424,8 @@ the data struct of graph.
|Clear()||public void Clear()| |Clear()||public void Clear()|
|DeepFirstTraverse()||public void DeepFirstTraverse(GraphNode startNode, System.Action<GraphNode> onTraverse)| |DeepFirstTraverse()||public void DeepFirstTraverse(GraphNode startNode, System.Action<GraphNode> onTraverse)|
|EachNode()||public void EachNode(System.Action<GraphNode> onEach)| |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()| |GetDepthNodes()||public List<List<GraphNode>> GetDepthNodes()|
|GetEdge()||public GraphEdge GetEdge(string nodeId1, string nodeId2)| |GetEdge()||public GraphEdge GetEdge(string nodeId1, string nodeId2)|
|GetMaxDepth()||public int GetMaxDepth()| |GetMaxDepth()||public int GetMaxDepth()|
@@ -1433,7 +1435,7 @@ the data struct of graph.
|GetNodeDepth()||public int GetNodeDepth(GraphNode node, int recursiveCount = 0)| |GetNodeDepth()||public int GetNodeDepth(GraphNode node, int recursiveCount = 0)|
|GetNodesTotalValue()||public static double GetNodesTotalValue(List<GraphNode> nodes)| |GetNodesTotalValue()||public static double GetNodesTotalValue(List<GraphNode> nodes)|
|GetRootNodes()||public List<GraphNode> GetRootNodes()| |GetRootNodes()||public List<GraphNode> GetRootNodes()|
|Graph()||public Graph(bool directed)| |GraphData()||public GraphData(bool directed)|
|Refresh()||public void Refresh()| |Refresh()||public void Refresh()|
## GraphEdge ## GraphEdge
@@ -1454,7 +1456,10 @@ The node of graph.
|public method|since|description| |public method|since|description|
|--|--|--| |--|--|--|
|Expand()||public void Expand(bool flag)|
|GraphNode()||public GraphNode(string id, string name, int dataIndex)| |GraphNode()||public GraphNode(string id, string name, int dataIndex)|
|IsAllInEdgesCollapsed()||public bool IsAllInEdgesCollapsed()|
|IsAnyInEdgesExpanded()||public bool IsAnyInEdgesExpanded()|
|ToString()||public override string ToString()| |ToString()||public override string ToString()|
## GridCoord ## GridCoord

View File

@@ -80,7 +80,7 @@ slug: /api
- [EmphasisStyle](#emphasisstyle) - [EmphasisStyle](#emphasisstyle)
- [EndLabelStyle](#endlabelstyle) - [EndLabelStyle](#endlabelstyle)
- [FormatterHelper](#formatterhelper) - [FormatterHelper](#formatterhelper)
- [Graph](#graph) - [GraphData](#graphdata)
- [GraphEdge](#graphedge) - [GraphEdge](#graphedge)
- [GraphNode](#graphnode) - [GraphNode](#graphnode)
- [GridCoord](#gridcoord) - [GridCoord](#gridcoord)
@@ -1410,7 +1410,7 @@ DataZoom 组件 用于区域缩放,从而能自由关注细节的数据信息
|TrimAndReplaceLine()||public static string TrimAndReplaceLine(string content)| |TrimAndReplaceLine()||public static string TrimAndReplaceLine(string content)|
|TrimAndReplaceLine()||public static string TrimAndReplaceLine(StringBuilder sb)| |TrimAndReplaceLine()||public static string TrimAndReplaceLine(StringBuilder sb)|
## Graph ## GraphData
> class in XCharts.Runtime > class in XCharts.Runtime
@@ -1424,6 +1424,8 @@ DataZoom 组件 用于区域缩放,从而能自由关注细节的数据信息
|Clear()||public void Clear()| |Clear()||public void Clear()|
|DeepFirstTraverse()||public void DeepFirstTraverse(GraphNode startNode, System.Action<GraphNode> onTraverse)| |DeepFirstTraverse()||public void DeepFirstTraverse(GraphNode startNode, System.Action<GraphNode> onTraverse)|
|EachNode()||public void EachNode(System.Action<GraphNode> onEach)| |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()| |GetDepthNodes()||public List<List<GraphNode>> GetDepthNodes()|
|GetEdge()||public GraphEdge GetEdge(string nodeId1, string nodeId2)| |GetEdge()||public GraphEdge GetEdge(string nodeId1, string nodeId2)|
|GetMaxDepth()||public int GetMaxDepth()| |GetMaxDepth()||public int GetMaxDepth()|
@@ -1433,7 +1435,7 @@ DataZoom 组件 用于区域缩放,从而能自由关注细节的数据信息
|GetNodeDepth()||public int GetNodeDepth(GraphNode node, int recursiveCount = 0)| |GetNodeDepth()||public int GetNodeDepth(GraphNode node, int recursiveCount = 0)|
|GetNodesTotalValue()||public static double GetNodesTotalValue(List<GraphNode> nodes)| |GetNodesTotalValue()||public static double GetNodesTotalValue(List<GraphNode> nodes)|
|GetRootNodes()||public List<GraphNode> GetRootNodes()| |GetRootNodes()||public List<GraphNode> GetRootNodes()|
|Graph()||public Graph(bool directed)| |GraphData()||public GraphData(bool directed)|
|Refresh()||public void Refresh()| |Refresh()||public void Refresh()|
## GraphEdge ## GraphEdge
@@ -1454,7 +1456,10 @@ DataZoom 组件 用于区域缩放,从而能自由关注细节的数据信息
|API|版本|描述| |API|版本|描述|
|--|--|--| |--|--|--|
|Expand()||public void Expand(bool flag)|
|GraphNode()||public GraphNode(string id, string name, int dataIndex)| |GraphNode()||public GraphNode(string id, string name, int dataIndex)|
|IsAllInEdgesCollapsed()||public bool IsAllInEdgesCollapsed()|
|IsAnyInEdgesExpanded()||public bool IsAnyInEdgesExpanded()|
|ToString()||public override string ToString()| |ToString()||public override string ToString()|
## GridCoord ## GridCoord

View File

@@ -7,7 +7,7 @@ namespace XCharts.Runtime
/// the data struct of graph. /// the data struct of graph.
/// ||数据结构-图。 /// ||数据结构-图。
/// </summary> /// </summary>
public class Graph public class GraphData
{ {
public bool directed; public bool directed;
public List<GraphNode> nodes = new List<GraphNode>(); public List<GraphNode> nodes = new List<GraphNode>();
@@ -16,7 +16,7 @@ namespace XCharts.Runtime
public Dictionary<string, GraphNode> nodeMap = new Dictionary<string, GraphNode>(); public Dictionary<string, GraphNode> nodeMap = new Dictionary<string, GraphNode>();
public Dictionary<string, GraphEdge> edgeMap = new Dictionary<string, GraphEdge>(); public Dictionary<string, GraphEdge> edgeMap = new Dictionary<string, GraphEdge>();
public Graph(bool directed) public GraphData(bool directed)
{ {
this.directed = directed; this.directed = directed;
} }
@@ -108,7 +108,7 @@ namespace XCharts.Runtime
// { // {
// if (recursiveCount > 50) // if (recursiveCount > 50)
// { // {
// XLog.Error("Graph.GetNodeDeep(): recursiveCount > 50, maybe graph is ring"); // XLog.Error("GraphData.GetNodeDeep(): recursiveCount > 50, maybe graph is ring");
// return; // return;
// } // }
// if (node.inDegree == 0) // if (node.inDegree == 0)
@@ -129,7 +129,7 @@ namespace XCharts.Runtime
{ {
if (recursiveCount > 50) 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; return 0;
} }
int depth = 0; int depth = 0;
@@ -214,27 +214,27 @@ namespace XCharts.Runtime
GraphNode node1, node2; GraphNode node1, node2;
if (!nodeMap.TryGetValue(nodeId1, out node1)) if (!nodeMap.TryGetValue(nodeId1, out node1))
{ {
XLog.Warning("Graph.AddEdge(): " + nodeId1 + " not exist"); XLog.Warning("GraphData.AddEdge(): " + nodeId1 + " not exist");
return null; return null;
} }
if (!nodeMap.TryGetValue(nodeId2, out node2)) if (!nodeMap.TryGetValue(nodeId2, out node2))
{ {
XLog.Warning("Graph.AddEdge(): " + nodeId2 + " not exist"); XLog.Warning("GraphData.AddEdge(): " + nodeId2 + " not exist");
return null; return null;
} }
if (node1 == null) if (node1 == null)
{ {
XLog.Warning("Graph.AddEdge(): node1 is null"); XLog.Warning("GraphData.AddEdge(): node1 is null");
return null; return null;
} }
if (node2 == null) if (node2 == null)
{ {
XLog.Warning("Graph.AddEdge(): node2 is null"); XLog.Warning("GraphData.AddEdge(): node2 is null");
return null; return null;
} }
if (node1 == node2) if (node1 == node2)
{ {
XLog.Warning("Graph.AddEdge(): node1 == node2"); XLog.Warning("GraphData.AddEdge(): node1 == node2");
return null; return null;
} }
string edgeKey = nodeId1 + "_" + nodeId2; 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);
}
}
}
} }
/// <summary> /// <summary>
@@ -344,10 +364,12 @@ namespace XCharts.Runtime
public List<GraphEdge> edges = new List<GraphEdge>(); public List<GraphEdge> edges = new List<GraphEdge>();
public List<GraphEdge> inEdges = new List<GraphEdge>(); public List<GraphEdge> inEdges = new List<GraphEdge>();
public List<GraphEdge> outEdges = new List<GraphEdge>(); public List<GraphEdge> outEdges = new List<GraphEdge>();
public Graph hostGraph; public GraphData hostGraph;
public int dataIndex; public int dataIndex;
public bool visited; public bool visited;
public int depth = -1; public int depth = -1;
public bool expand = true;
public int level = 0;
public GraphNode(string id, string name, int dataIndex) public GraphNode(string id, string name, int dataIndex)
{ {
@@ -388,6 +410,36 @@ namespace XCharts.Runtime
{ {
return name; 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;
}
}
} }
/// <summary> /// <summary>
@@ -400,11 +452,12 @@ namespace XCharts.Runtime
public GraphNode node1; public GraphNode node1;
public GraphNode node2; public GraphNode node2;
public double value; public double value;
public Graph hostGraph; public GraphData hostGraph;
public List<Vector3> points = new List<Vector3>(); public List<Vector3> points = new List<Vector3>();
public float width; public float width;
public bool highlight; public bool highlight;
public bool expand = true;
public GraphEdge(GraphNode node1, GraphNode node2, double value) public GraphEdge(GraphNode node1, GraphNode node2, double value)
{ {

View File

@@ -1,5 +1,5 @@
fileFormatVersion: 2 fileFormatVersion: 2
guid: 1d778205a63524227a09c7e5b0e8736f guid: 9d8951dd10b1247c9baf8515b3a22771
MonoImporter: MonoImporter:
externalObjects: {} externalObjects: {}
serializedVersion: 2 serializedVersion: 2

View File

@@ -59,16 +59,13 @@ namespace XCharts.Runtime
/// Whether the data item is highlighted. /// Whether the data item is highlighted.
/// ||该数据项是否被高亮,一般由鼠标悬停或图例悬停触发高亮。 /// ||该数据项是否被高亮,一般由鼠标悬停或图例悬停触发高亮。
/// </summary> /// </summary>
public bool highlight public bool highlight;
{
get { return m_Highligth; }
set
{
m_Highligth = value;
}
}
private bool m_Highligth;
public bool selected; public bool selected;
/// <summary>
/// the id of the node in the graph.
/// ||图中节点的id。
/// </summary>
public string graphNodeId;
public double inTotalValue; public double inTotalValue;
public double outTotalValue; public double outTotalValue;