优化代码,更好的支持自定义图表

This commit is contained in:
monitor1394
2021-04-27 12:47:46 +08:00
parent 3933420cf6
commit 6a76f25b7d
35 changed files with 611 additions and 643 deletions

View File

@@ -152,7 +152,7 @@ namespace XCharts
CheckTooltip();
CheckRefreshChart();
CheckRefreshLabel();
CheckAnimation();
Internal_CheckAnimation();
foreach (var draw in m_DrawSeries) draw.Update();
}
@@ -716,7 +716,7 @@ namespace XCharts
}
}
protected void CheckAnimation()
public void Internal_CheckAnimation()
{
if (!m_CheckAnimation)
{

View File

@@ -1702,7 +1702,7 @@ namespace XCharts
var content = "";
if (anyPercentStack && isPercentStack)
{
var tempTotal = GetSameStackTotalValue(serie.stack, j);
var tempTotal = Internal_GetBarSameStackTotalValue(serie.stack, j);
content = SerieLabelHelper.GetFormatterContent(serie, serieData, value, tempTotal,
serieLabel, theme.GetColor(i));
}
@@ -1958,13 +1958,13 @@ namespace XCharts
RefreshChart();
}
protected void CheckClipAndDrawPolygon(VertexHelper vh, Vector3 p1, Vector3 p2, Vector3 p3, Vector3 p4,
public void Internal_CheckClipAndDrawPolygon(VertexHelper vh, Vector3 p1, Vector3 p2, Vector3 p3, Vector3 p4,
Color32 color, bool clip, Grid grid)
{
CheckClipAndDrawPolygon(vh, p1, p2, p3, p4, color, color, clip, grid);
Internal_CheckClipAndDrawPolygon(vh, p1, p2, p3, p4, color, color, clip, grid);
}
protected void CheckClipAndDrawPolygon(VertexHelper vh, Vector3 p, float radius, Color32 color,
public void Internal_CheckClipAndDrawPolygon(VertexHelper vh, Vector3 p, float radius, Color32 color,
bool clip, bool vertical, Grid grid)
{
if (!IsInChart(p)) return;
@@ -1972,7 +1972,7 @@ namespace XCharts
UGL.DrawSquare(vh, p, radius, color);
}
protected void CheckClipAndDrawPolygon(VertexHelper vh, Vector3 p1, Vector3 p2, Vector3 p3, Vector3 p4,
public void Internal_CheckClipAndDrawPolygon(VertexHelper vh, Vector3 p1, Vector3 p2, Vector3 p3, Vector3 p4,
Color32 startColor, Color32 toColor, bool clip, Grid grid)
{
ClampInChart(ref p1);
@@ -1990,7 +1990,7 @@ namespace XCharts
UGL.DrawQuadrilateral(vh, p1, p2, p3, p4, startColor, toColor);
}
protected void CheckClipAndDrawPolygon(VertexHelper vh, ref Vector3 p1, ref Vector3 p2, ref Vector3 p3, ref Vector3 p4,
public void Internal_CheckClipAndDrawPolygon(VertexHelper vh, ref Vector3 p1, ref Vector3 p2, ref Vector3 p3, ref Vector3 p4,
Color32 startColor, Color32 toColor, bool clip, Grid grid)
{
ClampInChart(ref p1);
@@ -2009,13 +2009,13 @@ namespace XCharts
UGL.DrawQuadrilateral(vh, p1, p2, p3, p4, startColor, toColor);
}
protected void CheckClipAndDrawTriangle(VertexHelper vh, Vector3 p1, Vector3 p2, Vector3 p3, Color32 color,
public void Internal_CheckClipAndDrawTriangle(VertexHelper vh, Vector3 p1, Vector3 p2, Vector3 p3, Color32 color,
bool clip, Grid grid)
{
CheckClipAndDrawTriangle(vh, p1, p2, p3, color, color, color, clip, grid);
Internal_CheckClipAndDrawTriangle(vh, p1, p2, p3, color, color, color, clip, grid);
}
protected void CheckClipAndDrawTriangle(VertexHelper vh, Vector3 p1, Vector3 p2, Vector3 p3, Color32 color,
public void Internal_CheckClipAndDrawTriangle(VertexHelper vh, Vector3 p1, Vector3 p2, Vector3 p3, Color32 color,
Color32 color2, Color32 color3, bool clip, Grid grid)
{
if (!IsInChart(p1) || !IsInChart(p2) || !IsInChart(p3)) return;
@@ -2023,7 +2023,7 @@ namespace XCharts
UGL.DrawTriangle(vh, p1, p2, p3, color, color2, color3);
}
protected void CheckClipAndDrawLine(VertexHelper vh, Vector3 p1, Vector3 p2, float size, Color32 color,
public void Internal_CheckClipAndDrawLine(VertexHelper vh, Vector3 p1, Vector3 p2, float size, Color32 color,
bool clip, Grid grid)
{
if (!IsInChart(p1) || !IsInChart(p2)) return;
@@ -2031,7 +2031,7 @@ namespace XCharts
UGL.DrawLine(vh, p1, p2, size, color);
}
protected void CheckClipAndDrawSymbol(VertexHelper vh, SerieSymbolType type, float symbolSize, float tickness,
public void Internal_CheckClipAndDrawSymbol(VertexHelper vh, SerieSymbolType type, float symbolSize, float tickness,
Vector3 pos, Color32 color, Color32 toColor, float gap, bool clip, float[] cornerRadius, Grid grid)
{
if (!IsInChart(pos)) return;
@@ -2039,7 +2039,7 @@ namespace XCharts
DrawSymbol(vh, type, symbolSize, tickness, pos, color, toColor, gap, cornerRadius);
}
protected void CheckClipAndDrawZebraLine(VertexHelper vh, Vector3 p1, Vector3 p2, float size, float zebraWidth,
public void Internal_CheckClipAndDrawZebraLine(VertexHelper vh, Vector3 p1, Vector3 p2, float size, float zebraWidth,
float zebraGap, Color32 color, bool clip, Grid grid)
{
ClampInChart(ref p1);
@@ -2059,7 +2059,7 @@ namespace XCharts
return Color32.Lerp(areaToColor, areaColor, (pos.x - grid.runtimeX) / grid.runtimeWidth);
}
internal Grid GetAxisGridOrDefault(Axis axis)
public Grid GetAxisGridOrDefault(Axis axis)
{
var index = axis.gridIndex;
if (index >= 0 && index < m_Grids.Count)
@@ -2076,7 +2076,7 @@ namespace XCharts
}
}
protected Grid GetDataZoomGridOrDefault(DataZoom dataZoom)
public Grid GetDataZoomGridOrDefault(DataZoom dataZoom)
{
var xAxis = GetXAxis(dataZoom.xAxisIndexs[0]);
Grid grid = GetGrid(xAxis.gridIndex);
@@ -2106,7 +2106,7 @@ namespace XCharts
return grid;
}
protected XAxis GetSerieXAxisOrDefault(Serie serie)
public XAxis GetSerieXAxisOrDefault(Serie serie)
{
var axis = GetXAxis(serie.xAxisIndex);
if (axis == null)
@@ -2117,7 +2117,7 @@ namespace XCharts
return axis;
}
protected YAxis GetSerieYAxisOrDefault(Serie serie)
public YAxis GetSerieYAxisOrDefault(Serie serie)
{
var axis = GetYAxis(serie.yAxisIndex);
if (axis == null)
@@ -2139,7 +2139,7 @@ namespace XCharts
}
}
private float GetXAxisOnZeroOffset(XAxis axis)
public float GetXAxisOnZeroOffset(XAxis axis)
{
if (!axis.axisLine.onZero) return 0;
foreach (var yAxis in m_YAxes)
@@ -2149,7 +2149,7 @@ namespace XCharts
return 0;
}
private float GetYAxisOnZeroOffset(YAxis axis)
public float GetYAxisOnZeroOffset(YAxis axis)
{
if (!axis.axisLine.onZero) return 0;
foreach (var xAxis in m_XAxes)
@@ -2159,7 +2159,7 @@ namespace XCharts
return 0;
}
private YAxis GetRelatedYAxis(XAxis axis)
public YAxis GetRelatedYAxis(XAxis axis)
{
foreach (var yAxis in m_YAxes)
{
@@ -2168,7 +2168,7 @@ namespace XCharts
return m_YAxes[0];
}
private XAxis GetRelatedXAxis(YAxis axis)
public XAxis GetRelatedXAxis(YAxis axis)
{
foreach (var xAxis in m_XAxes)
{

View File

@@ -27,12 +27,12 @@ namespace XCharts
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 barGap = Internal_GetBarGap();
float totalBarWidth = Internal_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 + GetBarIndex(serie) * barGapWidth;
float space = serie.barGap == -1 ? offset : offset + Internal_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);
@@ -81,7 +81,7 @@ namespace XCharts
var valueTotal = 0f;
if (isPercentStack)
{
valueTotal = GetSameStackTotalValue(serie.stack, i);
valueTotal = Internal_GetBarSameStackTotalValue(serie.stack, i);
barHig = valueTotal != 0 ? (value / valueTotal * grid.runtimeWidth) : 0;
}
else
@@ -93,7 +93,7 @@ namespace XCharts
}
serieData.runtimeStackHig = barHig;
var isBarEnd = false;
float currHig = CheckAnimation(serie, i, barHig, out isBarEnd);
float currHig = Internal_CheckBarAnimation(serie, i, barHig, out isBarEnd);
if (!isBarEnd) isAllBarEnd = false;
Vector3 plt, prt, prb, plb, top;
if (value < 0)
@@ -143,7 +143,7 @@ namespace XCharts
}
}
private float CheckAnimation(Serie serie, int dataIndex, float barHig, out bool isBarEnd)
public float Internal_CheckBarAnimation(Serie serie, int dataIndex, float barHig, out bool isBarEnd)
{
float currHig = serie.animation.CheckBarProgress(dataIndex, barHig, serie.dataCount, out isBarEnd);
if (!serie.animation.IsFinish())
@@ -166,12 +166,12 @@ namespace XCharts
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 barGap = Internal_GetBarGap();
float totalBarWidth = Internal_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 + GetBarIndex(serie) * barGapWidth;
float space = serie.barGap == -1 ? offset : offset + Internal_GetBarIndex(serie) * barGapWidth;
int maxCount = serie.maxShow > 0
? (serie.maxShow > showData.Count ? showData.Count : serie.maxShow)
: showData.Count;
@@ -215,7 +215,7 @@ namespace XCharts
var valueTotal = 0f;
if (isPercentStack)
{
valueTotal = GetSameStackTotalValue(serie.stack, i);
valueTotal = Internal_GetBarSameStackTotalValue(serie.stack, i);
barHig = valueTotal != 0 ? (value / valueTotal * grid.runtimeHeight) : 0;
}
else
@@ -228,7 +228,7 @@ namespace XCharts
}
serieData.runtimeStackHig = barHig;
var isBarEnd = false;
float currHig = CheckAnimation(serie, i, barHig, out isBarEnd);
float currHig = Internal_CheckBarAnimation(serie, i, barHig, out isBarEnd);
if (!isBarEnd) isAllBarEnd = false;
Vector3 plb, plt, prt, prb, top;
if (value < 0)
@@ -313,7 +313,7 @@ namespace XCharts
}
else
{
CheckClipAndDrawPolygon(vh, plb, plt, prt, prb, areaColor, areaToColor, serie.clip, grid);
Internal_CheckClipAndDrawPolygon(vh, plb, plt, prt, prb, areaColor, areaToColor, serie.clip, grid);
}
UGL.DrawBorder(vh, center, itemWidth, itemHeight, borderWidth, itemStyle.borderColor,
itemStyle.borderToColor, 0, itemStyle.cornerRadius, isYAxis);
@@ -340,7 +340,7 @@ namespace XCharts
}
else
{
CheckClipAndDrawPolygon(vh, ref prb, ref plb, ref plt, ref prt, areaColor, areaToColor,
Internal_CheckClipAndDrawPolygon(vh, ref prb, ref plb, ref plt, ref prt, areaColor, areaToColor,
serie.clip, grid);
}
UGL.DrawBorder(vh, center, itemWidth, itemHeight, borderWidth, itemStyle.borderColor,
@@ -359,14 +359,14 @@ namespace XCharts
{
plt = (plb + plt) / 2;
prt = (prt + prb) / 2;
CheckClipAndDrawZebraLine(vh, plt, prt, barWidth / 2, serie.barZebraWidth, serie.barZebraGap,
Internal_CheckClipAndDrawZebraLine(vh, plt, prt, barWidth / 2, serie.barZebraWidth, serie.barZebraGap,
areaColor, serie.clip, grid);
}
else
{
plb = (prb + plb) / 2;
plt = (plt + prt) / 2;
CheckClipAndDrawZebraLine(vh, plb, plt, barWidth / 2, serie.barZebraWidth, serie.barZebraGap,
Internal_CheckClipAndDrawZebraLine(vh, plb, plt, barWidth / 2, serie.barZebraWidth, serie.barZebraGap,
areaColor, serie.clip, grid);
}
}
@@ -395,14 +395,14 @@ 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,
Internal_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,
Internal_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);
@@ -420,14 +420,14 @@ 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,
Internal_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,
Internal_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);
@@ -449,14 +449,14 @@ 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,
Internal_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,
Internal_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);
@@ -474,14 +474,14 @@ 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,
Internal_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,
Internal_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);
@@ -510,7 +510,7 @@ namespace XCharts
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, grid);
Internal_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())
@@ -534,7 +534,7 @@ namespace XCharts
}
else
{
CheckClipAndDrawPolygon(vh, ref plb, ref plt, ref prt, ref prb, color, color, serie.clip, grid);
Internal_CheckClipAndDrawPolygon(vh, ref plb, ref plt, ref prt, ref prb, color, color, serie.clip, grid);
}
}
else
@@ -551,7 +551,7 @@ namespace XCharts
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,
Internal_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);
@@ -576,18 +576,18 @@ namespace XCharts
}
else
{
CheckClipAndDrawPolygon(vh, ref prb, ref plb, ref plt, ref prt, color, color, serie.clip, grid);
Internal_CheckClipAndDrawPolygon(vh, ref prb, ref plb, ref plt, ref prt, color, color, serie.clip, grid);
}
}
}
private float GetBarGap()
public float Internal_GetBarGap()
{
float gap = 0.3f;
for (int i = 0; i < m_Series.Count; i++)
{
var serie = m_Series.list[i];
if (serie.type == SerieType.Bar || serie.type == SerieType.Candlestick)
if (serie.type == SerieType.Bar || serie.type == SerieType.Candlestick || serie.type == SerieType.Custom)
{
if (serie.barGap != 0)
{
@@ -598,13 +598,13 @@ namespace XCharts
return gap;
}
private float GetSameStackTotalValue(string stack, int dataIndex)
public float Internal_GetBarSameStackTotalValue(string stack, int dataIndex)
{
if (string.IsNullOrEmpty(stack)) return 0;
float total = 0;
foreach (var serie in m_Series.list)
{
if (serie.type == SerieType.Bar)
if (serie.type == SerieType.Bar || serie.type == SerieType.Custom)
{
if (stack.Equals(serie.stack))
{
@@ -617,7 +617,7 @@ namespace XCharts
private HashSet<string> barStackSet = new HashSet<string>();
private float GetBarTotalWidth(float categoryWidth, float gap)
public float Internal_GetBarTotalWidth(float categoryWidth, float gap)
{
float total = 0;
float lastGap = 0;
@@ -626,7 +626,7 @@ namespace XCharts
{
var serie = m_Series.list[i];
if (!serie.show) continue;
if (serie.type == SerieType.Bar || serie.type == SerieType.Candlestick)
if (serie.type == SerieType.Bar || serie.type == SerieType.Candlestick || serie.type == SerieType.Custom)
{
if (!string.IsNullOrEmpty(serie.stack))
{
@@ -657,7 +657,7 @@ namespace XCharts
for (int i = 0; i < m_Series.Count; i++)
{
var serie = m_Series.list[i];
if ((serie.type == SerieType.Bar && serie.type == SerieType.Candlestick)
if ((serie.type == SerieType.Bar || serie.type == SerieType.Candlestick || serie.type == SerieType.Custom)
&& serie.show && now.stack.Equals(serie.stack))
{
if (serie.barWidth > barWidth) barWidth = serie.barWidth;
@@ -668,14 +668,14 @@ namespace XCharts
}
private List<string> tempList = new List<string>();
private int GetBarIndex(Serie currSerie)
public int Internal_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 (serie.type != SerieType.Bar || serie.type == SerieType.Custom) continue;
if (string.IsNullOrEmpty(serie.stack))
{
if (serie.index == currSerie.index) return index;

View File

@@ -69,7 +69,7 @@ namespace XCharts
}
serieData.runtimeStackHig = barHig;
var isBarEnd = false;
float currHig = CheckAnimation(serie, i, barHig, out isBarEnd);
float currHig = Internal_CheckBarAnimation(serie, i, barHig, out isBarEnd);
if (!isBarEnd) isAllBarEnd = false;
Vector3 plb, plt, prt, prb, top;
@@ -111,7 +111,7 @@ namespace XCharts
}
else
{
CheckClipAndDrawPolygon(vh, ref prb, ref plb, ref plt, ref prt, areaColor, areaColor,
Internal_CheckClipAndDrawPolygon(vh, ref prb, ref plb, ref plt, ref prt, areaColor, areaColor,
serie.clip, grid);
}
UGL.DrawBorder(vh, center, itemWidth, itemHeight, 2 * borderWidth, borderColor, 0,

View File

@@ -141,7 +141,7 @@ namespace XCharts
}
else
{
CheckClipAndDrawPolygon(vh, ref prb, ref plb, ref plt, ref prt, color, color,
Internal_CheckClipAndDrawPolygon(vh, ref prb, ref plb, ref plt, ref prt, color, color,
serie.clip, grid);
}
if (borderWidth != 0)

View File

@@ -45,7 +45,7 @@ namespace XCharts
var symbolBorder = SerieHelper.GetSymbolBorder(serie, serieData, m_Theme, highlight);
var cornerRadius = SerieHelper.GetSymbolCornerRadius(serie, serieData, highlight);
symbolSize = serie.animation.GetSysmbolSize(symbolSize);
CheckClipAndDrawSymbol(vh, symbol.type, symbolSize, symbolBorder, serie.dataPoints[i], symbolColor,
Internal_CheckClipAndDrawSymbol(vh, symbol.type, symbolSize, symbolBorder, serie.dataPoints[i], symbolColor,
symbolToColor, symbol.gap, clip, cornerRadius, grid);
}
}
@@ -773,8 +773,8 @@ namespace XCharts
{
isShort = true;
isStart = true;
CheckClipAndDrawPolygon(vh, stPos1, upPos1, upPos2, stPos2, lineColor, serie.clip, grid);
CheckClipAndDrawTriangle(vh, stPos2, upPos2, dnPos, lineColor, serie.clip, grid);
Internal_CheckClipAndDrawPolygon(vh, stPos1, upPos1, upPos2, stPos2, lineColor, serie.clip, grid);
Internal_CheckClipAndDrawTriangle(vh, stPos2, upPos2, dnPos, lineColor, serie.clip, grid);
TryAddToList(isTurnBack, isYAxis, smoothPoints, lastSmoothPoint, stPos1, isEndPos);
TryAddToList(isTurnBack, isYAxis, smoothPoints, lastSmoothPoint, upPos1, isEndPos);
TryAddToList(isTurnBack, isYAxis, smoothDownPoints, lastSmoothDownPoint, dnPos, isEndPos);
@@ -784,7 +784,7 @@ namespace XCharts
(!lastIsDown && IsInRightOrUp(isYAxis, lastDnPos, tp1)))
{
isStart = true;
CheckClipAndDrawPolygon(vh, stPos1, tp1, tp2, stPos2, lineColor, serie.clip, grid);
Internal_CheckClipAndDrawPolygon(vh, stPos1, tp1, tp2, stPos2, lineColor, serie.clip, grid);
}
}
else
@@ -793,24 +793,24 @@ namespace XCharts
{
if (np != nnp)
{
CheckClipAndDrawPolygon(vh, ltp1, upPos1, dnPos, ltp2, lineColor, serie.clip, grid);
CheckClipAndDrawTriangle(vh, upPos1, upPos2, dnPos, lineColor, serie.clip, grid);
Internal_CheckClipAndDrawPolygon(vh, ltp1, upPos1, dnPos, ltp2, lineColor, serie.clip, grid);
Internal_CheckClipAndDrawTriangle(vh, upPos1, upPos2, dnPos, lineColor, serie.clip, grid);
}
else
{
CheckClipAndDrawPolygon(vh, ltp1, upPos1, upPos2, ltp2, lineColor, serie.clip, grid);
Internal_CheckClipAndDrawPolygon(vh, ltp1, upPos1, upPos2, ltp2, lineColor, serie.clip, grid);
}
}
else
{
if (IsInRightOrUp(isYAxis, tp2, dnPos) || isTurnBack)
{
CheckClipAndDrawLine(vh, start, cp, serie.lineStyle.GetWidth(m_Theme.serie.lineWidth), lineColor, serie.clip, grid);
Internal_CheckClipAndDrawLine(vh, start, cp, serie.lineStyle.GetWidth(m_Theme.serie.lineWidth), lineColor, serie.clip, grid);
}
else
{
CheckClipAndDrawPolygon(vh, ltp1, upPos1, dnPos, ltp2, lineColor, serie.clip, grid);
CheckClipAndDrawTriangle(vh, upPos1, upPos2, dnPos, lineColor, serie.clip, grid);
Internal_CheckClipAndDrawPolygon(vh, ltp1, upPos1, dnPos, ltp2, lineColor, serie.clip, grid);
Internal_CheckClipAndDrawTriangle(vh, upPos1, upPos2, dnPos, lineColor, serie.clip, grid);
i = segment;
}
}
@@ -834,11 +834,11 @@ namespace XCharts
isStart = true;
isShort = true;
if (np == nnp)
CheckClipAndDrawPolygon(vh, stPos1, dnPos, upPos2, stPos2, lineColor, serie.clip, grid);
Internal_CheckClipAndDrawPolygon(vh, stPos1, dnPos, upPos2, stPos2, lineColor, serie.clip, grid);
else
{
CheckClipAndDrawPolygon(vh, stPos1, dnPos, upPos1, stPos2, lineColor, serie.clip, grid);
CheckClipAndDrawTriangle(vh, dnPos, upPos1, upPos2, lineColor, serie.clip, grid);
Internal_CheckClipAndDrawPolygon(vh, stPos1, dnPos, upPos1, stPos2, lineColor, serie.clip, grid);
Internal_CheckClipAndDrawTriangle(vh, dnPos, upPos1, upPos2, lineColor, serie.clip, grid);
}
TryAddToList(isTurnBack, isYAxis, smoothPoints, lastSmoothPoint, dnPos, isEndPos);
TryAddToList(isTurnBack, isYAxis, smoothDownPoints, lastSmoothDownPoint, stPos2, isEndPos);
@@ -851,7 +851,7 @@ namespace XCharts
isStart = true;
if (stPos2 != Vector3.zero)
{
CheckClipAndDrawPolygon(vh, stPos1, tp1, tp2, stPos2, lineColor, serie.clip, grid);
Internal_CheckClipAndDrawPolygon(vh, stPos1, tp1, tp2, stPos2, lineColor, serie.clip, grid);
}
}
}
@@ -861,21 +861,21 @@ namespace XCharts
{
if (np != nnp)
{
CheckClipAndDrawPolygon(vh, ltp1, dnPos, upPos1, ltp2, lineColor, serie.clip, grid);
CheckClipAndDrawTriangle(vh, dnPos, upPos2, upPos1, lineColor, serie.clip, grid);
Internal_CheckClipAndDrawPolygon(vh, ltp1, dnPos, upPos1, ltp2, lineColor, serie.clip, grid);
Internal_CheckClipAndDrawTriangle(vh, dnPos, upPos2, upPos1, lineColor, serie.clip, grid);
}
else CheckClipAndDrawPolygon(vh, ltp1, upPos1, upPos2, ltp2, lineColor, serie.clip, grid);
else Internal_CheckClipAndDrawPolygon(vh, ltp1, upPos1, upPos2, ltp2, lineColor, serie.clip, grid);
}
else
{
if (IsInRightOrUp(isYAxis, tp1, dnPos) || isTurnBack)
{
CheckClipAndDrawLine(vh, start, cp, serie.lineStyle.GetWidth(m_Theme.serie.lineWidth), lineColor, serie.clip, grid);
Internal_CheckClipAndDrawLine(vh, start, cp, serie.lineStyle.GetWidth(m_Theme.serie.lineWidth), lineColor, serie.clip, grid);
}
else
{
CheckClipAndDrawPolygon(vh, ltp1, dnPos, upPos1, ltp2, lineColor, serie.clip, grid);
CheckClipAndDrawTriangle(vh, dnPos, upPos2, upPos1, lineColor, serie.clip, grid);
Internal_CheckClipAndDrawPolygon(vh, ltp1, dnPos, upPos1, ltp2, lineColor, serie.clip, grid);
Internal_CheckClipAndDrawTriangle(vh, dnPos, upPos2, upPos1, lineColor, serie.clip, grid);
i = segment;
}
}
@@ -979,7 +979,7 @@ namespace XCharts
if ((isYAxis && ep.y > luPos.y) || (!isYAxis && ep.x > luPos.x))
{
var tp = isYAxis ? new Vector3(luPos.x, sp.y) : new Vector3(sp.x, luPos.y);
CheckClipAndDrawTriangle(vh, sp, luPos, tp, areaColor, areaToColor, areaToColor, serie.clip, grid);
Internal_CheckClipAndDrawTriangle(vh, sp, luPos, tp, areaColor, areaToColor, areaToColor, serie.clip, grid);
break;
}
DrawPolygonToZero(vh, sp, ep, axis, zeroPos, areaColor, areaToColor, Vector3.zero);
@@ -1001,7 +1001,7 @@ namespace XCharts
{
first = true;
var tp = isYAxis ? new Vector3(rdPos.x, ep.y) : new Vector3(ep.x, rdPos.y);
CheckClipAndDrawTriangle(vh, rdPos, tp, ep, areaToColor, areaToColor, areaColor, serie.clip, grid);
Internal_CheckClipAndDrawTriangle(vh, rdPos, tp, ep, areaToColor, areaToColor, areaColor, serie.clip, grid);
sp = ep;
continue;
}
@@ -1025,7 +1025,7 @@ namespace XCharts
if ((isYAxis && ep.y > rdPos.y) || (!isYAxis && ep.x > rdPos.x))
{
var tp = isYAxis ? new Vector3(rdPos.x, sp.y) : new Vector3(sp.x, rdPos.y);
CheckClipAndDrawTriangle(vh, sp, rdPos, tp, areaColor, areaToColor, areaToColor, serie.clip, grid);
Internal_CheckClipAndDrawTriangle(vh, sp, rdPos, tp, areaColor, areaToColor, areaToColor, serie.clip, grid);
break;
}
if (rdPos != Vector3.zero) DrawPolygonToZero(vh, sp, ep, axis, zeroPos, areaColor, areaToColor, Vector3.zero);
@@ -1047,7 +1047,7 @@ namespace XCharts
{
first = true;
var tp = isYAxis ? new Vector3(luPos.x, ep.y) : new Vector3(ep.x, luPos.y);
CheckClipAndDrawTriangle(vh, ep, luPos, tp, areaColor, areaToColor, areaToColor, serie.clip, grid);
Internal_CheckClipAndDrawTriangle(vh, ep, luPos, tp, areaColor, areaToColor, areaToColor, serie.clip, grid);
sp = ep;
continue;
}
@@ -1132,7 +1132,7 @@ namespace XCharts
diff = isLessthan0 ? -lineWidth : lineWidth;
areaColor = GetYLerpColor(areaColor, areaToColor, sp, grid);
if (isLessthan0) areaDiff = -areaDiff;
CheckClipAndDrawPolygon(vh, new Vector3(zeroPos.x + diff, sp.y), new Vector3(zeroPos.x + diff, ep.y),
Internal_CheckClipAndDrawPolygon(vh, new Vector3(zeroPos.x + diff, sp.y), new Vector3(zeroPos.x + diff, ep.y),
ep + areaDiff, sp + areaDiff, areaToColor, areaColor, clip, grid);
}
else
@@ -1143,12 +1143,12 @@ namespace XCharts
if (isLessthan0) areaDiff = -areaDiff;
if (isLessthan0)
{
CheckClipAndDrawPolygon(vh, ep + areaDiff, sp + areaDiff, new Vector3(sp.x, zeroPos.y + diff),
Internal_CheckClipAndDrawPolygon(vh, ep + areaDiff, sp + areaDiff, new Vector3(sp.x, zeroPos.y + diff),
new Vector3(ep.x, zeroPos.y + diff), areaColor, areaToColor, clip, grid);
}
else
{
CheckClipAndDrawPolygon(vh, sp + areaDiff, ep + areaDiff, new Vector3(ep.x, zeroPos.y + diff),
Internal_CheckClipAndDrawPolygon(vh, sp + areaDiff, ep + areaDiff, new Vector3(ep.x, zeroPos.y + diff),
new Vector3(sp.x, zeroPos.y + diff), areaColor, areaToColor, clip, grid);
}
}
@@ -1228,7 +1228,7 @@ namespace XCharts
start = bezierPoints[i];
to = bezierPoints[i + 1];
CheckLineGradientColor(start, serie.lineStyle, xAxis, defaultLineColor, ref lineColor);
CheckClipAndDrawLine(vh, start, to, lineWidth, lineColor, serie.clip, grid);
Internal_CheckClipAndDrawLine(vh, start, to, lineWidth, lineColor, serie.clip, grid);
}
return true;
}
@@ -1251,8 +1251,8 @@ namespace XCharts
if (!serie.animation.IsInFadeOut())
{
CheckLineGradientColor(lp, serie.lineStyle, xAxis, defaultLineColor, ref lineColor);
CheckClipAndDrawTriangle(vh, smoothStartPosUp, startUp, lp, lineColor, serie.clip, grid);
CheckClipAndDrawTriangle(vh, smoothStartPosDn, startDn, lp, lineColor, serie.clip, grid);
Internal_CheckClipAndDrawTriangle(vh, smoothStartPosUp, startUp, lp, lineColor, serie.clip, grid);
Internal_CheckClipAndDrawTriangle(vh, smoothStartPosDn, startDn, lp, lineColor, serie.clip, grid);
TryAddToList(isTurnBack, isYAxis, smoothPoints, lastSmoothPoint, smoothStartPosUp, false);
TryAddToList(isTurnBack, isYAxis, smoothDownPoints, lastSmoothDownPoint, smoothStartPosDn, false);
}
@@ -1279,8 +1279,8 @@ namespace XCharts
toUp = to - diff;
toDn = to + diff;
CheckLineGradientColor(to, serie.lineStyle, xAxis, defaultLineColor, ref lineColor);
if (isYAxis) CheckClipAndDrawPolygon(vh, startDn, toDn, toUp, startUp, lineColor, serie.clip, grid);
else CheckClipAndDrawPolygon(vh, startUp, toUp, toDn, startDn, lineColor, serie.clip, grid);
if (isYAxis) Internal_CheckClipAndDrawPolygon(vh, startDn, toDn, toUp, startUp, lineColor, serie.clip, grid);
else Internal_CheckClipAndDrawPolygon(vh, startUp, toUp, toDn, startDn, lineColor, serie.clip, grid);
TryAddToList(isTurnBack, isYAxis, smoothPoints, lastSmoothPoint, toUp, true);
TryAddToList(isTurnBack, isYAxis, smoothDownPoints, lastSmoothDownPoint, toDn, true);
if (isEndPos)
@@ -1383,12 +1383,12 @@ namespace XCharts
if (k < lastSmoothPoints.Count - 1)
{
tnp = lastSmoothPoints[lastCount - 1];
CheckClipAndDrawTriangle(vh, start, to, tnp, areaColor, areaColor, areaToColor, serie.clip, grid);
Internal_CheckClipAndDrawTriangle(vh, start, to, tnp, areaColor, areaColor, areaToColor, serie.clip, grid);
while (lastCount < lastSmoothPoints.Count)
{
tlp = lastSmoothPoints[lastCount];
if (serie.animation.CheckDetailBreak(tlp, isYAxis)) break;
CheckClipAndDrawTriangle(vh, tnp, to, tlp, areaToColor, areaColor, areaToColor, serie.clip, grid);
Internal_CheckClipAndDrawTriangle(vh, tnp, to, tlp, areaToColor, areaColor, areaToColor, serie.clip, grid);
lastCount++;
tnp = tlp;
}
@@ -1400,7 +1400,7 @@ namespace XCharts
{
tlp = lastSmoothPoints[lastSmoothPoints.Count - 1];
if (serie.animation.CheckDetailBreak(tlp, isYAxis)) break;
CheckClipAndDrawTriangle(vh, to, start, tlp, areaColor, areaColor, areaToColor, serie.clip, grid);
Internal_CheckClipAndDrawTriangle(vh, to, start, tlp, areaColor, areaColor, areaToColor, serie.clip, grid);
start = to;
continue;
}
@@ -1410,7 +1410,7 @@ namespace XCharts
{
tlp = lastSmoothPoints[lastCount - 1];
if (serie.animation.CheckDetailBreak(tlp, isYAxis)) break;
CheckClipAndDrawPolygon(vh, start, to, tnp, tlp, areaColor, areaToColor, serie.clip, grid);
Internal_CheckClipAndDrawPolygon(vh, start, to, tnp, tlp, areaColor, areaToColor, serie.clip, grid);
lastCount++;
}
else
@@ -1418,12 +1418,12 @@ namespace XCharts
if (diff < 0)
{
tnp = lastSmoothPoints[lastCount - 1];
CheckClipAndDrawTriangle(vh, start, to, tnp, areaColor, areaColor, areaToColor, serie.clip, grid);
Internal_CheckClipAndDrawTriangle(vh, start, to, tnp, areaColor, areaColor, areaToColor, serie.clip, grid);
while (diff < 0 && lastCount < lastSmoothPoints.Count)
{
tlp = lastSmoothPoints[lastCount];
if (serie.animation.CheckDetailBreak(tlp, isYAxis)) break;
CheckClipAndDrawTriangle(vh, tnp, to, tlp, areaToColor, areaColor, areaToColor, serie.clip, grid);
Internal_CheckClipAndDrawTriangle(vh, tnp, to, tlp, areaToColor, areaColor, areaToColor, serie.clip, grid);
lastCount++;
diff = isYAxis ? tlp.y - to.y : tlp.x - to.x;
tnp = tlp;
@@ -1433,7 +1433,7 @@ namespace XCharts
{
tlp = lastSmoothPoints[lastCount - 1];
if (serie.animation.CheckDetailBreak(tlp, isYAxis)) break;
CheckClipAndDrawTriangle(vh, start, to, tlp, areaColor, areaColor, areaToColor, serie.clip, grid);
Internal_CheckClipAndDrawTriangle(vh, start, to, tlp, areaColor, areaColor, areaToColor, serie.clip, grid);
}
}
start = to;
@@ -1444,7 +1444,7 @@ namespace XCharts
var p2 = lastSmoothPoints[lastSmoothPoints.Count - 1];
if (!serie.animation.CheckDetailBreak(p1, isYAxis) && !serie.animation.CheckDetailBreak(p2, isYAxis))
{
CheckClipAndDrawTriangle(vh, p1, start, p2, areaToColor, areaColor, areaToColor, serie.clip, grid);
Internal_CheckClipAndDrawTriangle(vh, p1, start, p2, areaToColor, areaColor, areaToColor, serie.clip, grid);
}
}
}
@@ -1477,15 +1477,15 @@ namespace XCharts
{
ep = linePointList[i];
if (serie.animation.CheckDetailBreak(ep, isYAxis)) return false;
CheckClipAndDrawLine(vh, sp, ep, lineWidth, lineColor, serie.clip, grid);
Internal_CheckClipAndDrawLine(vh, sp, ep, lineWidth, lineColor, serie.clip, grid);
sp = ep;
}
CheckClipAndDrawPolygon(vh, middle, lineWidth, lineColor, serie.clip, true, grid);
Internal_CheckClipAndDrawPolygon(vh, middle, lineWidth, lineColor, serie.clip, true, grid);
}
else
{
if (dataIndex == 1) CheckClipAndDrawPolygon(vh, lp, lineWidth, lineColor, serie.clip, true, grid);
CheckClipAndDrawLine(vh, lp + diff1, middle + diff1, lineWidth, lineColor, serie.clip, grid);
if (dataIndex == 1) Internal_CheckClipAndDrawPolygon(vh, lp, lineWidth, lineColor, serie.clip, true, grid);
Internal_CheckClipAndDrawLine(vh, lp + diff1, middle + diff1, lineWidth, lineColor, serie.clip, grid);
}
if (serie.areaStyle.show)
{
@@ -1505,7 +1505,7 @@ namespace XCharts
{
ep = linePointList[i];
if (serie.animation.CheckDetailBreak(ep, isYAxis)) return false;
CheckClipAndDrawLine(vh, sp, ep, lineWidth, lineColor, serie.clip, grid);
Internal_CheckClipAndDrawLine(vh, sp, ep, lineWidth, lineColor, serie.clip, grid);
if (serie.areaStyle.show)
{
DrawPolygonToZero(vh, sp, ep, axis, zeroPos, areaColor, areaToColor, areaDiff);
@@ -1516,7 +1516,7 @@ namespace XCharts
if (nnp != np)
{
if (serie.animation.CheckDetailBreak(np, isYAxis)) return false;
CheckClipAndDrawPolygon(vh, np, lineWidth, lineColor, serie.clip, true, grid);
Internal_CheckClipAndDrawPolygon(vh, np, lineWidth, lineColor, serie.clip, true, grid);
bool flag = ((isYAxis && nnp.x > np.x && np.x > zeroPos.x) || (!isYAxis && nnp.y > np.y && np.y > zeroPos.y));
if (serie.areaStyle.show && flag)
{
@@ -1542,7 +1542,7 @@ namespace XCharts
{
ep = linePointList[i];
if (serie.animation.CheckDetailBreak(ep, isYAxis)) return false;
CheckClipAndDrawLine(vh, sp, ep, lineWidth, lineColor, serie.clip, grid);
Internal_CheckClipAndDrawLine(vh, sp, ep, lineWidth, lineColor, serie.clip, grid);
if (serie.areaStyle.show)
{
DrawPolygonToZero(vh, sp, ep, axis, zeroPos, areaColor, areaToColor, areaDiff);
@@ -1550,7 +1550,7 @@ namespace XCharts
sp = ep;
}
if (serie.animation.CheckDetailBreak(middle1, isYAxis)) return false;
CheckClipAndDrawPolygon(vh, middle1, lineWidth, lineColor, serie.clip, true, grid);
Internal_CheckClipAndDrawPolygon(vh, middle1, lineWidth, lineColor, serie.clip, true, grid);
if (serie.areaStyle.show && Vector3.Dot(middleZero - middle1, middle2 - middle1) <= 0)
{
DrawPolygonToZero(vh, middle1 - diff1, middle1 + diff1, axis, zeroPos, areaColor, areaToColor, areaDiff);
@@ -1558,8 +1558,8 @@ namespace XCharts
}
else
{
if (dataIndex == 1) CheckClipAndDrawPolygon(vh, lp, lineWidth, lineColor, serie.clip, true, grid);
CheckClipAndDrawLine(vh, lp + diff1, middle1 + diff1, lineWidth, lineColor, serie.clip, grid);
if (dataIndex == 1) Internal_CheckClipAndDrawPolygon(vh, lp, lineWidth, lineColor, serie.clip, true, grid);
Internal_CheckClipAndDrawLine(vh, lp + diff1, middle1 + diff1, lineWidth, lineColor, serie.clip, grid);
}
//draw middle1 to middle2
@@ -1570,10 +1570,10 @@ namespace XCharts
for (int i = 1; i < linePointList.Count; i++)
{
ep = linePointList[i];
CheckClipAndDrawLine(vh, sp, ep, lineWidth, lineColor, serie.clip, grid);
Internal_CheckClipAndDrawLine(vh, sp, ep, lineWidth, lineColor, serie.clip, grid);
sp = ep;
}
CheckClipAndDrawPolygon(vh, middle2, lineWidth, lineColor, serie.clip, true, grid);
Internal_CheckClipAndDrawPolygon(vh, middle2, lineWidth, lineColor, serie.clip, true, grid);
if (serie.areaStyle.show && Vector3.Dot(middleZero - middle2, middle2 - middle1) >= 0)
{
DrawPolygonToZero(vh, middle2 - diff1, middle2 + diff1, axis, zeroPos, areaColor, areaToColor, areaDiff);
@@ -1581,7 +1581,7 @@ namespace XCharts
}
else
{
CheckClipAndDrawLine(vh, middle1 + diff2, middle2 + diff2, lineWidth, lineColor, serie.clip, grid);
Internal_CheckClipAndDrawLine(vh, middle1 + diff2, middle2 + diff2, lineWidth, lineColor, serie.clip, grid);
}
//draw middle2 to np
if (Vector3.Distance(middle2, np) > 2 * lineWidth)
@@ -1592,7 +1592,7 @@ namespace XCharts
{
ep = linePointList[i];
if (serie.animation.CheckDetailBreak(ep, isYAxis)) return false;
CheckClipAndDrawLine(vh, sp, ep, lineWidth, lineColor, serie.clip, grid);
Internal_CheckClipAndDrawLine(vh, sp, ep, lineWidth, lineColor, serie.clip, grid);
if (serie.areaStyle.show)
{
DrawPolygonToZero(vh, sp, ep, axis, zeroPos, areaColor, areaToColor, areaDiff);
@@ -1600,7 +1600,7 @@ namespace XCharts
sp = ep;
}
if (serie.animation.CheckDetailBreak(np, isYAxis)) return false;
CheckClipAndDrawPolygon(vh, np, lineWidth, lineColor, serie.clip, true, grid);
Internal_CheckClipAndDrawPolygon(vh, np, lineWidth, lineColor, serie.clip, true, grid);
if (serie.areaStyle.show)
{
DrawPolygonToZero(vh, np - diff1, np + diff1, axis, zeroPos, areaColor, areaToColor, areaDiff);
@@ -1608,7 +1608,7 @@ namespace XCharts
}
else
{
CheckClipAndDrawLine(vh, middle1 + diff1, middle1 + diff1, lineWidth, lineColor, serie.clip, grid);
Internal_CheckClipAndDrawLine(vh, middle1 + diff1, middle1 + diff1, lineWidth, lineColor, serie.clip, grid);
}
break;
case LineType.StepEnd:
@@ -1627,7 +1627,7 @@ namespace XCharts
{
ep = linePointList[i];
if (serie.animation.CheckDetailBreak(ep, isYAxis)) return false;
CheckClipAndDrawLine(vh, sp, ep, lineWidth, lineColor, serie.clip, grid);
Internal_CheckClipAndDrawLine(vh, sp, ep, lineWidth, lineColor, serie.clip, grid);
if (serie.areaStyle.show)
{
DrawPolygonToZero(vh, sp, ep, axis, zeroPos, areaColor, areaToColor, areaDiff);
@@ -1635,7 +1635,7 @@ namespace XCharts
sp = ep;
}
if (serie.animation.CheckDetailBreak(middle, isYAxis)) return false;
CheckClipAndDrawPolygon(vh, middle, lineWidth, lineColor, serie.clip, true, grid);
Internal_CheckClipAndDrawPolygon(vh, middle, lineWidth, lineColor, serie.clip, true, grid);
if (serie.areaStyle.show && Vector3.Dot(np - middle, middleZero - middle) <= 0)
{
DrawPolygonToZero(vh, middle - diff1, middle + diff1, axis, zeroPos, areaColor, areaToColor, areaDiff);
@@ -1643,8 +1643,8 @@ namespace XCharts
}
else
{
if (dataIndex == 1) CheckClipAndDrawPolygon(vh, lp, lineWidth, lineColor, serie.clip, true, grid);
CheckClipAndDrawLine(vh, lp + diff1, middle + diff1, lineWidth, lineColor, serie.clip, grid);
if (dataIndex == 1) Internal_CheckClipAndDrawPolygon(vh, lp, lineWidth, lineColor, serie.clip, true, grid);
Internal_CheckClipAndDrawLine(vh, lp + diff1, middle + diff1, lineWidth, lineColor, serie.clip, grid);
}
if (Vector3.Distance(middle, np) > 2 * lineWidth)
@@ -1654,14 +1654,14 @@ namespace XCharts
for (int i = 1; i < linePointList.Count; i++)
{
ep = linePointList[i];
CheckClipAndDrawLine(vh, sp, ep, lineWidth, lineColor, serie.clip, grid);
Internal_CheckClipAndDrawLine(vh, sp, ep, lineWidth, lineColor, serie.clip, grid);
sp = ep;
}
if (nnp != np) CheckClipAndDrawPolygon(vh, np, lineWidth, lineColor, serie.clip, true, grid);
if (nnp != np) Internal_CheckClipAndDrawPolygon(vh, np, lineWidth, lineColor, serie.clip, true, grid);
}
else
{
CheckClipAndDrawLine(vh, middle + diff2, np + diff2, lineWidth, lineColor, serie.clip, grid);
Internal_CheckClipAndDrawLine(vh, middle + diff2, np + diff2, lineWidth, lineColor, serie.clip, grid);
}
bool flag2 = ((isYAxis && middle.x > np.x && np.x > zeroPos.x) || (!isYAxis && middle.y > np.y && np.y > zeroPos.y));
if (serie.areaStyle.show && flag2)

View File

@@ -1,412 +0,0 @@
/************************************************/
/* */
/* Copyright (c) 2018 - 2021 monitor1394 */
/* https://github.com/monitor1394 */
/* */
/************************************************/
using System.Text;
using UnityEngine;
using UnityEngine.UI;
namespace XCharts
{
public static class AxisHelper
{
/// <summary>
/// 包含箭头偏移的轴线长度
/// </summary>
/// <param name="axis"></param>
/// <returns></returns>
public static float GetAxisLineSymbolOffset(Axis axis)
{
if (axis.axisLine.show && axis.axisLine.showArrow && axis.axisLine.arrow.offset > 0)
{
return axis.axisLine.arrow.offset;
}
return 0;
}
/// <summary>
/// 获得分割段数
/// </summary>
/// <param name="dataZoom"></param>
/// <returns></returns>
public static int GetSplitNumber(Axis axis, float coordinateWid, DataZoom dataZoom)
{
if (axis.type == Axis.AxisType.Value)
{
if (axis.interval > 0)
{
if (coordinateWid <= 0) return 0;
int num = Mathf.CeilToInt(axis.runtimeMinMaxRange / axis.interval);
int maxNum = Mathf.CeilToInt(coordinateWid / 15);
if (num > maxNum)
{
axis.interval *= 2;
num = Mathf.CeilToInt(axis.runtimeMinMaxRange / axis.interval);
}
return num;
}
else
{
return axis.splitNumber > 0 ? axis.splitNumber : 4;
}
}
else if (axis.type == Axis.AxisType.Time)
{
if (axis.interval > 0)
{
if (coordinateWid <= 0) return 0;
int num = Mathf.CeilToInt(axis.runtimeMinMaxRange / axis.interval);
int maxNum = Mathf.CeilToInt(coordinateWid / 15);
if (num > maxNum)
{
axis.interval *= 2;
num = Mathf.CeilToInt(axis.runtimeMinMaxRange / axis.interval);
}
return num;
}
else
{
return axis.splitNumber > 0 ? axis.splitNumber : 4;
}
}
else if (axis.type == Axis.AxisType.Log)
{
return axis.splitNumber > 0 ? axis.splitNumber : 4;
}
else if (axis.type == Axis.AxisType.Category)
{
int dataCount = axis.GetDataList(dataZoom).Count;
if (axis.splitNumber <= 0 || axis.splitNumber > dataCount) return dataCount;
if (dataCount >= axis.splitNumber * 2) return axis.splitNumber;
else return dataCount;
}
return 0;
}
/// <summary>
/// 获得分割段的宽度
/// </summary>
/// <param name="coordinateWidth"></param>
/// <param name="dataZoom"></param>
/// <returns></returns>
public static float GetSplitWidth(Axis axis, float coordinateWidth, DataZoom dataZoom)
{
int split = GetSplitNumber(axis, coordinateWidth, dataZoom);
int segment = (axis.boundaryGap ? split : split - 1);
segment = segment <= 0 ? 1 : segment;
return coordinateWidth / segment;
}
/// <summary>
/// 获得一个类目数据在坐标系中代表的宽度
/// </summary>
/// <param name="coordinateWidth"></param>
/// <param name="dataZoom"></param>
/// <returns></returns>
public static float GetDataWidth(Axis axis, float coordinateWidth, int dataCount, DataZoom dataZoom)
{
if (dataCount < 1) dataCount = 1;
var categoryCount = axis.GetDataNumber(dataZoom);
int segment = (axis.boundaryGap ? categoryCount : categoryCount - 1);
segment = segment <= 0 ? dataCount : segment;
if (segment <= 0) segment = 1;
return coordinateWidth / segment;
}
/// <summary>
/// 获得标签显示的名称
/// </summary>
/// <param name="index"></param>
/// <param name="minValue"></param>
/// <param name="maxValue"></param>
/// <param name="dataZoom"></param>
/// <returns></returns>
internal static string GetLabelName(Axis axis, float coordinateWidth, int index, float minValue, float maxValue,
DataZoom dataZoom, bool forcePercent)
{
int split = GetSplitNumber(axis, coordinateWidth, dataZoom);
if (axis.type == Axis.AxisType.Value)
{
if (minValue == 0 && maxValue == 0) return string.Empty;
var value = 0f;
if (forcePercent) maxValue = 100;
if (axis.interval > 0)
{
if (index == split) value = maxValue;
else value = minValue + index * axis.interval;
}
else
{
value = minValue + (maxValue - minValue) * index / split;
if (!axis.clockwise && value != minValue) value = maxValue - value;
}
if (axis.inverse)
{
value = -value;
minValue = -minValue;
maxValue = -maxValue;
}
if (forcePercent) return string.Format("{0}%", (int)value);
else return axis.axisLabel.GetFormatterContent(value, minValue, maxValue);
}
else if (axis.type == Axis.AxisType.Log)
{
float value = axis.logBaseE ? Mathf.Exp(axis.runtimeMinLogIndex + index) :
Mathf.Pow(axis.logBase, axis.runtimeMinLogIndex + index);
if (axis.inverse)
{
value = -value;
minValue = -minValue;
maxValue = -maxValue;
}
return axis.axisLabel.GetFormatterContent(value, minValue, maxValue, true);
}
else if (axis.type == Axis.AxisType.Time)
{
if (minValue == 0 && maxValue == 0) return string.Empty;
var value = 0f;
if (axis.interval > 0)
{
if (index == split) value = maxValue;
else value = minValue + index * axis.interval;
}
else
{
value = minValue + (maxValue - minValue) * index / split;
}
var timestamp = (int)value;
var dateTime = DateTimeUtil.GetDateTime(timestamp);
return axis.axisLabel.GetFormatterDateTime(dateTime);
}
var showData = axis.GetDataList(dataZoom);
int dataCount = showData.Count;
if (dataCount <= 0) return "";
int rate = Mathf.RoundToInt(dataCount * 1f / split);
int newIndex = index * rate;
if (newIndex <= dataCount - 1)
{
return axis.axisLabel.GetFormatterContent(showData[newIndex]);
}
else
{
if (rate == 1) return string.Empty;
else if (axis.boundaryGap && coordinateWidth / dataCount > 10) return string.Empty;
else
{
if ((index - 1) * rate > dataCount - 1) return string.Empty;
else return axis.axisLabel.GetFormatterContent(showData[dataCount - 1]);
}
}
}
/// <summary>
/// 获得分割线条数
/// </summary>
/// <param name="dataZoom"></param>
/// <returns></returns>
internal static int GetScaleNumber(Axis axis, float coordinateWidth, DataZoom dataZoom = null)
{
int splitNum = GetSplitNumber(axis, coordinateWidth, dataZoom);
if (axis.IsCategory())
{
var data = axis.GetDataList();
int tick = Mathf.RoundToInt(data.Count * 1f / splitNum);
if (axis.boundaryGap)
return Mathf.CeilToInt(data.Count * 1.0f / tick) + 1;
else
return Mathf.CeilToInt(data.Count * 1.0f / tick);
}
else
{
return splitNum + 1;
}
}
/// <summary>
/// 获得分割段宽度
/// </summary>
/// <param name="coordinateWidth"></param>
/// <param name="dataZoom"></param>
/// <returns></returns>
internal static float GetScaleWidth(Axis axis, float coordinateWidth, int index, DataZoom dataZoom = null)
{
if (index < 0) return 0;
int num = GetScaleNumber(axis, coordinateWidth, dataZoom);
int splitNum = GetSplitNumber(axis, coordinateWidth, dataZoom);
if (num <= 0) num = 1;
if (axis.type == Axis.AxisType.Value && axis.interval > 0)
{
if (axis.runtimeMinMaxRange <= 0) return 0;
if (index >= splitNum) return coordinateWidth - (index - 1) * axis.interval * coordinateWidth / axis.runtimeMinMaxRange;
else return axis.interval * coordinateWidth / axis.runtimeMinMaxRange;
}
else
{
var data = axis.GetDataList();
if (axis.IsCategory() && data.Count > 0)
{
int tick = Mathf.RoundToInt(data.Count * 1f / splitNum);
var count = axis.boundaryGap ? data.Count : data.Count - 1;
if (count <= 0) return 0;
var each = coordinateWidth / count;
if (index >= num - 1)
{
if (axis.axisTick.alignWithLabel) return each * tick;
else return coordinateWidth - each * tick * (index - 1);
}
else return each * tick;
}
else
{
if (splitNum <= 0) return 0;
else return coordinateWidth / splitNum;
}
}
}
internal static float GetEachWidth(Axis axis, float coordinateWidth, DataZoom dataZoom = null)
{
var data = axis.GetDataList();
if (data.Count > 0)
{
var count = axis.boundaryGap ? data.Count : data.Count - 1;
return count > 0 ? coordinateWidth / count : coordinateWidth;
}
else
{
int num = GetScaleNumber(axis, coordinateWidth, dataZoom) - 1;
return num > 0 ? coordinateWidth / num : coordinateWidth;
}
}
/// <summary>
/// 调整最大最小值
/// </summary>
/// <param name="minValue"></param>
/// <param name="maxValue"></param>
internal static void AdjustMinMaxValue(Axis axis, ref float minValue, ref float maxValue, bool needFormat, int ceilRate = 0)
{
if (axis.type == Axis.AxisType.Log)
{
int minSplit = 0;
int maxSplit = 0;
maxValue = ChartHelper.GetMaxLogValue(maxValue, axis.logBase, axis.logBaseE, out maxSplit);
minValue = ChartHelper.GetMinLogValue(minValue, axis.logBase, axis.logBaseE, out minSplit);
axis.splitNumber = (minSplit > 0 && maxSplit > 0) ? (maxSplit + minSplit - 1) : (maxSplit + minSplit);
return;
}
if (axis.minMaxType == Axis.AxisMinMaxType.Custom)
{
if (axis.min != 0 || axis.max != 0)
{
if (axis.inverse)
{
minValue = -axis.max;
maxValue = -axis.min;
}
else
{
minValue = axis.min;
maxValue = axis.max;
}
}
}
else
{
if (ceilRate == 0) ceilRate = axis.ceilRate;
switch (axis.minMaxType)
{
case Axis.AxisMinMaxType.Default:
if (minValue == 0 && maxValue == 0)
{
}
else if (minValue > 0 && maxValue > 0)
{
minValue = 0;
maxValue = needFormat ? ChartHelper.GetMaxDivisibleValue(maxValue, ceilRate) : maxValue;
}
else if (minValue < 0 && maxValue < 0)
{
minValue = needFormat ? ChartHelper.GetMinDivisibleValue(minValue, ceilRate) : minValue;
maxValue = 0;
}
else
{
minValue = needFormat ? ChartHelper.GetMinDivisibleValue(minValue, ceilRate) : minValue;
maxValue = needFormat ? ChartHelper.GetMaxDivisibleValue(maxValue, ceilRate) : maxValue;
}
break;
case Axis.AxisMinMaxType.MinMax:
minValue = needFormat ? ChartHelper.GetMinDivisibleValue(minValue, ceilRate) : minValue;
maxValue = needFormat ? ChartHelper.GetMaxDivisibleValue(maxValue, ceilRate) : maxValue;
break;
}
}
var tempRange = maxValue - minValue;
if (axis.runtimeMinMaxRange != tempRange)
{
axis.runtimeMinMaxRange = tempRange;
if (axis.type == Axis.AxisType.Value && axis.interval > 0)
{
axis.SetComponentDirty();
}
}
}
internal static bool NeedShowSplit(Axis axis)
{
if (!axis.show) return false;
if (axis.IsCategory() && axis.GetDataList().Count <= 0) return false;
else if (axis.IsValue() && axis.runtimeMinValue == 0 && axis.runtimeMaxValue == 0) return false;
else return true;
}
internal static void AdjustCircleLabelPos(ChartText txt, Vector3 pos, Vector3 cenPos, float txtHig, Vector3 offset)
{
var txtWidth = txt.GetPreferredWidth();
var sizeDelta = new Vector2(txtWidth, txt.GetPreferredHeight());
txt.SetSizeDelta(sizeDelta);
var diff = pos.x - cenPos.x;
if (diff < -1f) //left
{
pos = new Vector3(pos.x - txtWidth / 2, pos.y);
}
else if (diff > 1f) //right
{
pos = new Vector3(pos.x + txtWidth / 2, pos.y);
}
else
{
float y = pos.y > cenPos.y ? pos.y + txtHig / 2 : pos.y - txtHig / 2;
pos = new Vector3(pos.x, y);
}
txt.SetLocalPosition(pos + offset);
}
internal static void AdjustRadiusAxisLabelPos(ChartText txt, Vector3 pos, Vector3 cenPos, float txtHig, Vector3 offset)
{
var txtWidth = txt.GetPreferredWidth();
var sizeDelta = new Vector2(txtWidth, txt.GetPreferredHeight());
txt.SetSizeDelta(sizeDelta);
var diff = pos.y - cenPos.y;
if (diff > 20f) //left
{
pos = new Vector3(pos.x - txtWidth / 2, pos.y);
}
else if (diff < -20f) //right
{
pos = new Vector3(pos.x + txtWidth / 2, pos.y);
}
else
{
float y = pos.y > cenPos.y ? pos.y + txtHig / 2 : pos.y - txtHig / 2;
pos = new Vector3(pos.x, y);
}
txt.SetLocalPosition(pos);
}
}
}

View File

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

View File

@@ -1,24 +0,0 @@
/************************************************/
/* */
/* Copyright (c) 2018 - 2021 monitor1394 */
/* https://github.com/monitor1394 */
/* */
/************************************************/
using UnityEngine;
using UnityEngine.UI;
namespace XCharts
{
internal static class ItemStyleHelper
{
public static bool IsNeedCorner(ItemStyle itemStyle)
{
if (itemStyle.cornerRadius == null) return false;
foreach (var value in itemStyle.cornerRadius)
{
if (value != 0) return true;
}
return false;
}
}
}

View File

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

View File

@@ -1,307 +0,0 @@
/************************************************/
/* */
/* Copyright (c) 2018 - 2021 monitor1394 */
/* https://github.com/monitor1394 */
/* */
/************************************************/
using UnityEngine;
using UnityEngine.UI;
namespace XCharts
{
internal static class LegendHelper
{
public static Color GetContentColor(Legend legend, ChartTheme theme, bool active)
{
var textStyle = legend.textStyle;
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, ChartTheme theme, Series series, string legendName, bool active)
{
if (active)
{
if (legend.itemAutoColor || legend.GetIcon(readIndex) == null)
{
return SeriesHelper.GetNameColor(series, readIndex, legendName, theme);
}
else
return Color.white;
}
else return theme.legend.unableColor;
}
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);
var anchorMax = new Vector2(0, 0.5f);
var pivot = new Vector2(0, 0.5f);
var sizeDelta = new Vector2(100, 30);
var iconSizeDelta = new Vector2(legend.itemWidth, legend.itemHeight);
var textStyle = legend.textStyle;
var contentColor = GetContentColor(legend, theme, active);
var objAnchorMin = new Vector2(0, 1);
var objAnchorMax = new Vector2(0, 1);
var objPivot = new Vector2(0, 1);
var btnObj = ChartHelper.AddObject(objName, parent, objAnchorMin, objAnchorMax, objPivot, sizeDelta, i);
var iconObj = ChartHelper.AddObject("icon", btnObj.transform, anchorMin, anchorMax, pivot, iconSizeDelta);
var contentObj = ChartHelper.AddObject("content", btnObj.transform, anchorMin, anchorMax, pivot, sizeDelta);
var img = ChartHelper.GetOrAddComponent<Image>(btnObj);
img.color = Color.clear;
ChartHelper.GetOrAddComponent<Button>(btnObj);
ChartHelper.GetOrAddComponent<Image>(iconObj);
ChartHelper.GetOrAddComponent<Image>(contentObj);
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;
item.legendName = legendName;
item.SetObject(btnObj);
item.SetIconSize(legend.itemWidth, legend.itemHeight);
item.SetIconColor(itemColor);
item.SetIconImage(legend.GetIcon(i));
item.SetContentPosition(textStyle.offsetv3);
item.SetContent(content);
item.SetContentBackgroundColor(textStyle.backgroundColor);
return item;
}
public static void ResetItemPosition(Legend legend, Vector3 chartPos, float chartWidth, float chartHeight)
{
var startX = 0f;
var startY = 0f;
var legendMaxWidth = chartWidth - legend.location.left - legend.location.right;
var legendMaxHeight = chartHeight - legend.location.top - legend.location.bottom;
UpdateLegendWidthAndHeight(legend, legendMaxWidth, legendMaxHeight);
var legendRuntimeWidth = legend.runtimeWidth;
var legendRuntimeHeight = legend.runtimeHeight;
var isVertical = legend.orient == Orient.Vertical;
switch (legend.location.align)
{
case Location.Align.TopCenter:
startX = chartPos.x + chartWidth / 2 - legendRuntimeWidth / 2;
startY = chartPos.y + chartHeight - legend.location.top;
break;
case Location.Align.TopLeft:
startX = chartPos.x + legend.location.left;
startY = chartPos.y + chartHeight - legend.location.top;
break;
case Location.Align.TopRight:
startX = chartPos.x + chartWidth - legendRuntimeWidth - legend.location.right;
startY = chartPos.y + chartHeight - legend.location.top;
break;
case Location.Align.Center:
startX = chartPos.x + chartWidth / 2 - legendRuntimeWidth / 2;
startY = chartPos.y + chartHeight / 2 + legendRuntimeHeight / 2;
break;
case Location.Align.CenterLeft:
startX = chartPos.x + legend.location.left;
startY = chartPos.y + chartHeight / 2 + legendRuntimeHeight / 2;
break;
case Location.Align.CenterRight:
startX = chartPos.x + chartWidth - legendRuntimeWidth - legend.location.right;
startY = chartPos.y + chartHeight / 2 + legendRuntimeHeight / 2;
break;
case Location.Align.BottomCenter:
startX = chartPos.x + chartWidth / 2 - legendRuntimeWidth / 2;
startY = chartPos.y + legendRuntimeHeight + legend.location.bottom;
break;
case Location.Align.BottomLeft:
startX = chartPos.x + legend.location.left;
startY = chartPos.y + legendRuntimeHeight + legend.location.bottom;
break;
case Location.Align.BottomRight:
startX = chartPos.x + chartWidth - legendRuntimeWidth - legend.location.right;
startY = chartPos.y + legendRuntimeHeight + legend.location.bottom;
break;
}
if (isVertical) SetVerticalItemPosition(legend, legendMaxHeight, startX, startY);
else SetHorizonalItemPosition(legend, legendMaxWidth, startX, startY);
}
private static void SetVerticalItemPosition(Legend legend, float legendMaxHeight, float startX, float startY)
{
var currHeight = 0f;
var offsetX = 0f;
var row = 0;
foreach (var kv in legend.buttonList)
{
var item = kv.Value;
if (currHeight + item.height > legendMaxHeight)
{
currHeight = 0;
offsetX += legend.runtimeEachWidth[row];
row++;
}
item.SetPosition(new Vector3(startX + offsetX, startY - currHeight));
currHeight += item.height + legend.itemGap;
}
}
private static void SetHorizonalItemPosition(Legend legend, float legendMaxWidth, float startX, float startY)
{
var currWidth = 0f;
var offsetY = 0f;
foreach (var kv in legend.buttonList)
{
var item = kv.Value;
if (currWidth + item.width > legendMaxWidth)
{
currWidth = 0;
offsetY += legend.runtimeEachHeight;
}
item.SetPosition(new Vector3(startX + currWidth, startY - offsetY));
currWidth += item.width + legend.itemGap;
}
}
private static void UpdateLegendWidthAndHeight(Legend legend, float maxWidth, float maxHeight)
{
var width = 0f;
var height = 0f;
var realHeight = 0f;
var realWidth = 0f;
legend.runtimeEachWidth.Clear();
legend.runtimeEachHeight = 0;
if (legend.orient == Orient.Horizonal)
{
foreach (var kv in legend.buttonList)
{
if (width + kv.Value.width > maxWidth)
{
realWidth = width - legend.itemGap;
realHeight += height + legend.itemGap;
if (legend.runtimeEachHeight < height + legend.itemGap)
{
legend.runtimeEachHeight = height + legend.itemGap;
}
height = 0;
width = 0;
}
width += kv.Value.width + legend.itemGap;
if (kv.Value.height > height)
height = kv.Value.height;
}
width -= legend.itemGap;
legend.runtimeHeight = realHeight + height;
legend.runtimeWidth = realWidth > 0 ? realWidth : width;
}
else
{
var row = 0;
foreach (var kv in legend.buttonList)
{
if (height + kv.Value.height > maxHeight)
{
realHeight = height - legend.itemGap;
realWidth += width + legend.itemGap;
legend.runtimeEachWidth[row] = width + legend.itemGap;
row++;
height = 0;
width = 0;
}
height += kv.Value.height + legend.itemGap;
if (kv.Value.width > width)
width = kv.Value.width;
}
height -= legend.itemGap;
legend.runtimeHeight = realHeight > 0 ? realHeight : height;
legend.runtimeWidth = realWidth + width;
}
}
private static bool IsBeyondWidth(Legend legend, float maxWidth)
{
var totalWidth = 0f;
foreach (var kv in legend.buttonList)
{
var item = kv.Value;
totalWidth += item.width + legend.itemGap;
if (totalWidth > maxWidth) return true;
}
return false;
}
public static bool CheckDataShow(Series series, string legendName, bool show)
{
bool needShow = false;
foreach (var serie in series.list)
{
if (legendName.Equals(serie.name))
{
serie.show = show;
serie.highlighted = false;
if (serie.show) needShow = true;
}
else
{
foreach (var data in serie.data)
{
if (legendName.Equals(data.name))
{
data.show = show;
data.highlighted = false;
if (data.show) needShow = true;
}
}
}
}
return needShow;
}
public static bool CheckDataHighlighted(Series series, string legendName, bool heighlight)
{
bool show = false;
foreach (var serie in series.list)
{
if (legendName.Equals(serie.name))
{
serie.highlighted = heighlight;
}
else
{
foreach (var data in serie.data)
{
if (legendName.Equals(data.name))
{
data.highlighted = heighlight;
if (data.highlighted) show = true;
}
}
}
}
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,11 +0,0 @@
fileFormatVersion: 2
guid: d03ce7a11ecde41b6930883612bf8f05
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -9,9 +9,9 @@ using UnityEngine;
namespace XCharts
{
internal static class PolarHelper
public static class PolarHelper
{
internal static void UpdatePolarCenter(Polar polar, Vector3 chartPosition, float chartWidth, float chartHeight)
public static void UpdatePolarCenter(Polar polar, Vector3 chartPosition, float chartWidth, float chartHeight)
{
if (polar.center.Length < 2) return;
var centerX = polar.center[0] <= 1 ? chartWidth * polar.center[0] : polar.center[0];

View File

@@ -1,427 +0,0 @@
/************************************************/
/* */
/* Copyright (c) 2018 - 2021 monitor1394 */
/* https://github.com/monitor1394 */
/* */
/************************************************/
using System.Collections.Generic;
using UnityEngine;
namespace XCharts
{
public static partial class SerieHelper
{
internal static Color32 GetItemBackgroundColor(Serie serie, SerieData serieData, ChartTheme theme, int index,
bool highlight, bool useDefault = true)
{
var color = ChartConst.clearColor32;
if (highlight)
{
var itemStyleEmphasis = GetItemStyleEmphasis(serie, serieData);
if (itemStyleEmphasis != null && !ChartHelper.IsClearColor(itemStyleEmphasis.backgroundColor))
{
color = itemStyleEmphasis.backgroundColor;
ChartHelper.SetColorOpacity(ref color, itemStyleEmphasis.opacity);
return color;
}
}
var itemStyle = GetItemStyle(serie, serieData);
if (!ChartHelper.IsClearColor(itemStyle.backgroundColor))
{
color = itemStyle.backgroundColor;
if (highlight) color = ChartHelper.GetHighlightColor(color);
ChartHelper.SetColorOpacity(ref color, itemStyle.opacity);
return color;
}
else if (useDefault)
{
color = theme.GetColor(index);
if (highlight) color = ChartHelper.GetHighlightColor(color);
color.a = 50;
return color;
}
return color;
}
internal static Color32 GetItemColor(Serie serie, SerieData serieData, ChartTheme theme, int index, bool highlight)
{
if (serie == null) return ChartConst.clearColor32;
if (highlight)
{
var itemStyleEmphasis = GetItemStyleEmphasis(serie, serieData);
if (itemStyleEmphasis != null && !ChartHelper.IsClearColor(itemStyleEmphasis.color))
{
var color = itemStyleEmphasis.color;
ChartHelper.SetColorOpacity(ref color, itemStyleEmphasis.opacity);
return color;
}
}
var itemStyle = GetItemStyle(serie, serieData);
if (!ChartHelper.IsClearColor(itemStyle.color))
{
return itemStyle.GetColor();
}
else
{
var color = theme.GetColor(index);
if (highlight) color = ChartHelper.GetHighlightColor(color);
ChartHelper.SetColorOpacity(ref color, itemStyle.opacity);
return color;
}
}
internal static Color32 GetItemColor0(Serie serie, SerieData serieData, ChartTheme theme, bool highlight, Color32 defaultColor)
{
if (serie == null) return ChartConst.clearColor32;
if (highlight)
{
var itemStyleEmphasis = GetItemStyleEmphasis(serie, serieData);
if (itemStyleEmphasis != null && !ChartHelper.IsClearColor(itemStyleEmphasis.color))
{
var color = itemStyleEmphasis.color0;
ChartHelper.SetColorOpacity(ref color, itemStyleEmphasis.opacity);
return color;
}
}
var itemStyle = GetItemStyle(serie, serieData);
if (!ChartHelper.IsClearColor(itemStyle.color0))
{
return itemStyle.GetColor0();
}
else
{
var color = defaultColor;
if (highlight) color = ChartHelper.GetHighlightColor(color);
ChartHelper.SetColorOpacity(ref color, itemStyle.opacity);
return color;
}
}
internal static Color32 GetItemToColor(Serie serie, SerieData serieData, ChartTheme theme, int index, bool highlight)
{
if (highlight)
{
var itemStyleEmphasis = GetItemStyleEmphasis(serie, serieData);
if (itemStyleEmphasis != null && !ChartHelper.IsClearColor(itemStyleEmphasis.toColor))
{
return itemStyleEmphasis.GetColor();
}
}
var itemStyle = GetItemStyle(serie, serieData, highlight);
if (itemStyle == null) itemStyle = serieData.itemStyle;
if (!ChartHelper.IsClearColor(itemStyle.toColor))
{
var color = itemStyle.toColor;
if (highlight) color = ChartHelper.GetHighlightColor(color);
ChartHelper.SetColorOpacity(ref color, itemStyle.opacity);
return color;
}
if (!ChartHelper.IsClearColor(itemStyle.color))
{
var color = itemStyle.color;
if (highlight) color = ChartHelper.GetHighlightColor(color);
ChartHelper.SetColorOpacity(ref color, itemStyle.opacity);
return color;
}
else
{
var color = theme.GetColor(index);
if (highlight) color = ChartHelper.GetHighlightColor(color);
ChartHelper.SetColorOpacity(ref color, itemStyle.opacity);
return color;
}
}
internal static bool IsDownPoint(Serie serie, int index)
{
var dataPoints = serie.dataPoints;
if (dataPoints.Count < 2) return false;
else if (index > 0 && index < dataPoints.Count - 1)
{
var lp = dataPoints[index - 1];
var np = dataPoints[index + 1];
var cp = dataPoints[index];
var dot = Vector3.Cross(np - lp, cp - np);
return dot.z < 0;
}
else if (index == 0)
{
return dataPoints[0].y < dataPoints[1].y;
}
else if (index == dataPoints.Count - 1)
{
return dataPoints[index].y < dataPoints[index - 1].y;
}
else
{
return false;
}
}
internal static ItemStyle GetItemStyle(Serie serie, SerieData serieData, bool highlight = false)
{
if (highlight)
{
var style = GetItemStyleEmphasis(serie, serieData);
if (style == null) return GetItemStyle(serie, serieData, false);
else return style;
}
else if (serie.IsPerformanceMode()) return serie.itemStyle;
else if (serieData != null && serieData.enableItemStyle) return serieData.itemStyle;
else return serie.itemStyle;
}
internal static ItemStyle GetItemStyleEmphasis(Serie serie, SerieData serieData)
{
if (!serie.IsPerformanceMode() && serieData != null && serieData.enableEmphasis && serieData.emphasis.show)
return serieData.emphasis.itemStyle;
else if (serie.emphasis.show) return serie.emphasis.itemStyle;
else return null;
}
public static SerieLabel GetSerieLabel(Serie serie, SerieData serieData, bool highlight = false)
{
if (highlight)
{
if (!serie.IsPerformanceMode() && serieData.enableEmphasis && serieData.emphasis.show)
return serieData.emphasis.label;
else if (serie.emphasis.show) return serie.emphasis.label;
else return serie.label;
}
else
{
if (!serie.IsPerformanceMode() && serieData.enableLabel) return serieData.label;
else return serie.label;
}
}
internal static SerieSymbol GetSerieSymbol(Serie serie, SerieData serieData)
{
if (!serie.IsPerformanceMode() && serieData.enableSymbol) return serieData.symbol;
else return serie.symbol;
}
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);
if (highlight)
{
if (!ChartHelper.IsClearColor(areaStyle.highlightColor)) color = areaStyle.highlightColor;
else color = ChartHelper.GetHighlightColor(color);
}
ChartHelper.SetColorOpacity(ref color, areaStyle.opacity);
return color;
}
internal static Color32 GetAreaToColor(Serie serie, ChartTheme theme, int index, bool highlight)
{
var areaStyle = serie.areaStyle;
if (!ChartHelper.IsClearColor(areaStyle.toColor))
{
var color = areaStyle.toColor;
if (highlight)
{
if (!ChartHelper.IsClearColor(areaStyle.highlightToColor)) color = areaStyle.highlightToColor;
else color = ChartHelper.GetHighlightColor(color);
}
ChartHelper.SetColorOpacity(ref color, areaStyle.opacity);
return color;
}
else
{
return GetAreaColor(serie, theme, index, highlight);
}
}
internal static Color32 GetLineColor(Serie serie, ChartTheme theme, int index, bool highlight)
{
Color32 color = ChartConst.clearColor32;
if (highlight)
{
var itemStyleEmphasis = GetItemStyleEmphasis(serie, null);
if (itemStyleEmphasis != null && !ChartHelper.IsClearColor(itemStyleEmphasis.color))
{
color = itemStyleEmphasis.color;
ChartHelper.SetColorOpacity(ref color, itemStyleEmphasis.opacity);
return color;
}
}
if (!ChartHelper.IsClearColor(serie.lineStyle.color)) color = serie.lineStyle.GetColor();
else if (!ChartHelper.IsClearColor(serie.itemStyle.color)) color = serie.itemStyle.GetColor();
if (ChartHelper.IsClearColor(color))
{
color = theme.GetColor(index);
ChartHelper.SetColorOpacity(ref color, serie.lineStyle.opacity);
}
if (highlight) color = ChartHelper.GetHighlightColor(color);
return color;
}
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 return serie.lineStyle.GetWidth(theme.serie.lineWidth);
}
internal static float[] GetSymbolCornerRadius(Serie serie, SerieData serieData, bool highlight)
{
var itemStyle = GetItemStyle(serie, serieData, highlight);
if (itemStyle != null) return itemStyle.cornerRadius;
else return null;
}
internal static string GetNumericFormatter(Serie serie, SerieData serieData)
{
var itemStyle = SerieHelper.GetItemStyle(serie, serieData);
if (!string.IsNullOrEmpty(itemStyle.numericFormatter)) return itemStyle.numericFormatter;
else return string.Empty;
}
/// <summary>
/// 获得指定维数的最大最小值
/// </summary>
/// <param name="dimension"></param>
/// <param name="dataZoom"></param>
/// <returns></returns>
internal static void UpdateMinMaxData(Serie serie, int dimension, int ceilRate = 0, DataZoom dataZoom = null)
{
float min = 0, max = 0;
GetMinMaxData(serie, dimension, out min, out max, dataZoom);
if (ceilRate < 0)
{
serie.runtimeDataMin = min;
serie.runtimeDataMax = max;
}
else
{
serie.runtimeDataMin = ChartHelper.GetMinDivisibleValue(min, ceilRate);
serie.runtimeDataMax = ChartHelper.GetMaxDivisibleValue(max, ceilRate);
}
}
internal static void GetAllMinMaxData(Serie serie, int ceilRate = 0, DataZoom dataZoom = null)
{
float min = 0, max = 0;
GetMinMaxData(serie, out min, out max, dataZoom);
if (ceilRate < 0)
{
serie.runtimeDataMin = min;
serie.runtimeDataMax = max;
}
else
{
serie.runtimeDataMin = ChartHelper.GetMinDivisibleValue(min, ceilRate);
serie.runtimeDataMax = ChartHelper.GetMaxDivisibleValue(max, ceilRate);
}
}
private static List<SerieData> emptyFilter = new List<SerieData>();
/// <summary>
/// 根据dataZoom更新数据列表缓存
/// </summary>
/// <param name="dataZoom"></param>
internal static void UpdateFilterData(Serie serie, DataZoom dataZoom)
{
if (dataZoom == null || !dataZoom.enable) return;
if (dataZoom.xAxisIndexs.Contains(serie.xAxisIndex))
{
if (dataZoom.IsXAxisIndexValue(serie.xAxisIndex))
{
float min = 0, max = 0;
dataZoom.GetXAxisIndexValue(serie.xAxisIndex, out min, out max);
UpdateFilterData_XAxisValue(serie, dataZoom, 0, min, max);
}
else
{
UpdateFilterData_Category(serie, dataZoom);
}
}
else if (dataZoom.yAxisIndexs.Contains(serie.yAxisIndex))
{
if (dataZoom.IsYAxisIndexValue(serie.yAxisIndex))
{
float min = 0, max = 0;
dataZoom.GetYAxisIndexValue(serie.yAxisIndex, out min, out max);
UpdateFilterData_XAxisValue(serie, dataZoom, 0, min, max);
}
else
{
UpdateFilterData_Category(serie, dataZoom);
}
}
}
private static void UpdateFilterData_XAxisValue(Serie serie, DataZoom dataZoom, int dimension, float min, float max)
{
var data = serie.data;
var startValue = min + (max - min) * dataZoom.start / 100;
var endValue = min + (max - min) * dataZoom.end / 100;
if (endValue < startValue) endValue = startValue;
if (startValue != serie.m_FilterStartValue || endValue != serie.m_FilterEndValue
|| dataZoom.minShowNum != serie.m_FilterMinShow || serie.m_NeedUpdateFilterData)
{
serie.m_FilterStartValue = startValue;
serie.m_FilterEndValue = endValue;
serie.m_FilterMinShow = dataZoom.minShowNum;
serie.m_NeedUpdateFilterData = false;
serie.m_FilterData.Clear();
foreach (var serieData in data)
{
var value = serieData.GetData(dimension);
if (value >= startValue && value <= endValue)
{
serie.m_FilterData.Add(serieData);
}
}
}
else if (endValue == 0)
{
serie.m_FilterData = emptyFilter;
}
}
private static void UpdateFilterData_Category(Serie serie, DataZoom dataZoom)
{
var data = serie.data;
var startIndex = (int)((data.Count - 1) * dataZoom.start / 100);
var endIndex = (int)((data.Count - 1) * dataZoom.end / 100);
if (endIndex < startIndex) endIndex = startIndex;
if (startIndex != serie.m_FilterStart || endIndex != serie.m_FilterEnd
|| dataZoom.minShowNum != serie.m_FilterMinShow || serie.m_NeedUpdateFilterData)
{
serie.m_FilterStart = startIndex;
serie.m_FilterEnd = endIndex;
serie.m_FilterMinShow = dataZoom.minShowNum;
serie.m_NeedUpdateFilterData = false;
var count = endIndex == startIndex ? 1 : endIndex - startIndex + 1;
if (count < dataZoom.minShowNum)
{
if (dataZoom.minShowNum > data.Count) count = data.Count;
else count = dataZoom.minShowNum;
}
if (data.Count > 0)
{
if (startIndex + count > data.Count)
{
int start = endIndex - count;
data = data.GetRange(start < 0 ? 0 : start, count);
}
else serie.m_FilterData = data.GetRange(startIndex, count);
}
else
{
serie.m_FilterData = data;
}
}
else if (endIndex == 0)
{
serie.m_FilterData = emptyFilter;
}
}
}
}

View File

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

View File

@@ -1,314 +0,0 @@
/************************************************/
/* */
/* Copyright (c) 2018 - 2021 monitor1394 */
/* https://github.com/monitor1394 */
/* */
/************************************************/
using System.Collections.Generic;
using UnityEngine;
namespace XCharts
{
public static class SerieLabelHelper
{
public static void CheckLabel(Serie serie, ref bool m_ReinitLabel, ref bool m_UpdateLabelText)
{
switch (serie.type)
{
case SerieType.Gauge:
case SerieType.Ring:
var serieData = serie.GetSerieData(0);
if (serieData != null)
{
if (serie.label.show && serie.show)
{
if (serieData.labelObject != null)
{
serieData.SetLabelActive(true);
m_UpdateLabelText = true;
}
else
{
m_ReinitLabel = true;
}
}
else if (serieData.labelObject != null)
{
serieData.SetLabelActive(false);
}
}
break;
}
}
public static void UpdateLabelText(Series series, ChartTheme theme, List<string> legendRealShowName)
{
foreach (var serie in series.list)
{
if (!serie.label.show) continue;
var colorIndex = legendRealShowName.IndexOf(serie.name);
switch (serie.type)
{
case SerieType.Gauge:
SetGaugeLabelText(serie);
break;
case SerieType.Ring:
SetRingLabelText(serie, theme);
break;
case SerieType.Liquid:
SetLiquidLabelText(serie, theme, colorIndex);
break;
}
}
}
public static Color GetLabelColor(Serie serie, ChartTheme theme, int index)
{
if (!ChartHelper.IsClearColor(serie.label.textStyle.color))
{
return serie.label.textStyle.color;
}
else
{
return theme.GetColor(index);
}
}
public static void ResetLabel(ChartText labelObject, SerieLabel label, ChartTheme theme, int colorIndex)
{
if (labelObject == null) return;
labelObject.SetColor(!ChartHelper.IsClearColor(label.textStyle.color) ? label.textStyle.color :
(Color)theme.GetColor(colorIndex));
labelObject.SetFontSize(label.textStyle.GetFontSize(theme.common));
labelObject.SetFontStyle(label.textStyle.fontStyle);
}
public static bool CanShowLabel(Serie serie, SerieData serieData, SerieLabel label, int dimesion)
{
return serie.show && serieData.canShowLabel && !serie.IsIgnoreValue(serieData.GetData(dimesion));
}
public static string GetFormatterContent(Serie serie, SerieData serieData,
float dataValue, float dataTotal, SerieLabel serieLabel, Color color)
{
if (serieLabel == null)
{
serieLabel = SerieHelper.GetSerieLabel(serie, serieData);
}
var numericFormatter = serieLabel == null ? serie.label.numericFormatter : serieLabel.numericFormatter;
var serieName = serie.name;
var dataName = serieData != null ? serieData.name : null;
if (string.IsNullOrEmpty(serieLabel.formatter))
return ChartCached.NumberToStr(dataValue, numericFormatter);
else
{
var content = serieLabel.formatter;
FormatterHelper.ReplaceSerieLabelContent(ref content, numericFormatter, dataValue,
dataTotal, serieName, dataName, color);
return content;
}
}
public static void SetGaugeLabelText(Serie serie)
{
var serieData = serie.GetSerieData(0);
if (serieData == null) return;
if (serieData.labelObject == null) return;
var value = serieData.GetData(1);
var total = serie.max;
var content = SerieLabelHelper.GetFormatterContent(serie, serieData, value, total, null, Color.clear);
serieData.labelObject.SetText(content);
serieData.labelObject.SetLabelPosition(serie.runtimeCenterPos + serie.label.offset);
if (!ChartHelper.IsClearColor(serie.label.textStyle.color))
{
serieData.labelObject.label.SetColor(serie.label.textStyle.color);
}
}
public static void SetRingLabelText(Serie serie, ChartTheme theme)
{
for (int i = 0; i < serie.dataCount; i++)
{
var serieData = serie.data[i];
var serieLabel = SerieHelper.GetSerieLabel(serie, serieData, serieData.highlighted);
if (serieLabel.show && serieData.labelObject != null)
{
if (!serie.show || !serieData.show)
{
serieData.SetLabelActive(false);
continue;
}
var value = serieData.GetData(0);
var total = serieData.GetData(1);
var content = SerieLabelHelper.GetFormatterContent(serie, serieData, value, total, null, Color.clear);
serieData.SetLabelActive(true);
serieData.labelObject.SetText(content);
serieData.labelObject.SetLabelColor(GetLabelColor(serie, theme, i));
if (serie.label.position == SerieLabel.Position.Bottom)
{
var labelWidth = serieData.GetLabelWidth();
if (serie.clockwise)
serieData.labelObject.SetLabelPosition(serieData.labelPosition - new Vector3(labelWidth / 2, 0));
else
serieData.labelObject.SetLabelPosition(serieData.labelPosition + new Vector3(labelWidth / 2, 0));
}
else
{
serieData.labelObject.SetLabelPosition(serieData.labelPosition);
}
}
}
}
public static void SetLiquidLabelText(Serie serie, ChartTheme theme, int colorIndex)
{
var serieData = serie.GetSerieData(0);
if (serieData == null) return;
var serieLabel = SerieHelper.GetSerieLabel(serie, serieData, serieData.highlighted);
if (serieLabel.show && serieData.labelObject != null)
{
if (!serie.show || !serieData.show)
{
serieData.SetLabelActive(false);
return;
}
var value = serieData.GetData(1);
var total = serie.max - serie.min;
var content = SerieLabelHelper.GetFormatterContent(serie, serieData, value, total, null, Color.clear);
serieData.SetLabelActive(true);
serieData.labelObject.SetText(content);
serieData.labelObject.SetLabelColor(GetLabelColor(serie, theme, colorIndex));
serieData.labelObject.SetLabelPosition(serieData.labelPosition + serieLabel.offset);
}
}
public static void UpdatePieLabelPosition(Serie serie, SerieData serieData)
{
if (serieData.labelObject == null) return;
var currAngle = serieData.runtimePieHalfAngle;
var currRad = currAngle * Mathf.Deg2Rad;
var offsetRadius = serieData.runtimePieOffsetRadius;
var insideRadius = serieData.runtimePieInsideRadius;
var outsideRadius = serieData.runtimePieOutsideRadius;
var serieLabel = SerieHelper.GetSerieLabel(serie, serieData);
switch (serieLabel.position)
{
case SerieLabel.Position.Center:
serieData.labelPosition = serie.runtimeCenterPos;
break;
case SerieLabel.Position.Inside:
var labelRadius = offsetRadius + insideRadius + (outsideRadius - insideRadius) / 2;
var labelCenter = new Vector2(serie.runtimeCenterPos.x + labelRadius * Mathf.Sin(currRad),
serie.runtimeCenterPos.y + labelRadius * Mathf.Cos(currRad));
serieData.labelPosition = labelCenter;
break;
case SerieLabel.Position.Outside:
if (serieLabel.lineType == SerieLabel.LineType.HorizontalLine)
{
var radius1 = serie.runtimeOutsideRadius;
var radius3 = insideRadius + (outsideRadius - insideRadius) / 2;
var currSin = Mathf.Sin(currRad);
var currCos = Mathf.Cos(currRad);
var pos0 = new Vector3(serie.runtimeCenterPos.x + radius3 * currSin, serie.runtimeCenterPos.y + radius3 * currCos);
if (currAngle > 180)
{
currSin = Mathf.Sin((360 - currAngle) * Mathf.Deg2Rad);
currCos = Mathf.Cos((360 - currAngle) * Mathf.Deg2Rad);
}
var r4 = Mathf.Sqrt(radius1 * radius1 - Mathf.Pow(currCos * radius3, 2)) - currSin * radius3;
r4 += serieLabel.lineLength1 + serieLabel.lineWidth * 4;
r4 += serieData.labelObject.label.GetPreferredWidth() / 2;
serieData.labelPosition = pos0 + (currAngle > 180 ? Vector3.left : Vector3.right) * r4;
}
else
{
labelRadius = serie.runtimeOutsideRadius + serieLabel.lineLength1;
labelCenter = new Vector2(serie.runtimeCenterPos.x + labelRadius * Mathf.Sin(currRad),
serie.runtimeCenterPos.y + labelRadius * Mathf.Cos(currRad));
serieData.labelPosition = labelCenter;
}
break;
}
}
internal static void AvoidLabelOverlap(Serie serie)
{
if (!serie.avoidLabelOverlap) return;
var lastCheckPos = Vector3.zero;
var data = serie.data;
var splitCount = 0;
for (int n = 0; n < data.Count; n++)
{
var serieData = data[n];
if (serieData.labelPosition.x != 0 && serieData.labelPosition.x < serie.runtimeCenterPos.x)
{
splitCount = n;
break;
}
}
for (int n = 0; n < splitCount; n++)
{
var serieData = data[n];
CheckSerieDataLabel(serie, serieData, false, ref lastCheckPos);
}
lastCheckPos = Vector3.zero;
for (int n = data.Count - 1; n >= splitCount; n--)
{
var serieData = data[n];
CheckSerieDataLabel(serie, serieData, true, ref lastCheckPos);
}
}
private static void CheckSerieDataLabel(Serie serie, SerieData serieData, bool isLeft, ref Vector3 lastCheckPos)
{
if (!serieData.canShowLabel)
{
serieData.SetLabelActive(false);
return;
}
if (!serieData.show) return;
var serieLabel = SerieHelper.GetSerieLabel(serie, serieData);
if (!serieLabel.show) return;
if (serieLabel.position != SerieLabel.Position.Outside) return;
if (lastCheckPos == Vector3.zero)
{
lastCheckPos = serieData.labelPosition;
}
else if (serieData.labelPosition.x != 0)
{
float hig = serieLabel.textStyle.fontSize;
if (lastCheckPos.y - serieData.labelPosition.y < hig)
{
var labelRadius = serie.runtimeOutsideRadius + serieLabel.lineLength1;
var y1 = lastCheckPos.y - hig;
var cy = serie.runtimeCenterPos.y;
var diff = Mathf.Abs(y1 - cy);
var diffX = labelRadius * labelRadius - diff * diff;
diffX = diffX <= 0 ? 0 : diffX;
var x1 = serie.runtimeCenterPos.x + Mathf.Sqrt(diffX) * (isLeft ? -1 : 1);
serieData.labelPosition = new Vector3(x1, y1);
}
lastCheckPos = serieData.labelPosition;
serieData.labelObject.SetPosition(SerieLabelHelper.GetRealLabelPosition(serieData, serieLabel));
}
}
public static Vector3 GetRealLabelPosition(SerieData serieData, SerieLabel label)
{
if (label.position == SerieLabel.Position.Outside && label.lineType != SerieLabel.LineType.HorizontalLine)
{
var currAngle = serieData.runtimePieHalfAngle;
var offset = label.lineLength2 + serieData.labelObject.GetLabelWidth() / 2;
if (currAngle > 180)
return serieData.labelPosition + new Vector3(-offset, 0, 0);
else
return serieData.labelPosition + new Vector3(offset, 0, 0);
}
else
{
return serieData.labelPosition;
}
}
}
}

View File

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

View File

@@ -1,548 +0,0 @@
/************************************************/
/* */
/* Copyright (c) 2018 - 2021 monitor1394 */
/* https://github.com/monitor1394 */
/* */
/************************************************/
using System.Collections.Generic;
using UnityEngine;
namespace XCharts
{
public static class SeriesHelper
{
public static bool IsNeedLabelUpdate(Series series)
{
foreach (var serie in series.list)
{
if (serie.label.vertsDirty) return true;
}
return false;
}
public static bool IsLabelDirty(Series series)
{
if (series.labelDirty) return true;
foreach (var serie in series.list)
{
if (serie.label.componentDirty) return true;
}
return false;
}
public static bool IsNameDirty(Series series)
{
foreach (var serie in series.list)
{
if (serie.nameDirty) return true;
}
return false;
}
public static void ClearNameDirty(Series series)
{
foreach (var serie in series.list)
{
serie.ClearNameDirty();
}
}
public static bool IsLegalLegendName(string name)
{
int numName = -1;
if (int.TryParse(name, out numName))
{
if (numName >= 0 && numName < 100) return false;
}
return true;
}
public static List<string> GetLegalSerieNameList(Series series)
{
var list = new List<string>();
for (int n = 0; n < series.list.Count; n++)
{
var serie = series.GetSerie(n);
switch (serie.type)
{
case SerieType.Pie:
case SerieType.Radar:
case SerieType.Ring:
for (int i = 0; i < serie.data.Count; i++)
{
var dataName = serie.data[i].name;
if (!string.IsNullOrEmpty(dataName) && IsLegalLegendName(dataName) && !list.Contains(dataName))
list.Add(dataName);
}
break;
default:
if (!string.IsNullOrEmpty(serie.name) && !list.Contains(serie.name) && IsLegalLegendName(serie.name))
list.Add(serie.name);
break;
}
}
return list;
}
/// <summary>
/// 获得所有系列名,不包含空名字。
/// </summary>
/// <returns></returns>
internal static void UpdateSerieNameList(Series series, ref List<string> serieNameList)
{
serieNameList.Clear();
for (int n = 0; n < series.list.Count; n++)
{
var serie = series.GetSerie(n);
switch (serie.type)
{
case SerieType.Pie:
case SerieType.Radar:
case SerieType.Ring:
for (int i = 0; i < serie.data.Count; i++)
{
if (serie.type == SerieType.Pie && serie.IsIgnoreValue(serie.data[i].GetData(1))) continue;
if (string.IsNullOrEmpty(serie.data[i].name))
serieNameList.Add(ChartCached.IntToStr(i));
else if (!serieNameList.Contains(serie.data[i].name))
serieNameList.Add(serie.data[i].name);
}
break;
default:
if (string.IsNullOrEmpty(serie.name))
serieNameList.Add(ChartCached.IntToStr(n));
else if (!serieNameList.Contains(serie.name))
serieNameList.Add(serie.name);
break;
}
}
}
internal static Color GetNameColor(Series series, int index, string name, ChartTheme theme)
{
Serie destSerie = null;
SerieData destSerieData = null;
for (int n = 0; n < series.list.Count; n++)
{
var serie = series.GetSerie(n);
if (serie.type == SerieType.Pie || serie.type == SerieType.Radar || serie.type == SerieType.Ring)
{
bool found = false;
for (int i = 0; i < serie.data.Count; i++)
{
if (name.Equals(serie.data[i].name))
{
destSerie = serie;
destSerieData = serie.data[i];
found = true;
break;
}
}
if (found) break;
}
else
{
if (name.Equals(serie.name))
{
destSerie = serie;
destSerieData = null;
break;
}
}
}
return SerieHelper.GetItemColor(destSerie, destSerieData, theme, index, false);
}
/// <summary>
/// 同堆叠的serie是否有渐变色的。
/// </summary>
/// <param name="stack"></param>
/// <returns></returns>
internal static bool IsAnyGradientSerie(Series series, string stack)
{
if (string.IsNullOrEmpty(stack)) return false;
foreach (var serie in series.list)
{
if (serie.show && serie.areaStyle.show && stack.Equals(serie.stack))
{
if (!ChartHelper.IsValueEqualsColor(serie.areaStyle.color, serie.areaStyle.toColor)
&& !ChartHelper.IsClearColor(serie.areaStyle.toColor))
return true;
}
}
return false;
}
/// <summary>
/// 是否有需裁剪的serie。
/// </summary>
/// <returns></returns>
internal static bool IsAnyClipSerie(Series series)
{
foreach (var serie in series.list)
{
if (serie.clip) return true;
}
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)
{
if (serie.animation.enable && serie.animation.dataChangeEnable)
{
return true;
}
}
return false;
}
/// <summary>
/// 获得上一个同堆叠且显示的serie。
/// </summary>
/// <param name="serie"></param>
/// <returns></returns>
internal static Serie GetLastStackSerie(Series series, Serie serie)
{
if (serie == null || string.IsNullOrEmpty(serie.stack)) return null;
for (int i = serie.index - 1; i >= 0; i--)
{
var temp = series.list[i];
if (temp.show && serie.stack.Equals(temp.stack)) return temp;
}
return null;
}
/// <summary>
/// 获得上一个同堆叠且显示的serie。
/// </summary>
/// <param name="index"></param>
/// <returns></returns>
internal static Serie GetLastStackSerie(Series series, int index)
{
var serie = series.GetSerie(index);
return GetLastStackSerie(series, serie);
}
internal static Serie GetSerieByVesselIndex(Series series, int vesselIndex)
{
foreach (var serie in series.list)
{
if (serie.vesselIndex == vesselIndex) return serie;
}
return null;
}
private static HashSet<string> _setForStack = new HashSet<string>();
/// <summary>
/// 是否由数据堆叠
/// </summary>
/// <returns></returns>
internal static bool IsStack(Series series)
{
_setForStack.Clear();
foreach (var serie in series.list)
{
if (string.IsNullOrEmpty(serie.stack)) continue;
if (_setForStack.Contains(serie.stack)) return true;
else
{
_setForStack.Add(serie.stack);
}
}
return false;
}
/// <summary>
/// 是否堆叠
/// </summary>
/// <param name="stackName"></param>
/// <param name="type"></param>
/// <returns></returns>
internal static bool IsStack(Series series, string stackName, SerieType type)
{
if (string.IsNullOrEmpty(stackName)) return false;
int count = 0;
foreach (var serie in series.list)
{
if (serie.show && serie.type == type)
{
if (stackName.Equals(serie.stack)) count++;
if (count >= 2) return true;
}
}
return false;
}
/// <summary>
/// 是否时百分比堆叠
/// </summary>
/// <param name="type"></param>
/// <returns></returns>
internal static bool IsPercentStack(Series series, SerieType type)
{
int count = 0;
bool isPercentStack = false;
foreach (var serie in series.list)
{
if (serie.show && serie.type == type)
{
if (!string.IsNullOrEmpty(serie.stack))
{
count++;
if (serie.barPercentStack) isPercentStack = true;
}
if (count >= 2 && isPercentStack) return true;
}
}
return false;
}
/// <summary>
/// 是否时百分比堆叠
/// </summary>
/// <param name="stackName"></param>
/// <param name="type"></param>
/// <returns></returns>
internal static bool IsPercentStack(Series series, string stackName, SerieType type)
{
if (string.IsNullOrEmpty(stackName)) return false;
int count = 0;
bool isPercentStack = false;
foreach (var serie in series.list)
{
if (serie.show && serie.type == type)
{
if (stackName.Equals(serie.stack))
{
count++;
if (serie.barPercentStack) isPercentStack = true;
}
if (count >= 2 && isPercentStack) return true;
}
}
return false;
}
private static Dictionary<string, int> sets = new Dictionary<string, int>();
/// <summary>
/// 获得堆叠系列列表
/// </summary>
/// <param name="Dictionary<int"></param>
/// <param name="stackSeries"></param>
internal static void GetStackSeries(Series series, ref Dictionary<int, List<Serie>> stackSeries)
{
int count = 0;
var serieCount = series.list.Count;
sets.Clear();
if (stackSeries == null)
{
stackSeries = new Dictionary<int, List<Serie>>(serieCount);
}
else
{
foreach (var kv in stackSeries)
{
kv.Value.Clear();
}
}
for (int i = 0; i < serieCount; i++)
{
var serie = series.GetSerie(i);
serie.index = i;
if (string.IsNullOrEmpty(serie.stack))
{
if (!stackSeries.ContainsKey(count))
stackSeries[count] = new List<Serie>(serieCount);
stackSeries[count].Add(serie);
count++;
}
else
{
if (!sets.ContainsKey(serie.stack))
{
sets.Add(serie.stack, count);
if (!stackSeries.ContainsKey(count))
stackSeries[count] = new List<Serie>(serieCount);
stackSeries[count].Add(serie);
count++;
}
else
{
int stackIndex = sets[serie.stack];
stackSeries[stackIndex].Add(serie);
}
}
}
}
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>
/// <param name="dataZoom"></param>
/// <param name="axisIndex"></param>
/// <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 isPolar = false)
{
GetMinMaxValue(series, dataZoom, axisIndex, isValueAxis, inverse, false, out minVaule, out maxValue, isPolar);
}
/// <summary>
/// 获得维度Y的最大最小值
/// </summary>
/// <param name="dataZoom"></param>
/// <param name="axisIndex"></param>
/// <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 isPolar = false)
{
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 isPolar = false)
{
float min = int.MaxValue;
float max = int.MinValue;
var isPercentStack = SeriesHelper.IsPercentStack(series, SerieType.Bar);
if (!SeriesHelper.IsStack(series) || (isValueAxis && !yValue))
{
for (int i = 0; i < series.list.Count; i++)
{
var serie = series.GetSerie(i);
if ((isPolar && serie.polarIndex != axisIndex)
|| (!isPolar && serie.yAxisIndex != axisIndex)) continue;
if (series.IsActive(i))
{
if (isPercentStack && SeriesHelper.IsPercentStack(series, serie.name, SerieType.Bar))
{
if (100 > max) max = 100;
if (0 < min) min = 0;
}
else
{
var showData = serie.GetDataList(dataZoom);
foreach (var data in showData)
{
if (serie.type == SerieType.Candlestick)
{
var dataMin = data.min;
var dataMax = data.max;
if (dataMax > max) max = dataMax;
if (dataMin < min) min = dataMin;
}
else
{
var currData = data.GetData(yValue ? 1 : 0, inverse);
if (currData > max) max = currData;
if (currData < min) min = currData;
}
}
}
}
}
}
else
{
SeriesHelper.GetStackSeries(series, ref _stackSeriesForMinMax);
foreach (var ss in _stackSeriesForMinMax)
{
_serieTotalValueForMinMax.Clear();
for (int i = 0; i < ss.Value.Count; i++)
{
var serie = ss.Value[i];
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))
{
for (int j = 0; j < showData.Count; j++)
{
_serieTotalValueForMinMax[j] = 100;
}
}
else
{
for (int j = 0; j < showData.Count; j++)
{
if (!_serieTotalValueForMinMax.ContainsKey(j))
_serieTotalValueForMinMax[j] = 0;
var currData = 0f;
if (serie.type == SerieType.Candlestick)
{
currData = showData[j].max;
}
else
{
currData = yValue ? showData[j].GetData(1) : showData[j].GetData(0);
}
if (inverse) currData = -currData;
_serieTotalValueForMinMax[j] = _serieTotalValueForMinMax[j] + currData;
}
}
}
float tmax = int.MinValue;
float tmin = int.MaxValue;
foreach (var tt in _serieTotalValueForMinMax)
{
if (tt.Value > tmax) tmax = tt.Value;
if (tt.Value < tmin) tmin = tt.Value;
}
if (tmax > max) max = tmax;
if (tmin < min) min = tmin;
}
}
if (max == int.MinValue && min == int.MaxValue)
{
minVaule = 0;
maxValue = 0;
}
else
{
minVaule = min > 1 ? Mathf.FloorToInt(min) : min;
maxValue = max > 1 ? Mathf.CeilToInt(max) : max;
}
}
public static int GetMaxSerieDataCount(Series series)
{
int max = 0;
foreach (var serie in series.list)
{
if (serie.dataCount > max) max = serie.dataCount;
}
return max;
}
}
}

View File

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

View File

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

View File

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

View File

@@ -1,43 +0,0 @@
/************************************************/
/* */
/* Copyright (c) 2018 - 2021 monitor1394 */
/* https://github.com/monitor1394 */
/* */
/************************************************/
using UnityEngine;
using UnityEngine.UI;
namespace XCharts
{
internal static class TitleStyleHelper
{
public static void CheckTitle(Serie serie, ref bool m_ReinitTitle, ref bool m_UpdateTitleText)
{
if (serie.titleStyle.show)
{
if (serie.titleStyle.IsInited())
{
serie.titleStyle.UpdatePosition(serie.runtimeCenterPos);
m_UpdateTitleText = true;
}
else
{
m_ReinitTitle = true;
}
}
}
public static void UpdateTitleText(Series series)
{
foreach (var serie in series.list) UpdateTitleText(serie);
}
public static void UpdateTitleText(Serie serie)
{
if (serie.titleStyle.show)
{
serie.titleStyle.SetText(serie.name);
}
}
}
}

View File

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

View File

@@ -1,577 +0,0 @@
/************************************************/
/* */
/* Copyright (c) 2018 - 2021 monitor1394 */
/* https://github.com/monitor1394 */
/* */
/************************************************/
using System.Text;
using UnityEngine;
namespace XCharts
{
internal static class TooltipHelper
{
private static void InitScatterTooltip(ref StringBuilder sb, Tooltip tooltip, Serie serie, int index,
ChartTheme theme)
{
if (!tooltip.runtimeSerieIndex.ContainsKey(serie.index)) return;
var dataIndexList = tooltip.runtimeSerieIndex[serie.index];
if (!string.IsNullOrEmpty(serie.name))
{
sb.Append(serie.name).Append(FormatterHelper.PH_NN);
}
for (int i = 0; i < dataIndexList.Count; i++)
{
var dataIndex = dataIndexList[i];
var serieData = serie.GetSerieData(dataIndex);
var numericFormatter = GetItemNumericFormatter(tooltip, serie, serieData);
float xValue, yValue;
serie.GetXYData(dataIndex, null, out xValue, out yValue);
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),
ChartCached.FloatToStr(yValue, numericFormatter));
if (i != dataIndexList.Count - 1)
{
sb.Append("\n");
}
}
}
private static void InitPieTooltip(ref StringBuilder sb, Tooltip tooltip, Serie serie, int index,
ChartTheme theme)
{
if (tooltip.runtimeDataIndex[serie.index] < 0) return;
string key = serie.data[index].name;
var serieData = serie.GetSerieData(index);
var numericFormatter = GetItemNumericFormatter(tooltip, serie, serieData);
float value = serieData.GetData(1);
sb.Length = 0;
if (!string.IsNullOrEmpty(serie.name))
{
sb.Append(serie.name).Append(FormatterHelper.PH_NN);
}
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,
ChartTheme theme)
{
var serieData = serie.GetSerieData(index);
var numericFormatter = GetItemNumericFormatter(tooltip, serie, serieData);
float value = serieData.GetFirstData();
sb.Length = 0;
if (!string.IsNullOrEmpty(serieData.name))
{
sb.Append("<color=#").Append(theme.GetColorStr(index)).Append(">● </color>")
.Append(serieData.name).Append(": ").Append(ChartCached.FloatToStr(value, numericFormatter));
}
else
{
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,
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);
if (!serieData.show) return;
var numericFormatter = GetItemNumericFormatter(tooltip, serie, serieData);
switch (serie.radarType)
{
case RadarType.Multiple:
if (radar.isAxisTooltip)
{
var dimension = tooltip.runtimeDataIndex[2];
if (!string.IsNullOrEmpty(serie.name))
sb.Append(serie.name).Append("\n");
var total = serie.GetDataTotal(dimension);
var first = true;
for (int i = 0; i < serie.dataCount; i++)
{
var sd = serie.GetSerieData(i);
if (!sd.show) continue;
var key = sd.name;
var value = sd.GetData(dimension);
var itemFormatter = GetItemFormatter(tooltip, serie, sd);
numericFormatter = GetItemNumericFormatter(tooltip, serie, sd);
if (!first) sb.Append("\n");
first = false;
sb.Append("<color=#").Append(theme.GetColorStr(i)).Append(">● </color>");
if (string.IsNullOrEmpty(itemFormatter))
{
if (string.IsNullOrEmpty(key)) key = radar.indicatorList[dataIndex].name;
if (string.IsNullOrEmpty(key))
sb.AppendFormat("{0}\n", ChartCached.FloatToStr(value, numericFormatter));
else
sb.AppendFormat("{0}: {1}\n", key, ChartCached.FloatToStr(value, numericFormatter));
}
else
{
string content = itemFormatter;
FormatterHelper.ReplaceSerieLabelContent(ref content, numericFormatter, value, total, serie.name,
sd.name, theme.GetColor(i));
sb.Append(content);
}
}
}
else
{
if (serie.index != tooltip.runtimeDataIndex[0]) return;
sb.Append(serieData.name);
for (int i = 0; i < radar.indicatorList.Count; i++)
{
string key = radar.indicatorList[i].name;
float value = serieData.GetData(i);
if ((i == 0 && !string.IsNullOrEmpty(serieData.name)) || i > 0) sb.Append(FormatterHelper.PH_NN);
sb.AppendFormat("{0}: {1}", key, ChartCached.FloatToStr(value, numericFormatter));
}
}
break;
case RadarType.Single:
var key2 = serieData.name;
var value2 = serieData.GetData(1);
var total2 = serie.GetDataTotal(1);
var itemFormatter2 = GetItemFormatter(tooltip, serie, serieData);
if (string.IsNullOrEmpty(itemFormatter2))
{
if (string.IsNullOrEmpty(key2))
{
key2 = radar.indicatorList[dataIndex].name;
}
sb.AppendFormat("{0}: {1}", key2, ChartCached.FloatToStr(value2, numericFormatter));
}
else
{
string content = itemFormatter2;
FormatterHelper.ReplaceSerieLabelContent(ref content, numericFormatter, value2, total2, serie.name,
serieData.name, theme.GetColor(serie.index));
sb.Append(content);
}
break;
}
}
private static void InitCoordinateTooltip(ref StringBuilder sb, Tooltip tooltip, Serie serie, int index,
ChartTheme theme, bool isCartesian, DataZoom dataZoom = null)
{
string key = serie.name;
float xValue, yValue;
serie.GetXYData(index, dataZoom, out xValue, out yValue);
var isIngore = serie.IsIgnorePoint(index);
var serieData = serie.GetSerieData(index, dataZoom);
var numericFormatter = GetItemNumericFormatter(tooltip, serie, serieData);
if (isCartesian)
{
if (serieData != null && serieData.highlighted)
{
sb.Append(key).Append(!string.IsNullOrEmpty(key) ? " : " : "");
sb.Append("[").Append(ChartCached.FloatToStr(xValue, numericFormatter)).Append(",")
.Append(ChartCached.FloatToStr(yValue, numericFormatter)).Append("]");
}
}
else if (!isIngore || (isIngore && tooltip.ignoreDataShow))
{
var valueTxt = isIngore ? tooltip.ignoreDataDefaultContent :
ChartCached.FloatToStr(yValue, numericFormatter);
sb.Append("<color=#").Append(theme.GetColorStr(serie.index)).Append(">● </color>");
if (serie.type == SerieType.Candlestick)
{
sb.Append(key).Append(FormatterHelper.PH_NN);
var data = serieData.data;
var open = ChartCached.FloatToStr(data[0], numericFormatter);
var close = ChartCached.FloatToStr(data[1], numericFormatter);
var lowest = ChartCached.FloatToStr(data[2], numericFormatter);
var heighest = ChartCached.FloatToStr(data[3], numericFormatter);
sb.Append(" open: ").Append(open).Append(FormatterHelper.PH_NN);
sb.Append(" close: ").Append(close).Append(FormatterHelper.PH_NN);
sb.Append(" lowest: ").Append(lowest).Append(FormatterHelper.PH_NN);
sb.Append(" heighest: ").Append(heighest);
}
else
{
sb.Append(key).Append(!string.IsNullOrEmpty(key) ? " : " : "");
sb.Append(valueTxt);
}
}
}
private static void InitGanttTooltip(ref StringBuilder sb, Tooltip tooltip, Serie serie, int index,
ChartTheme theme)
{
//if (tooltip.runtimeGridIndex >= 0) return;
//if (serie.index != index || serie.type != SerieType.Gantt) return;
sb.Append(serie.name);
}
private static void InitDefaultContent(ref StringBuilder sb, Tooltip tooltip, Serie serie, int index,
ChartTheme theme = null, DataZoom dataZoom = null, bool isCartesian = false,
Radar radar = null)
{
switch (serie.type)
{
case SerieType.Line:
case SerieType.Bar:
case SerieType.Candlestick:
InitCoordinateTooltip(ref sb, tooltip, serie, index, theme, isCartesian, dataZoom);
break;
case SerieType.Scatter:
case SerieType.EffectScatter:
InitScatterTooltip(ref sb, tooltip, serie, index, theme);
break;
case SerieType.Radar:
InitRadarTooltip(ref sb, tooltip, serie, radar, theme);
break;
case SerieType.Pie:
InitPieTooltip(ref sb, tooltip, serie, index, theme);
break;
case SerieType.Ring:
InitRingTooltip(ref sb, tooltip, serie, index, theme);
break;
case SerieType.Heatmap:
break;
case SerieType.Gauge:
InitGaugeTooltip(ref sb, tooltip, serie, index, theme);
break;
case SerieType.Gantt:
InitGanttTooltip(ref sb, tooltip, serie, index, theme);
break;
}
}
public static void SetContentAndPosition(Tooltip tooltip, string content, Rect chartRect)
{
tooltip.UpdateContentText(content);
var pos = tooltip.GetContentPos();
if (pos.x + tooltip.runtimeWidth > chartRect.x + chartRect.width)
{
pos.x = chartRect.x + chartRect.width - tooltip.runtimeWidth;
}
if (pos.y - tooltip.runtimeHeight < chartRect.y)
{
pos.y = chartRect.y + tooltip.runtimeHeight;
}
tooltip.UpdateContentPos(pos);
}
public static string GetPolarFormatterContent(Tooltip tooltip, BaseChart chart, AngleAxis angleAxis)
{
if (string.IsNullOrEmpty(tooltip.formatter))
{
var sb = ChartHelper.sb;
sb.Length = 0;
var title = tooltip.titleFormatter;
var formatTitle = !string.IsNullOrEmpty(title);
if ("{i}".Equals(tooltip.titleFormatter))
{
title = string.Empty;
formatTitle = false;
}
else if (string.IsNullOrEmpty(title))
{
var angle = angleAxis.clockwise ? tooltip.runtimeAngle : 360 - tooltip.runtimeAngle;
title = ChartCached.FloatToStr(angle);
}
foreach (var serie in chart.series.list)
{
if (serie.show && IsSelectedSerie(tooltip, serie.index))
{
if (formatTitle)
{
FormatterHelper.ReplaceContent(ref title, 0, tooltip.numericFormatter, serie, chart, null);
}
var dataIndexList = tooltip.runtimeSerieIndex[serie.index];
for (int i = 0; i < dataIndexList.Count; i++)
{
var dataIndex = dataIndexList[i];
var serieData = serie.GetSerieData(dataIndex);
var itemFormatter = GetItemFormatter(tooltip, serie, serieData);
var numericFormatter = GetItemNumericFormatter(tooltip, serie, serieData);
float xValue, yValue;
serie.GetXYData(dataIndex, null, out xValue, out yValue);
if (string.IsNullOrEmpty(itemFormatter))
{
sb.Append("<color=#").Append(chart.theme.GetColorStr(serie.index)).Append(">● </color>");
if (!string.IsNullOrEmpty(serie.name))
sb.Append(serie.name).Append(": ");
sb.AppendFormat("{0}", ChartCached.FloatToStr(xValue, numericFormatter));
if (i != dataIndexList.Count - 1)
{
sb.Append(FormatterHelper.PH_NN);
}
}
else
{
string content = itemFormatter;
FormatterHelper.ReplaceContent(ref content, dataIndex, tooltip.numericFormatter, serie, chart, null);
var dotColorIndex = serie.type == SerieType.Pie || serie.type == SerieType.Radar
|| serie.type == SerieType.Ring ? dataIndex : serie.index;
sb.Append(ChartCached.ColorToDotStr(chart.theme.GetColor(dotColorIndex)));
sb.Append(content);
}
}
sb.Append(FormatterHelper.PH_NN);
}
}
if (string.IsNullOrEmpty(title))
{
return FormatterHelper.TrimAndReplaceLine(sb);
}
else
{
title = FormatterHelper.TrimAndReplaceLine(title);
return title + FormatterHelper.PH_NN + FormatterHelper.TrimAndReplaceLine(sb);
}
}
else
{
string content = tooltip.formatter;
FormatterHelper.ReplaceContent(ref content, 0, tooltip.numericFormatter, null, chart, null);
return content;
}
}
public static string GetFormatterContent(Tooltip tooltip, int dataIndex, BaseChart chart, DataZoom dataZoom = null,
bool isCartesian = false, Radar radar = null)
{
if (string.IsNullOrEmpty(tooltip.formatter))
{
var sb = ChartHelper.sb;
var title = tooltip.titleFormatter;
var formatTitle = !string.IsNullOrEmpty(title);
var titleIsIgnroe = false;
var needCategory = false;
var first = true;
var isScatter = false;
sb.Length = 0;
if ("{i}".Equals(tooltip.titleFormatter))
{
title = string.Empty;
formatTitle = false;
titleIsIgnroe = true;
}
for (int i = 0; i < chart.series.Count; i++)
{
var serie = chart.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))
{
isScatter = true;
var itemFormatter = GetItemFormatter(tooltip, serie, null);
if (string.IsNullOrEmpty(itemFormatter))
{
if (!first) sb.Append(FormatterHelper.PH_NN);
InitDefaultContent(ref sb, tooltip, serie, dataIndex, chart.theme, dataZoom, isCartesian, radar);
first = false;
continue;
}
var itemTitle = title;
if (!string.IsNullOrEmpty(itemTitle))
{
FormatterHelper.ReplaceContent(ref itemTitle, dataIndex, tooltip.numericFormatter, serie, chart, 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, chart, dataZoom);
if (!foundDot)
{
sb.Append(ChartCached.ColorToDotStr(chart.theme.GetColor(serie.index)));
}
sb.Append(content).Append(FormatterHelper.PH_NN);
}
}
}
else if (IsNeedTooltipSerie(serie, tooltip))
{
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, chart, 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, chart.theme, dataZoom, isCartesian, radar);
first = false;
continue;
}
string content = itemFormatter;
FormatterHelper.ReplaceContent(ref content, dataIndex, tooltip.numericFormatter, serie, chart, 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(chart.theme.GetColor(dotColorIndex)));
sb.Append(content);
first = false;
}
}
}
if (isScatter)
{
return FormatterHelper.TrimAndReplaceLine(sb);
}
else if (string.IsNullOrEmpty(title))
{
if (needCategory && !titleIsIgnroe)
{
var category = (chart as CoordinateChart).GetTooltipCategory(dataIndex, dataZoom);
return category + FormatterHelper.PH_NN + FormatterHelper.TrimAndReplaceLine(sb);
}
else
return FormatterHelper.TrimAndReplaceLine(sb);
}
else
{
title = FormatterHelper.TrimAndReplaceLine(title);
return title + FormatterHelper.PH_NN + FormatterHelper.TrimAndReplaceLine(sb);
}
}
else
{
string content = tooltip.formatter;
FormatterHelper.ReplaceContent(ref content, dataIndex, tooltip.numericFormatter, null, chart, dataZoom);
return content;
}
}
private static bool IsNeedTooltipSerie(Serie serie, Tooltip tooltip)
{
//if (serie.type == SerieType.Pie || serie.type == SerieType.Radar || serie.type == SerieType.Ring)
if (serie.type == SerieType.Pie || serie.type == SerieType.Ring)
{
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
{
return true;
}
}
private static bool IsSelectedSerie(Tooltip tooltip, int serieIndex)
{
if (tooltip.runtimeSerieIndex.ContainsKey(serieIndex))
{
return tooltip.runtimeSerieIndex[serieIndex].Count > 0;
}
return false;
}
private static string GetItemFormatter(Tooltip tooltip, Serie serie, SerieData serieData)
{
var itemStyle = SerieHelper.GetItemStyle(serie, serieData);
if (!string.IsNullOrEmpty(itemStyle.tooltipFormatter)) return itemStyle.tooltipFormatter;
else return tooltip.itemFormatter;
}
private static string GetItemNumericFormatter(Tooltip tooltip, Serie serie, SerieData serieData)
{
var itemStyle = SerieHelper.GetItemStyle(serie, serieData);
if (!string.IsNullOrEmpty(itemStyle.numericFormatter)) return itemStyle.numericFormatter;
else return tooltip.numericFormatter;
}
public static Color32 GetLineColor(Tooltip tooltip, ChartTheme theme)
{
var lineStyle = tooltip.lineStyle;
if (!ChartHelper.IsClearColor(lineStyle.color))
{
return lineStyle.GetColor();
}
else
{
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,11 +0,0 @@
fileFormatVersion: 2
guid: f0fa1b19683a8424bb335802de5c9726
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -12,7 +12,7 @@ namespace XCharts
{
public static class VesselHelper
{
internal static Color32 GetColor(Vessel vessel, Serie serie, ChartTheme theme, List<string> legendRealShowName)
public static Color32 GetColor(Vessel vessel, Serie serie, ChartTheme theme, List<string> legendRealShowName)
{
if (serie != null && vessel.autoColor)
{
@@ -25,7 +25,7 @@ namespace XCharts
}
}
internal static void UpdateVesselCenter(Vessel vessel, Vector3 chartPosition, float chartWidth, float chartHeight)
public static void UpdateVesselCenter(Vessel vessel, Vector3 chartPosition, float chartWidth, float chartHeight)
{
if (vessel.center.Length < 2) return;
var centerX = vessel.center[0] <= 1 ? chartWidth * vessel.center[0] : vessel.center[0];

View File

@@ -1,142 +0,0 @@
/************************************************/
/* */
/* Copyright (c) 2018 - 2021 monitor1394 */
/* https://github.com/monitor1394 */
/* */
/************************************************/
using System;
using UnityEngine;
namespace XCharts
{
public static class VisualMapHelper
{
public static void AutoSetLineMinMax(VisualMap visualMap, Serie serie, XAxis xAxis, YAxis yAxis)
{
if (!IsNeedGradient(visualMap) || !visualMap.autoMinMax) return;
float min = 0;
float max = 0;
switch (visualMap.direction)
{
case VisualMap.Direction.Default:
case VisualMap.Direction.X:
min = xAxis.IsCategory() ? 0 : xAxis.runtimeMinValue;
max = xAxis.IsCategory() ? serie.dataCount : xAxis.runtimeMaxValue;
SetMinMax(visualMap, min, max);
break;
case VisualMap.Direction.Y:
min = yAxis.IsCategory() ? 0 : yAxis.runtimeMinValue;
max = yAxis.IsCategory() ? serie.dataCount : yAxis.runtimeMaxValue;
SetMinMax(visualMap, min, max);
break;
}
}
public static void SetMinMax(VisualMap visualMap, float min, float max)
{
if (visualMap.enable && (visualMap.min != min || visualMap.max != max))
{
if (max >= min)
{
visualMap.min = min;
visualMap.max = max;
}
else
{
throw new Exception("SetMinMax:max < min:" + min + "," + max);
}
}
}
public static void GetLineGradientColor(VisualMap visualMap, float xValue, float yValue,
out Color32 startColor, out Color32 toColor)
{
startColor = ChartConst.clearColor32;
toColor = ChartConst.clearColor32;
switch (visualMap.direction)
{
case VisualMap.Direction.Default:
case VisualMap.Direction.X:
startColor = visualMap.IsPiecewise() ? visualMap.GetColor(xValue) : visualMap.GetColor(xValue - 1);
toColor = visualMap.IsPiecewise() ? startColor : visualMap.GetColor(xValue);
break;
case VisualMap.Direction.Y:
startColor = visualMap.IsPiecewise() ? visualMap.GetColor(yValue) : visualMap.GetColor(yValue - 1);
toColor = visualMap.IsPiecewise() ? startColor : visualMap.GetColor(yValue);
break;
}
}
internal static Color32 GetLineGradientColor(VisualMap visualMap, Vector3 pos, CoordinateChart chart, Axis axis, Color32 defaultColor)
{
float value = 0;
switch (visualMap.direction)
{
case VisualMap.Direction.Default:
case VisualMap.Direction.X:
var min = axis.runtimeMinValue;
var max = axis.runtimeMaxValue;
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.xAxes[axis.index];
min = yAxis.runtimeMinValue;
max = yAxis.runtimeMaxValue;
}
else
{
var yAxis = chart.yAxes[axis.index];
min = yAxis.runtimeMinValue;
max = yAxis.runtimeMaxValue;
}
grid = chart.GetAxisGridOrDefault(axis);
value = min + (pos.y - grid.runtimeY) / grid.runtimeHeight * (max - min);
break;
}
var color = visualMap.GetColor(value);
if (ChartHelper.IsClearColor(color)) return defaultColor;
else return color;
}
internal static Color32 GetItemStyleGradientColor(ItemStyle itemStyle, Vector3 pos, CoordinateChart chart, Axis axis, Color32 defaultColor)
{
var min = axis.runtimeMinValue;
var max = axis.runtimeMaxValue;
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;
else return color;
}
internal static Color32 GetLineStyleGradientColor(LineStyle lineStyle, Vector3 pos, CoordinateChart chart, Axis axis, Color32 defaultColor)
{
var min = axis.runtimeMinValue;
var max = axis.runtimeMaxValue;
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;
else return color;
}
public static bool IsNeedGradient(VisualMap visualMap)
{
if (!visualMap.enable || visualMap.inRange.Count <= 0) return false;
return true;
}
public static int GetDimension(VisualMap visualMap, int serieDataCount)
{
var dimension = visualMap.enable && visualMap.dimension >= 0 ? visualMap.dimension : serieDataCount - 1;
if (dimension > serieDataCount - 1) dimension = serieDataCount - 1;
return dimension;
}
}
}

View File

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