diff --git a/Editor/ChildComponents/SettingsDrawer.cs b/Editor/ChildComponents/SettingsDrawer.cs
index ac798997..4608af10 100644
--- a/Editor/ChildComponents/SettingsDrawer.cs
+++ b/Editor/ChildComponents/SettingsDrawer.cs
@@ -22,6 +22,7 @@ namespace XCharts.Editor
PropertyField(prop, "m_MaxPainter");
PropertyField(prop, "m_BasePainterMaterial");
PropertyField(prop, "m_SeriePainterMaterial");
+ PropertyField(prop, "m_UpperPainterMaterial");
PropertyField(prop, "m_TopPainterMaterial");
PropertyField(prop, "m_LineSmoothStyle");
PropertyField(prop, "m_LineSmoothness");
diff --git a/Editor/ChildComponents/TextPaddingDrawer.cs b/Editor/ChildComponents/TextPaddingDrawer.cs
index 608605d5..0aa6c9f8 100644
--- a/Editor/ChildComponents/TextPaddingDrawer.cs
+++ b/Editor/ChildComponents/TextPaddingDrawer.cs
@@ -4,8 +4,8 @@ using XCharts.Runtime;
namespace XCharts.Editor
{
- [CustomPropertyDrawer(typeof(TextPadding), true)]
- public class TextPaddingDrawer : BasePropertyDrawer
+ [CustomPropertyDrawer(typeof(Padding), true)]
+ public class PaddingDrawer : BasePropertyDrawer
{
public override string ClassName { get { return "Padding"; } }
public override void OnGUI(Rect pos, SerializedProperty prop, GUIContent label)
@@ -22,4 +22,9 @@ namespace XCharts.Editor
}
}
}
+
+ [CustomPropertyDrawer(typeof(TextPadding), true)]
+ public class TextPaddingDrawer : PaddingDrawer
+ {
+ }
}
\ No newline at end of file
diff --git a/Editor/MainComponents/LegendEditor.cs b/Editor/MainComponents/LegendEditor.cs
index 34fc3242..db3d8063 100644
--- a/Editor/MainComponents/LegendEditor.cs
+++ b/Editor/MainComponents/LegendEditor.cs
@@ -20,6 +20,8 @@ namespace XCharts.Editor
PropertyField("m_Formatter");
PropertyField("m_Location");
PropertyField("m_LabelStyle");
+ PropertyField("m_Background");
+ PropertyField("m_Padding");
PropertyListField("m_Icons");
PropertyListField("m_Colors");
PropertyListField("m_Data");
diff --git a/Runtime/Component/Child/Padding.cs b/Runtime/Component/Child/Padding.cs
new file mode 100644
index 00000000..59a6b2bb
--- /dev/null
+++ b/Runtime/Component/Child/Padding.cs
@@ -0,0 +1,79 @@
+using System;
+using UnityEngine;
+
+namespace XCharts.Runtime
+{
+ ///
+ /// padding setting of item or text.
+ /// |边距设置。
+ ///
+ [Serializable]
+ public class Padding : ChildComponent
+ {
+ [SerializeField] protected bool m_Show = true;
+ [SerializeField] protected float m_Top = 2;
+ [SerializeField] protected float m_Right = 4;
+ [SerializeField] protected float m_Left = 4;
+ [SerializeField] protected float m_Bottom = 2;
+
+ public Padding() { }
+
+ public Padding(float top, float right, float bottom, float left)
+ {
+ SetPadding(top, right, bottom, left);
+ }
+
+ public void SetPadding(float top, float right, float bottom, float left)
+ {
+ m_Top = top;;
+ m_Right = right;
+ m_Bottom = bottom;
+ m_Left = left;
+ }
+ ///
+ /// show padding.
+ /// 是否显示。
+ ///
+ public bool show
+ {
+ get { return m_Show; }
+ set { if (PropertyUtil.SetStruct(ref m_Show, value)) SetComponentDirty(); }
+ }
+ ///
+ /// padding of top.
+ /// |顶部间距。
+ ///
+ public float top
+ {
+ get { return m_Top; }
+ set { if (PropertyUtil.SetStruct(ref m_Top, value)) SetComponentDirty(); }
+ }
+ ///
+ /// padding of right.
+ /// |右部间距。
+ ///
+ public float right
+ {
+ get { return m_Right; }
+ set { if (PropertyUtil.SetStruct(ref m_Right, value)) SetComponentDirty(); }
+ }
+ ///
+ /// padding of bottom.
+ /// |底部间距。
+ ///
+ public float bottom
+ {
+ get { return m_Bottom; }
+ set { if (PropertyUtil.SetStruct(ref m_Bottom, value)) SetComponentDirty(); }
+ }
+ ///
+ /// padding of left.
+ /// |左边间距。
+ ///
+ public float left
+ {
+ get { return m_Left; }
+ set { if (PropertyUtil.SetStruct(ref m_Left, value)) SetComponentDirty(); }
+ }
+ }
+}
\ No newline at end of file
diff --git a/Runtime/Component/Child/Padding.cs.meta b/Runtime/Component/Child/Padding.cs.meta
new file mode 100644
index 00000000..9b9851fc
--- /dev/null
+++ b/Runtime/Component/Child/Padding.cs.meta
@@ -0,0 +1,11 @@
+fileFormatVersion: 2
+guid: c4249907274734533ba65edb14987472
+MonoImporter:
+ externalObjects: {}
+ serializedVersion: 2
+ defaultReferences: []
+ executionOrder: 0
+ icon: {instanceID: 0}
+ userData:
+ assetBundleName:
+ assetBundleVariant:
diff --git a/Runtime/Component/Child/TextPadding.cs b/Runtime/Component/Child/TextPadding.cs
index 7031f4f0..bcbeab7f 100644
--- a/Runtime/Component/Child/TextPadding.cs
+++ b/Runtime/Component/Child/TextPadding.cs
@@ -8,72 +8,13 @@ namespace XCharts.Runtime
/// |文本的内边距设置。
///
[Serializable]
- public class TextPadding : ChildComponent
+ public class TextPadding : Padding
{
- [SerializeField] private bool m_Show = true;
- [SerializeField] private float m_Top = 2;
- [SerializeField] private float m_Right = 4;
- [SerializeField] private float m_Left = 4;
- [SerializeField] private float m_Bottom = 2;
-
public TextPadding() { }
public TextPadding(float top, float right, float bottom, float left)
{
SetPadding(top, right, bottom, left);
}
-
- public void SetPadding(float top, float right, float bottom, float left)
- {
- m_Top = top;;
- m_Right = right;
- m_Bottom = bottom;
- m_Left = left;
- }
- ///
- /// show padding.
- /// 是否显示。
- ///
- public bool show
- {
- get { return m_Show; }
- set { if (PropertyUtil.SetStruct(ref m_Show, value)) SetComponentDirty(); }
- }
- ///
- /// padding of top.
- /// |顶部间距。
- ///
- public float top
- {
- get { return m_Top; }
- set { if (PropertyUtil.SetStruct(ref m_Top, value)) SetComponentDirty(); }
- }
- ///
- /// padding of right.
- /// |右部间距。
- ///
- public float right
- {
- get { return m_Right; }
- set { if (PropertyUtil.SetStruct(ref m_Right, value)) SetComponentDirty(); }
- }
- ///
- /// padding of bottom.
- /// |底部间距。
- ///
- public float bottom
- {
- get { return m_Bottom; }
- set { if (PropertyUtil.SetStruct(ref m_Bottom, value)) SetComponentDirty(); }
- }
- ///
- /// padding of left.
- /// |左边间距。
- ///
- public float left
- {
- get { return m_Left; }
- set { if (PropertyUtil.SetStruct(ref m_Left, value)) SetComponentDirty(); }
- }
}
}
\ No newline at end of file
diff --git a/Runtime/Component/Comment/CommentHander.cs b/Runtime/Component/Comment/CommentHander.cs
index f1c93ab3..92c17536 100644
--- a/Runtime/Component/Comment/CommentHander.cs
+++ b/Runtime/Component/Comment/CommentHander.cs
@@ -53,7 +53,7 @@ namespace XCharts.Runtime
}
}
- public override void DrawTop(VertexHelper vh)
+ public override void DrawUpper(VertexHelper vh)
{
for (int i = 0; i < component.items.Count; i++)
{
diff --git a/Runtime/Component/DataZoom/DataZoomHandler.cs b/Runtime/Component/DataZoom/DataZoomHandler.cs
index 6fce8896..aa9e7644 100644
--- a/Runtime/Component/DataZoom/DataZoomHandler.cs
+++ b/Runtime/Component/DataZoom/DataZoomHandler.cs
@@ -19,7 +19,7 @@ namespace XCharts.Runtime
public override void InitComponent()
{
var dataZoom = component;
- dataZoom.painter = chart.m_PainterTop;
+ dataZoom.painter = chart.m_PainterUpper;
dataZoom.refreshComponent = delegate()
{
var dataZoomObject = ChartHelper.AddObject(s_DefaultDataZoom + dataZoom.index, chart.transform,
@@ -62,7 +62,7 @@ namespace XCharts.Runtime
CheckDataZoomLabel(component);
}
- public override void DrawTop(VertexHelper vh)
+ public override void DrawUpper(VertexHelper vh)
{
if (chart == null)
return;
diff --git a/Runtime/Component/Mark/MarkAreaHandler.cs b/Runtime/Component/Mark/MarkAreaHandler.cs
index 9e1345b5..f7939418 100644
--- a/Runtime/Component/Mark/MarkAreaHandler.cs
+++ b/Runtime/Component/Mark/MarkAreaHandler.cs
@@ -39,7 +39,7 @@ namespace XCharts.Runtime
private void InitMarkArea(MarkArea markArea)
{
- markArea.painter = chart.m_PainterTop;
+ markArea.painter = chart.m_PainterUpper;
markArea.refreshComponent = delegate()
{
var label = ChartHelper.AddChartLabel("label", m_MarkLineLabelRoot.transform, markArea.label, chart.theme.axis,
diff --git a/Runtime/Component/Mark/MarkLineHandler.cs b/Runtime/Component/Mark/MarkLineHandler.cs
index 5be581fc..cafbdcf2 100644
--- a/Runtime/Component/Mark/MarkLineHandler.cs
+++ b/Runtime/Component/Mark/MarkLineHandler.cs
@@ -19,7 +19,7 @@ namespace XCharts.Runtime
InitMarkLine(component);
}
- public override void DrawTop(VertexHelper vh)
+ public override void DrawUpper(VertexHelper vh)
{
DrawMarkLine(vh, component);
}
@@ -69,7 +69,7 @@ namespace XCharts.Runtime
private void InitMarkLineLabel(Serie serie, MarkLineData data, Color serieColor)
{
- data.painter = chart.m_PainterTop;
+ data.painter = chart.m_PainterUpper;
data.refreshComponent = delegate()
{
var textName = string.Format("markLine_{0}_{1}", serie.index, data.index);
diff --git a/Runtime/Component/Settings/Settings.cs b/Runtime/Component/Settings/Settings.cs
index 4d8bc804..1ae8d719 100644
--- a/Runtime/Component/Settings/Settings.cs
+++ b/Runtime/Component/Settings/Settings.cs
@@ -15,6 +15,7 @@ namespace XCharts.Runtime
[SerializeField] protected bool m_ReversePainter = false;
[SerializeField] protected Material m_BasePainterMaterial;
[SerializeField] protected Material m_SeriePainterMaterial;
+ [SerializeField] protected Material m_UpperPainterMaterial;
[SerializeField] protected Material m_TopPainterMaterial;
[SerializeField][Range(1, 10)] protected float m_LineSmoothStyle = 3f;
[SerializeField][Range(1f, 20)] protected float m_LineSmoothness = 2f;
@@ -58,7 +59,7 @@ namespace XCharts.Runtime
set { if (PropertyUtil.SetClass(ref m_SeriePainterMaterial, value)) SetComponentDirty(); }
}
///
- /// Top Pointer 材质球,设置后会影响Tooltip等。
+ /// Top Pointer 材质球。
///
public Material topPainterMaterial
{
@@ -66,6 +67,14 @@ namespace XCharts.Runtime
set { if (PropertyUtil.SetClass(ref m_TopPainterMaterial, value)) SetComponentDirty(); }
}
///
+ /// Upper Pointer 材质球。
+ ///
+ public Material upperPainterMaterial
+ {
+ get { return m_UpperPainterMaterial; }
+ set { if (PropertyUtil.SetClass(ref m_UpperPainterMaterial, value)) SetComponentDirty(); }
+ }
+ ///
/// Curve smoothing factor. By adjusting the smoothing coefficient, the curvature of the curve can be changed,
/// and different curves with slightly different appearance can be obtained.
/// |曲线平滑系数。通过调整平滑系数可以改变曲线的曲率,得到外观稍微有变化的不同曲线。
@@ -134,6 +143,7 @@ namespace XCharts.Runtime
m_MaxPainter = settings.maxPainter;
m_BasePainterMaterial = settings.basePainterMaterial;
m_SeriePainterMaterial = settings.seriePainterMaterial;
+ m_UpperPainterMaterial = settings.upperPainterMaterial;
m_TopPainterMaterial = settings.topPainterMaterial;
m_LineSmoothStyle = settings.lineSmoothStyle;
m_LineSmoothness = settings.lineSmoothness;
diff --git a/Runtime/Component/Title/TitleHandler.cs b/Runtime/Component/Title/TitleHandler.cs
index 63e32940..a0437acb 100644
--- a/Runtime/Component/Title/TitleHandler.cs
+++ b/Runtime/Component/Title/TitleHandler.cs
@@ -24,7 +24,7 @@ namespace XCharts.Runtime
var titleObject = ChartHelper.AddObject(objName, chart.transform, anchorMin, anchorMax,
pivot, chart.chartSizeDelta);
title.gameObject = titleObject;
- title.gameObject.transform.SetSiblingIndex(chart.m_PainterTop.transform.GetSiblingIndex() + 1);
+ title.gameObject.transform.SetSiblingIndex(chart.m_PainterUpper.transform.GetSiblingIndex() + 1);
anchorMin = title.location.runtimeAnchorMin;
anchorMax = title.location.runtimeAnchorMax;
pivot = title.location.runtimePivot;
diff --git a/Runtime/Component/Tooltip/TooltipHandler.cs b/Runtime/Component/Tooltip/TooltipHandler.cs
index e55d3670..75722240 100644
--- a/Runtime/Component/Tooltip/TooltipHandler.cs
+++ b/Runtime/Component/Tooltip/TooltipHandler.cs
@@ -26,14 +26,14 @@ namespace XCharts.Runtime
component.view.Update();
}
- public override void DrawTop(VertexHelper vh)
+ public override void DrawUpper(VertexHelper vh)
{
DrawTooltipIndicator(vh, component);
}
private void InitTooltip(Tooltip tooltip)
{
- tooltip.painter = chart.m_PainterTop;
+ tooltip.painter = chart.m_PainterUpper;
tooltip.refreshComponent = delegate()
{
var objName = ChartCached.GetComponentObjectName(tooltip);
diff --git a/Runtime/Coord/Grid/GridCoordHandler.cs b/Runtime/Coord/Grid/GridCoordHandler.cs
index 03dec597..cf37bad7 100644
--- a/Runtime/Coord/Grid/GridCoordHandler.cs
+++ b/Runtime/Coord/Grid/GridCoordHandler.cs
@@ -57,7 +57,7 @@ namespace XCharts.Runtime
DrawCoord(vh, component);
}
}
- public override void DrawTop(VertexHelper vh)
+ public override void DrawUpper(VertexHelper vh)
{
if (SeriesHelper.IsAnyClipSerie(chart.series))
{
diff --git a/Runtime/Coord/Parallel/ParallelCoordHandler.cs b/Runtime/Coord/Parallel/ParallelCoordHandler.cs
index 315e4779..2976b3f1 100644
--- a/Runtime/Coord/Parallel/ParallelCoordHandler.cs
+++ b/Runtime/Coord/Parallel/ParallelCoordHandler.cs
@@ -56,7 +56,7 @@ namespace XCharts.Runtime
DrawCoord(vh);
}
}
- public override void DrawTop(VertexHelper vh)
+ public override void DrawUpper(VertexHelper vh)
{
if (SeriesHelper.IsAnyClipSerie(chart.series))
{
diff --git a/Runtime/Internal/BaseChart.API.cs b/Runtime/Internal/BaseChart.API.cs
index 230af44a..3459b54a 100644
--- a/Runtime/Internal/BaseChart.API.cs
+++ b/Runtime/Internal/BaseChart.API.cs
@@ -84,7 +84,11 @@ namespace XCharts.Runtime
///
public Action onDrawAfterSerie { set { m_OnDrawSerieAfter = value; } }
///
- /// 自定义Top绘制回调。在绘制Tooltip前调用。
+ /// 自定义Upper层绘制回调。在绘制Tooltip前调用。
+ ///
+ public Action onDrawUpper { set { m_OnDrawUpper = value; } }
+ ///
+ /// 自定义Top层绘制回调。在绘制Tooltip前调用。
///
public Action onDrawTop { set { m_OnDrawTop = value; } }
///
@@ -143,6 +147,7 @@ namespace XCharts.Runtime
m_RefreshChart = true;
if (m_Painter) m_Painter.Refresh();
foreach (var painter in m_PainterList) painter.Refresh();
+ if (m_PainterUpper) m_PainterUpper.Refresh();
if (m_PainterTop) m_PainterTop.Refresh();
}
@@ -507,6 +512,19 @@ namespace XCharts.Runtime
}
}
+ ///
+ /// 设置Upper Painter的材质球
+ ///
+ ///
+ public void SetUpperPainterMaterial(Material material)
+ {
+ settings.upperPainterMaterial = material;
+ if (m_PainterUpper != null)
+ {
+ m_PainterUpper.material = material;
+ }
+ }
+
///
/// 设置Top Painter的材质球
///
diff --git a/Runtime/Internal/BaseChart.cs b/Runtime/Internal/BaseChart.cs
index 50b44db5..1be748e8 100644
--- a/Runtime/Internal/BaseChart.cs
+++ b/Runtime/Internal/BaseChart.cs
@@ -81,6 +81,7 @@ namespace XCharts.Runtime
protected Action m_OnInit;
protected Action m_OnUpdate;
protected Action m_OnDrawBase;
+ protected Action m_OnDrawUpper;
protected Action m_OnDrawTop;
protected Action m_OnDrawSerieBefore;
protected Action m_OnDrawSerieAfter;
@@ -96,8 +97,10 @@ namespace XCharts.Runtime
internal bool m_CheckAnimation = false;
internal protected List m_LegendRealShowName = new List();
protected List m_PainterList = new List();
+ internal Painter m_PainterUpper;
internal Painter m_PainterTop;
internal int m_BasePainterVertCount;
+ internal int m_UpperPainterVertCount;
internal int m_TopPainterVertCount;
private ThemeType m_CheckTheme = 0;
@@ -201,6 +204,11 @@ namespace XCharts.Runtime
m_PainterTop.Refresh();
}
+ public void RefreshUpperPainter()
+ {
+ m_PainterUpper.Refresh();
+ }
+
public void RefreshPainter(int index)
{
var painter = GetPainter(index);
@@ -218,7 +226,7 @@ namespace XCharts.Runtime
base.RefreshPainter(painter);
if (painter != null && painter.type == Painter.Type.Serie)
{
- m_PainterTop.Refresh();
+ m_PainterUpper.Refresh();
}
}
@@ -306,6 +314,10 @@ namespace XCharts.Runtime
serie.index = i;
SetPainterActive(i, true);
}
+ if (transform.childCount - 3 != m_PainterTop.transform.GetSiblingIndex())
+ {
+ m_PainterTop.transform.SetSiblingIndex(transform.childCount - 3);
+ }
}
protected override void InitPainter()
@@ -328,6 +340,14 @@ namespace XCharts.Runtime
painter.transform.SetSiblingIndex(index + 1);
m_PainterList.Add(painter);
}
+ m_PainterUpper = ChartHelper.AddPainterObject("painter_u", transform, m_GraphMinAnchor,
+ m_GraphMaxAnchor, m_GraphPivot, sizeDelta, chartHideFlags, 2 + settings.maxPainter);
+ m_PainterUpper.type = Painter.Type.Top;
+ m_PainterUpper.onPopulateMesh = OnDrawPainterUpper;
+ m_PainterUpper.SetActive(true, m_DebugInfo.showAllChartObject);
+ m_PainterUpper.material = settings.topPainterMaterial;
+ m_PainterUpper.transform.SetSiblingIndex(settings.maxPainter + 1);
+
m_PainterTop = ChartHelper.AddPainterObject("painter_t", transform, m_GraphMinAnchor,
m_GraphMaxAnchor, m_GraphPivot, sizeDelta, chartHideFlags, 2 + settings.maxPainter);
m_PainterTop.type = Painter.Type.Top;
@@ -372,6 +392,7 @@ namespace XCharts.Runtime
if (m_Painter == null) return;
m_Painter.CheckRefresh();
foreach (var painter in m_PainterList) painter.CheckRefresh();
+ if (m_PainterUpper != null) m_PainterUpper.CheckRefresh();
if (m_PainterTop != null) m_PainterTop.CheckRefresh();
}
@@ -543,6 +564,7 @@ namespace XCharts.Runtime
var maxPainter = settings.maxPainter;
var maxSeries = m_Series.Count;
var rate = Mathf.CeilToInt(maxSeries * 1.0f / maxPainter);
+ m_PainterUpper.Refresh();
m_PainterTop.Refresh();
m_DebugInfo.refreshCount++;
for (int i = painter.index * rate; i < (painter.index + 1) * rate && i < maxSeries; i++)
@@ -574,6 +596,18 @@ namespace XCharts.Runtime
}
}
+ protected virtual void OnDrawPainterUpper(VertexHelper vh, Painter painter)
+ {
+ vh.Clear();
+ DrawPainterUpper(vh);
+ foreach (var draw in m_ComponentHandlers) draw.DrawUpper(vh);
+ if (m_OnDrawUpper != null)
+ {
+ m_OnDrawUpper(vh);
+ }
+ m_UpperPainterVertCount = vh.currentVertCount;
+ }
+
protected virtual void OnDrawPainterTop(VertexHelper vh, Painter painter)
{
vh.Clear();
@@ -588,6 +622,12 @@ namespace XCharts.Runtime
protected virtual void DrawPainterSerie(VertexHelper vh, Serie serie) { }
+ protected virtual void DrawPainterUpper(VertexHelper vh)
+ {
+ foreach (var handler in m_SerieHandlers)
+ handler.DrawUpper(vh);
+ }
+
protected virtual void DrawPainterTop(VertexHelper vh)
{
foreach (var handler in m_SerieHandlers)
diff --git a/Runtime/Internal/Basic/MainComponent.cs b/Runtime/Internal/Basic/MainComponent.cs
index a0834de1..61159b30 100644
--- a/Runtime/Internal/Basic/MainComponent.cs
+++ b/Runtime/Internal/Basic/MainComponent.cs
@@ -96,6 +96,7 @@ namespace XCharts.Runtime
public virtual void CheckComponent(StringBuilder sb) { }
public virtual void Update() { }
public virtual void DrawBase(VertexHelper vh) { }
+ public virtual void DrawUpper(VertexHelper vh) { }
public virtual void DrawTop(VertexHelper vh) { }
public virtual void OnSerieDataUpdate(int serieIndex) { }
public virtual void OnPointerClick(PointerEventData eventData) { }
diff --git a/Runtime/Internal/Object/LegendItem.cs b/Runtime/Internal/Object/LegendItem.cs
index 9a6f7540..95194bb6 100644
--- a/Runtime/Internal/Object/LegendItem.cs
+++ b/Runtime/Internal/Object/LegendItem.cs
@@ -13,6 +13,7 @@ namespace XCharts.Runtime
private Button m_Button;
private Image m_Icon;
private ChartText m_Text;
+ private Image m_Background;
private Image m_TextBackground;
private RectTransform m_Rect;
private RectTransform m_IconRect;
@@ -53,7 +54,7 @@ namespace XCharts.Runtime
}
else
{
- return 0;
+ return m_Text.GetPreferredHeight();
}
}
}
@@ -64,6 +65,7 @@ namespace XCharts.Runtime
m_Button = obj.GetComponent