mirror of
https://github.com/XCharts-Team/XCharts.git
synced 2026-05-24 01:40:06 +00:00
3.0
This commit is contained in:
@@ -1,8 +1,3 @@
|
||||
|
||||
using System;
|
||||
using System.Reflection;
|
||||
using UnityEngine;
|
||||
|
||||
namespace XCharts.Runtime
|
||||
{
|
||||
[System.Serializable]
|
||||
@@ -10,7 +5,9 @@ namespace XCharts.Runtime
|
||||
[SerieConvert(typeof(Line), typeof(Pie))]
|
||||
[RequireChartComponent(typeof(GridCoord))]
|
||||
[DefaultAnimation(AnimationType.BottomToTop)]
|
||||
[SerieExtraComponent(typeof(LabelStyle), typeof(Emphasis))]
|
||||
[SerieExtraComponent(typeof(LabelStyle), typeof(EmphasisItemStyle), typeof(EmphasisLabelStyle))]
|
||||
[SerieDataExtraComponent(typeof(ItemStyle), typeof(LabelStyle), typeof(EmphasisItemStyle), typeof(EmphasisLabelStyle))]
|
||||
[SerieDataExtraField("m_Ignore")]
|
||||
public class Bar : Serie, INeedSerieContainer
|
||||
{
|
||||
public int containerIndex { get; internal set; }
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.EventSystems;
|
||||
using UnityEngine.UI;
|
||||
using XUGL;
|
||||
|
||||
@@ -47,6 +47,16 @@ namespace XCharts.Runtime
|
||||
}
|
||||
}
|
||||
|
||||
public override void OnPointerDown(PointerEventData eventData)
|
||||
{
|
||||
if (!serie.context.pointerEnter) return;
|
||||
if (serie.context.pointerItemDataIndex < 0) return;
|
||||
if (chart.onPointerClickBar != null)
|
||||
{
|
||||
chart.onPointerClickBar(eventData, serie.context.pointerItemDataIndex);
|
||||
}
|
||||
}
|
||||
|
||||
private void UpdateSerieContext()
|
||||
{
|
||||
if (m_SerieGrid == null)
|
||||
@@ -87,8 +97,8 @@ namespace XCharts.Runtime
|
||||
serie.context.pointerEnter = false;
|
||||
foreach (var serieData in serie.data)
|
||||
{
|
||||
if (serie.context.pointerAxisDataIndexs.Contains(serieData.index)
|
||||
|| serieData.context.rect.Contains(chart.pointerPos))
|
||||
if (serie.context.pointerAxisDataIndexs.Contains(serieData.index) ||
|
||||
serieData.context.rect.Contains(chart.pointerPos))
|
||||
{
|
||||
serie.context.pointerItemDataIndex = serieData.index;
|
||||
serie.context.pointerEnter = true;
|
||||
@@ -155,17 +165,17 @@ namespace XCharts.Runtime
|
||||
if (isStack)
|
||||
SeriesHelper.UpdateStackDataList(chart.series, serie, dataZoom, m_StackSerieData);
|
||||
|
||||
var barCount = chart.GetSerieBarRealCount<Bar>();
|
||||
float categoryWidth = AxisHelper.GetDataWidth(axis, axisLength, showData.Count, dataZoom);
|
||||
float barGap = chart.GetSerieBarGap<Bar>();
|
||||
float totalBarWidth = chart.GetSerieTotalWidth<Bar>(categoryWidth, barGap);
|
||||
float barWidth = serie.GetBarWidth(categoryWidth);
|
||||
float totalBarWidth = chart.GetSerieTotalWidth<Bar>(categoryWidth, barGap, barCount);
|
||||
float barWidth = serie.GetBarWidth(categoryWidth, barCount);
|
||||
float offset = (categoryWidth - totalBarWidth) * 0.5f;
|
||||
float barGapWidth = barWidth + barWidth * barGap;
|
||||
float gap = serie.barGap == -1 ? offset : offset + chart.GetSerieIndexIfStack<Bar>(serie) * barGapWidth;
|
||||
int maxCount = serie.maxShow > 0
|
||||
? (serie.maxShow > showData.Count ? showData.Count : serie.maxShow)
|
||||
: showData.Count;
|
||||
|
||||
var serieReadIndex = chart.GetSerieIndexIfStack<Bar>(serie);
|
||||
float gap = serie.barGap == -1 ? offset : offset + chart.GetSerieTotalGap<Bar>(categoryWidth, barGap, serieReadIndex);
|
||||
int maxCount = serie.maxShow > 0 ?
|
||||
(serie.maxShow > showData.Count ? showData.Count : serie.maxShow) :
|
||||
showData.Count;
|
||||
var isPercentStack = SeriesHelper.IsPercentStack<Bar>(chart.series, serie.stack);
|
||||
bool dataChanging = false;
|
||||
float dataChangeDuration = serie.animation.GetUpdateAnimationDuration();
|
||||
@@ -214,7 +224,7 @@ namespace XCharts.Runtime
|
||||
if (isPercentStack)
|
||||
{
|
||||
var valueTotal = chart.GetSerieSameStackTotalValue<Bar>(serie.stack, i);
|
||||
barHig = valueTotal != 0 ? (float)(relativedValue / valueTotal * relativedAxisLength) : 0;
|
||||
barHig = valueTotal != 0 ? (float) (relativedValue / valueTotal * relativedAxisLength) : 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -229,9 +239,9 @@ namespace XCharts.Runtime
|
||||
serieData.context.position = top;
|
||||
serieData.context.rect = Rect.MinMaxRect(plb.x + borderGapAndWidth, plb.y + borderGapAndWidth,
|
||||
prt.x - borderGapAndWidth, prt.y - borderGapAndWidth);
|
||||
serieData.context.backgroundRect = isY
|
||||
? Rect.MinMaxRect(m_SerieGrid.context.x, plb.y, m_SerieGrid.context.x + relativedAxisLength, prt.y)
|
||||
: Rect.MinMaxRect(plb.x, m_SerieGrid.context.y, prb.x, m_SerieGrid.context.y + relativedAxisLength);
|
||||
serieData.context.backgroundRect = isY ?
|
||||
Rect.MinMaxRect(m_SerieGrid.context.x, plb.y, m_SerieGrid.context.x + relativedAxisLength, prt.y) :
|
||||
Rect.MinMaxRect(plb.x, m_SerieGrid.context.y, prb.x, m_SerieGrid.context.y + relativedAxisLength);
|
||||
|
||||
if (!serie.clip || (serie.clip && m_SerieGrid.Contains(top)))
|
||||
serie.context.dataPoints.Add(top);
|
||||
@@ -283,7 +293,7 @@ namespace XCharts.Runtime
|
||||
if (axis.context.minMaxRange <= 0) pY = grid.context.y;
|
||||
else
|
||||
{
|
||||
var valueLen = (float)((value - axis.context.minValue) / axis.context.minMaxRange) * grid.context.height;
|
||||
var valueLen = (float) ((value - axis.context.minValue) / axis.context.minMaxRange) * grid.context.height;
|
||||
pY = grid.context.y + valueLen - categoryWidth * 0.5f;
|
||||
}
|
||||
}
|
||||
@@ -305,7 +315,7 @@ namespace XCharts.Runtime
|
||||
if (axis.context.minMaxRange <= 0) pX = grid.context.x;
|
||||
else
|
||||
{
|
||||
var valueLen = (float)((value - axis.context.minValue) / axis.context.minMaxRange) * grid.context.width;
|
||||
var valueLen = (float) ((value - axis.context.minValue) / axis.context.minMaxRange) * grid.context.width;
|
||||
pX = grid.context.x + valueLen - categoryWidth * 0.5f;
|
||||
}
|
||||
}
|
||||
@@ -374,9 +384,9 @@ namespace XCharts.Runtime
|
||||
{
|
||||
var borderWidth = itemStyle.runtimeBorderWidth;
|
||||
var backgroundColor = SerieHelper.GetItemBackgroundColor(serie, serieData, chart.theme, colorIndex, highlight, false);
|
||||
var cornerRadius = serie.barType == BarType.Capsule && !itemStyle.IsNeedCorner()
|
||||
? m_CapusleDefaultCornerRadius
|
||||
: itemStyle.cornerRadius;
|
||||
var cornerRadius = serie.barType == BarType.Capsule && !itemStyle.IsNeedCorner() ?
|
||||
m_CapusleDefaultCornerRadius :
|
||||
itemStyle.cornerRadius;
|
||||
var invert = value < 0;
|
||||
if (!ChartHelper.IsClearColor(backgroundColor))
|
||||
{
|
||||
@@ -384,7 +394,7 @@ namespace XCharts.Runtime
|
||||
cornerRadius, isYAxis, chart.settings.cicleSmoothness, invert);
|
||||
}
|
||||
UGL.DrawRoundRectangle(vh, serieData.context.rect, areaColor, areaToColor, 0,
|
||||
cornerRadius, isYAxis, chart.settings.cicleSmoothness, invert);
|
||||
cornerRadius, isYAxis, chart.settings.cicleSmoothness, invert);
|
||||
if (serie.barType == BarType.Capsule)
|
||||
{
|
||||
UGL.DrawBorder(vh, serieData.context.backgroundRect, borderWidth, itemStyle.borderColor,
|
||||
@@ -393,7 +403,7 @@ namespace XCharts.Runtime
|
||||
else
|
||||
{
|
||||
UGL.DrawBorder(vh, serieData.context.rect, borderWidth, itemStyle.borderColor,
|
||||
0, cornerRadius, isYAxis, chart.settings.cicleSmoothness, invert, itemStyle.borderGap);
|
||||
0, cornerRadius, isYAxis, chart.settings.cicleSmoothness, invert, itemStyle.borderGap);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
|
||||
using System;
|
||||
using UnityEngine;
|
||||
|
||||
@@ -10,6 +9,8 @@ namespace XCharts.Runtime
|
||||
[CoordOptions(typeof(GridCoord))]
|
||||
[DefaultAnimation(AnimationType.LeftToRight)]
|
||||
[SerieExtraComponent()]
|
||||
[SerieDataExtraComponent()]
|
||||
[SerieDataExtraField()]
|
||||
public class SimplifiedBar : Serie, INeedSerieContainer, ISimplifiedSerie
|
||||
{
|
||||
public int containerIndex { get; internal set; }
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using UnityEngine;
|
||||
@@ -138,16 +137,17 @@ namespace XCharts.Runtime
|
||||
var axisLength = isY ? m_SerieGrid.context.height : m_SerieGrid.context.width;
|
||||
var axisXY = isY ? m_SerieGrid.context.y : m_SerieGrid.context.x;
|
||||
|
||||
var barCount = chart.GetSerieBarRealCount<SimplifiedBar>();
|
||||
float categoryWidth = AxisHelper.GetDataWidth(axis, axisLength, showData.Count, dataZoom);
|
||||
float barGap = chart.GetSerieBarGap<Bar>();
|
||||
float totalBarWidth = chart.GetSerieTotalWidth<Bar>(categoryWidth, barGap);
|
||||
float barWidth = serie.GetBarWidth(categoryWidth);
|
||||
float barGap = chart.GetSerieBarGap<SimplifiedBar>();
|
||||
float totalBarWidth = chart.GetSerieTotalWidth<SimplifiedBar>(categoryWidth, barGap, barCount);
|
||||
float barWidth = serie.GetBarWidth(categoryWidth, barCount);
|
||||
float offset = (categoryWidth - totalBarWidth) * 0.5f;
|
||||
float barGapWidth = barWidth + barWidth * barGap;
|
||||
float gap = serie.barGap == -1 ? offset : offset + serie.index * barGapWidth;
|
||||
int maxCount = serie.maxShow > 0
|
||||
? (serie.maxShow > showData.Count ? showData.Count : serie.maxShow)
|
||||
: showData.Count;
|
||||
int maxCount = serie.maxShow > 0 ?
|
||||
(serie.maxShow > showData.Count ? showData.Count : serie.maxShow) :
|
||||
showData.Count;
|
||||
|
||||
bool dataChanging = false;
|
||||
float dataChangeDuration = serie.animation.GetUpdateAnimationDuration();
|
||||
@@ -231,7 +231,7 @@ namespace XCharts.Runtime
|
||||
else
|
||||
{
|
||||
if (axis.context.minMaxRange <= 0) pY = grid.context.y;
|
||||
else pY = grid.context.y + (float)((value - axis.context.minValue) / axis.context.minMaxRange) * (grid.context.height - barWidth);
|
||||
else pY = grid.context.y + (float) ((value - axis.context.minValue) / axis.context.minMaxRange) * (grid.context.height - barWidth);
|
||||
}
|
||||
pX = AxisHelper.GetAxisValuePosition(grid, relativedAxis, categoryWidth, 0);
|
||||
}
|
||||
@@ -244,7 +244,7 @@ namespace XCharts.Runtime
|
||||
else
|
||||
{
|
||||
if (axis.context.minMaxRange <= 0) pX = grid.context.x;
|
||||
else pX = grid.context.x + (float)((value - axis.context.minValue) / axis.context.minMaxRange) * (grid.context.width - barWidth);
|
||||
else pX = grid.context.x + (float) ((value - axis.context.minValue) / axis.context.minMaxRange) * (grid.context.width - barWidth);
|
||||
}
|
||||
pY = AxisHelper.GetAxisValuePosition(grid, relativedAxis, categoryWidth, 0);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user