增加设置图表Size支持

This commit is contained in:
monitor1394
2019-07-15 19:21:22 +08:00
parent 3cad69e40b
commit f9a853dee4
9 changed files with 66 additions and 19 deletions

View File

@@ -25,7 +25,7 @@ namespace XCharts
get{
return new Bar(){
m_InSameBar = false,
m_BarWidth = 0.7f,
m_BarWidth = 0.6f,
m_Space = 10
};
}
@@ -41,8 +41,9 @@ namespace XCharts
{
base.Reset();
m_Bar = Bar.defaultBar;
m_Title.text = "BarChart";
RemoveData();
AddSerie("bar1", SerieType.Line);
AddSerie("serie1", SerieType.Line);
for (int i = 0; i < 5; i++)
{
AddXAxisData("x" + (i + 1));

View File

@@ -19,6 +19,8 @@ namespace XCharts
private static readonly string s_TitleObjectName = "title";
private static readonly string s_LegendObjectName = "legend";
[SerializeField] protected float m_ChartWidth;
[SerializeField] protected float m_ChartHeight;
[SerializeField] protected Theme m_Theme = Theme.Default;
[SerializeField] protected ThemeInfo m_ThemeInfo;
[SerializeField] protected Title m_Title = Title.defaultTitle;
@@ -39,8 +41,6 @@ namespace XCharts
[NonSerialized] private bool m_RefreshChart = false;
[NonSerialized] protected List<Text> m_LegendTextList = new List<Text>();
protected float chartWidth { get { return rectTransform.sizeDelta.x; } }
protected float chartHeight { get { return rectTransform.sizeDelta.y; } }
protected Vector2 chartAnchorMax { get { return rectTransform.anchorMax; } }
protected Vector2 chartAnchorMin { get { return rectTransform.anchorMin; } }
protected Vector2 chartPivot { get { return rectTransform.pivot; } }
@@ -50,6 +50,9 @@ namespace XCharts
public Tooltip tooltip { get { return m_Tooltip; } }
public Series series { get { return m_Series; } }
public float chartWidth { get { return m_ChartWidth; } }
public float chartHeight { get { return m_ChartHeight; } }
/// <summary>
/// The min number of data to show in chart.
/// </summary>
@@ -79,6 +82,21 @@ namespace XCharts
set { m_MaxCacheDataNumber = value; if (m_MaxCacheDataNumber < 0) m_MaxCacheDataNumber = 0; }
}
/// <summary>
/// Set the size of chart.
/// </summary>
/// <param name="width">width</param>
/// <param name="height">height</param>
public virtual void SetSize(float width, float height)
{
m_ChartWidth = width;
m_ChartHeight = height;
m_CheckWidth = width;
m_CheckHeight = height;
rectTransform.sizeDelta = new Vector2(m_ChartWidth, m_ChartHeight);
OnSizeChanged();
}
/// <summary>
/// Remove all series and legend data.
/// It just emptying all of serie's data without emptying the list of series.
@@ -246,8 +264,10 @@ namespace XCharts
rectTransform.anchorMax = Vector2.zero;
rectTransform.anchorMin = Vector2.zero;
rectTransform.pivot = Vector2.zero;
m_CheckWidth = chartWidth;
m_CheckHeight = chartHeight;
m_ChartWidth = rectTransform.sizeDelta.x;
m_ChartHeight = rectTransform.sizeDelta.y;
m_CheckWidth = m_ChartWidth;
m_CheckHeight = m_ChartHeight;
m_CheckTheme = m_Theme;
InitTitle();
InitLegend();
@@ -267,6 +287,11 @@ namespace XCharts
#if UNITY_EDITOR
protected override void Reset()
{
var sizeDelta = rectTransform.sizeDelta;
if (sizeDelta.x < 580 && sizeDelta.y < 300)
{
rectTransform.sizeDelta = new Vector2(580, 300);
}
ChartHelper.DestoryAllChilds(transform);
m_ThemeInfo = ThemeInfo.Default;
m_Title = Title.defaultTitle;
@@ -388,9 +413,12 @@ namespace XCharts
{
if (m_CheckWidth != chartWidth || m_CheckHeight != chartHeight)
{
m_CheckWidth = chartWidth;
m_CheckHeight = chartHeight;
OnSizeChanged();
SetSize(chartWidth, chartHeight);
}
var sizeDelta = rectTransform.sizeDelta;
if (m_CheckWidth != sizeDelta.x || m_CheckHeight != sizeDelta.y)
{
SetSize(sizeDelta.x, sizeDelta.y);
}
}

View File

@@ -28,7 +28,7 @@ namespace XCharts
{
m_Left = 50,
m_Right = 30,
m_Top = 60,
m_Top = 50,
m_Bottom = 30,
m_Tickness = 0.6f,
m_FontSize = 16,

View File

@@ -330,7 +330,7 @@ namespace XCharts
var axis1 = YAxis.defaultYAxis;
var axis2 = YAxis.defaultYAxis;
axis1.show = true;
axis1.splitNumber = 6;
axis1.splitNumber = 5;
axis1.boundaryGap = false;
axis2.show = false;
m_YAxises.Add(axis1);

View File

@@ -42,7 +42,7 @@ namespace XCharts
{
var legend = new Legend
{
m_Show = true,
m_Show = false,
m_Orient = Orient.Horizonal,
m_Location = Location.defaultTop,
m_ItemWidth = 60.0f,

View File

@@ -19,8 +19,9 @@ namespace XCharts
{
base.Reset();
m_Line = Line.defaultLine;
m_Title.text = "LineChart";
RemoveData();
AddSerie("line1", SerieType.Line);
AddSerie("serie1", SerieType.Line);
for (int i = 0; i < 5; i++)
{
AddXAxisData("x" + (i + 1));

View File

@@ -74,9 +74,10 @@ namespace XCharts
{
base.Reset();
m_Pie = Pie.defaultPie;
m_Title.text = "PieChart";
RemoveData();
AddData("Pie1", 80);
AddData("Pie2", 20);
AddData("serie1", 80);
AddData("serie2", 20);
}
#endif

View File

@@ -48,7 +48,8 @@ namespace XCharts
base.Reset();
RemoveData();
m_Radar = Radar.defaultRadar;
AddSerie("Radar", SerieType.Radar);
m_Title.text = "RadarChart";
AddSerie("serie1", SerieType.Radar);
for (int i = 0; i < 5; i++)
{
AddData(0, Random.Range(20, 90));