mirror of
https://github.com/XCharts-Team/XCharts.git
synced 2026-05-20 07:20:08 +00:00
3.0
This commit is contained in:
65
Runtime/Component/Comment/Comment.cs
Normal file
65
Runtime/Component/Comment/Comment.cs
Normal file
@@ -0,0 +1,65 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace XCharts.Runtime
|
||||
{
|
||||
/// <summary>
|
||||
/// comment of chart.
|
||||
/// |图表注解组件。
|
||||
/// </summary>
|
||||
[Serializable]
|
||||
[ComponentHandler(typeof(CommentHander), true)]
|
||||
public class Comment : MainComponent
|
||||
{
|
||||
[SerializeField] private bool m_Show = true;
|
||||
[SerializeField] private LabelStyle m_LabelStyle = new LabelStyle();
|
||||
[SerializeField] private CommentMarkStyle m_MarkStyle;
|
||||
[SerializeField] private List<CommentItem> m_Items = new List<CommentItem>() { new CommentItem() };
|
||||
|
||||
/// <summary>
|
||||
/// Set this to false to prevent the comment from showing.
|
||||
/// |是否显示注解组件。
|
||||
/// </summary>
|
||||
public bool show { get { return m_Show; } set { if (PropertyUtil.SetStruct(ref m_Show, value)) SetComponentDirty(); } }
|
||||
public List<CommentItem> items { get { return m_Items; } set { m_Items = value; SetComponentDirty(); } }
|
||||
/// <summary>
|
||||
/// The text style of all comments.
|
||||
/// |所有组件的文本样式。
|
||||
/// </summary>
|
||||
public LabelStyle labelStyle
|
||||
{
|
||||
get { return m_LabelStyle; }
|
||||
set { if (PropertyUtil.SetClass(ref m_LabelStyle, value)) SetComponentDirty(); }
|
||||
}
|
||||
/// <summary>
|
||||
/// The text style of all comments.
|
||||
/// |所有组件的文本样式。
|
||||
/// </summary>
|
||||
public CommentMarkStyle markStyle
|
||||
{
|
||||
get { return m_MarkStyle; }
|
||||
set { if (PropertyUtil.SetClass(ref m_MarkStyle, value)) SetVerticesDirty(); }
|
||||
}
|
||||
|
||||
public LabelStyle GetLabelStyle(int index)
|
||||
{
|
||||
if (index >= 0 && index < items.Count)
|
||||
{
|
||||
var labelStyle = items[index].labelStyle;
|
||||
if (labelStyle.show) return labelStyle;
|
||||
}
|
||||
return m_LabelStyle;
|
||||
}
|
||||
|
||||
public CommentMarkStyle GetMarkStyle(int index)
|
||||
{
|
||||
if (index >= 0 && index < items.Count)
|
||||
{
|
||||
var markStyle = items[index].markStyle;
|
||||
if (markStyle.show) return markStyle;
|
||||
}
|
||||
return m_MarkStyle;
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Runtime/Component/Comment/Comment.cs.meta
Normal file
11
Runtime/Component/Comment/Comment.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ec99dd6b13a3b4e9789d007f23ffa499
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
71
Runtime/Component/Comment/CommentHander.cs
Normal file
71
Runtime/Component/Comment/CommentHander.cs
Normal file
@@ -0,0 +1,71 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using XUGL;
|
||||
|
||||
namespace XCharts.Runtime
|
||||
{
|
||||
[UnityEngine.Scripting.Preserve]
|
||||
internal sealed class CommentHander : MainComponentHandler<Comment>
|
||||
{
|
||||
private static readonly string s_CommentObjectName = "comment";
|
||||
|
||||
public override void InitComponent()
|
||||
{
|
||||
var comment = component;
|
||||
comment.painter = null;
|
||||
comment.refreshComponent = delegate()
|
||||
{
|
||||
var objName = ChartCached.GetComponentObjectName(comment);
|
||||
var commentObj = ChartHelper.AddObject(objName,
|
||||
chart.transform,
|
||||
chart.chartMinAnchor,
|
||||
chart.chartMaxAnchor,
|
||||
chart.chartPivot,
|
||||
chart.chartSizeDelta);
|
||||
|
||||
commentObj.SetActive(comment.show);
|
||||
commentObj.hideFlags = chart.chartHideFlags;
|
||||
ChartHelper.HideAllObject(commentObj);
|
||||
for (int i = 0; i < comment.items.Count; i++)
|
||||
{
|
||||
var item = comment.items[i];
|
||||
var labelStyle = comment.GetLabelStyle(i);
|
||||
var label = ChartHelper.AddChartLabel(s_CommentObjectName + i, commentObj.transform, labelStyle, chart.theme.common,
|
||||
GetContent(item), Color.clear, TextAnchor.MiddleCenter);
|
||||
label.SetActive(comment.show && item.show);
|
||||
label.SetPosition(item.position + labelStyle.offset);
|
||||
}
|
||||
};
|
||||
comment.refreshComponent();
|
||||
}
|
||||
|
||||
private string GetContent(CommentItem item)
|
||||
{
|
||||
if (item.content.IndexOf("{") >= 0)
|
||||
{
|
||||
var content = item.content;
|
||||
FormatterHelper.ReplaceContent(ref content, 0, item.labelStyle.numericFormatter, null, chart);
|
||||
return content;
|
||||
}
|
||||
else
|
||||
{
|
||||
return item.content;
|
||||
}
|
||||
}
|
||||
|
||||
public override void DrawTop(VertexHelper vh)
|
||||
{
|
||||
for (int i = 0; i < component.items.Count; i++)
|
||||
{
|
||||
var item = component.items[i];
|
||||
var markStyle = component.GetMarkStyle(i);
|
||||
if (!markStyle.show) continue;
|
||||
var color = ChartHelper.IsClearColor(markStyle.lineStyle.color) ?
|
||||
chart.theme.axis.splitLineColor :
|
||||
markStyle.lineStyle.color;
|
||||
var width = markStyle.lineStyle.width == 0 ? 1 : markStyle.lineStyle.width;
|
||||
UGL.DrawBorder(vh, item.markRect, width, color);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Runtime/Component/Comment/CommentHander.cs.meta
Normal file
11
Runtime/Component/Comment/CommentHander.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 45362c4eed0e54d2880f2ed359ce9385
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
47
Runtime/Component/Comment/CommentItem.cs
Normal file
47
Runtime/Component/Comment/CommentItem.cs
Normal file
@@ -0,0 +1,47 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
|
||||
namespace XCharts.Runtime
|
||||
{
|
||||
/// <summary>
|
||||
/// comment of chart.
|
||||
/// |注解项。
|
||||
/// </summary>
|
||||
[Serializable]
|
||||
public class CommentItem : ChildComponent
|
||||
{
|
||||
[SerializeField] private bool m_Show = true;
|
||||
[SerializeField] private string m_Content = "comment";
|
||||
[SerializeField] private Vector3 m_Position;
|
||||
[SerializeField] private Rect m_MarkRect;
|
||||
[SerializeField] private CommentMarkStyle m_MarkStyle = new CommentMarkStyle() { show = false };
|
||||
[SerializeField] private LabelStyle m_LabelStyle = new LabelStyle() { show = false };
|
||||
|
||||
/// <summary>
|
||||
/// Set this to false to prevent this comment item from showing.
|
||||
/// |是否显示当前注解项。
|
||||
/// </summary>
|
||||
public bool show { get { return m_Show; } set { if (PropertyUtil.SetStruct(ref m_Show, value)) SetComponentDirty(); } }
|
||||
/// <summary>
|
||||
/// position of comment.
|
||||
/// |注解项的位置坐标。
|
||||
/// </summary>
|
||||
public Vector3 position { get { return m_Position; } set { if (PropertyUtil.SetStruct(ref m_Position, value)) SetComponentDirty(); } }
|
||||
/// <summary>
|
||||
/// content of comment.
|
||||
/// |注解的文本内容。
|
||||
/// </summary>
|
||||
public string content { get { return m_Content; } set { if (PropertyUtil.SetClass(ref m_Content, value)) SetComponentDirty(); } }
|
||||
public Rect markRect { get { return m_MarkRect; } set { if (PropertyUtil.SetStruct(ref m_MarkRect, value)) SetVerticesDirty(); } }
|
||||
public CommentMarkStyle markStyle { get { return m_MarkStyle; } set { if (PropertyUtil.SetClass(ref m_MarkStyle, value)) SetVerticesDirty(); } }
|
||||
/// <summary>
|
||||
/// The text style of all comments.
|
||||
/// |注解项的文本样式。
|
||||
/// </summary>
|
||||
public LabelStyle labelStyle
|
||||
{
|
||||
get { return m_LabelStyle; }
|
||||
set { if (PropertyUtil.SetClass(ref m_LabelStyle, value)) SetComponentDirty(); }
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Runtime/Component/Comment/CommentItem.cs.meta
Normal file
11
Runtime/Component/Comment/CommentItem.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f082815b255e546019b6b43ac20bf4cb
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
23
Runtime/Component/Comment/CommentMarkStyle.cs
Normal file
23
Runtime/Component/Comment/CommentMarkStyle.cs
Normal file
@@ -0,0 +1,23 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
|
||||
namespace XCharts.Runtime
|
||||
{
|
||||
/// <summary>
|
||||
/// comment of chart.
|
||||
/// |注解项。
|
||||
/// </summary>
|
||||
[Serializable]
|
||||
public class CommentMarkStyle : ChildComponent
|
||||
{
|
||||
[SerializeField] private bool m_Show = true;
|
||||
[SerializeField] private LineStyle m_LineStyle;
|
||||
|
||||
/// <summary>
|
||||
/// Set this to false to prevent this comment item from showing.
|
||||
/// |是否显示当前注解项。
|
||||
/// </summary>
|
||||
public bool show { get { return m_Show; } set { if (PropertyUtil.SetStruct(ref m_Show, value)) SetVerticesDirty(); } }
|
||||
public LineStyle lineStyle { get { return m_LineStyle; } set { if (PropertyUtil.SetClass(ref m_LineStyle, value)) SetVerticesDirty(); } }
|
||||
}
|
||||
}
|
||||
11
Runtime/Component/Comment/CommentMarkStyle.cs.meta
Normal file
11
Runtime/Component/Comment/CommentMarkStyle.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 764734b787d72455782bf75bb38e465e
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user