XCharts 2.0

This commit is contained in:
monitor1394
2021-01-11 08:54:28 +08:00
parent ed8d0687f7
commit 489095865d
304 changed files with 14799 additions and 12503 deletions

View File

@@ -1,20 +0,0 @@
/******************************************/
/* */
/* Copyright (c) 2018 monitor1394 */
/* https://github.com/monitor1394 */
/* */
/******************************************/
namespace XCharts
{
public class APIException : System.Exception
{
public APIException() { }
public APIException(string message) : base(message) { }
public APIException(string message, System.Exception inner) : base(message, inner) { }
protected APIException(
System.Runtime.Serialization.SerializationInfo info,
System.Runtime.Serialization.StreamingContext context) : base(info, context) { }
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -1,9 +1,9 @@
/******************************************/
/* */
/* Copyright (c) 2018 monitor1394 */
/* https://github.com/monitor1394 */
/* */
/******************************************/
/************************************************/
/* */
/* Copyright (c) 2018 - 2021 monitor1394 */
/* https://github.com/monitor1394 */
/* */
/************************************************/
using UnityEngine;
using UnityEngine.UI;
@@ -17,7 +17,13 @@ namespace XCharts
IPointerEnterHandler, IPointerExitHandler, IBeginDragHandler, IPointerClickHandler,
IDragHandler, IEndDragHandler, IScrollHandler
{
protected static readonly string s_BackgroundObjectName = "background";
[SerializeField] protected bool m_MultiComponentMode = false;
[SerializeField] protected bool m_DebugMode = false;
[SerializeField] protected bool m_EnableTextMeshPro = false;
[SerializeField] protected Background m_Background = Background.defaultBackground;
protected Painter m_Painter;
protected int m_SiblingIndex;
protected float m_GraphWidth;
protected float m_GraphHeight;
@@ -32,6 +38,8 @@ namespace XCharts
protected bool m_RefreshChart = false;
protected bool m_ForceOpenRaycastTarget;
protected bool m_IsControlledByLayout = false;
protected bool m_PainerDirty = false;
protected bool m_IsOnValidate = false;
protected Vector3 m_LastLocalPosition;
protected Action<PointerEventData, BaseGraph> m_OnPointerClick;
@@ -44,20 +52,24 @@ namespace XCharts
protected Action<PointerEventData, BaseGraph> m_OnEndDrag;
protected Action<PointerEventData, BaseGraph> m_OnScroll;
protected Vector2 chartAnchorMax { get { return m_GraphMinAnchor; } }
protected Vector2 chartAnchorMin { get { return m_GraphMaxAnchor; } }
protected Vector2 chartPivot { get { return m_GraphPivot; } }
protected HideFlags chartHideFlags { get { return m_DebugMode ? HideFlags.None : HideFlags.HideInHierarchy; } }
protected Vector2 graphAnchorMax { get { return m_GraphMinAnchor; } }
protected Vector2 graphAnchorMin { get { return m_GraphMaxAnchor; } }
protected Vector2 graphPivot { get { return m_GraphPivot; } }
internal HideFlags chartHideFlags { get { return m_DebugMode ? HideFlags.None : HideFlags.HideInHierarchy; } }
private ScrollRect m_ScrollRect;
protected virtual void InitComponent()
{
InitPainter();
InitBackground();
}
protected override void Awake()
{
CheckTextMeshPro();
m_SiblingIndex = 0;
if (transform.parent != null)
{
m_IsControlledByLayout = transform.parent.GetComponent<LayoutGroup>() != null;
@@ -77,13 +89,76 @@ namespace XCharts
protected virtual void Update()
{
CheckSize();
CheckComponent();
if (m_IsOnValidate)
{
m_IsOnValidate = false;
m_RefreshChart = true;
CheckTextMeshPro();
InitComponent();
}
else
{
CheckComponent();
}
CheckPointerPos();
CheckRefreshChart();
CheckRefreshPainter();
}
protected virtual void SetAllComponentDirty()
{
#if UNITY_EDITOR
if (!Application.isPlaying)
{
m_IsOnValidate = true;
Update();
}
#endif
m_PainerDirty = true;
m_Background.SetAllDirty();
}
protected virtual void CheckComponent()
{
CheckComponentDirty(m_Background);
if (m_PainerDirty)
{
InitPainter();
m_PainerDirty = false;
}
}
private void CheckTextMeshPro()
{
#if dUI_TextMeshPro
var enableTextMeshPro = true;
#else
var enableTextMeshPro = false;
#endif
if (m_EnableTextMeshPro != enableTextMeshPro)
{
m_EnableTextMeshPro = enableTextMeshPro;
RemoveChartObject();
}
}
protected void CheckComponentDirty(ChartComponent component)
{
if (component.anyDirty)
{
if (component.componentDirty)
{
component.refreshComponent?.Invoke();
}
if (component.vertsDirty)
{
if (component.painter != null)
{
RefreshPainter(component.painter);
}
}
component.ClearDirty();
}
}
protected override void OnEnable()
@@ -103,6 +178,7 @@ namespace XCharts
protected override void OnValidate()
{
m_IsOnValidate = true;
}
#endif
@@ -114,6 +190,39 @@ namespace XCharts
}
}
private void InitBackground()
{
var backgroundObj = ChartHelper.AddObject(s_BackgroundObjectName, transform, m_GraphMinAnchor,
m_GraphMaxAnchor, m_GraphPivot, m_GraphSizeDelta);
m_Background.gameObject = backgroundObj;
m_Background.painter = m_Painter;
m_Background.refreshComponent = delegate ()
{
if (backgroundObj == null) return;
backgroundObj.hideFlags = chartHideFlags;
var backgroundImage = ChartHelper.GetOrAddComponent<Image>(backgroundObj);
ChartHelper.UpdateRectTransform(backgroundObj, m_GraphMinAnchor,
m_GraphMaxAnchor, m_GraphPivot, m_GraphSizeDelta);
backgroundImage.sprite = m_Background.image;
backgroundImage.type = m_Background.imageType;
backgroundImage.color = m_Background.imageColor;
backgroundObj.transform.SetSiblingIndex(0);
backgroundObj.SetActive(m_Background.show);
};
m_Background.refreshComponent();
}
protected virtual void InitPainter()
{
var painterObj = ChartHelper.AddObject("painter_b", transform, m_GraphMinAnchor, m_GraphMaxAnchor,
m_GraphPivot, new Vector2(m_GraphWidth, m_GraphHeight));
painterObj.transform.SetSiblingIndex(1);
painterObj.hideFlags = chartHideFlags;
m_Painter = ChartHelper.GetOrAddComponent<Painter>(painterObj);
m_Painter.type = Painter.Type.Base;
m_Painter.onPopulateMesh = OnDrawPainterBase;
}
private void CheckSize()
{
var currWidth = rectTransform.rect.width;
@@ -198,11 +307,22 @@ namespace XCharts
{
if (m_RefreshChart)
{
SetVerticesDirty();
m_Painter.Refresh();
m_RefreshChart = false;
}
}
protected virtual void CheckRefreshPainter()
{
m_Painter.CheckRefresh();
}
internal virtual void RefreshPainter(Painter painter)
{
if (painter == null) return;
painter.Refresh();
}
protected virtual void OnSizeChanged()
{
m_RefreshChart = true;
@@ -212,14 +332,14 @@ namespace XCharts
{
}
protected override void OnPopulateMesh(VertexHelper vh)
protected virtual void OnDrawPainterBase(VertexHelper vh, Painter painter)
{
vh.Clear();
Debug.LogError("OnDrawPainterBase:" + Time.frameCount + "," + painter.name);
DrawBackground(vh);
DrawGraphic(vh);
DrawPainterBase(vh);
}
protected virtual void DrawGraphic(VertexHelper vh)
protected virtual void DrawPainterBase(VertexHelper vh)
{
}

File diff suppressed because it is too large Load Diff

View File

@@ -1,48 +1,45 @@
/******************************************/
/* */
/* Copyright (c) 2018 monitor1394 */
/* https://github.com/monitor1394 */
/* */
/******************************************/
/************************************************/
/* */
/* Copyright (c) 2018 - 2021 monitor1394 */
/* https://github.com/monitor1394 */
/* */
/************************************************/
using System;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;
using XUGL;
namespace XCharts
{
public partial class CoordinateChart
{
protected float m_BarLastOffset = 0;
protected Action<PointerEventData, int> m_OnPointerClickBar;
protected void DrawYBarSerie(VertexHelper vh, Serie serie, int colorIndex, ref List<float> seriesHig)
protected void DrawYBarSerie(VertexHelper vh, Serie serie, int colorIndex)
{
if (!IsActive(serie.name)) return;
if (serie.animation.HasFadeOut()) return;
var xAxis = m_XAxises[serie.axisIndex];
var yAxis = m_YAxises[serie.axisIndex];
if (!yAxis.show) yAxis = m_YAxises[(serie.axisIndex + 1) % m_YAxises.Count];
var showData = serie.GetDataList(m_DataZoom);
float categoryWidth = AxisHelper.GetDataWidth(yAxis, m_CoordinateHeight, showData.Count, m_DataZoom);
var xAxis = m_XAxes[serie.xAxisIndex];
var yAxis = m_YAxes[serie.yAxisIndex];
var grid = GetSerieGridOrDefault(serie);
var showData = serie.GetDataList(dataZoom);
float categoryWidth = AxisHelper.GetDataWidth(yAxis, grid.runtimeHeight, showData.Count, dataZoom);
float barGap = GetBarGap();
float totalBarWidth = GetBarTotalWidth(categoryWidth, barGap);
float barWidth = serie.GetBarWidth(categoryWidth);
float offset = (categoryWidth - totalBarWidth) / 2;
float barGapWidth = barWidth + barWidth * barGap;
float space = serie.barGap == -1 ? offset : offset + m_BarLastOffset;
float space = serie.barGap == -1 ? offset : offset + GetBarIndex(serie) * barGapWidth;
var isStack = SeriesHelper.IsStack(m_Series, serie.stack, SerieType.Bar);
m_StackSerieData.Clear();
if (isStack) SeriesHelper.UpdateStackDataList(m_Series, serie, dataZoom, m_StackSerieData);
int maxCount = serie.maxShow > 0 ?
(serie.maxShow > showData.Count ? showData.Count : serie.maxShow)
: showData.Count;
if (seriesHig.Count < serie.minShow)
{
for (int i = 0; i < serie.minShow; i++)
{
seriesHig.Add(0);
}
}
var isPercentStack = SeriesHelper.IsPercentStack(m_Series, serie.stack, SerieType.Bar);
bool dataChanging = false;
float dataChangeDuration = serie.animation.GetUpdateAnimationDuration();
@@ -51,17 +48,13 @@ namespace XCharts
var isAllBarEnd = true;
for (int i = serie.minShow; i < maxCount; i++)
{
if (i >= seriesHig.Count)
{
seriesHig.Add(0);
}
var serieData = showData[i];
if (serie.IsIgnoreValue(serieData.GetData(1)))
{
serie.dataPoints.Add(Vector3.zero);
continue;
}
var highlight = (m_Tooltip.show && m_Tooltip.IsSelected(i))
var highlight = (tooltip.show && tooltip.IsSelected(i))
|| serie.data[i].highlighted
|| serie.highlighted;
var itemStyle = SerieHelper.GetItemStyle(serie, serieData, highlight);
@@ -70,28 +63,34 @@ namespace XCharts
float value = showData[i].GetCurrData(1, dataChangeDuration, xAxis.inverse, xMinValue, xMaxValue);
float borderWidth = value == 0 ? 0 : itemStyle.runtimeBorderWidth;
if (showData[i].IsDataChanged()) dataChanging = true;
float axisLineWidth = (value < 0 ? -1 : 1) * yAxis.axisLine.width;
float pX = seriesHig[i] + m_CoordinateX + xAxis.runtimeZeroXOffset + axisLineWidth;
float pY = m_CoordinateY + i * categoryWidth;
float axisLineWidth = (value < 0 ? -1 : 1) * yAxis.axisLine.GetWidth(m_Theme.axis.lineWidth);
float pY = grid.runtimeY + i * categoryWidth;
if (!yAxis.boundaryGap) pY -= categoryWidth / 2;
float pX = grid.runtimeX + xAxis.runtimeZeroXOffset + axisLineWidth;
if (isStack)
{
for (int n = 0; n < m_StackSerieData.Count - 1; n++)
{
pX += m_StackSerieData[n][i].runtimeStackHig;
}
}
var barHig = 0f;
var valueTotal = 0f;
if (isPercentStack)
{
valueTotal = GetSameStackTotalValue(serie.stack, i);
barHig = valueTotal != 0 ? (value / valueTotal * m_CoordinateWidth) : 0;
seriesHig[i] += barHig;
barHig = valueTotal != 0 ? (value / valueTotal * grid.runtimeWidth) : 0;
}
else
{
valueTotal = xMaxValue - xMinValue;
if (valueTotal != 0)
barHig = (xMinValue > 0 ? value - xMinValue : value)
/ valueTotal * m_CoordinateWidth;
seriesHig[i] += barHig;
/ valueTotal * grid.runtimeWidth;
}
serieData.runtimeStackHig = barHig;
var isBarEnd = false;
float currHig = CheckAnimation(serie, i, barHig, out isBarEnd);
if (!isBarEnd) isAllBarEnd = false;
@@ -111,11 +110,11 @@ namespace XCharts
plb = new Vector3(pX + borderWidth, pY + space + borderWidth);
}
top = new Vector3(pX + currHig - borderWidth, pY + space + barWidth / 2);
plt = ClampInCoordinate(plt);
prt = ClampInCoordinate(prt);
prb = ClampInCoordinate(prb);
plb = ClampInCoordinate(plb);
top = ClampInCoordinate(top);
plt = ClampInGrid(grid, plt);
prt = ClampInGrid(grid, prt);
prb = ClampInGrid(grid, prb);
plb = ClampInGrid(grid, plb);
top = ClampInGrid(grid, top);
serie.dataPoints.Add(top);
if (serie.show)
{
@@ -123,27 +122,23 @@ namespace XCharts
{
case BarType.Normal:
DrawNormalBar(vh, serie, serieData, itemStyle, colorIndex, highlight, space, barWidth,
pX, pY, plb, plt, prt, prb, true);
pX, pY, plb, plt, prt, prb, true, grid);
break;
case BarType.Zebra:
DrawZebraBar(vh, serie, serieData, itemStyle, colorIndex, highlight, space, barWidth,
pX, pY, plb, plt, prt, prb, true);
pX, pY, plb, plt, prt, prb, true, grid);
break;
case BarType.Capsule:
DrawCapsuleBar(vh, serie, serieData, itemStyle, colorIndex, highlight, space, barWidth,
pX, pY, plb, plt, prt, prb, true);
pX, pY, plb, plt, prt, prb, true, grid);
break;
}
}
}
if (isAllBarEnd) serie.animation.AllBarEnd();
if (!SeriesHelper.IsStack(m_Series, serie.stack, SerieType.Bar))
{
m_BarLastOffset += barGapWidth;
}
if (dataChanging)
{
RefreshChart();
RefreshPainter(serie);
}
}
@@ -152,40 +147,34 @@ namespace XCharts
float currHig = serie.animation.CheckBarProgress(dataIndex, barHig, serie.dataCount, out isBarEnd);
if (!serie.animation.IsFinish())
{
RefreshChart();
RefreshPainter(serie);
m_IsPlayingAnimation = true;
}
return currHig;
}
protected void DrawXBarSerie(VertexHelper vh, Serie serie, int colorIndex, ref List<float> seriesHig)
protected void DrawXBarSerie(VertexHelper vh, Serie serie, int colorIndex)
{
if (!IsActive(serie.index)) return;
if (serie.animation.HasFadeOut()) return;
var showData = serie.GetDataList(m_DataZoom);
var yAxis = m_YAxises[serie.axisIndex];
var xAxis = m_XAxises[serie.axisIndex];
if (!xAxis.show) xAxis = m_XAxises[(serie.axisIndex + 1) % m_XAxises.Count];
float categoryWidth = AxisHelper.GetDataWidth(xAxis, m_CoordinateWidth, showData.Count, m_DataZoom);
var showData = serie.GetDataList(dataZoom);
var yAxis = m_YAxes[serie.yAxisIndex];
var xAxis = m_XAxes[serie.xAxisIndex];
var grid = GetSerieGridOrDefault(serie);
var isStack = SeriesHelper.IsStack(m_Series, serie.stack, SerieType.Bar);
m_StackSerieData.Clear();
if (isStack) SeriesHelper.UpdateStackDataList(m_Series, serie, dataZoom, m_StackSerieData);
float categoryWidth = AxisHelper.GetDataWidth(xAxis, grid.runtimeWidth, showData.Count, dataZoom);
float barGap = GetBarGap();
float totalBarWidth = GetBarTotalWidth(categoryWidth, barGap);
float barWidth = serie.GetBarWidth(categoryWidth);
float offset = (categoryWidth - totalBarWidth) / 2;
float barGapWidth = barWidth + barWidth * barGap;
float space = serie.barGap == -1 ? offset : offset + m_BarLastOffset;
int maxCount = serie.maxShow > 0 ?
(serie.maxShow > showData.Count ? showData.Count : serie.maxShow)
float space = serie.barGap == -1 ? offset : offset + GetBarIndex(serie) * barGapWidth;
int maxCount = serie.maxShow > 0
? (serie.maxShow > showData.Count ? showData.Count : serie.maxShow)
: showData.Count;
if (seriesHig.Count < serie.minShow)
{
for (int i = 0; i < serie.minShow; i++)
{
seriesHig.Add(0);
}
}
var isPercentStack = SeriesHelper.IsPercentStack(m_Series, serie.stack, SerieType.Bar);
bool dataChanging = false;
float dataChangeDuration = serie.animation.GetUpdateAnimationDuration();
@@ -194,45 +183,48 @@ namespace XCharts
var isAllBarEnd = true;
for (int i = serie.minShow; i < maxCount; i++)
{
if (i >= seriesHig.Count)
{
seriesHig.Add(0);
}
var serieData = showData[i];
if (serie.IsIgnoreValue(serieData.GetData(1)))
{
serie.dataPoints.Add(Vector3.zero);
continue;
}
var highlight = (m_Tooltip.show && m_Tooltip.IsSelected(i))
var highlight = (tooltip.show && tooltip.IsSelected(i))
|| serie.data[i].highlighted
|| serie.highlighted;
var itemStyle = SerieHelper.GetItemStyle(serie, serieData, highlight);
float value = serieData.GetCurrData(1, dataChangeDuration, yAxis.inverse, yMinValue, yMaxValue);
float borderWidth = value == 0 ? 0 : itemStyle.runtimeBorderWidth;
if (serieData.IsDataChanged()) dataChanging = true;
float pX = m_CoordinateX + i * categoryWidth;
float zeroY = m_CoordinateY + yAxis.runtimeZeroYOffset;
float pX = grid.runtimeX + i * categoryWidth;
float zeroY = grid.runtimeY + yAxis.runtimeZeroYOffset;
if (!xAxis.boundaryGap) pX -= categoryWidth / 2;
float axisLineWidth = (value < 0 ? -1 : 1) * xAxis.axisLine.width;
float pY = seriesHig[i] + zeroY + axisLineWidth;
float axisLineWidth = (value < 0 ? -1 : 1) * xAxis.axisLine.GetWidth(m_Theme.axis.lineWidth);
float pY = zeroY + axisLineWidth;
if (isStack)
{
for (int n = 0; n < m_StackSerieData.Count - 1; n++)
{
pY += m_StackSerieData[n][i].runtimeStackHig;
}
}
var barHig = 0f;
var valueTotal = 0f;
if (isPercentStack)
{
valueTotal = GetSameStackTotalValue(serie.stack, i);
barHig = valueTotal != 0 ? (value / valueTotal * m_CoordinateHeight) : 0;
seriesHig[i] += barHig;
barHig = valueTotal != 0 ? (value / valueTotal * grid.runtimeHeight) : 0;
}
else
{
valueTotal = yMaxValue - yMinValue;
if (valueTotal != 0)
barHig = (yMinValue > 0 ? value - yMinValue : value)
/ valueTotal * m_CoordinateHeight;
seriesHig[i] += barHig;
{
barHig = (yMinValue > 0 ? value - yMinValue : value) / valueTotal * grid.runtimeHeight;
}
}
serieData.runtimeStackHig = barHig;
var isBarEnd = false;
float currHig = CheckAnimation(serie, i, barHig, out isBarEnd);
if (!isBarEnd) isAllBarEnd = false;
@@ -254,11 +246,11 @@ namespace XCharts
top = new Vector3(pX + space + barWidth / 2, pY + currHig - borderWidth);
if (serie.clip)
{
plb = ClampInCoordinate(plb);
plt = ClampInCoordinate(plt);
prt = ClampInCoordinate(prt);
prb = ClampInCoordinate(prb);
top = ClampInCoordinate(top);
plb = ClampInGrid(grid, plb);
plt = ClampInGrid(grid, plt);
prt = ClampInGrid(grid, prt);
prb = ClampInGrid(grid, prb);
top = ClampInGrid(grid, top);
}
serie.dataPoints.Add(top);
if (serie.show && currHig != 0)
@@ -267,15 +259,15 @@ namespace XCharts
{
case BarType.Normal:
DrawNormalBar(vh, serie, serieData, itemStyle, colorIndex, highlight, space, barWidth,
pX, pY, plb, plt, prt, prb, false);
pX, pY, plb, plt, prt, prb, false, grid);
break;
case BarType.Zebra:
DrawZebraBar(vh, serie, serieData, itemStyle, colorIndex, highlight, space, barWidth,
pX, pY, plb, plt, prt, prb, false);
pX, pY, plb, plt, prt, prb, false, grid);
break;
case BarType.Capsule:
DrawCapsuleBar(vh, serie, serieData, itemStyle, colorIndex, highlight, space, barWidth,
pX, pY, plb, plt, prt, prb, false);
pX, pY, plb, plt, prt, prb, false, grid);
break;
}
}
@@ -286,30 +278,26 @@ namespace XCharts
}
if (dataChanging)
{
RefreshChart();
}
if (!SeriesHelper.IsStack(m_Series, serie.stack, SerieType.Bar))
{
m_BarLastOffset += barGapWidth;
RefreshPainter(serie);
}
}
private void DrawNormalBar(VertexHelper vh, Serie serie, SerieData serieData, ItemStyle itemStyle, int colorIndex,
bool highlight, float space, float barWidth, float pX, float pY, Vector3 plb, Vector3 plt, Vector3 prt,
Vector3 prb, bool isYAxis)
Vector3 prb, bool isYAxis, Grid grid)
{
var areaColor = SerieHelper.GetItemColor(serie, serieData, m_ThemeInfo, colorIndex, highlight);
var areaToColor = SerieHelper.GetItemToColor(serie, serieData, m_ThemeInfo, colorIndex, highlight);
DrawBarBackground(vh, serie, serieData, itemStyle, colorIndex, highlight, pX, pY, space, barWidth, isYAxis);
var areaColor = SerieHelper.GetItemColor(serie, serieData, m_Theme, colorIndex, highlight);
var areaToColor = SerieHelper.GetItemToColor(serie, serieData, m_Theme, colorIndex, highlight);
DrawBarBackground(vh, serie, serieData, itemStyle, colorIndex, highlight, pX, pY, space, barWidth, isYAxis, grid);
var borderWidth = itemStyle.runtimeBorderWidth;
if (isYAxis)
{
if (serie.clip)
{
prb = ClampInCoordinate(prb);
plb = ClampInCoordinate(plb);
plt = ClampInCoordinate(plt);
prt = ClampInCoordinate(prt);
prb = ClampInGrid(grid, prb);
plb = ClampInGrid(grid, plb);
plt = ClampInGrid(grid, plt);
prt = ClampInGrid(grid, prt);
}
var borderColor = itemStyle.borderColor;
var itemWidth = Mathf.Abs(prb.x - plt.x);
@@ -319,23 +307,25 @@ namespace XCharts
{
if (ItemStyleHelper.IsNeedCorner(itemStyle))
{
ChartDrawer.DrawRoundRectangle(vh, center, itemWidth, itemHeight, areaColor, areaToColor, 0, itemStyle.cornerRadius, isYAxis);
UGL.DrawRoundRectangle(vh, center, itemWidth, itemHeight, areaColor, areaToColor, 0,
itemStyle.cornerRadius, isYAxis);
}
else
{
CheckClipAndDrawPolygon(vh, plb, plt, prt, prb, areaColor, areaToColor, serie.clip);
CheckClipAndDrawPolygon(vh, plb, plt, prt, prb, areaColor, areaToColor, serie.clip, grid);
}
ChartDrawer.DrawBorder(vh, center, itemWidth, itemHeight, borderWidth, borderColor, 0, itemStyle.cornerRadius, isYAxis);
UGL.DrawBorder(vh, center, itemWidth, itemHeight, borderWidth, borderColor, 0,
itemStyle.cornerRadius, isYAxis);
}
}
else
{
if (serie.clip)
{
prb = ClampInCoordinate(prb);
plb = ClampInCoordinate(plb);
plt = ClampInCoordinate(plt);
prt = ClampInCoordinate(prt);
prb = ClampInGrid(grid, prb);
plb = ClampInGrid(grid, plb);
plt = ClampInGrid(grid, plt);
prt = ClampInGrid(grid, prt);
}
var borderColor = itemStyle.borderColor;
var itemWidth = Mathf.Abs(prt.x - plb.x);
@@ -345,46 +335,49 @@ namespace XCharts
{
if (ItemStyleHelper.IsNeedCorner(itemStyle))
{
ChartDrawer.DrawRoundRectangle(vh, center, itemWidth, itemHeight, areaColor, areaToColor, 0, itemStyle.cornerRadius, isYAxis);
UGL.DrawRoundRectangle(vh, center, itemWidth, itemHeight, areaColor, areaToColor, 0,
itemStyle.cornerRadius, isYAxis);
}
else
{
CheckClipAndDrawPolygon(vh, ref prb, ref plb, ref plt, ref prt, areaColor, areaToColor, serie.clip);
CheckClipAndDrawPolygon(vh, ref prb, ref plb, ref plt, ref prt, areaColor, areaToColor,
serie.clip, grid);
}
ChartDrawer.DrawBorder(vh, center, itemWidth, itemHeight, borderWidth, borderColor, 0, itemStyle.cornerRadius, isYAxis);
UGL.DrawBorder(vh, center, itemWidth, itemHeight, borderWidth, borderColor, 0,
itemStyle.cornerRadius, isYAxis);
}
}
}
private void DrawZebraBar(VertexHelper vh, Serie serie, SerieData serieData, ItemStyle itemStyle, int colorIndex,
bool highlight, float space, float barWidth, float pX, float pY, Vector3 plb, Vector3 plt, Vector3 prt,
Vector3 prb, bool isYAxis)
Vector3 prb, bool isYAxis, Grid grid)
{
var areaColor = SerieHelper.GetItemColor(serie, serieData, m_ThemeInfo, colorIndex, highlight);
DrawBarBackground(vh, serie, serieData, itemStyle, colorIndex, highlight, pX, pY, space, barWidth, isYAxis);
var areaColor = SerieHelper.GetItemColor(serie, serieData, m_Theme, colorIndex, highlight);
DrawBarBackground(vh, serie, serieData, itemStyle, colorIndex, highlight, pX, pY, space, barWidth, isYAxis, grid);
if (isYAxis)
{
plt = (plb + plt) / 2;
prt = (prt + prb) / 2;
CheckClipAndDrawZebraLine(vh, plt, prt, barWidth / 2, serie.barZebraWidth, serie.barZebraGap,
areaColor, serie.clip);
areaColor, serie.clip, grid);
}
else
{
plb = (prb + plb) / 2;
plt = (plt + prt) / 2;
CheckClipAndDrawZebraLine(vh, plb, plt, barWidth / 2, serie.barZebraWidth, serie.barZebraGap,
areaColor, serie.clip);
areaColor, serie.clip, grid);
}
}
private void DrawCapsuleBar(VertexHelper vh, Serie serie, SerieData serieData, ItemStyle itemStyle, int colorIndex,
bool highlight, float space, float barWidth, float pX, float pY, Vector3 plb, Vector3 plt, Vector3 prt,
Vector3 prb, bool isYAxis)
Vector3 prb, bool isYAxis, Grid grid)
{
var areaColor = SerieHelper.GetItemColor(serie, serieData, m_ThemeInfo, colorIndex, highlight);
var areaToColor = SerieHelper.GetItemToColor(serie, serieData, m_ThemeInfo, colorIndex, highlight);
DrawBarBackground(vh, serie, serieData, itemStyle, colorIndex, highlight, pX, pY, space, barWidth, isYAxis);
var areaColor = SerieHelper.GetItemColor(serie, serieData, m_Theme, colorIndex, highlight);
var areaToColor = SerieHelper.GetItemToColor(serie, serieData, m_Theme, colorIndex, highlight);
DrawBarBackground(vh, serie, serieData, itemStyle, colorIndex, highlight, pX, pY, space, barWidth, isYAxis, grid);
var borderWidth = itemStyle.runtimeBorderWidth;
var radius = barWidth / 2 - borderWidth;
var isGradient = !ChartHelper.IsValueEqualsColor(areaColor, areaToColor);
@@ -402,15 +395,17 @@ namespace XCharts
var barLen = prt.x - plt.x;
var rectStartColor = Color32.Lerp(areaColor, areaToColor, radius / barLen);
var rectEndColor = Color32.Lerp(areaColor, areaToColor, (barLen - radius) / barLen);
CheckClipAndDrawPolygon(vh, plb + diff, plt + diff, prt - diff, prb - diff, rectStartColor, rectEndColor, serie.clip);
ChartDrawer.DrawSector(vh, pcl, radius, areaColor, rectStartColor, 180, 360, 1, isYAxis);
ChartDrawer.DrawSector(vh, pcr, radius, rectEndColor, areaToColor, 0, 180, 1, isYAxis);
CheckClipAndDrawPolygon(vh, plb + diff, plt + diff, prt - diff, prb - diff, rectStartColor,
rectEndColor, serie.clip, grid);
UGL.DrawSector(vh, pcl, radius, areaColor, rectStartColor, 180, 360, 1, isYAxis);
UGL.DrawSector(vh, pcr, radius, rectEndColor, areaToColor, 0, 180, 1, isYAxis);
}
else
{
CheckClipAndDrawPolygon(vh, plb + diff, plt + diff, prt - diff, prb - diff, areaColor, areaToColor, serie.clip);
ChartDrawer.DrawSector(vh, pcl, radius, areaColor, 180, 360);
ChartDrawer.DrawSector(vh, pcr, radius, areaToColor, 0, 180);
CheckClipAndDrawPolygon(vh, plb + diff, plt + diff, prt - diff, prb - diff, areaColor,
areaToColor, serie.clip, grid);
UGL.DrawSector(vh, pcl, radius, areaColor, 180, 360);
UGL.DrawSector(vh, pcr, radius, areaToColor, 0, 180);
}
}
}
@@ -425,15 +420,17 @@ namespace XCharts
var barLen = plt.x - prt.x;
var rectStartColor = Color32.Lerp(areaColor, areaToColor, radius / barLen);
var rectEndColor = Color32.Lerp(areaColor, areaToColor, (barLen - radius) / barLen);
CheckClipAndDrawPolygon(vh, plb - diff, plt - diff, prt + diff, prb + diff, rectStartColor, rectEndColor, serie.clip);
ChartDrawer.DrawSector(vh, pcl, radius, rectStartColor, areaColor, 0, 180, 1, isYAxis);
ChartDrawer.DrawSector(vh, pcr, radius, areaToColor, rectEndColor, 180, 360, 1, isYAxis);
CheckClipAndDrawPolygon(vh, plb - diff, plt - diff, prt + diff, prb + diff, rectStartColor,
rectEndColor, serie.clip, grid);
UGL.DrawSector(vh, pcl, radius, rectStartColor, areaColor, 0, 180, 1, isYAxis);
UGL.DrawSector(vh, pcr, radius, areaToColor, rectEndColor, 180, 360, 1, isYAxis);
}
else
{
CheckClipAndDrawPolygon(vh, plb - diff, plt - diff, prt + diff, prb + diff, areaColor, areaToColor, serie.clip);
ChartDrawer.DrawSector(vh, pcl, radius, areaColor, 0, 180);
ChartDrawer.DrawSector(vh, pcr, radius, areaToColor, 180, 360);
CheckClipAndDrawPolygon(vh, plb - diff, plt - diff, prt + diff, prb + diff, areaColor,
areaToColor, serie.clip, grid);
UGL.DrawSector(vh, pcl, radius, areaColor, 0, 180);
UGL.DrawSector(vh, pcr, radius, areaToColor, 180, 360);
}
}
}
@@ -452,15 +449,17 @@ namespace XCharts
var barLen = plt.y - plb.y;
var rectStartColor = Color32.Lerp(areaColor, areaToColor, radius / barLen);
var rectEndColor = Color32.Lerp(areaColor, areaToColor, (barLen - radius) / barLen);
CheckClipAndDrawPolygon(vh, prb + diff, plb + diff, plt - diff, prt - diff, rectStartColor, rectEndColor, serie.clip);
ChartDrawer.DrawSector(vh, pct, radius, rectEndColor, areaToColor, 270, 450, 1, isYAxis);
ChartDrawer.DrawSector(vh, pcb, radius, rectStartColor, areaColor, 90, 270, 1, isYAxis);
CheckClipAndDrawPolygon(vh, prb + diff, plb + diff, plt - diff, prt - diff, rectStartColor,
rectEndColor, serie.clip, grid);
UGL.DrawSector(vh, pct, radius, rectEndColor, areaToColor, 270, 450, 1, isYAxis);
UGL.DrawSector(vh, pcb, radius, rectStartColor, areaColor, 90, 270, 1, isYAxis);
}
else
{
CheckClipAndDrawPolygon(vh, prb + diff, plb + diff, plt - diff, prt - diff, areaColor, areaToColor, serie.clip);
ChartDrawer.DrawSector(vh, pct, radius, areaToColor, 270, 450);
ChartDrawer.DrawSector(vh, pcb, radius, areaColor, 90, 270);
CheckClipAndDrawPolygon(vh, prb + diff, plb + diff, plt - diff, prt - diff, areaColor,
areaToColor, serie.clip, grid);
UGL.DrawSector(vh, pct, radius, areaToColor, 270, 450);
UGL.DrawSector(vh, pcb, radius, areaColor, 90, 270);
}
}
}
@@ -475,102 +474,109 @@ namespace XCharts
var barLen = plb.y - plt.y;
var rectStartColor = Color32.Lerp(areaColor, areaToColor, radius / barLen);
var rectEndColor = Color32.Lerp(areaColor, areaToColor, (barLen - radius) / barLen);
CheckClipAndDrawPolygon(vh, prb - diff, plb - diff, plt + diff, prt + diff, rectStartColor, rectEndColor, serie.clip);
ChartDrawer.DrawSector(vh, pct, radius, rectEndColor, areaToColor, 90, 270, 1, isYAxis);
ChartDrawer.DrawSector(vh, pcb, radius, rectStartColor, areaColor, 270, 450, 1, isYAxis);
CheckClipAndDrawPolygon(vh, prb - diff, plb - diff, plt + diff, prt + diff, rectStartColor,
rectEndColor, serie.clip, grid);
UGL.DrawSector(vh, pct, radius, rectEndColor, areaToColor, 90, 270, 1, isYAxis);
UGL.DrawSector(vh, pcb, radius, rectStartColor, areaColor, 270, 450, 1, isYAxis);
}
else
{
CheckClipAndDrawPolygon(vh, prb - diff, plb - diff, plt + diff, prt + diff, areaColor, areaToColor, serie.clip);
ChartDrawer.DrawSector(vh, pct, radius, areaToColor, 90, 270);
ChartDrawer.DrawSector(vh, pcb, radius, areaColor, 270, 450);
CheckClipAndDrawPolygon(vh, prb - diff, plb - diff, plt + diff, prt + diff, areaColor,
areaToColor, serie.clip, grid);
UGL.DrawSector(vh, pct, radius, areaToColor, 90, 270);
UGL.DrawSector(vh, pcb, radius, areaColor, 270, 450);
}
}
}
}
}
private void DrawBarBackground(VertexHelper vh, Serie serie, SerieData serieData, ItemStyle itemStyle, int colorIndex,
bool highlight, float pX, float pY, float space, float barWidth, bool isYAxis)
private void DrawBarBackground(VertexHelper vh, Serie serie, SerieData serieData, ItemStyle itemStyle,
int colorIndex, bool highlight, float pX, float pY, float space, float barWidth, bool isYAxis, Grid grid)
{
var color = SerieHelper.GetItemBackgroundColor(serie, serieData, m_ThemeInfo, colorIndex, highlight, false);
var color = SerieHelper.GetItemBackgroundColor(serie, serieData, m_Theme, colorIndex, highlight, false);
if (ChartHelper.IsClearColor(color)) return;
if (isYAxis)
{
var axis = m_YAxises[serie.axisIndex];
var axisWidth = axis.axisLine.width;
Vector3 plt = new Vector3(m_CoordinateX + axisWidth, pY + space + barWidth);
Vector3 prt = new Vector3(m_CoordinateX + axisWidth + m_CoordinateWidth, pY + space + barWidth);
Vector3 prb = new Vector3(m_CoordinateX + axisWidth + m_CoordinateWidth, pY + space);
Vector3 plb = new Vector3(m_CoordinateX + axisWidth, pY + space);
var axis = m_YAxes[serie.yAxisIndex];
var axisWidth = axis.axisLine.GetWidth(m_Theme.axis.lineWidth);
Vector3 plt = new Vector3(grid.runtimeX + axisWidth, pY + space + barWidth);
Vector3 prt = new Vector3(grid.runtimeX + axisWidth + grid.runtimeWidth, pY + space + barWidth);
Vector3 prb = new Vector3(grid.runtimeX + axisWidth + grid.runtimeWidth, pY + space);
Vector3 plb = new Vector3(grid.runtimeX + axisWidth, pY + space);
if (serie.barType == BarType.Capsule)
{
var radius = barWidth / 2;
var diff = Vector3.right * radius;
var pcl = (plt + plb) / 2 + diff;
var pcr = (prt + prb) / 2 - diff;
CheckClipAndDrawPolygon(vh, plb + diff, plt + diff, prt - diff, prb - diff, color, color, serie.clip);
ChartDrawer.DrawSector(vh, pcl, radius, color, 180, 360);
ChartDrawer.DrawSector(vh, pcr, radius, color, 0, 180);
CheckClipAndDrawPolygon(vh, plb + diff, plt + diff, prt - diff, prb - diff, color, color, serie.clip, grid);
UGL.DrawSector(vh, pcl, radius, color, 180, 360);
UGL.DrawSector(vh, pcr, radius, color, 0, 180);
if (itemStyle.NeedShowBorder())
{
var borderWidth = itemStyle.borderWidth;
var borderColor = itemStyle.borderColor;
var smoothness = m_Settings.cicleSmoothness;
var smoothness = settings.cicleSmoothness;
var inRadius = radius - borderWidth;
var outRadius = radius;
var p1 = plb + diff + Vector3.up * borderWidth / 2;
var p2 = prb - diff + Vector3.up * borderWidth / 2;
var p3 = plt + diff - Vector3.up * borderWidth / 2;
var p4 = prt - diff - Vector3.up * borderWidth / 2;
ChartDrawer.DrawLine(vh, p1, p2, borderWidth / 2, borderColor);
ChartDrawer.DrawLine(vh, p3, p4, borderWidth / 2, borderColor);
ChartDrawer.DrawDoughnut(vh, pcl, inRadius, outRadius, borderColor, ChartConst.clearColor32, 180, 360, smoothness);
ChartDrawer.DrawDoughnut(vh, pcr, inRadius, outRadius, borderColor, ChartConst.clearColor32, 0, 180, smoothness);
UGL.DrawLine(vh, p1, p2, borderWidth / 2, borderColor);
UGL.DrawLine(vh, p3, p4, borderWidth / 2, borderColor);
UGL.DrawDoughnut(vh, pcl, inRadius, outRadius, borderColor, ChartConst.clearColor32,
180, 360, smoothness);
UGL.DrawDoughnut(vh, pcr, inRadius, outRadius, borderColor, ChartConst.clearColor32,
0, 180, smoothness);
}
}
else
{
CheckClipAndDrawPolygon(vh, ref plb, ref plt, ref prt, ref prb, color, color, serie.clip);
CheckClipAndDrawPolygon(vh, ref plb, ref plt, ref prt, ref prb, color, color, serie.clip, grid);
}
}
else
{
var axis = m_XAxises[serie.axisIndex];
var axisWidth = axis.axisLine.width;
Vector3 plb = new Vector3(pX + space, m_CoordinateY + axisWidth);
Vector3 plt = new Vector3(pX + space, m_CoordinateY + m_CoordinateHeight + axisWidth);
Vector3 prt = new Vector3(pX + space + barWidth, m_CoordinateY + m_CoordinateHeight + axisWidth);
Vector3 prb = new Vector3(pX + space + barWidth, m_CoordinateY + axisWidth);
var axis = m_XAxes[serie.xAxisIndex];
var axisWidth = axis.axisLine.GetWidth(m_Theme.axis.lineWidth);
Vector3 plb = new Vector3(pX + space, grid.runtimeY + axisWidth);
Vector3 plt = new Vector3(pX + space, grid.runtimeY + grid.runtimeHeight + axisWidth);
Vector3 prt = new Vector3(pX + space + barWidth, grid.runtimeY + grid.runtimeHeight + axisWidth);
Vector3 prb = new Vector3(pX + space + barWidth, grid.runtimeY + axisWidth);
if (serie.barType == BarType.Capsule)
{
var radius = barWidth / 2;
var diff = Vector3.up * radius;
var pct = (plt + prt) / 2 - diff;
var pcb = (plb + prb) / 2 + diff;
CheckClipAndDrawPolygon(vh, prb + diff, plb + diff, plt - diff, prt - diff, color, color, serie.clip);
ChartDrawer.DrawSector(vh, pct, radius, color, 270, 450);
ChartDrawer.DrawSector(vh, pcb, radius, color, 90, 270);
CheckClipAndDrawPolygon(vh, prb + diff, plb + diff, plt - diff, prt - diff, color, color,
serie.clip, grid);
UGL.DrawSector(vh, pct, radius, color, 270, 450);
UGL.DrawSector(vh, pcb, radius, color, 90, 270);
if (itemStyle.NeedShowBorder())
{
var borderWidth = itemStyle.borderWidth;
var borderColor = itemStyle.borderColor;
var smoothness = m_Settings.cicleSmoothness;
var smoothness = settings.cicleSmoothness;
var inRadius = radius - borderWidth;
var outRadius = radius;
var p1 = plb + diff + Vector3.right * borderWidth / 2;
var p2 = plt - diff + Vector3.right * borderWidth / 2;
var p3 = prb + diff - Vector3.right * borderWidth / 2;
var p4 = prt - diff - Vector3.right * borderWidth / 2;
ChartDrawer.DrawLine(vh, p1, p2, borderWidth / 2, borderColor);
ChartDrawer.DrawLine(vh, p3, p4, borderWidth / 2, borderColor);
ChartDrawer.DrawDoughnut(vh, pct, inRadius, outRadius, borderColor, ChartConst.clearColor32, 270, 450, smoothness);
ChartDrawer.DrawDoughnut(vh, pcb, inRadius, outRadius, borderColor, ChartConst.clearColor32, 90, 270, smoothness);
UGL.DrawLine(vh, p1, p2, borderWidth / 2, borderColor);
UGL.DrawLine(vh, p3, p4, borderWidth / 2, borderColor);
UGL.DrawDoughnut(vh, pct, inRadius, outRadius, borderColor, ChartConst.clearColor32,
270, 450, smoothness);
UGL.DrawDoughnut(vh, pcb, inRadius, outRadius, borderColor, ChartConst.clearColor32,
90, 270, smoothness);
}
}
else
{
CheckClipAndDrawPolygon(vh, ref prb, ref plb, ref plt, ref prt, color, color, serie.clip);
CheckClipAndDrawPolygon(vh, ref prb, ref plb, ref plt, ref prt, color, color, serie.clip, grid);
}
}
}
@@ -658,5 +664,37 @@ namespace XCharts
if (barWidth > 1) return barWidth;
else return barWidth * categoryWidth;
}
private List<string> tempList = new List<string>();
private int GetBarIndex(Serie currSerie)
{
tempList.Clear();
int index = 0;
for (int i = 0; i < m_Series.Count; i++)
{
var serie = m_Series.GetSerie(i);
if (serie.type != SerieType.Bar) continue;
if (string.IsNullOrEmpty(serie.stack))
{
if (serie.index == currSerie.index) return index;
tempList.Add(string.Empty);
index++;
}
else
{
if (!tempList.Contains(serie.stack))
{
if (serie.index == currSerie.index) return index;
tempList.Add(serie.stack);
index++;
}
else
{
if (serie.index == currSerie.index) return tempList.IndexOf(serie.stack);
}
}
}
return 0;
}
}
}

