增加AxissplitLine参数控制分割线

This commit is contained in:
monitor1394
2020-02-11 20:37:34 +08:00
parent cd3f933764
commit 9e3e0c8b0d
12 changed files with 326 additions and 138 deletions

View File

@@ -78,7 +78,7 @@ namespace XCharts
m_Symbol = false,
m_SymbolWidth = 10,
m_SymbolHeight = 15,
m_SymbolOffset = 0,
m_SymbolOffset = -5f,
m_SymbolDent = 3,
};
return axisLine;

View File

@@ -0,0 +1,91 @@
/******************************************/
/* */
/* Copyright (c) 2018 monitor1394 */
/* https://github.com/monitor1394 */
/* */
/******************************************/
using System;
using UnityEngine;
namespace XCharts
{
/// <summary>
/// Split line of axis in grid area.
/// 坐标轴在 grid 区域中的分隔线。
/// </summary>
[Serializable]
public class AxisSplitLine : SubComponent
{
[SerializeField] private bool m_Show;
[SerializeField] private int m_Interval;
[SerializeField] private LineStyle m_LineStyle = new LineStyle(0.7f);
/// <summary>
/// Set this to true to show the split line.
/// 是否显示分隔线。
/// </summary>
public bool show { get { return m_Show; } set { m_Show = value; } }
public int interval { get { return m_Interval; } set { m_Interval = value; } }
/// <summary>
/// 线条样式
/// </summary>
public LineStyle lineStyle { get { return m_LineStyle; } set { if (value != null) m_LineStyle = value; } }
public static AxisSplitLine defaultSplitLine
{
get
{
return new AxisSplitLine()
{
m_Show = false,
};
}
}
public void Copy(AxisSplitLine other)
{
m_Show = other.show;
m_Interval = other.interval;
m_LineStyle.Copy(other.m_LineStyle);
}
public override bool Equals(object obj)
{
if (obj == null || GetType() != obj.GetType())
{
return false;
}
var other = (AxisSplitLine)obj;
return m_Show == other.show &&
m_Interval == other.interval &&
m_LineStyle.Equals(other.lineStyle);
}
public override int GetHashCode()
{
return base.GetHashCode();
}
internal Color GetColor(ThemeInfo theme)
{
if (lineStyle.color != Color.clear)
{
var color = lineStyle.color;
color.a *= lineStyle.opacity;
return color;
}
else
{
var color = (Color)theme.axisSplitLineColor;
color.a *= lineStyle.opacity;
return color;
}
}
internal bool NeedShow(int index)
{
return interval == 0 || index % (interval + 1) == 0;
}
}
}

View File

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

View File

@@ -75,5 +75,49 @@ namespace XCharts
/// 线的透明度。支持从 0 到 1 的数字,为 0 时不绘制该图形。
/// </summary>
public float opacity { get { return m_Opacity; } set { m_Opacity = value; } }
public LineStyle()
{
}
public LineStyle(float width)
{
this.width = width;
}
public LineStyle(LineStyle.Type type, float width)
{
this.type = type;
this.width = width;
}
public void Copy(LineStyle other)
{
m_Show = other.show;
m_Type = other.type;
m_Color = other.color;
m_Width = other.width;
m_Opacity = other.opacity;
}
public override bool Equals(object obj)
{
if (obj == null || GetType() != obj.GetType())
{
return false;
}
var other = (LineStyle)obj;
return m_Show == other.show &&
m_Type == other.type &&
m_Width == other.width &&
m_Opacity == other.opacity &&
ChartHelper.IsValueEqualsColor(m_Color, other.color);
}
public override int GetHashCode()
{
return base.GetHashCode();
}
}
}