mirror of
https://github.com/XCharts-Team/XCharts.git
synced 2026-05-24 18:00:26 +00:00
[optimize][painter] add upper and top painter layer
This commit is contained in:
@@ -84,7 +84,11 @@ namespace XCharts.Runtime
|
||||
/// </summary>
|
||||
public Action<VertexHelper, Serie> onDrawAfterSerie { set { m_OnDrawSerieAfter = value; } }
|
||||
/// <summary>
|
||||
/// 自定义Top绘制回调。在绘制Tooltip前调用。
|
||||
/// 自定义Upper层绘制回调。在绘制Tooltip前调用。
|
||||
/// </summary>
|
||||
public Action<VertexHelper> onDrawUpper { set { m_OnDrawUpper = value; } }
|
||||
/// <summary>
|
||||
/// 自定义Top层绘制回调。在绘制Tooltip前调用。
|
||||
/// </summary>
|
||||
public Action<VertexHelper> onDrawTop { set { m_OnDrawTop = value; } }
|
||||
/// <summary>
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 设置Upper Painter的材质球
|
||||
/// </summary>
|
||||
/// <param name="material"></param>
|
||||
public void SetUpperPainterMaterial(Material material)
|
||||
{
|
||||
settings.upperPainterMaterial = material;
|
||||
if (m_PainterUpper != null)
|
||||
{
|
||||
m_PainterUpper.material = material;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 设置Top Painter的材质球
|
||||
/// </summary>
|
||||
|
||||
@@ -81,6 +81,7 @@ namespace XCharts.Runtime
|
||||
protected Action m_OnInit;
|
||||
protected Action m_OnUpdate;
|
||||
protected Action<VertexHelper> m_OnDrawBase;
|
||||
protected Action<VertexHelper> m_OnDrawUpper;
|
||||
protected Action<VertexHelper> m_OnDrawTop;
|
||||
protected Action<VertexHelper, Serie> m_OnDrawSerieBefore;
|
||||
protected Action<VertexHelper, Serie> m_OnDrawSerieAfter;
|
||||
@@ -96,8 +97,10 @@ namespace XCharts.Runtime
|
||||
internal bool m_CheckAnimation = false;
|
||||
internal protected List<string> m_LegendRealShowName = new List<string>();
|
||||
protected List<Painter> m_PainterList = new List<Painter>();
|
||||
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)
|
||||
|
||||
@@ -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) { }
|
||||
|
||||
@@ -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<Button>();
|
||||
m_Rect = obj.GetComponent<RectTransform>();
|
||||
m_Icon = obj.transform.Find("icon").gameObject.GetComponent<Image>();
|
||||
m_Background = obj.GetComponent<Image>();
|
||||
m_TextBackground = obj.transform.Find("content").gameObject.GetComponent<Image>();
|
||||
m_Text = new ChartText(obj);
|
||||
m_IconRect = m_Icon.gameObject.GetComponent<RectTransform>();
|
||||
@@ -172,7 +174,8 @@ namespace XCharts.Runtime
|
||||
|
||||
public bool SetContent(string content)
|
||||
{
|
||||
if (m_Text != null && !m_Text.GetText().Equals(content))
|
||||
if (m_Text == null) return false;
|
||||
if (!m_Text.GetText().Equals(content))
|
||||
{
|
||||
m_Text.SetText(content);
|
||||
if (m_LabelAutoSize)
|
||||
@@ -186,11 +189,13 @@ namespace XCharts.Runtime
|
||||
m_TextRect.anchoredPosition3D = new Vector3(m_LabelPaddingLeftRight, 0);
|
||||
m_TextBackgroundRect.sizeDelta = new Vector2(m_Text.GetPreferredWidth() + m_LabelPaddingLeftRight * 2,
|
||||
m_Text.GetPreferredHeight() + m_LabelPaddingTopBottom * 2 - 4);
|
||||
m_Rect.sizeDelta = new Vector3(width, height);
|
||||
|
||||
}
|
||||
m_Rect.sizeDelta = new Vector3(width, height);
|
||||
return sizeChange;
|
||||
}
|
||||
}
|
||||
m_Rect.sizeDelta = new Vector3(width, height);
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -209,5 +214,10 @@ namespace XCharts.Runtime
|
||||
m_GameObject.SetActive(active);
|
||||
}
|
||||
}
|
||||
|
||||
public void SetBackground(ImageStyle imageStyle)
|
||||
{
|
||||
ChartHelper.SetBackground(m_Background, imageStyle);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -314,6 +314,22 @@ namespace XCharts.Runtime
|
||||
return img;
|
||||
}
|
||||
|
||||
public static void SetBackground(Image background, ImageStyle imageStyle)
|
||||
{
|
||||
if (background == null) return;
|
||||
if (imageStyle.show)
|
||||
{
|
||||
background.sprite = imageStyle.sprite;
|
||||
background.color = imageStyle.color;
|
||||
background.type = imageStyle.type;
|
||||
}
|
||||
else
|
||||
{
|
||||
background.sprite = null;
|
||||
background.color = Color.clear;
|
||||
}
|
||||
}
|
||||
|
||||
public static ChartLabel AddAxisLabelObject(int total, int index, string name, Transform parent,
|
||||
Vector2 sizeDelta, Axis axis, ComponentTheme theme,
|
||||
string content, Color autoColor, TextAnchor autoAlignment = TextAnchor.MiddleCenter)
|
||||
|
||||
Reference in New Issue
Block a user