UI update 02

This commit is contained in:
2026-06-30 21:21:30 +08:00
parent b2a1e307a4
commit f62f643cfc
1666 changed files with 211081 additions and 22799 deletions
@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 9f827513754e8436bbc63e64c5b5e6c3
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,506 @@
using System;
using UnityEngine;
namespace XCharts.Runtime
{
/// <summary>
/// the animation info.
/// ||动画配置参数。
/// </summary>
[Since("v3.8.0")]
[System.Serializable]
public class AnimationInfo
{
[SerializeField][Since("v3.8.0")] private bool m_Enable = true;
[SerializeField][Since("v3.8.0")] private bool m_Reverse = false;
[SerializeField][Since("v3.8.0")] private float m_Delay = 0;
[SerializeField][Since("v3.8.0")] private float m_Duration = 1000;
[SerializeField][Since("v3.14.0")] private float m_Speed = 0;
public AnimationInfoContext context = new AnimationInfoContext();
/// <summary>
/// whether enable animation.
/// ||是否开启动画效果。
/// </summary>
public bool enable { get { return m_Enable; } set { m_Enable = value; } }
/// <summary>
/// whether enable reverse animation.
/// ||是否开启反向动画效果。
/// </summary>
public bool reverse { get { return m_Reverse; } set { m_Reverse = value; } }
/// <summary>
/// the delay time before animation start.
/// ||动画开始前的延迟时间。
/// </summary>
public float delay { get { return m_Delay; } set { m_Delay = value; } }
/// <summary>
/// the duration of animation. Default is used to calculate the speed of animation. It can also be specified by speed.
/// ||动画的时长。默认用于计算动画的速度。也可以通过speed指定速度。
/// </summary>
public float duration { get { return m_Duration; } set { m_Duration = value; } }
/// <summary>
/// the speed of animation. When speed is specified, duration will be invalid. Default is 0, which means no speed specified.
/// ||动画的速度。当指定speed时,duration将失效。默认为0,表示不指定速度。
/// </summary>
public float speed { get { return m_Speed; } set { m_Speed = value; } }
/// <summary>
/// the callback function of animation start.
/// ||动画开始的回调。
/// </summary>
public Action OnAnimationStart { get; set; }
/// <summary>
/// the callback function of animation end.
/// ||动画结束的回调。
/// </summary>
public Action OnAnimationEnd { get; set; }
/// <summary>
/// the delegate function of animation delay.
/// ||动画延迟的委托函数。
/// </summary>
public AnimationDelayFunction delayFunction { get; set; }
/// <summary>
/// the delegate function of animation duration.
/// ||动画时长的委托函数。
/// </summary>
public AnimationDurationFunction durationFunction { get; set; }
/// <summary>
/// Reset animation.
/// ||重置动画。
/// </summary>
public void Reset()
{
if (!enable) return;
context.init = false;
context.start = false;
context.pause = false;
context.end = false;
context.startTime = 0;
context.currProgress = 0;
context.destProgress = 0;
context.totalProgress = 0;
context.sizeProgress = 0;
context.currPointIndex = 0;
context.currPoint = Vector3.zero;
context.destPoint = Vector3.zero;
context.dataCurrProgress.Clear();
context.dataDestProgress.Clear();
}
/// <summary>
/// Start animation.
/// ||开始动画。
/// </summary>
/// <param name="reset">是否重置上一次的参数</param>
public void Start(bool reset = true)
{
if (!enable) return;
if (context.start)
{
context.pause = false;
return;
}
context.init = false;
context.start = true;
context.end = false;
context.pause = false;
context.startTime = Time.time;
if (reset)
{
context.currProgress = 0;
context.destProgress = 1;
context.totalProgress = 0;
context.sizeProgress = 0;
context.dataCurrProgress.Clear();
context.dataDestProgress.Clear();
}
if (OnAnimationStart != null)
{
OnAnimationStart();
}
}
/// <summary>
/// Pause animation.
/// ||暂停动画。
/// </summary>
public void Pause()
{
if (!enable) return;
if (!context.start || context.end) return;
context.pause = true;
}
/// <summary>
/// Resume animation.
/// ||恢复动画。
/// </summary>
public void Resume()
{
if (!enable) return;
if (!context.pause) return;
context.pause = false;
}
/// <summary>
/// End animation.
/// ||结束动画。
/// </summary>
public void End()
{
if (!enable) return;
if (!context.start || context.end) return;
context.init = false;
context.start = false;
context.end = true;
context.currPointIndex = context.destPointIndex;
context.startTime = Time.time;
if (OnAnimationEnd != null)
{
OnAnimationEnd();
}
}
/// <summary>
/// Initialize animation.
/// ||初始化动画。
/// </summary>
/// <param name="curr">当前进度</param>
/// <param name="dest">目标进度</param>
/// <param name="totalPointIndex">目标索引</param>
/// <returns></returns>
public bool Init(float curr, float dest, int totalPointIndex)
{
if (!enable || !context.start) return false;
context.totalProgress = dest - curr;
context.destPointIndex = totalPointIndex;
if (reverse)
{
if (!context.init) context.currProgress = dest;
context.destProgress = curr;
}
else
{
if (!context.init) context.currProgress = curr;
context.destProgress = dest;
}
context.init = true;
return true;
}
/// <summary>
/// Whether animation is finish.
/// ||动画是否结束。
/// </summary>
public bool IsFinish()
{
if (!context.start) return true;
if (context.end) return true;
if (context.pause) return false;
if (!context.init) return false;
return m_Reverse ? context.currProgress <= context.destProgress
: context.currProgress >= context.destProgress;
}
/// <summary>
/// Whether animation is in delay.
/// ||动画是否在延迟中。
/// </summary>
public bool IsInDelay()
{
if (!context.start)
return false;
else
return m_Delay > 0 && Time.time - context.startTime < m_Delay / 1000;
}
/// <summary>
/// Whether animation is in index delay.
/// ||动画是否在索引延迟中。
/// </summary>
/// <param name="dataIndex"></param>
/// <returns></returns>
public bool IsInIndexDelay(int dataIndex)
{
if (context.start)
return Time.time - context.startTime < GetIndexDelay(dataIndex) / 1000f;
else
return false;
}
/// <summary>
/// Get animation delay.
/// ||获取动画延迟。
/// </summary>
/// <param name="dataIndex"></param>
/// <returns></returns>
public float GetIndexDelay(int dataIndex)
{
if (!context.start) return 0;
if (delayFunction != null)
return delayFunction(dataIndex);
return delay;
}
internal float GetCurrAnimationDuration(int dataIndex = -1)
{
if (dataIndex >= 0)
{
if (context.start && durationFunction != null)
return durationFunction(dataIndex) / 1000f;
}
return m_Duration > 0 ? m_Duration / 1000 : 1f;
}
internal void SetDataCurrProgress(int index, float state)
{
context.dataCurrProgress[index] = state;
}
internal float GetDataCurrProgress(int index, float initValue, float destValue, ref bool isBarEnd)
{
if (IsInDelay())
{
isBarEnd = false;
return initValue;
}
var c1 = !context.dataCurrProgress.ContainsKey(index);
var c2 = !context.dataDestProgress.ContainsKey(index);
if (c1 || c2)
{
if (c1)
context.dataCurrProgress.Add(index, initValue);
if (c2)
context.dataDestProgress.Add(index, destValue);
isBarEnd = false;
}
else
{
isBarEnd = context.dataCurrProgress[index] == context.dataDestProgress[index];
}
return context.dataCurrProgress[index];
}
internal void CheckProgress(double total, bool m_UnscaledTime)
{
if (!context.start || !context.init || context.pause) return;
if (IsInDelay()) return;
var delta = GetDelta(total, m_UnscaledTime);
if (reverse)
{
context.currProgress -= delta;
if (context.currProgress <= context.destProgress)
{
context.currProgress = context.destProgress;
End();
}
}
else
{
context.currProgress += delta;
if (context.currProgress >= context.destProgress)
{
context.currProgress = context.destProgress;
End();
}
}
}
internal float CheckItemProgress(int dataIndex, float destProgress, ref bool isEnd, float startProgress, bool m_UnscaledTime)
{
if (m_Reverse)
{
var temp = startProgress;
startProgress = destProgress;
destProgress = temp;
}
var currHig = GetDataCurrProgress(dataIndex, startProgress, destProgress, ref isEnd);
if (IsFinish())
{
return destProgress;
}
else if (IsInDelay() || IsInIndexDelay(dataIndex))
{
return startProgress;
}
else if (context.pause)
{
return currHig;
}
else
{
var delta = GetDelta(destProgress - startProgress, m_UnscaledTime);
currHig += delta;
if (reverse)
{
if ((destProgress > 0 && currHig <= 0) || (destProgress < 0 && currHig >= 0))
{
currHig = 0;
isEnd = true;
}
}
else
{
if ((destProgress - startProgress > 0 && currHig > destProgress) ||
(destProgress - startProgress < 0 && currHig < destProgress))
{
currHig = destProgress;
isEnd = true;
}
}
SetDataCurrProgress(dataIndex, currHig);
return currHig;
}
}
internal void CheckSymbol(float dest, bool m_UnscaledTime)
{
if (!context.start || !context.init || context.pause) return;
if (IsInDelay())
return;
var delta = GetDelta(dest, m_UnscaledTime);
if (reverse)
{
context.sizeProgress -= delta;
if (context.sizeProgress < 0)
context.sizeProgress = 0;
}
else
{
context.sizeProgress += delta;
if (context.sizeProgress > dest)
context.sizeProgress = dest;
}
}
private float GetDelta(double total, bool unscaledTime)
{
if (m_Speed > 0)
{
context.currDuration = (float)total / m_Speed;
return (float)(m_Speed * (unscaledTime ? Time.unscaledDeltaTime : Time.deltaTime));
}
else
{
context.currDuration = 0;
return (float)(total / GetCurrAnimationDuration() * (unscaledTime ? Time.unscaledDeltaTime : Time.deltaTime));
}
}
}
/// <summary>
/// Fade in animation.
/// ||淡入动画。
/// </summary>
[Since("v3.8.0")]
[System.Serializable]
public class AnimationFadeIn : AnimationInfo
{
}
/// <summary>
/// Fade out animation.
/// ||淡出动画。
/// </summary>
[Since("v3.8.0")]
[System.Serializable]
public class AnimationFadeOut : AnimationInfo
{
}
/// <summary>
/// Data change animation.
/// ||数据变更动画。
/// </summary>
[Since("v3.8.0")]
[System.Serializable]
public class AnimationChange : AnimationInfo
{
}
/// <summary>
/// Data addition animation.
/// ||数据新增动画。
/// </summary>
[Since("v3.8.0")]
[System.Serializable]
public class AnimationAddition : AnimationInfo
{
}
/// <summary>
/// Data hiding animation.
/// ||数据隐藏动画。
/// </summary>
[Since("v3.8.0")]
[System.Serializable]
public class AnimationHiding : AnimationInfo
{
}
/// <summary>
/// Interactive animation of charts.
/// ||交互动画。
/// </summary>
[Since("v3.8.0")]
[System.Serializable]
public class AnimationInteraction : AnimationInfo
{
[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 mlvalue of width.
/// ||宽度的多样式数值。
/// </summary>
public MLValue width { get { return m_Width; } set { m_Width = value; } }
/// <summary>
/// the mlvalue of radius.
/// ||半径的多样式数值。
/// </summary>
public MLValue radius { get { return m_Radius; } set { m_Radius = value; } }
/// <summary>
/// the mlvalue of offset. Such as the offset of the pie chart when the sector is selected.
/// ||交互的多样式数值。如饼图的扇形选中时的偏移。
/// </summary>
public MLValue offset { get { return m_Offset; } set { m_Offset = value; } }
public float GetRadius(float radius)
{
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;
}
}
/// <summary>
/// Data exchange animation. Generally used for animation of data sorting.
/// ||数据交换动画。一般用于图表数据排序时顺序变化的动画。
/// </summary>
[Since("v3.15.0")]
[System.Serializable]
public class AnimationExchange : AnimationInfo
{
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: ae54b92d6276445ac9524b598bfb6e84
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,26 @@
using System;
using System.Collections.Generic;
using UnityEngine;
namespace XCharts.Runtime
{
public sealed class AnimationInfoContext
{
public bool init;
public bool start;
public bool pause;
public bool end;
public float startTime;
public float currProgress;
public float destProgress;
public float totalProgress;
public float sizeProgress;
public int currPointIndex;
public int destPointIndex;
public float currDuration;
public Vector3 currPoint;
public Vector3 destPoint;
public Dictionary<int, float> dataCurrProgress = new Dictionary<int, float>();
public Dictionary<int, float> dataDestProgress = new Dictionary<int, float>();
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 023c7390605c34a72b13f5db7a647f06
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,630 @@
using System;
using System.Collections.Generic;
using UnityEngine;
namespace XCharts.Runtime
{
public enum AnimationType
{
/// <summary>
/// he default. An animation playback mode will be selected according to the actual situation.
/// ||默认。内部会根据实际情况选择一种动画播放方式。
/// </summary>
Default,
/// <summary>
/// Play the animation from left to right.
/// ||从左往右播放动画。
/// </summary>
LeftToRight,
/// <summary>
/// Play the animation from bottom to top.
/// ||从下往上播放动画。
/// </summary>
BottomToTop,
/// <summary>
/// Play animations from the inside out.
/// ||由内到外播放动画。
/// </summary>
InsideOut,
/// <summary>
/// Play the animation along the path.
/// ||沿着路径播放动画。当折线图从左到右无序或有折返时,可以使用该模式。
/// </summary>
AlongPath,
/// <summary>
/// Play the animation clockwise.
/// ||顺时针播放动画。
/// </summary>
Clockwise,
}
public enum AnimationEasing
{
Linear,
}
/// <summary>
/// the animation of serie. support animation type: fadeIn, fadeOut, change, addition, exchange.
/// ||动画组件,用于控制图表的动画播放。支持配置五种动画表现:FadeIn(渐入动画),FadeOut(渐出动画),Change(变更动画),Addition(新增动画),Interaction(交互动画),Exchange(交换动画)。
/// 按作用的对象可以分为两类:SerieAnimation(系列动画)和DataAnimation(数据动画)。
/// </summary>
[System.Serializable]
public class AnimationStyle : ChildComponent
{
[SerializeField] private bool m_Enable = true;
[SerializeField] private AnimationType m_Type;
[SerializeField] private AnimationEasing m_Easting;
[SerializeField] private int m_Threshold = 2000;
[SerializeField][Since("v3.4.0")] private bool m_UnscaledTime;
[SerializeField][Since("v3.8.0")] private AnimationFadeIn m_FadeIn = new AnimationFadeIn();
[SerializeField][Since("v3.8.0")] private AnimationFadeOut m_FadeOut = new AnimationFadeOut() { reverse = true };
[SerializeField][Since("v3.8.0")] private AnimationChange m_Change = new AnimationChange() { duration = 500 };
[SerializeField][Since("v3.8.0")] private AnimationAddition m_Addition = new AnimationAddition() { duration = 500 };
[SerializeField][Since("v3.8.0")] private AnimationHiding m_Hiding = new AnimationHiding() { duration = 500 };
[SerializeField][Since("v3.8.0")] private AnimationInteraction m_Interaction = new AnimationInteraction() { duration = 250 };
[SerializeField][Since("v3.15.0")] private AnimationExchange m_Exchange = new AnimationExchange() { duration = 250 };
[Obsolete("Use animation.fadeIn.delayFunction instead.", true)]
public AnimationDelayFunction fadeInDelayFunction;
[Obsolete("Use animation.fadeIn.durationFunction instead.", true)]
public AnimationDurationFunction fadeInDurationFunction;
[Obsolete("Use animation.fadeOut.delayFunction instead.", true)]
public AnimationDelayFunction fadeOutDelayFunction;
[Obsolete("Use animation.fadeOut.durationFunction instead.", true)]
public AnimationDurationFunction fadeOutDurationFunction;
[Obsolete("Use animation.fadeIn.OnAnimationEnd() instead.", true)]
public Action fadeInFinishCallback { get; set; }
[Obsolete("Use animation.fadeOut.OnAnimationEnd() instead.", true)]
public Action fadeOutFinishCallback { get; set; }
public AnimationStyleContext context = new AnimationStyleContext();
/// <summary>
/// Whether to enable animation.
/// ||是否开启动画效果。
/// </summary>
public bool enable { get { return m_Enable; } set { m_Enable = value; } }
/// <summary>
/// The type of animation.
/// ||动画类型。
/// </summary>
public AnimationType type
{
get { return m_Type; }
set
{
m_Type = value;
if (m_Type != AnimationType.Default)
{
context.type = m_Type;
}
}
}
/// <summary>
/// Whether to set graphic number threshold to animation. Animation will be disabled when graphic number is larger than threshold.
/// ||是否开启动画的阈值,当单个系列显示的图形数量大于这个阈值时会关闭动画。
/// </summary>
public int threshold { get { return m_Threshold; } set { m_Threshold = value; } }
/// <summary>
/// Animation updates independently of Time.timeScale.
/// ||动画是否受TimeScaled的影响。默认为 false 受TimeScaled的影响。
/// </summary>
public bool unscaledTime { get { return m_UnscaledTime; } set { m_UnscaledTime = value; } }
/// <summary>
/// Fade in animation configuration.
/// ||渐入动画配置。
/// </summary>
public AnimationFadeIn fadeIn { get { return m_FadeIn; } }
/// <summary>
/// Fade out animation configuration.
/// ||渐出动画配置。
/// </summary>
public AnimationFadeOut fadeOut { get { return m_FadeOut; } }
/// <summary>
/// Update data animation configuration.
/// ||数据变更动画配置。
/// </summary>
public AnimationChange change { get { return m_Change; } }
/// <summary>
/// Add data animation configuration.
/// ||数据新增动画配置。
/// </summary>
public AnimationAddition addition { get { return m_Addition; } }
/// <summary>
/// Data hiding animation configuration.
/// ||数据隐藏动画配置。
/// </summary>
public AnimationHiding hiding { get { return m_Hiding; } }
/// <summary>
/// Interaction animation configuration.
/// ||交互动画配置。
/// </summary>
public AnimationInteraction interaction { get { return m_Interaction; } }
/// <summary>
/// Exchange animation configuration. Valid in sort bar chart.
/// ||交换动画配置。如在排序柱图中有效。
/// </summary>
public AnimationExchange exchange { get { return m_Exchange; } }
private Vector3 m_LinePathLastPos;
private List<AnimationInfo> m_Animations;
private List<AnimationInfo> animations
{
get
{
if (m_Animations == null)
{
m_Animations = new List<AnimationInfo>
{
m_FadeIn,
m_FadeOut,
m_Change,
m_Addition,
m_Hiding,
m_Exchange
};
}
return m_Animations;
}
}
/// <summary>
/// The actived animation.
/// ||当前激活的动画。
/// </summary>
public AnimationInfo activedAnimation
{
get
{
foreach (var anim in animations)
{
if (anim.context.start) return anim;
}
return null;
}
}
/// <summary>
/// Start fadein animation.
/// ||开始渐入动画。
/// </summary>
public void FadeIn()
{
if (m_FadeOut.context.start) return;
m_FadeIn.Start();
}
/// <summary>
/// Restart the actived animation.
/// ||重启当前激活的动画。
/// </summary>
public void Restart()
{
var anim = activedAnimation;
Reset();
if (anim != null)
{
anim.Start();
}
}
/// <summary>
/// Start fadeout animation.
/// ||开始渐出动画。
/// </summary>
public void FadeOut()
{
m_FadeOut.Start();
}
/// <summary>
/// Start additon animation.
/// ||开始数据新增动画。
/// </summary>
public void Addition()
{
if (!enable) return;
if (!m_FadeIn.context.start && !m_FadeOut.context.start)
{
m_Addition.Start(false);
}
}
/// <summary>
/// Pause all animations.
/// ||暂停所有动画。
/// </summary>
public void Pause()
{
foreach (var anim in animations)
{
anim.Pause();
}
}
/// <summary>
/// Resume all animations.
/// ||恢复所有动画。
/// </summary>
public void Resume()
{
foreach (var anim in animations)
{
anim.Resume();
}
}
/// <summary>
/// Reset all animations.
/// </summary>
public void Reset()
{
foreach (var anim in animations)
{
anim.Reset();
}
}
/// <summary>
/// Initialize animation configuration.
/// ||初始化动画配置。
/// </summary>
/// <param name="curr">当前进度</param>
/// <param name="dest">目标进度</param>
public void InitProgress(float curr, float dest)
{
var anim = activedAnimation;
if (anim == null) return;
var isAddedAnim = anim is AnimationAddition;
if (IsSerieAnimation())
{
if (isAddedAnim)
{
anim.Init(anim.context.currPointIndex, dest, (int)dest - 1);
}
else
{
m_Addition.context.currPointIndex = (int)dest - 1;
anim.Init(curr, dest, (int)dest - 1);
}
}
else
{
anim.Init(curr, dest, 0);
}
}
/// <summary>
/// Initialize animation configuration.
/// ||初始化动画配置。
/// </summary>
/// <param name="paths">路径坐标点列表</param>
/// <param name="isY">是Y轴还是X轴</param>
public void InitProgress(List<Vector3> paths, bool isY)
{
if (paths.Count < 1) return;
var anim = activedAnimation;
if (anim == null)
{
m_Addition.context.currPointIndex = paths.Count - 1;
return;
}
var isAddedAnim = anim is AnimationAddition;
var startIndex = 0;
if (isAddedAnim)
{
startIndex = anim.context.currPointIndex == paths.Count - 1 ?
paths.Count - 2 :
anim.context.currPointIndex;
if (startIndex < 0 || startIndex >= paths.Count - 1) return;
}
else
{
m_Addition.context.currPointIndex = paths.Count - 1;
}
var sp = paths[startIndex];
var ep = paths[paths.Count - 1];
var currDetailProgress = isY ? sp.y : sp.x;
var totalDetailProgress = isY ? ep.y : ep.x;
if (context.type == AnimationType.AlongPath)
{
currDetailProgress = 0;
totalDetailProgress = 0;
var lp = sp;
for (int i = 1; i < paths.Count; i++)
{
var np = paths[i];
totalDetailProgress += Vector3.Distance(np, lp);
lp = np;
if (startIndex > 0 && i == startIndex)
currDetailProgress = totalDetailProgress;
}
m_LinePathLastPos = sp;
context.currentPathDistance = 0;
}
if (sp == anim.context.currPoint && ep == anim.context.destPoint)
{
return;
}
if (anim.Init(currDetailProgress, totalDetailProgress, paths.Count - 1))
{
anim.context.currPoint = sp;
anim.context.destPoint = ep;
}
}
public bool IsEnd()
{
foreach (var animation in animations)
{
if (animation.context.start)
return animation.context.end;
}
return m_FadeIn.context.end;
}
public bool IsFinish()
{
#if UNITY_EDITOR
if (!Application.isPlaying)
return true;
#endif
if (!m_Enable)
return true;
var animation = activedAnimation;
if (animation != null && animation.context.end)
{
return true;
}
if (IsSerieAnimation())
{
if (m_FadeOut.context.start)
{
return m_FadeOut.context.currProgress <= m_FadeOut.context.destProgress;
}
else if (m_Addition.context.start)
{
return m_Addition.context.currProgress >= m_Addition.context.destProgress;
}
else
{
return m_FadeIn.context.currProgress >= m_FadeIn.context.destProgress;
}
}
else if (IsDataAnimation())
{
if (animation == null) return true;
else return animation.context.end;
}
return true;
}
public bool IsInDelay()
{
var anim = activedAnimation;
if (anim != null)
return anim.IsInDelay();
return false;
}
/// <summary>
/// whther animaiton is data animation. BottomToTop and InsideOut are data animation.
/// ||是否为数据动画。BottomToTop和InsideOut类型的为数据动画。
/// </summary>
public bool IsDataAnimation()
{
return context.type == AnimationType.BottomToTop || context.type == AnimationType.InsideOut;
}
/// <summary>
/// whther animaiton is serie animation. LeftToRight, AlongPath and Clockwise are serie animation.
/// ||是否为系列动画。LeftToRight、AlongPath和Clockwise类型的为系列动画。
/// </summary>
public bool IsSerieAnimation()
{
return context.type == AnimationType.LeftToRight ||
context.type == AnimationType.AlongPath || context.type == AnimationType.Clockwise;
}
public bool CheckDetailBreak(float detail)
{
if (!IsSerieAnimation())
return false;
foreach (var animation in animations)
{
if (animation.context.start)
return !IsFinish() && detail > animation.context.currProgress;
}
return false;
}
public bool CheckDetailBreak(Vector3 pos, bool isYAxis)
{
if (!IsSerieAnimation())
return false;
if (IsFinish())
return false;
if (context.type == AnimationType.AlongPath)
{
context.currentPathDistance += Vector3.Distance(pos, m_LinePathLastPos);
m_LinePathLastPos = pos;
return CheckDetailBreak(context.currentPathDistance);
}
else
{
if (isYAxis)
return pos.y > GetCurrDetail();
else
return pos.x > GetCurrDetail();
}
}
public void CheckProgress()
{
if (IsDataAnimation() && context.isAllItemAnimationEnd)
{
foreach (var animation in animations)
{
animation.End();
}
return;
}
foreach (var animation in animations)
{
animation.CheckProgress(animation.context.totalProgress, m_UnscaledTime);
}
}
public void CheckProgress(double total)
{
if (IsFinish())
return;
foreach (var animation in animations)
{
animation.CheckProgress(total, m_UnscaledTime);
}
}
internal float CheckItemProgress(int dataIndex, float destProgress, ref bool isEnd, float startProgress = 0)
{
isEnd = false;
var anim = activedAnimation;
if (anim == null)
{
isEnd = true;
return destProgress;
}
return anim.CheckItemProgress(dataIndex, destProgress, ref isEnd, startProgress, m_UnscaledTime);
}
public void CheckSymbol(float dest)
{
m_FadeIn.CheckSymbol(dest, m_UnscaledTime);
m_FadeOut.CheckSymbol(dest, m_UnscaledTime);
}
public float GetSysmbolSize(float dest)
{
#if UNITY_EDITOR
if (!Application.isPlaying)
return dest;
#endif
if (!enable)
return dest;
if (IsEnd())
return m_FadeOut.context.start ? 0 : dest;
return m_FadeOut.context.start ? m_FadeOut.context.sizeProgress : m_FadeIn.context.sizeProgress;
}
public float GetCurrDetail()
{
#if UNITY_EDITOR
if (!Application.isPlaying)
{
foreach (var animation in animations)
{
if (animation.context.start)
return animation.context.destProgress;
}
}
#endif
foreach (var animation in animations)
{
if (animation.context.start)
return animation.context.currProgress;
}
return m_FadeIn.context.currProgress;
}
public float GetCurrRate()
{
#if UNITY_EDITOR
if (!Application.isPlaying)
return 1;
#endif
if (!enable || IsEnd())
return 1;
return m_FadeOut.context.start ? m_FadeOut.context.currProgress : m_FadeIn.context.currProgress;
}
public int GetCurrIndex()
{
#if UNITY_EDITOR
if (!Application.isPlaying)
return -1;
#endif
if (!enable)
return -1;
var anim = activedAnimation;
if (anim == null)
return -1;
return (int)anim.context.currProgress;
}
public float GetChangeDuration()
{
if (m_Enable && m_Change.enable)
return m_Change.context.currDuration > 0 ? m_Change.context.currDuration : m_Change.duration;
else
return 0;
}
public float GetExchangeDuration()
{
if (m_Enable && m_Exchange.enable)
return m_Exchange.context.currDuration > 0 ? m_Exchange.context.currDuration : m_Exchange.duration;
else
return 0;
}
public float GetAdditionDuration()
{
if (m_Enable && m_Addition.enable)
return m_Addition.context.currDuration > 0 ? m_Addition.context.currDuration : m_Addition.duration;
else
return 0;
}
public float GetInteractionDuration()
{
if (m_Enable && m_Interaction.enable)
return m_Interaction.context.currDuration > 0 ? m_Interaction.context.currDuration : m_Interaction.duration;
else
return 0;
}
public float GetInteractionRadius(float radius)
{
if (m_Enable && m_Interaction.enable)
return m_Interaction.GetRadius(radius);
else
return radius;
}
public bool HasFadeOut()
{
return enable && m_FadeOut.context.end;
}
public bool IsFadeIn()
{
return enable && m_FadeIn.context.start;
}
public bool IsFadeOut()
{
return enable && m_FadeOut.context.start;
}
public bool CanCheckInteract()
{
return enable && interaction.enable
&& !IsFadeIn() && !IsFadeOut();
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: e31c30f2ef61c48718a626f93307ce92
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,14 @@
using System;
using System.Collections.Generic;
using UnityEngine;
namespace XCharts.Runtime
{
public struct AnimationStyleContext
{
public AnimationType type;
public bool enableSerieDataAddedAnimation;
public float currentPathDistance;
public bool isAllItemAnimationEnd;
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: b3dc504960589413fa6a76267067775c
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,77 @@
using UnityEngine;
using XUGL;
namespace XCharts.Runtime
{
public static class AnimationStyleHelper
{
public static float CheckDataAnimation(BaseChart chart, Serie serie, int dataIndex, float destProgress, float startPorgress = 0)
{
if (!serie.animation.IsDataAnimation())
{
serie.animation.context.isAllItemAnimationEnd = false;
return destProgress;
}
if (serie.animation.IsFinish())
{
serie.animation.context.isAllItemAnimationEnd = false;
return destProgress;
}
var isDataAnimationEnd = true;
var currHig = serie.animation.CheckItemProgress(dataIndex, destProgress, ref isDataAnimationEnd, startPorgress);
if (!isDataAnimationEnd)
{
serie.animation.context.isAllItemAnimationEnd = false;
}
return currHig;
}
public static void UpdateSerieAnimation(Serie serie)
{
var serieType = serie.GetType();
var animationType = AnimationType.LeftToRight;
var enableSerieDataAnimation = true;
if (serieType.IsDefined(typeof(DefaultAnimationAttribute), false))
{
var attribute = serieType.GetAttribute<DefaultAnimationAttribute>();
animationType = attribute.type;
enableSerieDataAnimation = attribute.enableSerieDataAddedAnimation;
}
UpdateAnimationType(serie.animation, animationType, enableSerieDataAnimation);
}
public static void UpdateAnimationType(AnimationStyle animation, AnimationType defaultType, bool enableSerieDataAnimation)
{
animation.context.type = animation.type == AnimationType.Default ?
defaultType :
animation.type;
animation.context.enableSerieDataAddedAnimation = enableSerieDataAnimation;
}
public static bool GetAnimationPosition(AnimationStyle animation, bool isY, Vector3 lp, Vector3 cp, float progress, ref Vector3 ip, ref float rate)
{
if (animation.context.type == AnimationType.AlongPath)
{
var dist = Vector3.Distance(lp, cp);
rate = (dist - animation.context.currentPathDistance + animation.GetCurrDetail()) / dist;
ip = Vector3.Lerp(lp, cp, rate);
return true;
}
else
{
var startPos = isY ? new Vector3(-10000, progress) : new Vector3(progress, -10000);
var endPos = isY ? new Vector3(10000, progress) : new Vector3(progress, 10000);
if (UGLHelper.GetIntersection(lp, cp, startPos, endPos, ref ip))
{
rate = Vector3.Distance(lp, ip) / Vector3.Distance(lp, cp);
return true;
}
else
{
return false;
}
}
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 54cadaee0856b4f7085787fd450eec37
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 194a62edf7ec2484fa2eebbf5bde3e95
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 28b88ca3453f04fbdb23a53b5bcb4bf7
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,53 @@
using System.Collections.Generic;
using UnityEngine;
namespace XCharts.Runtime
{
/// <summary>
/// Angle axis of Polar Coordinate.
/// ||极坐标系的角度轴。
/// </summary>
[System.Serializable]
[RequireChartComponent(typeof(PolarCoord))]
[ComponentHandler(typeof(AngleAxisHandler), true)]
public class AngleAxis : Axis
{
[SerializeField] private float m_StartAngle = 0;
/// <summary>
/// Starting angle of axis. 0 degrees by default, standing for right position of center.
/// ||起始刻度的角度,默认为 0 度,即圆心的正右方。
/// </summary>
public float startAngle
{
get { return m_StartAngle; }
set { if (PropertyUtil.SetStruct(ref m_StartAngle, value)) SetAllDirty(); }
}
public float GetValueAngle(float value)
{
return (value + context.startAngle + 360) % 360;
}
public float GetValueAngle(double value)
{
return (float) (value + context.startAngle + 360) % 360;
}
public override void SetDefaultValue()
{
m_Show = true;
m_Type = AxisType.Value;
m_SplitNumber = 12;
m_StartAngle = 0;
m_BoundaryGap = false;
m_Data = new List<string>(12);
splitLine.show = true;
splitLine.lineStyle.type = LineStyle.Type.Solid;
axisLabel.textLimit.enable = false;
minMaxType = AxisMinMaxType.Custom;
min = 0;
max = 360;
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 787015be923a74e1da4000c7abc2dcdf
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,174 @@
using UnityEngine;
using UnityEngine.UI;
using XUGL;
namespace XCharts.Runtime
{
[UnityEngine.Scripting.Preserve]
internal sealed class AngleAxisHandler : AxisHandler<AngleAxis>
{
public override void InitComponent()
{
InitAngleAxis(component);
}
public override void Update()
{
component.context.startAngle = 90 - component.startAngle;
UpdateAxisMinMaxValue(component);
UpdatePointerValue(component);
}
public override void DrawBase(VertexHelper vh)
{
DrawAngleAxis(vh, component);
}
private void UpdateAxisMinMaxValue(AngleAxis axis, bool updateChart = true)
{
if (axis.IsCategory() || !axis.show) return;
double tempMinValue = 0;
double tempMaxValue = 0;
SeriesHelper.GetYMinMaxValue(chart, axis.polarIndex, axis.inverse, out tempMinValue,
out tempMaxValue, true);
AxisHelper.AdjustMinMaxValue(axis, ref tempMinValue, ref tempMaxValue, true);
if (tempMinValue != axis.context.minValue || tempMaxValue != axis.context.maxValue)
{
axis.UpdateMinMaxValue(tempMinValue, tempMaxValue);
axis.context.offset = 0;
axis.context.lastCheckInverse = axis.inverse;
UpdateAxisTickValueList(axis);
if (updateChart)
{
UpdateAxisLabelText(axis);
chart.RefreshChart();
}
}
}
internal void UpdateAxisLabelText(AngleAxis axis)
{
var runtimeWidth = 360;
if (axis.context.labelObjectList.Count <= 0)
InitAngleAxis(axis);
else
UpdateLabelText(axis, runtimeWidth, null, false);
}
private void InitAngleAxis(AngleAxis axis)
{
var polar = chart.GetChartComponent<PolarCoord>(axis.polarIndex);
if (polar == null) return;
PolarHelper.UpdatePolarCenter(polar, chart.chartPosition, chart.chartWidth, chart.chartHeight);
var radius = polar.context.outsideRadius;
axis.context.labelObjectList.Clear();
axis.context.startAngle = 90 - axis.startAngle;
string objName = component.GetType().Name + axis.index;
var axisObj = ChartHelper.AddObject(objName, chart.transform, chart.chartMinAnchor,
chart.chartMaxAnchor, chart.chartPivot, chart.chartSizeDelta, -1, chart.childrenNodeNames);
axisObj.transform.localPosition = Vector3.zero;
axisObj.SetActive(axis.show);
axisObj.hideFlags = chart.chartHideFlags;
ChartHelper.HideAllObject(axisObj);
var splitNumber = AxisHelper.GetSplitNumber(axis, radius, null);
var totalAngle = axis.context.startAngle;
var total = 360;
var cenPos = polar.context.center;
var txtHig = axis.axisLabel.textStyle.GetFontSize(chart.theme.axis) + 2;
var margin = axis.axisLabel.distance + axis.axisTick.GetLength(chart.theme.axis.tickLength);
var isCategory = axis.IsCategory();
var isPercentStack = SeriesHelper.IsPercentStack<Bar>(chart.series);
for (int i = 0; i < splitNumber; i++)
{
float scaleAngle = AxisHelper.GetScaleWidth(axis, total, i + 1, null);
bool inside = axis.axisLabel.inside;
var labelName = AxisHelper.GetLabelName(axis, total, i, axis.context.minValue, axis.context.maxValue,
null, isPercentStack, chart.useUtc);
var label = ChartHelper.AddAxisLabelObject(splitNumber, i, objName + i, axisObj.transform,
new Vector2(scaleAngle, txtHig), axis,
chart.theme.axis, labelName, Color.clear);
label.text.SetAlignment(axis.axisLabel.textStyle.GetAlignment(TextAnchor.MiddleCenter));
var pos = ChartHelper.GetPos(cenPos, radius + margin,
isCategory ? (totalAngle + scaleAngle / 2) : totalAngle, true);
AxisHelper.AdjustCircleLabelPos(label, pos, cenPos, txtHig, Vector3.zero);
if (i == 0) axis.axisLabel.SetRelatedText(label.text, scaleAngle);
axis.context.labelObjectList.Add(label);
totalAngle += scaleAngle;
}
}
private void DrawAngleAxis(VertexHelper vh, AngleAxis angleAxis)
{
var polar = chart.GetChartComponent<PolarCoord>(angleAxis.polarIndex);
var radius = polar.context.outsideRadius;
var cenPos = polar.context.center;
var total = 360;
var size = AxisHelper.GetScaleNumber(angleAxis, total, null);
var currAngle = angleAxis.context.startAngle;
var tickWidth = angleAxis.axisTick.GetWidth(chart.theme.axis.tickWidth);
var tickLength = angleAxis.axisTick.GetLength(chart.theme.axis.tickLength);
var tickColor = angleAxis.axisTick.GetColor(chart.theme.axis.lineColor);
var lineColor = angleAxis.axisLine.GetColor(chart.theme.axis.lineColor);
var splitLineColor = angleAxis.splitLine.GetColor(chart.theme.axis.splitLineColor);
for (int i = 1; i < size; i++)
{
var scaleWidth = AxisHelper.GetScaleWidth(angleAxis, total, i);
var pos1 = ChartHelper.GetPos(cenPos, polar.context.insideRadius, currAngle, true);
var pos2 = ChartHelper.GetPos(cenPos, polar.context.outsideRadius, currAngle, true);
if (angleAxis.show && angleAxis.splitLine.show)
{
if (angleAxis.splitLine.NeedShow(i - 1, size - 1))
{
var lineWidth = angleAxis.splitLine.GetWidth(chart.theme.axis.splitLineWidth);
UGL.DrawLine(vh, pos1, pos2, lineWidth, splitLineColor);
}
}
if (angleAxis.show && angleAxis.axisTick.show)
{
if ((i == 1 && angleAxis.axisTick.showStartTick) ||
(i == size - 1 && angleAxis.axisTick.showEndTick) ||
(i > 1 && i < size - 1))
{
var tickY = radius + tickLength;
var tickPos = ChartHelper.GetPos(cenPos, tickY, currAngle, true);
UGL.DrawLine(vh, pos2, tickPos, tickWidth, tickColor);
}
}
currAngle += scaleWidth;
}
if (angleAxis.show && angleAxis.axisLine.show)
{
var lineWidth = angleAxis.axisLine.GetWidth(chart.theme.axis.lineWidth);
var outsideRaidus = radius + lineWidth * 2;
UGL.DrawDoughnut(vh, cenPos, radius, outsideRaidus, lineColor, ColorUtil.clearColor32);
if (polar.context.insideRadius > 0)
{
radius = polar.context.insideRadius;
outsideRaidus = radius + lineWidth * 2;
UGL.DrawDoughnut(vh, cenPos, radius, outsideRaidus, lineColor, ColorUtil.clearColor32);
}
}
}
protected override void UpdatePointerValue(Axis axis)
{
var polar = chart.GetChartComponent<PolarCoord>(axis.polarIndex);
if (polar == null)
return;
if (!polar.context.isPointerEnter)
{
axis.context.pointerValue = double.PositiveInfinity;
return;
}
var dir = (chart.pointerPos - new Vector2(polar.context.center.x, polar.context.center.y)).normalized;
var angle = ChartHelper.GetAngle360(Vector2.up, dir);
axis.context.pointerValue = (angle - component.context.startAngle + 360) % 360;
axis.context.pointerLabelPosition = polar.context.center + new Vector3(dir.x, dir.y) * (polar.context.outsideRadius + polar.indicatorLabelOffset);
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 83f228c42435c4619943a2f187c98e7b
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,991 @@
using System;
using System.Collections.Generic;
using UnityEngine;
namespace XCharts.Runtime
{
/// <summary>
/// The axis in rectangular coordinate.
/// ||直角坐标系的坐标轴组件。
/// </summary>
[System.Serializable]
public class Axis : MainComponent
{
/// <summary>
/// the type of axis.
/// ||坐标轴类型。
/// </summary>
public enum AxisType
{
/// <summary>
/// Numerical axis, suitable for continuous data.
/// ||数值轴。适用于连续数据。
/// </summary>
Value,
/// <summary>
/// Category axis, suitable for discrete category data. Data should only be set via data for this type.
/// ||类目轴。适用于离散的类目数据,为该类型时必须通过 data 设置类目数据。serie的数据第0维数据对应坐标轴data的index。
/// </summary>
Category,
/// <summary>
/// Log axis, suitable for log data.
/// ||对数轴。适用于对数数据。
/// </summary>
Log,
/// <summary>
/// Time axis, suitable for continuous time series data.
/// ||时间轴。适用于连续的时序数据。
/// </summary>
Time
}
/// <summary>
/// the type of axis min and max value.
/// ||坐标轴最大最小刻度显示类型。
/// </summary>
public enum AxisMinMaxType
{
/// <summary>
/// 0 - maximum.
/// ||0-最大值。
/// </summary>
Default,
/// <summary>
/// minimum - maximum.
/// ||最小值-最大值。
/// </summary>
MinMax,
/// <summary>
/// Customize the minimum and maximum.
/// ||自定义最小值最大值。
/// </summary>
Custom,
/// <summary>
/// [since("v3.7.0")]minimum - maximum, automatically calculate the appropriate values.
/// ||[since("v3.7.0")]最小值-最大值。自动计算合适的值。
/// </summary>
MinMaxAuto,
}
/// <summary>
/// the position of axis in grid.
/// ||坐标轴在Grid中的位置
/// </summary>
public enum AxisPosition
{
Left,
Right,
Bottom,
Top,
Center
}
[SerializeField] protected bool m_Show = true;
[SerializeField] protected Axis.AxisType m_Type;
[SerializeField] protected Axis.AxisMinMaxType m_MinMaxType;
[SerializeField] protected int m_GridIndex;
[SerializeField] protected int m_PolarIndex;
[SerializeField] protected int m_ParallelIndex;
[SerializeField] protected Axis.AxisPosition m_Position;
[SerializeField] protected float m_Offset;
[SerializeField] protected double m_Min;
[SerializeField] protected double m_Max;
[SerializeField] protected int m_SplitNumber = 0;
[SerializeField] protected double m_Interval = 0;
[SerializeField] protected bool m_BoundaryGap = true;
[SerializeField] protected int m_MaxCache = 0;
[SerializeField] protected float m_LogBase = 10;
[SerializeField] protected bool m_LogBaseE = false;
[SerializeField] protected double m_CeilRate = 0;
[SerializeField] protected bool m_Inverse = false;
[SerializeField] private bool m_Clockwise = true;
[SerializeField] private bool m_InsertDataToHead;
[SerializeField][Since("v3.11.0")] private float m_MinCategorySpacing = 0;
[SerializeField][Since("v3.15.0")] private bool m_MainAxis = false;
[SerializeField] protected List<Sprite> m_Icons = new List<Sprite>();
[SerializeField] protected List<string> m_Data = new List<string>();
[SerializeField] protected AxisLine m_AxisLine = AxisLine.defaultAxisLine;
[SerializeField] protected AxisName m_AxisName = AxisName.defaultAxisName;
[SerializeField] protected AxisTick m_AxisTick = AxisTick.defaultTick;
[SerializeField] protected AxisLabel m_AxisLabel = AxisLabel.defaultAxisLabel;
[SerializeField] protected AxisSplitLine m_SplitLine = AxisSplitLine.defaultSplitLine;
[SerializeField] protected AxisSplitArea m_SplitArea = AxisSplitArea.defaultSplitArea;
[SerializeField] protected AxisAnimation m_Animation = new AxisAnimation();
[SerializeField][Since("v3.2.0")] protected AxisMinorTick m_MinorTick = AxisMinorTick.defaultMinorTick;
[SerializeField][Since("v3.2.0")] protected AxisMinorSplitLine m_MinorSplitLine = AxisMinorSplitLine.defaultMinorSplitLine;
[SerializeField][Since("v3.4.0")] protected LabelStyle m_IndicatorLabel = new LabelStyle() { numericFormatter = "f2" };
public AxisContext context = new AxisContext();
private Action<int, string> m_OnLabelClick;
/// <summary>
/// Callback function when click on the label. Parameters: labelIndex, labelName.
/// ||点击文本标签回调函数。参数:labelIndex, labelName。
/// </summary>
[Since("v3.15.0")]
public Action<int, string> onLabelClick { internal get { return m_OnLabelClick; } set { m_OnLabelClick = value; } }
/// <summary>
/// Whether to show axis.
/// ||是否显示坐标轴。
/// </summary>
public bool show
{
get { return m_Show; }
set { if (PropertyUtil.SetStruct(ref m_Show, value)) SetAllDirty(); }
}
/// <summary>
/// the type of axis.
/// ||坐标轴类型。
/// </summary>
public AxisType type
{
get { return m_Type; }
set { if (PropertyUtil.SetStruct(ref m_Type, value)) SetAllDirty(); }
}
/// <summary>
/// the type of axis minmax.
/// ||坐标轴刻度最大最小值显示类型。
/// </summary>
public AxisMinMaxType minMaxType
{
get { return m_MinMaxType; }
set { if (PropertyUtil.SetStruct(ref m_MinMaxType, value)) SetAllDirty(); }
}
/// <summary>
/// The index of the grid on which the axis are located, by default, is in the first grid.
/// ||坐标轴所在的 grid 的索引,默认位于第一个 grid。
/// </summary>
public int gridIndex
{
get { return m_GridIndex; }
set { if (PropertyUtil.SetStruct(ref m_GridIndex, value)) SetAllDirty(); }
}
/// <summary>
/// The index of the polar on which the axis are located, by default, is in the first polar.
/// ||坐标轴所在的 ploar 的索引,默认位于第一个 polar。
/// </summary>
public int polarIndex
{
get { return m_PolarIndex; }
set { if (PropertyUtil.SetStruct(ref m_PolarIndex, value)) SetAllDirty(); }
}
/// <summary>
/// The index of the parallel on which the axis are located, by default, is in the first parallel.
/// ||坐标轴所在的 parallel 的索引,默认位于第一个 parallel。
/// </summary>
public int parallelIndex
{
get { return m_ParallelIndex; }
set { if (PropertyUtil.SetStruct(ref m_ParallelIndex, value)) SetAllDirty(); }
}
/// <summary>
/// the position of axis in grid.
/// ||坐标轴在Grid中的位置。
/// </summary>
public AxisPosition position
{
get { return m_Position; }
set { if (PropertyUtil.SetStruct(ref m_Position, value)) SetAllDirty(); }
}
/// <summary>
/// the offset of axis from the default position. Useful when the same position has multiple axes.
/// ||坐标轴相对默认位置的偏移。在相同position有多个坐标轴时有用。
/// </summary>
public float offset
{
get { return m_Offset; }
set { if (PropertyUtil.SetStruct(ref m_Offset, value)) SetAllDirty(); }
}
/// <summary>
/// The minimun value of axis.Valid when `minMaxType` is `Custom`
/// ||设定的坐标轴刻度最小值,当minMaxType为Custom时有效。
/// </summary>
public double min
{
get { return m_Min; }
set { if (PropertyUtil.SetStruct(ref m_Min, value)) SetAllDirty(); }
}
/// <summary>
/// The maximum value of axis.Valid when `minMaxType` is `Custom`
/// ||设定的坐标轴刻度最大值,当minMaxType为Custom时有效。
/// </summary>
public double max
{
get { return m_Max; }
set { if (PropertyUtil.SetStruct(ref m_Max, value)) SetAllDirty(); }
}
/// <summary>
/// Number of segments that the axis is split into.
/// ||坐标轴的期望的分割段数。默认为0表示自动分割。
/// </summary>
public int splitNumber
{
get { return m_SplitNumber; }
set { if (PropertyUtil.SetStruct(ref m_SplitNumber, value)) SetAllDirty(); }
}
/// <summary>
/// Compulsively set segmentation interval for axis.This is unavailable for category axis.
/// ||强制设置坐标轴分割间隔。无法在类目轴中使用。
/// </summary>
public double interval
{
get { return m_Interval; }
set { if (PropertyUtil.SetStruct(ref m_Interval, value)) SetAllDirty(); }
}
/// <summary>
/// The boundary gap on both sides of a coordinate axis, which is valid only for category axis with type: 'Category'.
/// ||坐标轴两边是否留白。只对类目轴有效。
/// </summary>
public bool boundaryGap
{
get { return IsCategory() ? m_BoundaryGap : false; }
set { if (PropertyUtil.SetStruct(ref m_BoundaryGap, value)) SetAllDirty(); }
}
/// <summary>
/// Base of logarithm, which is valid only for numeric axes with type: 'Log'.
/// ||对数轴的底数,只在对数轴(type:'Log')中有效。
/// </summary>
public float logBase
{
get { return m_LogBase; }
set
{
if (value <= 0 || value == 1) value = 10;
if (PropertyUtil.SetStruct(ref m_LogBase, value)) SetAllDirty();
}
}
/// <summary>
/// On the log axis, if base e is the natural number, and is true, logBase fails.
/// ||对数轴是否以自然数 e 为底数,为 true 时 logBase 失效。
/// </summary>
public bool logBaseE
{
get { return m_LogBaseE; }
set { if (PropertyUtil.SetStruct(ref m_LogBaseE, value)) SetAllDirty(); }
}
/// <summary>
/// The max number of axis data cache.
/// ||The first data will be remove when the size of axis data is larger then maxCache.
/// ||可缓存的最大数据量。默认为0没有限制,大于0时超过指定值会移除旧数据再插入新数据。
/// </summary>
public int maxCache
{
get { return m_MaxCache; }
set { if (PropertyUtil.SetStruct(ref m_MaxCache, value < 0 ? 0 : value)) SetAllDirty(); }
}
/// <summary>
/// The ratio of maximum and minimum values rounded upward. The default is 0, which is automatically calculated.
/// ||最大最小值向上取整的倍率。默认为0时自动计算。
/// </summary>
public double ceilRate
{
get { return m_CeilRate; }
set { if (PropertyUtil.SetStruct(ref m_CeilRate, value < 0 ? 0 : value)) SetAllDirty(); }
}
/// <summary>
/// Whether the axis are reversed or not. Invalid in `Category` axis.
/// ||是否反向坐标轴。在类目轴中无效。
/// </summary>
public bool inverse
{
get { return m_Inverse; }
set { if (m_Type == AxisType.Value && PropertyUtil.SetStruct(ref m_Inverse, value)) SetAllDirty(); }
}
/// <summary>
/// Whether the positive position of axis is in clockwise. True for clockwise by default.
/// ||刻度增长是否按顺时针,默认顺时针。
/// </summary>
public bool clockwise
{
get { return m_Clockwise; }
set { if (PropertyUtil.SetStruct(ref m_Clockwise, value)) SetAllDirty(); }
}
/// <summary>
/// Whether it is the main axis. When both X and Y axes are of the same type, the axis set to main axis will determine the orientation,
/// such as horizontal bar chart and vertical bar chart.
/// ||是否为主轴。当XY轴类型都相同时,设置为主轴的轴会决定朝向,如横向柱图和纵向柱图。
/// </summary>
[Since("v3.15.0")]
public bool mainAxis
{
get { return m_MainAxis; }
set { if (PropertyUtil.SetStruct(ref m_MainAxis, value)) SetAllDirty(); }
}
/// <summary>
/// Category data, available in type: 'Category' axis.
/// ||类目数据,在类目轴(type: 'category')中有效。
/// </summary>
public List<string> data
{
get { return m_Data; }
set { if (value != null) { m_Data = value; SetAllDirty(); } }
}
/// <summary>
/// 类目数据对应的图标。
/// </summary>
public List<Sprite> icons
{
get { return m_Icons; }
set { if (value != null) { m_Icons = value; SetAllDirty(); } }
}
/// <summary>
/// axis Line.
/// ||坐标轴轴线。
/// </summary>
public AxisLine axisLine
{
get { return m_AxisLine; }
set { if (value != null) { m_AxisLine = value; SetVerticesDirty(); } }
}
/// <summary>
/// axis name.
/// ||坐标轴名称。
/// </summary>
public AxisName axisName
{
get { return m_AxisName; }
set { if (value != null) { m_AxisName = value; SetComponentDirty(); } }
}
/// <summary>
/// axis tick.
/// ||坐标轴刻度。
/// </summary>
public AxisTick axisTick
{
get { return m_AxisTick; }
set { if (value != null) { m_AxisTick = value; SetVerticesDirty(); } }
}
/// <summary>
/// axis label.
/// ||坐标轴刻度标签。
/// </summary>
public AxisLabel axisLabel
{
get { return m_AxisLabel; }
set { if (value != null) { m_AxisLabel = value; SetComponentDirty(); } }
}
/// <summary>
/// axis split line.
/// ||坐标轴分割线。
/// </summary>
public AxisSplitLine splitLine
{
get { return m_SplitLine; }
set { if (value != null) { m_SplitLine = value; SetVerticesDirty(); } }
}
/// <summary>
/// axis split area.
/// ||坐标轴分割区域。
/// </summary>
public AxisSplitArea splitArea
{
get { return m_SplitArea; }
set { if (value != null) { m_SplitArea = value; SetVerticesDirty(); } }
}
/// <summary>
/// axis minor tick.
/// ||坐标轴次刻度。
/// </summary>
public AxisMinorTick minorTick
{
get { return m_MinorTick; }
set { if (value != null) { m_MinorTick = value; SetVerticesDirty(); } }
}
/// <summary>
/// axis minor split line.
/// ||坐标轴次分割线。
/// </summary>
public AxisMinorSplitLine minorSplitLine
{
get { return m_MinorSplitLine; }
set { if (value != null) { m_MinorSplitLine = value; SetVerticesDirty(); } }
}
/// <summary>
/// Style of axis tooltip indicator label.
/// ||指示器文本的样式。Tooltip为Cross时使用。
/// </summary>
public LabelStyle indicatorLabel
{
get { return m_IndicatorLabel; }
set { if (value != null) { m_IndicatorLabel = value; SetComponentDirty(); } }
}
/// <summary>
/// animation of axis.
/// ||坐标轴动画。
/// </summary>
public AxisAnimation animation
{
get { return m_Animation; }
set { if (value != null) { m_Animation = value; SetComponentDirty(); } }
}
/// <summary>
/// Whether to add new data at the head or at the end of the list.
/// ||添加新数据时是在列表的头部还是尾部加入。
/// </summary>
public bool insertDataToHead
{
get { return m_InsertDataToHead; }
set { if (PropertyUtil.SetStruct(ref m_InsertDataToHead, value)) SetAllDirty(); }
}
/// <summary>
/// The minimum spacing between categories.
/// ||类目之间的最小间距。
/// </summary>
public float minCategorySpacing
{
get { return m_MinCategorySpacing; }
set { if (PropertyUtil.SetStruct(ref m_MinCategorySpacing, value)) SetAllDirty(); }
}
public override bool vertsDirty
{
get
{
return m_VertsDirty ||
axisLine.anyDirty ||
axisTick.anyDirty ||
splitLine.anyDirty ||
splitArea.anyDirty ||
minorTick.anyDirty ||
minorSplitLine.anyDirty;
}
}
public override bool componentDirty
{
get
{
return m_ComponentDirty ||
axisName.anyDirty ||
axisLabel.anyDirty ||
indicatorLabel.anyDirty;
}
}
public override void ClearComponentDirty()
{
base.ClearComponentDirty();
axisName.ClearComponentDirty();
axisLabel.ClearComponentDirty();
indicatorLabel.ClearComponentDirty();
}
public override void ClearVerticesDirty()
{
base.ClearVerticesDirty();
axisLabel.ClearVerticesDirty();
axisLine.ClearVerticesDirty();
axisTick.ClearVerticesDirty();
splitLine.ClearVerticesDirty();
splitArea.ClearVerticesDirty();
minorTick.ClearVerticesDirty();
minorSplitLine.ClearVerticesDirty();
indicatorLabel.ClearVerticesDirty();
}
public override void SetComponentDirty()
{
context.isNeedUpdateFilterData = true;
base.SetComponentDirty();
}
/// <summary>
/// 重置状态。
/// </summary>
public override void ResetStatus()
{
context.minValue = 0;
context.maxValue = 0;
context.destMinValue = 0;
context.destMaxValue = 0;
context.labelValueList.Clear();
}
public Axis Clone()
{
var axis = new Axis();
axis.show = show;
axis.type = type;
axis.gridIndex = 0;
axis.minMaxType = minMaxType;
axis.min = min;
axis.max = max;
axis.splitNumber = splitNumber;
axis.interval = interval;
axis.boundaryGap = boundaryGap;
axis.maxCache = maxCache;
axis.logBase = logBase;
axis.logBaseE = logBaseE;
axis.ceilRate = ceilRate;
axis.insertDataToHead = insertDataToHead;
axis.axisLine = axisLine.Clone();
axis.axisName = axisName.Clone();
axis.axisTick = axisTick.Clone();
axis.axisLabel = axisLabel.Clone();
axis.splitLine = splitLine.Clone();
axis.splitArea = splitArea.Clone();
axis.minorTick = minorTick.Clone();
axis.minorSplitLine = minorSplitLine.Clone();
axis.indicatorLabel = indicatorLabel.Clone();
axis.animation = animation.Clone();
axis.icons = new List<Sprite>();
axis.data = new List<string>();
ChartHelper.CopyList(axis.data, data);
return axis;
}
public void Copy(Axis axis)
{
show = axis.show;
type = axis.type;
minMaxType = axis.minMaxType;
gridIndex = axis.gridIndex;
min = axis.min;
max = axis.max;
splitNumber = axis.splitNumber;
interval = axis.interval;
boundaryGap = axis.boundaryGap;
maxCache = axis.maxCache;
logBase = axis.logBase;
logBaseE = axis.logBaseE;
ceilRate = axis.ceilRate;
insertDataToHead = axis.insertDataToHead;
axisLine.Copy(axis.axisLine);
axisName.Copy(axis.axisName);
axisTick.Copy(axis.axisTick);
axisLabel.Copy(axis.axisLabel);
splitLine.Copy(axis.splitLine);
splitArea.Copy(axis.splitArea);
minorTick.Copy(axis.minorTick);
minorSplitLine.Copy(axis.minorSplitLine);
indicatorLabel.Copy(axis.indicatorLabel);
animation.Copy(axis.animation);
ChartHelper.CopyList(data, axis.data);
ChartHelper.CopyList<Sprite>(icons, axis.icons);
}
/// <summary>
/// 清空类目数据
/// </summary>
public override void ClearData()
{
m_Data.Clear();
m_Icons.Clear();
context.Clear();
SetAllDirty();
}
/// <summary>
/// 是否为类目轴。
/// </summary>
/// <returns></returns>
public bool IsCategory()
{
return m_Type == AxisType.Category;
}
/// <summary>
/// 是否为数值轴。
/// </summary>
/// <returns></returns>
public bool IsValue()
{
return m_Type == AxisType.Value;
}
/// <summary>
/// 是否为对数轴。
/// </summary>
/// <returns></returns>
public bool IsLog()
{
return m_Type == AxisType.Log;
}
/// <summary>
/// 是否为时间轴。
/// </summary>
public bool IsTime()
{
return m_Type == AxisType.Time;
}
public bool IsLeft()
{
return m_Position == AxisPosition.Left;
}
public bool IsRight()
{
return m_Position == AxisPosition.Right;
}
public bool IsTop()
{
return m_Position == AxisPosition.Top;
}
public bool IsBottom()
{
return m_Position == AxisPosition.Bottom;
}
public bool IsNeedShowLabel(int index, int total = 0, string content = null)
{
if (total == 0)
{
total = context.labelValueList.Count;
}
return axisLabel.IsNeedShowLabel(index, total, content);
}
public void SetNeedUpdateFilterData()
{
context.isNeedUpdateFilterData = true;
}
/// <summary>
/// 添加一个类目到类目数据列表
/// </summary>
/// <param name="category"></param>
public void AddData(string category)
{
if (maxCache > 0)
{
if (context.addedDataCount < m_Data.Count)
context.addedDataCount = m_Data.Count;
while (m_Data.Count >= maxCache)
{
RemoveData(m_InsertDataToHead ? m_Data.Count - 1 : 0);
}
}
context.addedDataCount++;
if (m_InsertDataToHead)
m_Data.Insert(0, category);
else
m_Data.Add(category);
SetAllDirty();
}
/// <summary>
/// get the history data count.
/// ||获得添加过的历史数据总数
/// </summary>
/// <returns></returns>
public int GetAddedDataCount()
{
return context.addedDataCount < m_Data.Count ? m_Data.Count : context.addedDataCount;
}
public void RemoveData(int dataIndex)
{
context.isNeedUpdateFilterData = true;
m_Data.RemoveAt(dataIndex);
}
/// <summary>
/// 更新类目数据
/// </summary>
/// <param name="index"></param>
/// <param name="category"></param>
public void UpdateData(int index, string category)
{
if (index >= 0 && index < m_Data.Count)
{
m_Data[index] = category;
SetComponentDirty();
}
}
/// <summary>
/// 添加图标
/// </summary>
/// <param name="icon"></param>
public void AddIcon(Sprite icon)
{
if (maxCache > 0)
{
while (m_Icons.Count > maxCache)
{
m_Icons.RemoveAt(m_InsertDataToHead ? m_Icons.Count - 1 : 0);
}
}
if (m_InsertDataToHead) m_Icons.Insert(0, icon);
else m_Icons.Add(icon);
SetAllDirty();
}
/// <summary>
/// 更新图标
/// </summary>
/// <param name="index"></param>
/// <param name="icon"></param>
public void UpdateIcon(int index, Sprite icon)
{
if (index >= 0 && index < m_Icons.Count)
{
m_Icons[index] = icon;
SetComponentDirty();
}
}
/// <summary>
/// 获得指定索引的类目数据
/// </summary>
/// <param name="index"></param>
/// <returns></returns>
public string GetData(int index)
{
if (index >= 0 && index < m_Data.Count)
return m_Data[index];
else
return null;
}
/// <summary>
/// 获得在dataZoom范围内指定索引的类目数据
/// </summary>
/// <param name="index">类目数据索引</param>
/// <param name="dataZoom">区域缩放</param>
/// <returns></returns>
public string GetData(int index, DataZoom dataZoom)
{
var showData = GetDataList(dataZoom);
if (index >= 0 && index < showData.Count)
return showData[index];
else
return "";
}
public Sprite GetIcon(int index)
{
if (index >= 0 && index < m_Icons.Count)
return m_Icons[index];
else
return null;
}
/// <summary>
/// 获得值在坐标轴上的距离
/// </summary>
/// <param name="value"></param>
/// <param name="axisLength"></param>
/// <returns></returns>
public float GetDistance(double value, float axisLength = 0)
{
if (context.minMaxRange == 0)
return 0;
if (axisLength == 0)
{
axisLength = context.length;
}
if (IsCategory() && boundaryGap)
{
var each = axisLength / data.Count;
return (float)(each * (value + 0.5f));
}
else if (IsLog())
{
var logValue = GetLogValue(value);
var logMin = GetLogValue(context.minValue);
var logMax = GetLogValue(context.maxValue);
return axisLength * (float)((logValue - logMin) / (logMax - logMin));
}
else
{
return axisLength * (float)((value - context.minValue) / context.minMaxRange);
}
}
public float GetValueLength(double value, float axisLength)
{
if (context.minMaxRange > 0)
{
return axisLength * ((float)(value / context.minMaxRange));
}
else
{
return 0;
}
}
/// <summary>
/// 获得指定区域缩放的类目数据列表
/// </summary>
/// <param name="dataZoom">区域缩放</param>
/// <returns></returns>
internal List<string> GetDataList(DataZoom dataZoom)
{
if (dataZoom != null && dataZoom.enable && dataZoom.IsContainsAxis(this))
{
UpdateFilterData(dataZoom);
return context.filterData;
}
else
{
return m_Data.Count > 0 ? m_Data : context.runtimeData;
}
}
internal List<string> GetDataList()
{
return m_Data.Count > 0 ? m_Data : context.runtimeData;
}
/// <summary>
/// 更新dataZoom对应的类目数据列表
/// </summary>
/// <param name="dataZoom"></param>
internal void UpdateFilterData(DataZoom dataZoom)
{
if (dataZoom != null && dataZoom.enable && dataZoom.IsContainsAxis(this))
{
var data = GetDataList();
context.UpdateFilterData(data, dataZoom);
}
}
/// <summary>
/// 获得类目数据个数
/// </summary>
/// <param name="dataZoom"></param>
/// <returns></returns>
internal int GetDataCount(DataZoom dataZoom)
{
return IsCategory() ? GetDataList(dataZoom).Count : 0;
}
internal Vector3 GetLabelObjectPosition(int index)
{
if (context.labelObjectList != null && index < context.labelObjectList.Count)
return context.labelObjectList[index].GetPosition();
else
return Vector3.zero;
}
internal void UpdateMinMaxValue(double minValue, double maxValue, bool needAnimation = false)
{
if (needAnimation)
{
if (context.lastMinValue == 0 && context.lastMaxValue == 0)
{
context.minValue = minValue;
context.maxValue = maxValue;
}
context.lastMinValue = context.minValue;
context.lastMaxValue = context.maxValue;
context.destMinValue = minValue;
context.destMaxValue = maxValue;
}
else
{
context.minValue = minValue;
context.maxValue = maxValue;
context.destMinValue = minValue;
context.destMaxValue = maxValue;
}
double tempRange = maxValue - minValue;
if (context.minMaxRange != tempRange)
{
context.minMaxRange = tempRange;
if (type == Axis.AxisType.Value && interval > 0)
{
SetComponentDirty();
}
}
}
public float GetLogValue(double value)
{
if (value <= 0 || value == 1)
return 0;
else
return logBaseE ? (float)Math.Log(value) : (float)Math.Log(value, logBase);
}
public double GetLogMinIndex()
{
if (context.minValue <= 0 || context.minValue == 1)
return 0;
return logBaseE ?
Math.Log(context.minValue) :
Math.Log(context.minValue, logBase);
}
public double GetLogMaxIndex()
{
if (context.maxValue <= 0 || context.maxValue == 1)
return 0;
return logBaseE ?
Math.Log(context.maxValue) :
Math.Log(context.maxValue, logBase);
}
public double GetLabelValue(int index)
{
if (index < 0)
return context.minValue;
else if (index > context.labelValueList.Count - 1)
return context.maxValue;
else
return context.labelValueList[index];
}
public double GetLastLabelValue()
{
if (context.labelValueList.Count > 0)
return context.labelValueList[context.labelValueList.Count - 1];
else
return 0;
}
public void UpdateZeroOffset(float axisLength)
{
context.offset = context.minValue > 0 || context.minMaxRange == 0 ?
0 :
(context.maxValue < 0 ?
axisLength :
(float)(Math.Abs(context.minValue) * (axisLength / (Math.Abs(context.minValue) + Math.Abs(context.maxValue))))
);
}
public Vector3 GetCategoryPosition(int categoryIndex, int dataCount = 0)
{
if (dataCount <= 0)
{
dataCount = data.Count;
}
if (IsCategory() && dataCount > 0)
{
Vector3 pos;
if (boundaryGap)
{
var each = context.length / dataCount;
pos = context.start + context.dire * (each * (categoryIndex + 0.5f));
}
else
{
var each = context.length / (dataCount - 1);
pos = context.start + context.dire * (each * categoryIndex);
}
if (axisLabel.distance != 0)
{
if (this is YAxis)
{
pos.x = GetLabelObjectPosition(0).x;
}
else
{
pos.y = GetLabelObjectPosition(0).y;
}
}
return pos;
}
else
{
return Vector3.zero;
}
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: d5c29555575e04db98ee243c3b17f0ed
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,160 @@
using UnityEngine;
using UnityEngine.UI;
using XUGL;
namespace XCharts.Runtime
{
public static class Axis3DHelper
{
public static Vector3 Get3DGridPosition(GridCoord3D grid, XAxis3D xAxis, YAxis3D yAxis, ZAxis3D zAxis, double xValue, double yValue, double zValue)
{
var x = xAxis.GetDistance(xValue);
var y = yAxis.GetDistance(yValue);
var z = zAxis.GetDistance(zValue);
var dest = grid.context.pointA;
dest += xAxis.context.dire * x;
dest += yAxis.context.dire * y;
dest += zAxis.context.dire * z;
return dest;
}
public static Vector3 Get3DGridPosition(GridCoord3D grid, XAxis3D xAxis, YAxis3D yAxis, double xValue, double yValue)
{
var x = xAxis.GetDistance(xValue);
var y = yAxis.GetDistance(yValue);
var dest = grid.context.pointA;
dest += xAxis.context.dire * x;
dest += yAxis.context.dire * y;
return dest;
}
internal static void DrawAxisTick(VertexHelper vh, Axis axis, AxisTheme theme, DataZoom dataZoom,
Vector3 start, Vector3 end, Vector3 relativedDire)
{
var tickLength = axis.axisTick.GetLength(theme.tickLength);
var axisLength = Vector3.Distance(start, end);
var axisDire = (end - start).normalized;
if (axis.position == Axis.AxisPosition.Right)
{
relativedDire = -relativedDire;
}
if (AxisHelper.NeedShowSplit(axis))
{
var size = AxisHelper.GetScaleNumber(axis, axisLength, dataZoom);
if (axis.IsTime())
{
size += 1;
if (!ChartHelper.IsEquals(axis.GetLastLabelValue(), axis.context.maxValue))
size += 1;
}
var tickWidth = axis.axisTick.GetWidth(theme.tickWidth);
var tickColor = axis.axisTick.GetColor(theme.tickColor);
var current = start;
for (int i = 0; i < size; i++)
{
var scaleWidth = AxisHelper.GetScaleWidth(axis, axisLength, i + 1, dataZoom);
var hideTick = (i == 0 && (!axis.axisTick.showStartTick || axis.axisTick.alignWithLabel)) ||
(i == size - 1 && !axis.axisTick.showEndTick);
if (axis.axisTick.show && !hideTick)
{
UGL.DrawLine(vh, current, current + relativedDire * tickLength, tickWidth, tickColor);
}
current += axisDire * scaleWidth;
}
}
if (axis.show && axis.axisLine.show && axis.axisLine.showArrow)
{
}
}
public static void DrawAxisSplit(VertexHelper vh, Axis axis, AxisTheme theme, DataZoom dataZoom,
Vector3 start, Vector3 end, Axis relativedAxis)
{
if (relativedAxis == null) return;
var axisLength = Vector3.Distance(start, end);
var axisDire = (end - start).normalized;
var splitLength = relativedAxis.context.length;
var relativeDire = relativedAxis.context.dire;
var axisLineWidth = axis.axisLine.GetWidth(theme.lineWidth);
splitLength -= axisLineWidth;
var lineColor = axis.splitLine.GetColor(theme.splitLineColor);
var lineWidth = axis.splitLine.GetWidth(theme.lineWidth);
var lineType = axis.splitLine.GetType(theme.splitLineType);
var size = AxisHelper.GetScaleNumber(axis, axisLength, dataZoom);
if (axis.IsTime())
{
size += 1;
if (!ChartHelper.IsEquals(axis.GetLastLabelValue(), axis.context.maxValue))
size += 1;
}
var current = start;
for (int i = 0; i < size; i++)
{
var scaleWidth = AxisHelper.GetScaleWidth(axis, axisLength, axis.IsTime() ? i : i + 1, dataZoom);
if (axis.boundaryGap && axis.axisTick.alignWithLabel)
current -= axisDire * scaleWidth / 2;
if (axis.splitArea.show && i <= size - 1)
{
var p1 = current;
var p2 = current + relativeDire * splitLength;
var p3 = p2 + axisDire * scaleWidth;
var p4 = p1 + axisDire * scaleWidth;
UGL.DrawQuadrilateral(vh, p1, p2, p3, p4, axis.splitArea.GetColor(i, theme));
}
if (axis.splitLine.show)
{
if (axis.splitLine.NeedShow(i, size))
{
if (relativedAxis == null || !relativedAxis.axisLine.show
|| (Vector3.Distance(current, relativedAxis.context.start) > 0.5f && Vector3.Distance(current, relativedAxis.context.end) > 0.5f))
{
ChartDrawer.DrawLineStyle(vh,
lineType,
lineWidth,
current,
current + relativeDire * splitLength,
lineColor);
}
}
}
current += axisDire * scaleWidth;
}
}
public static Vector3 GetLabelPosition(int i, Axis axis, Axis relativedAxis, AxisTheme theme, float scaleWid)
{
var axisStart = axis.context.start;
var axisEnd = axis.context.end;
var axisDire = axis.context.dire;
var relativedDire = relativedAxis != null ? relativedAxis.context.dire : Vector3.zero;
var axisLength = Vector3.Distance(axisStart, axisEnd);
var inside = axis.axisLabel.inside;
var fontSize = axis.axisLabel.textStyle.GetFontSize(theme);
var current = axis.offset;
if (axis.position == Axis.AxisPosition.Right)
{
relativedDire = -relativedDire;
}
if (axis.IsTime() || axis.IsValue())
{
scaleWid = axis.context.minMaxRange != 0 ?
axis.GetDistance(axis.GetLabelValue(i), axisLength) :
0;
}
return axisStart + axisDire * scaleWid + axis.axisLabel.offset - relativedDire * (axis.axisLabel.distance + fontSize / 2);
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 52469636872044a81a291bb00b71a140
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,63 @@
using UnityEngine;
namespace XCharts.Runtime
{
/// <summary>
/// animation style of axis.
/// ||坐标轴动画配置。
/// </summary>
[System.Serializable]
[Since("v3.9.0")]
public class AxisAnimation : ChildComponent
{
[SerializeField] private bool m_Show = true;
[SerializeField] private float m_Duration;
[SerializeField] private bool m_UnscaledTime;
/// <summary>
/// whether to enable animation.
/// ||是否开启动画。
/// </summary>
public bool show
{
get { return m_Show; }
set { if (PropertyUtil.SetStruct(ref m_Show, value)) SetComponentDirty(); }
}
/// <summary>
/// the duration of animation (ms). When it is set to 0, the animation duration will be automatically calculated according to the serie.
/// ||动画时长(ms)。 默认设置为0时,会自动获取serie的动画时长。
/// </summary>
public float duration
{
get { return m_Duration; }
set { if (PropertyUtil.SetStruct(ref m_Duration, value)) SetComponentDirty(); }
}
/// <summary>
/// Animation updates independently of Time.timeScale.
/// ||动画是否受TimeScaled的影响。默认为 false 受TimeScaled的影响。
/// </summary>
public bool unscaledTime
{
get { return m_UnscaledTime; }
set { if (PropertyUtil.SetStruct(ref m_UnscaledTime, value)) SetComponentDirty(); }
}
public AxisAnimation Clone()
{
var animation = new AxisAnimation
{
show = show,
duration = duration,
unscaledTime = unscaledTime
};
return animation;
}
public void Copy(AxisAnimation animation)
{
show = animation.show;
duration = animation.duration;
unscaledTime = animation.unscaledTime;
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: ecce90a24f1e64ce2affa51992d56ac4
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,169 @@
using System;
using System.Collections.Generic;
using UnityEngine;
namespace XCharts.Runtime
{
public class AxisContext : MainComponentContext
{
public Orient orient;
/// <summary>
/// 坐标轴的起点X
/// </summary>
public float x;
/// <summary>
/// 坐标轴的起点Y
/// </summary>
public float y;
public Vector3 start;
public Vector3 end;
public Vector3 dire;
/// <summary>
/// 坐标轴原点X
/// </summary>
public float zeroX;
/// <summary>
/// 坐标轴原点Y
/// </summary>
public float zeroY;
public float width;
public float height;
public float length;
public Vector3 position;
public float left;
public float right;
public float bottom;
public float top;
/// <summary>
/// the current minimun value.
/// ||当前最小值。
/// </summary>
public double minValue;
public double lastMinValue { get; internal set; }
public double destMinValue { get; internal set; }
/// <summary>
/// the current maximum value.
/// ||当前最大值。
/// </summary>
public double maxValue;
public double lastMaxValue { get; internal set; }
public double destMaxValue { get; internal set; }
public bool needAnimation { get; internal set; }
/// <summary>
/// the offset of zero position.
/// ||坐标轴原点在坐标轴的偏移。
/// </summary>
public float offset;
public double minMaxRange;
/// <summary>
/// the tick value of value axis.
/// ||数值轴时每个tick的数值。
/// </summary>
public double tickValue;
public float scaleWidth;
public float startAngle;
public double pointerValue;
public Vector3 pointerLabelPosition;
public double axisTooltipValue;
public TextAnchor aligment;
public List<string> runtimeData { get { return m_RuntimeData; } }
public List<double> labelValueList { get { return m_LabelValueList; } }
public List<ChartLabel> labelObjectList { get { return m_AxisLabelList; } }
public List<int> sortedDataIndices { get { return m_SortedDataIndices; } }
public int dataZoomStartIndex;
/// <summary>
/// 添加过的历史数据总数
/// </summary>
public int addedDataCount;
internal List<string> filterData;
internal bool lastCheckInverse;
internal bool isNeedUpdateFilterData;
private int filterStart;
private int filterEnd;
private int filterMinShow;
private List<ChartLabel> m_AxisLabelList = new List<ChartLabel>();
private List<double> m_LabelValueList = new List<double>();
private List<string> m_RuntimeData = new List<string>();
private List<int> m_SortedDataIndices = new List<int>();
internal void Clear()
{
addedDataCount = 0;
m_RuntimeData.Clear();
}
private List<string> m_EmptyFliter = new List<string>();
/// <summary>
/// 更新dataZoom对应的类目数据列表
/// </summary>
/// <param name="dataZoom"></param>
internal void UpdateFilterData(List<string> data, DataZoom dataZoom)
{
int start = 0, end = 0;
var range = Mathf.RoundToInt(data.Count * (dataZoom.end - dataZoom.start) / 100);
if (range <= 0)
range = 1;
if (dataZoom.context.invert)
{
end = Mathf.RoundToInt(data.Count * dataZoom.end / 100);
start = end - range;
if (start < 0) start = 0;
}
else
{
start = Mathf.RoundToInt(data.Count * dataZoom.start / 100);
end = start + range;
if (end > data.Count) end = data.Count;
}
var minZoomRatio = (int)(data.Count * dataZoom.minZoomRatio);
if (start != filterStart ||
end != filterEnd ||
minZoomRatio != filterMinShow ||
isNeedUpdateFilterData)
{
filterStart = start;
filterEnd = end;
filterMinShow = minZoomRatio;
isNeedUpdateFilterData = false;
if (data.Count > 0)
{
if (range < minZoomRatio)
{
if (dataZoom.minZoomRatio > data.Count)
range = data.Count;
else
range = minZoomRatio;
}
if (range > data.Count - start)
start = data.Count - range;
if (start >= 0)
{
dataZoomStartIndex = start;
filterData = data.GetRange(start, range);
}
else
{
dataZoomStartIndex = 0;
filterData = data;
}
}
else
{
dataZoomStartIndex = 0;
filterData = data;
}
}
else if (end == 0)
{
dataZoomStartIndex = 0;
filterData = m_EmptyFliter;
}
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 6525f065fa5d04663ab7026a3467f56e
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 0babef8a2708b4745bbb0a0648913a35
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,655 @@
using UnityEngine;
namespace XCharts.Runtime
{
public static class AxisHelper
{
/// <summary>
/// 包含箭头偏移的轴线长度
/// </summary>
/// <param name="axis"></param>
/// <returns></returns>
public static float GetAxisLineArrowOffset(Axis axis)
{
if (axis.axisLine.show && axis.axisLine.showArrow && axis.axisLine.arrow.offset > 0)
{
return axis.axisLine.arrow.offset;
}
return 0;
}
/// <summary>
/// 获得分割网格个数,包含次刻度
/// </summary>
/// <param name="axis"></param>
/// <returns></returns>
public static int GetTotalSplitGridNum(Axis axis)
{
if (axis.IsCategory())
return axis.data.Count;
else
{
var splitNum = axis.splitNumber <= 0 ? GetSplitNumber(axis, 0, null) : axis.splitNumber;
return splitNum * axis.minorTick.splitNumber;
}
}
/// <summary>
/// 获得分割段数
/// </summary>
/// <param name="dataZoom"></param>
/// <returns></returns>
public static int GetSplitNumber(Axis axis, float coordinateWid, DataZoom dataZoom)
{
if (axis.type == Axis.AxisType.Value)
{
return axis.context.labelValueList.Count - 1;
}
else if (axis.type == Axis.AxisType.Time)
{
return axis.context.labelValueList.Count;
}
else if (axis.type == Axis.AxisType.Log)
{
return axis.splitNumber > 0 ? axis.splitNumber : 4;
}
else if (axis.type == Axis.AxisType.Category)
{
int dataCount = axis.GetDataList(dataZoom).Count;
if (!axis.boundaryGap)
dataCount -= 1;
if (dataCount <= 0)
dataCount = 1;
if (axis.splitNumber <= 0)
{
var eachWid = coordinateWid / dataCount;
var min = axis.minCategorySpacing > 0
? axis.minCategorySpacing
: (Mathf.Abs(axis.context.dire.y) < 0.01 ? 80 : 20);
if (eachWid > min) return dataCount;
var tick = Mathf.CeilToInt(min / eachWid);
return tick <= 1 ? dataCount : (int)(dataCount / tick);
}
else
{
if (axis.splitNumber <= 0 || axis.splitNumber > dataCount)
return dataCount;
if (dataCount >= axis.splitNumber * 2)
return axis.splitNumber;
else
return dataCount;
}
}
return 0;
}
/// <summary>
/// 获得一个类目数据在坐标系中代表的宽度
/// </summary>
/// <param name="coordinateWidth"></param>
/// <param name="dataZoom"></param>
/// <returns></returns>
public static float GetDataWidth(Axis axis, float coordinateWidth, int dataCount, DataZoom dataZoom)
{
if (dataCount < 1)
dataCount = 1;
if (axis.IsValue())
return dataCount > 1 ? coordinateWidth / (dataCount - 1) : coordinateWidth;
var categoryCount = axis.GetDataCount(dataZoom);
int segment = (axis.boundaryGap ? categoryCount : categoryCount - 1);
segment = segment <= 0 ? dataCount : segment;
if (segment <= 0)
segment = 1;
return coordinateWidth / segment;
}
/// <summary>
/// 获得标签显示的名称
/// </summary>
/// <param name="index"></param>
/// <param name="minValue"></param>
/// <param name="maxValue"></param>
/// <param name="dataZoom"></param>
/// <returns></returns>
public static string GetLabelName(Axis axis, float coordinateWidth, int index, double minValue, double maxValue,
DataZoom dataZoom, bool forcePercent, bool useUtc, int sortIndex = -1)
{
int split = GetSplitNumber(axis, coordinateWidth, dataZoom);
if (sortIndex == -1) sortIndex = index;
if (axis.type == Axis.AxisType.Value)
{
if (minValue == 0 && maxValue == 0)
maxValue = axis.max != 0 ? axis.max : 1;
double value = 0;
if (forcePercent)
maxValue = 100;
value = axis.GetLabelValue(index);
if (axis.inverse)
{
value = -value;
minValue = -minValue;
maxValue = -maxValue;
}
if (forcePercent)
return string.Format("{0}%", (int)value);
else
return axis.axisLabel.GetFormatterContent(sortIndex, axis.context.labelValueList.Count, value, minValue, maxValue);
}
else if (axis.type == Axis.AxisType.Log)
{
double value = axis.logBaseE ?
System.Math.Exp(axis.GetLogMinIndex() + index) :
System.Math.Pow(axis.logBase, axis.GetLogMinIndex() + index);
if (axis.inverse)
{
value = -value;
minValue = -minValue;
maxValue = -maxValue;
}
return axis.axisLabel.GetFormatterContent(sortIndex, 0, value, minValue, maxValue, true);
}
else if (axis.type == Axis.AxisType.Time)
{
if (minValue == 0 && maxValue == 0)
return string.Empty;
if (index > axis.context.labelValueList.Count - 1)
return string.Empty;
var value = axis.GetLabelValue(index);
return axis.axisLabel.GetFormatterDateTime(sortIndex, axis.context.labelValueList.Count, value, minValue, maxValue, !useUtc);
}
var showData = axis.GetDataList(dataZoom);
int dataCount = showData.Count;
if (dataCount <= 0)
return "";
int rate = axis.boundaryGap ? (dataCount / split) : (dataCount - 1) / split;
if (rate == 0) rate = 1;
if (axis.insertDataToHead)
{
if (index > 0)
{
var residue = dataCount - 1 - split * rate;
var newIndex = residue + (index - 1) * rate;
if (newIndex < 0)
newIndex = 0;
return axis.axisLabel.GetFormatterContent(sortIndex, dataCount, showData[newIndex]);
}
else
{
if (axis.boundaryGap && coordinateWidth / dataCount > 5)
return string.Empty;
else
return axis.axisLabel.GetFormatterContent(sortIndex, dataCount, showData[0]);
}
}
else
{
int newIndex = index * rate;
if (newIndex < dataCount)
{
return axis.axisLabel.GetFormatterContent(sortIndex, dataCount, showData[newIndex]);
}
else
{
var diff = newIndex - dataCount;
if (axis.boundaryGap && ((diff > 0 && diff / rate < 0.4f) || dataCount >= axis.data.Count))
return string.Empty;
else
return axis.axisLabel.GetFormatterContent(sortIndex, dataCount, showData[dataCount - 1]);
}
}
}
/// <summary>
/// 获得分割线条数
/// </summary>
/// <param name="dataZoom"></param>
/// <returns></returns>
public static int GetScaleNumber(Axis axis, float coordinateWidth, DataZoom dataZoom = null)
{
int splitNum = GetSplitNumber(axis, coordinateWidth, dataZoom);
if (splitNum == 0)
return 0;
if (axis.IsCategory())
{
var dataCount = axis.GetDataList(dataZoom).Count;
var scaleNum = 0;
if (axis.boundaryGap)
{
scaleNum = dataCount > 1 && dataCount % splitNum == 0 ?
splitNum + 1 :
splitNum + 2;
}
else
{
scaleNum = splitNum + 1;
}
return scaleNum;
}
else if (axis.IsTime())
return splitNum;
else
return splitNum + 1;
}
/// <summary>
/// 获得分割段宽度
/// </summary>
/// <param name="coordinateWidth"></param>
/// <param name="dataZoom"></param>
/// <returns></returns>
public static float GetScaleWidth(Axis axis, float coordinateWidth, int index, DataZoom dataZoom = null)
{
if (index < 0)
return 0;
if (axis.IsTime() || axis.IsValue())
{
var value = axis.GetLabelValue(index);
var lastValue = axis.GetLabelValue(index - 1);
var width = axis.context.minMaxRange == 0 ? 0 :
(float)(coordinateWidth * ((value - lastValue) / axis.context.minMaxRange));
return width;
}
else
{
int num = GetScaleNumber(axis, coordinateWidth, dataZoom);
int splitNum = GetSplitNumber(axis, coordinateWidth, dataZoom);
if (num <= 0)
num = 1;
var data = axis.GetDataList(dataZoom);
if (axis.IsCategory() && data.Count > 0 && splitNum > 0)
{
var count = axis.boundaryGap ? data.Count : data.Count - 1;
int tick = count / splitNum;
if (count <= 0)
return 0;
var each = coordinateWidth / count;
if (axis.insertDataToHead)
{
var max = axis.boundaryGap ? splitNum : splitNum - 1;
if (index == 1)
{
if (axis.axisTick.alignWithLabel)
return each * tick;
else
return coordinateWidth - each * tick * max;
}
else
{
if (count < splitNum)
return each;
else
return each * (count / splitNum);
}
}
else
{
var max = axis.boundaryGap ? num - 1 : num;
if (index >= max)
{
if (axis.axisTick.alignWithLabel)
return each * tick;
else
return coordinateWidth - each * tick * (index - 1);
}
else
{
if (count < splitNum)
return each;
else
return each * (count / splitNum);
}
}
}
else
{
if (splitNum <= 0)
return 0;
else
return coordinateWidth / splitNum;
}
}
}
public static float GetEachWidth(Axis axis, float coordinateWidth, DataZoom dataZoom = null)
{
var data = axis.GetDataList(dataZoom);
if (data.Count > 0)
{
var count = axis.boundaryGap ? data.Count : data.Count - 1;
return count > 0 ? coordinateWidth / count : coordinateWidth;
}
else
{
int num = GetScaleNumber(axis, coordinateWidth, dataZoom) - 1;
return num > 0 ? coordinateWidth / num : coordinateWidth;
}
}
/// <summary>
/// 调整最大最小值
/// </summary>
/// <param name="minValue"></param>
/// <param name="maxValue"></param>
public static void AdjustMinMaxValue(Axis axis, ref double minValue, ref double maxValue, bool needFormat, double ceilRate = 0)
{
if (axis.type == Axis.AxisType.Log)
{
int minSplit = 0;
int maxSplit = 0;
maxValue = ChartHelper.GetMaxLogValue(maxValue, axis.logBase, axis.logBaseE, out maxSplit);
minValue = ChartHelper.GetMinLogValue(minValue, axis.logBase, axis.logBaseE, out minSplit);
var splitNumber = maxSplit + minSplit;
if (splitNumber > 15)
splitNumber = 15;
axis.splitNumber = splitNumber;
return;
}
if (ceilRate == 0) ceilRate = axis.ceilRate;
if (axis.minMaxType == Axis.AxisMinMaxType.Custom)
{
if (axis.min != 0 || axis.max != 0)
{
if (axis.inverse)
{
minValue = -axis.max;
maxValue = -axis.min;
}
else
{
minValue = axis.min;
maxValue = axis.max;
}
}
}
else if (axis.type == Axis.AxisType.Time)
{
if (ceilRate != 0)
{
minValue = ChartHelper.GetMinCeilRate(minValue, ceilRate);
maxValue = ChartHelper.GetMaxCeilRate(maxValue, ceilRate);
}
}
else
{
switch (axis.minMaxType)
{
case Axis.AxisMinMaxType.Default:
if (minValue == 0 && maxValue == 0) { }
else if (minValue > 0 && maxValue > 0)
{
minValue = 0;
maxValue = needFormat ? ChartHelper.GetMaxDivisibleValue(maxValue, ceilRate) : maxValue;
}
else if (minValue < 0 && maxValue < 0)
{
minValue = needFormat ? ChartHelper.GetMinDivisibleValue(minValue, ceilRate) : minValue;
maxValue = 0;
}
else
{
minValue = needFormat ? ChartHelper.GetMinDivisibleValue(minValue, ceilRate) : minValue;
maxValue = needFormat ? ChartHelper.GetMaxDivisibleValue(maxValue, ceilRate) : maxValue;
}
break;
case Axis.AxisMinMaxType.MinMax:
if (ceilRate != 0)
{
minValue = ChartHelper.GetMinCeilRate(minValue, ceilRate);
maxValue = ChartHelper.GetMaxCeilRate(maxValue, ceilRate);
}
break;
case Axis.AxisMinMaxType.MinMaxAuto:
minValue = needFormat ? ChartHelper.GetMinDivisibleValue(minValue, ceilRate) : minValue;
maxValue = needFormat ? ChartHelper.GetMaxDivisibleValue(maxValue, ceilRate) : maxValue;
break;
}
}
}
public static bool NeedShowSplit(Axis axis)
{
if (!axis.show)
return false;
if (axis.IsCategory() && axis.GetDataList().Count <= 0)
return false;
else
return true;
}
public static void AdjustCircleLabelPos(ChartLabel txt, Vector3 pos, Vector3 cenPos, float txtHig, Vector3 offset)
{
var txtWidth = txt.text.GetPreferredWidth();
var sizeDelta = new Vector2(txtWidth, txt.text.GetPreferredHeight());
txt.text.SetSizeDelta(sizeDelta);
var diff = pos.x - cenPos.x;
if (diff < -1f) //left
{
pos = new Vector3(pos.x - txtWidth / 2, pos.y);
}
else if (diff > 1f) //right
{
pos = new Vector3(pos.x + txtWidth / 2, pos.y);
}
else
{
float y = pos.y > cenPos.y ? pos.y + txtHig / 2 : pos.y - txtHig / 2;
pos = new Vector3(pos.x, y);
}
txt.SetPosition(pos + offset);
}
public static void AdjustRadiusAxisLabelPos(ChartLabel txt, Vector3 pos, Vector3 cenPos, float txtHig, Vector3 offset)
{
var txtWidth = txt.text.GetPreferredWidth();
var sizeDelta = new Vector2(txtWidth, txt.text.GetPreferredHeight());
txt.text.SetSizeDelta(sizeDelta);
var diff = pos.y - cenPos.y;
if (diff > 20f) //left
{
pos = new Vector3(pos.x - txtWidth / 2, pos.y);
}
else if (diff < -20f) //right
{
pos = new Vector3(pos.x + txtWidth / 2, pos.y);
}
else
{
float y = pos.y > cenPos.y ? pos.y + txtHig / 2 : pos.y - txtHig / 2;
pos = new Vector3(pos.x, y);
}
txt.SetPosition(pos);
}
public static float GetAxisPosition(GridCoord grid, Axis axis, double value, int dataCount = 0, DataZoom dataZoom = null)
{
var gridHeight = axis is YAxis ? grid.context.height : grid.context.width;
var gridXY = axis is YAxis ? grid.context.y : grid.context.x;
if (axis.IsCategory())
{
if (dataCount == 0) dataCount = axis.data.Count;
var categoryIndex = (int)value;
var scaleWid = AxisHelper.GetDataWidth(axis, gridHeight, dataCount, dataZoom);
float startY = gridXY + (axis.boundaryGap ? scaleWid / 2 : 0);
return startY + scaleWid * categoryIndex;
}
else
{
var yDataHig = (axis.context.minMaxRange == 0) ? 0f :
(float)((value - axis.context.minValue) / axis.context.minMaxRange * gridHeight);
return gridXY + yDataHig;
}
}
public static double GetAxisPositionValue(GridCoord grid, Axis axis, Vector3 pos)
{
if (axis is YAxis)
return GetAxisPositionValue(pos.y, grid.context.height, axis.context.minMaxRange, grid.context.y, axis.context.offset);
else if (axis is XAxis)
return GetAxisPositionValue(pos.x, grid.context.width, axis.context.minMaxRange, grid.context.x, axis.context.offset);
else
return 0;
}
public static double GetAxisPositionValue(float xy, float axisLength, double axisRange, float axisStart, float axisOffset)
{
var yRate = axisRange / axisLength;
return yRate * (xy - axisStart - axisOffset);
}
/// <summary>
/// 获得数值value在坐标轴上的坐标位置
/// </summary>
/// <param name="grid"></param>
/// <param name="axis"></param>
/// <param name="scaleWidth"></param>
/// <param name="value"></param>
/// <returns></returns>
public static float GetAxisValuePosition(GridCoord grid, Axis axis, float scaleWidth, double value)
{
return GetAxisPositionInternal(grid, axis, scaleWidth, value, true, false);
}
/// <summary>
/// 获得数值value在坐标轴上相对起点的距离
/// </summary>
/// <param name="grid"></param>
/// <param name="axis"></param>
/// <param name="scaleWidth"></param>
/// <param name="value"></param>
/// <returns></returns>
public static float GetAxisValueDistance(GridCoord grid, Axis axis, float scaleWidth, double value)
{
return GetAxisPositionInternal(grid, axis, scaleWidth, value, false, false);
}
/// <summary>
/// 获得数值value在坐标轴上对应的长度
/// </summary>
/// <param name="grid"></param>
/// <param name="axis"></param>
/// <param name="scaleWidth"></param>
/// <param name="value"></param>
/// <returns></returns>
public static float GetAxisValueLength(GridCoord grid, Axis axis, float scaleWidth, double value, float gap = 0)
{
return GetAxisPositionInternal(grid, axis, scaleWidth, value, false, true, gap);
}
/// <summary>
/// 获得数值value在坐标轴上对应的split索引
/// </summary>
/// <param name="axis"></param>
/// <param name="value"></param>
/// <returns></returns>
public static int GetAxisValueSplitIndex(Axis axis, double value, bool checkMaxCache, int totalSplitNumber = -1)
{
if (axis.IsCategory())
{
if (checkMaxCache)
return axis.maxCache > 0 ? (int)value - (axis.GetAddedDataCount() - axis.data.Count) : (int)value;
else
return (int)value;
}
else
{
if (value == axis.context.minValue)
return 0;
else
{
if (totalSplitNumber == -1)
totalSplitNumber = GetTotalSplitGridNum(axis);
if (axis.minMaxType == Axis.AxisMinMaxType.Custom)
return Mathf.CeilToInt(((float)((value - axis.min) / axis.max) * totalSplitNumber) - 1);
else
return Mathf.CeilToInt(((float)((value - axis.context.minValue) / axis.context.minMaxRange) * totalSplitNumber) - 1);
}
}
}
private static float GetAxisPositionInternal(GridCoord grid, Axis axis, float scaleWidth, double value, bool includeGridXY, bool realLength, float gap = 0)
{
var isY = axis is YAxis;
var gridHeight = isY ? grid.context.height : grid.context.width;
gridHeight -= gap;
var gridXY = isY ? grid.context.y : grid.context.x;
if (axis.IsLog())
{
var minIndex = axis.GetLogMinIndex();
var nowIndex = axis.GetLogValue(value);
return includeGridXY ?
(float)(gridXY + (nowIndex - minIndex) / axis.splitNumber * gridHeight) :
(float)((nowIndex - minIndex) / axis.splitNumber * gridHeight);
}
else if (axis.IsCategory())
{
var categoryIndex = (int)value;
return includeGridXY ?
gridXY + (axis.boundaryGap ? scaleWidth / 2 : 0) + scaleWidth * categoryIndex :
(axis.boundaryGap ? scaleWidth / 2 : 0) + scaleWidth * categoryIndex;
}
else
{
var yDataHig = 0f;
if (axis.context.minMaxRange != 0)
{
if (realLength)
yDataHig = (float)(value * gridHeight / axis.context.minMaxRange);
else
yDataHig = (float)((value - axis.context.minValue) / axis.context.minMaxRange * gridHeight);
}
return includeGridXY ?
gridXY + yDataHig :
yDataHig;
}
}
public static float GetAxisXOrY(GridCoord grid, Axis axis, Axis relativedAxis)
{
if (axis is XAxis)
return GetXAxisXOrY(grid, axis, relativedAxis);
else if (axis is YAxis)
return GetYAxisXOrY(grid, axis, relativedAxis);
else if (axis is SingleAxis)
return axis.context.y + axis.offset;
else if (axis is ParallelAxis)
return axis.context.y;
else
return axis.context.x;
}
public static float GetXAxisXOrY(GridCoord grid, Axis xAxis, Axis relativedAxis)
{
var startY = grid.context.y + xAxis.offset;
if (xAxis.IsTop())
startY += grid.context.height;
else if (xAxis.axisLine.onZero && relativedAxis != null && relativedAxis.IsValue()
&& relativedAxis.gridIndex == xAxis.gridIndex)
startY += relativedAxis.context.offset;
return startY;
}
public static float GetYAxisXOrY(GridCoord grid, Axis yAxis, Axis relativedAxis)
{
var startX = grid.context.x + yAxis.offset;
if (yAxis.IsRight())
startX += grid.context.width;
else if (yAxis.axisLine.onZero && relativedAxis != null && relativedAxis.IsValue()
&& relativedAxis.gridIndex == yAxis.gridIndex)
startX += relativedAxis.context.offset;
return startX;
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 566e3426780cc4339a1fb92d9604d21f
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,198 @@
using System;
using UnityEngine;
using UnityEngine.UI;
namespace XCharts.Runtime
{
/// <summary>
/// Settings related to axis label.
/// ||坐标轴刻度标签的相关设置。
/// </summary>
[Serializable]
public class AxisLabel : LabelStyle
{
[SerializeField] private int m_Interval = 0;
[SerializeField] private bool m_Inside = false;
[SerializeField] private bool m_ShowAsPositiveNumber = false;
[SerializeField] private bool m_OnZero = false;
[SerializeField] private bool m_ShowStartLabel = true;
[SerializeField] private bool m_ShowEndLabel = true;
[SerializeField][Since("v3.15.0")] private bool m_ShowZeroLabel = true;
[SerializeField] private TextLimit m_TextLimit = new TextLimit();
/// <summary>
/// The display interval of the axis label.
/// ||坐标轴刻度标签的显示间隔,在类目轴中有效。0表示显示所有标签,1表示隔一个隔显示一个标签,以此类推。
/// </summary>
public int interval
{
get { return m_Interval; }
set { if (PropertyUtil.SetStruct(ref m_Interval, value)) SetComponentDirty(); }
}
/// <summary>
/// Set this to true so the axis labels face the inside direction.
/// ||刻度标签是否朝内,默认朝外。
/// </summary>
public bool inside
{
get { return m_Inside; }
set { if (PropertyUtil.SetStruct(ref m_Inside, value)) SetComponentDirty(); }
}
/// <summary>
/// Show negative number as positive number.
/// ||将负数数值显示为正数。一般和`Serie`的`showAsPositiveNumber`配合使用。
/// </summary>
public bool showAsPositiveNumber
{
get { return m_ShowAsPositiveNumber; }
set { if (PropertyUtil.SetStruct(ref m_ShowAsPositiveNumber, value)) SetComponentDirty(); }
}
/// <summary>
/// 刻度标签显示在0刻度上。
/// </summary>
public bool onZero
{
get { return m_OnZero; }
set { if (PropertyUtil.SetStruct(ref m_OnZero, value)) SetComponentDirty(); }
}
/// <summary>
/// Whether to display the first label.
/// ||是否显示第一个文本。
/// </summary>
public bool showStartLabel
{
get { return m_ShowStartLabel; }
set { if (PropertyUtil.SetStruct(ref m_ShowStartLabel, value)) SetComponentDirty(); }
}
/// <summary>
/// Whether to display the last label.
/// ||是否显示最后一个文本。
/// </summary>
public bool showEndLabel
{
get { return m_ShowEndLabel; }
set { if (PropertyUtil.SetStruct(ref m_ShowEndLabel, value)) SetComponentDirty(); }
}
/// <summary>
/// Whether to display the zero label.
/// ||是否显示0刻度文本。
/// </summary>
public bool showZeroLabel
{
get { return m_ShowZeroLabel; }
set { if (PropertyUtil.SetStruct(ref m_ShowZeroLabel, value)) SetComponentDirty(); }
}
/// <summary>
/// 文本限制。
/// </summary>
public TextLimit textLimit
{
get { return m_TextLimit; }
set { if (value != null) { m_TextLimit = value; SetComponentDirty(); } }
}
public override bool componentDirty { get { return m_ComponentDirty || m_TextLimit.componentDirty; } }
public override void ClearComponentDirty()
{
base.ClearComponentDirty();
textLimit.ClearComponentDirty();
}
public static AxisLabel defaultAxisLabel
{
get
{
return new AxisLabel()
{
m_Show = true,
m_Interval = 0,
m_Inside = false,
m_Distance = 8,
m_TextStyle = new TextStyle(),
};
}
}
public new AxisLabel Clone()
{
var axisLabel = new AxisLabel
{
show = show,
formatter = formatter,
interval = interval,
inside = inside,
distance = distance,
numericFormatter = numericFormatter,
width = width,
height = height,
showStartLabel = showStartLabel,
showEndLabel = showEndLabel,
showZeroLabel = showZeroLabel,
textLimit = textLimit.Clone()
};
axisLabel.textStyle.Copy(textStyle);
return axisLabel;
}
public void Copy(AxisLabel axisLabel)
{
show = axisLabel.show;
formatter = axisLabel.formatter;
interval = axisLabel.interval;
inside = axisLabel.inside;
distance = axisLabel.distance;
numericFormatter = axisLabel.numericFormatter;
width = axisLabel.width;
height = axisLabel.height;
showStartLabel = axisLabel.showStartLabel;
showEndLabel = axisLabel.showEndLabel;
showZeroLabel = axisLabel.showZeroLabel;
textLimit.Copy(axisLabel.textLimit);
textStyle.Copy(axisLabel.textStyle);
}
public void SetRelatedText(ChartText txt, float labelWidth)
{
m_TextLimit.SetRelatedText(txt, labelWidth);
}
public override string GetFormatterContent(int labelIndex, int totalIndex, string category)
{
if (string.IsNullOrEmpty(category))
return GetFormatterFunctionContent(labelIndex, category, category);
if (string.IsNullOrEmpty(m_Formatter))
{
return GetFormatterFunctionContent(labelIndex, category, m_TextLimit.GetLimitContent(category));
}
else
{
var content = m_Formatter;
FormatterHelper.ReplaceAxisLabelContent(ref content, category, labelIndex, totalIndex);
return GetFormatterFunctionContent(labelIndex, category, m_TextLimit.GetLimitContent(content));
}
}
public override string GetFormatterContent(int labelIndex, int totalIndex, double value, double minValue, double maxValue, bool isLog = false)
{
if (showAsPositiveNumber && value < 0)
{
value = Math.Abs(value);
}
return base.GetFormatterContent(labelIndex, totalIndex, value, minValue, maxValue, isLog);
}
public bool IsNeedShowLabel(int index, int total, string content = null)
{
var labelShow = show && (interval == 0 || index % (interval + 1) == 0);
if (labelShow)
{
if (!showStartLabel && index == 0) labelShow = false;
else if (!showEndLabel && index == total - 1) labelShow = false;
if (labelShow && content == "0") labelShow = showZeroLabel;
}
return labelShow;
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 051f9473d1beb4e0bb35aa1600cb44bd
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,97 @@
using UnityEngine;
namespace XCharts.Runtime
{
/// <summary>
/// Settings related to axis line.
/// ||坐标轴轴线。
/// </summary>
[System.Serializable]
public class AxisLine : BaseLine
{
[SerializeField] private bool m_OnZero;
[SerializeField] private float m_StartExtendLength;
[SerializeField] private float m_EndExtendLength;
[SerializeField] private bool m_ShowArrow;
[SerializeField] private ArrowStyle m_Arrow = new ArrowStyle();
/// <summary>
/// When mutiple axes exists, this option can be used to specify which axis can be "onZero" to.
/// ||X 轴或者 Y 轴的轴线是否在另一个轴的 0 刻度上,只有在另一个轴为数值轴且包含 0 刻度时有效。
/// </summary>
public bool onZero
{
get { return m_OnZero; }
set { if (PropertyUtil.SetStruct(ref m_OnZero, value)) SetVerticesDirty(); }
}
/// <summary>
/// Extend length of the axis line at the start.
/// ||轴线起点延长线长度。
/// </summary>
public float startExtendLength
{
get { return m_StartExtendLength; }
set { if (PropertyUtil.SetStruct(ref m_StartExtendLength, value)) SetVerticesDirty(); }
}
/// <summary>
/// Extend length of the axis line at the end.
/// ||轴线终点延长线长度。
/// </summary>
public float endExtendLength
{
get { return m_EndExtendLength; }
set { if (PropertyUtil.SetStruct(ref m_EndExtendLength, value)) SetVerticesDirty(); }
}
/// <summary>
/// Whether to show the arrow symbol of axis.
/// ||是否显示箭头。
/// </summary>
public bool showArrow
{
get { return m_ShowArrow; }
set { if (PropertyUtil.SetStruct(ref m_ShowArrow, value)) SetVerticesDirty(); }
}
/// <summary>
/// the arrow of line.
/// ||轴线箭头。
/// </summary>
public ArrowStyle arrow
{
get { return m_Arrow; }
set { if (PropertyUtil.SetClass(ref m_Arrow, value)) SetVerticesDirty(); }
}
public static AxisLine defaultAxisLine
{
get
{
var axisLine = new AxisLine
{
m_Show = true,
m_OnZero = true,
m_ShowArrow = false,
m_Arrow = new ArrowStyle(),
m_LineStyle = new LineStyle(LineStyle.Type.None),
};
return axisLine;
}
}
public AxisLine Clone()
{
var axisLine = new AxisLine();
axisLine.show = show;
axisLine.onZero = onZero;
axisLine.showArrow = showArrow;
axisLine.arrow = arrow.Clone();
return axisLine;
}
public void Copy(AxisLine axisLine)
{
base.Copy(axisLine);
onZero = axisLine.onZero;
showArrow = axisLine.showArrow;
arrow.Copy(axisLine.arrow);
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 2748c2a8789724709aa76f6056eb708d
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,62 @@
using System;
using UnityEngine;
namespace XCharts.Runtime
{
/// <summary>
/// Minor split line of axis in grid area.
/// ||坐标轴在 grid 区域中的次分隔线。次分割线会对齐次刻度线 minorTick。
/// </summary>
[Serializable]
[Since("v3.2.0")]
public class AxisMinorSplitLine : BaseLine
{
[SerializeField] private float m_Distance;
[SerializeField] private bool m_AutoColor;
/// <summary>
/// The distance between the split line and axis line.
/// ||刻度线与轴线的距离。
/// </summary>
public float distance { get { return m_Distance; } set { m_Distance = value; } }
/// <summary>
/// auto color.
/// ||自动设置颜色。
/// </summary>
public bool autoColor { get { return m_AutoColor; } set { m_AutoColor = value; } }
public override bool vertsDirty { get { return m_VertsDirty || m_LineStyle.anyDirty; } }
public override void ClearVerticesDirty()
{
base.ClearVerticesDirty();
m_LineStyle.ClearVerticesDirty();
}
public static AxisMinorSplitLine defaultMinorSplitLine
{
get
{
return new AxisMinorSplitLine()
{
m_Show = false,
};
}
}
public AxisMinorSplitLine Clone()
{
var axisSplitLine = new AxisMinorSplitLine();
axisSplitLine.show = show;
axisSplitLine.distance = distance;
axisSplitLine.autoColor = autoColor;
axisSplitLine.lineStyle = lineStyle.Clone();
return axisSplitLine;
}
public void Copy(AxisMinorSplitLine splitLine)
{
base.Copy(splitLine);
distance = splitLine.distance;
autoColor = splitLine.autoColor;
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 7be5a277811c64887a121d7711929aab
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,63 @@
using UnityEngine;
namespace XCharts.Runtime
{
/// <summary>
/// Settings related to axis minor tick.
/// ||坐标轴次刻度相关设置。注意:次刻度无法在类目轴中使用。
/// </summary>
[System.Serializable]
[Since("v3.2.0")]
public class AxisMinorTick : BaseLine
{
[SerializeField] protected int m_SplitNumber = 5;
[SerializeField] private bool m_AutoColor;
/// <summary>
/// Number of segments that the axis is split into.
/// ||分隔线之间分割的刻度数。
/// </summary>
public int splitNumber
{
get { return m_SplitNumber; }
set { if (PropertyUtil.SetStruct(ref m_SplitNumber, value)) SetAllDirty(); }
}
public bool autoColor { get { return m_AutoColor; } set { m_AutoColor = value; } }
public override bool vertsDirty { get { return m_VertsDirty || m_LineStyle.anyDirty; } }
public override void ClearVerticesDirty()
{
base.ClearVerticesDirty();
m_LineStyle.ClearVerticesDirty();
}
public static AxisMinorTick defaultMinorTick
{
get
{
var tick = new AxisMinorTick
{
m_Show = false
};
return tick;
}
}
public AxisMinorTick Clone()
{
var axisTick = new AxisMinorTick();
axisTick.show = show;
axisTick.splitNumber = splitNumber;
axisTick.autoColor = autoColor;
axisTick.lineStyle = lineStyle.Clone();
return axisTick;
}
public void Copy(AxisMinorTick axisTick)
{
show = axisTick.show;
splitNumber = axisTick.splitNumber;
autoColor = axisTick.autoColor;
lineStyle.Copy(axisTick.lineStyle);
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 3bea237f1eccc409ba2635e6f4ca609c
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,86 @@
using System;
using UnityEngine;
namespace XCharts.Runtime
{
/// <summary>
/// the name of axis.
/// ||坐标轴名称。
/// </summary>
[Serializable]
public class AxisName : ChildComponent
{
[SerializeField] private bool m_Show;
[SerializeField] private string m_Name;
[SerializeField][Since("v3.1.0")] private bool m_OnZero;
[SerializeField] private LabelStyle m_LabelStyle = new LabelStyle();
/// <summary>
/// Whether to show axis name.
/// ||是否显示坐标轴名称。
/// </summary>
public bool show
{
get { return m_Show; }
set { if (PropertyUtil.SetStruct(ref m_Show, value)) SetComponentDirty(); }
}
/// <summary>
/// the name of axis.
/// ||坐标轴名称。
/// </summary>
public string name
{
get { return m_Name; }
set { if (PropertyUtil.SetClass(ref m_Name, value)) SetComponentDirty(); }
}
/// <summary>
/// Whether the axis name position are the same with 0 position of YAxis.
/// ||坐标轴名称的位置是否保持和Y轴0刻度一致。
/// </summary>
public bool onZero
{
get { return m_OnZero; }
set { if (PropertyUtil.SetStruct(ref m_OnZero, value)) SetComponentDirty(); }
}
/// <summary>
/// The text style of axis name.
/// ||文本样式。
/// </summary>
public LabelStyle labelStyle
{
get { return m_LabelStyle; }
set { if (PropertyUtil.SetClass(ref m_LabelStyle, value)) SetComponentDirty(); }
}
public static AxisName defaultAxisName
{
get
{
var axisName = new AxisName()
{
m_Show = false,
m_Name = "axisName",
m_LabelStyle = new LabelStyle()
};
axisName.labelStyle.position = LabelStyle.Position.End;
return axisName;
}
}
public AxisName Clone()
{
var axisName = new AxisName();
axisName.show = show;
axisName.name = name;
axisName.m_LabelStyle.Copy(m_LabelStyle);
return axisName;
}
public void Copy(AxisName axisName)
{
show = axisName.show;
name = axisName.name;
m_LabelStyle.Copy(axisName.labelStyle);
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 878555ba3c6b1479f94f38185700531e
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,80 @@
using System;
using System.Collections.Generic;
using UnityEngine;
namespace XCharts.Runtime
{
/// <summary>
/// Split area of axis in grid area, not shown by default.
/// ||坐标轴在 grid 区域中的分隔区域,默认不显示。
/// </summary>
[Serializable]
public class AxisSplitArea : ChildComponent
{
[SerializeField] private bool m_Show;
[SerializeField] private List<Color32> m_Color;
/// <summary>
/// Set this to true to show the splitArea.
/// ||是否显示分隔区域。
/// </summary>
public bool show
{
get { return m_Show; }
set { if (PropertyUtil.SetStruct(ref m_Show, value)) SetVerticesDirty(); }
}
/// <summary>
/// Color of split area. SplitArea color could also be set in color array,
/// which the split lines would take as their colors in turns.
/// Dark and light colors in turns are used by default.
/// ||分隔区域颜色。分隔区域会按数组中颜色的顺序依次循环设置颜色。默认是一个深浅的间隔色。
/// </summary>
public List<Color32> color
{
get { return m_Color; }
set { if (value != null) { m_Color = value; SetVerticesDirty(); } }
}
public static AxisSplitArea defaultSplitArea
{
get
{
return new AxisSplitArea()
{
m_Show = false,
m_Color = new List<Color32>() { }
};
}
}
public AxisSplitArea Clone()
{
var axisSplitArea = new AxisSplitArea();
axisSplitArea.show = show;
axisSplitArea.color = new List<Color32>();
ChartHelper.CopyList(axisSplitArea.color, color);
return axisSplitArea;
}
public void Copy(AxisSplitArea splitArea)
{
show = splitArea.show;
color.Clear();
ChartHelper.CopyList(color, splitArea.color);
}
public Color32 GetColor(int index, BaseAxisTheme theme)
{
if (color.Count > 0)
{
var i = index % color.Count;
return color[i];
}
else
{
var i = index % theme.splitAreaColors.Count;
return theme.splitAreaColors[i];
}
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 18702fd7797054670af64546b7304bb4
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,112 @@
using System;
using UnityEngine;
namespace XCharts.Runtime
{
/// <summary>
/// Split line of axis in grid area.
/// ||坐标轴在 grid 区域中的分隔线。
/// </summary>
[Serializable]
public class AxisSplitLine : BaseLine
{
[SerializeField] private int m_Interval;
[SerializeField] private float m_Distance;
[SerializeField] private bool m_AutoColor;
[SerializeField][Since("v3.3.0")] private bool m_ShowStartLine = true;
[SerializeField][Since("v3.3.0")] private bool m_ShowEndLine = true;
[SerializeField][Since("v3.11.0")] private bool m_ShowZLine = true;
/// <summary>
/// The distance between the split line and axis line.
/// ||刻度线与轴线的距离。
/// </summary>
public float distance { get { return m_Distance; } set { m_Distance = value; } }
/// <summary>
/// auto color.
/// ||自动设置颜色。
/// </summary>
public bool autoColor { get { return m_AutoColor; } set { m_AutoColor = value; } }
/// <summary>
/// Interval of Axis splitLine.
/// ||坐标轴分隔线的显示间隔。
/// </summary>
public int interval
{
get { return m_Interval; }
set { if (PropertyUtil.SetStruct(ref m_Interval, value)) SetVerticesDirty(); }
}
/// <summary>
/// Whether to show the first split line.
/// ||是否显示第一条分割线。
/// </summary>
public bool showStartLine
{
get { return m_ShowStartLine; }
set { if (PropertyUtil.SetStruct(ref m_ShowStartLine, value)) SetVerticesDirty(); }
}
/// <summary>
/// Whether to show the last split line.
/// ||是否显示最后一条分割线。
/// </summary>
public bool showEndLine
{
get { return m_ShowEndLine; }
set { if (PropertyUtil.SetStruct(ref m_ShowEndLine, value)) SetVerticesDirty(); }
}
/// <summary>
/// Whether to show the Z axis part of the split line. Generally used for 3D coordinate systems.
/// ||是否显示Z轴部分分割线。一般用于3D坐标系。
/// </summary>
public bool showZLine
{
get { return m_ShowZLine; }
set { if (PropertyUtil.SetStruct(ref m_ShowZLine, value)) SetVerticesDirty(); }
}
public override bool vertsDirty { get { return m_VertsDirty || m_LineStyle.anyDirty; } }
public override void ClearVerticesDirty()
{
base.ClearVerticesDirty();
m_LineStyle.ClearVerticesDirty();
}
public static AxisSplitLine defaultSplitLine
{
get
{
return new AxisSplitLine()
{
m_Show = false,
};
}
}
public AxisSplitLine Clone()
{
var axisSplitLine = new AxisSplitLine();
axisSplitLine.show = show;
axisSplitLine.interval = interval;
axisSplitLine.showStartLine = showStartLine;
axisSplitLine.showEndLine = showEndLine;
axisSplitLine.lineStyle = lineStyle.Clone();
return axisSplitLine;
}
public void Copy(AxisSplitLine splitLine)
{
base.Copy(splitLine);
interval = splitLine.interval;
showStartLine = splitLine.showStartLine;
showEndLine = splitLine.showEndLine;
}
internal bool NeedShow(int index, int total)
{
if (!show) return false;
if (interval != 0 && index % (interval + 1) != 0) return false;
if (!showStartLine && index == 0) return false;
if (!showEndLine && index == total - 1) return false;
return true;
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 3da942a7a6bea44e2998ed993c0641ab
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,110 @@
using UnityEngine;
namespace XCharts.Runtime
{
/// <summary>
/// Settings related to axis tick.
/// ||坐标轴刻度相关设置。
/// </summary>
[System.Serializable]
public class AxisTick : BaseLine
{
[SerializeField] private bool m_AlignWithLabel;
[SerializeField] private bool m_Inside;
[SerializeField] private bool m_ShowStartTick;
[SerializeField] private bool m_ShowEndTick;
[SerializeField] private float m_Distance;
[SerializeField] protected int m_SplitNumber = 0;
[SerializeField] private bool m_AutoColor;
/// <summary>
/// The distance between the tick line and axis line.
/// ||刻度线与轴线的距离。
/// </summary>
public float distance { get { return m_Distance; } set { m_Distance = value; } }
/// <summary>
/// Align axis tick with label, which is available only when boundaryGap is set to be true in category axis.
/// ||类目轴中在 boundaryGap 为 true 的时候有效,可以保证刻度线和标签对齐。
/// </summary>
public bool alignWithLabel
{
get { return m_AlignWithLabel; }
set { if (PropertyUtil.SetStruct(ref m_AlignWithLabel, value)) SetVerticesDirty(); }
}
/// <summary>
/// Set this to true so the axis labels face the inside direction.
/// ||坐标轴刻度是否朝内,默认朝外。
/// </summary>
public bool inside
{
get { return m_Inside; }
set { if (PropertyUtil.SetStruct(ref m_Inside, value)) SetVerticesDirty(); }
}
/// <summary>
/// Whether to display the first tick.
/// ||是否显示第一个刻度。
/// </summary>
public bool showStartTick
{
get { return m_ShowStartTick; }
set { if (PropertyUtil.SetStruct(ref m_ShowStartTick, value)) SetVerticesDirty(); }
}
/// <summary>
/// Whether to display the last tick.
/// ||是否显示最后一个刻度。
/// </summary>
public bool showEndTick
{
get { return m_ShowEndTick; }
set { if (PropertyUtil.SetStruct(ref m_ShowEndTick, value)) SetVerticesDirty(); }
}
/// <summary>
/// Number of segments that the axis is split into.
/// ||分隔线之间分割的刻度数。
/// </summary>
public int splitNumber
{
get { return m_SplitNumber; }
set { if (PropertyUtil.SetStruct(ref m_SplitNumber, value)) SetAllDirty(); }
}
public bool autoColor { get { return m_AutoColor; } set { m_AutoColor = value; } }
public static AxisTick defaultTick
{
get
{
var tick = new AxisTick
{
m_Show = true,
m_AlignWithLabel = false,
m_Inside = false,
m_ShowStartTick = true,
m_ShowEndTick = true
};
return tick;
}
}
public AxisTick Clone()
{
var axisTick = new AxisTick();
axisTick.show = show;
axisTick.alignWithLabel = alignWithLabel;
axisTick.inside = inside;
axisTick.showStartTick = showStartTick;
axisTick.showEndTick = showEndTick;
axisTick.lineStyle = lineStyle.Clone();
return axisTick;
}
public void Copy(AxisTick axisTick)
{
show = axisTick.show;
alignWithLabel = axisTick.alignWithLabel;
inside = axisTick.inside;
showStartTick = axisTick.showStartTick;
showEndTick = axisTick.showEndTick;
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 60278762ed892450d85e27b7df8f997e
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 24693180b2a2e41b2ab4025b2bbebf01
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,30 @@
using System.Collections.Generic;
using UnityEngine;
namespace XCharts.Runtime
{
[System.Serializable]
[RequireChartComponent(typeof(ParallelCoord))]
[ComponentHandler(typeof(ParallelAxisHander), true)]
public class ParallelAxis : Axis
{
public override void SetDefaultValue()
{
m_Show = true;
m_Type = AxisType.Value;
m_Min = 0;
m_Max = 0;
m_SplitNumber = 0;
m_BoundaryGap = true;
m_Position = AxisPosition.Bottom;
m_Offset = 0;
m_Data = new List<string>() { "x1", "x2", "x3", "x4", "x5" };
m_Icons = new List<Sprite>(5);
splitLine.show = false;
splitLine.lineStyle.type = LineStyle.Type.None;
axisLabel.textLimit.enable = true;
axisName.labelStyle.offset = new Vector3(0, 25, 0);
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: d7bc01c54f4d6485389fd57c37810c74
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,168 @@
using UnityEngine;
using UnityEngine.UI;
namespace XCharts.Runtime
{
[UnityEngine.Scripting.Preserve]
internal sealed class ParallelAxisHander : AxisHandler<ParallelAxis>
{
private Orient m_Orient;
private ParallelCoord m_Parallel;
protected override Orient orient { get { return m_Orient; } }
public override void InitComponent()
{
InitParallelAxis(component);
}
public override void Update()
{
UpdateContext(component);
}
public override void DrawBase(VertexHelper vh)
{
UpdateContext(component);
DrawParallelAxisSplit(vh, component);
DrawParallelAxisLine(vh, component);
DrawParallelAxisTick(vh, component);
}
private void UpdateContext(ParallelAxis axis)
{
var parallel = chart.GetChartComponent<ParallelCoord>(axis.parallelIndex);
if (parallel == null)
return;
m_Orient = parallel.orient;
m_Parallel = parallel;
var axisCount = chart.GetChartComponentNum<ParallelAxis>();
if (m_Orient == Orient.Horizonal)
{
var each = axisCount > 1 ? parallel.context.height / (axisCount - 1) : 0;
axis.context.x = parallel.context.x;
axis.context.y = parallel.context.y + (axis.index) * each;
axis.context.width = parallel.context.width;
axis.context.length = parallel.context.width;
}
else
{
var each = axisCount > 1 ? parallel.context.width / (axisCount - 1) : 0;
axis.context.x = parallel.context.x + (axis.index) * each;
axis.context.y = parallel.context.y;
axis.context.width = parallel.context.height;
axis.context.length = parallel.context.height;
}
axis.context.orient = m_Orient;
axis.context.height = 0;
axis.context.position = new Vector3(axis.context.x, axis.context.y);
}
private void InitParallelAxis(ParallelAxis axis)
{
var theme = chart.theme;
var xAxisIndex = axis.index;
axis.painter = chart.painter;
axis.refreshComponent = delegate()
{
UpdateContext(axis);
InitAxis(null,
m_Orient,
axis.context.x,
axis.context.y,
axis.context.width,
axis.context.height);
};
axis.refreshComponent();
}
internal override void UpdateAxisLabelText(Axis axis)
{
base.UpdateAxisLabelText(axis);
if (axis.IsTime() || axis.IsValue())
{
for (int i = 0; i < axis.context.labelObjectList.Count; i++)
{
var label = axis.context.labelObjectList[i];
if (label != null)
{
var pos = GetLabelPosition(0, i);
label.SetPosition(pos);
CheckValueLabelActive(component, i, label, pos);
}
}
}
}
protected override Vector3 GetLabelPosition(float scaleWid, int i)
{
if (m_Parallel == null)
return Vector3.zero;
return GetLabelPosition(i, m_Orient, component, null,
chart.theme.axis,
scaleWid,
component.context.x,
component.context.y,
component.context.width,
component.context.height);
}
private void DrawParallelAxisSplit(VertexHelper vh, ParallelAxis axis)
{
if (AxisHelper.NeedShowSplit(axis))
{
if (m_Parallel == null)
return;
var dataZoom = chart.GetDataZoomOfAxis(axis);
DrawAxisSplit(vh, chart.theme.axis, dataZoom,
m_Orient,
axis.context.x,
axis.context.y,
axis.context.width,
axis.context.height);
}
}
private void DrawParallelAxisTick(VertexHelper vh, ParallelAxis axis)
{
if (AxisHelper.NeedShowSplit(axis))
{
if (m_Parallel == null)
return;
var dataZoom = chart.GetDataZoomOfAxis(axis);
DrawAxisTick(vh, axis, chart.theme.axis, dataZoom,
m_Orient,
axis.context.x,
axis.context.y,
axis.context.width);
}
}
private void DrawParallelAxisLine(VertexHelper vh, ParallelAxis axis)
{
if (axis.show && axis.axisLine.show)
{
if (m_Parallel == null)
return;
DrawAxisLine(vh, axis,
chart.theme.axis,
m_Orient,
axis.context.x,
axis.context.y,
axis.context.width);
}
}
internal override float GetAxisLineXOrY()
{
return component.context.x;
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 26ab25bf702c54ad38461c91ba1451af
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 7c8971958a94d47e68f7ebdff5872b71
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,28 @@
using System.Collections.Generic;
namespace XCharts.Runtime
{
/// <summary>
/// Radial axis of polar coordinate.
/// ||极坐标系的径向轴。
/// </summary>
[System.Serializable]
[RequireChartComponent(typeof(PolarCoord))]
[ComponentHandler(typeof(RadiusAxisHandler), true)]
public class RadiusAxis : Axis
{
public override void SetDefaultValue()
{
m_Show = true;
m_Type = AxisType.Value;
m_Min = 0;
m_Max = 0;
m_SplitNumber = 5;
m_BoundaryGap = false;
m_Data = new List<string>(5);
splitLine.show = true;
splitLine.lineStyle.type = LineStyle.Type.Solid;
axisLabel.textLimit.enable = false;
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: f6429398a27934726ba49d387d681728
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,217 @@
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using XUGL;
namespace XCharts.Runtime
{
[UnityEngine.Scripting.Preserve]
internal sealed class RadiusAxisHandler : AxisHandler<RadiusAxis>
{
public override void InitComponent()
{
InitRadiusAxis(component);
}
public override void Update()
{
UpdateAxisMinMaxValue(component);
UpdatePointerValue(component);
}
public override void DrawBase(VertexHelper vh)
{
DrawRadiusAxis(vh, component);
}
protected override void UpdatePointerValue(Axis axis)
{
if (axis == null)
return;
var polar = chart.GetChartComponent<PolarCoord>(axis.polarIndex);
if (polar == null)
return;
if (!polar.context.isPointerEnter)
{
axis.context.pointerValue = double.PositiveInfinity;
return;
}
var angleAxis = ComponentHelper.GetAngleAxis(chart.components, polar.index);
if (angleAxis == null)
return;
var dist = Vector3.Distance(chart.pointerPos, polar.context.center);
axis.context.pointerValue = axis.context.minValue + (dist / polar.context.radius) * axis.context.minMaxRange;
axis.context.pointerLabelPosition = GetLabelPosition(polar, axis, angleAxis.context.startAngle, dist);
}
private void UpdateAxisMinMaxValue(RadiusAxis axis, bool updateChart = true)
{
if (axis == null) return;
if (axis.IsCategory() || !axis.show) return;
double tempMinValue;
double tempMaxValue;
SeriesHelper.GetXMinMaxValue(chart, axis.polarIndex, axis.inverse, out tempMinValue,
out tempMaxValue, true);
AxisHelper.AdjustMinMaxValue(axis, ref tempMinValue, ref tempMaxValue, true);
if (tempMinValue != axis.context.minValue || tempMaxValue != axis.context.maxValue)
{
axis.UpdateMinMaxValue(tempMinValue, tempMaxValue);
axis.context.offset = 0;
axis.context.lastCheckInverse = axis.inverse;
UpdateAxisTickValueList(axis);
if (updateChart)
{
UpdateAxisLabelText(axis);
chart.RefreshChart();
}
}
}
internal void UpdateAxisLabelText(RadiusAxis axis)
{
if (axis == null)
return;
var polar = chart.GetChartComponent<PolarCoord>(axis.polarIndex);
if (axis.context.labelObjectList.Count <= 0)
InitRadiusAxis(axis);
else
{
UpdateLabelText(axis, polar.context.radius, null, false);
}
}
private void InitRadiusAxis(RadiusAxis axis)
{
var polar = chart.GetChartComponent<PolarCoord>(axis.index);
if (polar == null)
return;
var angleAxis = ComponentHelper.GetAngleAxis(chart.components, polar.index);
if (angleAxis == null)
return;
PolarHelper.UpdatePolarCenter(polar, chart.chartPosition, chart.chartWidth, chart.chartHeight);
axis.context.labelObjectList.Clear();
var radius = polar.context.outsideRadius - polar.context.insideRadius;
var objName = component.GetType().Name + axis.index;
var axisObj = ChartHelper.AddObject(objName, chart.transform, chart.chartMinAnchor,
chart.chartMaxAnchor, chart.chartPivot, chart.chartSizeDelta, -1, chart.childrenNodeNames);
axisObj.transform.localPosition = Vector3.zero;
axisObj.SetActive(axis.show && axis.axisLabel.show);
axisObj.hideFlags = chart.chartHideFlags;
ChartHelper.HideAllObject(axisObj);
var textStyle = axis.axisLabel.textStyle;
var splitNumber = AxisHelper.GetScaleNumber(axis, radius, null);
var totalWidth = polar.context.insideRadius;
var txtHig = textStyle.GetFontSize(chart.theme.axis) + 2;
for (int i = 0; i < splitNumber; i++)
{
var labelWidth = AxisHelper.GetScaleWidth(axis, radius, i + 1, null);
var inside = axis.axisLabel.inside;
var isPercentStack = SeriesHelper.IsPercentStack<Bar>(chart.series);
var labelName = AxisHelper.GetLabelName(axis, radius, i, axis.context.minValue, axis.context.maxValue,
null, isPercentStack, chart.useUtc);
var label = ChartHelper.AddAxisLabelObject(splitNumber, i, objName + i, axisObj.transform,
new Vector2(labelWidth, txtHig), axis, chart.theme.axis, labelName, Color.clear);
if (i == 0)
axis.axisLabel.SetRelatedText(label.text, labelWidth);
label.text.SetAlignment(textStyle.GetAlignment(TextAnchor.MiddleCenter));
label.SetText(labelName);
label.SetPosition(GetLabelPosition(polar, axis, angleAxis.context.startAngle, totalWidth));
label.SetActive(true, true);
label.SetTextActive(true);
axis.context.labelObjectList.Add(label);
totalWidth += labelWidth;
}
}
private Vector3 GetLabelPosition(PolarCoord polar, Axis axis, float startAngle, float totalWidth)
{
var cenPos = polar.context.center;
var dire = ChartHelper.GetDire(startAngle, true).normalized;
var tickLength = axis.axisTick.GetLength(chart.theme.axis.tickLength);
var tickVector = ChartHelper.GetVertialDire(dire) *
(tickLength + axis.axisLabel.distance);
if (axis.IsCategory())
{
totalWidth += polar.context.radius / axis.data.Count / 2;
}
return ChartHelper.GetPos(cenPos, totalWidth, startAngle, true) + tickVector;
}
private void DrawRadiusAxis(VertexHelper vh, RadiusAxis radiusAxis)
{
if (radiusAxis == null)
return;
var polar = chart.GetChartComponent<PolarCoord>(radiusAxis.polarIndex);
if (polar == null)
return;
var angleAxis = ComponentHelper.GetAngleAxis(chart.components, polar.index);
if (angleAxis == null)
return;
var startAngle = angleAxis.context.startAngle;
var radius = polar.context.radius;
var cenPos = polar.context.center;
var size = AxisHelper.GetScaleNumber(radiusAxis, radius, null);
var totalWidth = polar.context.insideRadius;
var dire = ChartHelper.GetDire(startAngle, true).normalized;
var tickWidth = radiusAxis.axisTick.GetWidth(chart.theme.axis.tickWidth);
var tickLength = radiusAxis.axisTick.GetLength(chart.theme.axis.tickLength);
var tickVetor = ChartHelper.GetVertialDire(dire) * tickLength;
for (int i = 0; i < size; i++)
{
var scaleWidth = AxisHelper.GetScaleWidth(radiusAxis, radius, i + 1);
var pos = ChartHelper.GetPos(cenPos, totalWidth + tickWidth, startAngle, true);
if (radiusAxis.show && radiusAxis.splitLine.show)
{
if (CanDrawSplitLine(angleAxis, i, size) && radiusAxis.splitLine.NeedShow(i, size))
{
var outsideRaidus = totalWidth + radiusAxis.splitLine.GetWidth(chart.theme.axis.splitLineWidth) * 2;
var splitLineColor = radiusAxis.splitLine.GetColor(chart.theme.axis.splitLineColor);
UGL.DrawDoughnut(vh, cenPos, totalWidth, outsideRaidus, splitLineColor, ColorUtil.clearColor32);
}
}
if (radiusAxis.show && radiusAxis.axisTick.show)
{
if ((i == 0 && radiusAxis.axisTick.showStartTick) ||
(i == size && radiusAxis.axisTick.showEndTick) ||
(i > 0 && i < size))
{
UGL.DrawLine(vh, pos, pos + tickVetor, tickWidth, chart.theme.axis.lineColor);
}
}
totalWidth += scaleWidth;
}
if (radiusAxis.show && radiusAxis.axisLine.show)
{
var lineStartPos = polar.context.center + dire * polar.context.insideRadius;
var lineEndPos = polar.context.center + dire * (polar.context.outsideRadius + 2 * tickWidth);
var lineWidth = radiusAxis.axisLine.GetWidth(chart.theme.axis.lineWidth);
UGL.DrawLine(vh, lineStartPos, lineEndPos, lineWidth, chart.theme.axis.lineColor);
}
}
private bool CanDrawSplitLine(AngleAxis angleAxis, int i, int size)
{
if (angleAxis.axisLine.show)
{
return i != size - 1 && i != 0;
}
else
{
return true;
}
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 3f2cb79bfe30c4f14a3117f9f30ed3bd
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 17498717d39c14b43a91c67401407410
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,162 @@
using System.Collections.Generic;
using UnityEngine;
namespace XCharts.Runtime
{
/// <summary>
/// Single axis.
/// ||单轴。
/// </summary>
[System.Serializable]
[ComponentHandler(typeof(SingleAxisHander), true)]
public class SingleAxis : Axis, IUpdateRuntimeData
{
[SerializeField] protected Orient m_Orient = Orient.Horizonal;
[SerializeField] private float m_Left = 0.1f;
[SerializeField] private float m_Right = 0.1f;
[SerializeField] private float m_Top = 0f;
[SerializeField] private float m_Bottom = 0.2f;
[SerializeField] private float m_Width = 0;
[SerializeField] private float m_Height = 50;
/// <summary>
/// Orientation of the axis. By default, it's 'Horizontal'. You can set it to be 'Vertical' to make a vertical axis.
/// ||坐标轴朝向。默认为水平朝向。
/// </summary>
public Orient orient
{
get { return m_Orient; }
set { if (PropertyUtil.SetStruct(ref m_Orient, value)) SetAllDirty(); }
}
/// <summary>
/// Distance between component and the left side of the container.
/// ||组件离容器左侧的距离。
/// </summary>
public float left
{
get { return m_Left; }
set { if (PropertyUtil.SetStruct(ref m_Left, value)) SetAllDirty(); }
}
/// <summary>
/// Distance between component and the right side of the container.
/// ||组件离容器右侧的距离。
/// </summary>
public float right
{
get { return m_Right; }
set { if (PropertyUtil.SetStruct(ref m_Right, value)) SetAllDirty(); }
}
/// <summary>
/// Distance between component and the top side of the container.
/// ||组件离容器上侧的距离。
/// </summary>
public float top
{
get { return m_Top; }
set { if (PropertyUtil.SetStruct(ref m_Top, value)) SetAllDirty(); }
}
/// <summary>
/// Distance between component and the bottom side of the container.
/// ||组件离容器下侧的距离。
/// </summary>
public float bottom
{
get { return m_Bottom; }
set { if (PropertyUtil.SetStruct(ref m_Bottom, value)) SetAllDirty(); }
}
/// <summary>
/// width of axis.
/// ||坐标轴宽。
/// </summary>
public float width
{
get { return m_Width; }
set { if (PropertyUtil.SetStruct(ref m_Width, value)) SetAllDirty(); }
}
/// <summary>
/// height of axis.
/// ||坐标轴高。
/// </summary>
public float height
{
get { return m_Height; }
set { if (PropertyUtil.SetStruct(ref m_Height, value)) SetAllDirty(); }
}
public void UpdateRuntimeData(BaseChart chart)
{
var chartX = chart.chartX;
var chartY = chart.chartY;
var chartWidth = chart.chartWidth;
var chartHeight = chart.chartHeight;
context.left = left <= 1 ? left * chartWidth : left;
context.bottom = bottom <= 1 ? bottom * chartHeight : bottom;
context.top = top <= 1 ? top * chartHeight : top;
context.right = right <= 1 ? right * chartWidth : right;
context.height = height <= 1 ? height * chartHeight : height;
if (m_Orient == Orient.Horizonal)
{
context.width = width == 0 ?
chartWidth - context.left - context.right :
(width <= 1 ? chartWidth * width : width);
}
else
{
context.width = width == 0 ?
chartHeight - context.top - context.bottom :
(width <= 1 ? chartHeight * width : width);
}
if (context.left != 0 && context.right == 0)
context.x = chartX + context.left;
else if (context.left == 0 && context.right != 0)
context.x = chartX + chartWidth - context.right - context.width;
else
context.x = chartX + context.left;
if (context.bottom != 0 && context.top == 0)
context.y = chartY + context.bottom;
else if (context.bottom == 0 && context.top != 0)
context.y = chartY + chartHeight - context.top - context.height;
else
context.y = chartY + context.bottom;
context.start = new Vector3(context.x, context.y);
if (m_Orient == Orient.Horizonal)
context.end = new Vector3(context.x + context.width, context.y);
else
context.end = new Vector3(context.x, context.y + context.height);
context.length = (context.end - context.start).magnitude;
context.position = new Vector3(context.x, context.y);
}
public override void SetDefaultValue()
{
m_Show = true;
m_Type = AxisType.Category;
m_Min = 0;
m_Max = 0;
m_SplitNumber = 0;
m_BoundaryGap = true;
m_Position = AxisPosition.Bottom;
m_Offset = 0;
m_Left = 0.1f;
m_Right = 0.1f;
m_Top = 0;
m_Bottom = 0.2f;
m_Width = 0;
m_Height = 50;
m_Data = new List<string>() { "x1", "x2", "x3", "x4", "x5" };
m_Icons = new List<Sprite>(5);
splitLine.show = false;
splitLine.lineStyle.type = LineStyle.Type.None;
axisLabel.textLimit.enable = true;
axisTick.showStartTick = true;
axisTick.showEndTick = true;
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: aeb871d6555744e609bd651306c601a8
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,122 @@
using UnityEngine;
using UnityEngine.UI;
namespace XCharts.Runtime
{
[UnityEngine.Scripting.Preserve]
internal sealed class SingleAxisHander : AxisHandler<SingleAxis>
{
protected override Orient orient { get { return component.orient; } }
public override void InitComponent()
{
InitXAxis(component);
}
public override void Update()
{
UpdateAxisMinMaxValue(component.index, component);
UpdatePointerValue(component);
}
public override void DrawBase(VertexHelper vh)
{
DrawSingleAxisSplit(vh, component);
DrawSingleAxisLine(vh, component);
DrawSingleAxisTick(vh, component);
}
private void InitXAxis(SingleAxis axis)
{
var theme = chart.theme;
var xAxisIndex = axis.index;
axis.painter = chart.painter;
axis.refreshComponent = delegate()
{
axis.UpdateRuntimeData(chart);
InitAxis(null,
axis.orient,
axis.context.x,
axis.context.y,
axis.context.width,
axis.context.height);
};
axis.refreshComponent();
}
internal override void UpdateAxisLabelText(Axis axis)
{
base.UpdateAxisLabelText(axis);
if (axis.IsTime() || axis.IsValue())
{
for (int i = 0; i < axis.context.labelObjectList.Count; i++)
{
var label = axis.context.labelObjectList[i];
if (label != null)
{
var pos = GetLabelPosition(0, i);
label.SetPosition(pos);
CheckValueLabelActive(component, i, label, pos);
}
}
}
}
protected override Vector3 GetLabelPosition(float scaleWid, int i)
{
return GetLabelPosition(i, component.orient, component, null,
chart.theme.axis,
scaleWid,
component.context.x,
component.context.y,
component.context.width,
component.context.height);
}
private void DrawSingleAxisSplit(VertexHelper vh, SingleAxis axis)
{
if (AxisHelper.NeedShowSplit(axis))
{
var dataZoom = chart.GetDataZoomOfAxis(axis);
DrawAxisSplit(vh, chart.theme.axis, dataZoom,
axis.orient,
axis.context.x,
axis.context.y,
axis.context.width,
axis.context.height);
}
}
private void DrawSingleAxisTick(VertexHelper vh, SingleAxis axis)
{
if (AxisHelper.NeedShowSplit(axis))
{
var dataZoom = chart.GetDataZoomOfAxis(axis);
DrawAxisTick(vh, axis, chart.theme.axis, dataZoom,
axis.orient,
axis.context.x,
axis.context.y,
axis.context.width);
}
}
private void DrawSingleAxisLine(VertexHelper vh, SingleAxis axis)
{
if (axis.show && axis.axisLine.show)
{
DrawAxisLine(vh, axis,
chart.theme.axis,
axis.orient,
axis.context.x,
GetAxisLineXOrY(),
axis.context.width);
}
}
internal override float GetAxisLineXOrY()
{
return component.context.y + component.offset;
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 50b3514e3079543ea9000d21d809cad3
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: e5e50f8f0f8bb406b99fb32d6b5c7769
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,34 @@
using System;
using System.Collections.Generic;
using UnityEngine;
namespace XCharts.Runtime
{
/// <summary>
/// The x axis in cartesian(rectangular) coordinate.
/// ||直角坐标系 grid 中的 x 轴。
/// </summary>
[System.Serializable]
[RequireChartComponent(typeof(GridCoord))]
[ComponentHandler(typeof(XAxisHander), true)]
public class XAxis : Axis
{
public override void SetDefaultValue()
{
m_Show = true;
m_Type = AxisType.Category;
m_Min = 0;
m_Max = 0;
m_SplitNumber = 0;
m_BoundaryGap = true;
m_Position = AxisPosition.Bottom;
m_Offset = 0;
m_Data = new List<string>() { "x1", "x2", "x3", "x4", "x5" };
m_Icons = new List<Sprite>(5);
splitLine.show = false;
splitLine.lineStyle.type = LineStyle.Type.None;
axisLabel.textLimit.enable = true;
axisName.labelStyle.offset = new Vector3(5, 0, 0);
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 0a71be0d36b9745c2894e598b3d9188a
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,186 @@
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.EventSystems;
namespace XCharts.Runtime
{
[UnityEngine.Scripting.Preserve]
internal sealed class XAxisHander : AxisHandler<XAxis>
{
protected override Orient orient { get { return Orient.Horizonal; } }
public override void InitComponent()
{
InitXAxis(component);
}
public override void Update()
{
UpdateAxisMinMaxValue(component.index, component);
if (!chart.isTriggerOnClick)
{
UpdatePointerValue(component);
}
}
public override void OnPointerClick(PointerEventData eventData)
{
base.OnPointerClick(eventData);
if (chart.isTriggerOnClick)
{
UpdatePointerValue(component);
}
}
public override void OnPointerExit(PointerEventData eventData)
{
base.OnPointerExit(eventData);
if (chart.isTriggerOnClick)
{
component.context.pointerValue = double.PositiveInfinity;
}
}
public override void DrawBase(VertexHelper vh)
{
UpdatePosition(component);
DrawXAxisSplit(vh, component);
DrawXAxisLine(vh, component);
DrawXAxisTick(vh, component);
}
private void UpdatePosition(XAxis axis)
{
var grid = chart.GetChartComponent<GridCoord>(axis.gridIndex);
if (grid != null)
{
var relativedAxis = chart.GetChartComponent<YAxis>(axis.gridIndex);
axis.context.x = grid.context.x;
axis.context.y = AxisHelper.GetXAxisXOrY(grid, axis, relativedAxis);
axis.context.start = new Vector3(grid.context.x, axis.context.y);
axis.context.end = new Vector3(grid.context.x + grid.context.width, axis.context.y);
var vec = axis.context.end - axis.context.start;
axis.context.dire = vec.normalized;
axis.context.length = vec.magnitude;
axis.context.zeroY = grid.context.y;
axis.context.zeroX = grid.context.x + axis.context.offset;
}
}
private void InitXAxis(XAxis xAxis)
{
var theme = chart.theme;
var xAxisIndex = xAxis.index;
xAxis.painter = chart.painter;
xAxis.refreshComponent = delegate()
{
var grid = chart.GetChartComponent<GridCoord>(xAxis.gridIndex);
if (grid != null)
{
var yAxis = chart.GetChartComponent<YAxis>(xAxis.index);
InitAxis(yAxis,
orient,
grid.context.x,
grid.context.y,
grid.context.width,
grid.context.height);
}
};
xAxis.refreshComponent();
}
internal override void UpdateAxisLabelText(Axis axis)
{
base.UpdateAxisLabelText(axis);
if (axis.IsTime() || axis.IsValue())
{
for (int i = 0; i < axis.context.labelObjectList.Count; i++)
{
var label = axis.context.labelObjectList[i];
if (label != null)
{
var pos = GetLabelPosition(0, i);
label.SetPosition(pos);
CheckValueLabelActive(component, i, label, pos);
}
}
}
}
protected override Vector3 GetLabelPosition(float scaleWid, int i)
{
var grid = chart.GetChartComponent<GridCoord>(component.gridIndex);
if (grid == null)
return Vector3.zero;
var yAxis = chart.GetChartComponent<YAxis>(component.index);
return GetLabelPosition(i, Orient.Horizonal, component, yAxis,
chart.theme.axis,
scaleWid,
grid.context.x,
grid.context.y,
grid.context.width,
grid.context.height);
}
private void DrawXAxisSplit(VertexHelper vh, XAxis xAxis)
{
if (AxisHelper.NeedShowSplit(xAxis))
{
var grid = chart.GetChartComponent<GridCoord>(xAxis.gridIndex);
if (grid == null)
return;
var relativedAxis = chart.GetChartComponent<YAxis>(xAxis.gridIndex);
var dataZoom = chart.GetDataZoomOfAxis(xAxis);
DrawAxisSplit(vh, chart.theme.axis, dataZoom,
Orient.Horizonal,
grid.context.x,
grid.context.y,
grid.context.width,
grid.context.height,
relativedAxis);
}
}
private void DrawXAxisTick(VertexHelper vh, XAxis xAxis)
{
if (AxisHelper.NeedShowSplit(xAxis))
{
var grid = chart.GetChartComponent<GridCoord>(xAxis.gridIndex);
if (grid == null)
return;
var dataZoom = chart.GetDataZoomOfAxis(xAxis);
DrawAxisTick(vh, xAxis, chart.theme.axis, dataZoom,
Orient.Horizonal,
grid.context.x,
GetAxisLineXOrY(),
grid.context.width);
}
}
private void DrawXAxisLine(VertexHelper vh, XAxis xAxis)
{
if (xAxis.show && xAxis.axisLine.show)
{
var grid = chart.GetChartComponent<GridCoord>(xAxis.gridIndex);
if (grid == null)
return;
DrawAxisLine(vh, xAxis, chart.theme.axis,
Orient.Horizonal,
grid.context.x,
GetAxisLineXOrY(),
grid.context.width);
}
}
internal override float GetAxisLineXOrY()
{
return component.context.y;
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: d7818e1175663412196de53f19b5ac08
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 6350e9983955e49c5b48704d3866cbfe
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,36 @@
using System;
using System.Collections.Generic;
using UnityEngine;
namespace XCharts.Runtime
{
/// <summary>
/// The x axis in cartesian(rectangular) coordinate.
/// ||直角坐标系 grid 中的 x 轴。
/// </summary>
[Since("v3.11.0")]
[System.Serializable]
[RequireChartComponent(typeof(GridCoord3D))]
[ComponentHandler(typeof(XAxis3DHander), true)]
public class XAxis3D : Axis
{
public override void SetDefaultValue()
{
m_Show = true;
m_Type = AxisType.Category;
m_Min = 0;
m_Max = 0;
m_SplitNumber = 0;
m_BoundaryGap = true;
m_Position = AxisPosition.Bottom;
m_Offset = 0;
m_Data = new List<string>() { "x1", "x2", "x3", "x4", "x5" };
m_Icons = new List<Sprite>(5);
splitLine.show = false;
splitLine.lineStyle.type = LineStyle.Type.None;
axisLabel.textLimit.enable = true;
axisName.name = "X";
axisName.labelStyle.position = LabelStyle.Position.Middle;
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 9129bca9c2a864e1ea337d7eb74d1024
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,190 @@
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.EventSystems;
namespace XCharts.Runtime
{
[UnityEngine.Scripting.Preserve]
internal sealed class XAxis3DHander : AxisHandler<XAxis3D>
{
protected override Orient orient { get { return Orient.Horizonal; } }
public override void InitComponent()
{
InitXAxis(component);
}
public override void Update()
{
UpdateAxisMinMaxValue(component.index, component);
if (!chart.isTriggerOnClick)
{
UpdatePointerValue(component);
}
}
public override void OnPointerClick(PointerEventData eventData)
{
base.OnPointerClick(eventData);
if (chart.isTriggerOnClick)
{
UpdatePointerValue(component);
}
}
public override void OnPointerExit(PointerEventData eventData)
{
base.OnPointerExit(eventData);
if (chart.isTriggerOnClick)
{
component.context.pointerValue = double.PositiveInfinity;
}
}
public override void DrawBase(VertexHelper vh)
{
UpdatePosition(component);
DrawXAxisSplit(vh, component);
DrawXAxisLine(vh, component);
DrawXAxisTick(vh, component);
}
private void UpdatePosition(XAxis3D axis)
{
var grid = chart.GetChartComponent<GridCoord3D>(axis.gridIndex);
if (grid != null)
{
if (axis.position == Axis.AxisPosition.Right || axis.position == Axis.AxisPosition.Top)
{
axis.context.start = grid.xyExchanged ? grid.context.pointD : grid.context.pointB;
axis.context.end = grid.context.pointC;
}
else
{
axis.context.start = grid.context.pointA;
axis.context.end = grid.xyExchanged ? grid.context.pointB : grid.context.pointD;
}
var vect = axis.context.end - axis.context.start;
axis.context.x = axis.context.start.x;
axis.context.y = axis.context.start.y;
axis.context.dire = vect.normalized;
axis.context.length = vect.magnitude;
}
}
private void InitXAxis(XAxis3D xAxis)
{
var theme = chart.theme;
var xAxisIndex = xAxis.index;
xAxis.painter = chart.painter;
xAxis.refreshComponent = delegate ()
{
var yAxis = chart.GetChartComponent<YAxis3D>(xAxis.index);
InitAxis3D(yAxis, orient);
};
xAxis.refreshComponent();
}
internal override void UpdateAxisLabelText(Axis axis)
{
base.UpdateAxisLabelText(axis);
if (axis.IsTime() || axis.IsValue())
{
for (int i = 0; i < axis.context.labelObjectList.Count; i++)
{
var label = axis.context.labelObjectList[i];
if (label != null)
{
var pos = GetLabelPosition(0, i);
label.SetPosition(pos);
CheckValueLabelActive(component, i, label, pos);
}
}
}
}
protected override Vector3 GetLabelPosition(float scaleWid, int i)
{
var yAxis = chart.GetChartComponent<YAxis3D>(component.index);
return Axis3DHelper.GetLabelPosition(i, component, yAxis, chart.theme.axis, scaleWid);
}
private void DrawXAxisSplit(VertexHelper vh, XAxis3D xAxis)
{
if (AxisHelper.NeedShowSplit(xAxis))
{
var grid = chart.GetChartComponent<GridCoord3D>(xAxis.gridIndex);
var relativedAxis = chart.GetChartComponent<YAxis3D>(xAxis.gridIndex);
var dataZoom = chart.GetDataZoomOfAxis(xAxis);
var isLeft = grid.IsLeft();
if (grid.xyExchanged)
{
Axis3DHelper.DrawAxisSplit(vh, xAxis, chart.theme.axis, dataZoom,
grid.context.pointA,
grid.context.pointB,
relativedAxis);
if (xAxis.splitLine.showZLine)
{
var relativedAxis2 = chart.GetChartComponent<ZAxis3D>(xAxis.gridIndex);
Axis3DHelper.DrawAxisSplit(vh, xAxis, chart.theme.axis, dataZoom,
isLeft ? grid.context.pointD : grid.context.pointA,
isLeft ? grid.context.pointC : grid.context.pointB,
relativedAxis2);
}
}
else
{
Axis3DHelper.DrawAxisSplit(vh, xAxis, chart.theme.axis, dataZoom,
grid.context.pointA,
grid.context.pointD,
relativedAxis);
if (xAxis.splitLine.showZLine)
{
var relativedAxis2 = chart.GetChartComponent<ZAxis3D>(xAxis.gridIndex);
Axis3DHelper.DrawAxisSplit(vh, xAxis, chart.theme.axis, dataZoom,
grid.context.pointB,
grid.context.pointC,
relativedAxis2);
}
}
}
}
private void DrawXAxisTick(VertexHelper vh, XAxis3D xAxis)
{
if (AxisHelper.NeedShowSplit(xAxis))
{
var grid = chart.GetChartComponent<GridCoord3D>(xAxis.gridIndex);
if (grid == null)
return;
var dataZoom = chart.GetDataZoomOfAxis(xAxis);
var relativedAxis = chart.GetChartComponent<YAxis3D>(xAxis.gridIndex);
Axis3DHelper.DrawAxisTick(vh, xAxis, chart.theme.axis, dataZoom,
xAxis.context.start,
xAxis.context.end,
-relativedAxis.context.dire);
}
}
private void DrawXAxisLine(VertexHelper vh, XAxis3D axis)
{
if (axis.show && axis.axisLine.show)
{
var theme = chart.theme.axis;
var lineWidth = axis.axisLine.GetWidth(theme.lineWidth);
var lineType = axis.axisLine.GetType(theme.lineType);
var lineColor = axis.axisLine.GetColor(theme.lineColor);
var start = axis.context.start;
var end = axis.context.end;
ChartDrawer.DrawLineStyle(vh, lineType, lineWidth, start, end, lineColor);
}
}
internal override float GetAxisLineXOrY()
{
return component.context.y;
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: fc1147481a423494d963df29b423f3a0
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 69f8ba8fcc7d84b12b42f837f9f2b94b
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,32 @@
using System.Collections.Generic;
using UnityEngine;
namespace XCharts.Runtime
{
/// <summary>
/// The x axis in cartesian(rectangular) coordinate.
/// ||直角坐标系 grid 中的 y 轴。
/// </summary>
[System.Serializable]
[RequireChartComponent(typeof(GridCoord), typeof(XAxis))]
[ComponentHandler(typeof(YAxisHander), true)]
public class YAxis : Axis
{
public override void SetDefaultValue()
{
m_Show = true;
m_Type = AxisType.Value;
m_Min = 0;
m_Max = 0;
m_SplitNumber = 0;
m_BoundaryGap = false;
m_Position = AxisPosition.Left;
m_Data = new List<string>(5);
splitLine.show = true;
splitLine.lineStyle.type = LineStyle.Type.None;
axisLabel.textLimit.enable = false;
axisTick.showStartTick = true;
axisName.labelStyle.offset = new Vector3(0, 22, 0);
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 6ac60b8329f7a45c3898c7539d78f091
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,162 @@
using UnityEngine;
using UnityEngine.UI;
namespace XCharts.Runtime
{
[UnityEngine.Scripting.Preserve]
internal sealed class YAxisHander : AxisHandler<YAxis>
{
protected override Orient orient { get { return Orient.Vertical; } }
public override void InitComponent()
{
InitYAxis(component);
}
public override void Update()
{
UpdateAxisMinMaxValue(component.index, component);
UpdatePointerValue(component);
}
public override void DrawBase(VertexHelper vh)
{
UpdatePosition(component);
DrawYAxisSplit(vh, component.index, component);
DrawYAxisLine(vh, component.index, component);
DrawYAxisTick(vh, component.index, component);
}
private void UpdatePosition(YAxis axis)
{
var grid = chart.GetChartComponent<GridCoord>(axis.gridIndex);
if (grid != null)
{
var relativedAxis = chart.GetChartComponent<XAxis>(axis.gridIndex);
axis.context.x = AxisHelper.GetYAxisXOrY(grid, axis, relativedAxis);
axis.context.y = grid.context.y;
axis.context.start = new Vector3(axis.context.x, grid.context.y);
axis.context.end = new Vector3(axis.context.x, grid.context.y + grid.context.height);
var vect = axis.context.end - axis.context.start;
axis.context.dire = vect.normalized;
axis.context.length = vect.magnitude;
axis.context.zeroX = axis.context.x;
axis.context.zeroY = axis.context.y + axis.context.offset;
}
}
private void InitYAxis(YAxis yAxis)
{
var theme = chart.theme;
var yAxisIndex = yAxis.index;
yAxis.painter = chart.painter;
yAxis.refreshComponent = delegate()
{
var grid = chart.GetChartComponent<GridCoord>(yAxis.gridIndex);
if (grid != null)
{
var xAxis = chart.GetChartComponent<YAxis>(yAxis.index);
InitAxis(xAxis,
orient,
grid.context.x,
grid.context.y,
grid.context.height,
grid.context.width);
}
};
yAxis.refreshComponent();
}
internal override void UpdateAxisLabelText(Axis axis)
{
base.UpdateAxisLabelText(axis);
if (axis.IsTime() || axis.IsValue())
{
for (int i = 0; i < axis.context.labelObjectList.Count; i++)
{
var label = axis.context.labelObjectList[i];
if (label != null)
{
var pos = GetLabelPosition(0, i);
label.SetPosition(pos);
CheckValueLabelActive(axis, i, label, pos);
}
}
}
}
protected override Vector3 GetLabelPosition(float scaleWid, int i)
{
var grid = chart.GetChartComponent<GridCoord>(component.gridIndex);
if (grid == null)
return Vector3.zero;
var xAxis = chart.GetChartComponent<XAxis>(component.index);
return GetLabelPosition(i, Orient.Vertical, component, xAxis,
chart.theme.axis,
scaleWid,
grid.context.x,
grid.context.y,
grid.context.height,
grid.context.width);
}
private void DrawYAxisSplit(VertexHelper vh, int yAxisIndex, YAxis yAxis)
{
if (AxisHelper.NeedShowSplit(yAxis))
{
var grid = chart.GetChartComponent<GridCoord>(yAxis.gridIndex);
if (grid == null)
return;
var relativedAxis = chart.GetChartComponent<XAxis>(yAxis.gridIndex);
var dataZoom = chart.GetDataZoomOfAxis(yAxis);
DrawAxisSplit(vh, chart.theme.axis, dataZoom,
Orient.Vertical,
grid.context.x,
grid.context.y,
grid.context.height,
grid.context.width,
relativedAxis);
}
}
private void DrawYAxisTick(VertexHelper vh, int yAxisIndex, YAxis yAxis)
{
if (AxisHelper.NeedShowSplit(yAxis))
{
var grid = chart.GetChartComponent<GridCoord>(yAxis.gridIndex);
if (grid == null)
return;
var dataZoom = chart.GetDataZoomOfAxis(yAxis);
DrawAxisTick(vh, yAxis, chart.theme.axis, dataZoom,
Orient.Vertical,
GetAxisLineXOrY(),
grid.context.y,
grid.context.height);
}
}
private void DrawYAxisLine(VertexHelper vh, int yAxisIndex, YAxis yAxis)
{
if (yAxis.show && yAxis.axisLine.show)
{
var grid = chart.GetChartComponent<GridCoord>(yAxis.gridIndex);
if (grid == null)
return;
DrawAxisLine(vh, yAxis, chart.theme.axis,
Orient.Vertical,
GetAxisLineXOrY(),
grid.context.y,
grid.context.height);
}
}
internal override float GetAxisLineXOrY()
{
return component.context.x;
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: f09b5dcb5fcc54583bcd7946f18dfa48
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: aa26616789b6b4903aae479a4c552b89
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,33 @@
using System.Collections.Generic;
namespace XCharts.Runtime
{
/// <summary>
/// The x axis in cartesian(rectangular) coordinate.
/// ||直角坐标系 grid 中的 y 轴。
/// </summary>
[Since("v3.11.0")]
[System.Serializable]
[RequireChartComponent(typeof(GridCoord3D), typeof(XAxis3D))]
[ComponentHandler(typeof(YAxis3DHander), true)]
public class YAxis3D : Axis
{
public override void SetDefaultValue()
{
m_Show = true;
m_Type = AxisType.Value;
m_Min = 0;
m_Max = 0;
m_SplitNumber = 0;
m_BoundaryGap = false;
m_Position = AxisPosition.Left;
m_Data = new List<string>(5);
splitLine.show = true;
splitLine.lineStyle.type = LineStyle.Type.None;
axisLabel.textLimit.enable = false;
axisTick.showStartTick = true;
axisName.name = "Y";
axisName.labelStyle.position = LabelStyle.Position.Middle;
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: a3cb4a6657aaf473bbae7162eb189cc0
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,176 @@
using UnityEngine;
using UnityEngine.UI;
namespace XCharts.Runtime
{
[UnityEngine.Scripting.Preserve]
internal sealed class YAxis3DHander : AxisHandler<YAxis3D>
{
protected override Orient orient { get { return Orient.Vertical; } }
public override void InitComponent()
{
InitYAxis(component);
}
public override void Update()
{
UpdateAxisMinMaxValue(component.index, component);
UpdatePointerValue(component);
}
public override void DrawBase(VertexHelper vh)
{
UpdatePosition(component);
DrawYAxisSplit(vh, component.index, component);
DrawYAxisLine(vh, component.index, component);
DrawYAxisTick(vh, component.index, component);
}
private void UpdatePosition(YAxis3D axis)
{
var grid = chart.GetChartComponent<GridCoord3D>(axis.gridIndex);
if (grid != null)
{
if (axis.position == Axis.AxisPosition.Right)
{
axis.context.start = grid.xyExchanged ? grid.context.pointB : grid.context.pointD;
axis.context.end = grid.context.pointC;
}
else
{
axis.context.start = grid.context.pointA;
axis.context.end = grid.xyExchanged ? grid.context.pointD : grid.context.pointB;
}
axis.context.x = axis.context.start.x;
axis.context.y = axis.context.start.y;
var vect = axis.context.end - axis.context.start;
axis.context.dire = vect.normalized;
axis.context.length = vect.magnitude;
}
}
private void InitYAxis(YAxis3D yAxis)
{
var theme = chart.theme;
var yAxisIndex = yAxis.index;
yAxis.painter = chart.painter;
yAxis.refreshComponent = delegate ()
{
var grid = chart.GetChartComponent<GridCoord3D>(yAxis.gridIndex);
if (grid != null)
{
var xAxis = chart.GetChartComponent<YAxis3D>(yAxis.index);
InitAxis3D(xAxis, orient);
}
};
yAxis.refreshComponent();
}
internal override void UpdateAxisLabelText(Axis axis)
{
base.UpdateAxisLabelText(axis);
if (axis.IsTime() || axis.IsValue())
{
for (int i = 0; i < axis.context.labelObjectList.Count; i++)
{
var label = axis.context.labelObjectList[i];
if (label != null)
{
var pos = GetLabelPosition(0, i);
label.SetPosition(pos);
CheckValueLabelActive(axis, i, label, pos);
}
}
}
}
protected override Vector3 GetLabelPosition(float scaleWid, int i)
{
var xAxis = chart.GetChartComponent<XAxis3D>(component.index);
return Axis3DHelper.GetLabelPosition(i, component, xAxis, chart.theme.axis, scaleWid);
}
private void DrawYAxisSplit(VertexHelper vh, int yAxisIndex, YAxis3D yAxis)
{
if (AxisHelper.NeedShowSplit(yAxis))
{
var grid = chart.GetChartComponent<GridCoord3D>(yAxis.gridIndex);
var relativedAxis = chart.GetChartComponent<XAxis3D>(yAxis.gridIndex);
var dataZoom = chart.GetDataZoomOfAxis(yAxis);
var isLeft = grid.IsLeft();
if (grid.xyExchanged)
{
Axis3DHelper.DrawAxisSplit(vh, yAxis, chart.theme.axis, dataZoom,
grid.context.pointA,
grid.context.pointD,
relativedAxis);
if (yAxis.splitLine.showZLine)
{
var relativedAxis2 = chart.GetChartComponent<ZAxis3D>(yAxis.gridIndex);
Axis3DHelper.DrawAxisSplit(vh, yAxis, chart.theme.axis, dataZoom,
grid.context.pointB, grid.context.pointC, relativedAxis2);
}
}
else
{
Axis3DHelper.DrawAxisSplit(vh, yAxis, chart.theme.axis, dataZoom,
grid.context.pointA,
grid.context.pointB,
relativedAxis);
if (yAxis.splitLine.showZLine)
{
var relativedAxis2 = chart.GetChartComponent<ZAxis3D>(yAxis.gridIndex);
Axis3DHelper.DrawAxisSplit(vh, yAxis, chart.theme.axis, dataZoom,
isLeft ? grid.context.pointD : grid.context.pointA,
isLeft ? grid.context.pointC : grid.context.pointB,
relativedAxis2);
}
}
}
}
private void DrawYAxisTick(VertexHelper vh, int yAxisIndex, YAxis3D yAxis)
{
if (AxisHelper.NeedShowSplit(yAxis))
{
var grid = chart.GetChartComponent<GridCoord3D>(yAxis.gridIndex);
if (grid == null)
return;
var dataZoom = chart.GetDataZoomOfAxis(yAxis);
var relativedAxis = chart.GetChartComponent<XAxis3D>(yAxis.gridIndex);
Axis3DHelper.DrawAxisTick(vh, yAxis, chart.theme.axis, dataZoom,
yAxis.context.start,
yAxis.context.end,
-relativedAxis.context.dire);
}
}
private void DrawYAxisLine(VertexHelper vh, int axisIndex, YAxis3D axis)
{
if (axis.show && axis.axisLine.show)
{
var grid = chart.GetChartComponent<GridCoord3D>(axis.gridIndex);
if (grid == null)
return;
var theme = chart.theme.axis;
var lineWidth = axis.axisLine.GetWidth(theme.lineWidth);
var lineType = axis.axisLine.GetType(theme.lineType);
var lineColor = axis.axisLine.GetColor(theme.lineColor);
var start = axis.context.start;
var end = axis.context.end;
ChartDrawer.DrawLineStyle(vh, lineType, lineWidth, start, end, lineColor);
}
}
internal override float GetAxisLineXOrY()
{
return component.context.x;
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 56b4be734c61645e1bf91c22a6e3da6c
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 378448672ed084b0798c7ad343314693
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,33 @@
using System.Collections.Generic;
namespace XCharts.Runtime
{
/// <summary>
/// The x axis in cartesian(rectangular) coordinate.
/// ||直角坐标系 grid 中的 y 轴。
/// </summary>
[Since("v3.11.0")]
[System.Serializable]
[RequireChartComponent(typeof(GridCoord3D), typeof(XAxis3D))]
[ComponentHandler(typeof(ZAxis3DHander), true)]
public class ZAxis3D : Axis
{
public override void SetDefaultValue()
{
m_Show = true;
m_Type = AxisType.Value;
m_Min = 0;
m_Max = 0;
m_SplitNumber = 0;
m_BoundaryGap = false;
m_Position = AxisPosition.Left;
m_Data = new List<string>(5);
splitLine.show = true;
splitLine.lineStyle.type = LineStyle.Type.None;
axisLabel.textLimit.enable = false;
axisTick.showStartTick = true;
axisName.name = "Z";
axisName.labelStyle.position = LabelStyle.Position.Middle;
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 65aa8ae88610c431ebdab86935af2379
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,198 @@
using UnityEngine;
using UnityEngine.UI;
namespace XCharts.Runtime
{
[UnityEngine.Scripting.Preserve]
internal sealed class ZAxis3DHander : AxisHandler<ZAxis3D>
{
protected override Orient orient { get { return Orient.Vertical; } }
public override void InitComponent()
{
InitYAxis(component);
}
public override void Update()
{
UpdateAxisMinMaxValue(component.index, component);
UpdatePointerValue(component);
}
public override void DrawBase(VertexHelper vh)
{
UpdatePosition(component);
DrawZAxisSplit(vh, component.index, component);
DrawZAxisLine(vh, component.index, component);
DrawZAxisTick(vh, component.index, component);
}
private void UpdatePosition(ZAxis3D axis)
{
var grid = chart.GetChartComponent<GridCoord3D>(axis.gridIndex);
if (grid != null)
{
if (grid.context.pointB.x < grid.context.pointA.x)
{
axis.context.start = grid.context.pointD;
axis.context.end = grid.context.pointH;
}
else if (axis.position == Axis.AxisPosition.Center)
{
axis.context.start = grid.context.pointB;
axis.context.end = grid.context.pointF;
}
else if (axis.position == Axis.AxisPosition.Right)
{
axis.context.start = grid.context.pointC;
axis.context.end = grid.context.pointG;
}
else
{
axis.context.start = grid.context.pointA;
axis.context.end = grid.context.pointE;
}
axis.context.x = axis.context.start.x;
axis.context.y = axis.context.start.y;
var vect = axis.context.end - axis.context.start;
axis.context.dire = vect.normalized;
axis.context.length = vect.magnitude;
}
}
private void InitYAxis(ZAxis3D yAxis)
{
var theme = chart.theme;
var yAxisIndex = yAxis.index;
yAxis.painter = chart.painter;
yAxis.refreshComponent = delegate ()
{
var grid = chart.GetChartComponent<GridCoord3D>(yAxis.gridIndex);
if (grid != null)
{
var relativedAxis = chart.GetChartComponent<ZAxis3D>(yAxis.index);
InitAxis3D(relativedAxis, orient);
}
};
yAxis.refreshComponent();
}
internal override void UpdateAxisLabelText(Axis axis)
{
base.UpdateAxisLabelText(axis);
if (axis.IsTime() || axis.IsValue())
{
for (int i = 0; i < axis.context.labelObjectList.Count; i++)
{
var label = axis.context.labelObjectList[i];
if (label != null)
{
var pos = GetLabelPosition(0, i);
label.SetPosition(pos);
CheckValueLabelActive(axis, i, label, pos);
}
}
}
}
protected override Vector3 GetLabelPosition(float scaleWid, int i)
{
var grid = chart.GetChartComponent<GridCoord3D>(component.gridIndex);
if (grid == null)
return Vector3.zero;
var yAxis = chart.GetChartComponent<XAxis3D>(component.index);
return Axis3DHelper.GetLabelPosition(i, component, yAxis,
chart.theme.axis,
scaleWid);
}
private void DrawZAxisSplit(VertexHelper vh, int yAxisIndex, ZAxis3D yAxis)
{
if (AxisHelper.NeedShowSplit(yAxis))
{
var grid = chart.GetChartComponent<GridCoord3D>(yAxis.gridIndex);
if (grid == null)
return;
var isLeft = grid.IsLeft();
if (grid.xyExchanged)
{
var relativedAxis = chart.GetChartComponent<XAxis3D>(yAxis.gridIndex);
var dataZoom = chart.GetDataZoomOfAxis(yAxis);
Axis3DHelper.DrawAxisSplit(vh, yAxis, chart.theme.axis, dataZoom,
isLeft ? grid.context.pointD : grid.context.pointA,
isLeft ? grid.context.pointH : grid.context.pointE,
relativedAxis);
if (yAxis.splitLine.showZLine)
{
var relativedAxis2 = chart.GetChartComponent<YAxis3D>(yAxis.gridIndex);
Axis3DHelper.DrawAxisSplit(vh, yAxis, chart.theme.axis, dataZoom,
grid.context.pointB,
grid.context.pointF,
relativedAxis2);
}
}
else
{
var relativedAxis = chart.GetChartComponent<YAxis3D>(yAxis.gridIndex);
var dataZoom = chart.GetDataZoomOfAxis(yAxis);
Axis3DHelper.DrawAxisSplit(vh, yAxis, chart.theme.axis, dataZoom,
isLeft ? grid.context.pointD : grid.context.pointA,
isLeft ? grid.context.pointH : grid.context.pointE,
relativedAxis);
if (yAxis.splitLine.showZLine)
{
var relativedAxis2 = chart.GetChartComponent<XAxis3D>(yAxis.gridIndex);
Axis3DHelper.DrawAxisSplit(vh, yAxis, chart.theme.axis, dataZoom,
grid.context.pointB,
grid.context.pointF,
relativedAxis2);
}
}
}
}
private void DrawZAxisTick(VertexHelper vh, int yAxisIndex, ZAxis3D zAxis)
{
if (AxisHelper.NeedShowSplit(zAxis))
{
var grid = chart.GetChartComponent<GridCoord3D>(zAxis.gridIndex);
if (grid == null)
return;
var dataZoom = chart.GetDataZoomOfAxis(zAxis);
var relativedDire = grid.context.pointA - grid.context.pointB;
Axis3DHelper.DrawAxisTick(vh, zAxis, chart.theme.axis, dataZoom,
zAxis.context.start,
zAxis.context.end,
relativedDire.normalized);
}
}
private void DrawZAxisLine(VertexHelper vh, int axisIndex, ZAxis3D axis)
{
if (axis.show && axis.axisLine.show)
{
var grid = chart.GetChartComponent<GridCoord3D>(axis.gridIndex);
if (grid == null)
return;
var theme = chart.theme.axis;
var lineWidth = axis.axisLine.GetWidth(theme.lineWidth);
var lineType = axis.axisLine.GetType(theme.lineType);
var lineColor = axis.axisLine.GetColor(theme.lineColor);
var start = axis.context.start;
var end = axis.context.end;
ChartDrawer.DrawLineStyle(vh, lineType, lineWidth, start, end, lineColor);
}
}
internal override float GetAxisLineXOrY()
{
return component.context.x;
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 67fb4be32885d4915979719c676aac5a
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 7db6fdcbbbfd148f58ff7a1f1a569d51
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,118 @@
using System;
using UnityEngine;
using UnityEngine.UI;
namespace XCharts.Runtime
{
/// <summary>
/// Background component.
/// ||背景组件。
/// </summary>
[Serializable]
[DisallowMultipleComponent]
[ComponentHandler(typeof(BackgroundHandler), false, 0)]
public class Background : MainComponent
{
[SerializeField] private bool m_Show = true;
[SerializeField] private Sprite m_Image;
[SerializeField] private Image.Type m_ImageType;
[SerializeField] private Color m_ImageColor = Color.white;
[SerializeField][Since("v3.10.0")] private float m_ImageWidth = 0;
[SerializeField][Since("v3.10.0")] private float m_ImageHeight = 0;
[SerializeField] private bool m_AutoColor = true;
[SerializeField][Since("v3.10.0")] private BorderStyle m_BorderStyle = new BorderStyle();
/// <summary>
/// Whether to enable the background component.
/// ||是否启用背景组件。
/// </summary>
public bool show
{
get { return m_Show; }
set { if (PropertyUtil.SetStruct(ref m_Show, value)) SetComponentDirty(); }
}
/// <summary>
/// the image of background.
/// ||背景图。
/// </summary>
public Sprite image
{
get { return m_Image; }
set { if (PropertyUtil.SetClass(ref m_Image, value)) SetComponentDirty(); }
}
/// <summary>
/// the fill type of background image.
/// ||背景图填充类型。
/// </summary>
public Image.Type imageType
{
get { return m_ImageType; }
set { if (PropertyUtil.SetStruct(ref m_ImageType, value)) SetComponentDirty(); }
}
/// <summary>
/// 背景图颜色。
/// </summary>
public Color imageColor
{
get { return m_ImageColor; }
set { if (PropertyUtil.SetColor(ref m_ImageColor, value)) SetComponentDirty(); }
}
/// <summary>
/// the width of background image.
/// ||背景图宽度。
/// </summary>
public float imageWidth
{
get { return m_ImageWidth; }
set { if (PropertyUtil.SetStruct(ref m_ImageWidth, value)) SetComponentDirty(); }
}
/// <summary>
/// the height of background image.
/// ||背景图高度。
/// </summary>
public float imageHeight
{
get { return m_ImageHeight; }
set { if (PropertyUtil.SetStruct(ref m_ImageHeight, value)) SetComponentDirty(); }
}
/// <summary>
/// Whether to use theme background color for component color when the background component is on.
/// ||当background组件开启时,是否自动使用主题背景色作为backgrounnd组件的颜色。当设置为false时,用imageColor作为颜色。
/// </summary>
public bool autoColor
{
get { return m_AutoColor; }
set { if (PropertyUtil.SetStruct(ref m_AutoColor, value)) SetVerticesDirty(); }
}
/// <summary>
/// the border style of background.
/// ||背景边框样式。
/// </summary>
public BorderStyle borderStyle
{
get { return m_BorderStyle; }
set { if (PropertyUtil.SetClass(ref m_BorderStyle, value)) SetComponentDirty(); }
}
/// <summary>
/// the rect of background.
/// ||背景的矩形区域。
/// </summary>
public Rect rect { get; set; }
public override void SetDefaultValue()
{
m_Show = true;
m_Image = null;
m_ImageType = Image.Type.Sliced;
m_ImageColor = Color.white;
m_AutoColor = true;
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 524f7df5241cc4379ae241a73d5b2ff2
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,56 @@
using System;
using UnityEngine;
using UnityEngine.UI;
using XUGL;
namespace XCharts.Runtime
{
[UnityEngine.Scripting.Preserve]
internal sealed class BackgroundHandler : MainComponentHandler<Background>
{
private readonly string s_BackgroundObjectName = "background";
public override void InitComponent()
{
component.painter = chart.painter;
component.refreshComponent = delegate ()
{
var backgroundObj = ChartHelper.AddObject(s_BackgroundObjectName, chart.transform, chart.chartMinAnchor,
chart.chartMaxAnchor, chart.chartPivot, chart.chartSizeDelta, -1, chart.childrenNodeNames);
component.gameObject = backgroundObj;
backgroundObj.hideFlags = chart.chartHideFlags;
var backgroundImage = ChartHelper.EnsureComponent<Image>(backgroundObj);
ChartHelper.UpdateRectTransform(backgroundObj, chart.chartMinAnchor,
chart.chartMaxAnchor, chart.chartPivot, chart.chartSizeDelta);
backgroundImage.sprite = component.image;
backgroundImage.type = component.imageType;
backgroundImage.color = chart.theme.GetBackgroundColor(component);
backgroundObj.transform.SetSiblingIndex(0);
backgroundObj.SetActive(component.show && component.image != null);
};
component.refreshComponent();
}
public override void Update()
{
if (component.gameObject != null && component.gameObject.transform.GetSiblingIndex() != 0)
component.gameObject.transform.SetSiblingIndex(0);
}
public override void DrawBase(VertexHelper vh)
{
if (!component.show)
return;
if (component.image != null)
return;
var backgroundColor = chart.theme.GetBackgroundColor(component);
var borderWidth = component.borderStyle.GetRuntimeBorderWidth();
var borderColor = component.borderStyle.GetRuntimeBorderColor();
var cornerRadius = component.borderStyle.GetRuntimeCornerRadius();
UGL.DrawRoundRectangleWithBorder(vh, chart.chartRect, backgroundColor, backgroundColor, cornerRadius,
borderWidth, borderColor, 0, 1f);
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: f1cb3d1a2aa224bbe84eef2681cf3df4
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 20d31ade0390641698e6b846b4294b74
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,132 @@
using UnityEngine;
namespace XCharts.Runtime
{
/// <summary>
/// The style of area.
/// ||区域填充样式。
/// </summary>
[System.Serializable]
public class AreaStyle : ChildComponent, ISerieComponent, ISerieDataComponent
{
/// <summary>
/// Origin position of area.
/// ||图形区域的起始位置。默认情况下,图形会从坐标轴轴线到数据间进行填充。如果需要填充的区域是坐标轴最大值到数据间,或者坐标轴最小值到数据间,则可以通过这个配置项进行设置。
/// </summary>
public enum AreaOrigin
{
/// <summary>
/// to fill between axis line to data.
/// ||填充坐标轴轴线到数据间的区域。
/// </summary>
Auto,
/// <summary>
/// to fill between min axis value (when not inverse) to data.
/// ||填充坐标轴底部到数据间的区域。
/// </summary>
Start,
/// <summary>
/// to fill between max axis value (when not inverse) to data.
/// ||填充坐标轴顶部到数据间的区域。
/// </summary>
End
}
[SerializeField] private bool m_Show = true;
[SerializeField] private AreaStyle.AreaOrigin m_Origin;
[SerializeField] private Color32 m_Color;
[SerializeField] private Color32 m_ToColor;
[SerializeField][Range(0, 1)] private float m_Opacity = 0.6f;
[SerializeField][Since("v3.2.0")] private bool m_InnerFill;
[SerializeField][Since("v3.6.0")] private bool m_ToTop = true;
/// <summary>
/// Set this to false to prevent the areafrom showing.
/// ||是否显示区域填充。
/// </summary>
public bool show
{
get { return m_Show; }
set { if (PropertyUtil.SetStruct(ref m_Show, value)) SetVerticesDirty(); }
}
/// <summary>
/// the origin of area.
/// ||区域填充的起始位置。
/// </summary>
public AreaOrigin origin
{
get { return m_Origin; }
set { if (PropertyUtil.SetStruct(ref m_Origin, value)) SetVerticesDirty(); }
}
/// <summary>
/// the color of area,default use serie color.
/// ||区域填充的颜色,如果toColor不是默认值,则表示渐变色的起点颜色。
/// </summary>
public Color32 color
{
get { return m_Color; }
set { if (PropertyUtil.SetColor(ref m_Color, value)) SetVerticesDirty(); }
}
/// <summary>
/// Gradient color, start color to toColor.
/// ||渐变色的终点颜色。
/// </summary>
public Color32 toColor
{
get { return m_ToColor; }
set { if (PropertyUtil.SetColor(ref m_ToColor, value)) SetVerticesDirty(); }
}
/// <summary>
/// Opacity of the component. Supports value from 0 to 1, and the component will not be drawn when set to 0.
/// ||图形透明度。支持从 0 到 1 的数字,为 0 时不绘制该图形。
/// </summary>
public float opacity
{
get { return m_Opacity; }
set { if (PropertyUtil.SetStruct(ref m_Opacity, value)) SetVerticesDirty(); }
}
/// <summary>
/// Whether to fill only polygonal areas. Currently, only convex polygons are supported.
/// ||是否只填充多边形区域。目前只支持凸多边形。
/// </summary>
public bool innerFill
{
get { return m_InnerFill; }
set { if (PropertyUtil.SetStruct(ref m_InnerFill, value)) SetVerticesDirty(); }
}
/// <summary>
/// Whether to fill the gradient color to the top. The default is true, which means that the gradient color is filled to the top.
/// If it is false, the gradient color is filled to the actual position.
/// ||渐变色是到顶部还是到实际位置。默认为true到顶部。
/// </summary>
public bool toTop
{
get { return m_ToTop; }
set { if (PropertyUtil.SetStruct(ref m_ToTop, value)) SetVerticesDirty(); }
}
public Color32 GetColor()
{
if (m_Opacity == 1)
return m_Color;
var color = m_Color;
color.a = (byte) (color.a * m_Opacity);
return color;
}
public Color32 GetColor(Color32 themeColor)
{
if (!ChartHelper.IsClearColor(color))
{
return GetColor();
}
else
{
var color = themeColor;
color.a = (byte) (color.a * opacity);
return color;
}
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: ec0d95a9298bb4c159dcae36020beec9
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,92 @@
using System;
using UnityEngine;
namespace XCharts.Runtime
{
/// <summary>
/// </summary>
[Serializable]
public class ArrowStyle : ChildComponent
{
[SerializeField] private float m_Width = 10;
[SerializeField] private float m_Height = 15;
[SerializeField] private float m_Offset = 0;
[SerializeField] private float m_Dent = 3;
[SerializeField] private Color32 m_Color = Color.clear;
/// <summary>
/// The widht of arrow.
/// ||箭头宽。
/// </summary>
public float width
{
get { return m_Width; }
set { if (PropertyUtil.SetStruct(ref m_Width, value)) SetVerticesDirty(); }
}
/// <summary>
/// The height of arrow.
/// ||箭头高。
/// </summary>
public float height
{
get { return m_Height; }
set { if (PropertyUtil.SetStruct(ref m_Height, value)) SetVerticesDirty(); }
}
/// <summary>
/// The offset of arrow.
/// ||箭头偏移。
/// </summary>
public float offset
{
get { return m_Offset; }
set { if (PropertyUtil.SetStruct(ref m_Offset, value)) SetVerticesDirty(); }
}
/// <summary>
/// The dent of arrow.
/// ||箭头的凹度。
/// </summary>
public float dent
{
get { return m_Dent; }
set { if (PropertyUtil.SetStruct(ref m_Dent, value)) SetVerticesDirty(); }
}
/// <summary>
/// the color of arrow.
/// ||箭头颜色。
/// </summary>
public Color32 color
{
get { return m_Color; }
set { if (PropertyUtil.SetColor(ref m_Color, value)) SetVerticesDirty(); }
}
public ArrowStyle Clone()
{
var arrow = new ArrowStyle();
arrow.width = width;
arrow.height = height;
arrow.offset = offset;
arrow.dent = dent;
arrow.color = color;
return arrow;
}
public void Copy(ArrowStyle arrow)
{
width = arrow.width;
height = arrow.height;
offset = arrow.offset;
dent = arrow.dent;
color = arrow.color;
}
public Color32 GetColor(Color32 defaultColor)
{
if (ChartHelper.IsClearColor(color))
return defaultColor;
else
return color;
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 2232b812c68f042d29c44863e38d0417
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,82 @@
using UnityEngine;
namespace XCharts.Runtime
{
/// <summary>
/// Settings related to base line.
/// ||线条基础配置。
/// </summary>
[System.Serializable]
public class BaseLine : ChildComponent
{
[SerializeField] protected bool m_Show;
[SerializeField] protected LineStyle m_LineStyle = new LineStyle();
/// <summary>
/// Set this to false to prevent the axis line from showing.
/// ||是否显示坐标轴轴线。
/// </summary>
public bool show
{
get { return m_Show; }
set { if (PropertyUtil.SetStruct(ref m_Show, value)) SetVerticesDirty(); }
}
/// <summary>
/// 线条样式
/// </summary>
public LineStyle lineStyle
{
get { return m_LineStyle; }
set { if (value != null) { m_LineStyle = value; SetVerticesDirty(); } }
}
public static BaseLine defaultBaseLine
{
get
{
var axisLine = new BaseLine
{
m_Show = true,
m_LineStyle = new LineStyle()
};
return axisLine;
}
}
public BaseLine()
{
lineStyle = new LineStyle();
}
public BaseLine(bool show) : base()
{
m_Show = show;
}
public void Copy(BaseLine axisLine)
{
show = axisLine.show;
lineStyle.Copy(axisLine.lineStyle);
}
public LineStyle.Type GetType(LineStyle.Type themeType)
{
return lineStyle.GetType(themeType);
}
public float GetWidth(float themeWidth)
{
return lineStyle.GetWidth(themeWidth);
}
public float GetLength(float themeLength)
{
return lineStyle.GetLength(themeLength);
}
public Color32 GetColor(Color32 themeColor)
{
return lineStyle.GetColor(themeColor);
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 4c431b00ccffe4db4b61179b6df06eb2
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,92 @@
using UnityEngine;
using UnityEngine.UI;
namespace XCharts.Runtime
{
/// <summary>
/// The style of border.
/// ||边框样式。
/// </summary>
[System.Serializable]
[Since("v3.10.0")]
public class BorderStyle : ChildComponent
{
[SerializeField] private bool m_Show = false;
[SerializeField] private float m_BorderWidth;
[SerializeField] private Color32 m_BorderColor;
[SerializeField] private bool m_RoundedCorner = true;
[SerializeField] private float[] m_CornerRadius = new float[] { 0, 0, 0, 0 };
/// <summary>
/// whether the border is visible.
/// ||是否显示边框。
/// </summary>
public bool show
{
get { return m_Show; }
set { if (PropertyUtil.SetStruct(ref m_Show, value)) SetAllDirty(); }
}
/// <summary>
/// the width of border.
/// ||边框宽度。
/// </summary>
public float borderWidth
{
get { return m_BorderWidth; }
set { if (PropertyUtil.SetStruct(ref m_BorderWidth, value)) SetAllDirty(); }
}
/// <summary>
/// the color of border.
/// ||边框颜色。
/// </summary>
public Color32 borderColor
{
get { return m_BorderColor; }
set { if (PropertyUtil.SetColor(ref m_BorderColor, value)) SetAllDirty(); }
}
/// <summary>
/// whether the border is rounded corner.
/// ||是否显示圆角。
/// </summary>
public bool roundedCorner
{
get { return m_RoundedCorner; }
set { if (PropertyUtil.SetStruct(ref m_RoundedCorner, value)) SetAllDirty(); }
}
/// <summary>
/// The radius of rounded corner. Its unit is px. Use array to respectively specify the 4 corner radiuses((clockwise upper left,
/// upper right, bottom right and bottom left)). When is set to (1,1,1,1), all corners are rounded.
/// ||圆角半径。用数组分别指定4个圆角半径(顺时针左上,右上,右下,左下)。当为(1,1,1,1)时为全圆角。
/// </summary>
public float[] cornerRadius
{
get { return m_CornerRadius; }
set { if (PropertyUtil.SetClass(ref m_CornerRadius, value)) SetAllDirty(); }
}
public float GetRuntimeBorderWidth()
{
return m_Show ? m_BorderWidth : 0;
}
public Color32 GetRuntimeBorderColor()
{
return m_Show ? m_BorderColor : ColorUtil.clearColor32;
}
public float[] GetRuntimeCornerRadius()
{
return m_Show && roundedCorner ? m_CornerRadius : null;
}
public bool IsCricle()
{
return roundedCorner && m_CornerRadius[0] == 1 && m_CornerRadius[1] == 1 &&
m_CornerRadius[2] == 1 && m_CornerRadius[3] == 1;
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 0a756cb373aab4292b93a0597fc4e82c
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,118 @@
using UnityEngine;
using UnityEngine.UI;
namespace XCharts.Runtime
{
[System.Serializable]
public class IconStyle : ChildComponent
{
public enum Layer
{
/// <summary>
/// The icon is display under the label text.
/// 图标在标签文字下
/// </summary>
UnderText,
/// <summary>
/// The icon is display above the label text.
/// 图标在标签文字上
/// </summary>
AboveText
}
[SerializeField] private bool m_Show = false;
[SerializeField] private Layer m_Layer;
[SerializeField] private Align m_Align = Align.Left;
[SerializeField] private Sprite m_Sprite;
[SerializeField] private Image.Type m_Type;
[SerializeField] private Color m_Color = Color.white;
[SerializeField] private float m_Width = 20;
[SerializeField] private float m_Height = 20;
[SerializeField] private Vector3 m_Offset;
[SerializeField] private bool m_AutoHideWhenLabelEmpty = false;
public void Reset()
{
m_Show = false;
m_Layer = Layer.UnderText;
m_Sprite = null;
m_Color = Color.white;
m_Width = 20;
m_Height = 20;
m_Offset = Vector3.zero;
m_AutoHideWhenLabelEmpty = false;
}
/// <summary>
/// Whether the data icon is show.
/// ||是否显示图标。
/// </summary>
public bool show { get { return m_Show; } set { m_Show = value; } }
/// <summary>
/// 显示在上层还是在下层。
/// </summary>
public Layer layer { get { return m_Layer; } set { m_Layer = value; } }
/// <summary>
/// The image of icon.
/// ||图标的图片。
/// </summary>
public Sprite sprite { get { return m_Sprite; } set { m_Sprite = value; } }
/// <summary>
/// How to display the icon.
/// ||图片的显示类型。
/// </summary>
public Image.Type type { get { return m_Type; } set { m_Type = value; } }
/// <summary>
/// 图标颜色。
/// </summary>
public Color color { get { return m_Color; } set { m_Color = value; } }
/// <summary>
/// 图标宽。
/// </summary>
public float width { get { return m_Width; } set { m_Width = value; } }
/// <summary>
/// 图标高。
/// </summary>
public float height { get { return m_Height; } set { m_Height = value; } }
/// <summary>
/// 图标偏移。
/// </summary>
public Vector3 offset { get { return m_Offset; } set { m_Offset = value; } }
/// <summary>
/// 水平方向对齐方式。
/// </summary>
public Align align { get { return m_Align; } set { m_Align = value; } }
/// <summary>
/// 当label内容为空时是否自动隐藏图标
/// </summary>
public bool autoHideWhenLabelEmpty { get { return m_AutoHideWhenLabelEmpty; } set { m_AutoHideWhenLabelEmpty = value; } }
public IconStyle Clone()
{
var iconStyle = new IconStyle();
iconStyle.show = show;
iconStyle.layer = layer;
iconStyle.sprite = sprite;
iconStyle.type = type;
iconStyle.color = color;
iconStyle.width = width;
iconStyle.height = height;
iconStyle.offset = offset;
iconStyle.align = align;
iconStyle.autoHideWhenLabelEmpty = autoHideWhenLabelEmpty;
return iconStyle;
}
public void Copy(IconStyle iconStyle)
{
show = iconStyle.show;
layer = iconStyle.layer;
sprite = iconStyle.sprite;
type = iconStyle.type;
color = iconStyle.color;
width = iconStyle.width;
height = iconStyle.height;
offset = iconStyle.offset;
align = iconStyle.align;
autoHideWhenLabelEmpty = iconStyle.autoHideWhenLabelEmpty;
}
}
}

Some files were not shown because too many files have changed in this diff Show More