[optimize] optimize interact and performance

This commit is contained in:
monitor1394
2022-04-13 13:26:46 +08:00
parent 7ca4ddcb88
commit a3d2d3f1d5
15 changed files with 156 additions and 168 deletions

View File

@@ -7,43 +7,43 @@ namespace XCharts.Runtime
{
public class AxisContext : MainComponentContext
{
internal Orient orient { get; set; }
public float x { get; internal set; }
public float y { get; internal set; }
public float width { get; internal set; }
public float height { get; internal set; }
public Vector3 position { get; internal set; }
public float left { get; internal set; }
public float right { get; internal set; }
public float bottom { get; internal set; }
public float top { get; internal set; }
public Orient orient;
public float x;
public float y;
public float width;
public float height;
public Vector3 position;
public float left;
public float right;
public float bottom;
public float top;
/// <summary>
/// the current minimun value.
/// |当前最小值。
/// </summary>
public double minValue { get; internal set; }
public double minValue;
/// <summary>
/// the current maximum value.
/// |当前最大值。
/// </summary>
public double maxValue { get; internal set; }
public double maxValue;
/// <summary>
/// the offset of zero position.
/// |坐标轴原点在坐标轴的偏移。
/// </summary>
public float offset { get; internal set; }
public double minMaxRange { get; internal set; }
public float scaleWidth { get; internal set; }
public float startAngle { get; set; }
public double pointerValue { get; internal set; }
public Vector3 pointerLabelPosition { get; internal set; }
public double axisTooltipValue { get; internal set; }
public float offset;
public double minMaxRange;
public float scaleWidth;
public float startAngle;
public double pointerValue;
public Vector3 pointerLabelPosition;
public double axisTooltipValue;
public List<string> runtimeData { get { return m_RuntimeData; } }
public List<double> labelValueList { get { return m_LabelValueList; } }
public List<ChartLabel> labelObjectList { get { return m_AxisLabelList; } }
internal List<string> filterData;
internal bool lastCheckInverse { get; set; }
internal bool lastCheckInverse;
internal bool isNeedUpdateFilterData;
private int filterStart;

View File

@@ -34,7 +34,7 @@ namespace XCharts
return;
if (!grid.context.isPointerEnter)
{
axis.context.pointerValue = 0;
axis.context.pointerValue = double.PositiveInfinity;
}
else
{

View File

@@ -36,12 +36,11 @@ namespace XCharts.Runtime
axis.context.pointerValue = double.PositiveInfinity;
return;
}
var angleAxis = ComponentHelper.GetAngleAxis(chart.components, polar.index);
if (angleAxis == null)
return;
var startAngle = angleAxis.context.startAngle;
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);

View File

@@ -231,6 +231,16 @@ namespace XCharts.Runtime
return color;
}
public Color32 GetToColor()
{
if (m_Opacity == 1 || m_ToColor.a == 0)
return m_ToColor;
var color = m_ToColor;
color.a = (byte)(color.a * m_Opacity);
return color;
}
public Color32 GetColor0()
{
if (m_Opacity == 1 || m_Color0.a == 0)

View File

@@ -179,6 +179,7 @@ namespace XCharts.Runtime
private void SetTooltipIndicatorLabel(Axis axis, ChartLabel label)
{
if (label == null) return;
if (double.IsPositiveInfinity(axis.context.pointerValue)) return;
label.SetActive(true);
label.SetLabelActive(true);
label.SetPosition(axis.context.pointerLabelPosition);
@@ -234,7 +235,6 @@ namespace XCharts.Runtime
private void UpdateAxisPointerDataIndex(Serie serie, XAxis xAxis, YAxis yAxis, GridCoord grid, bool isTriggerAxis)
{
serie.context.pointerAxisDataIndexs.Clear();
if (yAxis.IsCategory())
{

View File

@@ -3,18 +3,18 @@ using UnityEngine;
namespace XCharts.Runtime
{
public class GridCoordContext : MainComponentContext, IRectContext
public class GridCoordContext : MainComponentContext
{
public float x { get; internal set; }
public float y { get; internal set; }
public float width { get; internal set; }
public float height { get; internal set; }
public Vector3 position { get; internal set; }
public Vector3 center { get; internal set; }
public float left { get; internal set; }
public float right { get; internal set; }
public float bottom { get; internal set; }
public float top { get; internal set; }
public bool isPointerEnter { get; set; }
public float x;
public float y;
public float width;
public float height;
public Vector3 position;
public Vector3 center;
public float left;
public float right;
public float bottom;
public float top;
public bool isPointerEnter;
}
}

View File

@@ -6,16 +6,16 @@ namespace XCharts.Runtime
{
public class ParallelCoordContext : MainComponentContext
{
public float x { get; internal set; }
public float y { get; internal set; }
public float width { get; internal set; }
public float height { get; internal set; }
public Vector3 position { get; internal set; }
public float left { get; internal set; }
public float right { get; internal set; }
public float bottom { get; internal set; }
public float top { get; internal set; }
public bool runtimeIsPointerEnter { get; set; }
public float x;
public float y;
public float width;
public float height;
public Vector3 position;
public float left;
public float right;
public float bottom;
public float top;
public bool runtimeIsPointerEnter;
internal List<ParallelAxis> parallelAxes = new List<ParallelAxis>();
}
}

View File

@@ -10,12 +10,12 @@ namespace XCharts.Runtime
/// the center position of polar in container.
/// |极坐标在容器中的具体中心点。
/// </summary>
public Vector3 center { get; internal set; }
public Vector3 center;
/// <summary>
/// the true radius of polar.
/// |极坐标的运行时实际半径。
/// </summary>
public float radius { get; internal set; }
public bool isPointerEnter { get; set; }
public float radius;
public bool isPointerEnter;
}
}

View File

@@ -277,90 +277,71 @@ namespace XCharts.Runtime
public static Color32 GetItemColor(Serie serie, SerieData serieData, ThemeStyle theme, int index, bool highlight)
{
if (serie == null) return ChartConst.clearColor32;
if (serie == null)
return ChartConst.clearColor32;
ItemStyle itemStyle = null;
if (highlight)
{
var itemStyleEmphasis = GetItemStyleEmphasis(serie, serieData);
if (itemStyleEmphasis != null && !ChartHelper.IsClearColor(itemStyleEmphasis.color))
{
var color = itemStyleEmphasis.color;
ChartHelper.SetColorOpacity(ref color, itemStyleEmphasis.opacity);
return color;
}
}
var itemStyle = GetItemStyle(serie, serieData);
if (!ChartHelper.IsClearColor(itemStyle.color))
{
return itemStyle.GetColor();
}
else
{
var color = theme.GetColor(index);
if (highlight) color = ChartHelper.GetHighlightColor(color);
ChartHelper.SetColorOpacity(ref color, itemStyle.opacity);
return color;
}
itemStyle = GetItemStyleEmphasis(serie, serieData);
if (itemStyle == null)
itemStyle = GetItemStyle(serie, serieData);
var color = ChartHelper.IsClearColor(itemStyle.color)
? theme.GetColor(index)
: itemStyle.color;
if (highlight)
color = ChartHelper.GetHighlightColor(color);
ChartHelper.SetColorOpacity(ref color, itemStyle.opacity);
return color;
}
public static Color32 GetItemColor0(Serie serie, SerieData serieData, ThemeStyle theme, bool highlight, Color32 defaultColor)
{
if (serie == null) return ChartConst.clearColor32;
if (serie == null)
return ChartConst.clearColor32;
ItemStyle itemStyle = null;
if (highlight)
{
var itemStyleEmphasis = GetItemStyleEmphasis(serie, serieData);
if (itemStyleEmphasis != null && !ChartHelper.IsClearColor(itemStyleEmphasis.color))
{
var color = itemStyleEmphasis.color0;
ChartHelper.SetColorOpacity(ref color, itemStyleEmphasis.opacity);
return color;
}
}
var itemStyle = GetItemStyle(serie, serieData);
if (!ChartHelper.IsClearColor(itemStyle.color0))
{
return itemStyle.GetColor0();
}
else
{
var color = defaultColor;
if (highlight) color = ChartHelper.GetHighlightColor(color);
ChartHelper.SetColorOpacity(ref color, itemStyle.opacity);
return color;
}
itemStyle = GetItemStyleEmphasis(serie, serieData);
if (itemStyle == null)
itemStyle = GetItemStyle(serie, serieData);
var color = ChartHelper.IsClearColor(itemStyle.color0)
? defaultColor
: itemStyle.color0;
if (highlight)
color = ChartHelper.GetHighlightColor(color);
ChartHelper.SetColorOpacity(ref color, itemStyle.opacity);
return color;
}
public static Color32 GetItemToColor(Serie serie, SerieData serieData, ThemeStyle theme, int index, bool highlight)
{
if (serie == null)
return ChartConst.clearColor32;
ItemStyle itemStyle = null;
if (highlight)
itemStyle = GetItemStyleEmphasis(serie, serieData);
if (itemStyle == null)
itemStyle = GetItemStyle(serie, serieData);
var color = itemStyle.toColor;
if (ChartHelper.IsClearColor(color))
{
var itemStyleEmphasis = GetItemStyleEmphasis(serie, serieData);
if (itemStyleEmphasis != null && !ChartHelper.IsClearColor(itemStyleEmphasis.toColor))
{
return itemStyleEmphasis.GetColor();
}
}
var itemStyle = GetItemStyle(serie, serieData, highlight);
if (itemStyle == null) itemStyle = serieData.itemStyle;
if (!ChartHelper.IsClearColor(itemStyle.toColor))
{
var color = itemStyle.toColor;
if (highlight) color = ChartHelper.GetHighlightColor(color);
ChartHelper.SetColorOpacity(ref color, itemStyle.opacity);
return color;
}
if (!ChartHelper.IsClearColor(itemStyle.color))
{
var color = itemStyle.color;
if (highlight) color = ChartHelper.GetHighlightColor(color);
ChartHelper.SetColorOpacity(ref color, itemStyle.opacity);
return color;
}
else
{
var color = theme.GetColor(index);
if (highlight) color = ChartHelper.GetHighlightColor(color);
ChartHelper.SetColorOpacity(ref color, itemStyle.opacity);
return color;
color = ChartHelper.IsClearColor(itemStyle.color)
? theme.GetColor(index)
: itemStyle.color;
}
if (highlight)
color = ChartHelper.GetHighlightColor(color);
ChartHelper.SetColorOpacity(ref color, itemStyle.opacity);
return color;
}
public static bool IsDownPoint(Serie serie, int index)

View File

@@ -1,14 +0,0 @@
using UnityEngine;
namespace XCharts.Runtime
{
public interface IRectContext
{
float x { get; }
float y { get; }
float width { get; }
float height { get; }
Vector3 position { get; }
}
}

View File

@@ -1,11 +0,0 @@
fileFormatVersion: 2
guid: 6e994b64b93384ae4bfa9a7a85ba8914
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -90,7 +90,8 @@ namespace XCharts.Runtime
serie.context.pointerEnter = false;
foreach (var serieData in serie.data)
{
if (serieData.context.rect.Contains(chart.pointerPos))
if (serie.context.pointerAxisDataIndexs.Contains(serieData.index)
|| serieData.context.rect.Contains(chart.pointerPos))
{
serie.context.pointerItemDataIndex = serieData.index;
serie.context.pointerEnter = true;

View File

@@ -25,11 +25,14 @@ namespace XCharts.Runtime
{
if (m_TargetValue != size)
{
needInteract = true;
m_UpdateFlag = true;
m_ValueEnable = true;
m_UpdateTime = Time.time;
m_PreviousValue = m_TargetValue;
if (float.IsNaN(m_TargetValue))
{
needInteract = true;
m_UpdateFlag = true;
m_ValueEnable = true;
m_UpdateTime = Time.time;
m_PreviousValue = m_TargetValue;
}
m_TargetValue = size;
}
}
@@ -38,11 +41,14 @@ namespace XCharts.Runtime
{
if (!ChartHelper.IsValueEqualsColor(color, m_TargetColor))
{
needInteract = true;
m_UpdateFlag = true;
m_ValueEnable = true;
m_UpdateTime = Time.time;
m_PreviousColor = m_TargetColor;
if (!ChartHelper.IsClearColor(m_TargetColor))
{
needInteract = true;
m_UpdateFlag = true;
m_ValueEnable = true;
m_UpdateTime = Time.time;
m_PreviousColor = m_TargetColor;
}
m_TargetColor = color;
}
}
@@ -51,11 +57,14 @@ namespace XCharts.Runtime
SetColor(ref needInteract, color);
if (!ChartHelper.IsValueEqualsColor(toColor, m_TargetToColor))
{
needInteract = true;
m_UpdateFlag = true;
m_ValueEnable = true;
m_UpdateTime = Time.time;
m_PreviousToColor = m_TargetToColor;
if (!ChartHelper.IsClearColor(m_TargetToColor))
{
needInteract = true;
m_UpdateFlag = true;
m_ValueEnable = true;
m_UpdateTime = Time.time;
m_PreviousToColor = m_TargetToColor;
}
m_TargetToColor = toColor;
}
}
@@ -179,7 +188,13 @@ namespace XCharts.Runtime
public void Reset()
{
m_UpdateFlag = false;
m_ValueEnable = false;
m_PreviousValue = float.NaN;
m_TargetColor = ColorUtil.clearColor32;
m_TargetToColor = ColorUtil.clearColor32;
m_PreviousColor = ColorUtil.clearColor32;
m_PreviousToColor = ColorUtil.clearColor32;
}
private bool IsValueEnable()

View File

@@ -120,11 +120,8 @@ namespace XCharts.Runtime
m_Name = string.Empty;
m_Show = true;
m_Selected = false;
context.canShowLabel = true;
context.highlight = false;
context.children.Clear();
context.dataPoints.Clear();
m_Radius = 0;
context.Reset();
interact.Reset();
m_Data.Clear();
m_PreviousData.Clear();

View File

@@ -36,7 +36,6 @@ namespace XCharts.Runtime
public Vector3 position;
public List<Vector3> dataPoints = new List<Vector3>();
public List<SerieData> children = new List<SerieData>();
/// <summary>
/// 绘制区域。
/// </summary>
@@ -50,7 +49,6 @@ namespace XCharts.Runtime
public Vector3 offsetCenter;
public float stackHeight;
public bool isClip;
public bool canShowLabel = true;
public Image symbol;
/// <summary>
@@ -58,5 +56,17 @@ namespace XCharts.Runtime
/// |该数据项是否被高亮,一般由鼠标悬停或图例悬停触发高亮。
/// </summary>
public bool highlight;
public void Reset()
{
canShowLabel = true;
highlight = false;
parent = null;
symbol = null;
rect = Rect.zero;
subRect = Rect.zero;
children.Clear();
dataPoints.Clear();
}
}
}