[optimize][painter] add upper and top painter layer

This commit is contained in:
monitor1394
2022-06-24 22:17:01 +08:00
parent 7c07499e44
commit 9a1c76c236
22 changed files with 215 additions and 80 deletions

View File

@@ -0,0 +1,79 @@
using System;
using UnityEngine;
namespace XCharts.Runtime
{
/// <summary>
/// padding setting of item or text.
/// |边距设置。
/// </summary>
[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;
}
/// <summary>
/// show padding.
/// 是否显示。
/// </summary>
public bool show
{
get { return m_Show; }
set { if (PropertyUtil.SetStruct(ref m_Show, value)) SetComponentDirty(); }
}
/// <summary>
/// padding of top.
/// |顶部间距。
/// </summary>
public float top
{
get { return m_Top; }
set { if (PropertyUtil.SetStruct(ref m_Top, value)) SetComponentDirty(); }
}
/// <summary>
/// padding of right.
/// |右部间距。
/// </summary>
public float right
{
get { return m_Right; }
set { if (PropertyUtil.SetStruct(ref m_Right, value)) SetComponentDirty(); }
}
/// <summary>
/// padding of bottom.
/// |底部间距。
/// </summary>
public float bottom
{
get { return m_Bottom; }
set { if (PropertyUtil.SetStruct(ref m_Bottom, value)) SetComponentDirty(); }
}
/// <summary>
/// padding of left.
/// |左边间距。
/// </summary>
public float left
{
get { return m_Left; }
set { if (PropertyUtil.SetStruct(ref m_Left, value)) SetComponentDirty(); }
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: c4249907274734533ba65edb14987472
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -8,72 +8,13 @@ namespace XCharts.Runtime
/// |文本的内边距设置。
/// </summary>
[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;
}
/// <summary>
/// show padding.
/// 是否显示。
/// </summary>
public bool show
{
get { return m_Show; }
set { if (PropertyUtil.SetStruct(ref m_Show, value)) SetComponentDirty(); }
}
/// <summary>
/// padding of top.
/// |顶部间距。
/// </summary>
public float top
{
get { return m_Top; }
set { if (PropertyUtil.SetStruct(ref m_Top, value)) SetComponentDirty(); }
}
/// <summary>
/// padding of right.
/// |右部间距。
/// </summary>
public float right
{
get { return m_Right; }
set { if (PropertyUtil.SetStruct(ref m_Right, value)) SetComponentDirty(); }
}
/// <summary>
/// padding of bottom.
/// |底部间距。
/// </summary>
public float bottom
{
get { return m_Bottom; }
set { if (PropertyUtil.SetStruct(ref m_Bottom, value)) SetComponentDirty(); }
}
/// <summary>
/// padding of left.
/// |左边间距。
/// </summary>
public float left
{
get { return m_Left; }
set { if (PropertyUtil.SetStruct(ref m_Left, value)) SetComponentDirty(); }
}
}
}

View File

@@ -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++)
{

View File

@@ -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;

View File

@@ -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,

View File

@@ -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);

View File

@@ -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(); }
}
/// <summary>
/// Top Pointer 材质球设置后会影响Tooltip等
/// Top Pointer 材质球。
/// </summary>
public Material topPainterMaterial
{
@@ -66,6 +67,14 @@ namespace XCharts.Runtime
set { if (PropertyUtil.SetClass(ref m_TopPainterMaterial, value)) SetComponentDirty(); }
}
/// <summary>
/// Upper Pointer 材质球。
/// </summary>
public Material upperPainterMaterial
{
get { return m_UpperPainterMaterial; }
set { if (PropertyUtil.SetClass(ref m_UpperPainterMaterial, value)) SetComponentDirty(); }
}
/// <summary>
/// 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;

View File

@@ -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;

View File

@@ -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);