mirror of
https://github.com/XCharts-Team/XCharts.git
synced 2026-05-25 10:20:10 +00:00
增加MLValue多样式数值
This commit is contained in:
@@ -73,6 +73,7 @@ slug: /changelog
|
||||
|
||||
日志详情:
|
||||
|
||||
* (2023.07.26) 增加`MLValue`多样式数值
|
||||
* (2023.07.25) 增加`XLog`日志系统
|
||||
* (2023.07.18) 完善`Pie`饼图的交互动画效果
|
||||
* (2023.07.14) 增加`Animation`的`Interaction`交互动画配置支持
|
||||
|
||||
@@ -60,8 +60,8 @@ namespace XCharts.Editor
|
||||
{
|
||||
++EditorGUI.indentLevel;
|
||||
PropertyField(prop, "m_Duration");
|
||||
PropertyField(prop, "m_WidthRate");
|
||||
PropertyField(prop, "m_RadiusRate");
|
||||
PropertyField(prop, "m_Width");
|
||||
PropertyField(prop, "m_Radius");
|
||||
PropertyField(prop, "m_Offset");
|
||||
--EditorGUI.indentLevel;
|
||||
}
|
||||
|
||||
27
Editor/ChildComponents/MLValueDrawer.cs
Normal file
27
Editor/ChildComponents/MLValueDrawer.cs
Normal file
@@ -0,0 +1,27 @@
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
using XCharts.Runtime;
|
||||
|
||||
namespace XCharts.Editor
|
||||
{
|
||||
|
||||
[CustomPropertyDrawer(typeof(MLValue), true)]
|
||||
public class MLValueDrawer : BasePropertyDrawer
|
||||
{
|
||||
public override void OnGUI(Rect pos, SerializedProperty prop, GUIContent label)
|
||||
{
|
||||
Rect drawRect = pos;
|
||||
drawRect.height = EditorGUIUtility.singleLineHeight;
|
||||
SerializedProperty m_Percent = prop.FindPropertyRelative("m_Type");
|
||||
SerializedProperty m_Color = prop.FindPropertyRelative("m_Value");
|
||||
|
||||
ChartEditorHelper.MakeTwoField(ref drawRect, drawRect.width, m_Percent, m_Color, prop.displayName);
|
||||
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
|
||||
}
|
||||
|
||||
public override float GetPropertyHeight(SerializedProperty prop, GUIContent label)
|
||||
{
|
||||
return 1 * EditorGUIUtility.singleLineHeight + 1 * EditorGUIUtility.standardVerticalSpacing;
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Editor/ChildComponents/MLValueDrawer.cs.meta
Normal file
11
Editor/ChildComponents/MLValueDrawer.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 364b6129b88e14605b1a1454b7bf876b
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -412,30 +412,44 @@ namespace XCharts.Runtime
|
||||
[System.Serializable]
|
||||
public class AnimationInteraction : AnimationInfo
|
||||
{
|
||||
[SerializeField][Since("v3.8.0")] private float m_WidthRate = 1.1f;
|
||||
[SerializeField][Since("v3.8.0")] private float m_RadiusRate = 1.1f;
|
||||
[SerializeField][Since("v3.8.0")] private float m_Offset = 5f;
|
||||
[SerializeField][Since("v3.8.0")] private MLValue m_Width = new MLValue(1.1f);
|
||||
[SerializeField][Since("v3.8.0")] private MLValue m_Radius = new MLValue(1.1f);
|
||||
[SerializeField][Since("v3.8.0")] private MLValue m_Offset = new MLValue(MLValue.Type.Absolute, 5f);
|
||||
|
||||
/// <summary>
|
||||
/// the size rate of the width.
|
||||
/// |宽度的放大倍率。
|
||||
/// the mlvalue of width.
|
||||
/// |宽度的多样式数值。
|
||||
/// </summary>
|
||||
public float widthRate { get { return m_WidthRate; } set { m_WidthRate = value; } }
|
||||
public MLValue width { get { return m_Width; } set { m_Width = value; } }
|
||||
/// <summary>
|
||||
/// the size rate of the radius.
|
||||
/// |半径的放大倍率。
|
||||
/// the mlvalue of radius.
|
||||
/// |半径的多样式数值。
|
||||
/// </summary>
|
||||
public float radiusRate { get { return m_RadiusRate; } set { m_RadiusRate = value; } }
|
||||
public MLValue radius { get { return m_Radius; } set { m_Radius = value; } }
|
||||
/// <summary>
|
||||
/// the offset when interaction. Such as the offset of the pie chart when the sector is selected.
|
||||
/// |交互时的偏移。如饼图的扇形选中时的偏移。
|
||||
/// the mlvalue of offset. Such as the offset of the pie chart when the sector is selected.
|
||||
/// |交互的多样式数值。如饼图的扇形选中时的偏移。
|
||||
/// </summary>
|
||||
public float offset { get { return m_Offset; } set { m_Offset = value; } }
|
||||
|
||||
public MLValue offset { get { return m_Offset; } set { m_Offset = value; } }
|
||||
|
||||
public float GetRadius(float radius)
|
||||
{
|
||||
return radius * radiusRate;
|
||||
return m_Radius.GetValue(radius);
|
||||
}
|
||||
|
||||
public float GetWidth(float width)
|
||||
{
|
||||
return m_Width.GetValue(width);
|
||||
}
|
||||
|
||||
public float GetOffset(float total)
|
||||
{
|
||||
return m_Offset.GetValue(total);
|
||||
}
|
||||
|
||||
public float GetOffset()
|
||||
{
|
||||
return m_Offset.value;
|
||||
}
|
||||
}
|
||||
}
|
||||
63
Runtime/Component/Child/MLValue.cs
Normal file
63
Runtime/Component/Child/MLValue.cs
Normal file
@@ -0,0 +1,63 @@
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace XCharts.Runtime
|
||||
{
|
||||
/// <summary>
|
||||
/// 多样式数值。
|
||||
/// </summary>
|
||||
[Since("v3.8.0")]
|
||||
[System.Serializable]
|
||||
public class MLValue : ChildComponent
|
||||
{
|
||||
public enum Type
|
||||
{
|
||||
/// <summary>
|
||||
/// Percent form.
|
||||
/// |百分比形式。
|
||||
/// </summary>
|
||||
Percent,
|
||||
/// <summary>
|
||||
/// Absolute form.
|
||||
/// |绝对值形式。
|
||||
/// </summary>
|
||||
Absolute,
|
||||
/// <summary>
|
||||
/// Extra form.
|
||||
/// |额外形式。
|
||||
/// </summary>
|
||||
Extra
|
||||
}
|
||||
[SerializeField] private Type m_Type;
|
||||
[SerializeField] private float m_Value;
|
||||
|
||||
public Type type { get { return m_Type; } set { m_Type = value; } }
|
||||
public float value { get { return m_Value; } set { m_Value = value; } }
|
||||
|
||||
public MLValue(Type type, float value)
|
||||
{
|
||||
m_Type = type;
|
||||
m_Value = value;
|
||||
}
|
||||
|
||||
public MLValue(float value)
|
||||
{
|
||||
m_Type = Type.Percent;
|
||||
m_Value = value;
|
||||
}
|
||||
|
||||
public float GetValue(float total)
|
||||
{
|
||||
switch (m_Type)
|
||||
{
|
||||
case Type.Percent:
|
||||
return m_Value * total;
|
||||
case Type.Absolute:
|
||||
return m_Value;
|
||||
case Type.Extra:
|
||||
return total + m_Value;
|
||||
default: return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Runtime/Component/Child/MLValue.cs.meta
Normal file
11
Runtime/Component/Child/MLValue.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 10f15d7e58cf24fa6a1986793ba2a36b
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -53,7 +53,7 @@ namespace XCharts.Runtime
|
||||
if (m_LegendEnter)
|
||||
{
|
||||
serie.context.pointerEnter = true;
|
||||
serie.interact.SetValue(ref needInteract, lineWidth, true, serie.animation.interaction.widthRate);
|
||||
serie.interact.SetValue(ref needInteract, lineWidth, true, serie.animation.interaction.GetWidth(lineWidth));
|
||||
for (int i = 0; i < serie.dataCount; i++)
|
||||
{
|
||||
var serieData = serie.data[i];
|
||||
|
||||
@@ -53,7 +53,7 @@ namespace XCharts.Runtime
|
||||
if (m_LegendEnter)
|
||||
{
|
||||
serie.context.pointerEnter = true;
|
||||
serie.interact.SetValue(ref needInteract, lineWidth, true, serie.animation.interaction.widthRate);
|
||||
serie.interact.SetValue(ref needInteract, lineWidth, true, serie.animation.interaction.GetWidth(lineWidth));
|
||||
for (int i = 0; i < serie.dataCount; i++)
|
||||
{
|
||||
var serieData = serie.data[i];
|
||||
|
||||
@@ -61,7 +61,7 @@ namespace XCharts.Runtime
|
||||
if (m_LegendEnter)
|
||||
{
|
||||
serie.context.pointerEnter = true;
|
||||
serie.interact.SetValue(ref needInteract, lineWidth, true, serie.animation.interaction.widthRate);
|
||||
serie.interact.SetValue(ref needInteract, lineWidth, true, serie.animation.interaction.GetWidth(lineWidth));
|
||||
for (int i = 0; i < serie.dataCount; i++)
|
||||
{
|
||||
var serieData = serie.data[i];
|
||||
@@ -73,7 +73,7 @@ namespace XCharts.Runtime
|
||||
else if (serie.context.isTriggerByAxis)
|
||||
{
|
||||
serie.context.pointerEnter = false;
|
||||
serie.interact.SetValue(ref needInteract, lineWidth, true, serie.animation.interaction.widthRate);
|
||||
serie.interact.SetValue(ref needInteract, lineWidth, true, serie.animation.interaction.GetWidth(lineWidth));
|
||||
for (int i = 0; i < serie.dataCount; i++)
|
||||
{
|
||||
var serieData = serie.data[i];
|
||||
@@ -116,7 +116,7 @@ namespace XCharts.Runtime
|
||||
needInteract = true;
|
||||
}
|
||||
if (serie.context.pointerItemDataIndex >= 0)
|
||||
serie.interact.SetValue(ref needInteract, lineWidth, true, serie.animation.interaction.widthRate);
|
||||
serie.interact.SetValue(ref needInteract, lineWidth, true, serie.animation.interaction.GetWidth(lineWidth));
|
||||
else
|
||||
serie.interact.SetValue(ref needInteract, lineWidth);
|
||||
}
|
||||
|
||||
@@ -53,7 +53,7 @@ namespace XCharts.Runtime
|
||||
if (m_LegendEnter)
|
||||
{
|
||||
serie.context.pointerEnter = true;
|
||||
serie.interact.SetValue(ref needInteract, lineWidth, true, serie.animation.interaction.widthRate);
|
||||
serie.interact.SetValue(ref needInteract, lineWidth, true, serie.animation.interaction.GetWidth(lineWidth));
|
||||
for (int i = 0; i < serie.dataCount; i++)
|
||||
{
|
||||
var serieData = serie.data[i];
|
||||
|
||||
@@ -72,7 +72,7 @@ namespace XCharts.Runtime
|
||||
if (m_LegendEnter)
|
||||
{
|
||||
serie.context.pointerEnter = true;
|
||||
serie.interact.SetValue(ref needInteract, lineWidth, true, serie.animation.interaction.widthRate);
|
||||
serie.interact.SetValue(ref needInteract, lineWidth, true, serie.animation.interaction.GetWidth(lineWidth));
|
||||
for (int i = 0; i < serie.dataCount; i++)
|
||||
{
|
||||
var serieData = serie.data[i];
|
||||
@@ -84,7 +84,7 @@ namespace XCharts.Runtime
|
||||
else if (serie.context.isTriggerByAxis)
|
||||
{
|
||||
serie.context.pointerEnter = true;
|
||||
serie.interact.SetValue(ref needInteract, lineWidth, true, serie.animation.interaction.widthRate);
|
||||
serie.interact.SetValue(ref needInteract, lineWidth, true, serie.animation.interaction.GetWidth(lineWidth));
|
||||
for (int i = 0; i < serie.dataCount; i++)
|
||||
{
|
||||
var serieData = serie.data[i];
|
||||
|
||||
@@ -229,23 +229,24 @@ namespace XCharts.Runtime
|
||||
serie.context.outsideRadius;
|
||||
|
||||
var offset = 0f;
|
||||
var interactOffset = serie.animation.interaction.GetOffset(serie.context.outsideRadius);
|
||||
if (serie.pieClickOffset && (serieData.selected || serieData.context.selected))
|
||||
{
|
||||
offset += serie.animation.interaction.offset;
|
||||
offset += interactOffset;
|
||||
}
|
||||
if (offset > 0)
|
||||
{
|
||||
serieData.context.outsideRadius += serie.animation.interaction.offset;
|
||||
serieData.context.outsideRadius += interactOffset;
|
||||
var currRad = serieData.context.halfAngle * Mathf.Deg2Rad;
|
||||
var currSin = Mathf.Sin(currRad);
|
||||
var currCos = Mathf.Cos(currRad);
|
||||
serieData.context.offsetRadius = 0;
|
||||
if (serie.pieClickOffset && (serieData.selected || serieData.context.selected))
|
||||
{
|
||||
serieData.context.offsetRadius += serie.animation.interaction.offset;
|
||||
serieData.context.offsetRadius += interactOffset;
|
||||
if (serieData.context.insideRadius > 0)
|
||||
{
|
||||
serieData.context.insideRadius += serie.animation.interaction.offset;
|
||||
serieData.context.insideRadius += interactOffset;
|
||||
}
|
||||
}
|
||||
serieData.context.offsetCenter = new Vector3(
|
||||
@@ -512,7 +513,8 @@ namespace XCharts.Runtime
|
||||
return -1;
|
||||
|
||||
var dist = Vector2.Distance(local, serie.context.center);
|
||||
var maxRadius = serie.context.outsideRadius + 3 * serie.animation.interaction.offset;
|
||||
var interactOffset = serie.animation.interaction.GetOffset(serie.context.outsideRadius);
|
||||
var maxRadius = serie.context.outsideRadius + 2 * interactOffset;
|
||||
if (dist < serie.context.insideRadius || dist > maxRadius)
|
||||
return -1;
|
||||
|
||||
|
||||
@@ -688,7 +688,7 @@ namespace XCharts.Runtime
|
||||
{
|
||||
case SerieState.Emphasis:
|
||||
case SerieState.Select:
|
||||
size *= serie.animation.interaction.radiusRate;
|
||||
size = serie.animation.interaction.GetRadius(size);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
|
||||
Reference in New Issue
Block a user