mirror of
https://github.com/XCharts-Team/XCharts.git
synced 2026-05-21 07:50:16 +00:00
增加Settings全局参数配置组件,开放更多参数可配置
This commit is contained in:
@@ -20,9 +20,8 @@ namespace XCharts
|
||||
protected SerializedProperty m_Legend;
|
||||
protected SerializedProperty m_Tooltip;
|
||||
protected SerializedProperty m_Series;
|
||||
|
||||
protected SerializedProperty m_Settings;
|
||||
protected SerializedProperty m_Large;
|
||||
protected SerializedProperty m_LineSmoothStyle;
|
||||
|
||||
protected float m_DefaultLabelWidth;
|
||||
protected float m_DefaultFieldWidth;
|
||||
@@ -43,7 +42,7 @@ namespace XCharts
|
||||
m_Series = serializedObject.FindProperty("m_Series");
|
||||
|
||||
m_Large = serializedObject.FindProperty("m_Large");
|
||||
m_LineSmoothStyle = serializedObject.FindProperty("m_LineSmoothStyle");
|
||||
m_Settings = serializedObject.FindProperty("m_Settings");
|
||||
}
|
||||
|
||||
public override void OnInspectorGUI()
|
||||
@@ -78,17 +77,7 @@ namespace XCharts
|
||||
protected virtual void OnMiddleInspectorGUI()
|
||||
{
|
||||
EditorGUILayout.PropertyField(m_Series, true);
|
||||
m_BaseModuleToggle = EditorGUILayout.Foldout(m_BaseModuleToggle,
|
||||
new GUIContent("Settings", "基础配置"),
|
||||
ChartEditorHelper.foldoutStyle);
|
||||
if (m_BaseModuleToggle)
|
||||
{
|
||||
EditorGUI.indentLevel++;
|
||||
var largeTip = "Whether to enable the optimization of large-scale graph. \n是否启用大规模线图的优化,在数据图形特别多的时候(>=5k)可以开启。";
|
||||
EditorGUILayout.PropertyField(m_Large, new GUIContent("Large", largeTip));
|
||||
EditorGUILayout.PropertyField(m_LineSmoothStyle,true);
|
||||
EditorGUI.indentLevel--;
|
||||
}
|
||||
EditorGUILayout.PropertyField(m_Settings, true);
|
||||
}
|
||||
|
||||
protected virtual void OnEndInspectorGUI()
|
||||
|
||||
@@ -0,0 +1,49 @@
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
namespace XCharts
|
||||
{
|
||||
[CustomPropertyDrawer(typeof(Settings), true)]
|
||||
public class SettingsDrawer : PropertyDrawer
|
||||
{
|
||||
private bool m_SettingsModuleToggle = false;
|
||||
|
||||
public override void OnGUI(Rect pos, SerializedProperty prop, GUIContent label)
|
||||
{
|
||||
Rect drawRect = pos;
|
||||
drawRect.height = EditorGUIUtility.singleLineHeight;
|
||||
|
||||
SerializedProperty m_LineSmoothStyle = prop.FindPropertyRelative("m_LineSmoothStyle");
|
||||
SerializedProperty m_LineSmoothness = prop.FindPropertyRelative("m_LineSmoothness");
|
||||
SerializedProperty m_LineSegmentDistance = prop.FindPropertyRelative("m_LineSegmentDistance");
|
||||
SerializedProperty m_CicleSmoothness = prop.FindPropertyRelative("m_CicleSmoothness");
|
||||
|
||||
ChartEditorHelper.MakeFoldout(ref drawRect, ref m_SettingsModuleToggle, "Settings");
|
||||
EditorGUI.LabelField(drawRect, "Settings", EditorStyles.boldLabel);
|
||||
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
|
||||
if (m_SettingsModuleToggle)
|
||||
{
|
||||
++EditorGUI.indentLevel;
|
||||
EditorGUI.PropertyField(drawRect, m_LineSmoothStyle);
|
||||
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
|
||||
EditorGUI.PropertyField(drawRect, m_LineSmoothness);
|
||||
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
|
||||
EditorGUI.PropertyField(drawRect, m_LineSegmentDistance);
|
||||
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
|
||||
EditorGUI.PropertyField(drawRect, m_CicleSmoothness);
|
||||
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
|
||||
--EditorGUI.indentLevel;
|
||||
}
|
||||
}
|
||||
|
||||
public override float GetPropertyHeight(SerializedProperty prop, GUIContent label)
|
||||
{
|
||||
int num = 1;
|
||||
if (m_SettingsModuleToggle)
|
||||
{
|
||||
num = 5;
|
||||
}
|
||||
return num * EditorGUIUtility.singleLineHeight + (num - 1) * EditorGUIUtility.standardVerticalSpacing;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 70536a1ba3af245e7ad3b11e97682d8d
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -191,7 +191,7 @@ namespace XCharts
|
||||
radar.center[0] = 0.5f;
|
||||
radar.center[1] = 0.45f;
|
||||
radar.splitArea.show = true;
|
||||
radar.lineStyle.width = 0.3f;
|
||||
radar.lineStyle.width = 0.6f;
|
||||
return radar;
|
||||
}
|
||||
}
|
||||
|
||||
46
Assets/XCharts/Scripts/UI/Component/Settings.cs
Normal file
46
Assets/XCharts/Scripts/UI/Component/Settings.cs
Normal file
@@ -0,0 +1,46 @@
|
||||
using UnityEngine;
|
||||
using System;
|
||||
|
||||
namespace XCharts
|
||||
{
|
||||
/// <summary>
|
||||
/// Global parameter setting component. The default value can be used in general, and can be adjusted when necessary.
|
||||
/// 全局参数设置组件。一般情况下可使用默认值,当有需要时可进行调整。
|
||||
/// </summary>
|
||||
[Serializable]
|
||||
public class Settings
|
||||
{
|
||||
[SerializeField] [Range(1, 10)] protected float m_LineSmoothStyle = 3f;
|
||||
[SerializeField] [Range(1f, 20)] protected float m_LineSmoothness = 2f;
|
||||
[SerializeField] [Range(1f, 20)] protected float m_LineSegmentDistance = 3f;
|
||||
[SerializeField] [Range(1, 10)] protected float m_CicleSmoothness = 2f;
|
||||
|
||||
/// <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.
|
||||
/// 曲线平滑系数。通过调整平滑系数可以改变曲线的曲率,得到外观稍微有变化的不同曲线。
|
||||
/// </summary>
|
||||
public float lineSmoothStyle { get { return m_LineSmoothStyle; } set { m_LineSmoothStyle = value <= 0 ? 1f : value; } }
|
||||
/// <summary>
|
||||
/// Smoothness of curve. The smaller the value, the smoother the curve, but the number of vertices will increase.
|
||||
/// When the area with gradient is filled, the larger the value, the worse the transition effect.
|
||||
/// 曲线平滑度。值越小曲线越平滑,但顶点数也会随之增加。当开启有渐变的区域填充时,数值越大渐变过渡效果越差。
|
||||
/// </summary>
|
||||
/// <value></value>
|
||||
public float lineSmoothness { get { return m_LineSmoothness; } set { m_LineSmoothness = value <= 0 ? 1f : value; } }
|
||||
/// <summary>
|
||||
/// The partition distance of a line segment. A line in a normal line chart is made up of many segments,
|
||||
/// the number of which is determined by the change in value. The smaller the number of segments,
|
||||
/// the higher the number of vertices. When the area with gradient is filled, the larger the value, the worse the transition effect.
|
||||
/// 线段的分割距离。普通折线图的线是由很多线段组成,段数由该数值决定。值越小段数越多,但顶点数也会随之增加。当开启有渐变的区域填充时,数值越大渐变过渡效果越差。
|
||||
/// </summary>
|
||||
/// <value></value>
|
||||
public float lineSegmentDistance { get { return m_LineSegmentDistance; } set { m_LineSegmentDistance = value <= 0 ? 1f : value; } }
|
||||
/// <summary>
|
||||
/// the smoothess of cricle.
|
||||
/// 圆形的平滑度。数越小圆越平滑,但顶点数也会随之增加。
|
||||
/// </summary>
|
||||
public float cicleSmoothness { get { return m_CicleSmoothness; } set { m_CicleSmoothness = value <= 0 ? 1f : value; } }
|
||||
|
||||
}
|
||||
}
|
||||
11
Assets/XCharts/Scripts/UI/Component/Settings.cs.meta
Normal file
11
Assets/XCharts/Scripts/UI/Component/Settings.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f3d421d759f9447daab3a45e123f13a7
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -39,8 +39,8 @@ namespace XCharts
|
||||
[SerializeField] protected Legend m_Legend = Legend.defaultLegend;
|
||||
[SerializeField] protected Tooltip m_Tooltip = Tooltip.defaultTooltip;
|
||||
[SerializeField] protected Series m_Series = Series.defaultSeries;
|
||||
[SerializeField] protected Settings m_Settings = new Settings();
|
||||
[SerializeField] protected float m_Large = 1;
|
||||
[SerializeField] [Range(1, 8)] protected float m_LineSmoothStyle = 2f;
|
||||
[SerializeField] protected Action<VertexHelper> m_CustomDrawCallback;
|
||||
|
||||
[NonSerialized] private Theme m_CheckTheme = 0;
|
||||
@@ -184,7 +184,7 @@ namespace XCharts
|
||||
var legendObject = ChartHelper.AddObject(s_LegendObjectName, transform, anchorMin, anchorMax,
|
||||
pivot, new Vector2(chartWidth, chartHeight));
|
||||
legendObject.transform.localPosition = m_Legend.location.GetPosition(chartWidth, chartHeight);
|
||||
|
||||
|
||||
m_LegendRealShowName = m_Series.GetSerieNameList();
|
||||
List<string> datas;
|
||||
if (m_Legend.show && m_Legend.data.Count > 0)
|
||||
@@ -642,12 +642,10 @@ namespace XCharts
|
||||
case SerieSymbolType.None:
|
||||
break;
|
||||
case SerieSymbolType.Circle:
|
||||
ChartDrawer.DrawCricle(vh, pos, symbolSize, color, GetSymbolCricleSegment(symbolSize));
|
||||
ChartDrawer.DrawCricle(vh, pos, symbolSize, color, m_Settings.cicleSmoothness);
|
||||
break;
|
||||
case SerieSymbolType.EmptyCircle:
|
||||
int segment = GetSymbolCricleSegment(symbolSize);
|
||||
ChartDrawer.DrawCricle(vh, pos, symbolSize, m_ThemeInfo.backgroundColor, segment);
|
||||
ChartDrawer.DrawDoughnut(vh, pos, symbolSize - tickness, symbolSize, 0, 360, color, segment);
|
||||
ChartDrawer.DrawEmptyCricle(vh, pos, symbolSize, tickness, color, m_ThemeInfo.backgroundColor, m_Settings.cicleSmoothness);
|
||||
break;
|
||||
case SerieSymbolType.Rect:
|
||||
ChartDrawer.DrawPolygon(vh, pos, symbolSize, color);
|
||||
@@ -719,15 +717,6 @@ namespace XCharts
|
||||
}
|
||||
}
|
||||
|
||||
private int GetSymbolCricleSegment(float radiu)
|
||||
{
|
||||
int max = 50;
|
||||
int segent = (int)(2 * Mathf.PI * radiu / ChartDrawer.CRICLE_SMOOTHNESS);
|
||||
if (segent > max) segent = max;
|
||||
segent = (int)(segent / (1 + (m_Large - 1) / 10));
|
||||
return segent;
|
||||
}
|
||||
|
||||
public virtual void OnPointerDown(PointerEventData eventData)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -40,15 +40,7 @@ namespace XCharts
|
||||
/// The height of chart.
|
||||
/// 图表的高
|
||||
/// </summary>
|
||||
/// <value></value>
|
||||
public float chartHeight { get { return m_ChartHeight; } }
|
||||
|
||||
/// <summary>
|
||||
/// the smooth line chart style.
|
||||
/// 平滑折线图的平滑系数。
|
||||
/// </summary>
|
||||
/// <value></value>
|
||||
public float lineSmoothStyle { get { return m_LineSmoothStyle; } set { m_LineSmoothStyle = value; } }
|
||||
/// <summary>
|
||||
/// 自定义绘制回调。
|
||||
/// </summary>
|
||||
|
||||
@@ -288,47 +288,6 @@ namespace XCharts
|
||||
return showData[index].data[1];
|
||||
}
|
||||
|
||||
private float GetDetailProgress(Serie serie, Axis axis, Vector3 lp, Vector3 np, Vector3 llp,
|
||||
Vector3 nnp, bool fine)
|
||||
{
|
||||
var isYAxis = axis is YAxis;
|
||||
float progress = 0;
|
||||
switch (serie.lineType)
|
||||
{
|
||||
case LineType.Normal:
|
||||
var lineWidth = serie.lineStyle.width;
|
||||
var ySmall = Mathf.Abs(lp.y - np.y) < lineWidth * 3;
|
||||
var xSmall = Mathf.Abs(lp.x - np.x) < lineWidth * 3;
|
||||
if ((isYAxis && ySmall) || (!isYAxis && xSmall))
|
||||
{
|
||||
progress = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
progress = Vector3.Distance(lp, np) / 3f - 1;
|
||||
}
|
||||
break;
|
||||
case LineType.Smooth:
|
||||
ChartHelper.GetBezierList(ref bezierPoints, lp, np, llp, nnp, fine, lineSmoothStyle);
|
||||
if (bezierPoints.Count > 0) progress = bezierPoints.Count - 1;
|
||||
break;
|
||||
case LineType.StepStart:
|
||||
var middle = isYAxis ? new Vector3(np.x, lp.y) : new Vector3(lp.x, np.y);
|
||||
progress = (Vector3.Distance(middle, np)) / 3f - 1;
|
||||
break;
|
||||
case LineType.StepMiddle:
|
||||
var middle1 = isYAxis ? new Vector2(lp.x, (lp.y + np.y) / 2) : new Vector2((lp.x + np.x) / 2, lp.y);
|
||||
var middle2 = isYAxis ? new Vector2(np.x, (lp.y + np.y) / 2) : new Vector2((lp.x + np.x) / 2, np.y);
|
||||
progress = (Vector3.Distance(lp, middle1) + Vector3.Distance(middle2, np)) / 3f - 1;
|
||||
break;
|
||||
case LineType.StepEnd:
|
||||
middle = isYAxis ? new Vector3(lp.x, np.y) : new Vector3(np.x, lp.y);
|
||||
progress = Vector3.Distance(lp, middle) / 3f - 1;
|
||||
break;
|
||||
}
|
||||
return progress;
|
||||
}
|
||||
|
||||
private float GetDataPoint(Axis xAxis, Axis yAxis, List<SerieData> showData, float yValue, float startX, int i,
|
||||
float scaleWid, float serieHig, ref Vector3 np)
|
||||
{
|
||||
@@ -547,9 +506,7 @@ namespace XCharts
|
||||
var smoothPoints = serie.GetUpSmoothList(dataIndex);
|
||||
var smoothDownPoints = serie.GetDownSmoothList(dataIndex);
|
||||
var dist = Vector3.Distance(lp, np);
|
||||
var fine = m_Series.IsAnyGradientSerie(serie.stack);
|
||||
var tick = fine ? 3f : 3f; // 3f:30f
|
||||
int segment = (int)(dist / tick);
|
||||
int segment = (int)(dist / m_Settings.lineSegmentDistance);
|
||||
if (segment <= 3) segment = (int)(dist / lineWidth);
|
||||
smoothPoints.Clear();
|
||||
smoothDownPoints.Clear();
|
||||
@@ -883,8 +840,8 @@ namespace XCharts
|
||||
var smoothPoints = serie.GetUpSmoothList(dataIndex);
|
||||
var smoothDownPoints = serie.GetDownSmoothList(dataIndex);
|
||||
var fine = isStack && m_Series.IsAnyGradientSerie(serie.stack);
|
||||
if (isYAxis) ChartHelper.GetBezierListVertical(ref bezierPoints, lp, np, fine, lineSmoothStyle);
|
||||
else ChartHelper.GetBezierList(ref bezierPoints, lp, np, llp, nnp, fine, lineSmoothStyle);
|
||||
if (isYAxis) ChartHelper.GetBezierListVertical(ref bezierPoints, lp, np, m_Settings.lineSmoothness, m_Settings.lineSmoothStyle);
|
||||
else ChartHelper.GetBezierList(ref bezierPoints, lp, np, llp, nnp, m_Settings.lineSmoothness, m_Settings.lineSmoothStyle);
|
||||
|
||||
Vector3 start, to;
|
||||
if (serie.lineType == LineType.SmoothDash)
|
||||
@@ -1101,7 +1058,7 @@ namespace XCharts
|
||||
|
||||
if (Vector3.Distance(lp, middle) > 2 * lineWidth)
|
||||
{
|
||||
ChartHelper.GetPointList(ref linePointList, start, middle - diff1, 3f);
|
||||
ChartHelper.GetPointList(ref linePointList, start, middle - diff1, m_Settings.lineSegmentDistance);
|
||||
sp = linePointList[0];
|
||||
for (int i = 1; i < linePointList.Count; i++)
|
||||
{
|
||||
@@ -1128,7 +1085,7 @@ namespace XCharts
|
||||
}
|
||||
}
|
||||
|
||||
ChartHelper.GetPointList(ref linePointList, middle + diff2, end, 3f);
|
||||
ChartHelper.GetPointList(ref linePointList, middle + diff2, end, m_Settings.lineSegmentDistance);
|
||||
sp = linePointList[0];
|
||||
for (int i = 1; i < linePointList.Count; i++)
|
||||
{
|
||||
@@ -1165,7 +1122,7 @@ namespace XCharts
|
||||
//draw lp to middle1
|
||||
if (Vector3.Distance(lp, middle1) > 2 * lineWidth)
|
||||
{
|
||||
ChartHelper.GetPointList(ref linePointList, start, middle1 - diff1, 3f);
|
||||
ChartHelper.GetPointList(ref linePointList, start, middle1 - diff1, m_Settings.lineSegmentDistance);
|
||||
sp = linePointList[0];
|
||||
for (int i = 1; i < linePointList.Count; i++)
|
||||
{
|
||||
@@ -1194,7 +1151,7 @@ namespace XCharts
|
||||
//draw middle1 to middle2
|
||||
if (Vector3.Distance(middle1, middle2) > 2 * lineWidth)
|
||||
{
|
||||
ChartHelper.GetPointList(ref linePointList, middle1 + diff2, middle2 - diff2, 3f);
|
||||
ChartHelper.GetPointList(ref linePointList, middle1 + diff2, middle2 - diff2, m_Settings.lineSegmentDistance);
|
||||
sp = linePointList[0];
|
||||
for (int i = 1; i < linePointList.Count; i++)
|
||||
{
|
||||
@@ -1215,7 +1172,7 @@ namespace XCharts
|
||||
//draw middle2 to np
|
||||
if (Vector3.Distance(middle2, np) > 2 * lineWidth)
|
||||
{
|
||||
ChartHelper.GetPointList(ref linePointList, middle2 + diff1, np - diff1, 3f);
|
||||
ChartHelper.GetPointList(ref linePointList, middle2 + diff1, np - diff1, m_Settings.lineSegmentDistance);
|
||||
sp = linePointList[0];
|
||||
for (int i = 1; i < linePointList.Count; i++)
|
||||
{
|
||||
@@ -1250,7 +1207,7 @@ namespace XCharts
|
||||
|
||||
if (Vector3.Distance(lp, middle) > 2 * lineWidth)
|
||||
{
|
||||
ChartHelper.GetPointList(ref linePointList, start, middle - diff1, 3f);
|
||||
ChartHelper.GetPointList(ref linePointList, start, middle - diff1, m_Settings.lineSegmentDistance);
|
||||
sp = linePointList[0];
|
||||
for (int i = 1; i < linePointList.Count; i++)
|
||||
{
|
||||
@@ -1278,7 +1235,7 @@ namespace XCharts
|
||||
|
||||
if (Vector3.Distance(middle, np) > 2 * lineWidth)
|
||||
{
|
||||
ChartHelper.GetPointList(ref linePointList, middle + diff2, end, 3f);
|
||||
ChartHelper.GetPointList(ref linePointList, middle + diff2, end, m_Settings.lineSegmentDistance);
|
||||
sp = linePointList[0];
|
||||
for (int i = 1; i < linePointList.Count; i++)
|
||||
{
|
||||
|
||||
@@ -140,12 +140,12 @@ namespace XCharts
|
||||
center.y + serieData.pieOffsetRadius * currCos);
|
||||
|
||||
ChartDrawer.DrawDoughnut(vh, serieData.pieOffsetCenter, serieData.pieInsideRadius, serieData.pieOutsideRadius,
|
||||
startDegree, serieData.pieCurrAngle, color);
|
||||
color, m_ThemeInfo.backgroundColor, m_Settings.cicleSmoothness, startDegree, serieData.pieCurrAngle);
|
||||
}
|
||||
else
|
||||
{
|
||||
ChartDrawer.DrawDoughnut(vh, center, serieData.pieInsideRadius, serieData.pieOutsideRadius,
|
||||
startDegree, serieData.pieCurrAngle, color);
|
||||
color, m_ThemeInfo.backgroundColor, m_Settings.cicleSmoothness, startDegree, serieData.pieCurrAngle);
|
||||
}
|
||||
serieData.canShowLabel = serieData.pieCurrAngle >= serieData.pieHalfAngle;
|
||||
isDrawPie = true;
|
||||
@@ -282,7 +282,7 @@ namespace XCharts
|
||||
ChartDrawer.DrawLine(vh, pos3, pos5, serie.label.lineWidth, color);
|
||||
break;
|
||||
case SerieLabel.LineType.Curves:
|
||||
ChartDrawer.DrawCurves(vh, pos1, pos5, pos1, pos2, serie.label.lineWidth, color);
|
||||
ChartDrawer.DrawCurves(vh, pos1, pos5, pos1, pos2, serie.label.lineWidth, color, m_Settings.lineSmoothness);
|
||||
break;
|
||||
case SerieLabel.LineType.HorizontalLine:
|
||||
ChartDrawer.DrawCricle(vh, pos0, horizontalLineCircleRadius, color, 20);
|
||||
|
||||
@@ -293,7 +293,7 @@ namespace XCharts
|
||||
{
|
||||
ChartDrawer.DrawLine(vh, startPoint, firstPoint, serie.lineStyle.width, lineColor);
|
||||
}
|
||||
if (serie.symbol.type != SerieSymbolType.None )
|
||||
if (serie.symbol.type != SerieSymbolType.None)
|
||||
{
|
||||
var symbolSize = (isHighlight ? serie.symbol.selectedSize : serie.symbol.size);
|
||||
var symbolColor = serie.symbol.color != Color.clear ? serie.symbol.color : lineColor;
|
||||
@@ -377,11 +377,13 @@ namespace XCharts
|
||||
outsideRadius = insideRadius + block;
|
||||
if (radar.splitArea.show)
|
||||
{
|
||||
ChartDrawer.DrawDoughnut(vh, p, insideRadius, outsideRadius, 0, 360, color);
|
||||
ChartDrawer.DrawDoughnut(vh, p, insideRadius, outsideRadius, color, Color.clear,
|
||||
m_Settings.cicleSmoothness, 0, 360);
|
||||
}
|
||||
if (radar.lineStyle.show)
|
||||
{
|
||||
ChartDrawer.DrawCicleNotFill(vh, p, outsideRadius, radar.lineStyle.width, lineColor);
|
||||
ChartDrawer.DrawEmptyCricle(vh, p, outsideRadius, radar.lineStyle.width, lineColor,
|
||||
Color.clear, m_Settings.cicleSmoothness);
|
||||
}
|
||||
insideRadius = outsideRadius;
|
||||
}
|
||||
|
||||
@@ -7,7 +7,6 @@ namespace XCharts
|
||||
{
|
||||
public static class ChartDrawer
|
||||
{
|
||||
public static float CRICLE_SMOOTHNESS = 2f;
|
||||
private static UIVertex[] vertex = new UIVertex[4];
|
||||
private static List<Vector3> s_CurvesPosList = new List<Vector3>();
|
||||
|
||||
@@ -182,44 +181,21 @@ namespace XCharts
|
||||
}
|
||||
|
||||
public static void DrawCricle(VertexHelper vh, Vector3 p, float radius, Color32 color,
|
||||
int segments = 0)
|
||||
float smoothness = 2f)
|
||||
{
|
||||
if (segments <= 0)
|
||||
{
|
||||
segments = (int)((2 * Mathf.PI * radius) / CRICLE_SMOOTHNESS);
|
||||
}
|
||||
if (segments < 3) segments = 3;
|
||||
DrawSector(vh, p, radius, color, 0, 360, segments);
|
||||
DrawSector(vh, p, radius, color, 0, 360, smoothness);
|
||||
}
|
||||
|
||||
public static void DrawCicleNotFill(VertexHelper vh, Vector3 p, float radius, float tickness,
|
||||
Color32 color, int segments = 0)
|
||||
public static void DrawEmptyCricle(VertexHelper vh, Vector3 p, float radius, float tickness,
|
||||
Color32 color, Color emptyColor, float smoothness = 2f)
|
||||
{
|
||||
if (segments <= 0)
|
||||
{
|
||||
segments = (int)((2 * Mathf.PI * radius) / CRICLE_SMOOTHNESS);
|
||||
}
|
||||
float startDegree = 0, toDegree = 360;
|
||||
Vector3 p2, p3;
|
||||
float startAngle = startDegree * Mathf.Deg2Rad;
|
||||
float angle = (toDegree - startDegree) * Mathf.Deg2Rad / segments;
|
||||
p2 = new Vector3(p.x + radius * Mathf.Sin(startAngle), p.y + radius * Mathf.Cos(startAngle));
|
||||
for (int i = 0; i <= segments; i++)
|
||||
{
|
||||
float currAngle = startAngle + i * angle;
|
||||
p3 = new Vector3(p.x + radius * Mathf.Sin(currAngle), p.y + radius * Mathf.Cos(currAngle));
|
||||
DrawLine(vh, p2, p3, tickness, color);
|
||||
p2 = p3;
|
||||
}
|
||||
DrawDoughnut(vh, p, radius - tickness, radius, color, emptyColor, smoothness);
|
||||
}
|
||||
|
||||
public static void DrawSector(VertexHelper vh, Vector3 p, float radius, Color32 color,
|
||||
float startDegree, float toDegree, int segments = 0)
|
||||
float startDegree, float toDegree, float smoothness = 2f)
|
||||
{
|
||||
if (segments <= 0)
|
||||
{
|
||||
segments = (int)((2 * Mathf.PI * radius) / CRICLE_SMOOTHNESS);
|
||||
}
|
||||
int segments = (int)((2 * Mathf.PI * radius) / (smoothness < 0 ? 2f : smoothness));
|
||||
Vector3 p2, p3;
|
||||
float startAngle = startDegree * Mathf.Deg2Rad;
|
||||
float angle = (toDegree - startDegree) * Mathf.Deg2Rad / segments;
|
||||
@@ -235,18 +211,15 @@ namespace XCharts
|
||||
}
|
||||
|
||||
public static void DrawDoughnut(VertexHelper vh, Vector3 p, float insideRadius, float outsideRadius,
|
||||
float startDegree, float toDegree, Color32 color, int segments = 0)
|
||||
Color32 color, Color emptyColor, float smoothness = 2f, float startDegree = 0, float toDegree = 360)
|
||||
{
|
||||
if (insideRadius <= 0)
|
||||
{
|
||||
DrawSector(vh, p, outsideRadius, color, startDegree, toDegree, segments);
|
||||
DrawSector(vh, p, outsideRadius, color, startDegree, toDegree, smoothness);
|
||||
return;
|
||||
}
|
||||
if (segments <= 0)
|
||||
{
|
||||
segments = (int)((2 * Mathf.PI * outsideRadius) / CRICLE_SMOOTHNESS);
|
||||
}
|
||||
Vector3 p1, p2, p3, p4;
|
||||
int segments = (int)((2 * Mathf.PI * outsideRadius) / (smoothness < 0 ? 2f : smoothness));
|
||||
float startAngle = startDegree * Mathf.Deg2Rad;
|
||||
float angle = (toDegree - startDegree) * Mathf.Deg2Rad / segments;
|
||||
p1 = new Vector3(p.x + insideRadius * Mathf.Sin(startAngle),
|
||||
@@ -260,6 +233,7 @@ namespace XCharts
|
||||
p.y + outsideRadius * Mathf.Cos(currAngle));
|
||||
p4 = new Vector3(p.x + insideRadius * Mathf.Sin(currAngle),
|
||||
p.y + insideRadius * Mathf.Cos(currAngle));
|
||||
if (emptyColor != Color.clear) DrawTriangle(vh, p, p1, p4, emptyColor);
|
||||
DrawPolygon(vh, p1, p2, p3, p4, color);
|
||||
p1 = p4;
|
||||
p2 = p3;
|
||||
@@ -277,10 +251,10 @@ namespace XCharts
|
||||
/// <param name="lineWidth">曲线宽</param>
|
||||
/// <param name="lineColor">曲线颜色</param>
|
||||
public static void DrawCurves(VertexHelper vh, Vector3 sp, Vector3 ep, Vector3 cp1, Vector3 cp2,
|
||||
float lineWidth, Color lineColor)
|
||||
float lineWidth, Color lineColor, float smoothness)
|
||||
{
|
||||
var dist = Vector3.Distance(sp, ep);
|
||||
var segment = (int)(dist / 1f);
|
||||
var segment = (int)(dist / (smoothness <= 0 ? 2f : smoothness));
|
||||
ChartHelper.GetBezierList2(ref s_CurvesPosList, sp, ep, segment, cp1, cp2);
|
||||
if (s_CurvesPosList.Count > 1)
|
||||
{
|
||||
|
||||
@@ -236,7 +236,7 @@ namespace XCharts
|
||||
return labelObj;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static void GetPointList(ref List<Vector3> posList, Vector3 sp, Vector3 ep, float k = 30f)
|
||||
{
|
||||
Vector3 dir = (ep - sp).normalized;
|
||||
@@ -252,7 +252,7 @@ namespace XCharts
|
||||
}
|
||||
|
||||
public static void GetBezierList(ref List<Vector3> posList, Vector3 sp, Vector3 ep,
|
||||
Vector3 lsp, Vector3 nep, bool fine, float k = 2.0f)
|
||||
Vector3 lsp, Vector3 nep, float smoothness = 2f, float k = 2.0f)
|
||||
{
|
||||
float dist = Mathf.Abs(sp.x - ep.x);
|
||||
Vector3 cp1, cp2;
|
||||
@@ -271,13 +271,13 @@ namespace XCharts
|
||||
if (nep == ep) cp2 = ep;
|
||||
else cp2 = ep - (nep - sp).normalized * diff;
|
||||
dist = Vector3.Distance(sp, ep);
|
||||
int segment = (int)(dist / (fine ? 2f : 6f));
|
||||
int segment = (int)(dist / (smoothness <= 0 ? 2f : smoothness));
|
||||
if (segment < 1) segment = (int)(dist / 0.5f);
|
||||
if (segment < 4) segment = 4;
|
||||
GetBezierList2(ref posList, sp, ep, segment, cp1, cp2);
|
||||
}
|
||||
|
||||
public static void GetBezierListVertical(ref List<Vector3> posList, Vector3 sp, Vector3 ep, bool fine, float k = 2.0f)
|
||||
public static void GetBezierListVertical(ref List<Vector3> posList, Vector3 sp, Vector3 ep, float smoothness = 2f, float k = 2.0f)
|
||||
{
|
||||
Vector3 dir = (ep - sp).normalized;
|
||||
float dist = Vector3.Distance(sp, ep);
|
||||
@@ -285,7 +285,7 @@ namespace XCharts
|
||||
Vector3 cp2 = sp + dist / k * dir * (k - 1);
|
||||
cp1.x = sp.x;
|
||||
cp2.x = ep.x;
|
||||
int segment = (int)(dist / (fine ? 3f : 7f));
|
||||
int segment = (int)(dist / (smoothness <= 0 ? 2f : smoothness));
|
||||
GetBezierList2(ref posList, sp, ep, segment, cp1, cp2);
|
||||
}
|
||||
|
||||
@@ -332,39 +332,6 @@ namespace XCharts
|
||||
t * t * t * ep;
|
||||
}
|
||||
|
||||
public static List<Vector3> GetBezierN(List<Vector3> arrayToCurve, float smoothness = 1.0f)
|
||||
{
|
||||
List<Vector3> points;
|
||||
List<Vector3> curvedPoints;
|
||||
int pointsLength = 0;
|
||||
int curvedLength = 0;
|
||||
|
||||
if (smoothness < 1.0f) smoothness = 1.0f;
|
||||
|
||||
pointsLength = arrayToCurve.Count;
|
||||
|
||||
curvedLength = (pointsLength * Mathf.RoundToInt(smoothness)) - 1;
|
||||
curvedPoints = new List<Vector3>(curvedLength);
|
||||
|
||||
float t = 0.0f;
|
||||
for (int pointInTimeOnCurve = 0; pointInTimeOnCurve < curvedLength + 1; pointInTimeOnCurve++)
|
||||
{
|
||||
t = Mathf.InverseLerp(0, curvedLength, pointInTimeOnCurve);
|
||||
|
||||
points = new List<Vector3>(arrayToCurve);
|
||||
|
||||
for (int j = pointsLength - 1; j > 0; j--)
|
||||
{
|
||||
for (int i = 0; i < j; i++)
|
||||
{
|
||||
points[i] = (1 - t) * points[i] + t * points[i + 1];
|
||||
}
|
||||
}
|
||||
curvedPoints.Add(points[0]);
|
||||
}
|
||||
return curvedPoints;
|
||||
}
|
||||
|
||||
public static bool IsValueEqualsColor(Color32 color1, Color32 color2)
|
||||
{
|
||||
return color1.a == color2.a &&
|
||||
|
||||
@@ -432,14 +432,12 @@
|
||||
|
||||
---
|
||||
|
||||
全局配置。
|
||||
全局参数设置组件。一般情况下可使用默认值,当有需要时可进行调整。
|
||||
|
||||
* `large`:
|
||||
* `minShowDataNumber`:图表所显示数据的最小索引。
|
||||
* `maxShowDataNumber`:图表所显示数据的最大索引。
|
||||
* `maxCacheDataNumber`:图表每个系列中可缓存的最大数据量。默认为0没有限制,大于`0`时超过指定值会移除旧数据再插入新数据。
|
||||
* `lineSmoothStyle`:平滑折线图的平滑系数。
|
||||
* `sampleDist`:采样的最小像素距离,默认为`0`时不采样。当两个数据点间的像素距离小于改值时,开启采样,保证两点间的像素距离不小于改值。
|
||||
* `lineSmoothStyle`:曲线平滑系数。通过调整平滑系数可以改变曲线的曲率,得到外观稍微有变化的不同曲线。
|
||||
* `lineSmoothness`:曲线平滑度。值越小曲线越平滑,但顶点数也会随之增加。当开启有渐变的区域填充时,数值越大渐变过渡效果越差。
|
||||
* `lineSegmentDistance`: 线段的分割距离。普通折线图的线是由很多线段组成,段数由该数值决定。值越小段数越多,但顶点数也会随之增加。当开启有渐变的区域填充时,数值越大渐变过渡效果越差。
|
||||
* `cicleSmoothness`:圆形(包括扇形、环形等)的平滑度。数越小圆越平滑,但顶点数也会随之增加。
|
||||
|
||||
[返回首页](https://github.com/monitor1394/unity-ugui-XCharts)
|
||||
[XChartsAPI接口](XChartsAPI.md)
|
||||
|
||||
Reference in New Issue
Block a user