mirror of
https://github.com/XCharts-Team/XCharts.git
synced 2026-05-22 17:00:08 +00:00
增加数据图的折叠和展开支持
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -7,7 +7,7 @@ namespace XCharts.Runtime
|
||||
/// the data struct of graph.
|
||||
/// ||数据结构-图。
|
||||
/// </summary>
|
||||
public class Graph
|
||||
public class GraphData
|
||||
{
|
||||
public bool directed;
|
||||
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, GraphEdge> edgeMap = new Dictionary<string, GraphEdge>();
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -344,10 +364,12 @@ namespace XCharts.Runtime
|
||||
public List<GraphEdge> edges = new List<GraphEdge>();
|
||||
public List<GraphEdge> inEdges = new List<GraphEdge>();
|
||||
public List<GraphEdge> outEdges = new List<GraphEdge>();
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -400,11 +452,12 @@ namespace XCharts.Runtime
|
||||
public GraphNode node1;
|
||||
public GraphNode node2;
|
||||
public double value;
|
||||
public Graph hostGraph;
|
||||
public GraphData hostGraph;
|
||||
|
||||
public List<Vector3> points = new List<Vector3>();
|
||||
public float width;
|
||||
public bool highlight;
|
||||
public bool expand = true;
|
||||
|
||||
public GraphEdge(GraphNode node1, GraphNode node2, double value)
|
||||
{
|
||||
@@ -1,5 +1,5 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1d778205a63524227a09c7e5b0e8736f
|
||||
guid: 9d8951dd10b1247c9baf8515b3a22771
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
@@ -59,16 +59,13 @@ namespace XCharts.Runtime
|
||||
/// Whether the data item is highlighted.
|
||||
/// ||该数据项是否被高亮,一般由鼠标悬停或图例悬停触发高亮。
|
||||
/// </summary>
|
||||
public bool highlight
|
||||
{
|
||||
get { return m_Highligth; }
|
||||
set
|
||||
{
|
||||
m_Highligth = value;
|
||||
}
|
||||
}
|
||||
private bool m_Highligth;
|
||||
public bool highlight;
|
||||
public bool selected;
|
||||
/// <summary>
|
||||
/// the id of the node in the graph.
|
||||
/// ||图中节点的id。
|
||||
/// </summary>
|
||||
public string graphNodeId;
|
||||
public double inTotalValue;
|
||||
public double outTotalValue;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user