View File

@@ -1,12 +1,13 @@
/******************************************/
/* */
/* Copyright (c) 2018 monitor1394 */
/* https://github.com/monitor1394 */
/* */
/******************************************/
/************************************************/
/* */
/* Copyright (c) 2018 - 2021 monitor1394 */
/* https://github.com/monitor1394 */
/* */
/************************************************/
using UnityEngine;
using UnityEngine.UI;
using XUGL;
namespace XCharts
{
@@ -17,62 +18,62 @@ namespace XCharts
protected void CheckVisualMap()
{
if (!m_VisualMap.enable || !m_VisualMap.show) return;
if (!visualMap.enable || !visualMap.show) return;
Vector2 local;
if (canvas == null) return;
if (!RectTransformUtility.ScreenPointToLocalPointInRectangle(rectTransform,
Input.mousePosition, canvas.worldCamera, out local))
{
if (m_VisualMap.runtimeSelectedIndex >= 0)
if (visualMap.runtimeSelectedIndex >= 0)
{
m_VisualMap.runtimeSelectedIndex = -1;
visualMap.runtimeSelectedIndex = -1;
RefreshChart();
}
return;
}
if (local.x < chartX || local.x > chartX + chartWidth ||
local.y < chartY || local.y > chartY + chartHeight ||
!m_VisualMap.IsInRangeRect(local, chartRect))
!visualMap.IsInRangeRect(local, chartRect))
{
if (m_VisualMap.runtimeSelectedIndex >= 0)
if (visualMap.runtimeSelectedIndex >= 0)
{
m_VisualMap.runtimeSelectedIndex = -1;
visualMap.runtimeSelectedIndex = -1;
RefreshChart();
}
return;
}
var pos1 = Vector3.zero;
var pos2 = Vector3.zero;
var halfHig = m_VisualMap.itemHeight / 2;
var centerPos = chartPosition + m_VisualMap.location.GetPosition(chartWidth, chartHeight);
var halfHig = visualMap.itemHeight / 2;
var centerPos = chartPosition + visualMap.location.GetPosition(chartWidth, chartHeight);
var selectedIndex = -1;
var value = 0f;
switch (m_VisualMap.orient)
switch (visualMap.orient)
{
case Orient.Horizonal:
pos1 = centerPos + Vector3.left * halfHig;
pos2 = centerPos + Vector3.right * halfHig;
value = m_VisualMap.min + (local.x - pos1.x) / (pos2.x - pos1.x) * (m_VisualMap.max - m_VisualMap.min);
selectedIndex = m_VisualMap.GetIndex(value);
value = visualMap.min + (local.x - pos1.x) / (pos2.x - pos1.x) * (visualMap.max - visualMap.min);
selectedIndex = visualMap.GetIndex(value);
break;
case Orient.Vertical:
pos1 = centerPos + Vector3.down * halfHig;
pos2 = centerPos + Vector3.up * halfHig;
value = m_VisualMap.min + (local.y - pos1.y) / (pos2.y - pos1.y) * (m_VisualMap.max - m_VisualMap.min);
selectedIndex = m_VisualMap.GetIndex(value);
value = visualMap.min + (local.y - pos1.y) / (pos2.y - pos1.y) * (visualMap.max - visualMap.min);
selectedIndex = visualMap.GetIndex(value);
break;
}
m_VisualMap.runtimeSelectedValue = value;
m_VisualMap.runtimeSelectedIndex = selectedIndex;
visualMap.runtimeSelectedValue = value;
visualMap.runtimeSelectedIndex = selectedIndex;
RefreshChart();
}
protected void OnDragVisualMapStart()
{
if (!m_VisualMap.enable || !m_VisualMap.show || !m_VisualMap.calculable) return;
var inMinRect = m_VisualMap.IsInRangeMinRect(pointerPos, chartRect, m_Settings.visualMapTriangeLen);
var inMaxRect = m_VisualMap.IsInRangeMaxRect(pointerPos, chartRect, m_Settings.visualMapTriangeLen);
if (!visualMap.enable || !visualMap.show || !visualMap.calculable) return;
var inMinRect = visualMap.IsInRangeMinRect(pointerPos, chartRect, m_Theme.visualMap.triangeLen);
var inMaxRect = visualMap.IsInRangeMaxRect(pointerPos, chartRect, m_Theme.visualMap.triangeLen);
if (inMinRect || inMaxRect)
{
if (inMinRect)
@@ -88,24 +89,24 @@ namespace XCharts
protected void OnDragVisualMap()
{
if (!m_VisualMap.enable || !m_VisualMap.show || !m_VisualMap.calculable) return;
if (!visualMap.enable || !visualMap.show || !visualMap.calculable) return;
if (!m_VisualMapMinDrag && !m_VisualMapMaxDrag) return;
var value = m_VisualMap.GetValue(pointerPos, chartRect);
var value = visualMap.GetValue(pointerPos, chartRect);
if (m_VisualMapMinDrag)
{
m_VisualMap.rangeMin = value;
visualMap.rangeMin = value;
}
else
{
m_VisualMap.rangeMax = value;
visualMap.rangeMax = value;
}
RefreshChart();
}
protected void OnDragVisualMapEnd()
{
if (!m_VisualMap.enable || !m_VisualMap.show || !m_VisualMap.calculable) return;
if (!visualMap.enable || !visualMap.show || !visualMap.calculable) return;
if (m_VisualMapMinDrag || m_VisualMapMaxDrag)
{
RefreshChart();
@@ -117,19 +118,20 @@ namespace XCharts
protected void DrawHeatmapSerie(VertexHelper vh, int colorIndex, Serie serie)
{
if (serie.animation.HasFadeOut()) return;
var yAxis = m_YAxises[serie.axisIndex];
var xAxis = m_XAxises[serie.axisIndex];
var yAxis = m_YAxes[serie.yAxisIndex];
var xAxis = m_XAxes[serie.xAxisIndex];
var grid = GetSerieGridOrDefault(serie);
var xCount = xAxis.data.Count;
var yCount = yAxis.data.Count;
var xWidth = m_CoordinateWidth / xCount;
var yWidth = m_CoordinateHeight / yCount;
var xWidth = grid.runtimeWidth / xCount;
var yWidth = grid.runtimeHeight / yCount;
var zeroX = m_CoordinateX;
var zeroY = m_CoordinateY;
var zeroX = grid.runtimeX;
var zeroY = grid.runtimeY;
var dataList = serie.GetDataList();
var rangeMin = m_VisualMap.rangeMin;
var rangeMax = m_VisualMap.rangeMax;
var color = m_ThemeInfo.GetColor(serie.index);
var rangeMin = visualMap.rangeMin;
var rangeMax = visualMap.rangeMax;
var color = m_Theme.GetColor(serie.index);
var borderWidth = serie.itemStyle.show ? serie.itemStyle.borderWidth : 0;
var borderColor = serie.itemStyle.opacity > 0 ? serie.itemStyle.borderColor : ChartConst.clearColor32;
borderColor.a = (byte)(borderColor.a * serie.itemStyle.opacity);
@@ -145,7 +147,7 @@ namespace XCharts
var dataIndex = i * yCount + j;
if (dataIndex >= dataList.Count) continue;
var serieData = dataList[dataIndex];
var dimension = VisualMapHelper.GetDimension(m_VisualMap, serieData.data.Count);
var dimension = VisualMapHelper.GetDimension(visualMap, serieData.data.Count);
if (serie.IsIgnoreIndex(dataIndex, dimension))
{
serie.dataPoints.Add(Vector3.zero);
@@ -157,32 +159,32 @@ namespace XCharts
serie.dataPoints.Add(pos);
serieData.canShowLabel = false;
if (value == 0) continue;
if (m_VisualMap.enable)
if (visualMap.enable)
{
if ((value < rangeMin && rangeMin != m_VisualMap.min)
|| (value > rangeMax && rangeMax != m_VisualMap.max))
if ((value < rangeMin && rangeMin != visualMap.min)
|| (value > rangeMax && rangeMax != visualMap.max))
{
continue;
}
if (!m_VisualMap.IsInSelectedValue(value)) continue;
color = m_VisualMap.GetColor(value);
if (!visualMap.IsInSelectedValue(value)) continue;
color = visualMap.GetColor(value);
}
if (animationIndex >= 0 && i > animationIndex) continue;
serieData.canShowLabel = true;
var emphasis = (m_Tooltip.show && i == (int)m_Tooltip.runtimeXValues[0] && j == (int)m_Tooltip.runtimeYValues[0])
|| m_VisualMap.runtimeSelectedIndex > 0;
var emphasis = (tooltip.show && i == (int)tooltip.runtimeXValues[0] && j == (int)tooltip.runtimeYValues[0])
|| visualMap.runtimeSelectedIndex > 0;
var rectWid = xWidth - 2 * borderWidth;
var rectHig = yWidth - 2 * borderWidth;
ChartDrawer.DrawPolygon(vh, pos, rectWid / 2, rectHig / 2, color);
UGL.DrawRectangle(vh, pos, rectWid / 2, rectHig / 2, color);
if (borderWidth > 0 && !ChartHelper.IsClearColor(borderColor))
{
ChartDrawer.DrawBorder(vh, pos, rectWid, rectHig, borderWidth, borderColor);
UGL.DrawBorder(vh, pos, rectWid, rectHig, borderWidth, borderColor);
}
if (m_VisualMap.hoverLink && emphasis && serie.emphasis.show && serie.emphasis.itemStyle.borderWidth > 0)
if (visualMap.hoverLink && emphasis && serie.emphasis.show && serie.emphasis.itemStyle.borderWidth > 0)
{
var emphasisBorderWidth = serie.emphasis.itemStyle.borderWidth;
var emphasisBorderColor = serie.emphasis.itemStyle.opacity > 0 ? serie.emphasis.itemStyle.borderColor : ChartConst.clearColor32;
ChartDrawer.DrawBorder(vh, pos, rectWid, rectHig, emphasisBorderWidth, emphasisBorderColor);
UGL.DrawBorder(vh, pos, rectWid, rectHig, emphasisBorderWidth, emphasisBorderColor);
}
}
}
@@ -190,32 +192,32 @@ namespace XCharts
{
serie.animation.CheckProgress(xCount);
m_IsPlayingAnimation = true;
RefreshChart();
RefreshPainter(serie);
}
if (dataChanging)
{
RefreshChart();
RefreshPainter(serie);
}
}
protected void DrawVisualMap(VertexHelper vh)
{
if (!m_VisualMap.enable || !m_VisualMap.show) return;
var centerPos = chartPosition + m_VisualMap.location.GetPosition(chartWidth, chartHeight);
if (!visualMap.enable || !visualMap.show) return;
var centerPos = chartPosition + visualMap.location.GetPosition(chartWidth, chartHeight);
var pos1 = Vector3.zero;
var pos2 = Vector3.zero;
var dir = Vector3.zero;
var halfWid = m_VisualMap.itemWidth / 2;
var halfHig = m_VisualMap.itemHeight / 2;
var halfWid = visualMap.itemWidth / 2;
var halfHig = visualMap.itemHeight / 2;
var xRadius = 0f;
var yRadius = 0f;
var splitNum = m_VisualMap.runtimeInRange.Count;
var splitWid = m_VisualMap.itemHeight / (splitNum - 1);
var splitNum = visualMap.runtimeInRange.Count;
var splitWid = visualMap.itemHeight / (splitNum - 1);
var isVertical = false;
var colors = m_VisualMap.runtimeInRange;
var triangeLen = m_Settings.visualMapTriangeLen;
switch (m_VisualMap.orient)
var colors = visualMap.runtimeInRange;
var triangeLen = m_Theme.visualMap.triangeLen;
switch (visualMap.orient)
{
case Orient.Horizonal:
pos1 = centerPos + Vector3.left * halfHig;
@@ -224,20 +226,20 @@ namespace XCharts
xRadius = splitWid / 2;
yRadius = halfWid;
isVertical = false;
if (m_VisualMap.calculable)
if (visualMap.calculable)
{
var p0 = pos1 + Vector3.right * m_VisualMap.runtimeRangeMinHeight;
var p0 = pos1 + Vector3.right * visualMap.runtimeRangeMinHeight;
var p1 = p0 + Vector3.up * halfWid;
var p2 = p0 + Vector3.up * (halfWid + triangeLen);
var p3 = p2 + Vector3.left * triangeLen;
var color = m_VisualMap.GetColor(m_VisualMap.rangeMin);
ChartDrawer.DrawTriangle(vh, p1, p2, p3, color);
p0 = pos1 + Vector3.right * m_VisualMap.runtimeRangeMaxHeight;
var color = visualMap.GetColor(visualMap.rangeMin);
UGL.DrawTriangle(vh, p1, p2, p3, color);
p0 = pos1 + Vector3.right * visualMap.runtimeRangeMaxHeight;
p1 = p0 + Vector3.up * halfWid;
p2 = p0 + Vector3.up * (halfWid + triangeLen);
p3 = p2 + Vector3.right * triangeLen;
color = m_VisualMap.GetColor(m_VisualMap.rangeMax);
ChartDrawer.DrawTriangle(vh, p1, p2, p3, color);
color = visualMap.GetColor(visualMap.rangeMax);
UGL.DrawTriangle(vh, p1, p2, p3, color);
}
break;
case Orient.Vertical:
@@ -247,32 +249,32 @@ namespace XCharts
xRadius = halfWid;
yRadius = splitWid / 2;
isVertical = true;
if (m_VisualMap.calculable)
if (visualMap.calculable)
{
var p0 = pos1 + Vector3.up * m_VisualMap.runtimeRangeMinHeight;
var p0 = pos1 + Vector3.up * visualMap.runtimeRangeMinHeight;
var p1 = p0 + Vector3.right * halfWid;
var p2 = p0 + Vector3.right * (halfWid + triangeLen);
var p3 = p2 + Vector3.down * triangeLen;
var color = m_VisualMap.GetColor(m_VisualMap.rangeMin);
ChartDrawer.DrawTriangle(vh, p1, p2, p3, color);
p0 = pos1 + Vector3.up * m_VisualMap.runtimeRangeMaxHeight;
var color = visualMap.GetColor(visualMap.rangeMin);
UGL.DrawTriangle(vh, p1, p2, p3, color);
p0 = pos1 + Vector3.up * visualMap.runtimeRangeMaxHeight;
p1 = p0 + Vector3.right * halfWid;
p2 = p0 + Vector3.right * (halfWid + triangeLen);
p3 = p2 + Vector3.up * triangeLen;
color = m_VisualMap.GetColor(m_VisualMap.rangeMax);
ChartDrawer.DrawTriangle(vh, p1, p2, p3, color);
color = visualMap.GetColor(visualMap.rangeMax);
UGL.DrawTriangle(vh, p1, p2, p3, color);
}
break;
}
if (m_VisualMap.calculable && (m_VisualMap.rangeMin > m_VisualMap.min
|| m_VisualMap.rangeMax < m_VisualMap.max))
if (visualMap.calculable && (visualMap.rangeMin > visualMap.min
|| visualMap.rangeMax < visualMap.max))
{
var rangeMin = m_VisualMap.rangeMin;
var rangeMax = m_VisualMap.rangeMax;
var diff = (m_VisualMap.max - m_VisualMap.min) / (splitNum - 1);
var rangeMin = visualMap.rangeMin;
var rangeMax = visualMap.rangeMax;
var diff = (visualMap.max - visualMap.min) / (splitNum - 1);
for (int i = 1; i < splitNum; i++)
{
var splitMin = m_VisualMap.min + (i - 1) * diff;
var splitMin = visualMap.min + (i - 1) * diff;
var splitMax = splitMin + diff;
if (rangeMin > splitMax || rangeMax < splitMin)
{
@@ -282,47 +284,47 @@ namespace XCharts
{
var splitPos = pos1 + dir * (i - 1 + 0.5f) * splitWid;
var startColor = colors[i - 1];
var toColor = m_VisualMap.IsPiecewise() ? startColor : colors[i];
ChartDrawer.DrawPolygon(vh, splitPos, xRadius, yRadius, startColor, toColor, isVertical);
var toColor = visualMap.IsPiecewise() ? startColor : colors[i];
UGL.DrawRectangle(vh, splitPos, xRadius, yRadius, startColor, toColor, isVertical);
}
else if (rangeMin > splitMin && rangeMax >= splitMax)
{
var p0 = pos1 + dir * m_VisualMap.runtimeRangeMinHeight;
var p0 = pos1 + dir * visualMap.runtimeRangeMinHeight;
var splitMaxPos = pos1 + dir * i * splitWid;
var splitPos = p0 + (splitMaxPos - p0) / 2;
var startColor = m_VisualMap.GetColor(m_VisualMap.rangeMin);
var toColor = m_VisualMap.IsPiecewise() ? startColor : colors[i];
var startColor = visualMap.GetColor(visualMap.rangeMin);
var toColor = visualMap.IsPiecewise() ? startColor : colors[i];
var yRadius1 = Vector3.Distance(p0, splitMaxPos) / 2;
if (m_VisualMap.orient == Orient.Vertical)
ChartDrawer.DrawPolygon(vh, splitPos, xRadius, yRadius1, startColor, toColor, isVertical);
if (visualMap.orient == Orient.Vertical)
UGL.DrawRectangle(vh, splitPos, xRadius, yRadius1, startColor, toColor, isVertical);
else
ChartDrawer.DrawPolygon(vh, splitPos, yRadius1, yRadius, startColor, toColor, isVertical);
UGL.DrawRectangle(vh, splitPos, yRadius1, yRadius, startColor, toColor, isVertical);
}
else if (rangeMax < splitMax && rangeMin <= splitMin)
{
var p0 = pos1 + dir * m_VisualMap.runtimeRangeMaxHeight;
var p0 = pos1 + dir * visualMap.runtimeRangeMaxHeight;
var splitMinPos = pos1 + dir * (i - 1) * splitWid;
var splitPos = splitMinPos + (p0 - splitMinPos) / 2;
var startColor = colors[i - 1];
var toColor = m_VisualMap.IsPiecewise() ? startColor : m_VisualMap.GetColor(m_VisualMap.rangeMax);
var toColor = visualMap.IsPiecewise() ? startColor : visualMap.GetColor(visualMap.rangeMax);
var yRadius1 = Vector3.Distance(p0, splitMinPos) / 2;
if (m_VisualMap.orient == Orient.Vertical)
ChartDrawer.DrawPolygon(vh, splitPos, xRadius, yRadius1, startColor, toColor, isVertical);
if (visualMap.orient == Orient.Vertical)
UGL.DrawRectangle(vh, splitPos, xRadius, yRadius1, startColor, toColor, isVertical);
else
ChartDrawer.DrawPolygon(vh, splitPos, yRadius1, yRadius, startColor, toColor, isVertical);
UGL.DrawRectangle(vh, splitPos, yRadius1, yRadius, startColor, toColor, isVertical);
}
else
{
var p0 = pos1 + dir * m_VisualMap.runtimeRangeMinHeight;
var p1 = pos1 + dir * m_VisualMap.runtimeRangeMaxHeight;
var p0 = pos1 + dir * visualMap.runtimeRangeMinHeight;
var p1 = pos1 + dir * visualMap.runtimeRangeMaxHeight;
var splitPos = (p0 + p1) / 2;
var startColor = m_VisualMap.GetColor(m_VisualMap.rangeMin);
var toColor = m_VisualMap.GetColor(m_VisualMap.rangeMax);
var startColor = visualMap.GetColor(visualMap.rangeMin);
var toColor = visualMap.GetColor(visualMap.rangeMax);
var yRadius1 = Vector3.Distance(p0, p1) / 2;
if (m_VisualMap.orient == Orient.Vertical)
ChartDrawer.DrawPolygon(vh, splitPos, xRadius, yRadius1, startColor, toColor, isVertical);
if (visualMap.orient == Orient.Vertical)
UGL.DrawRectangle(vh, splitPos, xRadius, yRadius1, startColor, toColor, isVertical);
else
ChartDrawer.DrawPolygon(vh, splitPos, yRadius1, yRadius, startColor, toColor, isVertical);
UGL.DrawRectangle(vh, splitPos, yRadius1, yRadius, startColor, toColor, isVertical);
}
}
}
@@ -332,45 +334,45 @@ namespace XCharts
{
var splitPos = pos1 + dir * (i - 1 + 0.5f) * splitWid;
var startColor = colors[i - 1];
var toColor = m_VisualMap.IsPiecewise() ? startColor : colors[i];
ChartDrawer.DrawPolygon(vh, splitPos, xRadius, yRadius, startColor, toColor, isVertical);
var toColor = visualMap.IsPiecewise() ? startColor : colors[i];
UGL.DrawRectangle(vh, splitPos, xRadius, yRadius, startColor, toColor, isVertical);
}
}
if (m_VisualMap.rangeMin > m_VisualMap.min)
if (visualMap.rangeMin > visualMap.min)
{
var p0 = pos1 + dir * m_VisualMap.runtimeRangeMinHeight;
ChartDrawer.DrawPolygon(vh, pos1, p0, m_VisualMap.itemWidth / 2, m_ThemeInfo.visualMapBackgroundColor);
var p0 = pos1 + dir * visualMap.runtimeRangeMinHeight;
UGL.DrawRectangle(vh, pos1, p0, visualMap.itemWidth / 2, m_Theme.visualMap.backgroundColor);
}
if (m_VisualMap.rangeMax < m_VisualMap.max)
if (visualMap.rangeMax < visualMap.max)
{
var p1 = pos1 + dir * m_VisualMap.runtimeRangeMaxHeight;
ChartDrawer.DrawPolygon(vh, p1, pos2, m_VisualMap.itemWidth / 2, m_ThemeInfo.visualMapBackgroundColor);
var p1 = pos1 + dir * visualMap.runtimeRangeMaxHeight;
UGL.DrawRectangle(vh, p1, pos2, visualMap.itemWidth / 2, m_Theme.visualMap.backgroundColor);
}
if (m_VisualMap.hoverLink)
if (visualMap.hoverLink)
{
if (m_VisualMap.runtimeSelectedIndex >= 0)
if (visualMap.runtimeSelectedIndex >= 0)
{
var p0 = pos1 + dir * m_VisualMap.runtimeRangeMinHeight;
var p1 = pos1 + dir * m_VisualMap.runtimeRangeMaxHeight;
var p0 = pos1 + dir * visualMap.runtimeRangeMinHeight;
var p1 = pos1 + dir * visualMap.runtimeRangeMaxHeight;
if (m_VisualMap.orient == Orient.Vertical)
if (visualMap.orient == Orient.Vertical)
{
var p2 = new Vector3(centerPos.x + halfWid, Mathf.Clamp(pointerPos.y + (triangeLen / 2), p0.y, p1.y));
var p3 = new Vector3(centerPos.x + halfWid, Mathf.Clamp(pointerPos.y - (triangeLen / 2), p0.y, p1.y));
var p4 = new Vector3(centerPos.x + halfWid + triangeLen / 2, pointerPos.y);
ChartDrawer.DrawTriangle(vh, p2, p3, p4, colors[m_VisualMap.runtimeSelectedIndex]);
UGL.DrawTriangle(vh, p2, p3, p4, colors[visualMap.runtimeSelectedIndex]);
}
else
{
var p2 = new Vector3(Mathf.Clamp(pointerPos.x + (triangeLen / 2), p0.x, p1.x), centerPos.y + halfWid);
var p3 = new Vector3(Mathf.Clamp(pointerPos.x - (triangeLen / 2), p0.x, p1.x), centerPos.y + halfWid);
var p4 = new Vector3(pointerPos.x, centerPos.y + halfWid + triangeLen / 2);
ChartDrawer.DrawTriangle(vh, p2, p3, p4, colors[m_VisualMap.runtimeSelectedIndex]);
UGL.DrawTriangle(vh, p2, p3, p4, colors[visualMap.runtimeSelectedIndex]);
}
}
else if (m_Tooltip.show && m_Tooltip.runtimeXValues[0] >= 0 && m_Tooltip.runtimeYValues[0] >= 0)
else if (tooltip.show && tooltip.runtimeXValues[0] >= 0 && tooltip.runtimeYValues[0] >= 0)
{
// var p0 = pos1 + dir * m_VisualMap.rangeMinHeight;
// var p1 = pos1 + dir * m_VisualMap.rangeMaxHeight;
@@ -379,14 +381,14 @@ namespace XCharts
// var p2 = new Vector3(centerPos.x + halfWid, Mathf.Clamp(pointerPos.y + (triangeLen / 2), p0.y, p1.y));
// var p3 = new Vector3(centerPos.x + halfWid, Mathf.Clamp(pointerPos.y - (triangeLen / 2), p0.y, p1.y));
// var p4 = new Vector3(centerPos.x + halfWid + triangeLen / 2, pointerPos.y);
// ChartDrawer.DrawTriangle(vh, p2, p3, p4, colors[m_VisualMap.rtSelectedIndex]);
// UGL.DrawTriangle(vh, p2, p3, p4, colors[m_VisualMap.rtSelectedIndex]);
// }
// else
// {
// var p2 = new Vector3(Mathf.Clamp(pointerPos.x + (triangeLen / 2), p0.x, p1.x), centerPos.y + halfWid);
// var p3 = new Vector3(Mathf.Clamp(pointerPos.x - (triangeLen / 2), p0.x, p1.x), centerPos.y + halfWid);
// var p4 = new Vector3(pointerPos.x, centerPos.y + halfWid + triangeLen / 2);
// ChartDrawer.DrawTriangle(vh, p2, p3, p4, colors[m_VisualMap.rtSelectedIndex]);
// UGL.DrawTriangle(vh, p2, p3, p4, colors[m_VisualMap.rtSelectedIndex]);
// }
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -1,9 +1,9 @@
/******************************************/
/* */
/* Copyright (c) 2018 monitor1394 */
/* https://github.com/monitor1394 */
/* */
/******************************************/
/************************************************/
/* */
/* Copyright (c) 2018 - 2021 monitor1394 */
/* https://github.com/monitor1394 */
/* */
/************************************************/
using UnityEngine;
using UnityEngine.UI;
@@ -16,8 +16,9 @@ namespace XCharts
{
if (serie.animation.HasFadeOut()) return;
if (!serie.show) return;
var yAxis = m_YAxises[serie.axisIndex];
var xAxis = m_XAxises[serie.axisIndex];
var yAxis = m_YAxes[serie.yAxisIndex];
var xAxis = m_XAxes[serie.xAxisIndex];
var grid = GetSerieGridOrDefault(serie);
int maxCount = serie.maxShow > 0 ?
(serie.maxShow > serie.dataCount ? serie.dataCount : serie.maxShow)
: serie.dataCount;
@@ -27,21 +28,21 @@ namespace XCharts
var dataChanging = false;
for (int n = serie.minShow; n < maxCount; n++)
{
var serieData = serie.GetDataList(m_DataZoom)[n];
var serieData = serie.GetDataList(dataZoom)[n];
var symbol = SerieHelper.GetSerieSymbol(serie, serieData);
if (!symbol.ShowSymbol(n, maxCount)) continue;
var highlight = serie.highlighted || serieData.highlighted;
var color = SerieHelper.GetItemColor(serie, serieData, m_ThemeInfo, colorIndex, highlight);
var toColor = SerieHelper.GetItemToColor(serie, serieData, m_ThemeInfo, colorIndex, highlight);
var symbolBorder = SerieHelper.GetSymbolBorder(serie, serieData, highlight);
var color = SerieHelper.GetItemColor(serie, serieData, m_Theme, colorIndex, highlight);
var toColor = SerieHelper.GetItemToColor(serie, serieData, m_Theme, colorIndex, highlight);
var symbolBorder = SerieHelper.GetSymbolBorder(serie, serieData, m_Theme, highlight);
var cornerRadius = SerieHelper.GetSymbolCornerRadius(serie, serieData, highlight);
float xValue = serieData.GetCurrData(0, dataChangeDuration, xAxis.inverse);
float yValue = serieData.GetCurrData(1, dataChangeDuration, yAxis.inverse);
if (serieData.IsDataChanged()) dataChanging = true;
float pX = m_CoordinateX + xAxis.axisLine.width;
float pY = m_CoordinateY + yAxis.axisLine.width;
float xDataHig = GetDataHig(xAxis, xValue, m_CoordinateWidth);
float yDataHig = GetDataHig(yAxis, yValue, m_CoordinateHeight);
float pX = grid.runtimeX + xAxis.axisLine.GetWidth(m_Theme.axis.lineWidth);
float pY = grid.runtimeY + yAxis.axisLine.GetWidth(m_Theme.axis.lineWidth);
float xDataHig = GetDataHig(xAxis, xValue, grid.runtimeWidth);
float yDataHig = GetDataHig(yAxis, yValue, grid.runtimeHeight);
var pos = new Vector3(pX + xDataHig, pY + yDataHig);
serie.dataPoints.Add(pos);
serieData.runtimePosition = pos;
@@ -49,11 +50,11 @@ namespace XCharts
float symbolSize = 0;
if (serie.highlighted || serieData.highlighted)
{
symbolSize = symbol.GetSelectedSize(datas);
symbolSize = symbol.GetSelectedSize(datas, m_Theme.serie.scatterSymbolSelectedSize);
}
else
{
symbolSize = symbol.GetSize(datas);
symbolSize = symbol.GetSize(datas, m_Theme.serie.scatterSymbolSize);
}
symbolSize *= rate;
if (symbolSize > 100) symbolSize = 100;
@@ -65,7 +66,7 @@ namespace XCharts
color.a = (byte)(255 * (symbolSize - nowSize) / symbolSize);
DrawSymbol(vh, symbol.type, nowSize, symbolBorder, pos, color, toColor, symbol.gap, cornerRadius);
}
RefreshChart();
RefreshPainter(serie);
}
else
{
@@ -76,11 +77,11 @@ namespace XCharts
{
serie.animation.CheckProgress(1);
m_IsPlayingAnimation = true;
RefreshChart();
RefreshPainter(serie);
}
if (dataChanging)
{
RefreshChart();
RefreshPainter(serie);
}
}

View File

@@ -0,0 +1,408 @@
/************************************************/
/* */
/* Copyright (c) 2018 - 2021 monitor1394 */
/* https://github.com/monitor1394 */
/* */
/************************************************/
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.EventSystems;
using XUGL;
namespace XCharts
{
internal class DrawSerieGauge : IDrawSerie
{
public BaseChart chart;
private static readonly string s_SerieLabelObjectName = "label";
private static readonly string s_AxisLabelObjectName = "axis_label";
private bool m_UpdateTitleText = false;
private bool m_UpdateLabelText = false;
public DrawSerieGauge(BaseChart chart)
{
this.chart = chart;
}
public void InitComponent()
{
InitAxisLabel();
}
public void CheckComponent()
{
}
public void Update()
{
if (m_UpdateTitleText)
{
m_UpdateTitleText = false;
foreach (var serie in chart.series.list)
{
if (serie.type == SerieType.Gauge)
{
TitleStyleHelper.UpdateTitleText(serie);
}
}
}
if (m_UpdateLabelText)
{
m_UpdateLabelText = false;
foreach (var serie in chart.series.list)
{
if (serie.type == SerieType.Gauge)
{
SerieLabelHelper.SetGaugeLabelText(serie);
UpdateAxisLabel(serie);
}
}
}
}
public void DrawBase(VertexHelper vh)
{
}
public void DrawSerie(VertexHelper vh, Serie serie)
{
if (serie.type != SerieType.Gauge) return;
DrawGauge(vh, serie);
}
public void RefreshLabel()
{
}
public bool CheckTootipArea(Vector2 local)
{
var serie = GetPointerInSerieIndex(chart.series, local);
if (serie != null)
{
chart.tooltip.runtimeDataIndex.Clear();
chart.tooltip.runtimeDataIndex.Add(serie.index);
chart.tooltip.UpdateContentPos(local + chart.tooltip.offset);
UpdateTooltip();
return true;
}
else if (chart.tooltip.IsActive())
{
chart.tooltip.SetActive(false);
chart.RefreshChart();
}
return false;
}
public bool OnLegendButtonClick(int index, string legendName, bool show)
{
return false;
}
public bool OnLegendButtonEnter(int index, string legendName)
{
return false;
}
public bool OnLegendButtonExit(int index, string legendName)
{
return false;
}
public void OnPointerDown(PointerEventData eventData)
{
}
private void InitAxisLabel()
{
if (!SeriesHelper.ContainsSerie(chart.series, SerieType.Gauge)) return;
var labelObject = ChartHelper.AddObject(s_AxisLabelObjectName, chart.transform, chart.chartMinAnchor,
chart.chartMaxAnchor, chart.chartPivot, chart.chartSizeDelta);
labelObject.hideFlags = chart.chartHideFlags;
SerieLabelPool.ReleaseAll(labelObject.transform);
for (int i = 0; i < chart.series.Count; i++)
{
var serie = chart.series.list[i];
var serieLabel = serie.gaugeAxis.axisLabel;
var count = serie.splitNumber > 36 ? 36 : (serie.splitNumber + 1);
var startAngle = serie.startAngle;
serie.gaugeAxis.ClearLabelObject();
SerieHelper.UpdateCenter(serie, chart.chartPosition, chart.chartWidth, chart.chartHeight);
for (int j = 0; j < count; j++)
{
var textName = ChartCached.GetSerieLabelName(s_SerieLabelObjectName, i, j);
var color = Color.grey;
var labelObj = SerieLabelPool.Get(textName, labelObject.transform, serieLabel, color, 100, 100, chart.theme);
var iconImage = labelObj.transform.Find("Icon").GetComponent<Image>();
var isAutoSize = serieLabel.backgroundWidth == 0 || serieLabel.backgroundHeight == 0;
var item = new ChartLabel();
item.SetLabel(labelObj, isAutoSize, serieLabel.paddingLeftRight, serieLabel.paddingTopBottom);
item.SetIcon(iconImage);
item.SetIconActive(false);
serie.gaugeAxis.AddLabelObject(item);
}
UpdateAxisLabel(serie);
}
}
private void UpdateAxisLabel()
{
foreach (var serie in chart.series.list)
{
if (serie.type == SerieType.Gauge)
{
UpdateAxisLabel(serie);
}
}
}
private void UpdateAxisLabel(Serie serie)
{
var show = serie.gaugeAxis.show && serie.gaugeAxis.axisLabel.show;
serie.gaugeAxis.SetLabelObjectActive(show);
if (!show)
{
return;
}
var count = serie.splitNumber > 36 ? 36 : serie.splitNumber;
var startAngle = serie.startAngle;
var totalAngle = serie.endAngle - serie.startAngle;
var totalValue = serie.max - serie.min;
var diffAngle = totalAngle / count;
var diffValue = totalValue / count;
var radius = serie.runtimeInsideRadius - serie.gaugeAxis.axisLabel.margin;
var serieData = serie.GetSerieData(0);
var customLabelText = serie.gaugeAxis.axisLabelText;
for (int j = 0; j <= count; j++)
{
var angle = serie.startAngle + j * diffAngle;
var value = serie.min + j * diffValue;
var pos = ChartHelper.GetPosition(serie.runtimeCenterPos, angle, radius);
var text = customLabelText != null && j < customLabelText.Count ? customLabelText[j] :
SerieLabelHelper.GetFormatterContent(serie, serieData, value, totalValue, serie.gaugeAxis.axisLabel);
serie.gaugeAxis.SetLabelObjectText(j, text);
serie.gaugeAxis.SetLabelObjectPosition(j, pos);
}
}
private void DrawGauge(VertexHelper vh, Serie serie)
{
SerieHelper.UpdateCenter(serie, chart.chartPosition, chart.chartWidth, chart.chartHeight);
var destAngle = GetCurrAngle(serie, true);
serie.animation.InitProgress(0, serie.startAngle, destAngle);
var currAngle = serie.animation.IsFinish() ? GetCurrAngle(serie, false) : serie.animation.GetCurrDetail();
DrawProgressBar(vh, serie, currAngle);
DrawStageColor(vh, serie);
DrawLineStyle(vh, serie);
DrawAxisTick(vh, serie);
DrawPointer(vh, serie, currAngle);
TitleStyleHelper.CheckTitle(serie, ref chart.m_ReinitTitle, ref m_UpdateTitleText);
SerieLabelHelper.CheckLabel(serie, ref chart.m_ReinitLabel, ref m_UpdateLabelText);
CheckAnimation(serie);
if (!serie.animation.IsFinish())
{
serie.animation.CheckProgress(destAngle - serie.startAngle);
chart.RefreshPainter(serie);
}
else if (NeedRefresh(serie))
{
chart.RefreshPainter(serie);
}
}
private void DrawProgressBar(VertexHelper vh, Serie serie, float currAngle)
{
if (serie.gaugeType != GaugeType.ProgressBar) return;
if (!serie.gaugeAxis.show || !serie.gaugeAxis.axisLine.show) return;
var color = serie.gaugeAxis.GetAxisLineColor(chart.theme, serie.index);
var backgroundColor = serie.gaugeAxis.GetAxisLineBackgroundColor(chart.theme, serie.index);
var lineWidth = serie.gaugeAxis.axisLine.GetWidth(chart.theme.gauge.lineWidth);
var outsideRadius = serie.runtimeInsideRadius + lineWidth;
var borderWidth = serie.itemStyle.borderWidth;
var borderColor = serie.itemStyle.borderColor;
UGL.DrawDoughnut(vh, serie.runtimeCenterPos, serie.runtimeInsideRadius, outsideRadius,
backgroundColor, backgroundColor, Color.clear, serie.startAngle, serie.endAngle, 0, Color.clear,
0, chart.settings.cicleSmoothness, serie.roundCap);
UGL.DrawDoughnut(vh, serie.runtimeCenterPos, serie.runtimeInsideRadius, outsideRadius,
color, color, Color.clear, serie.startAngle, currAngle, 0, Color.clear,
0, chart.settings.cicleSmoothness, serie.roundCap);
}
private void DrawStageColor(VertexHelper vh, Serie serie)
{
if (serie.gaugeType != GaugeType.Pointer) return;
if (!serie.gaugeAxis.show || !serie.gaugeAxis.axisLine.show) return;
var totalAngle = serie.endAngle - serie.startAngle;
var tempStartAngle = serie.startAngle;
var tempEndAngle = serie.startAngle;
var lineWidth = serie.gaugeAxis.axisLine.GetWidth(chart.theme.gauge.lineWidth);
var outsideRadius = serie.runtimeInsideRadius + lineWidth;
serie.gaugeAxis.runtimeStageAngle.Clear();
for (int i = 0; i < serie.gaugeAxis.axisLine.stageColor.Count; i++)
{
var stageColor = serie.gaugeAxis.axisLine.stageColor[i];
tempEndAngle = serie.startAngle + totalAngle * stageColor.percent;
serie.gaugeAxis.runtimeStageAngle.Add(tempEndAngle);
UGL.DrawDoughnut(vh, serie.runtimeCenterPos, serie.runtimeInsideRadius, outsideRadius,
stageColor.color, stageColor.color, Color.clear, tempStartAngle, tempEndAngle, 0, Color.clear,
0, chart.settings.cicleSmoothness);
tempStartAngle = tempEndAngle;
}
}
private void DrawPointer(VertexHelper vh, Serie serie, float currAngle)
{
if (!serie.gaugePointer.show) return;
var pointerColor = serie.gaugeAxis.GetPointerColor(chart.theme, serie.index, currAngle, serie.itemStyle);
var pointerToColor = !ChartHelper.IsClearColor(serie.itemStyle.toColor) ? serie.itemStyle.toColor : pointerColor;
var len = serie.gaugePointer.length < 1 && serie.gaugePointer.length > -1 ?
serie.runtimeInsideRadius * serie.gaugePointer.length :
serie.gaugePointer.length;
var p1 = ChartHelper.GetPosition(serie.runtimeCenterPos, currAngle, len);
var p2 = ChartHelper.GetPosition(serie.runtimeCenterPos, currAngle + 180, serie.gaugePointer.width);
var p3 = ChartHelper.GetPosition(serie.runtimeCenterPos, currAngle - 90, serie.gaugePointer.width / 2);
var p4 = ChartHelper.GetPosition(serie.runtimeCenterPos, currAngle + 90, serie.gaugePointer.width / 2);
UGL.DrawTriangle(vh, p2, p3, p1, pointerColor, pointerColor, pointerToColor);
UGL.DrawTriangle(vh, p4, p2, p1, pointerColor, pointerColor, pointerToColor);
}
private void DrawLineStyle(VertexHelper vh, Serie serie)
{
if (serie.gaugeType != GaugeType.Pointer) return;
if (!serie.gaugeAxis.show || !serie.gaugeAxis.splitLine.show) return;
if (serie.splitNumber <= 0) return;
var splitLine = serie.gaugeAxis.splitLine;
var totalAngle = serie.endAngle - serie.startAngle;
var diffAngle = totalAngle / serie.splitNumber;
var lineWidth = serie.gaugeAxis.axisLine.GetWidth(chart.theme.gauge.lineWidth);
var splitLineWidth = splitLine.GetWidth(chart.theme.gauge.splitLineWidth);
var splitLineLength = splitLine.GetLength(chart.theme.gauge.splitLineLength);
var outsideRadius = serie.runtimeInsideRadius + lineWidth;
var insideRadius = outsideRadius - splitLineLength;
for (int i = 0; i < serie.splitNumber + 1; i++)
{
var angle = serie.startAngle + i * diffAngle;
var lineColor = serie.gaugeAxis.GetSplitLineColor(chart.theme.gauge.splitLineColor, serie.index, angle);
var p1 = ChartHelper.GetPosition(serie.runtimeCenterPos, angle, insideRadius);
var p2 = ChartHelper.GetPosition(serie.runtimeCenterPos, angle, outsideRadius);
UGL.DrawLine(vh, p1, p2, splitLineWidth, lineColor);
}
}
private void DrawAxisTick(VertexHelper vh, Serie serie)
{
if (serie.gaugeType != GaugeType.Pointer) return;
if (!serie.gaugeAxis.show || !serie.gaugeAxis.axisTick.show) return;
if (serie.splitNumber <= 0) return;
var axisTick = serie.gaugeAxis.axisTick;
var totalAngle = serie.endAngle - serie.startAngle;
var diffAngle = totalAngle / serie.splitNumber;
var lineWidth = serie.gaugeAxis.axisLine.GetWidth(chart.theme.gauge.lineWidth);
var tickWidth = axisTick.GetWidth(chart.theme.gauge.tickWidth);
var tickLength = axisTick.GetLength(chart.theme.gauge.tickLength);
var outsideRadius = serie.runtimeInsideRadius + lineWidth;
var insideRadius = outsideRadius - (tickLength < 1 ? lineWidth * tickLength : tickLength);
for (int i = 0; i < serie.splitNumber; i++)
{
for (int j = 1; j < axisTick.splitNumber; j++)
{
var angle = serie.startAngle + i * diffAngle + j * (diffAngle / axisTick.splitNumber);
var lineColor = serie.gaugeAxis.GetSplitLineColor(chart.theme.gauge.tickColor, serie.index, angle);
var p1 = ChartHelper.GetPosition(serie.runtimeCenterPos, angle, insideRadius);
var p2 = ChartHelper.GetPosition(serie.runtimeCenterPos, angle, outsideRadius);
UGL.DrawLine(vh, p1, p2, tickWidth, lineColor);
}
}
}
private float GetCurrAngle(Serie serie, bool dest)
{
if (serie.animation.HasFadeOut())
{
return serie.animation.GetCurrDetail();
}
float rangeValue = serie.max - serie.min;
float rangeAngle = serie.endAngle - serie.startAngle;
float value = 0;
float angle = serie.startAngle;
if (serie.dataCount > 0)
{
var serieData = serie.data[0];
serieData.labelPosition = serie.runtimeCenterPos + serie.label.offset;
value = dest ? serieData.GetData(1)
: serieData.GetCurrData(1, serie.animation.GetUpdateAnimationDuration());
value = Mathf.Clamp(value, serie.min, serie.max);
}
if (rangeValue > 0)
{
angle += rangeAngle * value / rangeValue;
}
return angle;
}
private void CheckAnimation(Serie serie)
{
var serieData = serie.GetSerieData(0);
if (serieData != null)
{
var value = serieData.GetCurrData(1, serie.animation.GetUpdateAnimationDuration());
var data = serieData.GetData(1);
if (value != data) chart.RefreshPainter(serie);
}
}
private bool NeedRefresh(Serie serie)
{
if (serie.type == SerieType.Gauge)
{
var serieData = serie.GetSerieData(0);
if (serieData != null)
{
var destValue = serieData.GetData(1);
var currValue = serieData.GetCurrData(1, serie.animation.GetUpdateAnimationDuration());
return destValue != currValue;
}
}
return false;
}
private Serie GetPointerInSerieIndex(Series series, Vector2 local)
{
foreach (var serie in series.list)
{
if (serie.type != SerieType.Gauge) continue;
if (!serie.gaugePointer.show) continue;
var len = serie.gaugePointer.length < 1 && serie.gaugePointer.length > -1
? serie.runtimeInsideRadius * serie.gaugePointer.length
: serie.gaugePointer.length;
if (Vector3.Distance(local, serie.runtimeCenterPos) > len) continue;
var currAngle = serie.animation.IsFinish() ? GetCurrAngle(serie, false) : serie.animation.GetCurrDetail();
var p1 = ChartHelper.GetPosition(serie.runtimeCenterPos, currAngle, len);
var p2 = ChartHelper.GetPosition(serie.runtimeCenterPos, currAngle + 180, serie.gaugePointer.width);
var p3 = ChartHelper.GetPosition(serie.runtimeCenterPos, currAngle - 90, serie.gaugePointer.width / 2);
var p4 = ChartHelper.GetPosition(serie.runtimeCenterPos, currAngle + 90, serie.gaugePointer.width / 2);
if (ChartHelper.IsPointInQuadrilateral(local, p1, p3, p2, p4))
{
return serie;
}
}
return null;
}
private void UpdateTooltip()
{
int index = chart.tooltip.runtimeDataIndex[0];
if (index < 0)
{
chart.tooltip.SetActive(false);
return;
}
var content = TooltipHelper.GetFormatterContent(chart.tooltip, index, chart.series, chart.theme);
TooltipHelper.SetContentAndPosition(chart.tooltip, content.TrimStart(), chart.chartRect);
chart.tooltip.SetActive(true);
}
}
}

View File

@@ -1,5 +1,5 @@
fileFormatVersion: 2
guid: e9132f4c137015247b44450c2cb23606
guid: ca6e74d36e80c4daabf80b165986dfbb
MonoImporter:
externalObjects: {}
serializedVersion: 2

View File

@@ -0,0 +1,259 @@
/************************************************/
/* */
/* Copyright (c) 2018 - 2021 monitor1394 */
/* https://github.com/monitor1394 */
/* */
/************************************************/
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.EventSystems;
using XUGL;
namespace XCharts
{
internal class DrawSerieLiquid : IDrawSerie
{
public BaseChart chart;
private bool m_UpdateLabelText = false;
public DrawSerieLiquid(BaseChart chart)
{
this.chart = chart;
}
public void InitComponent()
{
//UpdateRuntimeData();
//SerieLabelHelper.UpdateLabelText(chart.series, chart.theme, m_LegendRealShowName);
}
public void CheckComponent()
{
}
public void Update()
{
if (m_UpdateLabelText)
{
m_UpdateLabelText = false;
foreach (var serie in chart.series.list)
{
if (serie.type == SerieType.Liquid)
{
var colorIndex = chart.m_LegendRealShowName.IndexOf(serie.name);
SerieLabelHelper.SetLiquidLabelText(serie, chart.theme, colorIndex);
}
}
}
}
public void DrawBase(VertexHelper vh)
{
}
public void DrawSerie(VertexHelper vh, Serie serie)
{
if (serie.type != SerieType.Liquid) return;
UpdateRuntimeData(serie);
DrawVesselBackground(vh, serie);
DrawLiquid(vh, serie);
DrawVessel(vh, serie);
}
public void RefreshLabel()
{
}
public bool CheckTootipArea(Vector2 local)
{
return false;
}
public bool OnLegendButtonClick(int index, string legendName, bool show)
{
return false;
}
public bool OnLegendButtonEnter(int index, string legendName)
{
return false;
}
public bool OnLegendButtonExit(int index, string legendName)
{
return false;
}
public void OnPointerDown(PointerEventData eventData)
{
}
private void UpdateRuntimeData()
{
foreach (var vessel in chart.vessels)
{
VesselHelper.UpdateVesselCenter(vessel, chart.chartPosition, chart.chartWidth, chart.chartHeight);
}
}
private void UpdateRuntimeData(Serie serie)
{
var vessel = chart.GetVessel(serie.vesselIndex);
if (vessel != null)
{
VesselHelper.UpdateVesselCenter(vessel, chart.chartPosition, chart.chartWidth, chart.chartHeight);
}
}
private void DrawVesselBackground(VertexHelper vh, Serie serie)
{
var vessel = chart.GetVessel(serie.vesselIndex);
if (vessel != null)
{
if (vessel.backgroundColor.a != 0)
{
var cenPos = vessel.runtimeCenterPos;
var radius = vessel.runtimeRadius;
UGL.DrawCricle(vh, cenPos, vessel.runtimeInnerRadius, vessel.backgroundColor, chart.settings.cicleSmoothness);
}
}
}
private void DrawVessel(VertexHelper vh, Serie serie)
{
var vessel = chart.GetVessel(serie.vesselIndex);
if (vessel != null)
{
DrawCirleVessel(vh, vessel);
}
}
private void DrawCirleVessel(VertexHelper vh, Vessel vessel)
{
var cenPos = vessel.runtimeCenterPos;
var radius = vessel.runtimeRadius;
var serie = SeriesHelper.GetSerieByVesselIndex(chart.series, vessel.index);
var vesselColor = VesselHelper.GetColor(vessel, serie, chart.theme, chart.m_LegendRealShowName);
UGL.DrawDoughnut(vh, cenPos, radius - vessel.shapeWidth, radius, vesselColor, Color.clear, chart.settings.cicleSmoothness);
}
private void DrawLiquid(VertexHelper vh, Serie serie)
{
if (!serie.show) return;
if (serie.animation.HasFadeOut()) return;
var vessel = chart.GetVessel(serie.vesselIndex);
if (vessel == null) return;
var cenPos = vessel.runtimeCenterPos;
var radius = vessel.runtimeInnerRadius;
var serieData = serie.GetSerieData(0);
if (serieData == null) return;
var dataChangeDuration = serie.animation.GetUpdateAnimationDuration();
var value = serieData.GetCurrData(1, dataChangeDuration);
if (serie.runtimeCheckValue != value)
{
serie.runtimeCheckValue = value;
m_UpdateLabelText = true;
}
if (serieData.labelPosition != cenPos)
{
serieData.labelPosition = cenPos;
m_UpdateLabelText = true;
}
if (value == 0) return;
var colorIndex = chart.m_LegendRealShowName.IndexOf(serie.name);
var realHig = (value - serie.min) / (serie.max - serie.min) * radius * 2;
serie.animation.InitProgress(1, 0, realHig);
var hig = serie.animation.IsFinish() ? realHig : serie.animation.GetCurrDetail();
var a = Mathf.Abs(radius - hig + (hig > radius ? serie.waveHeight : -serie.waveHeight));
var diff = Mathf.Sqrt(radius * radius - Mathf.Pow(a, 2));
var color = SerieHelper.GetItemColor(serie, serieData, chart.theme, colorIndex, false);
var toColor = SerieHelper.GetItemToColor(serie, serieData, chart.theme, colorIndex, false);
var isNeedGradient = !ChartHelper.IsValueEqualsColor(color, toColor);
var isFull = hig >= 2 * radius;
if (hig >= 2 * radius) hig = 2 * radius;
if (isFull && !isNeedGradient)
{
UGL.DrawCricle(vh, cenPos, radius, toColor, chart.settings.cicleSmoothness);
}
else
{
var startY = cenPos.y - radius + hig;
var waveStartPos = new Vector3(cenPos.x - diff, startY);
var waveEndPos = new Vector3(cenPos.x + diff, startY);
var startX = hig > radius ? cenPos.x - radius : waveStartPos.x;
var endX = hig > radius ? cenPos.x + radius : waveEndPos.x;
var step = vessel.smoothness;
if (step < 0.5f) step = 0.5f;
var lup = hig > radius ? new Vector3(cenPos.x - radius, cenPos.y) : waveStartPos;
var ldp = lup;
var nup = Vector3.zero;
var ndp = Vector3.zero;
var angle = 0f;
serie.runtimeWaveSpeed += serie.waveSpeed * Time.deltaTime;
var isStarted = false;
var isEnded = false;
var waveHeight = isFull ? 0 : serie.waveHeight;
while (startX < endX)
{
startX += step;
if (startX > endX) startX = endX;
if (startX > waveStartPos.x && !isStarted)
{
startX = waveStartPos.x;
isStarted = true;
}
if (startX > waveEndPos.x && !isEnded)
{
startX = waveEndPos.x;
isEnded = true;
}
var py = Mathf.Sqrt(Mathf.Pow(radius, 2) - Mathf.Pow(Mathf.Abs(cenPos.x - startX), 2));
if (startX < waveStartPos.x || startX > waveEndPos.x)
{
nup = new Vector3(startX, cenPos.y + py);
}
else
{
var py2 = waveHeight * Mathf.Sin(1 / serie.waveLength * angle + serie.runtimeWaveSpeed + serie.waveOffset);
var nupY = waveStartPos.y + py2;
if (nupY > cenPos.y + py) nupY = cenPos.y + py;
else if (nupY < cenPos.y - py) nupY = cenPos.y - py;
nup = new Vector3(startX, nupY);
angle += step;
}
ndp = new Vector3(startX, cenPos.y - py);
if (!ChartHelper.IsValueEqualsColor(color, toColor))
{
var colorMin = cenPos.y - radius;
var colorMax = startY + serie.waveHeight;
var tcolor1 = Color32.Lerp(color, toColor, 1 - (lup.y - colorMin) / (colorMax - colorMin));
var tcolor2 = Color32.Lerp(color, toColor, 1 - (ldp.y - colorMin) / (colorMax - colorMin));
UGL.DrawQuadrilateral(vh, lup, nup, ndp, ldp, tcolor1, tcolor2);
}
else
{
UGL.DrawQuadrilateral(vh, lup, nup, ndp, ldp, color);
}
lup = nup;
ldp = ndp;
}
}
if (serie.waveSpeed != 0 && Application.isPlaying && !isFull)
{
chart.RefreshPainter(serie);
}
if (!serie.animation.IsFinish())
{
serie.animation.CheckProgress(realHig);
chart.m_IsPlayingAnimation = true;
chart.RefreshPainter(serie);
}
}
}
}

View File

@@ -1,5 +1,5 @@
fileFormatVersion: 2
guid: 62abeafe2ed4141d69bdb9ad76c02e41
guid: 5e68718d39a3042ffb8162149246ef5e
MonoImporter:
externalObjects: {}
serializedVersion: 2

View File

@@ -0,0 +1,559 @@
/************************************************/
/* */
/* Copyright (c) 2018 - 2021 monitor1394 */
/* https://github.com/monitor1394 */
/* */
/************************************************/
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.EventSystems;
using XUGL;
namespace XCharts
{
internal class DrawSeriePie : IDrawSerie
{
public BaseChart chart;
protected bool m_IsEnterPieLegendButtom;
public DrawSeriePie(BaseChart chart)
{
this.chart = chart;
}
public void InitComponent()
{
}
public void CheckComponent()
{
}
public void Update()
{
}
public void DrawBase(VertexHelper vh)
{
}
public void DrawSerie(VertexHelper vh, Serie serie)
{
if (serie.type != SerieType.Pie) return;
UpdateRuntimeData(serie);
DrawPieLabelLine(vh, serie);
DrawPie(vh, serie);
DrawPieLabelBackground(vh, serie);
}
public void RefreshLabel()
{
int serieNameCount = -1;
for (int i = 0; i < chart.series.Count; i++)
{
var serie = chart.series.list[i];
serie.index = i;
if (!serie.show || serie.type != SerieType.Pie) continue;
var data = serie.data;
for (int n = 0; n < data.Count; n++)
{
var serieData = data[n];
if (!serieData.canShowLabel || serie.IsIgnoreValue(serieData.GetData(1)))
{
serieData.SetLabelActive(false);
continue;
}
if (!serieData.show) continue;
serieNameCount = chart.m_LegendRealShowName.IndexOf(serieData.name);
Color color = chart.theme.GetColor(serieNameCount);
DrawPieLabel(serie, n, serieData, color);
}
}
}
public bool CheckTootipArea(Vector2 local)
{
if (!PointerIsInPieSerie(chart.series, local)) return false;
bool selected = false;
chart.tooltip.runtimeDataIndex.Clear();
foreach (var serie in chart.series.list)
{
int index = GetPiePosIndex(serie, local);
chart.tooltip.runtimeDataIndex.Add(index);
if (serie.type != SerieType.Pie) continue;
bool refresh = false;
for (int j = 0; j < serie.data.Count; j++)
{
var serieData = serie.data[j];
if (serieData.highlighted != (j == index)) refresh = true;
serieData.highlighted = j == index;
}
if (index >= 0) selected = true;
if (refresh) chart.RefreshChart();
}
if (selected)
{
chart.tooltip.UpdateContentPos(local + chart.tooltip.offset);
UpdatePieTooltip();
}
else if (chart.tooltip.IsActive())
{
chart.tooltip.SetActive(false);
chart.RefreshChart();
}
return true;
}
public bool OnLegendButtonClick(int index, string legendName, bool show)
{
if (!SeriesHelper.ContainsSerie(chart.series, SerieType.Pie)) return false;
if (!LegendHelper.IsSerieLegend(chart.series, legendName, SerieType.Pie)) return false;
LegendHelper.CheckDataShow(chart.series, legendName, show);
chart.UpdateLegendColor(legendName, show);
chart.RefreshChart();
return true;
}
public bool OnLegendButtonEnter(int index, string legendName)
{
if (!SeriesHelper.ContainsSerie(chart.series, SerieType.Pie)) return false;
if (!LegendHelper.IsSerieLegend(chart.series, legendName, SerieType.Pie)) return false;
m_IsEnterPieLegendButtom = true;
LegendHelper.CheckDataHighlighted(chart.series, legendName, true);
chart.RefreshChart();
return true;
}
public bool OnLegendButtonExit(int index, string legendName)
{
if (!SeriesHelper.ContainsSerie(chart.series, SerieType.Pie)) return false;
if (!LegendHelper.IsSerieLegend(chart.series, legendName, SerieType.Pie)) return false;
m_IsEnterPieLegendButtom = false;
LegendHelper.CheckDataHighlighted(chart.series, legendName, false);
chart.RefreshChart();
return true;
}
public void OnPointerDown(PointerEventData eventData)
{
if (!SeriesHelper.ContainsSerie(chart.series, SerieType.Pie)) return;
if (chart.pointerPos == Vector2.zero) return;
var refresh = false;
for (int i = 0; i < chart.series.Count; i++)
{
var serie = chart.series.GetSerie(i);
if (serie.type != SerieType.Pie) continue;
var index = GetPiePosIndex(serie, chart.pointerPos);
if (index >= 0)
{
refresh = true;
for (int j = 0; j < serie.data.Count; j++)
{
if (j == index) serie.data[j].selected = !serie.data[j].selected;
else serie.data[j].selected = false;
}
if (chart.onPointerClickPie != null)
{
chart.onPointerClickPie(eventData, i, index);
}
}
}
if (refresh) chart.RefreshChart();
}
private void UpdateRuntimeData(Serie serie)
{
var data = serie.data;
serie.runtimeDataMax = serie.yMax;
serie.runtimePieDataTotal = serie.yTotal;
serie.animation.InitProgress(data.Count, 0, 360);
SerieHelper.UpdateCenter(serie, chart.chartPosition, chart.chartWidth, chart.chartHeight);
float totalDegree = 360f;
float startDegree = 0;
int showdataCount = 0;
foreach (var sd in serie.data)
{
if (sd.show && serie.pieRoseType == RoseType.Area) showdataCount++;
sd.canShowLabel = false;
}
float dataChangeDuration = serie.animation.GetUpdateAnimationDuration();
bool isAllZeroValue = SerieHelper.IsAllZeroValue(serie, 1);
float zeroReplaceValue = totalDegree / data.Count;
if (isAllZeroValue)
{
serie.runtimeDataMax = zeroReplaceValue;
serie.runtimePieDataTotal = totalDegree;
}
for (int n = 0; n < data.Count; n++)
{
var serieData = data[n];
serieData.index = n;
float value = isAllZeroValue ? zeroReplaceValue : serieData.GetCurrData(1, dataChangeDuration);
serieData.runtimePieStartAngle = startDegree;
serieData.runtimePieToAngle = startDegree;
serieData.runtimePieHalfAngle = startDegree;
serieData.runtimePieCurrAngle = startDegree;
if (!serieData.show)
{
continue;
}
float degree = serie.pieRoseType == RoseType.Area ?
(totalDegree / showdataCount) : (totalDegree * value / serie.runtimePieDataTotal);
serieData.runtimePieToAngle = startDegree + degree;
serieData.runtimePieOutsideRadius = serie.pieRoseType > 0 ?
serie.runtimeInsideRadius + (serie.runtimeOutsideRadius - serie.runtimeInsideRadius) * value / serie.runtimeDataMax :
serie.runtimeOutsideRadius;
if (serieData.highlighted)
{
serieData.runtimePieOutsideRadius += chart.theme.serie.pieTooltipExtraRadius;
}
var offset = 0f;
if (serie.pieClickOffset && serieData.selected)
{
offset += chart.theme.serie.pieSelectedOffset;
}
if (serie.animation.CheckDetailBreak(serieData.runtimePieToAngle))
{
serieData.runtimePieCurrAngle = serie.animation.GetCurrDetail();
}
else
{
serieData.runtimePieCurrAngle = serieData.runtimePieToAngle;
}
var halfDegree = (serieData.runtimePieToAngle - startDegree) / 2;
serieData.runtimePieHalfAngle = startDegree + halfDegree;
serieData.runtiemPieOffsetCenter = serie.runtimeCenterPos;
serieData.runtimePieInsideRadius = serie.runtimeInsideRadius;
if (offset > 0)
{
var currRad = serieData.runtimePieHalfAngle * Mathf.Deg2Rad;
var currSin = Mathf.Sin(currRad);
var currCos = Mathf.Cos(currRad);
serieData.runtimePieOffsetRadius = 0;
serieData.runtimePieInsideRadius -= serieData.runtimePieOffsetRadius;
serieData.runtimePieOutsideRadius -= serieData.runtimePieOffsetRadius;
if (serie.pieClickOffset && serieData.selected)
{
serieData.runtimePieOffsetRadius += chart.theme.serie.pieSelectedOffset;
if (serieData.runtimePieInsideRadius > 0) serieData.runtimePieInsideRadius += chart.theme.serie.pieSelectedOffset;
serieData.runtimePieOutsideRadius += chart.theme.serie.pieSelectedOffset;
}
serieData.runtiemPieOffsetCenter = new Vector3(serie.runtimeCenterPos.x + serieData.runtimePieOffsetRadius * currSin,
serie.runtimeCenterPos.y + serieData.runtimePieOffsetRadius * currCos);
}
serieData.canShowLabel = serieData.runtimePieCurrAngle >= serieData.runtimePieHalfAngle;
startDegree = serieData.runtimePieToAngle;
SerieLabelHelper.UpdatePieLabelPosition(serie, serieData);
}
SerieLabelHelper.AvoidLabelOverlap(serie);
}
private void DrawPieCenter(VertexHelper vh, Serie serie, ItemStyle itemStyle, float insideRadius)
{
if (!ChartHelper.IsClearColor(itemStyle.centerColor))
{
var radius = insideRadius - itemStyle.centerGap;
UGL.DrawCricle(vh, serie.runtimeCenterPos, radius, itemStyle.centerColor, chart.settings.cicleSmoothness);
}
}
private void DrawPie(VertexHelper vh, Serie serie)
{
var data = serie.data;
serie.animation.InitProgress(data.Count, 0, 360);
if (!serie.show || serie.animation.HasFadeOut())
{
return;
}
bool dataChanging = false;
for (int n = 0; n < data.Count; n++)
{
var serieData = data[n];
if (!serieData.show)
{
continue;
}
var itemStyle = SerieHelper.GetItemStyle(serie, serieData, serieData.highlighted);
if (serieData.IsDataChanged()) dataChanging = true;
var serieNameCount = chart.m_LegendRealShowName.IndexOf(serieData.legendName);
var color = SerieHelper.GetItemColor(serie, serieData, chart.theme, serieNameCount, serieData.highlighted);
var toColor = SerieHelper.GetItemToColor(serie, serieData, chart.theme, serieNameCount, serieData.highlighted);
var borderWidth = itemStyle.borderWidth;
var borderColor = itemStyle.borderColor;
if (serie.pieClickOffset && serieData.selected)
{
var drawEndDegree = serieData.runtimePieCurrAngle;
var needRoundCap = serie.roundCap && serieData.runtimePieInsideRadius > 0;
UGL.DrawDoughnut(vh, serieData.runtiemPieOffsetCenter, serieData.runtimePieInsideRadius,
serieData.runtimePieOutsideRadius, color, toColor, Color.clear, serieData.runtimePieStartAngle, drawEndDegree,
borderWidth, borderColor, serie.pieSpace / 2, chart.settings.cicleSmoothness, needRoundCap, true);
}
else
{
var drawEndDegree = serieData.runtimePieCurrAngle;
var needRoundCap = serie.roundCap && serieData.runtimePieInsideRadius > 0;
UGL.DrawDoughnut(vh, serie.runtimeCenterPos, serieData.runtimePieInsideRadius, serieData.runtimePieOutsideRadius,
color, toColor, Color.clear, serieData.runtimePieStartAngle, drawEndDegree, borderWidth, borderColor, serie.pieSpace / 2,
chart.settings.cicleSmoothness, needRoundCap, true);
DrawPieCenter(vh, serie, itemStyle, serieData.runtimePieInsideRadius);
}
if (!serie.animation.CheckDetailBreak(serieData.runtimePieToAngle)) serie.animation.SetDataFinish(n);
else break;
}
if (!serie.animation.IsFinish())
{
serie.animation.CheckProgress(360);
serie.animation.CheckSymbol(serie.symbol.GetSize(null, chart.theme.serie.lineSymbolSize));
chart.RefreshPainter(serie);
}
if (dataChanging)
{
chart.RefreshPainter(serie);
}
chart.raycastTarget = IsAnyPieClickOffset() || IsAnyPieDataHighlight();
}
private bool IsAnyPieClickOffset()
{
foreach (var serie in chart.series.list)
{
if (serie.type == SerieType.Pie && serie.pieClickOffset) return true;
}
return false;
}
private bool IsAnyPieDataHighlight()
{
foreach (var serie in chart.series.list)
{
if (serie.type == SerieType.Pie)
{
foreach (var serieData in serie.data)
{
if (serieData.highlighted) return true;
}
}
}
return false;
}
private void DrawPieLabelLine(VertexHelper vh, Serie serie)
{
foreach (var serieData in serie.data)
{
var serieLabel = SerieHelper.GetSerieLabel(serie, serieData);
if (SerieLabelHelper.CanShowLabel(serie, serieData, serieLabel, 1))
{
int colorIndex = chart.m_LegendRealShowName.IndexOf(serieData.name);
Color color = chart.theme.GetColor(colorIndex);
DrawPieLabelLine(vh, serie, serieData, color);
}
}
}
private void DrawPieLabelBackground(VertexHelper vh, Serie serie)
{
if (serie.avoidLabelOverlap) return;
foreach (var serieData in serie.data)
{
var serieLabel = SerieHelper.GetSerieLabel(serie, serieData);
if (SerieLabelHelper.CanShowLabel(serie, serieData, serieLabel, 1))
{
SerieLabelHelper.UpdatePieLabelPosition(serie, serieData);
chart.DrawLabelBackground(vh, serie, serieData);
}
}
}
private void DrawPieLabelLine(VertexHelper vh, Serie serie, SerieData serieData, Color color)
{
var serieLabel = SerieHelper.GetSerieLabel(serie, serieData);
if (serieLabel.show
&& serieLabel.position == SerieLabel.Position.Outside
&& serieLabel.line)
{
var insideRadius = serieData.runtimePieInsideRadius;
var outSideRadius = serieData.runtimePieOutsideRadius;
var center = serie.runtimeCenterPos;
var currAngle = serieData.runtimePieHalfAngle;
if (!ChartHelper.IsClearColor(serieLabel.lineColor)) color = serieLabel.lineColor;
else if (serieLabel.lineType == SerieLabel.LineType.HorizontalLine) color *= color;
float currSin = Mathf.Sin(currAngle * Mathf.Deg2Rad);
float currCos = Mathf.Cos(currAngle * Mathf.Deg2Rad);
var radius1 = serieLabel.lineType == SerieLabel.LineType.HorizontalLine ?
serie.runtimeOutsideRadius : outSideRadius;
var radius2 = serie.runtimeOutsideRadius + serieLabel.lineLength1;
var radius3 = insideRadius + (outSideRadius - insideRadius) / 2;
if (radius1 < serie.runtimeInsideRadius) radius1 = serie.runtimeInsideRadius;
radius1 -= 0.1f;
var pos0 = new Vector3(center.x + radius3 * currSin, center.y + radius3 * currCos);
var pos1 = new Vector3(center.x + radius1 * currSin, center.y + radius1 * currCos);
var pos2 = serieData.labelPosition;
if (pos2.x == 0)
{
pos2 = new Vector3(center.x + radius2 * currSin, center.y + radius2 * currCos);
}
Vector3 pos4, pos6;
var horizontalLineCircleRadius = serieLabel.lineWidth * 4f;
var lineCircleDiff = horizontalLineCircleRadius - 0.3f;
if (currAngle < 90)
{
var r4 = Mathf.Sqrt(radius1 * radius1 - Mathf.Pow(currCos * radius3, 2)) - currSin * radius3;
r4 += serieLabel.lineLength1 - lineCircleDiff;
pos6 = pos0 + Vector3.right * lineCircleDiff;
pos4 = pos6 + Vector3.right * r4;
}
else if (currAngle < 180)
{
var r4 = Mathf.Sqrt(radius1 * radius1 - Mathf.Pow(currCos * radius3, 2)) - currSin * radius3;
r4 += serieLabel.lineLength1 - lineCircleDiff;
pos6 = pos0 + Vector3.right * lineCircleDiff;
pos4 = pos6 + Vector3.right * r4;
}
else if (currAngle < 270)
{
var currSin1 = Mathf.Sin((360 - currAngle) * Mathf.Deg2Rad);
var currCos1 = Mathf.Cos((360 - currAngle) * Mathf.Deg2Rad);
var r4 = Mathf.Sqrt(radius1 * radius1 - Mathf.Pow(currCos1 * radius3, 2)) - currSin1 * radius3;
r4 += serieLabel.lineLength1 - lineCircleDiff;
pos6 = pos0 + Vector3.left * lineCircleDiff;
pos4 = pos6 + Vector3.left * r4;
}
else
{
var currSin1 = Mathf.Sin((360 - currAngle) * Mathf.Deg2Rad);
var currCos1 = Mathf.Cos((360 - currAngle) * Mathf.Deg2Rad);
var r4 = Mathf.Sqrt(radius1 * radius1 - Mathf.Pow(currCos1 * radius3, 2)) - currSin1 * radius3;
r4 += serieLabel.lineLength1 - lineCircleDiff;
pos6 = pos0 + Vector3.left * lineCircleDiff;
pos4 = pos6 + Vector3.left * r4;
}
var pos5 = new Vector3(currAngle > 180 ? pos2.x - serieLabel.lineLength2 : pos2.x + serieLabel.lineLength2, pos2.y);
switch (serieLabel.lineType)
{
case SerieLabel.LineType.BrokenLine:
UGL.DrawLine(vh, pos1, pos2, pos5, serieLabel.lineWidth, color);
break;
case SerieLabel.LineType.Curves:
UGL.DrawCurves(vh, pos1, pos5, pos1, pos2, serieLabel.lineWidth, color, chart.settings.lineSmoothness);
break;
case SerieLabel.LineType.HorizontalLine:
UGL.DrawCricle(vh, pos0, horizontalLineCircleRadius, color);
UGL.DrawLine(vh, pos6, pos4, serieLabel.lineWidth, color);
break;
}
}
}
private void DrawPieLabel(Serie serie, int dataIndex, SerieData serieData, Color serieColor)
{
if (serieData.labelObject == null) return;
var currAngle = serieData.runtimePieHalfAngle;
var isHighlight = (serieData.highlighted && serie.emphasis.label.show);
var serieLabel = SerieHelper.GetSerieLabel(serie, serieData);
var showLabel = ((serieLabel.show || isHighlight) && serieData.canShowLabel);
if (showLabel || serieData.iconStyle.show)
{
serieData.SetLabelActive(showLabel);
float rotate = 0;
bool isInsidePosition = serieLabel.position == SerieLabel.Position.Inside;
if (serieLabel.textStyle.rotate > 0 && isInsidePosition)
{
if (currAngle > 180) rotate += 270 - currAngle;
else rotate += -(currAngle - 90);
}
Color color = serieColor;
if (isHighlight)
{
if (!ChartHelper.IsClearColor(serie.emphasis.label.textStyle.color)) color = serie.emphasis.label.textStyle.color;
}
else if (!ChartHelper.IsClearColor(serieLabel.textStyle.color))
{
color = serieLabel.textStyle.color;
}
else
{
color = isInsidePosition ? Color.white : serieColor;
}
var fontSize = isHighlight
? serie.emphasis.label.textStyle.GetFontSize(chart.theme.common)
: serieLabel.textStyle.GetFontSize(chart.theme.common);
var fontStyle = isHighlight ? serie.emphasis.label.textStyle.fontStyle : serieLabel.textStyle.fontStyle;
serieData.labelObject.label.SetColor(color);
serieData.labelObject.label.SetFontSize(fontSize);
serieData.labelObject.label.SetFontStyle(fontStyle);
serieData.labelObject.SetLabelRotate(rotate);
if (!string.IsNullOrEmpty(serieLabel.formatter))
{
var value = serieData.data[1];
var total = serie.yTotal;
var content = SerieLabelHelper.GetFormatterContent(serie, serieData, value, total, serieLabel);
if (serieData.labelObject.SetText(content)) chart.RefreshPainter(serie);
}
else
{
if (serieData.labelObject.SetText(serieData.name)) chart.RefreshPainter(serie);
}
serieData.labelObject.SetPosition(SerieLabelHelper.GetRealLabelPosition(serieData, serieLabel));
if (showLabel) serieData.labelObject.SetLabelPosition(serieLabel.offset);
else serieData.SetLabelActive(false);
}
else
{
serieData.SetLabelActive(false);
}
serieData.labelObject.UpdateIcon(serieData.iconStyle);
}
protected int GetPiePosIndex(Serie serie, Vector2 local)
{
if (serie.type != SerieType.Pie) return -1;
var dist = Vector2.Distance(local, serie.runtimeCenterPos);
if (dist < serie.runtimeInsideRadius || dist > serie.runtimeOutsideRadius) return -1;
Vector2 dir = local - new Vector2(serie.runtimeCenterPos.x, serie.runtimeCenterPos.y);
float angle = ChartHelper.GetAngle360(Vector2.up, dir);
for (int i = 0; i < serie.data.Count; i++)
{
var serieData = serie.data[i];
if (angle >= serieData.runtimePieStartAngle && angle <= serieData.runtimePieToAngle)
{
return i;
}
}
return -1;
}
private bool PointerIsInPieSerie(Series series, Vector2 local)
{
foreach (var serie in series.list)
{
if (serie.type != SerieType.Pie) continue;
var dist = Vector2.Distance(local, serie.runtimeCenterPos);
if (dist >= serie.runtimeInsideRadius && dist <= serie.runtimeOutsideRadius) return true;
}
return false;
}
protected void UpdatePieTooltip()
{
bool showTooltip = false;
foreach (var serie in chart.series.list)
{
int index = chart.tooltip.runtimeDataIndex[serie.index];
if (index < 0) continue;
showTooltip = true;
var content = TooltipHelper.GetFormatterContent(chart.tooltip, index, chart.series, chart.theme);
TooltipHelper.SetContentAndPosition(chart.tooltip, content.TrimStart(), chart.chartRect);
}
chart.tooltip.SetActive(showTooltip);
}
}
}

View File

@@ -1,5 +1,5 @@
fileFormatVersion: 2
guid: 1277b7528331b42cfb61da7a2c762bee
guid: d5fa46fc54af9401796fc8691221e526
MonoImporter:
externalObjects: {}
serializedVersion: 2

View File

@@ -0,0 +1,762 @@
/************************************************/
/* */
/* Copyright (c) 2018 - 2021 monitor1394 */
/* https://github.com/monitor1394 */
/* */
/************************************************/
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.EventSystems;
using XUGL;
using System.Collections.Generic;
namespace XCharts
{
internal class DrawSerieRadar : IDrawSerie
{
public BaseChart chart;
private const string INDICATOR_TEXT = "indicator";
private bool m_IsEnterLegendButtom;
private bool m_RadarsDirty;
Dictionary<string, int> serieNameSet = new Dictionary<string, int>();
public DrawSerieRadar(BaseChart chart)
{
this.chart = chart;
}
public void InitComponent()
{
InitIndicator();
}
public void CheckComponent()
{
var anyDirty = IsAnyRadarDirty();
if (m_RadarsDirty || anyDirty)
{
InitIndicator();
chart.RefreshBasePainter();
chart.tooltip.UpdateToTop();
if (anyDirty)
{
foreach (var radar in chart.radars)
{
radar.ClearDirty();
}
}
m_RadarsDirty = false;
}
}
public void Update()
{
}
public void DrawBase(VertexHelper vh)
{
serieNameSet.Clear();
for (int i = 0; i < chart.radars.Count; i++)
{
var radar = chart.radars[i];
if (!radar.show) continue;
radar.index = i;
radar.UpdateRadarCenter(chart.chartPosition, chart.chartWidth, chart.chartHeight);
if (radar.shape == Radar.Shape.Circle)
{
DrawCricleRadar(vh, radar);
}
else
{
DrawRadar(vh, radar);
}
}
}
public void DrawSerie(VertexHelper vh, Serie serie)
{
if (serie.type != SerieType.Radar) return;
if (!serie.show) return;
switch (serie.radarType)
{
case RadarType.Multiple:
DrawMutipleRadar(vh, serie, serie.index);
break;
case RadarType.Single:
DrawSingleRadar(vh, serie, serie.index);
break;
}
}
public void RefreshLabel()
{
for (int i = 0; i < chart.series.Count; i++)
{
var serie = chart.series.GetSerie(i);
if (serie.type != SerieType.Radar) continue;
if (!serie.show && serie.radarType != RadarType.Single) continue;
var radar = chart.GetRadar(serie.radarIndex);
if (radar == null) continue;
var center = radar.runtimeCenterPos;
for (int n = 0; n < serie.dataCount; n++)
{
var serieData = serie.data[n];
if (serieData.labelObject == null) continue;
var serieLabel = SerieHelper.GetSerieLabel(serie, serieData);
var labelPos = serieData.labelPosition;
if (serieLabel.margin != 0)
{
labelPos += serieLabel.margin * (labelPos - center).normalized;
}
serieData.labelObject.SetPosition(labelPos);
serieData.labelObject.UpdateIcon(serieData.iconStyle);
if (serie.show && serieLabel.show && serieData.canShowLabel)
{
var value = serieData.GetCurrData(1);
var max = radar.GetIndicatorMax(n);
SerieLabelHelper.ResetLabel(serieData, serieLabel, chart.theme, i);
serieData.SetLabelActive(serieData.labelPosition != Vector3.zero);
serieData.labelObject.SetLabelPosition(serieLabel.offset);
var content = SerieLabelHelper.GetFormatterContent(serie, serieData, value, max, serieLabel);
if (serieData.labelObject.SetText(content))
{
chart.RefreshPainter(serie);
}
}
else
{
serieData.SetLabelActive(false);
}
}
}
}
public bool CheckTootipArea(Vector2 local)
{
if (m_IsEnterLegendButtom) return false;
if (!IsInRadar(local)) return false;
bool highlight = false;
chart.tooltip.ClearValue();
for (int i = 0; i < chart.series.Count; i++)
{
var serie = chart.series.GetSerie(i);
if (!serie.show || serie.type != SerieType.Radar) continue;
var radar = chart.radars[serie.radarIndex];
var dist = Vector2.Distance(radar.runtimeCenterPos, local);
if (dist > radar.runtimeRadius + serie.symbol.GetSize(null, chart.theme.serie.lineSymbolSize))
{
continue;
}
switch (serie.radarType)
{
case RadarType.Multiple:
for (int n = 0; n < serie.data.Count; n++)
{
var posKey = i * 1000 + n;
if (radar.runtimeDataPosList.ContainsKey(posKey))
{
var posList = radar.runtimeDataPosList[posKey];
var symbolSize = serie.symbol.GetSize(serie.data[n].data, chart.theme.serie.lineSymbolSize);
for (int k = 0; k < posList.Count; k++)
{
if (Vector2.Distance(posList[k], local) <= symbolSize * 1.3f)
{
chart.tooltip.runtimeDataIndex[0] = i;
chart.tooltip.runtimeDataIndex[1] = n;
if (chart.tooltip.runtimeDataIndex.Count >= 3)
chart.tooltip.runtimeDataIndex[2] = k;
else
chart.tooltip.runtimeDataIndex.Add(k);
highlight = true;
break;
}
}
}
}
break;
case RadarType.Single:
for (int n = 0; n < serie.data.Count; n++)
{
var serieData = serie.data[n];
var symbolSize = serie.symbol.GetSize(serie.data[n].data, chart.theme.serie.lineSymbolSize);
if (Vector2.Distance(serieData.labelPosition, local) <= symbolSize * 1.3f)
{
chart.tooltip.runtimeDataIndex[0] = i;
chart.tooltip.runtimeDataIndex[1] = n;
highlight = true;
break;
}
}
break;
}
}
if (!highlight)
{
if (chart.tooltip.IsActive())
{
chart.tooltip.SetActive(false);
chart.RefreshChart();
}
}
else
{
chart.tooltip.UpdateContentPos(local + chart.tooltip.offset);
UpdateTooltip();
chart.RefreshChart();
}
return highlight;
}
public bool OnLegendButtonClick(int index, string legendName, bool show)
{
if (!SeriesHelper.ContainsSerie(chart.series, SerieType.Radar)) return false;
if (!LegendHelper.IsSerieLegend(chart.series, legendName, SerieType.Radar)) return false;
LegendHelper.CheckDataShow(chart.series, legendName, show);
chart.UpdateLegendColor(legendName, show);
chart.RefreshChart();
return true;
}
public bool OnLegendButtonEnter(int index, string legendName)
{
if (!SeriesHelper.ContainsSerie(chart.series, SerieType.Radar)) return false;
if (!LegendHelper.IsSerieLegend(chart.series, legendName, SerieType.Radar)) return false;
m_IsEnterLegendButtom = true;
LegendHelper.CheckDataHighlighted(chart.series, legendName, true);
chart.RefreshChart();
return true;
}
public bool OnLegendButtonExit(int index, string legendName)
{
if (!SeriesHelper.ContainsSerie(chart.series, SerieType.Radar)) return false;
if (!LegendHelper.IsSerieLegend(chart.series, legendName, SerieType.Radar)) return false;
m_IsEnterLegendButtom = false;
LegendHelper.CheckDataHighlighted(chart.series, legendName, false);
chart.RefreshChart();
return true;
}
public void OnPointerDown(PointerEventData eventData)
{
}
private void InitIndicator()
{
ChartHelper.HideAllObject(chart.transform, INDICATOR_TEXT);
for (int n = 0; n < chart.radars.Count; n++)
{
Radar radar = chart.radars[n];
radar.UpdateRadarCenter(chart.chartPosition, chart.chartWidth, chart.chartHeight);
int indicatorNum = radar.indicatorList.Count;
float txtWid = 100;
float txtHig = 20;
for (int i = 0; i < indicatorNum; i++)
{
var indicator = radar.indicatorList[i];
var pos = radar.GetIndicatorPosition(i);
var textStyle = indicator.textStyle;
var objName = INDICATOR_TEXT + "_" + n + "_" + i;
var txt = ChartHelper.AddTextObject(objName, chart.transform, new Vector2(0.5f, 0.5f),
new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f), new Vector2(txtWid, txtHig),
textStyle, chart.theme.radar);
txt.gameObject.hideFlags = chart.chartHideFlags;
txt.SetAlignment(TextAnchor.MiddleCenter);
txt.SetText(radar.indicatorList[i].name);
txt.SetActive(radar.indicator);
var offset = new Vector3(textStyle.offset.x, textStyle.offset.y);
AxisHelper.AdjustCircleLabelPos(txt, pos, radar.runtimeCenterPos, txtHig, offset);
}
}
}
private void DrawMutipleRadar(VertexHelper vh, Serie serie, int i)
{
if (!serie.show) return;
var radar = chart.GetRadar(serie.radarIndex);
if (radar == null) return;
var startPoint = Vector3.zero;
var toPoint = Vector3.zero;
var firstPoint = Vector3.zero;
var indicatorNum = radar.indicatorList.Count;
var angle = 2 * Mathf.PI / indicatorNum;
var centerPos = radar.runtimeCenterPos;
var serieNameCount = -1;
serie.animation.InitProgress(1, 0, 1);
if (!chart.IsActive(i) || serie.animation.HasFadeOut())
{
return;
}
var rate = serie.animation.GetCurrRate();
var dataChanging = false;
var dataChangeDuration = serie.animation.GetUpdateAnimationDuration();
SerieHelper.GetAllMinMaxData(serie, radar.ceilRate);
for (int j = 0; j < serie.data.Count; j++)
{
var serieData = serie.data[j];
int key = i * 1000 + j;
if (!radar.runtimeDataPosList.ContainsKey(key))
{
radar.runtimeDataPosList.Add(i * 1000 + j, new List<Vector3>(serieData.data.Count));
}
else
{
radar.runtimeDataPosList[key].Clear();
}
string dataName = serieData.name;
int serieIndex = 0;
if (string.IsNullOrEmpty(dataName))
{
serieNameCount++;
serieIndex = serieNameCount;
}
else if (!serieNameSet.ContainsKey(dataName))
{
serieNameSet.Add(dataName, serieNameCount);
serieNameCount++;
serieIndex = serieNameCount;
}
else
{
serieIndex = serieNameSet[dataName];
}
if (!serieData.show)
{
continue;
}
var isHighlight = IsHighlight(radar, serie, serieData, j, 0);
var areaColor = SerieHelper.GetAreaColor(serie, chart.theme, serieIndex, isHighlight);
var areaToColor = SerieHelper.GetAreaToColor(serie, chart.theme, serieIndex, isHighlight);
var lineColor = SerieHelper.GetLineColor(serie, chart.theme, serieIndex, isHighlight);
var lineWidth = serie.lineStyle.GetWidth(chart.theme.serie.lineWidth);
int dataCount = radar.indicatorList.Count;
List<Vector3> pointList = radar.runtimeDataPosList[key];
for (int n = 0; n < dataCount; n++)
{
if (n >= serieData.data.Count) break;
float max = radar.GetIndicatorMax(n);
float value = serieData.GetCurrData(n, dataChangeDuration);
if (serieData.IsDataChanged()) dataChanging = true;
if (max == 0)
{
max = serie.runtimeDataMax;
}
var radius = max < 0 ? radar.runtimeDataRadius - radar.runtimeDataRadius * value / max
: radar.runtimeDataRadius * value / max;
var currAngle = (n + (radar.positionType == Radar.PositionType.Between ? 0.5f : 0)) * angle;
radius *= rate;
if (n == 0)
{
startPoint = new Vector3(centerPos.x + radius * Mathf.Sin(currAngle),
centerPos.y + radius * Mathf.Cos(currAngle));
firstPoint = startPoint;
}
else
{
toPoint = new Vector3(centerPos.x + radius * Mathf.Sin(currAngle),
centerPos.y + radius * Mathf.Cos(currAngle));
if (serie.areaStyle.show)
{
UGL.DrawTriangle(vh, startPoint, toPoint, centerPos, areaColor, areaColor, areaToColor);
}
if (serie.lineStyle.show)
{
ChartDrawer.DrawLineStyle(vh, serie.lineStyle.type, lineWidth, startPoint, toPoint, lineColor);
}
startPoint = toPoint;
}
pointList.Add(startPoint);
}
if (serie.areaStyle.show)
{
UGL.DrawTriangle(vh, startPoint, firstPoint, centerPos, areaColor, areaColor, areaToColor);
}
if (serie.lineStyle.show)
{
ChartDrawer.DrawLineStyle(vh, serie.lineStyle.type, lineWidth, startPoint, firstPoint, lineColor);
}
if (serie.symbol.show && serie.symbol.type != SerieSymbolType.None)
{
for (int m = 0; m < pointList.Count; m++)
{
var point = pointList[m];
isHighlight = IsHighlight(radar, serie, serieData, j, m);
var symbolSize = isHighlight
? serie.symbol.GetSelectedSize(null, chart.theme.serie.lineSymbolSelectedSize)
: serie.symbol.GetSize(null, chart.theme.serie.lineSymbolSize);
var symbolColor = SerieHelper.GetItemColor(serie, serieData, chart.theme, serieIndex, isHighlight);
var symbolToColor = SerieHelper.GetItemToColor(serie, serieData, chart.theme, serieIndex, isHighlight);
var symbolBorder = SerieHelper.GetSymbolBorder(serie, serieData, chart.theme, isHighlight);
var cornerRadius = SerieHelper.GetSymbolCornerRadius(serie, serieData, isHighlight);
chart.DrawSymbol(vh, serie.symbol.type, symbolSize, symbolBorder, point, symbolColor,
symbolToColor, serie.symbol.gap, cornerRadius);
}
}
}
if (!serie.animation.IsFinish())
{
serie.animation.CheckProgress(1);
chart.RefreshPainter(serie);
}
if (dataChanging)
{
chart.RefreshPainter(serie);
}
}
private bool IsHighlight(Radar radar, Serie serie, SerieData serieData, int dataIndex, int dimension)
{
if (serie.highlighted || serieData.highlighted) return true;
if (!chart.tooltip.show) return false;
var selectedSerieIndex = chart.tooltip.runtimeDataIndex[0];
if (selectedSerieIndex < 0) return false;
if (chart.series.GetSerie(selectedSerieIndex).radarIndex != serie.radarIndex) return false;
switch (serie.radarType)
{
case RadarType.Multiple:
if (radar.isAxisTooltip)
{
var selectedDimension = chart.tooltip.runtimeDataIndex[2];
return selectedDimension == dimension;
}
else if (chart.tooltip.runtimeDataIndex.Count >= 2)
{
return chart.tooltip.runtimeDataIndex[0] == serie.index && chart.tooltip.runtimeDataIndex[1] == dataIndex;
}
else
{
return false;
}
case RadarType.Single:
return chart.tooltip.runtimeDataIndex[1] == dataIndex;
}
return false;
}
private void DrawSingleRadar(VertexHelper vh, Serie serie, int i)
{
var startPoint = Vector3.zero;
var toPoint = Vector3.zero;
var firstPoint = Vector3.zero;
var radar = chart.radars[serie.radarIndex];
var indicatorNum = radar.indicatorList.Count;
var angle = 2 * Mathf.PI / indicatorNum;
var centerPos = radar.runtimeCenterPos;
var serieNameCount = -1;
serie.animation.InitProgress(1, 0, 1);
if (!chart.IsActive(i) || serie.animation.HasFadeOut())
{
return;
}
var rate = serie.animation.GetCurrRate();
var dataChanging = false;
var dataChangeDuration = serie.animation.GetUpdateAnimationDuration();
int key = i * 1000;
if (!radar.runtimeDataPosList.ContainsKey(key))
{
radar.runtimeDataPosList.Add(i * 1000, new List<Vector3>(serie.dataCount));
}
else
{
radar.runtimeDataPosList[key].Clear();
}
var pointList = radar.runtimeDataPosList[key];
var startIndex = GetStartShowIndex(serie);
var endIndex = GetEndShowIndex(serie);
SerieHelper.UpdateMinMaxData(serie, 1, radar.ceilRate);
for (int j = 0; j < serie.data.Count; j++)
{
var serieData = serie.data[j];
serieData.index = j;
string dataName = serieData.name;
int serieIndex = 0;
if (string.IsNullOrEmpty(dataName))
{
serieNameCount++;
serieIndex = serieNameCount;
}
else if (!serieNameSet.ContainsKey(dataName))
{
serieNameSet.Add(dataName, serieNameCount);
serieNameCount++;
serieIndex = serieNameCount;
}
else
{
serieIndex = serieNameSet[dataName];
}
if (!serieData.show)
{
serieData.labelPosition = Vector3.zero;
continue;
}
var isHighlight = IsHighlight(radar, serie, serieData, j, 0);
var areaColor = SerieHelper.GetAreaColor(serie, chart.theme, serieIndex, isHighlight);
var areaToColor = SerieHelper.GetAreaToColor(serie, chart.theme, serieIndex, isHighlight);
var lineColor = SerieHelper.GetLineColor(serie, chart.theme, serieIndex, isHighlight);
int dataCount = radar.indicatorList.Count;
var index = serieData.index;
var p = radar.runtimeCenterPos;
var max = radar.GetIndicatorMax(index);
var value = serieData.GetCurrData(1, dataChangeDuration);
if (serieData.IsDataChanged()) dataChanging = true;
if (max == 0)
{
max = serie.runtimeDataMax;
}
var radius = max < 0 ? radar.runtimeDataRadius - radar.runtimeDataRadius * value / max
: radar.runtimeDataRadius * value / max;
var currAngle = (index + (radar.positionType == Radar.PositionType.Between ? 0.5f : 0)) * angle;
radius *= rate;
if (index == startIndex)
{
startPoint = new Vector3(p.x + radius * Mathf.Sin(currAngle),
p.y + radius * Mathf.Cos(currAngle));
firstPoint = startPoint;
}
else
{
toPoint = new Vector3(p.x + radius * Mathf.Sin(currAngle),
p.y + radius * Mathf.Cos(currAngle));
if (serie.areaStyle.show)
{
UGL.DrawTriangle(vh, startPoint, toPoint, p, areaColor, areaColor, areaToColor);
}
if (serie.lineStyle.show)
{
ChartDrawer.DrawLineStyle(vh, serie.lineStyle, startPoint, toPoint, lineColor,
chart.theme.serie.lineWidth, LineStyle.Type.Solid);
}
startPoint = toPoint;
}
serieData.labelPosition = startPoint;
pointList.Add(startPoint);
if (serie.areaStyle.show && j == endIndex)
{
UGL.DrawTriangle(vh, startPoint, firstPoint, centerPos, areaColor, areaColor, areaToColor);
}
if (serie.lineStyle.show && j == endIndex)
{
ChartDrawer.DrawLineStyle(vh, serie.lineStyle, startPoint, firstPoint, lineColor,
chart.theme.serie.lineWidth, LineStyle.Type.Solid);
}
}
if (serie.symbol.show && serie.symbol.type != SerieSymbolType.None)
{
for (int j = 0; j < serie.data.Count; j++)
{
var serieData = serie.data[j];
if (!serieData.show) continue;
var isHighlight = serie.highlighted || serieData.highlighted ||
(chart.tooltip.show && chart.tooltip.runtimeDataIndex[0] == i && chart.tooltip.runtimeDataIndex[1] == j);
var serieIndex = serieData.index;
var symbolSize = isHighlight
? serie.symbol.GetSelectedSize(serieData.data, chart.theme.serie.lineSymbolSelectedSize)
: serie.symbol.GetSize(serieData.data, chart.theme.serie.lineSymbolSize);
var symbolColor = SerieHelper.GetItemColor(serie, serieData, chart.theme, serieIndex, isHighlight);
var symbolToColor = SerieHelper.GetItemToColor(serie, serieData, chart.theme, serieIndex, isHighlight);
var symbolBorder = SerieHelper.GetSymbolBorder(serie, serieData, chart.theme, isHighlight);
var cornerRadius = SerieHelper.GetSymbolCornerRadius(serie, serieData, isHighlight);
chart.DrawSymbol(vh, serie.symbol.type, symbolSize, symbolBorder, serieData.labelPosition, symbolColor,
symbolToColor, serie.symbol.gap, cornerRadius);
}
}
if (!serie.animation.IsFinish())
{
serie.animation.CheckProgress(1);
chart.RefreshPainter(serie);
}
if (dataChanging)
{
chart.RefreshPainter(serie);
}
}
private int GetStartShowIndex(Serie serie)
{
for (int i = 0; i < serie.dataCount; i++)
{
if (serie.data[i].show) return i;
}
return 0;
}
private int GetEndShowIndex(Serie serie)
{
for (int i = serie.dataCount - 1; i >= 0; i--)
{
if (serie.data[i].show) return i;
}
return 0;
}
private void DrawRadarSymbol(VertexHelper vh, Serie serie, SerieData serieData, int serieIndex, bool isHighlight,
List<Vector3> pointList)
{
if (serie.symbol.show && serie.symbol.type != SerieSymbolType.None)
{
var symbolSize = isHighlight
? serie.symbol.GetSelectedSize(serieData.data, chart.theme.serie.lineSymbolSelectedSize)
: serie.symbol.GetSize(serieData.data, chart.theme.serie.lineSymbolSize);
var symbolColor = SerieHelper.GetItemColor(serie, serieData, chart.theme, serieIndex, isHighlight);
var symbolToColor = SerieHelper.GetItemToColor(serie, serieData, chart.theme, serieIndex, isHighlight);
var symbolBorder = SerieHelper.GetSymbolBorder(serie, serieData, chart.theme, isHighlight);
var cornerRadius = SerieHelper.GetSymbolCornerRadius(serie, serieData, isHighlight);
foreach (var point in pointList)
{
chart.DrawSymbol(vh, serie.symbol.type, symbolSize, symbolBorder, point, symbolColor,
symbolToColor, serie.symbol.gap, cornerRadius);
}
}
}
private void DrawRadar(VertexHelper vh, Radar radar)
{
if (!radar.splitLine.show && !radar.splitArea.show)
{
return;
}
float insideRadius = 0, outsideRadius = 0;
float block = radar.runtimeRadius / radar.splitNumber;
int indicatorNum = radar.indicatorList.Count;
Vector3 p1, p2, p3, p4;
Vector3 p = radar.runtimeCenterPos;
float angle = 2 * Mathf.PI / indicatorNum;
var lineColor = radar.axisLine.GetColor(chart.theme.radar.lineColor);
var lineWidth = radar.axisLine.GetWidth(chart.theme.radar.lineWidth);
var lineType = radar.axisLine.GetType(chart.theme.radar.lineType);
var splitLineColor = radar.splitLine.GetColor(chart.theme.radar.splitLineColor);
var splitLineWidth = radar.splitLine.GetWidth(chart.theme.radar.splitLineWidth);
var splitLineType = radar.splitLine.GetType(chart.theme.radar.splitLineType);
for (int i = 0; i < radar.splitNumber; i++)
{
var isLast = i == radar.splitNumber - 1;
var color = radar.splitArea.GetColor(i, chart.theme.radar);
outsideRadius = insideRadius + block;
p1 = new Vector3(p.x + insideRadius * Mathf.Sin(0), p.y + insideRadius * Mathf.Cos(0));
p2 = new Vector3(p.x + outsideRadius * Mathf.Sin(0), p.y + outsideRadius * Mathf.Cos(0));
for (int j = 0; j <= indicatorNum; j++)
{
float currAngle = j * angle;
p3 = new Vector3(p.x + outsideRadius * Mathf.Sin(currAngle),
p.y + outsideRadius * Mathf.Cos(currAngle));
p4 = new Vector3(p.x + insideRadius * Mathf.Sin(currAngle),
p.y + insideRadius * Mathf.Cos(currAngle));
if (radar.splitArea.show)
{
UGL.DrawQuadrilateral(vh, p1, p2, p3, p4, color);
}
if (radar.splitLine.NeedShow(i))
{
if (isLast)
ChartDrawer.DrawLineStyle(vh, lineType, lineWidth, p2, p3, lineColor);
else
ChartDrawer.DrawLineStyle(vh, splitLineType, splitLineWidth, p2, p3, splitLineColor);
}
p1 = p4;
p2 = p3;
}
insideRadius = outsideRadius;
}
for (int j = 0; j <= indicatorNum; j++)
{
float currAngle = j * angle;
p3 = new Vector3(p.x + outsideRadius * Mathf.Sin(currAngle),
p.y + outsideRadius * Mathf.Cos(currAngle));
if (radar.splitLine.show)
{
ChartDrawer.DrawLineStyle(vh, splitLineType, splitLineWidth, p, p3, splitLineColor);
}
}
}
private void DrawCricleRadar(VertexHelper vh, Radar radar)
{
if (!radar.splitLine.show && !radar.splitArea.show)
{
return;
}
float insideRadius = 0, outsideRadius = 0;
float block = radar.runtimeRadius / radar.splitNumber;
int indicatorNum = radar.indicatorList.Count;
Vector3 p = radar.runtimeCenterPos;
Vector3 p1;
float angle = 2 * Mathf.PI / indicatorNum;
var lineColor = radar.axisLine.GetColor(chart.theme.radar.lineColor);
var lineWidth = radar.splitLine.GetWidth(chart.theme.radar.splitLineWidth);
for (int i = 0; i < radar.splitNumber; i++)
{
Color color = radar.splitArea.color[i % radar.splitArea.color.Count];
outsideRadius = insideRadius + block;
if (radar.splitArea.show)
{
UGL.DrawDoughnut(vh, p, insideRadius, outsideRadius, color, Color.clear,
0, 360, chart.settings.cicleSmoothness);
}
if (radar.splitLine.show)
{
UGL.DrawEmptyCricle(vh, p, outsideRadius, lineWidth, lineColor,
Color.clear, chart.settings.cicleSmoothness);
}
insideRadius = outsideRadius;
}
for (int j = 0; j <= indicatorNum; j++)
{
float currAngle = j * angle;
p1 = new Vector3(p.x + outsideRadius * Mathf.Sin(currAngle),
p.y + outsideRadius * Mathf.Cos(currAngle));
if (radar.splitLine.show)
{
UGL.DrawLine(vh, p, p1, lineWidth / 2, lineColor);
}
}
}
private bool IsInRadar(Vector2 local)
{
foreach (var radar in chart.radars)
{
var dist = Vector2.Distance(radar.runtimeCenterPos, local);
if (dist < radar.runtimeRadius + chart.theme.serie.lineSymbolSize)
{
return true;
}
}
return false;
}
protected void UpdateTooltip()
{
int serieIndex = chart.tooltip.runtimeDataIndex[0];
if (serieIndex < 0)
{
if (chart.tooltip.IsActive())
{
chart.tooltip.SetActive(false);
chart.RefreshChart();
}
return;
}
chart.tooltip.SetActive(true);
var serie = chart.series.GetSerie(serieIndex);
var radar = chart.radars[serie.radarIndex];
var dataIndex = chart.tooltip.runtimeDataIndex[1];
var content = TooltipHelper.GetFormatterContent(chart.tooltip, dataIndex, chart.series, chart.theme,
null, null, false, radar);
TooltipHelper.SetContentAndPosition(chart.tooltip, content, chart.chartRect);
}
private bool IsAnyRadarDirty()
{
foreach (var radar in chart.radars)
{
if (radar.anyDirty) return true;
}
return false;
}
}
}

View File

@@ -1,5 +1,5 @@
fileFormatVersion: 2
guid: e22859d8021f6491f8ee08339b71e577
guid: 8b5a823d3c59a461f872211f9580a28c
MonoImporter:
externalObjects: {}
serializedVersion: 2

View File

@@ -0,0 +1,361 @@
/************************************************/
/* */
/* Copyright (c) 2018 - 2021 monitor1394 */
/* https://github.com/monitor1394 */
/* */
/************************************************/
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.EventSystems;
using XUGL;
namespace XCharts
{
internal class DrawSerieRing : IDrawSerie
{
public BaseChart chart;
private bool m_UpdateTitleText = false;
private bool m_UpdateLabelText = false;
private bool m_IsEnterLegendButtom;
public DrawSerieRing(BaseChart chart)
{
this.chart = chart;
}
public void InitComponent()
{
}
public void CheckComponent()
{
}
public void Update()
{
if (m_UpdateTitleText)
{
m_UpdateTitleText = false;
foreach (var serie in chart.series.list)
{
if (serie.type == SerieType.Ring)
{
TitleStyleHelper.UpdateTitleText(serie);
}
}
}
if (m_UpdateLabelText)
{
m_UpdateLabelText = false;
foreach (var serie in chart.series.list)
{
if (serie.type == SerieType.Ring)
{
SerieLabelHelper.SetRingLabelText(serie, chart.theme);
}
}
}
}
public void DrawBase(VertexHelper vh)
{
}
public void DrawSerie(VertexHelper vh, Serie serie)
{
if (serie.type != SerieType.Ring) return;
if (!serie.show || serie.animation.HasFadeOut()) return;
var data = serie.data;
serie.animation.InitProgress(data.Count, serie.startAngle, serie.startAngle + 360);
SerieHelper.UpdateCenter(serie, chart.chartPosition, chart.chartWidth, chart.chartHeight);
TitleStyleHelper.CheckTitle(serie, ref chart.m_ReinitTitle, ref m_UpdateTitleText);
SerieLabelHelper.CheckLabel(serie, ref chart.m_ReinitLabel, ref m_UpdateLabelText);
var dataChangeDuration = serie.animation.GetUpdateAnimationDuration();
var ringWidth = serie.runtimeOutsideRadius - serie.runtimeInsideRadius;
var dataChanging = false;
for (int j = 0; j < data.Count; j++)
{
var serieData = data[j];
if (!serieData.show) continue;
if (serieData.IsDataChanged()) dataChanging = true;
var value = serieData.GetFirstData(dataChangeDuration);
var max = serieData.GetLastData();
var degree = 360 * value / max;
var startDegree = GetStartAngle(serie);
var toDegree = GetToAngle(serie, degree);
var itemStyle = SerieHelper.GetItemStyle(serie, serieData, serieData.highlighted);
var itemColor = SerieHelper.GetItemColor(serie, serieData, chart.theme, j, serieData.highlighted);
var itemToColor = SerieHelper.GetItemToColor(serie, serieData, chart.theme, j, serieData.highlighted);
var outsideRadius = serie.runtimeOutsideRadius - j * (ringWidth + serie.ringGap);
var insideRadius = outsideRadius - ringWidth;
var centerRadius = (outsideRadius + insideRadius) / 2;
var borderWidth = itemStyle.borderWidth;
var borderColor = itemStyle.borderColor;
var roundCap = serie.roundCap && insideRadius > 0;
serieData.runtimePieStartAngle = serie.clockwise ? startDegree : toDegree;
serieData.runtimePieToAngle = serie.clockwise ? toDegree : startDegree;
serieData.runtimePieInsideRadius = insideRadius;
serieData.runtimePieOutsideRadius = outsideRadius;
UGL.DrawDoughnut(vh, serie.runtimeCenterPos, insideRadius, outsideRadius, itemColor, itemToColor,
Color.clear, startDegree, toDegree, borderWidth, borderColor, 0, chart.settings.cicleSmoothness,
roundCap, serie.clockwise);
DrawCenter(vh, serie, serieData, insideRadius, j == data.Count - 1);
UpateLabelPosition(serie, serieData, j, startDegree, toDegree, centerRadius);
}
if (!serie.animation.IsFinish())
{
serie.animation.CheckProgress(360);
chart.RefreshChart();
}
if (dataChanging)
{
chart.RefreshChart();
}
}
public void RefreshLabel()
{
}
public bool CheckTootipArea(Vector2 local)
{
if (!PointerIsInRingSerie(chart.series, local)) return false;
if (m_IsEnterLegendButtom) return false;
bool selected = false;
chart.tooltip.runtimeDataIndex.Clear();
foreach (var serie in chart.series.list)
{
int index = GetRingIndex(serie, local);
chart.tooltip.runtimeDataIndex.Add(index);
if (serie.type != SerieType.Ring) continue;
bool refresh = false;
for (int j = 0; j < serie.data.Count; j++)
{
var serieData = serie.data[j];
if (serieData.highlighted != (j == index)) refresh = true;
serieData.highlighted = j == index;
}
if (index >= 0) selected = true;
if (refresh) chart.RefreshChart();
}
if (selected)
{
chart.tooltip.UpdateContentPos(local + chart.tooltip.offset);
UpdateTooltip();
}
else if (chart.tooltip.IsActive())
{
chart.tooltip.SetActive(false);
chart.RefreshChart();
}
return true;
}
public bool OnLegendButtonClick(int index, string legendName, bool show)
{
if (!SeriesHelper.ContainsSerie(chart.series, SerieType.Ring)) return false;
if (!LegendHelper.IsSerieLegend(chart.series, legendName, SerieType.Ring)) return false;
LegendHelper.CheckDataShow(chart.series, legendName, show);
chart.UpdateLegendColor(legendName, show);
chart.RefreshChart();
return true;
}
public bool OnLegendButtonEnter(int index, string legendName)
{
if (!SeriesHelper.ContainsSerie(chart.series, SerieType.Ring)) return false;
if (!LegendHelper.IsSerieLegend(chart.series, legendName, SerieType.Ring)) return false;
m_IsEnterLegendButtom = true;
LegendHelper.CheckDataHighlighted(chart.series, legendName, true);
chart.RefreshChart();
return true;
}
public bool OnLegendButtonExit(int index, string legendName)
{
if (!SeriesHelper.ContainsSerie(chart.series, SerieType.Ring)) return false;
if (!LegendHelper.IsSerieLegend(chart.series, legendName, SerieType.Ring)) return false;
m_IsEnterLegendButtom = false;
LegendHelper.CheckDataHighlighted(chart.series, legendName, false);
chart.RefreshChart();
return true;
}
public void OnPointerDown(PointerEventData eventData)
{
}
private float GetStartAngle(Serie serie)
{
return serie.clockwise ? serie.startAngle : 360 - serie.startAngle;
}
private float GetToAngle(Serie serie, float angle)
{
var toAngle = angle + serie.startAngle;
if (!serie.clockwise)
{
toAngle = 360 - angle - serie.startAngle;
}
if (!serie.animation.IsFinish())
{
var currAngle = serie.animation.GetCurrDetail();
if (serie.clockwise)
{
toAngle = toAngle > currAngle ? currAngle : toAngle;
}
else
{
toAngle = toAngle < 360 - currAngle ? 360 - currAngle : toAngle;
}
}
return toAngle;
}
private void DrawCenter(VertexHelper vh, Serie serie, SerieData serieData, float insideRadius, bool last)
{
var itemStyle = SerieHelper.GetItemStyle(serie, serieData);
if (!ChartHelper.IsClearColor(itemStyle.centerColor) && last)
{
var radius = insideRadius - itemStyle.centerGap;
var smoothness = chart.settings.cicleSmoothness;
UGL.DrawCricle(vh, serie.runtimeCenterPos, radius, itemStyle.centerColor, smoothness);
}
}
private void UpateLabelPosition(Serie serie, SerieData serieData, int index, float startAngle,
float toAngle, float centerRadius)
{
if (!serie.label.show) return;
if (serieData.labelObject == null) return;
switch (serie.label.position)
{
case SerieLabel.Position.Center:
serieData.labelPosition = serie.runtimeCenterPos + serie.label.offset;
break;
case SerieLabel.Position.Bottom:
var px1 = Mathf.Sin(startAngle * Mathf.Deg2Rad) * centerRadius;
var py1 = Mathf.Cos(startAngle * Mathf.Deg2Rad) * centerRadius;
var xDiff = serie.clockwise ? -serie.label.margin : serie.label.margin;
serieData.labelPosition = serie.runtimeCenterPos + new Vector3(px1 + xDiff, py1);
break;
case SerieLabel.Position.Top:
startAngle += serie.clockwise ? -serie.label.margin : serie.label.margin;
toAngle += serie.clockwise ? serie.label.margin : -serie.label.margin;
var px2 = Mathf.Sin(toAngle * Mathf.Deg2Rad) * centerRadius;
var py2 = Mathf.Cos(toAngle * Mathf.Deg2Rad) * centerRadius;
serieData.labelPosition = serie.runtimeCenterPos + new Vector3(px2, py2);
break;
}
serieData.labelObject.SetLabelPosition(serieData.labelPosition);
}
private void DrawBackground(VertexHelper vh, Serie serie, SerieData serieData, int index, float insideRadius, float outsideRadius)
{
var itemStyle = SerieHelper.GetItemStyle(serie, serieData);
var backgroundColor = SerieHelper.GetItemBackgroundColor(serie, serieData, chart.theme, index, false);
if (itemStyle.backgroundWidth != 0)
{
var centerRadius = (outsideRadius + insideRadius) / 2;
var inradius = centerRadius - itemStyle.backgroundWidth / 2;
var outradius = centerRadius + itemStyle.backgroundWidth / 2;
UGL.DrawDoughnut(vh, serie.runtimeCenterPos, inradius,
outradius, backgroundColor, Color.clear, chart.settings.cicleSmoothness);
}
else
{
UGL.DrawDoughnut(vh, serie.runtimeCenterPos, insideRadius,
outsideRadius, backgroundColor, Color.clear, chart.settings.cicleSmoothness);
}
}
private void DrawBorder(VertexHelper vh, Serie serie, SerieData serieData, float insideRadius, float outsideRadius)
{
var itemStyle = SerieHelper.GetItemStyle(serie, serieData);
if (itemStyle.show && itemStyle.borderWidth > 0 && !ChartHelper.IsClearColor(itemStyle.borderColor))
{
UGL.DrawDoughnut(vh, serie.runtimeCenterPos, outsideRadius,
outsideRadius + itemStyle.borderWidth, itemStyle.borderColor,
Color.clear, chart.settings.cicleSmoothness);
UGL.DrawDoughnut(vh, serie.runtimeCenterPos, insideRadius,
insideRadius + itemStyle.borderWidth, itemStyle.borderColor,
Color.clear, chart.settings.cicleSmoothness);
}
}
private void DrawRoundCap(VertexHelper vh, Serie serie, Vector3 centerPos, Color color,
float insideRadius, float outsideRadius, ref float drawStartDegree, ref float drawEndDegree)
{
if (serie.roundCap && insideRadius > 0 && drawStartDegree != drawEndDegree)
{
var width = (outsideRadius - insideRadius) / 2;
var radius = insideRadius + width;
var diffDegree = Mathf.Asin(width / radius) * Mathf.Rad2Deg;
drawStartDegree += serie.clockwise ? diffDegree : -diffDegree;
drawEndDegree -= serie.clockwise ? diffDegree : -diffDegree;
UGL.DrawRoundCap(vh, centerPos, width, radius, drawStartDegree, serie.clockwise, color, false);
UGL.DrawRoundCap(vh, centerPos, width, radius, drawEndDegree, serie.clockwise, color, true);
}
}
private int GetRingIndex(Serie serie, Vector2 local)
{
if (serie.type != SerieType.Ring) return -1;
var dist = Vector2.Distance(local, serie.runtimeCenterPos);
if (dist > serie.runtimeOutsideRadius) return -1;
Vector2 dir = local - new Vector2(serie.runtimeCenterPos.x, serie.runtimeCenterPos.y);
float angle = VectorAngle(Vector2.up, dir);
for (int i = 0; i < serie.data.Count; i++)
{
var serieData = serie.data[i];
if (dist >= serieData.runtimePieInsideRadius &&
dist <= serieData.runtimePieOutsideRadius &&
angle >= serieData.runtimePieStartAngle &&
angle <= serieData.runtimePieToAngle)
{
return i;
}
}
return -1;
}
private bool PointerIsInRingSerie(Series series, Vector2 local)
{
foreach (var serie in series.list)
{
if (serie.type != SerieType.Ring) continue;
if (GetRingIndex(serie, local) >= 0) return true;
}
return false;
}
private float VectorAngle(Vector2 from, Vector2 to)
{
float angle;
Vector3 cross = Vector3.Cross(from, to);
angle = Vector2.Angle(from, to);
angle = cross.z > 0 ? -angle : angle;
angle = (angle + 360) % 360;
return angle;
}
private void UpdateTooltip()
{
bool showTooltip = false;
foreach (var serie in chart.series.list)
{
int index = chart.tooltip.runtimeDataIndex[serie.index];
if (index < 0) continue;
showTooltip = true;
var content = TooltipHelper.GetFormatterContent(chart.tooltip, index, chart.series, chart.theme);
TooltipHelper.SetContentAndPosition(chart.tooltip, content.TrimStart(), chart.chartRect);
}
chart.tooltip.SetActive(showTooltip);
}
}
}

View File

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

View File

@@ -0,0 +1,71 @@
/************************************************/
/* */
/* Copyright (c) 2018 - 2021 monitor1394 */
/* https://github.com/monitor1394 */
/* */
/************************************************/
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.EventSystems;
using XUGL;
namespace XCharts
{
internal class DrawSerieTemplate : IDrawSerie
{
public BaseChart chart;
public DrawSerieTemplate(BaseChart chart)
{
this.chart = chart;
}
public void InitComponent()
{
}
public void CheckComponent()
{
}
public void Update()
{
}
public void DrawBase(VertexHelper vh)
{
}
public void DrawSerie(VertexHelper vh, Serie serie)
{
}
public void RefreshLabel()
{
}
public bool CheckTootipArea(Vector2 local)
{
return false;
}
public bool OnLegendButtonClick(int index, string legendName, bool show)
{
return false;
}
public bool OnLegendButtonEnter(int index, string legendName)
{
return false;
}
public bool OnLegendButtonExit(int index, string legendName)
{
return false;
}
public void OnPointerDown(PointerEventData eventData)
{
}
}
}

View File

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

View File

@@ -1,9 +1,9 @@
/******************************************/
/* */
/* Copyright (c) 2018 monitor1394 */
/* https://github.com/monitor1394 */
/* */
/******************************************/
/************************************************/
/* */
/* Copyright (c) 2018 - 2021 monitor1394 */
/* https://github.com/monitor1394 */
/* */
/************************************************/
using System.Text;
using UnityEngine;
using UnityEngine.UI;
@@ -12,10 +12,6 @@ namespace XCharts
{
public static class AxisHelper
{
public static float GetTickWidth(Axis axis)
{
return axis.axisTick.width != 0 ? axis.axisTick.width : axis.axisLine.width;
}
/// <summary>
/// 包含箭头偏移的轴线长度
@@ -24,9 +20,9 @@ namespace XCharts
/// <returns></returns>
public static float GetAxisLineSymbolOffset(Axis axis)
{
if (axis.axisLine.show && axis.axisLine.symbol && axis.axisLine.symbolOffset > 0)
if (axis.axisLine.show && axis.axisLine.showArrow && axis.axisLine.arrow.offset > 0)
{
return axis.axisLine.symbolOffset;
return axis.axisLine.arrow.offset;
}
return 0;
}
@@ -115,7 +111,7 @@ namespace XCharts
if (axis.type == Axis.AxisType.Value)
{
if (minValue == 0 && maxValue == 0) return string.Empty;
float value = 0;
var value = 0f;
if (forcePercent) maxValue = 100;
if (axis.interval > 0)
{
@@ -124,7 +120,7 @@ namespace XCharts
}
else
{
value = (minValue + (maxValue - minValue) * index / split);
value = minValue + (maxValue - minValue) * index / split;
if (!axis.clockwise && value != minValue) value = maxValue - value;
}
if (axis.inverse)
@@ -133,6 +129,7 @@ namespace XCharts
minValue = -minValue;
maxValue = -maxValue;
}
if (forcePercent) return string.Format("{0}%", (int)value);
else return axis.axisLabel.GetFormatterContent(value, minValue, maxValue);
}
@@ -324,11 +321,11 @@ namespace XCharts
else return true;
}
internal static void AdjustCircleLabelPos(Text txt, Vector3 pos, Vector3 cenPos, float txtHig, Vector3 offset)
internal static void AdjustCircleLabelPos(ChartText txt, Vector3 pos, Vector3 cenPos, float txtHig, Vector3 offset)
{
var txtWidth = txt.preferredWidth;
var sizeDelta = new Vector2(txtWidth, txt.preferredHeight);
txt.GetComponent<RectTransform>().sizeDelta = sizeDelta;
var txtWidth = txt.GetPreferredWidth();
var sizeDelta = new Vector2(txtWidth, txt.GetPreferredHeight());
txt.SetSizeDelta(sizeDelta);
var diff = pos.x - cenPos.x;
if (diff < -1f) //left
{
@@ -343,14 +340,14 @@ namespace XCharts
float y = pos.y > cenPos.y ? pos.y + txtHig / 2 : pos.y - txtHig / 2;
pos = new Vector3(pos.x, y);
}
txt.transform.localPosition = pos + offset;
txt.SetLocalPosition(pos + offset);
}
internal static void AdjustRadiusAxisLabelPos(Text txt, Vector3 pos, Vector3 cenPos, float txtHig, Vector3 offset)
internal static void AdjustRadiusAxisLabelPos(ChartText txt, Vector3 pos, Vector3 cenPos, float txtHig, Vector3 offset)
{
var txtWidth = txt.preferredWidth;
var sizeDelta = new Vector2(txtWidth, txt.preferredHeight);
txt.GetComponent<RectTransform>().sizeDelta = sizeDelta;
var txtWidth = txt.GetPreferredWidth();
var sizeDelta = new Vector2(txtWidth, txt.GetPreferredHeight());
txt.SetSizeDelta(sizeDelta);
var diff = pos.y - cenPos.y;
if (diff > 20f) //left
{
@@ -365,7 +362,7 @@ namespace XCharts
float y = pos.y > cenPos.y ? pos.y + txtHig / 2 : pos.y - txtHig / 2;
pos = new Vector3(pos.x, y);
}
txt.transform.localPosition = pos;
txt.SetLocalPosition(pos);
}
}
}

View File

@@ -1,9 +1,9 @@
/******************************************/
/* */
/* Copyright (c) 2018 monitor1394 */
/* https://github.com/monitor1394 */
/* */
/******************************************/
/************************************************/
/* */
/* Copyright (c) 2018 - 2021 monitor1394 */
/* https://github.com/monitor1394 */
/* */
/************************************************/
using UnityEngine;
using UnityEngine.UI;

View File

@@ -1,9 +1,9 @@
/******************************************/
/* */
/* Copyright (c) 2018 monitor1394 */
/* https://github.com/monitor1394 */
/* */
/******************************************/
/************************************************/
/* */
/* Copyright (c) 2018 - 2021 monitor1394 */
/* https://github.com/monitor1394 */
/* */
/************************************************/
using UnityEngine;
using UnityEngine.UI;
@@ -11,29 +11,29 @@ namespace XCharts
{
internal static class LegendHelper
{
public static Color GetContentColor(Legend legend, ThemeInfo themeInfo, bool active)
public static Color GetContentColor(Legend legend, ChartTheme theme, bool active)
{
var textStyle = legend.textStyle;
if (active) return !ChartHelper.IsClearColor(textStyle.color) ? textStyle.color : (Color)themeInfo.legendTextColor;
else return (Color)themeInfo.legendUnableColor;
if (active) return !ChartHelper.IsClearColor(textStyle.color) ? textStyle.color : theme.legend.textColor;
else return theme.legend.unableColor;
}
public static Color GetIconColor(Legend legend, int readIndex, ThemeInfo themeInfo, Series series, string legendName, bool active)
public static Color GetIconColor(Legend legend, int readIndex, ChartTheme theme, Series series, string legendName, bool active)
{
if (active)
{
if (legend.itemAutoColor || legend.GetIcon(readIndex) == null)
{
return SeriesHelper.GetNameColor(series, readIndex, legendName, themeInfo);
return SeriesHelper.GetNameColor(series, readIndex, legendName, theme);
}
else
return Color.white;
}
else return (Color)themeInfo.legendUnableColor;
else return theme.legend.unableColor;
}
public static LegendItem AddLegendItem(Legend legend, int i, string legendName, Transform parent, ThemeInfo themeInfo,
string content, Color itemColor, bool active)
public static LegendItem AddLegendItem(Legend legend, int i, string legendName, Transform parent,
ChartTheme theme, string content, Color itemColor, bool active)
{
var objName = i + "_" + legendName;
var anchorMin = new Vector2(0, 0.5f);
@@ -42,8 +42,7 @@ namespace XCharts
var sizeDelta = new Vector2(100, 30);
var iconSizeDelta = new Vector2(legend.itemWidth, legend.itemHeight);
var textStyle = legend.textStyle;
var font = textStyle.font ? textStyle.font : themeInfo.font;
var contentColor = GetContentColor(legend, themeInfo, active);
var contentColor = GetContentColor(legend, theme, active);
var objAnchorMin = new Vector2(0, 1);
var objAnchorMax = new Vector2(0, 1);
@@ -56,9 +55,10 @@ namespace XCharts
ChartHelper.GetOrAddComponent<Button>(btnObj);
ChartHelper.GetOrAddComponent<Image>(iconObj);
ChartHelper.GetOrAddComponent<Image>(contentObj);
ChartHelper.AddTextObject("Text", contentObj.transform, font, contentColor,
TextAnchor.MiddleLeft, anchorMin, anchorMax, pivot, sizeDelta, textStyle.fontSize,
textStyle.rotate, textStyle.fontStyle, textStyle.lineSpacing);
var txt = ChartHelper.AddTextObject("Text", contentObj.transform, anchorMin, anchorMax, pivot, sizeDelta,
textStyle, theme.legend);
txt.SetAlignment(TextAnchor.MiddleLeft);
txt.SetColor(contentColor);
var item = new LegendItem();
item.index = i;
item.name = objName;
@@ -278,5 +278,30 @@ namespace XCharts
}
return show;
}
public static bool IsSerieLegend(Series series, string legendName, SerieType type)
{
foreach (var serie in series.list)
{
if (serie.type == type)
{
switch (serie.type)
{
case SerieType.Pie:
case SerieType.Radar:
case SerieType.Ring:
foreach (var serieData in serie.data)
{
if (legendName.Equals(serieData.name)) return true;
}
break;
default:
if (legendName.Equals(serie.name)) return true;
break;
}
}
}
return false;
}
}
}

View File

@@ -1,9 +1,9 @@
/******************************************/
/* */
/* Copyright (c) 2018 monitor1394 */
/* https://github.com/monitor1394 */
/* */
/******************************************/
/************************************************/
/* */
/* Copyright (c) 2018 - 2021 monitor1394 */
/* https://github.com/monitor1394 */
/* */
/************************************************/
using UnityEngine;

View File

@@ -1,9 +1,9 @@
/******************************************/
/* */
/* Copyright (c) 2018 monitor1394 */
/* https://github.com/monitor1394 */
/* */
/******************************************/
/************************************************/
/* */
/* Copyright (c) 2018 - 2021 monitor1394 */
/* https://github.com/monitor1394 */
/* */
/************************************************/
using UnityEngine;
@@ -11,7 +11,7 @@ namespace XCharts
{
public static partial class SerieHelper
{
internal static Color32 GetItemBackgroundColor(Serie serie, SerieData serieData, ThemeInfo theme, int index,
internal static Color32 GetItemBackgroundColor(Serie serie, SerieData serieData, ChartTheme theme, int index,
bool highlight, bool useDefault = true)
{
var color = ChartConst.clearColor32;
@@ -43,7 +43,7 @@ namespace XCharts
return color;
}
internal static Color32 GetItemColor(Serie serie, SerieData serieData, ThemeInfo theme, int index, bool highlight)
internal static Color32 GetItemColor(Serie serie, SerieData serieData, ChartTheme theme, int index, bool highlight)
{
if (serie == null) return ChartConst.clearColor32;
if (highlight)
@@ -70,7 +70,7 @@ namespace XCharts
}
}
internal static Color32 GetItemToColor(Serie serie, SerieData serieData, ThemeInfo theme, int index, bool highlight)
internal static Color32 GetItemToColor(Serie serie, SerieData serieData, ChartTheme theme, int index, bool highlight)
{
if (highlight)
{
@@ -174,7 +174,7 @@ namespace XCharts
else return serie.symbol;
}
internal static Color32 GetAreaColor(Serie serie, ThemeInfo theme, int index, bool highlight)
internal static Color32 GetAreaColor(Serie serie, ChartTheme theme, int index, bool highlight)
{
var areaStyle = serie.areaStyle;
var color = !ChartHelper.IsClearColor(areaStyle.color) ? areaStyle.color : theme.GetColor(index);
@@ -187,7 +187,7 @@ namespace XCharts
return color;
}
internal static Color32 GetAreaToColor(Serie serie, ThemeInfo theme, int index, bool highlight)
internal static Color32 GetAreaToColor(Serie serie, ChartTheme theme, int index, bool highlight)
{
var areaStyle = serie.areaStyle;
if (!ChartHelper.IsClearColor(areaStyle.toColor))
@@ -207,7 +207,7 @@ namespace XCharts
}
}
internal static Color32 GetLineColor(Serie serie, ThemeInfo theme, int index, bool highlight)
internal static Color32 GetLineColor(Serie serie, ChartTheme theme, int index, bool highlight)
{
Color32 color = ChartConst.clearColor32;
if (highlight)
@@ -231,12 +231,11 @@ namespace XCharts
return color;
}
internal static float GetSymbolBorder(Serie serie, SerieData serieData, bool highlight, bool useLineWidth = true)
internal static float GetSymbolBorder(Serie serie, SerieData serieData, ChartTheme theme, bool highlight, bool useLineWidth = true)
{
var itemStyle = GetItemStyle(serie, serieData, highlight);
if (itemStyle != null && itemStyle.borderWidth != 0) return itemStyle.borderWidth;
else if (serie.lineStyle.width != 0 && useLineWidth) return serie.lineStyle.width;
else return 0;
else return serie.lineStyle.GetWidth(theme.serie.lineWidth);
}
internal static float[] GetSymbolCornerRadius(Serie serie, SerieData serieData, bool highlight)

View File

@@ -1,9 +1,9 @@
/******************************************/
/* */
/* Copyright (c) 2018 monitor1394 */
/* https://github.com/monitor1394 */
/* */
/******************************************/
/************************************************/
/* */
/* Copyright (c) 2018 - 2021 monitor1394 */
/* https://github.com/monitor1394 */
/* */
/************************************************/
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
@@ -42,7 +42,7 @@ namespace XCharts
}
}
public static void UpdateLabelText(Series series, ThemeInfo themeInfo, List<string> legendRealShowName)
public static void UpdateLabelText(Series series, ChartTheme theme, List<string> legendRealShowName)
{
foreach (var serie in series.list)
{
@@ -54,35 +54,35 @@ namespace XCharts
SetGaugeLabelText(serie);
break;
case SerieType.Ring:
SetRingLabelText(serie, themeInfo);
SetRingLabelText(serie, theme);
break;
case SerieType.Liquid:
SetLiquidLabelText(serie, themeInfo, colorIndex);
SetLiquidLabelText(serie, theme, colorIndex);
break;
}
}
}
public static Color GetLabelColor(Serie serie, ThemeInfo themeInfo, int index)
public static Color GetLabelColor(Serie serie, ChartTheme theme, int index)
{
if (!ChartHelper.IsClearColor(serie.label.color))
if (!ChartHelper.IsClearColor(serie.label.textStyle.color))
{
return serie.label.color;
return serie.label.textStyle.color;
}
else
{
return themeInfo.GetColor(index);
return theme.GetColor(index);
}
}
public static void ResetLabel(SerieData serieData, SerieLabel label, ThemeInfo themeInfo, int colorIndex)
public static void ResetLabel(SerieData serieData, SerieLabel label, ChartTheme theme, int colorIndex)
{
if (serieData.labelObject == null) return;
if (serieData.labelObject.label == null) return;
serieData.labelObject.label.color = !ChartHelper.IsClearColor(label.color) ? label.color :
(Color)themeInfo.GetColor(colorIndex);
serieData.labelObject.label.fontSize = label.fontSize;
serieData.labelObject.label.fontStyle = label.fontStyle;
serieData.labelObject.label.SetColor(!ChartHelper.IsClearColor(label.textStyle.color) ? label.textStyle.color :
(Color)theme.GetColor(colorIndex));
serieData.labelObject.label.SetFontSize(label.textStyle.GetFontSize(theme.common));
serieData.labelObject.label.SetFontStyle(label.textStyle.fontStyle);
}
public static bool CanShowLabel(Serie serie, SerieData serieData, SerieLabel label, int dimesion)
@@ -111,7 +111,7 @@ namespace XCharts
}
}
private static void SetGaugeLabelText(Serie serie)
public static void SetGaugeLabelText(Serie serie)
{
var serieData = serie.GetSerieData(0);
if (serieData == null) return;
@@ -121,13 +121,13 @@ namespace XCharts
var content = SerieLabelHelper.GetFormatterContent(serie, serieData, value, total);
serieData.labelObject.SetText(content);
serieData.labelObject.SetLabelPosition(serie.runtimeCenterPos + serie.label.offset);
if (!ChartHelper.IsClearColor(serie.label.color))
if (!ChartHelper.IsClearColor(serie.label.textStyle.color))
{
serieData.labelObject.label.color = serie.label.color;
serieData.labelObject.label.SetColor(serie.label.textStyle.color);
}
}
private static void SetRingLabelText(Serie serie, ThemeInfo themeInfo)
public static void SetRingLabelText(Serie serie, ChartTheme theme)
{
for (int i = 0; i < serie.dataCount; i++)
{
@@ -145,7 +145,7 @@ namespace XCharts
var content = SerieLabelHelper.GetFormatterContent(serie, serieData, value, total);
serieData.SetLabelActive(true);
serieData.labelObject.SetText(content);
serieData.labelObject.SetLabelColor(GetLabelColor(serie, themeInfo, i));
serieData.labelObject.SetLabelColor(GetLabelColor(serie, theme, i));
if (serie.label.position == SerieLabel.Position.Bottom)
{
@@ -163,7 +163,7 @@ namespace XCharts
}
}
private static void SetLiquidLabelText(Serie serie, ThemeInfo themeInfo, int colorIndex)
public static void SetLiquidLabelText(Serie serie, ChartTheme theme, int colorIndex)
{
var serieData = serie.GetSerieData(0);
if (serieData == null) return;
@@ -180,7 +180,7 @@ namespace XCharts
var content = SerieLabelHelper.GetFormatterContent(serie, serieData, value, total);
serieData.SetLabelActive(true);
serieData.labelObject.SetText(content);
serieData.labelObject.SetLabelColor(GetLabelColor(serie, themeInfo, colorIndex));
serieData.labelObject.SetLabelColor(GetLabelColor(serie, theme, colorIndex));
serieData.labelObject.SetLabelPosition(serieData.labelPosition + serieLabel.offset);
}
}
@@ -220,7 +220,7 @@ namespace XCharts
}
var r4 = Mathf.Sqrt(radius1 * radius1 - Mathf.Pow(currCos * radius3, 2)) - currSin * radius3;
r4 += serieLabel.lineLength1 + serieLabel.lineWidth * 4;
r4 += serieData.labelObject.label.preferredWidth / 2;
r4 += serieData.labelObject.label.GetPreferredWidth() / 2;
serieData.labelPosition = pos0 + (currAngle > 180 ? Vector3.left : Vector3.right) * r4;
}
else
@@ -228,7 +228,7 @@ namespace XCharts
labelRadius = serie.runtimeOutsideRadius + serieLabel.lineLength1;
labelCenter = new Vector2(serie.runtimeCenterPos.x + labelRadius * Mathf.Sin(currRad),
serie.runtimeCenterPos.y + labelRadius * Mathf.Cos(currRad));
float labelWidth = serieData.labelObject.label.preferredWidth;
float labelWidth = serieData.labelObject.label.GetPreferredWidth();
serieData.labelPosition = labelCenter;
}
break;
@@ -280,7 +280,7 @@ namespace XCharts
}
else if (serieData.labelPosition.x != 0)
{
float hig = serieLabel.fontSize;
float hig = serieLabel.textStyle.fontSize;
if (lastCheckPos.y - serieData.labelPosition.y < hig)
{
var labelRadius = serie.runtimeOutsideRadius + serieLabel.lineLength1;

View File

@@ -1,16 +1,16 @@
/******************************************/
/* */
/* Copyright (c) 2018 monitor1394 */
/* https://github.com/monitor1394 */
/* */
/******************************************/
/************************************************/
/* */
/* Copyright (c) 2018 - 2021 monitor1394 */
/* https://github.com/monitor1394 */
/* */
/************************************************/
using System.Collections.Generic;
using UnityEngine;
namespace XCharts
{
internal static class SeriesHelper
public static class SeriesHelper
{
public static bool IsNeedLabelUpdate(Series series)
{
@@ -119,7 +119,7 @@ namespace XCharts
}
}
internal static Color GetNameColor(Series series, int index, string name, ThemeInfo theme)
internal static Color GetNameColor(Series series, int index, string name, ChartTheme theme)
{
Serie destSerie = null;
SerieData destSerieData = null;
@@ -188,6 +188,15 @@ namespace XCharts
return false;
}
internal static bool ContainsSerie(Series series, SerieType type)
{
foreach (var serie in series.list)
{
if (serie.type == type) return true;
}
return false;
}
internal static bool IsAnyUpdateAnimationSerie(Series series)
{
foreach (var serie in series.list)
@@ -236,20 +245,6 @@ namespace XCharts
return null;
}
/// <summary>
/// 是否由系列在用指定索引的axis
/// </summary>
/// <param name="axisIndex"></param>
/// <returns></returns>
internal static bool IsUsedAxisIndex(Series series, int axisIndex)
{
foreach (var serie in series.list)
{
if (serie.axisIndex == axisIndex) return true;
}
return false;
}
private static HashSet<string> _setForStack = new HashSet<string>();
/// <summary>
/// 是否由数据堆叠
@@ -393,6 +388,19 @@ namespace XCharts
}
}
internal static void UpdateStackDataList(Series series, Serie currSerie, DataZoom dataZoom, List<List<SerieData>> dataList)
{
dataList.Clear();
for (int i = 0; i <= currSerie.index; i++)
{
var serie = series.list[i];
if (serie.type == currSerie.type && ChartHelper.IsValueEqualsString(serie.stack, currSerie.stack))
{
dataList.Add(serie.GetDataList(dataZoom));
}
}
}
/// <summary>
/// 获得维度X的最大最小值
/// </summary>
@@ -401,9 +409,9 @@ namespace XCharts
/// <param name="minVaule"></param>
/// <param name="maxValue"></param>
internal static void GetXMinMaxValue(Series series, DataZoom dataZoom, int axisIndex, bool isValueAxis,
bool inverse, out float minVaule, out float maxValue)
bool inverse, out float minVaule, out float maxValue, bool isPolar = false)
{
GetMinMaxValue(series, dataZoom, axisIndex, isValueAxis, inverse, false, out minVaule, out maxValue);
GetMinMaxValue(series, dataZoom, axisIndex, isValueAxis, inverse, false, out minVaule, out maxValue, isPolar);
}
/// <summary>
@@ -414,15 +422,15 @@ namespace XCharts
/// <param name="minVaule"></param>
/// <param name="maxValue"></param>
internal static void GetYMinMaxValue(Series series, DataZoom dataZoom, int axisIndex, bool isValueAxis,
bool inverse, out float minVaule, out float maxValue)
bool inverse, out float minVaule, out float maxValue, bool isPolar = false)
{
GetMinMaxValue(series, dataZoom, axisIndex, isValueAxis, inverse, true, out minVaule, out maxValue);
GetMinMaxValue(series, dataZoom, axisIndex, isValueAxis, inverse, true, out minVaule, out maxValue, isPolar);
}
private static Dictionary<int, List<Serie>> _stackSeriesForMinMax = new Dictionary<int, List<Serie>>();
private static Dictionary<int, float> _serieTotalValueForMinMax = new Dictionary<int, float>();
internal static void GetMinMaxValue(Series series, DataZoom dataZoom, int axisIndex, bool isValueAxis,
bool inverse, bool yValue, out float minVaule, out float maxValue)
bool inverse, bool yValue, out float minVaule, out float maxValue, bool isPolar = false)
{
float min = int.MaxValue;
float max = int.MinValue;
@@ -432,8 +440,8 @@ namespace XCharts
for (int i = 0; i < series.list.Count; i++)
{
var serie = series.GetSerie(i);
if (serie.axisIndex != axisIndex) continue;
if ((isPolar && serie.polarIndex != axisIndex)
|| (!isPolar && serie.yAxisIndex != axisIndex)) continue;
if (series.IsActive(i))
{
if (isPercentStack && SeriesHelper.IsPercentStack(series, serie.name, SerieType.Bar))
@@ -463,7 +471,9 @@ namespace XCharts
for (int i = 0; i < ss.Value.Count; i++)
{
var serie = ss.Value[i];
if (serie.axisIndex != axisIndex || !series.IsActive(i)) continue;
if ((isPolar && serie.polarIndex != axisIndex)
|| (!isPolar && serie.yAxisIndex != axisIndex)
|| !series.IsActive(i)) continue;
var showData = serie.GetDataList(dataZoom);
if (SeriesHelper.IsPercentStack(series, serie.stack, SerieType.Bar))
{

View File

@@ -1,9 +1,9 @@
/******************************************/
/* */
/* Copyright (c) 2018 monitor1394 */
/* https://github.com/monitor1394 */
/* */
/******************************************/
/************************************************/
/* */
/* Copyright (c) 2018 - 2021 monitor1394 */
/* https://github.com/monitor1394 */
/* */
/************************************************/
using UnityEngine;
@@ -11,10 +11,10 @@ namespace XCharts
{
internal static class ThemeHelper
{
public static Color32 GetBackgroundColor(ThemeInfo themeInfo, Background background)
public static Color32 GetBackgroundColor(ChartTheme theme, Background background)
{
if (background.show && background.runtimeActive && background.hideThemeBackgroundColor) return ChartConst.clearColor32;
else return themeInfo.backgroundColor;
if (background.show && background.hideThemeBackgroundColor) return ChartConst.clearColor32;
else return theme.backgroundColor;
}
}
}

View File

@@ -1,34 +0,0 @@
/******************************************/
/* */
/* Copyright (c) 2018 monitor1394 */
/* https://github.com/monitor1394 */
/* */
/******************************************/
using UnityEngine;
using UnityEngine.UI;
namespace XCharts
{
internal static class TitleHelper
{
public static Font GetTextFont(Title title, ThemeInfo themeInfo)
{
return (title.textStyle.font != null) ? title.textStyle.font : themeInfo.font;
}
public static Color GetTextColor(Title title, ThemeInfo themeInfo)
{
return !ChartHelper.IsClearColor(title.textStyle.color) ? title.textStyle.color : (Color)themeInfo.titleTextColor;
}
public static Font GetSubTextFont(Title title, ThemeInfo themeInfo)
{
return (title.subTextStyle.font != null) ? title.subTextStyle.font : themeInfo.font;
}
public static Color GetSubTextColor(Title title, ThemeInfo themeInfo)
{
return !ChartHelper.IsClearColor(title.subTextStyle.color) ? title.subTextStyle.color : (Color)themeInfo.titleSubTextColor;
}
}
}

View File

@@ -1,9 +1,9 @@
/******************************************/
/* */
/* Copyright (c) 2018 monitor1394 */
/* https://github.com/monitor1394 */
/* */
/******************************************/
/************************************************/
/* */
/* Copyright (c) 2018 - 2021 monitor1394 */
/* https://github.com/monitor1394 */
/* */
/************************************************/
using UnityEngine;
using UnityEngine.UI;

View File

@@ -1,9 +1,9 @@
/******************************************/
/* */
/* Copyright (c) 2018 monitor1394 */
/* https://github.com/monitor1394 */
/* */
/******************************************/
/************************************************/
/* */
/* Copyright (c) 2018 - 2021 monitor1394 */
/* https://github.com/monitor1394 */
/* */
/************************************************/
using System.Text;
using UnityEngine;
@@ -13,7 +13,7 @@ namespace XCharts
internal static class TooltipHelper
{
private static void InitScatterTooltip(ref StringBuilder sb, Tooltip tooltip, Serie serie, int index,
ThemeInfo themeInfo)
ChartTheme theme)
{
if (!tooltip.runtimeSerieIndex.ContainsKey(serie.index)) return;
var dataIndexList = tooltip.runtimeSerieIndex[serie.index];
@@ -29,7 +29,7 @@ namespace XCharts
float xValue, yValue;
serie.GetXYData(dataIndex, null, out xValue, out yValue);
sb.Append("<color=#").Append(themeInfo.GetColorStr(serie.index)).Append(">● </color>");
sb.Append("<color=#").Append(theme.GetColorStr(serie.index)).Append(">● </color>");
if (!string.IsNullOrEmpty(serieData.name))
sb.Append(serieData.name).Append(": ");
sb.AppendFormat("({0},{1})", ChartCached.FloatToStr(xValue, numericFormatter),
@@ -43,7 +43,7 @@ namespace XCharts
private static void InitPieTooltip(ref StringBuilder sb, Tooltip tooltip, Serie serie, int index,
ThemeInfo themeInfo)
ChartTheme theme)
{
if (tooltip.runtimeDataIndex[serie.index] < 0) return;
string key = serie.data[index].name;
@@ -56,14 +56,14 @@ namespace XCharts
{
sb.Append(serie.name).Append(FormatterHelper.PH_NN);
}
sb.Append("<color=#").Append(themeInfo.GetColorStr(index)).Append(">● </color>");
sb.Append("<color=#").Append(theme.GetColorStr(index)).Append(">● </color>");
if (!string.IsNullOrEmpty(key))
sb.Append(key).Append(": ");
sb.Append(ChartCached.FloatToStr(value, numericFormatter));
}
private static void InitRingTooltip(ref StringBuilder sb, Tooltip tooltip, Serie serie, int index,
ThemeInfo themeInfo)
ChartTheme theme)
{
var serieData = serie.GetSerieData(index);
var numericFormatter = GetItemNumericFormatter(tooltip, serie, serieData);
@@ -71,7 +71,7 @@ namespace XCharts
sb.Length = 0;
if (!string.IsNullOrEmpty(serieData.name))
{
sb.Append("<color=#").Append(themeInfo.GetColorStr(index)).Append(">● </color>")
sb.Append("<color=#").Append(theme.GetColorStr(index)).Append(">● </color>")
.Append(serieData.name).Append(": ").Append(ChartCached.FloatToStr(value, numericFormatter));
}
else
@@ -79,11 +79,36 @@ namespace XCharts
sb.Append(ChartCached.FloatToStr(value, numericFormatter));
}
}
private static void InitGaugeTooltip(ref StringBuilder sb, Tooltip tooltip, Serie serie, int index,
ChartTheme theme)
{
if (tooltip.runtimeGridIndex >= 0) return;
if (serie.index != index || serie.type != SerieType.Gauge) return;
var serieData = serie.GetSerieData(0);
var numericFormatter = GetItemNumericFormatter(tooltip, serie, serieData);
float value = serieData.data[1];
sb.Length = 0;
if (!string.IsNullOrEmpty(serie.name))
{
sb.Append(serie.name).Append("\n");
}
if (!string.IsNullOrEmpty(serieData.name))
{
//sb.Append("<color=#").Append(theme.GetColorStr(index)).Append(">● </color>")
sb.Append(serieData.name).Append(": ").Append(ChartCached.FloatToStr(value, numericFormatter));
}
else
{
sb.Append(ChartCached.FloatToStr(value, numericFormatter));
}
}
public static void InitRadarTooltip(ref StringBuilder sb, Tooltip tooltip, Serie serie, Radar radar,
ThemeInfo themeInfo)
ChartTheme theme)
{
if(radar == null) return;
if (!serie.show) return;
if (tooltip.runtimeGridIndex >= 0) return;
if (serie.radarIndex != radar.index) return;
var dataIndex = tooltip.runtimeDataIndex[1];
var serieData = serie.GetSerieData(dataIndex);
@@ -109,7 +134,7 @@ namespace XCharts
numericFormatter = GetItemNumericFormatter(tooltip, serie, sd);
if (!first) sb.Append("\n");
first = false;
sb.Append("<color=#").Append(themeInfo.GetColorStr(i)).Append(">● </color>");
sb.Append("<color=#").Append(theme.GetColorStr(i)).Append(">● </color>");
if (string.IsNullOrEmpty(itemFormatter))
{
if (string.IsNullOrEmpty(key)) key = radar.indicatorList[dataIndex].name;
@@ -164,7 +189,7 @@ namespace XCharts
}
private static void InitCoordinateTooltip(ref StringBuilder sb, Tooltip tooltip, Serie serie, int index,
ThemeInfo themeInfo, bool isCartesian, DataZoom dataZoom = null)
ChartTheme theme, bool isCartesian, DataZoom dataZoom = null)
{
string key = serie.name;
float xValue, yValue;
@@ -185,38 +210,39 @@ namespace XCharts
{
var valueTxt = isIngore ? tooltip.ignoreDataDefaultContent :
ChartCached.FloatToStr(yValue, numericFormatter);
sb.Append("<color=#").Append(themeInfo.GetColorStr(serie.index)).Append(">● </color>")
sb.Append("<color=#").Append(theme.GetColorStr(serie.index)).Append(">● </color>")
.Append(key).Append(!string.IsNullOrEmpty(key) ? " : " : "")
.Append(valueTxt);
}
}
private static void InitDefaultContent(ref StringBuilder sb, Tooltip tooltip, Serie serie, int index,
string category, ThemeInfo themeInfo = null, DataZoom dataZoom = null, bool isCartesian = false,
string category, ChartTheme theme = null, DataZoom dataZoom = null, bool isCartesian = false,
Radar radar = null)
{
switch (serie.type)
{
case SerieType.Line:
case SerieType.Bar:
InitCoordinateTooltip(ref sb, tooltip, serie, index, themeInfo, isCartesian, dataZoom);
InitCoordinateTooltip(ref sb, tooltip, serie, index, theme, isCartesian, dataZoom);
break;
case SerieType.Scatter:
case SerieType.EffectScatter:
InitScatterTooltip(ref sb, tooltip, serie, index, themeInfo);
InitScatterTooltip(ref sb, tooltip, serie, index, theme);
break;
case SerieType.Radar:
InitRadarTooltip(ref sb, tooltip, serie, radar, themeInfo);
InitRadarTooltip(ref sb, tooltip, serie, radar, theme);
break;
case SerieType.Pie:
InitPieTooltip(ref sb, tooltip, serie, index, themeInfo);
InitPieTooltip(ref sb, tooltip, serie, index, theme);
break;
case SerieType.Ring:
InitRingTooltip(ref sb, tooltip, serie, index, themeInfo);
InitRingTooltip(ref sb, tooltip, serie, index, theme);
break;
case SerieType.Heatmap:
break;
case SerieType.Gauge:
InitGaugeTooltip(ref sb, tooltip, serie, index, theme);
break;
}
}
@@ -236,7 +262,7 @@ namespace XCharts
tooltip.UpdateContentPos(pos);
}
public static string GetPolarFormatterContent(Tooltip tooltip, Series series, ThemeInfo themeInfo, AngleAxis angleAxis)
public static string GetPolarFormatterContent(Tooltip tooltip, Series series, ChartTheme theme, AngleAxis angleAxis)
{
if (string.IsNullOrEmpty(tooltip.formatter))
{
@@ -260,7 +286,7 @@ namespace XCharts
{
if (formatTitle)
{
FormatterHelper.ReplaceContent(ref title, 0, tooltip.numericFormatter, serie, series, themeInfo, null, null);
FormatterHelper.ReplaceContent(ref title, 0, tooltip.numericFormatter, serie, series, theme, null, null);
}
var dataIndexList = tooltip.runtimeSerieIndex[serie.index];
@@ -274,7 +300,7 @@ namespace XCharts
serie.GetXYData(dataIndex, null, out xValue, out yValue);
if (string.IsNullOrEmpty(itemFormatter))
{
sb.Append("<color=#").Append(themeInfo.GetColorStr(serie.index)).Append(">● </color>");
sb.Append("<color=#").Append(theme.GetColorStr(serie.index)).Append(">● </color>");
if (!string.IsNullOrEmpty(serie.name))
sb.Append(serie.name).Append(": ");
sb.AppendFormat("{0}", ChartCached.FloatToStr(xValue, numericFormatter));
@@ -286,9 +312,9 @@ namespace XCharts
else
{
string content = itemFormatter;
FormatterHelper.ReplaceContent(ref content, dataIndex, tooltip.numericFormatter, serie, series, themeInfo, null, null);
FormatterHelper.ReplaceContent(ref content, dataIndex, tooltip.numericFormatter, serie, series, theme, null, null);
var dotColorIndex = serie.type == SerieType.Pie || serie.type == SerieType.Radar || serie.type == SerieType.Ring ? dataIndex : serie.index;
sb.Append(ChartCached.ColorToDotStr(themeInfo.GetColor(dotColorIndex)));
sb.Append(ChartCached.ColorToDotStr(theme.GetColor(dotColorIndex)));
sb.Append(content);
}
}
@@ -308,12 +334,12 @@ namespace XCharts
else
{
string content = tooltip.formatter;
FormatterHelper.ReplaceContent(ref content, 0, tooltip.numericFormatter, null, series, themeInfo, null, null);
FormatterHelper.ReplaceContent(ref content, 0, tooltip.numericFormatter, null, series, theme, null, null);
return content;
}
}
public static string GetFormatterContent(Tooltip tooltip, int dataIndex, Series series, ThemeInfo themeInfo,
public static string GetFormatterContent(Tooltip tooltip, int dataIndex, Series series, ChartTheme theme,
string category = null, DataZoom dataZoom = null, bool isCartesian = false, Radar radar = null)
{
if (string.IsNullOrEmpty(tooltip.formatter))
@@ -335,6 +361,7 @@ namespace XCharts
for (int i = 0; i < series.Count; i++)
{
var serie = series.GetSerie(i);
if (tooltip.runtimeGridIndex >= 0 && serie.runtimeGridIndex != tooltip.runtimeGridIndex) continue;
if (serie.type == SerieType.Scatter || serie.type == SerieType.EffectScatter)
{
if (serie.show && IsSelectedSerie(tooltip, serie.index))
@@ -344,24 +371,24 @@ namespace XCharts
if (string.IsNullOrEmpty(itemFormatter))
{
if (!first) sb.Append(FormatterHelper.PH_NN);
InitDefaultContent(ref sb, tooltip, serie, dataIndex, category, themeInfo, dataZoom, isCartesian, radar);
InitDefaultContent(ref sb, tooltip, serie, dataIndex, category, theme, dataZoom, isCartesian, radar);
first = false;
continue;
}
var itemTitle = title;
if (!string.IsNullOrEmpty(itemTitle))
{
FormatterHelper.ReplaceContent(ref itemTitle, dataIndex, tooltip.numericFormatter, serie, series, themeInfo, category, dataZoom);
FormatterHelper.ReplaceContent(ref itemTitle, dataIndex, tooltip.numericFormatter, serie, series, theme, category, dataZoom);
sb.Append(itemTitle).Append(FormatterHelper.PH_NN);
}
var dataIndexList = tooltip.runtimeSerieIndex[serie.index];
foreach (var tempIndex in dataIndexList)
{
string content = itemFormatter;
var foundDot = FormatterHelper.ReplaceContent(ref content, tempIndex, tooltip.numericFormatter, serie, series, themeInfo, category, dataZoom);
var foundDot = FormatterHelper.ReplaceContent(ref content, tempIndex, tooltip.numericFormatter, serie, series, theme, category, dataZoom);
if (!foundDot)
{
sb.Append(ChartCached.ColorToDotStr(themeInfo.GetColor(serie.index)));
sb.Append(ChartCached.ColorToDotStr(theme.GetColor(serie.index)));
}
sb.Append(content).Append(FormatterHelper.PH_NN);
}
@@ -369,28 +396,38 @@ namespace XCharts
}
else if (IsNeedTooltipSerie(serie, tooltip))
{
var serieData = serie.GetSerieData(dataIndex, dataZoom);
if (serieData == null) continue;
var itemFormatter = GetItemFormatter(tooltip, serie, serieData);
var itemFormatter = string.Empty;
if (serie.type == SerieType.Gauge)
{
var serieData = serie.GetSerieData(0, dataZoom);
if (serieData == null) continue;
itemFormatter = GetItemFormatter(tooltip, serie, serieData);
}
else
{
var serieData = serie.GetSerieData(dataIndex, dataZoom);
if (serieData == null) continue;
itemFormatter = GetItemFormatter(tooltip, serie, serieData);
}
needCategory = needCategory || (serie.type == SerieType.Line || serie.type == SerieType.Bar);
if (formatTitle)
{
FormatterHelper.ReplaceContent(ref title, dataIndex, tooltip.numericFormatter, serie, series, themeInfo, category, dataZoom);
FormatterHelper.ReplaceContent(ref title, dataIndex, tooltip.numericFormatter, serie, series, theme, category, dataZoom);
}
if (serie.show)
{
if (string.IsNullOrEmpty(itemFormatter) || serie.type == SerieType.Radar)
{
if (!first) sb.Append(FormatterHelper.PH_NN);
InitDefaultContent(ref sb, tooltip, serie, dataIndex, category, themeInfo, dataZoom, isCartesian, radar);
InitDefaultContent(ref sb, tooltip, serie, dataIndex, category, theme, dataZoom, isCartesian, radar);
first = false;
continue;
}
string content = itemFormatter;
FormatterHelper.ReplaceContent(ref content, dataIndex, tooltip.numericFormatter, serie, series, themeInfo, category, dataZoom);
FormatterHelper.ReplaceContent(ref content, dataIndex, tooltip.numericFormatter, serie, series, theme, category, dataZoom);
if (!first) sb.Append(FormatterHelper.PH_NN);
var dotColorIndex = serie.type == SerieType.Pie || serie.type == SerieType.Radar || serie.type == SerieType.Ring ? dataIndex : i;
sb.Append(ChartCached.ColorToDotStr(themeInfo.GetColor(dotColorIndex)));
sb.Append(ChartCached.ColorToDotStr(theme.GetColor(dotColorIndex)));
sb.Append(content);
first = false;
}
@@ -416,7 +453,7 @@ namespace XCharts
else
{
string content = tooltip.formatter;
FormatterHelper.ReplaceContent(ref content, dataIndex, tooltip.numericFormatter, null, series, themeInfo, category, dataZoom);
FormatterHelper.ReplaceContent(ref content, dataIndex, tooltip.numericFormatter, null, series, theme, category, dataZoom);
return content;
}
}
@@ -426,7 +463,14 @@ namespace XCharts
//if (serie.type == SerieType.Pie || serie.type == SerieType.Radar || serie.type == SerieType.Ring)
if (serie.type == SerieType.Pie || serie.type == SerieType.Ring)
{
return tooltip.runtimeDataIndex[serie.index] >= 0;
if (serie.index < tooltip.runtimeDataIndex.Count)
return tooltip.runtimeDataIndex[serie.index] >= 0;
else
return false;
}
else if (serie.type == SerieType.Gauge)
{
return serie.index == tooltip.runtimeDataIndex[0];
}
else
{
@@ -457,7 +501,7 @@ namespace XCharts
else return tooltip.numericFormatter;
}
public static Color32 GetLineColor(Tooltip tooltip, ThemeInfo theme)
public static Color32 GetLineColor(Tooltip tooltip, ChartTheme theme)
{
var lineStyle = tooltip.lineStyle;
if (!ChartHelper.IsClearColor(lineStyle.color))
@@ -466,10 +510,34 @@ namespace XCharts
}
else
{
var color = theme.tooltipLineColor;
var color = theme.tooltip.lineColor;
ChartHelper.SetColorOpacity(ref color, lineStyle.opacity);
return color;
}
}
public static Color GetTexColor(Tooltip tooltip, ComponentTheme theme)
{
if (!ChartHelper.IsClearColor(tooltip.textStyle.color))
{
return tooltip.textStyle.color;
}
else
{
return theme.textColor;
}
}
public static Color GetTexBackgroundColor(Tooltip tooltip, ComponentTheme theme)
{
if (!ChartHelper.IsClearColor(tooltip.textStyle.backgroundColor))
{
return tooltip.textStyle.backgroundColor;
}
else
{
return theme.textBackgroundColor;
}
}
}
}

View File

@@ -1,9 +1,9 @@
/******************************************/
/* */
/* Copyright (c) 2018 monitor1394 */
/* https://github.com/monitor1394 */
/* */
/******************************************/
/************************************************/
/* */
/* Copyright (c) 2018 - 2021 monitor1394 */
/* https://github.com/monitor1394 */
/* */
/************************************************/
using System.Collections.Generic;
using UnityEngine;
@@ -12,12 +12,12 @@ namespace XCharts
{
public static class VesselHelper
{
internal static Color32 GetColor(Vessel vessel, Serie serie, ThemeInfo themeInfo, List<string> legendRealShowName)
internal static Color32 GetColor(Vessel vessel, Serie serie, ChartTheme theme, List<string> legendRealShowName)
{
if (serie != null && vessel.autoColor)
{
var colorIndex = legendRealShowName.IndexOf(serie.name);
return SerieHelper.GetItemColor(serie, null, themeInfo, colorIndex, false);
return SerieHelper.GetItemColor(serie, null, theme, colorIndex, false);
}
else
{

View File

@@ -1,9 +1,9 @@
/******************************************/
/* */
/* Copyright (c) 2018 monitor1394 */
/* https://github.com/monitor1394 */
/* */
/******************************************/
/************************************************/
/* */
/* Copyright (c) 2018 - 2021 monitor1394 */
/* https://github.com/monitor1394 */
/* */
/************************************************/
using System;
using System.Collections.Generic;
@@ -80,22 +80,24 @@ namespace XCharts
case VisualMap.Direction.X:
var min = axis.runtimeMinValue;
var max = axis.runtimeMaxValue;
value = min + (pos.x - chart.coordinateX) / chart.coordinateWidth * (max - min);
var grid = chart.GetAxisGridOrDefault(axis);
value = min + (pos.x - grid.runtimeX) / grid.runtimeWidth * (max - min);
break;
case VisualMap.Direction.Y:
if (axis is YAxis)
{
var yAxis = chart.xAxises[axis.index];
var yAxis = chart.xAxes[axis.index];
min = yAxis.runtimeMinValue;
max = yAxis.runtimeMaxValue;
}
else
{
var yAxis = chart.yAxises[axis.index];
var yAxis = chart.yAxes[axis.index];
min = yAxis.runtimeMinValue;
max = yAxis.runtimeMaxValue;
}
value = min + (pos.y - chart.coordinateY) / chart.coordinateHeight * (max - min);
grid = chart.GetAxisGridOrDefault(axis);
value = min + (pos.y - grid.runtimeY) / grid.runtimeHeight * (max - min);
break;
}
var color = visualMap.GetColor(value);
@@ -107,7 +109,8 @@ namespace XCharts
{
var min = axis.runtimeMinValue;
var max = axis.runtimeMaxValue;
var value = min + (pos.x - chart.coordinateX) / chart.coordinateWidth * (max - min);
var grid = chart.GetAxisGridOrDefault(axis);
var value = min + (pos.x - grid.runtimeX) / grid.runtimeWidth * (max - min);
var rate = (value - min) / (max - min);
var color = itemStyle.GetGradientColor(rate, defaultColor);
if (ChartHelper.IsClearColor(color)) return defaultColor;
@@ -118,7 +121,8 @@ namespace XCharts
{
var min = axis.runtimeMinValue;
var max = axis.runtimeMaxValue;
var value = min + (pos.x - chart.coordinateX) / chart.coordinateWidth * (max - min);
var grid = chart.GetAxisGridOrDefault(axis);
var value = min + (pos.x - grid.runtimeX) / grid.runtimeWidth * (max - min);
var rate = (value - min) / (max - min);
var color = lineStyle.GetGradientColor(rate, defaultColor);
if (ChartHelper.IsClearColor(color)) return defaultColor;

View File

@@ -0,0 +1,28 @@
/************************************************/
/* */
/* Copyright (c) 2018 - 2021 monitor1394 */
/* https://github.com/monitor1394 */
/* */
/************************************************/
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;
namespace XCharts
{
public interface IDrawSerie
{
void InitComponent();
void CheckComponent();
void Update();
void DrawBase(VertexHelper vh);
void DrawSerie(VertexHelper vh, Serie serie);
void RefreshLabel();
bool CheckTootipArea(Vector2 local);
bool OnLegendButtonClick(int index, string legendName, bool show);
bool OnLegendButtonEnter(int index, string legendName);
bool OnLegendButtonExit(int index, string legendName);
void OnPointerDown(PointerEventData eventData);
}
}

View File

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

View File

@@ -1,17 +0,0 @@
/******************************************/
/* */
/* Copyright (c) 2018 monitor1394 */
/* https://github.com/monitor1394 */
/* */
/******************************************/
namespace XCharts
{
/// <summary>
/// 从json导入数据接口
/// </summary>
public interface IJsonData
{
void ParseJsonData(string json);
}
}

View File

@@ -1,9 +1,9 @@
/******************************************/
/* */
/* Copyright (c) 2018 monitor1394 */
/* https://github.com/monitor1394 */
/* */
/******************************************/
/************************************************/
/* */
/* Copyright (c) 2018 - 2021 monitor1394 */
/* https://github.com/monitor1394 */
/* */
/************************************************/
namespace XCharts
{

View File

@@ -1,21 +1,21 @@
/******************************************/
/* */
/* Copyright (c) 2018 monitor1394 */
/* https://github.com/monitor1394 */
/* */
/******************************************/
/************************************************/
/* */
/* Copyright (c) 2018 - 2021 monitor1394 */
/* https://github.com/monitor1394 */
/* */
/************************************************/
using UnityEngine;
using UnityEngine.UI;
namespace XCharts
{
public class LabelObject : ChartObject
public class ChartLabel : ChartObject
{
private bool m_LabelAutoSize = true;
private float m_LabelPaddingLeftRight = 3f;
private float m_LabelPaddingTopBottom = 3f;
private Text m_LabelText;
private ChartText m_LabelText;
private RectTransform m_LabelRect;
private RectTransform m_IconRect;
private RectTransform m_ObjectRect;
@@ -24,9 +24,9 @@ namespace XCharts
public GameObject gameObject { get { return m_GameObject; } }
public Image icon { get { return m_IconImage; } }
public Text label { get { return m_LabelText; } }
public ChartText label { get { return m_LabelText; } }
public LabelObject()
public ChartLabel()
{
}
@@ -36,8 +36,8 @@ namespace XCharts
m_LabelAutoSize = autoSize;
m_LabelPaddingLeftRight = paddingLeftRight;
m_LabelPaddingTopBottom = paddingTopBottom;
m_LabelText = labelObj.GetComponentInChildren<Text>();
m_LabelRect = m_LabelText.GetComponent<RectTransform>();
m_LabelText = new ChartText(labelObj);
m_LabelRect = m_LabelText.gameObject.GetComponent<RectTransform>();
m_ObjectRect = labelObj.GetComponent<RectTransform>();
}
@@ -95,12 +95,12 @@ namespace XCharts
public void SetLabelColor(Color color)
{
if (m_LabelText) m_LabelText.color = color;
if (m_LabelText != null) m_LabelText.SetColor(color);
}
public void SetLabelRotate(float rotate)
{
if (m_LabelText) m_LabelText.transform.localEulerAngles = new Vector3(0, 0, rotate);
if (m_LabelText != null) m_LabelText.SetLocalEulerAngles(new Vector3(0, 0, rotate));
}
public void SetPosition(Vector3 position)
@@ -122,7 +122,7 @@ namespace XCharts
}
public void SetLabelActive(bool flag)
{
if (m_LabelText) ChartHelper.SetActive(m_LabelText, flag);
if (m_LabelText != null) m_LabelText.SetActive(flag);
}
public void SetIconActive(bool flag)
{
@@ -131,14 +131,15 @@ namespace XCharts
public bool SetText(string text)
{
if (m_LabelText && !m_LabelText.text.Equals(text))
if (m_LabelRect == null) return false;
if (m_LabelText != null && !m_LabelText.GetText().Equals(text))
{
m_LabelText.text = text;
m_LabelText.SetText(text);
if (m_LabelAutoSize)
{
var newSize = string.IsNullOrEmpty(text) ? Vector2.zero :
new Vector2(m_LabelText.preferredWidth + m_LabelPaddingLeftRight * 2,
m_LabelText.preferredHeight + m_LabelPaddingTopBottom * 2);
new Vector2(m_LabelText.GetPreferredWidth() + m_LabelPaddingLeftRight * 2,
m_LabelText.GetPreferredHeight() + m_LabelPaddingTopBottom * 2);
var sizeChange = newSize.x != m_LabelRect.sizeDelta.x || newSize.y != m_LabelRect.sizeDelta.y;
if (sizeChange)
{

View File

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

View File

@@ -1,9 +1,9 @@
/******************************************/
/* */
/* Copyright (c) 2018 monitor1394 */
/* https://github.com/monitor1394 */
/* */
/******************************************/
/************************************************/
/* */
/* Copyright (c) 2018 - 2021 monitor1394 */
/* https://github.com/monitor1394 */
/* */
/************************************************/
using System;
using UnityEngine;

View File

@@ -0,0 +1,255 @@
/************************************************/
/* */
/* Copyright (c) 2018 - 2021 monitor1394 */
/* https://github.com/monitor1394 */
/* */
/************************************************/
using UnityEngine;
using UnityEngine.UI;
#if dUI_TextMeshPro
using TMPro;
#endif
namespace XCharts
{
public class ChartText
{
private Text m_Text;
private TextGenerationSettings m_RelatedTextSettings;
public Text text
{
get { return m_Text; }
set
{
m_Text = value;
if (value != null)
{
m_RelatedTextSettings = m_Text.GetGenerationSettings(Vector2.zero);
}
}
}
#if dUI_TextMeshPro
private TextMeshProUGUI m_TMPText;
public TextMeshProUGUI tmpText { get { return m_TMPText; } set { m_TMPText = value; } }
#endif
public GameObject gameObject
{
get
{
#if dUI_TextMeshPro
if (m_TMPText != null) return m_TMPText.gameObject;
#else
if (m_Text != null) return m_Text.gameObject;
#endif
return null;
}
}
public ChartText()
{
}
public ChartText(GameObject textParent)
{
#if dUI_TextMeshPro
m_TMPText = textParent.GetComponentInChildren<TextMeshProUGUI>();
if (m_TMPText == null)
{
Debug.LogError("can't find TextMeshProUGUI component:" + textParent);
}
#else
m_Text = textParent.GetComponentInChildren<Text>();
if (m_Text == null)
{
Debug.LogError("can't find Text component:" + textParent);
}
#endif
}
public void SetFontSize(float fontSize)
{
#if dUI_TextMeshPro
if (m_TMPText != null) m_TMPText.fontSize = fontSize;
#else
if (m_Text != null) m_Text.fontSize = (int)fontSize;
#endif
}
public void SetText(string text)
{
if (text == null) text = string.Empty;
else text = text.Replace("\\n", "\n");
#if dUI_TextMeshPro
if(m_TMPText != null) m_TMPText.text = text;
#else
if (m_Text != null) m_Text.text = text;
#endif
}
public string GetText()
{
#if dUI_TextMeshPro
if (m_TMPText != null) return m_TMPText.text;
#else
if (m_Text != null) return m_Text.text;
#endif
return string.Empty;
}
public void SetColor(Color color)
{
#if dUI_TextMeshPro
if (m_TMPText != null) m_TMPText.color = color;
#else
if (m_Text != null) m_Text.color = color;
#endif
}
public void SetLineSpacing(float lineSpacing)
{
#if dUI_TextMeshPro
if (m_TMPText != null) m_TMPText.lineSpacing = lineSpacing;
#else
if (m_Text != null) m_Text.lineSpacing = lineSpacing;
#endif
}
public void SetActive(bool flag)
{
#if dUI_TextMeshPro
//m_TMPText.gameObject.SetActive(flag);
if (m_TMPText != null) ChartHelper.SetActive(m_TMPText.gameObject, flag);
#else
//m_Text.gameObject.SetActive(flag);
if (m_Text != null) ChartHelper.SetActive(m_Text.gameObject, flag);
#endif
}
public void SetLocalPosition(Vector3 position)
{
#if dUI_TextMeshPro
if (m_TMPText != null) m_TMPText.transform.localPosition = position;
#else
if (m_Text != null) m_Text.transform.localPosition = position;
#endif
}
public void SetSizeDelta(Vector2 sizeDelta)
{
#if dUI_TextMeshPro
if (m_TMPText != null) m_TMPText.GetComponent<RectTransform>().sizeDelta = sizeDelta;
#else
if (m_Text != null) m_Text.GetComponent<RectTransform>().sizeDelta = sizeDelta;
#endif
}
public void SetLocalEulerAngles(Vector3 position)
{
#if dUI_TextMeshPro
if (m_TMPText != null) m_TMPText.transform.localEulerAngles = position;
#else
if (m_Text != null) m_Text.transform.localEulerAngles = position;
#endif
}
public void SetAlignment(TextAnchor alignment)
{
#if dUI_TextMeshPro
if (m_TMPText == null) return;
switch (alignment)
{
case TextAnchor.LowerCenter: m_TMPText.alignment = TextAlignmentOptions.Bottom; break;
case TextAnchor.LowerLeft: m_TMPText.alignment = TextAlignmentOptions.BottomLeft; break;
case TextAnchor.LowerRight: m_TMPText.alignment = TextAlignmentOptions.BottomRight; break;
case TextAnchor.MiddleCenter: m_TMPText.alignment = TextAlignmentOptions.Center; break;
case TextAnchor.MiddleLeft: m_TMPText.alignment = TextAlignmentOptions.Left; break;
case TextAnchor.MiddleRight: m_TMPText.alignment = TextAlignmentOptions.Right; break;
case TextAnchor.UpperCenter: m_TMPText.alignment = TextAlignmentOptions.Top; break;
case TextAnchor.UpperLeft: m_TMPText.alignment = TextAlignmentOptions.TopLeft; break;
case TextAnchor.UpperRight: m_TMPText.alignment = TextAlignmentOptions.TopRight; break;
}
#else
if (m_Text != null) m_Text.alignment = alignment;
#endif
}
public void SetFont(Font font)
{
if (m_Text) m_Text.font = font;
}
public void SetFontStyle(FontStyle fontStyle)
{
#if dUI_TextMeshPro
if (m_TMPText == null) return;
switch (fontStyle)
{
case FontStyle.Normal: m_TMPText.fontStyle = FontStyles.Normal; break;
case FontStyle.Bold: m_TMPText.fontStyle = FontStyles.Bold; break;
case FontStyle.BoldAndItalic: m_TMPText.fontStyle = FontStyles.Bold | FontStyles.Italic; break;
case FontStyle.Italic: m_TMPText.fontStyle = FontStyles.Italic; break;
}
#else
if (m_Text != null) m_Text.fontStyle = fontStyle;
#endif
}
public void SetFontAndSizeAndStyle(TextStyle textStyle, ComponentTheme theme)
{
#if dUI_TextMeshPro
if (m_TMPText == null) return;
m_TMPText.font = textStyle.tmpFont == null ? theme.tmpFont : textStyle.tmpFont;
m_TMPText.fontSize = textStyle.fontSize == 0 ? theme.fontSize : textStyle.fontSize;
m_TMPText.fontStyle = textStyle.tmpFontStyle;
#else
if (m_Text != null)
{
m_Text.font = textStyle.font == null ? theme.font : textStyle.font;
m_Text.fontSize = textStyle.fontSize == 0 ? theme.fontSize : textStyle.fontSize;
m_Text.fontStyle = textStyle.fontStyle;
}
#endif
}
public float GetPreferredWidth(string content)
{
#if dUI_TextMeshPro
if (m_TMPText != null) return 0; // TODO:
#else
if (m_Text != null) return m_Text.cachedTextGenerator.GetPreferredWidth(content, m_RelatedTextSettings);
#endif
return 0;
}
public float GetPreferredWidth()
{
#if dUI_TextMeshPro
if (m_TMPText != null) return m_TMPText.preferredWidth;
#else
if (m_Text != null) return m_Text.preferredWidth;
#endif
return 0;
}
public float GetPreferredHeight()
{
#if dUI_TextMeshPro
if (m_TMPText != null) return m_TMPText.preferredHeight;
#else
if (m_Text != null) return m_Text.preferredHeight;
#endif
return 0;
}
#if dUI_TextMeshPro
public void SetAlignment(TextAlignmentOptions alignment)
{
if (m_TMPText != null) m_TMPText.alignment = alignment;
}
public void SetFont(TMP_FontAsset font)
{
if (m_TMPText != null) m_TMPText.font = font;
}
#endif
}
}

View File

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

View File

@@ -1,9 +1,9 @@
/******************************************/
/* */
/* Copyright (c) 2018 monitor1394 */
/* https://github.com/monitor1394 */
/* */
/******************************************/
/************************************************/
/* */
/* Copyright (c) 2018 - 2021 monitor1394 */
/* https://github.com/monitor1394 */
/* */
/************************************************/
using System;
using UnityEngine;
using UnityEngine.UI;
@@ -18,7 +18,7 @@ namespace XCharts
private GameObject m_GameObject;
private Button m_Button;
private Image m_Icon;
private Text m_Text;
private ChartText m_Text;
private Image m_TextBackground;
private RectTransform m_Rect;
private RectTransform m_IconRect;
@@ -71,7 +71,7 @@ namespace XCharts
m_Rect = obj.GetComponent<RectTransform>();
m_Icon = obj.transform.Find("icon").gameObject.GetComponent<Image>();
m_TextBackground = obj.transform.Find("content").gameObject.GetComponent<Image>();
m_Text = obj.transform.Find("content/Text").gameObject.GetComponent<Text>();
m_Text = new ChartText(obj);
m_IconRect = m_Icon.gameObject.GetComponent<RectTransform>();
m_TextRect = m_Text.gameObject.GetComponent<RectTransform>();
m_TextBackgroundRect = m_TextBackground.gameObject.GetComponent<RectTransform>();
@@ -87,7 +87,7 @@ namespace XCharts
m_Icon = icon;
}
public void SetText(Text text)
public void SetText(ChartText text)
{
m_Text = text;
}
@@ -123,9 +123,9 @@ namespace XCharts
public void SetContentColor(Color color)
{
if (m_Text)
if (m_Text != null)
{
m_Text.color = color;
m_Text.SetColor(color);
}
}
@@ -149,20 +149,20 @@ namespace XCharts
public bool SetContent(string content)
{
if (m_Text && !m_Text.text.Equals(content))
if (m_Text != null && !m_Text.GetText().Equals(content))
{
m_Text.text = content;
m_Text.SetText(content);
if (m_LabelAutoSize)
{
var newSize = string.IsNullOrEmpty(content) ? Vector2.zero :
new Vector2(m_Text.preferredWidth, m_Text.preferredHeight);
new Vector2(m_Text.GetPreferredWidth(), m_Text.GetPreferredHeight());
var sizeChange = newSize.x != m_TextRect.sizeDelta.x || newSize.y != m_TextRect.sizeDelta.y;
if (sizeChange)
{
m_TextRect.sizeDelta = newSize;
m_TextRect.anchoredPosition3D = new Vector3(m_LabelPaddingLeftRight, 0);
m_TextBackgroundRect.sizeDelta = new Vector2(m_Text.preferredWidth + m_LabelPaddingLeftRight * 2,
m_Text.preferredHeight + m_LabelPaddingTopBottom * 2 - 4);
m_TextBackgroundRect.sizeDelta = new Vector2(m_Text.GetPreferredWidth() + m_LabelPaddingLeftRight * 2,
m_Text.GetPreferredHeight() + m_LabelPaddingTopBottom * 2 - 4);
m_Rect.sizeDelta = new Vector3(width, height);
}
return sizeChange;

View File

@@ -0,0 +1,79 @@
/************************************************/
/* */
/* Copyright (c) 2018 - 2021 monitor1394 */
/* https://github.com/monitor1394 */
/* */
/************************************************/
using UnityEngine;
using UnityEngine.UI;
using System;
namespace XCharts
{
public partial class Painter : MaskableGraphic
{
public enum Type
{
Base,
Serie,
Top
}
protected int m_Index = -1;
protected Type m_Type = Type.Base;
protected bool m_Refresh;
protected Action<VertexHelper, Painter> m_OnPopulateMesh;
public Action<VertexHelper, Painter> onPopulateMesh { set { m_OnPopulateMesh = value; } }
public int index { get { return m_Index; } set { m_Index = value; } }
public Type type { get { return m_Type; } set { m_Type = value; } }
public void Refresh()
{
if (gameObject == null) return;
if (!gameObject.activeSelf) return;
m_Refresh = true;
//Debug.LogError("refresh painter:"+name);
}
public void Init()
{
raycastTarget = false;
}
public void SetActive(bool flag, bool isDebugMode = false)
{
if (gameObject.activeInHierarchy != flag)
{
gameObject.SetActive(flag);
}
// var higFlags = !flag || !isDebugMode ? HideFlags.HideInHierarchy : HideFlags.None;
// if (gameObject.hideFlags != higFlags)
// {
// gameObject.hideFlags = hideFlags;
// }
}
protected override void Awake()
{
Init();
}
internal void CheckRefresh()
{
if (m_Refresh && gameObject.activeSelf)
{
m_Refresh = false;
SetVerticesDirty();
}
}
protected override void OnPopulateMesh(VertexHelper vh)
{
vh.Clear();
if (m_OnPopulateMesh != null)
{
m_OnPopulateMesh(vh, this);
}
}
}
}

View File

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

View File

@@ -1,9 +1,9 @@
/******************************************/
/* */
/* Copyright (c) 2018 monitor1394 */
/* https://github.com/monitor1394 */
/* */
/******************************************/
/************************************************/
/* */
/* Copyright (c) 2018 - 2021 monitor1394 */
/* https://github.com/monitor1394 */
/* */
/************************************************/
namespace XCharts
{

View File

@@ -1,9 +1,9 @@
/******************************************/
/* */
/* Copyright (c) 2018 monitor1394 */
/* https://github.com/monitor1394 */
/* */
/******************************************/
/************************************************/
/* */
/* Copyright (c) 2018 - 2021 monitor1394 */
/* https://github.com/monitor1394 */
/* */
/************************************************/
using System.Collections.Generic;
using UnityEngine;

View File

@@ -1,9 +1,9 @@
/******************************************/
/* */
/* Copyright (c) 2018 monitor1394 */
/* https://github.com/monitor1394 */
/* */
/******************************************/
/************************************************/
/* */
/* Copyright (c) 2018 - 2021 monitor1394 */
/* https://github.com/monitor1394 */
/* */
/************************************************/
using System.Collections.Generic;
using UnityEngine;

View File

@@ -1,9 +1,9 @@
/******************************************/
/* */
/* Copyright (c) 2018 monitor1394 */
/* https://github.com/monitor1394 */
/* */
/******************************************/
/************************************************/
/* */
/* Copyright (c) 2018 - 2021 monitor1394 */
/* https://github.com/monitor1394 */
/* */
/************************************************/
using UnityEngine;

View File

@@ -1,9 +1,9 @@
/******************************************/
/* */
/* Copyright (c) 2018 monitor1394 */
/* https://github.com/monitor1394 */
/* */
/******************************************/
/************************************************/
/* */
/* Copyright (c) 2018 - 2021 monitor1394 */
/* https://github.com/monitor1394 */
/* */
/************************************************/
using System.Collections.Generic;
using UnityEngine;
@@ -16,41 +16,38 @@ namespace XCharts
private static readonly Stack<GameObject> m_Stack = new Stack<GameObject>(200);
private static Dictionary<int, bool> m_ReleaseDic = new Dictionary<int, bool>(1000);
public static GameObject Get(string name, Transform parent, SerieLabel label, Font font, Color color,
float iconWidth, float iconHeight)
public static GameObject Get(string name, Transform parent, SerieLabel label, Color color,
float iconWidth, float iconHeight, ChartTheme theme)
{
GameObject element;
if (m_Stack.Count == 0 || !Application.isPlaying)
{
element = CreateSerieLabel(name, parent, label, font, color, iconWidth, iconHeight);
element = CreateSerieLabel(name, parent, label, color, iconWidth, iconHeight, theme);
}
else
{
element = m_Stack.Pop();
if (element == null)
{
element = CreateSerieLabel(name, parent, label, font, color, iconWidth, iconHeight);
element = CreateSerieLabel(name, parent, label, color, iconWidth, iconHeight, theme);
}
m_ReleaseDic.Remove(element.GetInstanceID());
element.name = name;
element.transform.SetParent(parent);
element.transform.localEulerAngles = new Vector3(0, 0, label.rotate);
var text = element.GetComponentInChildren<Text>();
text.color = color;
text.font = font;
text.fontSize = label.fontSize;
text.fontStyle = label.fontStyle;
element.transform.localEulerAngles = new Vector3(0, 0, label.textStyle.rotate);
var text = new ChartText(element);
text.SetColor(color);
text.SetFontAndSizeAndStyle(label.textStyle, theme.common);
ChartHelper.SetActive(element, true);
}
return element;
}
private static GameObject CreateSerieLabel(string name, Transform parent, SerieLabel label, Font font, Color color,
float iconWidth, float iconHeight)
private static GameObject CreateSerieLabel(string name, Transform parent, SerieLabel label, Color color,
float iconWidth, float iconHeight, ChartTheme theme)
{
var element = ChartHelper.AddSerieLabel(name, parent, font,
color, label.backgroundColor, label.fontSize, label.fontStyle, label.rotate,
label.backgroundWidth, label.backgroundHeight, 1);
var element = ChartHelper.AddSerieLabel(name, parent, label.backgroundWidth, label.backgroundHeight,
color, label.textStyle, theme);
ChartHelper.AddIcon("Icon", element.transform, iconWidth, iconHeight);
return element;
}

View File

@@ -1,9 +1,9 @@
/******************************************/
/* */
/* Copyright (c) 2018 monitor1394 */
/* https://github.com/monitor1394 */
/* */
/******************************************/
/************************************************/
/* */
/* Copyright (c) 2018 - 2021 monitor1394 */
/* https://github.com/monitor1394 */
/* */
/************************************************/
using System.Collections.Generic;
using System.Globalization;
@@ -126,7 +126,6 @@ namespace XCharts
internal static string GetXAxisName(int axisIndex, int index = -1)
{
if (axisIndex > 0) axisIndex = 2;
if (index >= 0)
{
int key = (axisIndex + 1) * 10000 + index;
@@ -145,7 +144,6 @@ namespace XCharts
internal static string GetYAxisName(int axisIndex, int index = -1)
{
if (axisIndex > 0) axisIndex = 2;
if (index >= 0)
{
int key = (axisIndex + 1) * 10000 + index;

View File

@@ -1,9 +1,9 @@
/******************************************/
/* */
/* Copyright (c) 2018 monitor1394 */
/* https://github.com/monitor1394 */
/* */
/******************************************/
/************************************************/
/* */
/* Copyright (c) 2018 - 2021 monitor1394 */
/* https://github.com/monitor1394 */
/* */
/************************************************/
using UnityEngine;

File diff suppressed because it is too large Load Diff

View File

@@ -1,9 +1,9 @@
/******************************************/
/* */
/* Copyright (c) 2018 monitor1394 */
/* https://github.com/monitor1394 */
/* */
/******************************************/
/************************************************/
/* */
/* Copyright (c) 2018 - 2021 monitor1394 */
/* https://github.com/monitor1394 */
/* */
/************************************************/
using System.Text;
using System;
@@ -12,6 +12,9 @@ using System.Text.RegularExpressions;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;
#if dUI_TextMeshPro
using TMPro;
#endif
#if UNITY_EDITOR
using UnityEditor;
#endif
@@ -139,6 +142,21 @@ namespace XCharts
return name;
}
public static void RemoveComponent<T>(GameObject gameObject)
{
var component = gameObject.GetComponent<T>();
if (component != null)
{
#if UNITY_EDITOR
if (!Application.isPlaying)
GameObject.DestroyImmediate(component as GameObject);
else
GameObject.Destroy(component as GameObject);
#else
GameObject.Destroy(component as GameObject);
#endif
}
}
public static T GetOrAddComponent<T>(Transform transform) where T : Component
{
return GetOrAddComponent<T>(transform.gameObject);
@@ -148,9 +166,12 @@ namespace XCharts
{
if (gameObject.GetComponent<T>() == null)
{
gameObject.AddComponent<T>();
return gameObject.AddComponent<T>();
}
else
{
return gameObject.GetComponent<T>();
}
return gameObject.GetComponent<T>();
}
public static GameObject AddObject(string name, Transform parent, Vector2 anchorMin,
@@ -188,12 +209,62 @@ namespace XCharts
return obj;
}
public static void UpdateRectTransform(GameObject obj, Vector2 anchorMin,
Vector2 anchorMax, Vector2 pivot, Vector2 sizeDelta)
{
if (obj == null) return;
RectTransform rect = GetOrAddComponent<RectTransform>(obj);
rect.sizeDelta = sizeDelta;
rect.anchorMin = anchorMin;
rect.anchorMax = anchorMax;
rect.pivot = pivot;
}
public static ChartText AddTextObject(string name, Transform parent, Vector2 anchorMin, Vector2 anchorMax,
Vector2 pivot, Vector2 sizeDelta, TextStyle textStyle, ComponentTheme theme)
{
GameObject txtObj = AddObject(name, parent, anchorMin, anchorMax, pivot, sizeDelta);
txtObj.transform.localEulerAngles = new Vector3(0, 0, textStyle.rotate);
var chartText = new ChartText();
#if dUI_TextMeshPro
RemoveComponent<Text>(txtObj);
chartText.tmpText = GetOrAddComponent<TextMeshProUGUI>(txtObj);
chartText.tmpText.font = textStyle.tmpFont == null ? theme.tmpFont : textStyle.tmpFont;
chartText.tmpText.fontStyle = textStyle.tmpFontStyle;
chartText.tmpText.alignment = textStyle.tmpAlignment;
chartText.tmpText.richText = true;
chartText.tmpText.raycastTarget = false;
chartText.tmpText.enableWordWrapping = false;
#else
chartText.text = GetOrAddComponent<Text>(txtObj);
chartText.text.font = textStyle.font == null ? theme.font : textStyle.font;
chartText.text.fontStyle = textStyle.fontStyle;
chartText.text.alignment = textStyle.alignment;
chartText.text.horizontalOverflow = HorizontalWrapMode.Overflow;
chartText.text.verticalOverflow = VerticalWrapMode.Overflow;
chartText.text.supportRichText = true;
chartText.text.raycastTarget = false;
#endif
chartText.SetColor(textStyle.GetColor(theme.textColor));
chartText.SetFontSize(textStyle.fontSize > 0 ? textStyle.fontSize : theme.fontSize);
chartText.SetText("Text");
chartText.SetLineSpacing(textStyle.lineSpacing);
RectTransform rect = GetOrAddComponent<RectTransform>(txtObj);
rect.localPosition = Vector3.zero;
rect.sizeDelta = sizeDelta;
rect.anchorMin = anchorMin;
rect.anchorMax = anchorMax;
rect.pivot = pivot;
return chartText;
}
public static Text AddTextObject(string name, Transform parent, Font font, Color color,
TextAnchor anchor, Vector2 anchorMin, Vector2 anchorMax, Vector2 pivot, Vector2 sizeDelta,
int fontSize = 14, float rotate = 0, FontStyle fontStyle = FontStyle.Normal, float lineSpacing = 1)
{
GameObject txtObj = AddObject(name, parent, anchorMin, anchorMax, pivot, sizeDelta);
Text txt = GetOrAddComponent<Text>(txtObj);
var txt = GetOrAddComponent<Text>(txtObj);
txt.font = font;
txt.fontSize = fontSize;
txt.fontStyle = fontStyle;
@@ -212,9 +283,37 @@ namespace XCharts
rect.anchorMin = anchorMin;
rect.anchorMax = anchorMax;
rect.pivot = pivot;
return txtObj.GetComponent<Text>();
return txt;
}
#if dUI_TextMeshPro
public static TextMeshProUGUI AddTMPTextObject(string name, Transform parent, TMP_FontAsset font, Color color,
TextAlignmentOptions anchor, Vector2 anchorMin, Vector2 anchorMax, Vector2 pivot, Vector2 sizeDelta,
int fontSize = 14, float rotate = 0, FontStyles fontStyle = FontStyles.Normal, float lineSpacing = 1)
{
GameObject txtObj = AddObject(name, parent, anchorMin, anchorMax, pivot, sizeDelta);
var txt = GetOrAddComponent<TextMeshProUGUI>(txtObj);
txt.font = font;
txt.fontSize = fontSize;
txt.fontStyle = fontStyle;
txt.text = "Text";
txt.alignment = anchor;
txt.color = color;
txt.lineSpacing = lineSpacing;
txt.raycastTarget = false;
txt.enableWordWrapping = false;
txtObj.transform.localEulerAngles = new Vector3(0, 0, rotate);
RectTransform rect = GetOrAddComponent<RectTransform>(txtObj);
rect.localPosition = Vector3.zero;
rect.sizeDelta = sizeDelta;
rect.anchorMin = anchorMin;
rect.anchorMax = anchorMax;
rect.pivot = pivot;
return txt;
}
#endif
public static Button AddButtonObject(string name, Transform parent, Font font, int fontSize,
Color color, TextAnchor anchor, Vector2 anchorMin, Vector2 anchorMax, Vector2 pivot,
Vector2 sizeDelta, float lineSpacing)
@@ -230,8 +329,25 @@ namespace XCharts
return btnObj.GetComponent<Button>();
}
internal static GameObject AddTooltipContent(string name, Transform parent, Font font, int fontSize,
FontStyle fontStyle, float lineSpacing)
#if dUI_TextMeshPro
public static Button AddTMPButtonObject(string name, Transform parent, TMP_FontAsset font, int fontSize,
Color color, TextAlignmentOptions anchor, Vector2 anchorMin, Vector2 anchorMax, Vector2 pivot,
Vector2 sizeDelta, float lineSpacing)
{
GameObject btnObj = AddObject(name, parent, anchorMin, anchorMax, pivot, sizeDelta);
GetOrAddComponent<Image>(btnObj);
GetOrAddComponent<Button>(btnObj);
var txt = AddTMPTextObject("Text", btnObj.transform, font, color, anchor,
new Vector2(0, 0), new Vector2(1, 1), new Vector2(0.5f, 0.5f),
sizeDelta, fontSize, lineSpacing);
txt.rectTransform.offsetMin = Vector2.zero;
txt.rectTransform.offsetMax = Vector2.zero;
return btnObj.GetComponent<Button>();
}
#endif
internal static GameObject AddTooltipContent(string name, Transform parent, TextStyle textStyle,
ChartTheme theme)
{
var anchorMax = new Vector2(0, 1);
var anchorMin = new Vector2(0, 1);
@@ -240,10 +356,11 @@ namespace XCharts
GameObject tooltipObj = AddObject(name, parent, anchorMin, anchorMax, pivot, sizeDelta);
var img = GetOrAddComponent<Image>(tooltipObj);
img.color = Color.black;
Text txt = AddTextObject("Text", tooltipObj.transform, font, Color.white, TextAnchor.UpperLeft,
anchorMin, anchorMax, pivot, sizeDelta, fontSize, 0, fontStyle, lineSpacing);
txt.text = "Text";
txt.transform.localPosition = new Vector2(3, -3);
var txt = AddTextObject("Text", tooltipObj.transform, anchorMin, anchorMax, pivot, sizeDelta,
textStyle, theme.tooltip);
txt.SetAlignment(TextAnchor.UpperLeft);
txt.SetText("Text");
txt.SetLocalPosition(new Vector2(3, -3));
tooltipObj.transform.localPosition = Vector3.zero;
return tooltipObj;
}
@@ -260,46 +377,53 @@ namespace XCharts
return iconObj;
}
internal static GameObject AddSerieLabel(string name, Transform parent, Font font, Color textColor,
Color backgroundColor, int fontSize, FontStyle fontStyle, float rotate, float width, float height,
float lineSpacing)
internal static GameObject AddSerieLabel(string name, Transform parent, float width, float height,
Color color, TextStyle textStyle, ChartTheme theme)
{
var anchorMin = new Vector2(0.5f, 0.5f);
var anchorMax = new Vector2(0.5f, 0.5f);
var pivot = new Vector2(0.5f, 0.5f);
var sizeDelta = (width != 0 && height != 0) ? new Vector2(width, height) : new Vector2(50, fontSize + 2);
GameObject labelObj = AddObject(name, parent, anchorMin, anchorMax, pivot, sizeDelta);
//var img = GetOrAddComponent<Image>(labelObj);
//img.color = backgroundColor;
labelObj.transform.localEulerAngles = new Vector3(0, 0, rotate);
Text txt = AddTextObject("Text", labelObj.transform, font, textColor, TextAnchor.MiddleCenter,
anchorMin, anchorMax, pivot, sizeDelta, fontSize, 0, fontStyle, lineSpacing);
txt.text = "Text";
txt.transform.localPosition = new Vector2(0, 0);
txt.transform.localEulerAngles = Vector3.zero;
var sizeDelta = (width != 0 && height != 0)
? new Vector2(width, height)
: new Vector2(50, textStyle.GetFontSize(theme.common) + 2);
var labelObj = AddObject(name, parent, anchorMin, anchorMax, pivot, sizeDelta);
var txt = AddTextObject("Text", labelObj.transform, anchorMin, anchorMax, pivot, sizeDelta, textStyle,
theme.common);
txt.SetColor(color);
txt.SetAlignment(TextAnchor.MiddleCenter);
txt.SetText("Text");
txt.SetLocalPosition(new Vector2(0, 0));
txt.SetLocalEulerAngles(Vector3.zero);
labelObj.transform.localPosition = Vector3.zero;
labelObj.transform.localEulerAngles = new Vector3(0, 0, textStyle.rotate);
return labelObj;
}
internal static GameObject AddTooltipLabel(string name, Transform parent, Font font, Vector2 pivot)
internal static GameObject AddTooltipLabel(string name, Transform parent, ChartTheme theme, Vector2 pivot)
{
var anchorMax = new Vector2(0, 0);
var anchorMin = new Vector2(0, 0);
var sizeDelta = new Vector2(100, 50);
return AddTooltipLabel(name, parent, font, pivot, anchorMin, anchorMax, sizeDelta);
return AddTooltipLabel(name, parent, theme, pivot, anchorMin, anchorMax, sizeDelta);
}
internal static GameObject AddTooltipLabel(string name, Transform parent, Font font, Vector2 pivot, Vector2 anchorMin, Vector2 anchorMax, Vector2 sizeDelta)
internal static GameObject AddTooltipLabel(string name, Transform parent, ChartTheme theme, Vector2 pivot,
Vector2 anchorMin, Vector2 anchorMax, Vector2 sizeDelta)
{
GameObject labelObj = AddObject(name, parent, anchorMin, anchorMax, pivot, sizeDelta);
labelObj.transform.localPosition = Vector3.zero;
var img = GetOrAddComponent<Image>(labelObj);
img.color = Color.black;
Text txt = AddTextObject("Text", labelObj.transform, font, Color.white, TextAnchor.MiddleCenter,
#if dUI_TextMeshPro
var alignment = TextAlignmentOptions.Center;
var txt = AddTMPTextObject("Text", labelObj.transform, theme.tmpFont, Color.white, alignment,
new Vector2(0, 0), new Vector2(1, 1), new Vector2(1, 1), sizeDelta, 16);
#else
var txt = AddTextObject("Text", labelObj.transform, theme.font, Color.white, TextAnchor.MiddleCenter,
new Vector2(0, 0), new Vector2(1, 1), new Vector2(1, 1), sizeDelta, 16);
#endif
txt.GetComponent<RectTransform>().offsetMin = Vector2.zero;
txt.GetComponent<RectTransform>().offsetMax = Vector2.zero;
txt.text = "Text";
return labelObj;
}
@@ -624,7 +748,7 @@ namespace XCharts
splitNumber = 0;
if (value <= 0) return 0;
float max = 0;
while (max < value)
while (splitNumber < 12 && max < value)
{
if (isLogBaseE)
{
@@ -858,5 +982,21 @@ namespace XCharts
newColor.b = (byte)(color.b * rate);
return newColor;
}
public static bool IsPointInQuadrilateral(Vector3 P, Vector3 A, Vector3 B, Vector3 C, Vector3 D)
{
Vector3 v0 = Vector3.Cross(A - D, P - D);
Vector3 v1 = Vector3.Cross(B - A, P - A);
Vector3 v2 = Vector3.Cross(C - B, P - B);
Vector3 v3 = Vector3.Cross(D - C, P - C);
if (Vector3.Dot(v0, v1) < 0 || Vector3.Dot(v0, v2) < 0 || Vector3.Dot(v0, v3) < 0)
{
return false;
}
else
{
return true;
}
}
}
}

View File

@@ -1,59 +0,0 @@
/******************************************/
/* */
/* Copyright (c) 2018 monitor1394 */
/* https://github.com/monitor1394 */
/* */
/******************************************/
using System.Collections.Generic;
using UnityEngine;
namespace XCharts
{
internal static class PropertyUtility
{
public static bool SetColor(ref Color currentValue, Color newValue)
{
if (currentValue.r == newValue.r && currentValue.g == newValue.g && currentValue.b == newValue.b && currentValue.a == newValue.a)
return false;
currentValue = newValue;
return true;
}
public static bool SetColor(ref Color32 currentValue, Color32 newValue)
{
if (currentValue.r == newValue.r && currentValue.g == newValue.g && currentValue.b == newValue.b && currentValue.a == newValue.a)
return false;
currentValue = newValue;
return true;
}
public static bool SetStruct<T>(ref T currentValue, T newValue) where T : struct
{
if (EqualityComparer<T>.Default.Equals(currentValue, newValue))
return false;
currentValue = newValue;
return true;
}
public static bool SetClass<T>(ref T currentValue, T newValue, bool notNull = false) where T : class
{
if (notNull)
{
if (newValue == null)
{
Debug.LogError("can not be null.");
return false;
}
}
if ((currentValue == null && newValue == null) || (currentValue != null && currentValue.Equals(newValue)))
return false;
currentValue = newValue;
return true;
}
}
}

View File

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

View File

@@ -1,312 +0,0 @@
/******************************************/
/* */
/* Copyright (c) 2018 monitor1394 */
/* https://github.com/monitor1394 */
/* */
/******************************************/
using System.Text;
using System.Collections;
using System.Collections.Generic;
using System.Text.RegularExpressions;
using UnityEngine;
using UnityEngine.Networking;
using UnityEngine.SceneManagement;
namespace XCharts
{
class XChartsVersion
{
public string version = "";
public int date = 0;
public int checkdate = 0;
public string desc = "";
public string homepage = "";
}
[ExecuteInEditMode]
public class XChartsMgr : MonoBehaviour
{
public const string version = "1.6.3";
public const int date = 20210102;
[SerializeField] private string m_NowVersion;
[SerializeField] private string m_NewVersion;
[SerializeField] private List<BaseChart> m_ChartList = new List<BaseChart>();
private static XChartsMgr m_XCharts;
public static XChartsMgr Instance
{
get
{
if (m_XCharts == null)
{
var go = GameObject.Find("_xcharts_");
if (go == null)
{
go = new GameObject();
go.name = "_xcharts_";
if (Application.isPlaying)
{
DontDestroyOnLoad(go);
}
m_XCharts = go.AddComponent<XChartsMgr>();
}
else
{
m_XCharts = go.GetComponent<XChartsMgr>();
if (m_XCharts == null)
{
m_XCharts = go.AddComponent<XChartsMgr>();
}
}
m_XCharts.m_NowVersion = version + "_" + date;
}
return m_XCharts;
}
}
private XChartsMgr() { }
private void Awake()
{
SerieLabelPool.ClearAll();
m_ChartList.Clear();
}
public string changeLog { get; private set; }
public string newVersion { get { return m_NewVersion; } }
public string nowVersion { get { return m_NowVersion; } }
public string desc { get; private set; }
public string homepage { get; private set; }
public int newDate { get; private set; }
public int newCheckDate { get; private set; }
public bool isCheck { get; private set; }
public bool isNetworkError { get; private set; }
public string networkError { get; private set; }
public bool needUpdate
{
get
{
return !isNetworkError && !m_NowVersion.Equals(m_NewVersion);
}
}
public void CheckVersion()
{
StartCoroutine(GetVersion());
}
IEnumerator GetVersion()
{
isCheck = true;
isNetworkError = false;
networkError = "";
var url = "https://raw.githubusercontent.com/monitor1394/unity-ugui-XCharts/master/Assets/XCharts/package.json";
var web = UnityWebRequest.Get(url);
#if UNITY_5
yield return web.Send();
#else
yield return web.SendWebRequest();
#endif
CheckVersionWebRequest(web);
if (isNetworkError)
{
url = "https://gitee.com/monitor1394/unity-ugui-XCharts/raw/master/Assets/XCharts/package.json";
web = UnityWebRequest.Get(url);
#if UNITY_5
yield return web.Send();
#else
yield return web.SendWebRequest();
#endif
CheckVersionWebRequest(web);
}
if (needUpdate)
{
url = "https://raw.githubusercontent.com/monitor1394/unity-ugui-XCharts/master/Assets/XCharts/CHANGELOG.md";
web = UnityWebRequest.Get(url);
#if UNITY_5
yield return web.Send();
#else
yield return web.SendWebRequest();
#endif
if (!CheckLogWebRequest(web))
{
url = "https://gitee.com/monitor1394/unity-ugui-XCharts/raw/master/Assets/XCharts/CHANGELOG.md";
web = UnityWebRequest.Get(url);
#if UNITY_5
yield return web.Send();
#else
yield return web.SendWebRequest();
#endif
CheckLogWebRequest(web);
}
}
isCheck = false;
}
private void CheckVersionWebRequest(UnityWebRequest web)
{
if (IsNetworkError(web))
{
isNetworkError = true;
networkError = web.error;
m_NewVersion = "-";
}
else if (web.responseCode == 200)
{
isNetworkError = false;
var cv = JsonUtility.FromJson<XChartsVersion>(web.downloadHandler.text);
m_NewVersion = cv.version + "_" + cv.date;
newDate = cv.date;
newCheckDate = cv.checkdate;
desc = cv.desc;
homepage = cv.homepage;
}
else
{
isNetworkError = true;
if (web.responseCode > 0)
networkError = web.responseCode.ToString();
if (!string.IsNullOrEmpty(web.error))
networkError += "," + web.error;
if (string.IsNullOrEmpty(networkError))
{
networkError = "-";
}
m_NewVersion = "-";
}
web.Dispose();
}
private bool CheckLogWebRequest(UnityWebRequest web)
{
bool success = false;
if (web.responseCode == 200)
{
CheckLog(web.downloadHandler.text);
success = true;
}
web.Dispose();
return success;
}
private void CheckLog(string text)
{
StringBuilder sb = new StringBuilder();
var temp = text.Split('\n');
var regex = new Regex(".*(\\d{4}\\.\\d{2}\\.\\d{2}).*");
var checkDate = XChartsMgr.date;
foreach (var t in temp)
{
if (regex.IsMatch(t))
{
var mat = regex.Match(t);
var date = mat.Groups[1].ToString().Replace(".", "");
int logDate;
if (int.TryParse(date, out logDate))
{
if (logDate >= checkDate)
{
sb.Append(t).Append("\n");
}
else
{
break;
}
}
}
else
{
sb.Append(t).Append("\n");
}
}
changeLog = sb.ToString();
}
#if UNITY_5 || UNITY_2017_1
public bool IsNetworkError(UnityWebRequest request)
{
return request.isError && !IsHttpError(request);
}
#else
public bool IsNetworkError(UnityWebRequest request)
{
return request.isNetworkError;
}
#endif
#if UNITY_5
public bool IsHttpError(UnityWebRequest request)
{
return request.responseCode >= 400;
}
#else
public bool IsHttpError(UnityWebRequest request)
{
return request.isHttpError;
}
#endif
void OnEnable()
{
SceneManager.sceneUnloaded += OnSceneLoaded;
}
private void OnDisable()
{
SceneManager.sceneUnloaded -= OnSceneLoaded;
}
void OnSceneLoaded(Scene scene)
{
SerieLabelPool.ClearAll();
}
public void AddChart(BaseChart chart)
{
var sameNameChart = GetChart(chart.chartName);
if (sameNameChart != null)
{
var path = ChartHelper.GetFullName(sameNameChart.transform);
Debug.LogError("A chart named `" + chart.chartName + "` already exists:" + path);
}
if (!ContainsChart(chart))
{
m_ChartList.Add(chart);
}
}
public BaseChart GetChart(string chartName)
{
if (string.IsNullOrEmpty(chartName)) return null;
return m_ChartList.Find(chart => chartName.Equals(chart.chartName));
}
public List<BaseChart> GetCharts(string chartName)
{
if (string.IsNullOrEmpty(chartName)) return null;
return m_ChartList.FindAll(chart => chartName.Equals(chartName));
}
public void RemoveChart(string chartName)
{
if (string.IsNullOrEmpty(chartName)) return;
m_ChartList.RemoveAll(chart => chartName.Equals(chart.chartName));
}
public bool ContainsChart(string chartName)
{
if (string.IsNullOrEmpty(chartName)) return false;
return GetCharts(chartName) != null;
}
public bool ContainsChart(BaseChart chart)
{
return m_ChartList.Contains(chart);
}
}
}

View File

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