mirror of
https://github.com/XCharts-Team/XCharts.git
synced 2026-05-29 12:48:47 +00:00
增加设置图表Size支持
This commit is contained in:
@@ -12,6 +12,8 @@ namespace XCharts
|
|||||||
{
|
{
|
||||||
protected BaseChart m_Target;
|
protected BaseChart m_Target;
|
||||||
protected SerializedProperty m_Script;
|
protected SerializedProperty m_Script;
|
||||||
|
protected SerializedProperty m_ChartWidth;
|
||||||
|
protected SerializedProperty m_ChartHeight;
|
||||||
protected SerializedProperty m_Theme;
|
protected SerializedProperty m_Theme;
|
||||||
protected SerializedProperty m_ThemeInfo;
|
protected SerializedProperty m_ThemeInfo;
|
||||||
protected SerializedProperty m_Title;
|
protected SerializedProperty m_Title;
|
||||||
@@ -39,6 +41,8 @@ namespace XCharts
|
|||||||
{
|
{
|
||||||
m_Target = (BaseChart)target;
|
m_Target = (BaseChart)target;
|
||||||
m_Script = serializedObject.FindProperty("m_Script");
|
m_Script = serializedObject.FindProperty("m_Script");
|
||||||
|
m_ChartWidth = serializedObject.FindProperty("m_ChartWidth");
|
||||||
|
m_ChartHeight = serializedObject.FindProperty("m_ChartHeight");
|
||||||
m_Theme = serializedObject.FindProperty("m_Theme");
|
m_Theme = serializedObject.FindProperty("m_Theme");
|
||||||
m_ThemeInfo = serializedObject.FindProperty("m_ThemeInfo");
|
m_ThemeInfo = serializedObject.FindProperty("m_ThemeInfo");
|
||||||
m_Title = serializedObject.FindProperty("m_Title");
|
m_Title = serializedObject.FindProperty("m_Title");
|
||||||
@@ -74,12 +78,23 @@ namespace XCharts
|
|||||||
{
|
{
|
||||||
EditorGUILayout.PropertyField(m_Script);
|
EditorGUILayout.PropertyField(m_Script);
|
||||||
EditorGUILayout.BeginHorizontal();
|
EditorGUILayout.BeginHorizontal();
|
||||||
|
|
||||||
|
EditorGUIUtility.labelWidth = 20;
|
||||||
|
EditorGUILayout.LabelField("Size");
|
||||||
|
EditorGUIUtility.fieldWidth = 1;
|
||||||
|
m_ChartWidth.floatValue = EditorGUILayout.FloatField(m_ChartWidth.floatValue);
|
||||||
|
m_ChartHeight.floatValue = EditorGUILayout.FloatField(m_ChartHeight.floatValue);
|
||||||
|
EditorGUILayout.EndHorizontal();
|
||||||
|
|
||||||
|
EditorGUILayout.BeginHorizontal();
|
||||||
|
EditorGUIUtility.labelWidth = m_DefaultLabelWidth;
|
||||||
EditorGUIUtility.fieldWidth = EditorGUIUtility.labelWidth - 5;
|
EditorGUIUtility.fieldWidth = EditorGUIUtility.labelWidth - 5;
|
||||||
m_ThemeModuleToggle = EditorGUILayout.Foldout(m_ThemeModuleToggle,
|
m_ThemeModuleToggle = EditorGUILayout.Foldout(m_ThemeModuleToggle,
|
||||||
new GUIContent("Theme", "the theme of chart\n主题"),
|
new GUIContent("Theme", "the theme of chart\n主题"),
|
||||||
ChartEditorHelper.foldoutStyle);
|
ChartEditorHelper.foldoutStyle);
|
||||||
EditorGUILayout.PropertyField(m_Theme, GUIContent.none);
|
EditorGUILayout.PropertyField(m_Theme, GUIContent.none);
|
||||||
EditorGUILayout.EndHorizontal();
|
EditorGUILayout.EndHorizontal();
|
||||||
|
|
||||||
EditorGUIUtility.labelWidth = m_DefaultLabelWidth;
|
EditorGUIUtility.labelWidth = m_DefaultLabelWidth;
|
||||||
EditorGUIUtility.fieldWidth = m_DefaultFieldWidth;
|
EditorGUIUtility.fieldWidth = m_DefaultFieldWidth;
|
||||||
if (m_ThemeModuleToggle)
|
if (m_ThemeModuleToggle)
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ namespace XCharts
|
|||||||
get{
|
get{
|
||||||
return new Bar(){
|
return new Bar(){
|
||||||
m_InSameBar = false,
|
m_InSameBar = false,
|
||||||
m_BarWidth = 0.7f,
|
m_BarWidth = 0.6f,
|
||||||
m_Space = 10
|
m_Space = 10
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -41,8 +41,9 @@ namespace XCharts
|
|||||||
{
|
{
|
||||||
base.Reset();
|
base.Reset();
|
||||||
m_Bar = Bar.defaultBar;
|
m_Bar = Bar.defaultBar;
|
||||||
|
m_Title.text = "BarChart";
|
||||||
RemoveData();
|
RemoveData();
|
||||||
AddSerie("bar1", SerieType.Line);
|
AddSerie("serie1", SerieType.Line);
|
||||||
for (int i = 0; i < 5; i++)
|
for (int i = 0; i < 5; i++)
|
||||||
{
|
{
|
||||||
AddXAxisData("x" + (i + 1));
|
AddXAxisData("x" + (i + 1));
|
||||||
|
|||||||
@@ -19,6 +19,8 @@ namespace XCharts
|
|||||||
private static readonly string s_TitleObjectName = "title";
|
private static readonly string s_TitleObjectName = "title";
|
||||||
private static readonly string s_LegendObjectName = "legend";
|
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 Theme m_Theme = Theme.Default;
|
||||||
[SerializeField] protected ThemeInfo m_ThemeInfo;
|
[SerializeField] protected ThemeInfo m_ThemeInfo;
|
||||||
[SerializeField] protected Title m_Title = Title.defaultTitle;
|
[SerializeField] protected Title m_Title = Title.defaultTitle;
|
||||||
@@ -39,8 +41,6 @@ namespace XCharts
|
|||||||
[NonSerialized] private bool m_RefreshChart = false;
|
[NonSerialized] private bool m_RefreshChart = false;
|
||||||
[NonSerialized] protected List<Text> m_LegendTextList = new List<Text>();
|
[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 chartAnchorMax { get { return rectTransform.anchorMax; } }
|
||||||
protected Vector2 chartAnchorMin { get { return rectTransform.anchorMin; } }
|
protected Vector2 chartAnchorMin { get { return rectTransform.anchorMin; } }
|
||||||
protected Vector2 chartPivot { get { return rectTransform.pivot; } }
|
protected Vector2 chartPivot { get { return rectTransform.pivot; } }
|
||||||
@@ -50,6 +50,9 @@ namespace XCharts
|
|||||||
public Tooltip tooltip { get { return m_Tooltip; } }
|
public Tooltip tooltip { get { return m_Tooltip; } }
|
||||||
public Series series { get { return m_Series; } }
|
public Series series { get { return m_Series; } }
|
||||||
|
|
||||||
|
public float chartWidth { get { return m_ChartWidth; } }
|
||||||
|
public float chartHeight { get { return m_ChartHeight; } }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The min number of data to show in chart.
|
/// The min number of data to show in chart.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -79,6 +82,21 @@ namespace XCharts
|
|||||||
set { m_MaxCacheDataNumber = value; if (m_MaxCacheDataNumber < 0) m_MaxCacheDataNumber = 0; }
|
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>
|
/// <summary>
|
||||||
/// Remove all series and legend data.
|
/// Remove all series and legend data.
|
||||||
/// It just emptying all of serie's data without emptying the list of series.
|
/// 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.anchorMax = Vector2.zero;
|
||||||
rectTransform.anchorMin = Vector2.zero;
|
rectTransform.anchorMin = Vector2.zero;
|
||||||
rectTransform.pivot = Vector2.zero;
|
rectTransform.pivot = Vector2.zero;
|
||||||
m_CheckWidth = chartWidth;
|
m_ChartWidth = rectTransform.sizeDelta.x;
|
||||||
m_CheckHeight = chartHeight;
|
m_ChartHeight = rectTransform.sizeDelta.y;
|
||||||
|
m_CheckWidth = m_ChartWidth;
|
||||||
|
m_CheckHeight = m_ChartHeight;
|
||||||
m_CheckTheme = m_Theme;
|
m_CheckTheme = m_Theme;
|
||||||
InitTitle();
|
InitTitle();
|
||||||
InitLegend();
|
InitLegend();
|
||||||
@@ -267,6 +287,11 @@ namespace XCharts
|
|||||||
#if UNITY_EDITOR
|
#if UNITY_EDITOR
|
||||||
protected override void Reset()
|
protected override void Reset()
|
||||||
{
|
{
|
||||||
|
var sizeDelta = rectTransform.sizeDelta;
|
||||||
|
if (sizeDelta.x < 580 && sizeDelta.y < 300)
|
||||||
|
{
|
||||||
|
rectTransform.sizeDelta = new Vector2(580, 300);
|
||||||
|
}
|
||||||
ChartHelper.DestoryAllChilds(transform);
|
ChartHelper.DestoryAllChilds(transform);
|
||||||
m_ThemeInfo = ThemeInfo.Default;
|
m_ThemeInfo = ThemeInfo.Default;
|
||||||
m_Title = Title.defaultTitle;
|
m_Title = Title.defaultTitle;
|
||||||
@@ -388,9 +413,12 @@ namespace XCharts
|
|||||||
{
|
{
|
||||||
if (m_CheckWidth != chartWidth || m_CheckHeight != chartHeight)
|
if (m_CheckWidth != chartWidth || m_CheckHeight != chartHeight)
|
||||||
{
|
{
|
||||||
m_CheckWidth = chartWidth;
|
SetSize(chartWidth, chartHeight);
|
||||||
m_CheckHeight = chartHeight;
|
}
|
||||||
OnSizeChanged();
|
var sizeDelta = rectTransform.sizeDelta;
|
||||||
|
if (m_CheckWidth != sizeDelta.x || m_CheckHeight != sizeDelta.y)
|
||||||
|
{
|
||||||
|
SetSize(sizeDelta.x, sizeDelta.y);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ namespace XCharts
|
|||||||
{
|
{
|
||||||
m_Left = 50,
|
m_Left = 50,
|
||||||
m_Right = 30,
|
m_Right = 30,
|
||||||
m_Top = 60,
|
m_Top = 50,
|
||||||
m_Bottom = 30,
|
m_Bottom = 30,
|
||||||
m_Tickness = 0.6f,
|
m_Tickness = 0.6f,
|
||||||
m_FontSize = 16,
|
m_FontSize = 16,
|
||||||
|
|||||||
@@ -330,7 +330,7 @@ namespace XCharts
|
|||||||
var axis1 = YAxis.defaultYAxis;
|
var axis1 = YAxis.defaultYAxis;
|
||||||
var axis2 = YAxis.defaultYAxis;
|
var axis2 = YAxis.defaultYAxis;
|
||||||
axis1.show = true;
|
axis1.show = true;
|
||||||
axis1.splitNumber = 6;
|
axis1.splitNumber = 5;
|
||||||
axis1.boundaryGap = false;
|
axis1.boundaryGap = false;
|
||||||
axis2.show = false;
|
axis2.show = false;
|
||||||
m_YAxises.Add(axis1);
|
m_YAxises.Add(axis1);
|
||||||
|
|||||||
@@ -42,7 +42,7 @@ namespace XCharts
|
|||||||
{
|
{
|
||||||
var legend = new Legend
|
var legend = new Legend
|
||||||
{
|
{
|
||||||
m_Show = true,
|
m_Show = false,
|
||||||
m_Orient = Orient.Horizonal,
|
m_Orient = Orient.Horizonal,
|
||||||
m_Location = Location.defaultTop,
|
m_Location = Location.defaultTop,
|
||||||
m_ItemWidth = 60.0f,
|
m_ItemWidth = 60.0f,
|
||||||
|
|||||||
@@ -19,8 +19,9 @@ namespace XCharts
|
|||||||
{
|
{
|
||||||
base.Reset();
|
base.Reset();
|
||||||
m_Line = Line.defaultLine;
|
m_Line = Line.defaultLine;
|
||||||
|
m_Title.text = "LineChart";
|
||||||
RemoveData();
|
RemoveData();
|
||||||
AddSerie("line1", SerieType.Line);
|
AddSerie("serie1", SerieType.Line);
|
||||||
for (int i = 0; i < 5; i++)
|
for (int i = 0; i < 5; i++)
|
||||||
{
|
{
|
||||||
AddXAxisData("x" + (i + 1));
|
AddXAxisData("x" + (i + 1));
|
||||||
|
|||||||
@@ -74,9 +74,10 @@ namespace XCharts
|
|||||||
{
|
{
|
||||||
base.Reset();
|
base.Reset();
|
||||||
m_Pie = Pie.defaultPie;
|
m_Pie = Pie.defaultPie;
|
||||||
|
m_Title.text = "PieChart";
|
||||||
RemoveData();
|
RemoveData();
|
||||||
AddData("Pie1", 80);
|
AddData("serie1", 80);
|
||||||
AddData("Pie2", 20);
|
AddData("serie2", 20);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|||||||
@@ -48,7 +48,8 @@ namespace XCharts
|
|||||||
base.Reset();
|
base.Reset();
|
||||||
RemoveData();
|
RemoveData();
|
||||||
m_Radar = Radar.defaultRadar;
|
m_Radar = Radar.defaultRadar;
|
||||||
AddSerie("Radar", SerieType.Radar);
|
m_Title.text = "RadarChart";
|
||||||
|
AddSerie("serie1", SerieType.Radar);
|
||||||
for (int i = 0; i < 5; i++)
|
for (int i = 0; i < 5; i++)
|
||||||
{
|
{
|
||||||
AddData(0, Random.Range(20, 90));
|
AddData(0, Random.Range(20, 90));
|
||||||
|
|||||||
Reference in New Issue
Block a user