mirror of
https://github.com/XCharts-Team/XCharts.git
synced 2026-05-22 17:00:08 +00:00
优化性能,优化折线图和柱状图的大数据绘制,重构代码
This commit is contained in:
@@ -35,6 +35,7 @@ namespace XCharts
|
||||
IDragHandler, IEndDragHandler, IScrollHandler
|
||||
{
|
||||
protected static readonly string s_TitleObjectName = "title";
|
||||
protected static readonly string s_SubTitleObjectName = "title_sub";
|
||||
protected static readonly string s_LegendObjectName = "legend";
|
||||
protected static readonly string s_SerieLabelObjectName = "label";
|
||||
protected static readonly string s_SerieTitleObjectName = "serie";
|
||||
@@ -70,6 +71,7 @@ namespace XCharts
|
||||
[NonSerialized] protected bool m_CheckAnimation = false;
|
||||
[NonSerialized] protected bool m_IsPlayingAnimation = false;
|
||||
[NonSerialized] protected List<string> m_LegendRealShowName = new List<string>();
|
||||
[NonSerialized] protected GameObject m_SerieLabelRoot;
|
||||
|
||||
protected Vector2 chartAnchorMax { get { return m_ChartMinAnchor; } }
|
||||
protected Vector2 chartAnchorMin { get { return m_ChartMaxAnchor; } }
|
||||
@@ -249,7 +251,7 @@ namespace XCharts
|
||||
|
||||
var subTextFont = TitleHelper.GetSubTextFont(title, themeInfo);
|
||||
var subTextColor = TitleHelper.GetSubTextColor(title, themeInfo);
|
||||
Text subText = ChartHelper.AddTextObject(s_TitleObjectName + "_sub", titleObject.transform,
|
||||
Text subText = ChartHelper.AddTextObject(s_SubTitleObjectName, titleObject.transform,
|
||||
subTextFont, subTextColor, anchor, anchorMin, anchorMax, pivot,
|
||||
new Vector2(titleWid, m_Title.subTextStyle.fontSize), m_Title.subTextStyle.fontSize,
|
||||
m_Title.subTextStyle.rotate, m_Title.subTextStyle.fontStyle, m_Title.subTextStyle.lineSpacing);
|
||||
@@ -364,9 +366,9 @@ namespace XCharts
|
||||
|
||||
private void InitSerieLabel()
|
||||
{
|
||||
var labelObject = ChartHelper.AddObject(s_SerieLabelObjectName, transform, m_ChartMinAnchor,
|
||||
m_SerieLabelRoot = ChartHelper.AddObject(s_SerieLabelObjectName, transform, m_ChartMinAnchor,
|
||||
m_ChartMaxAnchor, m_ChartPivot, m_ChartSizeDelta);
|
||||
SerieLabelPool.ReleaseAll(labelObject.transform);
|
||||
SerieLabelPool.ReleaseAll(m_SerieLabelRoot.transform);
|
||||
int count = 0;
|
||||
for (int i = 0; i < m_Series.Count; i++)
|
||||
{
|
||||
@@ -375,34 +377,44 @@ namespace XCharts
|
||||
for (int j = 0; j < serie.data.Count; j++)
|
||||
{
|
||||
var serieData = serie.data[j];
|
||||
var serieLabel = SerieHelper.GetSerieLabel(serie, serieData);
|
||||
if (!serieLabel.show && j > 100) continue;
|
||||
var textName = ChartCached.GetSerieLabelName(s_SerieLabelObjectName, i, j);
|
||||
var color = Color.grey;
|
||||
if (serie.type == SerieType.Pie)
|
||||
{
|
||||
color = (serieLabel.position == SerieLabel.Position.Inside) ? Color.white :
|
||||
(Color)m_ThemeInfo.GetColor(count);
|
||||
}
|
||||
else
|
||||
{
|
||||
color = serieLabel.color != Color.clear ? serieLabel.color :
|
||||
(Color)m_ThemeInfo.GetColor(i);
|
||||
}
|
||||
var labelObj = SerieLabelPool.Get(textName, labelObject.transform, serieLabel, m_ThemeInfo.font, color,
|
||||
serieData.iconStyle.width, serieData.iconStyle.height);
|
||||
var iconImage = labelObj.transform.Find("Icon").GetComponent<Image>();
|
||||
serieData.SetIconImage(iconImage);
|
||||
|
||||
var isAutoSize = serieLabel.backgroundWidth == 0 || serieLabel.backgroundHeight == 0;
|
||||
serieData.InitLabel(labelObj, isAutoSize, serieLabel.paddingLeftRight, serieLabel.paddingTopBottom);
|
||||
serieData.SetLabelActive(false);
|
||||
serieData.index = j;
|
||||
AddSerieLabel(serie, serieData, count);
|
||||
count++;
|
||||
}
|
||||
}
|
||||
SerieLabelHelper.UpdateLabelText(m_Series, m_ThemeInfo);
|
||||
}
|
||||
|
||||
protected void AddSerieLabel(Serie serie, SerieData serieData, int count = -1)
|
||||
{
|
||||
if (m_SerieLabelRoot == null) return;
|
||||
if (count == -1) count = serie.dataCount;
|
||||
var serieLabel = SerieHelper.GetSerieLabel(serie, serieData);
|
||||
if (serie.IsPerformanceMode()) return;
|
||||
if (!serieLabel.show) return;
|
||||
var textName = ChartCached.GetSerieLabelName(s_SerieLabelObjectName, serie.index, serieData.index);
|
||||
var color = Color.grey;
|
||||
if (serie.type == SerieType.Pie)
|
||||
{
|
||||
color = (serieLabel.position == SerieLabel.Position.Inside) ? Color.white :
|
||||
(Color)m_ThemeInfo.GetColor(count);
|
||||
}
|
||||
else
|
||||
{
|
||||
color = !ChartHelper.IsClearColor(serieLabel.color) ? serieLabel.color :
|
||||
(Color)m_ThemeInfo.GetColor(serie.index);
|
||||
}
|
||||
var labelObj = SerieLabelPool.Get(textName, m_SerieLabelRoot.transform, serieLabel, m_ThemeInfo.font, color,
|
||||
serieData.iconStyle.width, serieData.iconStyle.height);
|
||||
var iconImage = labelObj.transform.Find("Icon").GetComponent<Image>();
|
||||
var isAutoSize = serieLabel.backgroundWidth == 0 || serieLabel.backgroundHeight == 0;
|
||||
var item = new LabelObject();
|
||||
item.SetLabel(labelObj, isAutoSize, serieLabel.paddingLeftRight, serieLabel.paddingTopBottom);
|
||||
item.SetIcon(iconImage);
|
||||
item.SetIconActive(false);
|
||||
serieData.labelObject = item;
|
||||
}
|
||||
|
||||
private void InitSerieTitle()
|
||||
{
|
||||
var titleObject = ChartHelper.AddObject(s_SerieTitleObjectName, transform, m_ChartMinAnchor,
|
||||
@@ -412,7 +424,7 @@ namespace XCharts
|
||||
{
|
||||
var serie = m_Series.list[i];
|
||||
var textStyle = serie.titleStyle.textStyle;
|
||||
var color = textStyle.color == Color.clear ? m_ThemeInfo.GetColor(i) : (Color32)textStyle.color;
|
||||
var color = ChartHelper.IsClearColor(textStyle.color) ? m_ThemeInfo.GetColor(i) : (Color32)textStyle.color;
|
||||
var anchorMin = new Vector2(0.5f, 0.5f);
|
||||
var anchorMax = new Vector2(0.5f, 0.5f);
|
||||
var pivot = new Vector2(0.5f, 0.5f);
|
||||
@@ -850,7 +862,7 @@ namespace XCharts
|
||||
&& SerieHelper.IsDownPoint(serie, serieData.index)
|
||||
&& !serie.areaStyle.show;
|
||||
var centerPos = serieData.labelPosition + serieLabel.offset * (invert ? -1 : 1);
|
||||
var labelHalfWid = serieData.GetLabelWidth() / 2;
|
||||
var labelHalfWid = serieData.labelObject.GetLabelWidth() / 2;
|
||||
var labelHalfHig = serieData.GetLabelHeight() / 2;
|
||||
var p1 = new Vector3(centerPos.x - labelHalfWid, centerPos.y + labelHalfHig);
|
||||
var p2 = new Vector3(centerPos.x + labelHalfWid, centerPos.y + labelHalfHig);
|
||||
|
||||
@@ -24,6 +24,10 @@ namespace XCharts
|
||||
[SerializeField] protected DataZoom m_DataZoom = DataZoom.defaultDataZoom;
|
||||
[SerializeField] protected VisualMap m_VisualMap = new VisualMap();
|
||||
|
||||
protected float m_CoordinateX;
|
||||
protected float m_CoordinateY;
|
||||
protected float m_CoordinateWidth;
|
||||
protected float m_CoordinateHeight;
|
||||
private bool m_DataZoomDrag;
|
||||
private bool m_DataZoomCoordinateDrag;
|
||||
private bool m_DataZoomStartDrag;
|
||||
@@ -147,11 +151,11 @@ namespace XCharts
|
||||
var xSplitDiff = xAxis0.splitLine.lineStyle.width;
|
||||
var ySplitDiff = yAxis0.splitLine.lineStyle.width;
|
||||
|
||||
var cpty = coordinateY + coordinateHeight + ySplitDiff;
|
||||
var cp1 = new Vector3(coordinateX - yLineDiff, coordinateY - xLineDiff);
|
||||
var cp2 = new Vector3(coordinateX - yLineDiff, cpty);
|
||||
var cp3 = new Vector3(coordinateX + coordinateWidth + xSplitDiff, cpty);
|
||||
var cp4 = new Vector3(coordinateX + coordinateWidth + xSplitDiff, coordinateY - xLineDiff);
|
||||
var cpty = m_CoordinateY + m_CoordinateHeight + ySplitDiff;
|
||||
var cp1 = new Vector3(m_CoordinateX - yLineDiff, m_CoordinateY - xLineDiff);
|
||||
var cp2 = new Vector3(m_CoordinateX - yLineDiff, cpty);
|
||||
var cp3 = new Vector3(m_CoordinateX + m_CoordinateWidth + xSplitDiff, cpty);
|
||||
var cp4 = new Vector3(m_CoordinateX + m_CoordinateWidth + xSplitDiff, m_CoordinateY - xLineDiff);
|
||||
ChartDrawer.DrawPolygon(vh, cp1, cp2, cp3, cp4, m_ThemeInfo.backgroundColor);
|
||||
|
||||
}
|
||||
@@ -170,23 +174,23 @@ namespace XCharts
|
||||
var ySplitDiff = yAxis0.splitLine.lineStyle.width;
|
||||
var lp1 = new Vector3(m_ChartX, m_ChartY);
|
||||
var lp2 = new Vector3(m_ChartX, m_ChartY + chartHeight);
|
||||
var lp3 = new Vector3(coordinateX - yLineDiff, m_ChartY + chartHeight);
|
||||
var lp4 = new Vector3(coordinateX - yLineDiff, m_ChartY);
|
||||
var lp3 = new Vector3(m_CoordinateX - yLineDiff, m_ChartY + chartHeight);
|
||||
var lp4 = new Vector3(m_CoordinateX - yLineDiff, m_ChartY);
|
||||
ChartDrawer.DrawPolygon(vh, lp1, lp2, lp3, lp4, m_ThemeInfo.backgroundColor);
|
||||
var rp1 = new Vector3(coordinateX + coordinateWidth + xSplitDiff, m_ChartY);
|
||||
var rp2 = new Vector3(coordinateX + coordinateWidth + xSplitDiff, m_ChartY + chartHeight);
|
||||
var rp1 = new Vector3(m_CoordinateX + m_CoordinateWidth + xSplitDiff, m_ChartY);
|
||||
var rp2 = new Vector3(m_CoordinateX + m_CoordinateWidth + xSplitDiff, m_ChartY + chartHeight);
|
||||
var rp3 = new Vector3(m_ChartX + chartWidth, m_ChartY + chartHeight);
|
||||
var rp4 = new Vector3(m_ChartX + chartWidth, m_ChartY);
|
||||
ChartDrawer.DrawPolygon(vh, rp1, rp2, rp3, rp4, m_ThemeInfo.backgroundColor);
|
||||
var up1 = new Vector3(coordinateX - yLineDiff, coordinateY + coordinateHeight + ySplitDiff);
|
||||
var up2 = new Vector3(coordinateX - yLineDiff, m_ChartY + chartHeight);
|
||||
var up3 = new Vector3(coordinateX + coordinateWidth + xSplitDiff, m_ChartY + chartHeight);
|
||||
var up4 = new Vector3(coordinateX + coordinateWidth + xSplitDiff, coordinateY + coordinateHeight + ySplitDiff);
|
||||
var up1 = new Vector3(m_CoordinateX - yLineDiff, m_CoordinateY + m_CoordinateHeight + ySplitDiff);
|
||||
var up2 = new Vector3(m_CoordinateX - yLineDiff, m_ChartY + chartHeight);
|
||||
var up3 = new Vector3(m_CoordinateX + m_CoordinateWidth + xSplitDiff, m_ChartY + chartHeight);
|
||||
var up4 = new Vector3(m_CoordinateX + m_CoordinateWidth + xSplitDiff, m_CoordinateY + m_CoordinateHeight + ySplitDiff);
|
||||
ChartDrawer.DrawPolygon(vh, up1, up2, up3, up4, m_ThemeInfo.backgroundColor);
|
||||
var dp1 = new Vector3(coordinateX - yLineDiff, m_ChartY);
|
||||
var dp2 = new Vector3(coordinateX - yLineDiff, coordinateY - xLineDiff);
|
||||
var dp3 = new Vector3(coordinateX + coordinateWidth + xSplitDiff, coordinateY - xLineDiff);
|
||||
var dp4 = new Vector3(coordinateX + coordinateWidth + xSplitDiff, m_ChartY);
|
||||
var dp1 = new Vector3(m_CoordinateX - yLineDiff, m_ChartY);
|
||||
var dp2 = new Vector3(m_CoordinateX - yLineDiff, m_CoordinateY - xLineDiff);
|
||||
var dp3 = new Vector3(m_CoordinateX + m_CoordinateWidth + xSplitDiff, m_CoordinateY - xLineDiff);
|
||||
var dp4 = new Vector3(m_CoordinateX + m_CoordinateWidth + xSplitDiff, m_ChartY);
|
||||
ChartDrawer.DrawPolygon(vh, dp1, dp2, dp3, dp4, m_ThemeInfo.backgroundColor);
|
||||
}
|
||||
|
||||
@@ -260,12 +264,12 @@ namespace XCharts
|
||||
if (!xAxis.show && !yAxis.show) continue;
|
||||
if (isCartesian && xAxis.show && yAxis.show)
|
||||
{
|
||||
var yRate = (yAxis.runtimeMaxValue - yAxis.runtimeMinValue) / coordinateHeight;
|
||||
var xRate = (xAxis.runtimeMaxValue - xAxis.runtimeMinValue) / coordinateWidth;
|
||||
var yValue = yRate * (local.y - coordinateY - yAxis.runtimeZeroYOffset);
|
||||
var yRate = (yAxis.runtimeMaxValue - yAxis.runtimeMinValue) / m_CoordinateHeight;
|
||||
var xRate = (xAxis.runtimeMaxValue - xAxis.runtimeMinValue) / m_CoordinateWidth;
|
||||
var yValue = yRate * (local.y - m_CoordinateY - yAxis.runtimeZeroYOffset);
|
||||
if (yAxis.runtimeMinValue > 0) yValue += yAxis.runtimeMinValue;
|
||||
m_Tooltip.runtimeYValues[i] = yValue;
|
||||
var xValue = xRate * (local.x - coordinateX - xAxis.runtimeZeroXOffset);
|
||||
var xValue = xRate * (local.x - m_CoordinateX - xAxis.runtimeZeroXOffset);
|
||||
if (xAxis.runtimeMinValue > 0) xValue += xAxis.runtimeMinValue;
|
||||
m_Tooltip.runtimeXValues[i] = xValue;
|
||||
|
||||
@@ -296,8 +300,8 @@ namespace XCharts
|
||||
|
||||
for (int j = 0; j < xAxis.GetDataNumber(m_DataZoom); j++)
|
||||
{
|
||||
float splitWid = xAxis.GetDataWidth(coordinateWidth, dataCount, m_DataZoom);
|
||||
float pX = coordinateX + j * splitWid;
|
||||
float splitWid = xAxis.GetDataWidth(m_CoordinateWidth, dataCount, m_DataZoom);
|
||||
float pX = m_CoordinateX + j * splitWid;
|
||||
if ((xAxis.boundaryGap && (local.x > pX && local.x <= pX + splitWid)) ||
|
||||
(!xAxis.boundaryGap && (local.x > pX - splitWid / 2 && local.x <= pX + splitWid / 2)))
|
||||
{
|
||||
@@ -308,8 +312,8 @@ namespace XCharts
|
||||
}
|
||||
for (int j = 0; j < yAxis.GetDataNumber(m_DataZoom); j++)
|
||||
{
|
||||
float splitWid = yAxis.GetDataWidth(coordinateHeight, dataCount, m_DataZoom);
|
||||
float pY = coordinateY + j * splitWid;
|
||||
float splitWid = yAxis.GetDataWidth(m_CoordinateHeight, dataCount, m_DataZoom);
|
||||
float pY = m_CoordinateY + j * splitWid;
|
||||
if ((yAxis.boundaryGap && (local.y > pY && local.y <= pY + splitWid)) ||
|
||||
(!yAxis.boundaryGap && (local.y > pY - splitWid / 2 && local.y <= pY + splitWid / 2)))
|
||||
{
|
||||
@@ -320,13 +324,13 @@ namespace XCharts
|
||||
}
|
||||
else if (xAxis.IsCategory())
|
||||
{
|
||||
var value = (yAxis.runtimeMaxValue - yAxis.runtimeMinValue) * (local.y - coordinateY - yAxis.runtimeZeroYOffset) / coordinateHeight;
|
||||
var value = (yAxis.runtimeMaxValue - yAxis.runtimeMinValue) * (local.y - m_CoordinateY - yAxis.runtimeZeroYOffset) / m_CoordinateHeight;
|
||||
if (yAxis.runtimeMinValue > 0) value += yAxis.runtimeMinValue;
|
||||
m_Tooltip.runtimeYValues[i] = value;
|
||||
for (int j = 0; j < xAxis.GetDataNumber(m_DataZoom); j++)
|
||||
{
|
||||
float splitWid = xAxis.GetDataWidth(coordinateWidth, dataCount, m_DataZoom);
|
||||
float pX = coordinateX + j * splitWid;
|
||||
float splitWid = xAxis.GetDataWidth(m_CoordinateWidth, dataCount, m_DataZoom);
|
||||
float pX = m_CoordinateX + j * splitWid;
|
||||
if ((xAxis.boundaryGap && (local.x > pX && local.x <= pX + splitWid)) ||
|
||||
(!xAxis.boundaryGap && (local.x > pX - splitWid / 2 && local.x <= pX + splitWid / 2)))
|
||||
{
|
||||
@@ -338,13 +342,13 @@ namespace XCharts
|
||||
}
|
||||
else if (yAxis.IsCategory())
|
||||
{
|
||||
var value = (xAxis.runtimeMaxValue - xAxis.runtimeMinValue) * (local.x - coordinateX - xAxis.runtimeZeroXOffset) / coordinateWidth;
|
||||
var value = (xAxis.runtimeMaxValue - xAxis.runtimeMinValue) * (local.x - m_CoordinateX - xAxis.runtimeZeroXOffset) / m_CoordinateWidth;
|
||||
if (xAxis.runtimeMinValue > 0) value += xAxis.runtimeMinValue;
|
||||
m_Tooltip.runtimeXValues[i] = value;
|
||||
for (int j = 0; j < yAxis.GetDataNumber(m_DataZoom); j++)
|
||||
{
|
||||
float splitWid = yAxis.GetDataWidth(coordinateHeight, dataCount, m_DataZoom);
|
||||
float pY = coordinateY + j * splitWid;
|
||||
float splitWid = yAxis.GetDataWidth(m_CoordinateHeight, dataCount, m_DataZoom);
|
||||
float pY = m_CoordinateY + j * splitWid;
|
||||
if ((yAxis.boundaryGap && (local.y > pY && local.y <= pY + splitWid)) ||
|
||||
(!yAxis.boundaryGap && (local.y > pY - splitWid / 2 && local.y <= pY + splitWid / 2)))
|
||||
{
|
||||
@@ -429,7 +433,7 @@ namespace XCharts
|
||||
Vector2 labelPos = Vector2.zero;
|
||||
if (axis is XAxis)
|
||||
{
|
||||
var posY = axisIndex > 0 ? coordinateY + coordinateHeight : coordinateY;
|
||||
var posY = axisIndex > 0 ? m_CoordinateY + m_CoordinateHeight : m_CoordinateY;
|
||||
var diff = axisIndex > 0 ? -axis.axisLabel.fontSize - axis.axisLabel.margin - 3.5f : axis.axisLabel.margin / 2 + 1;
|
||||
if (axis.IsValue())
|
||||
{
|
||||
@@ -439,15 +443,15 @@ namespace XCharts
|
||||
else
|
||||
{
|
||||
labelText = axis.GetData((int)m_Tooltip.runtimeXValues[axisIndex], m_DataZoom);
|
||||
float splitWidth = axis.GetSplitWidth(coordinateWidth, m_DataZoom);
|
||||
float splitWidth = axis.GetSplitWidth(m_CoordinateWidth, m_DataZoom);
|
||||
int index = (int)m_Tooltip.runtimeXValues[axisIndex];
|
||||
float px = coordinateX + index * splitWidth + (axis.boundaryGap ? splitWidth / 2 : 0) + 0.5f;
|
||||
float px = m_CoordinateX + index * splitWidth + (axis.boundaryGap ? splitWidth / 2 : 0) + 0.5f;
|
||||
labelPos = new Vector2(px, posY - diff);
|
||||
}
|
||||
}
|
||||
else if (axis is YAxis)
|
||||
{
|
||||
var posX = axisIndex > 0 ? coordinateX + coordinateWidth : coordinateX;
|
||||
var posX = axisIndex > 0 ? m_CoordinateX + m_CoordinateWidth : m_CoordinateX;
|
||||
var diff = axisIndex > 0 ? -axis.axisLabel.margin + 3 : axis.axisLabel.margin - 3;
|
||||
if (axis.IsValue())
|
||||
{
|
||||
@@ -457,9 +461,9 @@ namespace XCharts
|
||||
else
|
||||
{
|
||||
labelText = axis.GetData((int)m_Tooltip.runtimeYValues[axisIndex], m_DataZoom);
|
||||
float splitWidth = axis.GetSplitWidth(coordinateHeight, m_DataZoom);
|
||||
float splitWidth = axis.GetSplitWidth(m_CoordinateHeight, m_DataZoom);
|
||||
int index = (int)m_Tooltip.runtimeYValues[axisIndex];
|
||||
float py = coordinateY + index * splitWidth + (axis.boundaryGap ? splitWidth / 2 : 0);
|
||||
float py = m_CoordinateY + index * splitWidth + (axis.boundaryGap ? splitWidth / 2 : 0);
|
||||
labelPos = new Vector2(posX - diff, py);
|
||||
}
|
||||
}
|
||||
@@ -518,10 +522,10 @@ namespace XCharts
|
||||
axisObj.transform.localPosition = Vector3.zero;
|
||||
axisObj.SetActive(yAxis.show && yAxis.axisLabel.show);
|
||||
ChartHelper.HideAllObject(axisObj);
|
||||
var labelColor = yAxis.axisLabel.color == Color.clear ?
|
||||
var labelColor = ChartHelper.IsClearColor(yAxis.axisLabel.color) ?
|
||||
(Color)m_ThemeInfo.axisTextColor :
|
||||
yAxis.axisLabel.color;
|
||||
int splitNumber = yAxis.GetSplitNumber(coordinateHeight, m_DataZoom);
|
||||
int splitNumber = yAxis.GetSplitNumber(m_CoordinateHeight, m_DataZoom);
|
||||
float totalWidth = 0;
|
||||
for (int i = 0; i < splitNumber; i++)
|
||||
{
|
||||
@@ -542,12 +546,12 @@ namespace XCharts
|
||||
yAxis.axisLabel.fontSize, yAxis.axisLabel.rotate, yAxis.axisLabel.fontStyle);
|
||||
}
|
||||
|
||||
float labelWidth = yAxis.GetScaleWidth(coordinateHeight, i, m_DataZoom);
|
||||
float labelWidth = yAxis.GetScaleWidth(m_CoordinateHeight, i, m_DataZoom);
|
||||
if (i == 0) yAxis.axisLabel.SetRelatedText(txt, labelWidth);
|
||||
txt.transform.localPosition = GetLabelYPosition(totalWidth + (yAxis.boundaryGap ? labelWidth / 2 : 0), i, yAxisIndex, yAxis);
|
||||
|
||||
var isPercentStack = m_Series.IsPercentStack(SerieType.Bar);
|
||||
txt.text = yAxis.GetLabelName(coordinateHeight, i, yAxis.runtimeMinValue, yAxis.runtimeMaxValue, m_DataZoom, isPercentStack);
|
||||
txt.text = yAxis.GetLabelName(m_CoordinateHeight, i, yAxis.runtimeMinValue, yAxis.runtimeMaxValue, m_DataZoom, isPercentStack);
|
||||
txt.gameObject.SetActive(yAxis.show &&
|
||||
(yAxis.axisLabel.interval == 0 || i % (yAxis.axisLabel.interval + 1) == 0));
|
||||
yAxis.axisLabelTextList.Add(txt);
|
||||
@@ -555,12 +559,12 @@ namespace XCharts
|
||||
}
|
||||
if (yAxis.axisName.show)
|
||||
{
|
||||
var color = yAxis.axisName.color == Color.clear ? (Color)m_ThemeInfo.axisTextColor :
|
||||
var color = ChartHelper.IsClearColor(yAxis.axisName.color) ? (Color)m_ThemeInfo.axisTextColor :
|
||||
yAxis.axisName.color;
|
||||
var fontSize = yAxis.axisName.fontSize;
|
||||
var offset = yAxis.axisName.offset;
|
||||
Text axisName = null;
|
||||
var zeroPos = new Vector3(coordinateX + m_XAxises[yAxisIndex].runtimeZeroXOffset, coordinateY);
|
||||
var zeroPos = new Vector3(m_CoordinateX + m_XAxises[yAxisIndex].runtimeZeroXOffset, m_CoordinateY);
|
||||
switch (yAxis.axisName.location)
|
||||
{
|
||||
case AxisName.Location.Start:
|
||||
@@ -569,8 +573,8 @@ namespace XCharts
|
||||
new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f), new Vector2(100, 20), fontSize,
|
||||
yAxis.axisName.rotate, yAxis.axisName.fontStyle);
|
||||
axisName.transform.localPosition = yAxisIndex > 0 ?
|
||||
new Vector2(coordinateX + coordinateWidth + offset.x, coordinateY - offset.y) :
|
||||
new Vector2(zeroPos.x + offset.x, coordinateY - offset.y);
|
||||
new Vector2(m_CoordinateX + m_CoordinateWidth + offset.x, m_CoordinateY - offset.y) :
|
||||
new Vector2(zeroPos.x + offset.x, m_CoordinateY - offset.y);
|
||||
break;
|
||||
case AxisName.Location.Middle:
|
||||
axisName = ChartHelper.AddTextObject(s_DefaultAxisName, axisObj.transform,
|
||||
@@ -578,8 +582,8 @@ namespace XCharts
|
||||
new Vector2(1, 0.5f), new Vector2(1, 0.5f), new Vector2(100, 20), fontSize,
|
||||
yAxis.axisName.rotate, yAxis.axisName.fontStyle);
|
||||
axisName.transform.localPosition = yAxisIndex > 0 ?
|
||||
new Vector2(coordinateX + coordinateWidth - offset.x, coordinateY + coordinateHeight / 2 + offset.y) :
|
||||
new Vector2(coordinateX - offset.x, coordinateY + coordinateHeight / 2 + offset.y);
|
||||
new Vector2(m_CoordinateX + m_CoordinateWidth - offset.x, m_CoordinateY + m_CoordinateHeight / 2 + offset.y) :
|
||||
new Vector2(m_CoordinateX - offset.x, m_CoordinateY + m_CoordinateHeight / 2 + offset.y);
|
||||
break;
|
||||
case AxisName.Location.End:
|
||||
axisName = ChartHelper.AddTextObject(s_DefaultAxisName, axisObj.transform,
|
||||
@@ -587,8 +591,8 @@ namespace XCharts
|
||||
new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f), new Vector2(100, 20), fontSize,
|
||||
yAxis.axisName.rotate, yAxis.axisName.fontStyle);
|
||||
axisName.transform.localPosition = yAxisIndex > 0 ?
|
||||
new Vector2(coordinateX + coordinateWidth + offset.x, coordinateY + coordinateHeight + offset.y) :
|
||||
new Vector2(zeroPos.x + offset.x, coordinateY + coordinateHeight + offset.y);
|
||||
new Vector2(m_CoordinateX + m_CoordinateWidth + offset.x, m_CoordinateY + m_CoordinateHeight + offset.y) :
|
||||
new Vector2(zeroPos.x + offset.x, m_CoordinateY + m_CoordinateHeight + offset.y);
|
||||
break;
|
||||
}
|
||||
axisName.text = yAxis.axisName.name;
|
||||
@@ -623,14 +627,14 @@ namespace XCharts
|
||||
axisObj.transform.localPosition = Vector3.zero;
|
||||
axisObj.SetActive(xAxis.show && xAxis.axisLabel.show);
|
||||
ChartHelper.HideAllObject(axisObj);
|
||||
var labelColor = xAxis.axisLabel.color == Color.clear ?
|
||||
var labelColor = ChartHelper.IsClearColor(xAxis.axisLabel.color) ?
|
||||
(Color)m_ThemeInfo.axisTextColor :
|
||||
xAxis.axisLabel.color;
|
||||
int splitNumber = xAxis.GetSplitNumber(coordinateWidth, m_DataZoom);
|
||||
int splitNumber = xAxis.GetSplitNumber(m_CoordinateWidth, m_DataZoom);
|
||||
float totalWidth = 0;
|
||||
for (int i = 0; i < splitNumber; i++)
|
||||
{
|
||||
float labelWidth = xAxis.GetScaleWidth(coordinateWidth, i, m_DataZoom);
|
||||
float labelWidth = xAxis.GetScaleWidth(m_CoordinateWidth, i, m_DataZoom);
|
||||
bool inside = xAxis.axisLabel.inside;
|
||||
Text txt = ChartHelper.AddTextObject(ChartCached.GetXAxisName(xAxisIndex, i), axisObj.transform,
|
||||
m_ThemeInfo.font, labelColor, TextAnchor.MiddleCenter, new Vector2(0, 1),
|
||||
@@ -641,7 +645,7 @@ namespace XCharts
|
||||
i, xAxisIndex, xAxis);
|
||||
totalWidth += labelWidth;
|
||||
var isPercentStack = m_Series.IsPercentStack(SerieType.Bar);
|
||||
txt.text = xAxis.GetLabelName(coordinateWidth, i, xAxis.runtimeMinValue, xAxis.runtimeMaxValue, m_DataZoom,
|
||||
txt.text = xAxis.GetLabelName(m_CoordinateWidth, i, xAxis.runtimeMinValue, xAxis.runtimeMaxValue, m_DataZoom,
|
||||
isPercentStack);
|
||||
txt.gameObject.SetActive(xAxis.show &&
|
||||
(xAxis.axisLabel.interval == 0 || i % (xAxis.axisLabel.interval + 1) == 0));
|
||||
@@ -649,12 +653,12 @@ namespace XCharts
|
||||
}
|
||||
if (xAxis.axisName.show)
|
||||
{
|
||||
var color = xAxis.axisName.color == Color.clear ? (Color)m_ThemeInfo.axisTextColor :
|
||||
var color = ChartHelper.IsClearColor(xAxis.axisName.color) ? (Color)m_ThemeInfo.axisTextColor :
|
||||
xAxis.axisName.color;
|
||||
var fontSize = xAxis.axisName.fontSize;
|
||||
var offset = xAxis.axisName.offset;
|
||||
Text axisName = null;
|
||||
var zeroPos = new Vector3(coordinateX, coordinateY + m_YAxises[xAxisIndex].runtimeZeroYOffset);
|
||||
var zeroPos = new Vector3(m_CoordinateX, m_CoordinateY + m_YAxises[xAxisIndex].runtimeZeroYOffset);
|
||||
switch (xAxis.axisName.location)
|
||||
{
|
||||
case AxisName.Location.Start:
|
||||
@@ -663,7 +667,7 @@ namespace XCharts
|
||||
new Vector2(1, 0.5f), new Vector2(1, 0.5f), new Vector2(100, 20), fontSize,
|
||||
xAxis.axisName.rotate, xAxis.axisName.fontStyle);
|
||||
axisName.transform.localPosition = xAxisIndex > 0 ?
|
||||
new Vector2(zeroPos.x - offset.x, coordinateY + coordinateHeight + offset.y) :
|
||||
new Vector2(zeroPos.x - offset.x, m_CoordinateY + m_CoordinateHeight + offset.y) :
|
||||
new Vector2(zeroPos.x - offset.x, zeroPos.y + offset.y);
|
||||
break;
|
||||
case AxisName.Location.Middle:
|
||||
@@ -672,8 +676,8 @@ namespace XCharts
|
||||
new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f), new Vector2(100, 20), fontSize,
|
||||
xAxis.axisName.rotate, xAxis.axisName.fontStyle);
|
||||
axisName.transform.localPosition = xAxisIndex > 0 ?
|
||||
new Vector2(coordinateX + coordinateWidth / 2 + offset.x, coordinateY + coordinateHeight - offset.y) :
|
||||
new Vector2(coordinateX + coordinateWidth / 2 + offset.x, coordinateY - offset.y);
|
||||
new Vector2(m_CoordinateX + m_CoordinateWidth / 2 + offset.x, m_CoordinateY + m_CoordinateHeight - offset.y) :
|
||||
new Vector2(m_CoordinateX + m_CoordinateWidth / 2 + offset.x, m_CoordinateY - offset.y);
|
||||
break;
|
||||
case AxisName.Location.End:
|
||||
axisName = ChartHelper.AddTextObject(s_DefaultAxisName, axisObj.transform,
|
||||
@@ -681,8 +685,8 @@ namespace XCharts
|
||||
new Vector2(0, 0.5f), new Vector2(0, 0.5f), new Vector2(100, 20), fontSize,
|
||||
xAxis.axisName.rotate, xAxis.axisName.fontStyle);
|
||||
axisName.transform.localPosition = xAxisIndex > 0 ?
|
||||
new Vector2(coordinateX + coordinateWidth + offset.x, coordinateY + coordinateHeight + offset.y) :
|
||||
new Vector2(coordinateX + coordinateWidth + offset.x, zeroPos.y + offset.y);
|
||||
new Vector2(m_CoordinateX + m_CoordinateWidth + offset.x, m_CoordinateY + m_CoordinateHeight + offset.y) :
|
||||
new Vector2(m_CoordinateX + m_CoordinateWidth + offset.x, zeroPos.y + offset.y);
|
||||
break;
|
||||
}
|
||||
axisName.text = xAxis.axisName.name;
|
||||
@@ -727,7 +731,7 @@ namespace XCharts
|
||||
|
||||
private Vector3 GetLabelYPosition(float scaleWid, int i, int yAxisIndex, YAxis yAxis)
|
||||
{
|
||||
var startX = yAxisIndex == 0 ? coordinateX : coordinateX + coordinateWidth;
|
||||
var startX = yAxisIndex == 0 ? m_CoordinateX : m_CoordinateX + m_CoordinateWidth;
|
||||
var posX = 0f;
|
||||
var inside = yAxis.axisLabel.inside;
|
||||
if ((inside && yAxisIndex == 0) || (!inside && yAxisIndex == 1))
|
||||
@@ -738,13 +742,13 @@ namespace XCharts
|
||||
{
|
||||
posX = startX - yAxis.axisLabel.margin;
|
||||
}
|
||||
return new Vector3(posX, coordinateY + scaleWid, 0);
|
||||
return new Vector3(posX, m_CoordinateY + scaleWid, 0);
|
||||
}
|
||||
|
||||
private Vector3 GetLabelXPosition(float scaleWid, int i, int xAxisIndex, XAxis xAxis)
|
||||
{
|
||||
var startY = coordinateY + (xAxis.axisLabel.onZero ? m_YAxises[xAxisIndex].runtimeZeroYOffset : 0);
|
||||
if (xAxisIndex > 0) startY += coordinateHeight;
|
||||
var startY = m_CoordinateY + (xAxis.axisLabel.onZero ? m_YAxises[xAxisIndex].runtimeZeroYOffset : 0);
|
||||
if (xAxisIndex > 0) startY += m_CoordinateHeight;
|
||||
var posY = 0f;
|
||||
var inside = xAxis.axisLabel.inside;
|
||||
if ((inside && xAxisIndex == 0) || (!inside && xAxisIndex == 1))
|
||||
@@ -755,7 +759,7 @@ namespace XCharts
|
||||
{
|
||||
posY = startY - xAxis.axisLabel.margin - xAxis.axisLabel.fontSize / 2;
|
||||
}
|
||||
return new Vector3(coordinateX + scaleWid, posY);
|
||||
return new Vector3(m_CoordinateX + scaleWid, posY);
|
||||
}
|
||||
|
||||
private void CheckMinMaxValue()
|
||||
@@ -813,14 +817,14 @@ namespace XCharts
|
||||
if (axis is XAxis && axis.IsValue())
|
||||
{
|
||||
axis.runtimeZeroXOffset = axis.runtimeMinValue > 0 ? 0 :
|
||||
axis.runtimeMaxValue < 0 ? this.coordinateWidth :
|
||||
Mathf.Abs(axis.runtimeMinValue) * (this.coordinateWidth / (Mathf.Abs(axis.runtimeMinValue) + Mathf.Abs(axis.runtimeMaxValue)));
|
||||
axis.runtimeMaxValue < 0 ? this.m_CoordinateWidth :
|
||||
Mathf.Abs(axis.runtimeMinValue) * (this.m_CoordinateWidth / (Mathf.Abs(axis.runtimeMinValue) + Mathf.Abs(axis.runtimeMaxValue)));
|
||||
}
|
||||
if (axis is YAxis && axis.IsValue())
|
||||
{
|
||||
axis.runtimeZeroYOffset = axis.runtimeMinValue > 0 ? 0 :
|
||||
axis.runtimeMaxValue < 0 ? coordinateHeight :
|
||||
Mathf.Abs(axis.runtimeMinValue) * (coordinateHeight / (Mathf.Abs(axis.runtimeMinValue) + Mathf.Abs(axis.runtimeMaxValue)));
|
||||
axis.runtimeMaxValue < 0 ? m_CoordinateHeight :
|
||||
Mathf.Abs(axis.runtimeMinValue) * (m_CoordinateHeight / (Mathf.Abs(axis.runtimeMinValue) + Mathf.Abs(axis.runtimeMaxValue)));
|
||||
}
|
||||
}
|
||||
if (updateChart)
|
||||
@@ -838,13 +842,14 @@ namespace XCharts
|
||||
|
||||
protected void UpdateAxisLabelText(Axis axis)
|
||||
{
|
||||
float coordinateWidth = axis is XAxis ? this.coordinateWidth : coordinateHeight;
|
||||
float m_CoordinateWidth = axis is XAxis ? this.m_CoordinateWidth : m_CoordinateHeight;
|
||||
var isPercentStack = m_Series.IsPercentStack(SerieType.Bar);
|
||||
axis.UpdateLabelText(coordinateWidth, m_DataZoom, isPercentStack, 500);
|
||||
axis.UpdateLabelText(m_CoordinateWidth, m_DataZoom, isPercentStack, 500);
|
||||
}
|
||||
|
||||
protected virtual void OnCoordinateChanged()
|
||||
{
|
||||
UpdateCoordinate();
|
||||
m_XAxisesDirty = true;
|
||||
m_YAxisesDirty = true;
|
||||
}
|
||||
@@ -852,8 +857,7 @@ namespace XCharts
|
||||
protected override void OnSizeChanged()
|
||||
{
|
||||
base.OnSizeChanged();
|
||||
m_XAxisesDirty = true;
|
||||
m_YAxisesDirty = true;
|
||||
OnCoordinateChanged();
|
||||
}
|
||||
|
||||
private void DrawCoordinate(VertexHelper vh)
|
||||
@@ -891,12 +895,12 @@ namespace XCharts
|
||||
|
||||
private void DrawGrid(VertexHelper vh)
|
||||
{
|
||||
if (m_Grid.show && m_Grid.backgroundColor != Color.clear)
|
||||
if (m_Grid.show && !ChartHelper.IsClearColor(m_Grid.backgroundColor))
|
||||
{
|
||||
var p1 = new Vector2(coordinateX, coordinateY);
|
||||
var p2 = new Vector2(coordinateX, coordinateY + coordinateHeight);
|
||||
var p3 = new Vector2(coordinateX + coordinateWidth, coordinateY + coordinateHeight);
|
||||
var p4 = new Vector2(coordinateX + coordinateWidth, coordinateY);
|
||||
var p1 = new Vector2(m_CoordinateX, m_CoordinateY);
|
||||
var p2 = new Vector2(m_CoordinateX, m_CoordinateY + m_CoordinateHeight);
|
||||
var p3 = new Vector2(m_CoordinateX + m_CoordinateWidth, m_CoordinateY + m_CoordinateHeight);
|
||||
var p4 = new Vector2(m_CoordinateX + m_CoordinateWidth, m_CoordinateY);
|
||||
ChartDrawer.DrawPolygon(vh, p1, p2, p3, p4, m_Grid.backgroundColor);
|
||||
}
|
||||
}
|
||||
@@ -905,13 +909,13 @@ namespace XCharts
|
||||
{
|
||||
if (yAxis.NeedShowSplit())
|
||||
{
|
||||
var size = yAxis.GetScaleNumber(coordinateWidth, m_DataZoom);
|
||||
var totalWidth = coordinateY;
|
||||
var size = yAxis.GetScaleNumber(m_CoordinateWidth, m_DataZoom);
|
||||
var totalWidth = m_CoordinateY;
|
||||
var xAxis = m_XAxises[yAxisIndex];
|
||||
var zeroPos = new Vector3(coordinateX + xAxis.runtimeZeroXOffset, coordinateY + yAxis.runtimeZeroYOffset);
|
||||
var zeroPos = new Vector3(m_CoordinateX + xAxis.runtimeZeroXOffset, m_CoordinateY + yAxis.runtimeZeroYOffset);
|
||||
for (int i = 0; i < size; i++)
|
||||
{
|
||||
var scaleWidth = yAxis.GetScaleWidth(coordinateHeight, i, m_DataZoom);
|
||||
var scaleWidth = yAxis.GetScaleWidth(m_CoordinateHeight, i, m_DataZoom);
|
||||
float pY = totalWidth;
|
||||
if (yAxis.boundaryGap && yAxis.axisTick.alignWithLabel)
|
||||
{
|
||||
@@ -919,10 +923,10 @@ namespace XCharts
|
||||
}
|
||||
if (yAxis.splitArea.show && i < size - 1)
|
||||
{
|
||||
ChartDrawer.DrawPolygon(vh, new Vector2(coordinateX, pY),
|
||||
new Vector2(coordinateX + coordinateWidth, pY),
|
||||
new Vector2(coordinateX + coordinateWidth, pY + scaleWidth),
|
||||
new Vector2(coordinateX, pY + scaleWidth),
|
||||
ChartDrawer.DrawPolygon(vh, new Vector2(m_CoordinateX, pY),
|
||||
new Vector2(m_CoordinateX + m_CoordinateWidth, pY),
|
||||
new Vector2(m_CoordinateX + m_CoordinateWidth, pY + scaleWidth),
|
||||
new Vector2(m_CoordinateX, pY + scaleWidth),
|
||||
yAxis.splitArea.getColor(i));
|
||||
}
|
||||
if (yAxis.splitLine.show)
|
||||
@@ -931,8 +935,8 @@ namespace XCharts
|
||||
{
|
||||
if (yAxis.splitLine.NeedShow(i))
|
||||
{
|
||||
DrawLineStyle(vh, yAxis.splitLine.lineStyle, new Vector3(coordinateX, pY),
|
||||
new Vector3(coordinateX + coordinateWidth, pY), yAxis.splitLine.GetColor(m_ThemeInfo));
|
||||
DrawLineStyle(vh, yAxis.splitLine.lineStyle, new Vector3(m_CoordinateX, pY),
|
||||
new Vector3(m_CoordinateX + m_CoordinateWidth, pY), yAxis.splitLine.GetColor(m_ThemeInfo));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -945,12 +949,12 @@ namespace XCharts
|
||||
{
|
||||
if (yAxis.NeedShowSplit())
|
||||
{
|
||||
var size = yAxis.GetScaleNumber(coordinateWidth, m_DataZoom);
|
||||
var totalWidth = coordinateY;
|
||||
var size = yAxis.GetScaleNumber(m_CoordinateWidth, m_DataZoom);
|
||||
var totalWidth = m_CoordinateY;
|
||||
var xAxis = m_XAxises[yAxisIndex];
|
||||
for (int i = 0; i < size; i++)
|
||||
{
|
||||
var scaleWidth = yAxis.GetScaleWidth(coordinateHeight, i, m_DataZoom);
|
||||
var scaleWidth = yAxis.GetScaleWidth(m_CoordinateHeight, i, m_DataZoom);
|
||||
float pX = 0;
|
||||
float pY = totalWidth;
|
||||
if (yAxis.boundaryGap && yAxis.axisTick.alignWithLabel)
|
||||
@@ -959,9 +963,9 @@ namespace XCharts
|
||||
}
|
||||
if (yAxis.axisTick.show)
|
||||
{
|
||||
var startX = coordinateX + (yAxis.axisLine.onZero ? m_XAxises[yAxisIndex].runtimeZeroXOffset : 0);
|
||||
var startX = m_CoordinateX + (yAxis.axisLine.onZero ? m_XAxises[yAxisIndex].runtimeZeroXOffset : 0);
|
||||
startX -= yAxis.axisLine.width;
|
||||
if (yAxis.IsValue() && yAxisIndex > 0) startX += coordinateWidth;
|
||||
if (yAxis.IsValue() && yAxisIndex > 0) startX += m_CoordinateWidth;
|
||||
bool inside = yAxis.axisTick.inside;
|
||||
if ((inside && yAxisIndex == 0) || (!inside && yAxisIndex == 1))
|
||||
{
|
||||
@@ -979,13 +983,13 @@ namespace XCharts
|
||||
}
|
||||
if (yAxis.show && yAxis.axisLine.show)
|
||||
{
|
||||
var lineX = coordinateX + (yAxis.axisLine.onZero ? m_XAxises[yAxisIndex].runtimeZeroXOffset : 0);
|
||||
if (yAxis.IsValue() && yAxisIndex > 0) lineX += coordinateWidth;
|
||||
var top = new Vector3(lineX, coordinateY + coordinateHeight + yAxis.axisLine.width);
|
||||
var lineX = m_CoordinateX + (yAxis.axisLine.onZero ? m_XAxises[yAxisIndex].runtimeZeroXOffset : 0);
|
||||
if (yAxis.IsValue() && yAxisIndex > 0) lineX += m_CoordinateWidth;
|
||||
var top = new Vector3(lineX, m_CoordinateY + m_CoordinateHeight + yAxis.axisLine.width);
|
||||
if (yAxis.axisLine.symbol)
|
||||
{
|
||||
var axisLine = yAxis.axisLine;
|
||||
ChartDrawer.DrawArrow(vh, new Vector3(lineX, coordinateX), top, axisLine.symbolWidth, axisLine.symbolHeight,
|
||||
ChartDrawer.DrawArrow(vh, new Vector3(lineX, m_CoordinateX), top, axisLine.symbolWidth, axisLine.symbolHeight,
|
||||
axisLine.symbolOffset, axisLine.symbolDent, m_ThemeInfo.axisLineColor);
|
||||
}
|
||||
}
|
||||
@@ -995,13 +999,13 @@ namespace XCharts
|
||||
{
|
||||
if (xAxis.NeedShowSplit())
|
||||
{
|
||||
var size = xAxis.GetScaleNumber(coordinateWidth, m_DataZoom);
|
||||
var totalWidth = coordinateX;
|
||||
var size = xAxis.GetScaleNumber(m_CoordinateWidth, m_DataZoom);
|
||||
var totalWidth = m_CoordinateX;
|
||||
var yAxis = m_YAxises[xAxisIndex];
|
||||
var zeroPos = new Vector3(coordinateX, coordinateY + yAxis.runtimeZeroYOffset);
|
||||
var zeroPos = new Vector3(m_CoordinateX, m_CoordinateY + yAxis.runtimeZeroYOffset);
|
||||
for (int i = 0; i < size; i++)
|
||||
{
|
||||
var scaleWidth = xAxis.GetScaleWidth(coordinateWidth, i, m_DataZoom);
|
||||
var scaleWidth = xAxis.GetScaleWidth(m_CoordinateWidth, i, m_DataZoom);
|
||||
float pX = totalWidth;
|
||||
if (xAxis.boundaryGap && xAxis.axisTick.alignWithLabel)
|
||||
{
|
||||
@@ -1009,10 +1013,10 @@ namespace XCharts
|
||||
}
|
||||
if (xAxis.splitArea.show && i < size - 1)
|
||||
{
|
||||
ChartDrawer.DrawPolygon(vh, new Vector2(pX, coordinateY),
|
||||
new Vector2(pX, coordinateY + coordinateHeight),
|
||||
new Vector2(pX + scaleWidth, coordinateY + coordinateHeight),
|
||||
new Vector2(pX + scaleWidth, coordinateY),
|
||||
ChartDrawer.DrawPolygon(vh, new Vector2(pX, m_CoordinateY),
|
||||
new Vector2(pX, m_CoordinateY + m_CoordinateHeight),
|
||||
new Vector2(pX + scaleWidth, m_CoordinateY + m_CoordinateHeight),
|
||||
new Vector2(pX + scaleWidth, m_CoordinateY),
|
||||
xAxis.splitArea.getColor(i));
|
||||
}
|
||||
if (xAxis.splitLine.show)
|
||||
@@ -1021,8 +1025,8 @@ namespace XCharts
|
||||
{
|
||||
if (xAxis.splitLine.NeedShow(i))
|
||||
{
|
||||
DrawLineStyle(vh, xAxis.splitLine.lineStyle, new Vector3(pX, coordinateY),
|
||||
new Vector3(pX, coordinateY + coordinateHeight), xAxis.splitLine.GetColor(m_ThemeInfo));
|
||||
DrawLineStyle(vh, xAxis.splitLine.lineStyle, new Vector3(pX, m_CoordinateY),
|
||||
new Vector3(pX, m_CoordinateY + m_CoordinateHeight), xAxis.splitLine.GetColor(m_ThemeInfo));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1035,12 +1039,12 @@ namespace XCharts
|
||||
{
|
||||
if (xAxis.NeedShowSplit())
|
||||
{
|
||||
var size = xAxis.GetScaleNumber(coordinateWidth, m_DataZoom);
|
||||
var totalWidth = coordinateX;
|
||||
var size = xAxis.GetScaleNumber(m_CoordinateWidth, m_DataZoom);
|
||||
var totalWidth = m_CoordinateX;
|
||||
var yAxis = m_YAxises[xAxisIndex];
|
||||
for (int i = 0; i < size; i++)
|
||||
{
|
||||
var scaleWidth = xAxis.GetScaleWidth(coordinateWidth, i, m_DataZoom);
|
||||
var scaleWidth = xAxis.GetScaleWidth(m_CoordinateWidth, i, m_DataZoom);
|
||||
float pX = totalWidth;
|
||||
float pY = 0;
|
||||
if (xAxis.boundaryGap && xAxis.axisTick.alignWithLabel)
|
||||
@@ -1049,9 +1053,9 @@ namespace XCharts
|
||||
}
|
||||
if (xAxis.axisTick.show)
|
||||
{
|
||||
var startY = coordinateY + (xAxis.axisLine.onZero ? m_YAxises[xAxisIndex].runtimeZeroYOffset : 0);
|
||||
var startY = m_CoordinateY + (xAxis.axisLine.onZero ? m_YAxises[xAxisIndex].runtimeZeroYOffset : 0);
|
||||
startY -= xAxis.axisLine.width;
|
||||
if (xAxis.IsValue() && xAxisIndex > 0) startY += coordinateHeight;
|
||||
if (xAxis.IsValue() && xAxisIndex > 0) startY += m_CoordinateHeight;
|
||||
bool inside = xAxis.axisTick.inside;
|
||||
if ((inside && xAxisIndex == 0) || (!inside && xAxisIndex == 1))
|
||||
{
|
||||
@@ -1069,13 +1073,13 @@ namespace XCharts
|
||||
}
|
||||
if (xAxis.show && xAxis.axisLine.show)
|
||||
{
|
||||
var lineY = coordinateY + (xAxis.axisLine.onZero ? m_YAxises[xAxisIndex].runtimeZeroYOffset : 0);
|
||||
if (xAxis.IsValue() && xAxisIndex > 0) lineY += coordinateHeight;
|
||||
var top = new Vector3(coordinateX + coordinateWidth + xAxis.axisLine.width, lineY);
|
||||
var lineY = m_CoordinateY + (xAxis.axisLine.onZero ? m_YAxises[xAxisIndex].runtimeZeroYOffset : 0);
|
||||
if (xAxis.IsValue() && xAxisIndex > 0) lineY += m_CoordinateHeight;
|
||||
var top = new Vector3(m_CoordinateX + m_CoordinateWidth + xAxis.axisLine.width, lineY);
|
||||
if (xAxis.axisLine.symbol)
|
||||
{
|
||||
var axisLine = xAxis.axisLine;
|
||||
ChartDrawer.DrawArrow(vh, new Vector3(coordinateX, lineY), top, axisLine.symbolWidth, axisLine.symbolHeight,
|
||||
ChartDrawer.DrawArrow(vh, new Vector3(m_CoordinateX, lineY), top, axisLine.symbolWidth, axisLine.symbolHeight,
|
||||
axisLine.symbolOffset, axisLine.symbolDent, m_ThemeInfo.axisLineColor);
|
||||
}
|
||||
}
|
||||
@@ -1085,10 +1089,10 @@ namespace XCharts
|
||||
{
|
||||
if (xAxis.show && xAxis.axisLine.show)
|
||||
{
|
||||
var lineY = coordinateY + (xAxis.axisLine.onZero ? m_YAxises[xAxisIndex].runtimeZeroYOffset : 0);
|
||||
if (xAxis.IsValue() && xAxisIndex > 0) lineY += coordinateHeight;
|
||||
var left = new Vector3(coordinateX - xAxis.axisLine.width, lineY);
|
||||
var top = new Vector3(coordinateX + coordinateWidth + xAxis.axisLine.width, lineY);
|
||||
var lineY = m_CoordinateY + (xAxis.axisLine.onZero ? m_YAxises[xAxisIndex].runtimeZeroYOffset : 0);
|
||||
if (xAxis.IsValue() && xAxisIndex > 0) lineY += m_CoordinateHeight;
|
||||
var left = new Vector3(m_CoordinateX - xAxis.axisLine.width, lineY);
|
||||
var top = new Vector3(m_CoordinateX + m_CoordinateWidth + xAxis.axisLine.width, lineY);
|
||||
ChartDrawer.DrawLine(vh, left, top, xAxis.axisLine.width, m_ThemeInfo.axisLineColor);
|
||||
}
|
||||
}
|
||||
@@ -1097,10 +1101,10 @@ namespace XCharts
|
||||
{
|
||||
if (yAxis.show && yAxis.axisLine.show)
|
||||
{
|
||||
var lineX = coordinateX + (yAxis.axisLine.onZero ? m_XAxises[yAxisIndex].runtimeZeroXOffset : 0);
|
||||
if (yAxis.IsValue() && yAxisIndex > 0) lineX += coordinateWidth;
|
||||
var top = new Vector3(lineX, coordinateY + coordinateHeight + yAxis.axisLine.width);
|
||||
ChartDrawer.DrawLine(vh, new Vector3(lineX, coordinateY - yAxis.axisLine.width),
|
||||
var lineX = m_CoordinateX + (yAxis.axisLine.onZero ? m_XAxises[yAxisIndex].runtimeZeroXOffset : 0);
|
||||
if (yAxis.IsValue() && yAxisIndex > 0) lineX += m_CoordinateWidth;
|
||||
var top = new Vector3(lineX, m_CoordinateY + m_CoordinateHeight + yAxis.axisLine.width);
|
||||
ChartDrawer.DrawLine(vh, new Vector3(lineX, m_CoordinateY - yAxis.axisLine.width),
|
||||
top, yAxis.axisLine.width, m_ThemeInfo.axisLineColor);
|
||||
}
|
||||
}
|
||||
@@ -1109,10 +1113,10 @@ namespace XCharts
|
||||
{
|
||||
if (!m_DataZoom.enable || !m_DataZoom.supportSlider) return;
|
||||
var hig = m_DataZoom.GetHeight(grid.bottom);
|
||||
var p1 = new Vector3(coordinateX, m_ChartY + m_DataZoom.bottom);
|
||||
var p2 = new Vector3(coordinateX, m_ChartY + m_DataZoom.bottom + hig);
|
||||
var p3 = new Vector3(coordinateX + coordinateWidth, m_ChartY + m_DataZoom.bottom + hig);
|
||||
var p4 = new Vector3(coordinateX + coordinateWidth, m_ChartY + m_DataZoom.bottom);
|
||||
var p1 = new Vector3(m_CoordinateX, m_ChartY + m_DataZoom.bottom);
|
||||
var p2 = new Vector3(m_CoordinateX, m_ChartY + m_DataZoom.bottom + hig);
|
||||
var p3 = new Vector3(m_CoordinateX + m_CoordinateWidth, m_ChartY + m_DataZoom.bottom + hig);
|
||||
var p4 = new Vector3(m_CoordinateX + m_CoordinateWidth, m_ChartY + m_DataZoom.bottom);
|
||||
var xAxis = xAxises[0];
|
||||
ChartDrawer.DrawLine(vh, p1, p2, xAxis.axisLine.width, m_ThemeInfo.dataZoomLineColor);
|
||||
ChartDrawer.DrawLine(vh, p2, p3, xAxis.axisLine.width, m_ThemeInfo.dataZoomLineColor);
|
||||
@@ -1123,7 +1127,7 @@ namespace XCharts
|
||||
Serie serie = m_Series.list[0];
|
||||
Axis axis = yAxises[0];
|
||||
var showData = serie.GetDataList(null);
|
||||
float scaleWid = coordinateWidth / (showData.Count - 1);
|
||||
float scaleWid = m_CoordinateWidth / (showData.Count - 1);
|
||||
Vector3 lp = Vector3.zero;
|
||||
Vector3 np = Vector3.zero;
|
||||
float minValue = 0;
|
||||
@@ -1134,7 +1138,7 @@ namespace XCharts
|
||||
int rate = 1;
|
||||
var sampleDist = serie.sampleDist < 2 ? 2 : serie.sampleDist;
|
||||
var maxCount = showData.Count;
|
||||
if (sampleDist > 0) rate = (int)((maxCount - serie.minShow) / (coordinateWidth / sampleDist));
|
||||
if (sampleDist > 0) rate = (int)((maxCount - serie.minShow) / (m_CoordinateWidth / sampleDist));
|
||||
if (rate < 1) rate = 1;
|
||||
var totalAverage = serie.sampleAverage > 0 ? serie.sampleAverage :
|
||||
DataAverage(ref showData, serie.sampleType, serie.minShow, maxCount, rate);
|
||||
@@ -1143,7 +1147,7 @@ namespace XCharts
|
||||
{
|
||||
float value = SampleValue(ref showData, serie.sampleType, rate, serie.minShow, maxCount, totalAverage, i,
|
||||
serie.animation.GetUpdateAnimationDuration(), ref dataChanging, axis.inverse);
|
||||
float pX = coordinateX + i * scaleWid;
|
||||
float pX = m_CoordinateX + i * scaleWid;
|
||||
// float dataHig = (axis.runtimeMaxValue - axis.runtimeMinValue) == 0 ? 0 :
|
||||
// (value - axis.runtimeMinValue) / (axis.runtimeMaxValue - axis.runtimeMinValue) * hig;
|
||||
float dataHig = (maxValue - minValue) == 0 ? 0 :
|
||||
@@ -1170,8 +1174,8 @@ namespace XCharts
|
||||
switch (m_DataZoom.rangeMode)
|
||||
{
|
||||
case DataZoom.RangeMode.Percent:
|
||||
var start = coordinateX + coordinateWidth * m_DataZoom.start / 100;
|
||||
var end = coordinateX + coordinateWidth * m_DataZoom.end / 100;
|
||||
var start = m_CoordinateX + m_CoordinateWidth * m_DataZoom.start / 100;
|
||||
var end = m_CoordinateX + m_CoordinateWidth * m_DataZoom.end / 100;
|
||||
p1 = new Vector2(start, m_ChartY + m_DataZoom.bottom);
|
||||
p2 = new Vector2(start, m_ChartY + m_DataZoom.bottom + hig);
|
||||
p3 = new Vector2(end, m_ChartY + m_DataZoom.bottom + hig);
|
||||
@@ -1193,35 +1197,35 @@ namespace XCharts
|
||||
var xAxis = m_XAxises[i];
|
||||
var yAxis = m_YAxises[i];
|
||||
if (!xAxis.show) continue;
|
||||
float splitWidth = xAxis.GetDataWidth(coordinateWidth, dataCount, m_DataZoom);
|
||||
float splitWidth = xAxis.GetDataWidth(m_CoordinateWidth, dataCount, m_DataZoom);
|
||||
switch (m_Tooltip.type)
|
||||
{
|
||||
case Tooltip.Type.Corss:
|
||||
case Tooltip.Type.Line:
|
||||
float pX = coordinateX + m_Tooltip.runtimeXValues[i] * splitWidth
|
||||
float pX = m_CoordinateX + m_Tooltip.runtimeXValues[i] * splitWidth
|
||||
+ (xAxis.boundaryGap ? splitWidth / 2 : 0);
|
||||
if (xAxis.IsValue()) pX = m_Tooltip.runtimePointerPos.x;
|
||||
Vector2 sp = new Vector2(pX, coordinateY);
|
||||
Vector2 ep = new Vector2(pX, coordinateY + coordinateHeight);
|
||||
Vector2 sp = new Vector2(pX, m_CoordinateY);
|
||||
Vector2 ep = new Vector2(pX, m_CoordinateY + m_CoordinateHeight);
|
||||
var lineColor = TooltipHelper.GetLineColor(tooltip, m_ThemeInfo);
|
||||
DrawLineStyle(vh, m_Tooltip.lineStyle, sp, ep, lineColor);
|
||||
if (m_Tooltip.type == Tooltip.Type.Corss)
|
||||
{
|
||||
sp = new Vector2(coordinateX, m_Tooltip.runtimePointerPos.y);
|
||||
ep = new Vector2(coordinateX + coordinateWidth, m_Tooltip.runtimePointerPos.y);
|
||||
sp = new Vector2(m_CoordinateX, m_Tooltip.runtimePointerPos.y);
|
||||
ep = new Vector2(m_CoordinateX + m_CoordinateWidth, m_Tooltip.runtimePointerPos.y);
|
||||
DrawLineStyle(vh, m_Tooltip.lineStyle, sp, ep, lineColor);
|
||||
}
|
||||
break;
|
||||
case Tooltip.Type.Shadow:
|
||||
float tooltipSplitWid = splitWidth < 1 ? 1 : splitWidth;
|
||||
pX = coordinateX + splitWidth * m_Tooltip.runtimeXValues[i] -
|
||||
pX = m_CoordinateX + splitWidth * m_Tooltip.runtimeXValues[i] -
|
||||
(xAxis.boundaryGap ? 0 : splitWidth / 2);
|
||||
if (xAxis.IsValue()) pX = m_Tooltip.runtimeXValues[i];
|
||||
float pY = coordinateY + coordinateHeight;
|
||||
Vector3 p1 = new Vector3(pX, coordinateY);
|
||||
float pY = m_CoordinateY + m_CoordinateHeight;
|
||||
Vector3 p1 = new Vector3(pX, m_CoordinateY);
|
||||
Vector3 p2 = new Vector3(pX, pY);
|
||||
Vector3 p3 = new Vector3(pX + tooltipSplitWid, pY);
|
||||
Vector3 p4 = new Vector3(pX + tooltipSplitWid, coordinateY);
|
||||
Vector3 p4 = new Vector3(pX + tooltipSplitWid, m_CoordinateY);
|
||||
ChartDrawer.DrawPolygon(vh, p1, p2, p3, p4, m_ThemeInfo.tooltipFlagAreaColor);
|
||||
break;
|
||||
}
|
||||
@@ -1238,30 +1242,30 @@ namespace XCharts
|
||||
var yAxis = m_YAxises[i];
|
||||
var xAxis = m_XAxises[i];
|
||||
if (!yAxis.show) continue;
|
||||
float splitWidth = yAxis.GetDataWidth(coordinateHeight, dataCount, m_DataZoom);
|
||||
float splitWidth = yAxis.GetDataWidth(m_CoordinateHeight, dataCount, m_DataZoom);
|
||||
switch (m_Tooltip.type)
|
||||
{
|
||||
case Tooltip.Type.Corss:
|
||||
case Tooltip.Type.Line:
|
||||
float pY = coordinateY + m_Tooltip.runtimeYValues[i] * splitWidth + (yAxis.boundaryGap ? splitWidth / 2 : 0);
|
||||
Vector2 sp = new Vector2(coordinateX, pY);
|
||||
Vector2 ep = new Vector2(coordinateX + coordinateWidth, pY);
|
||||
float pY = m_CoordinateY + m_Tooltip.runtimeYValues[i] * splitWidth + (yAxis.boundaryGap ? splitWidth / 2 : 0);
|
||||
Vector2 sp = new Vector2(m_CoordinateX, pY);
|
||||
Vector2 ep = new Vector2(m_CoordinateX + m_CoordinateWidth, pY);
|
||||
var lineColor = TooltipHelper.GetLineColor(tooltip, m_ThemeInfo);
|
||||
DrawLineStyle(vh, m_Tooltip.lineStyle, sp, ep, lineColor);
|
||||
if (m_Tooltip.type == Tooltip.Type.Corss)
|
||||
{
|
||||
sp = new Vector2(coordinateX, m_Tooltip.runtimePointerPos.y);
|
||||
ep = new Vector2(coordinateX + coordinateWidth, m_Tooltip.runtimePointerPos.y);
|
||||
sp = new Vector2(m_CoordinateX, m_Tooltip.runtimePointerPos.y);
|
||||
ep = new Vector2(m_CoordinateX + m_CoordinateWidth, m_Tooltip.runtimePointerPos.y);
|
||||
DrawLineStyle(vh, m_Tooltip.lineStyle, sp, ep, lineColor);
|
||||
}
|
||||
break;
|
||||
case Tooltip.Type.Shadow:
|
||||
float tooltipSplitWid = splitWidth < 1 ? 1 : splitWidth;
|
||||
float pX = coordinateX + coordinateWidth;
|
||||
pY = coordinateY + splitWidth * m_Tooltip.runtimeYValues[i] -
|
||||
float pX = m_CoordinateX + m_CoordinateWidth;
|
||||
pY = m_CoordinateY + splitWidth * m_Tooltip.runtimeYValues[i] -
|
||||
(yAxis.boundaryGap ? 0 : splitWidth / 2);
|
||||
Vector3 p1 = new Vector3(coordinateX, pY);
|
||||
Vector3 p2 = new Vector3(coordinateX, pY + tooltipSplitWid);
|
||||
Vector3 p1 = new Vector3(m_CoordinateX, pY);
|
||||
Vector3 p2 = new Vector3(m_CoordinateX, pY + tooltipSplitWid);
|
||||
Vector3 p3 = new Vector3(pX, pY + tooltipSplitWid);
|
||||
Vector3 p4 = new Vector3(pX, pY);
|
||||
ChartDrawer.DrawPolygon(vh, p1, p2, p3, p4, m_ThemeInfo.tooltipFlagAreaColor);
|
||||
@@ -1328,9 +1332,9 @@ namespace XCharts
|
||||
m_DataZoom.SetLabelActive(false);
|
||||
return;
|
||||
}
|
||||
if (m_DataZoom.IsInSelectedZoom(local, coordinateX, chartY, coordinateWidth)
|
||||
|| m_DataZoom.IsInStartZoom(local, coordinateX, chartY, coordinateWidth)
|
||||
|| m_DataZoom.IsInEndZoom(local, coordinateX, chartY, coordinateWidth))
|
||||
if (m_DataZoom.IsInSelectedZoom(local, m_CoordinateX, chartY, m_CoordinateWidth)
|
||||
|| m_DataZoom.IsInStartZoom(local, m_CoordinateX, chartY, m_CoordinateWidth)
|
||||
|| m_DataZoom.IsInEndZoom(local, m_CoordinateX, chartY, m_CoordinateWidth))
|
||||
{
|
||||
m_DataZoom.SetLabelActive(true);
|
||||
RefreshDataZoomLabel();
|
||||
@@ -1358,8 +1362,8 @@ namespace XCharts
|
||||
}
|
||||
InitAxisX();
|
||||
}
|
||||
var start = coordinateX + coordinateWidth * m_DataZoom.start / 100;
|
||||
var end = coordinateX + coordinateWidth * m_DataZoom.end / 100;
|
||||
var start = m_CoordinateX + m_CoordinateWidth * m_DataZoom.start / 100;
|
||||
var end = m_CoordinateX + m_CoordinateWidth * m_DataZoom.end / 100;
|
||||
var hig = m_DataZoom.GetHeight(grid.bottom);
|
||||
m_DataZoom.UpdateStartLabelPosition(new Vector3(start - 10, chartY + m_DataZoom.bottom + hig / 2));
|
||||
m_DataZoom.UpdateEndLabelPosition(new Vector3(end + 10, chartY + m_DataZoom.bottom + hig / 2));
|
||||
@@ -1378,6 +1382,7 @@ namespace XCharts
|
||||
for (int j = 0; j < serie.data.Count; j++)
|
||||
{
|
||||
var serieData = serie.data[j];
|
||||
if (serieData.labelObject == null) continue;
|
||||
var serieLabel = SerieHelper.GetSerieLabel(serie, serieData, serieData.highlighted);
|
||||
serieData.index = j;
|
||||
if ((serieLabel.show || serieData.iconStyle.show))
|
||||
@@ -1406,12 +1411,12 @@ namespace XCharts
|
||||
if (isYAxis)
|
||||
{
|
||||
var xAxis = m_XAxises[serie.axisIndex];
|
||||
zeroPos = new Vector3(coordinateX + xAxis.runtimeZeroXOffset, coordinateY);
|
||||
zeroPos = new Vector3(m_CoordinateX + xAxis.runtimeZeroXOffset, m_CoordinateY);
|
||||
}
|
||||
else
|
||||
{
|
||||
var yAxis = m_YAxises[serie.axisIndex];
|
||||
zeroPos = new Vector3(coordinateX, coordinateY + yAxis.runtimeZeroYOffset);
|
||||
zeroPos = new Vector3(m_CoordinateX, m_CoordinateY + yAxis.runtimeZeroYOffset);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1448,18 +1453,20 @@ namespace XCharts
|
||||
for (int i = 0; i < m_Series.Count; i++)
|
||||
{
|
||||
var serie = m_Series.GetSerie(i);
|
||||
if (serie.IsPerformanceMode()) continue;
|
||||
var total = serie.yTotal;
|
||||
var isPercentStack = m_Series.IsPercentStack(serie.stack, SerieType.Bar);
|
||||
for (int j = 0; j < serie.data.Count; j++)
|
||||
{
|
||||
if (j >= serie.dataPoints.Count) break;
|
||||
var serieData = serie.data[j];
|
||||
if (serieData.labelObject == null) continue;
|
||||
var pos = serie.dataPoints[j];
|
||||
var serieLabel = SerieHelper.GetSerieLabel(serie, serieData);
|
||||
var dimension = 1;
|
||||
var isIgnore = serie.IsIgnoreIndex(j, 1);
|
||||
serieData.SetGameObjectPosition(serieData.labelPosition);
|
||||
serieData.UpdateIcon();
|
||||
serieData.labelObject.SetPosition(serieData.labelPosition);
|
||||
serieData.labelObject.UpdateIcon(serieData.iconStyle);
|
||||
if (serie.show && serieLabel.show && serieData.canShowLabel && !isIgnore)
|
||||
{
|
||||
float value = 0f;
|
||||
@@ -1485,8 +1492,8 @@ namespace XCharts
|
||||
}
|
||||
serieData.SetLabelActive(value != 0 && serieData.labelPosition != Vector3.zero);
|
||||
var invert = serie.type == SerieType.Line && SerieHelper.IsDownPoint(serie, j) && !serie.areaStyle.show;
|
||||
serieData.SetLabelPosition(invert ? -serieLabel.offset : serieLabel.offset);
|
||||
if (serieData.SetLabelText(content)) RefreshChart();
|
||||
serieData.labelObject.SetLabelPosition(invert ? -serieLabel.offset : serieLabel.offset);
|
||||
if (serieData.labelObject.SetText(content)) RefreshChart();
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -1514,15 +1521,15 @@ namespace XCharts
|
||||
}
|
||||
if (m_DataZoom.supportSlider)
|
||||
{
|
||||
if (m_DataZoom.IsInStartZoom(pos, coordinateX, chartY, coordinateWidth))
|
||||
if (m_DataZoom.IsInStartZoom(pos, m_CoordinateX, chartY, m_CoordinateWidth))
|
||||
{
|
||||
m_DataZoomStartDrag = true;
|
||||
}
|
||||
else if (m_DataZoom.IsInEndZoom(pos, coordinateX, chartY, coordinateWidth))
|
||||
else if (m_DataZoom.IsInEndZoom(pos, m_CoordinateX, chartY, m_CoordinateWidth))
|
||||
{
|
||||
m_DataZoomEndDrag = true;
|
||||
}
|
||||
else if (m_DataZoom.IsInSelectedZoom(pos, coordinateX, chartY, coordinateWidth))
|
||||
else if (m_DataZoom.IsInSelectedZoom(pos, m_CoordinateX, chartY, m_CoordinateWidth))
|
||||
{
|
||||
m_DataZoomDrag = true;
|
||||
}
|
||||
@@ -1534,7 +1541,7 @@ namespace XCharts
|
||||
{
|
||||
if (Input.touchCount > 1) return;
|
||||
float deltaX = eventData.delta.x;
|
||||
float deltaPercent = deltaX / coordinateWidth * 100;
|
||||
float deltaPercent = deltaX / m_CoordinateWidth * 100;
|
||||
OnDragInside(deltaPercent);
|
||||
OnDragSlider(deltaPercent);
|
||||
OnDragVisualMap();
|
||||
@@ -1648,30 +1655,30 @@ namespace XCharts
|
||||
return;
|
||||
}
|
||||
|
||||
if (m_DataZoom.IsInStartZoom(localPos, coordinateX, chartY, coordinateWidth) ||
|
||||
m_DataZoom.IsInEndZoom(localPos, coordinateX, chartY, coordinateWidth))
|
||||
if (m_DataZoom.IsInStartZoom(localPos, m_CoordinateX, chartY, m_CoordinateWidth) ||
|
||||
m_DataZoom.IsInEndZoom(localPos, m_CoordinateX, chartY, m_CoordinateWidth))
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (m_DataZoom.IsInZoom(localPos, coordinateX, chartY, coordinateWidth)
|
||||
&& !m_DataZoom.IsInSelectedZoom(localPos, coordinateX, chartY, coordinateWidth))
|
||||
if (m_DataZoom.IsInZoom(localPos, m_CoordinateX, chartY, m_CoordinateWidth)
|
||||
&& !m_DataZoom.IsInSelectedZoom(localPos, m_CoordinateX, chartY, m_CoordinateWidth))
|
||||
{
|
||||
var pointerX = localPos.x;
|
||||
var selectWidth = coordinateWidth * (m_DataZoom.end - m_DataZoom.start) / 100;
|
||||
var selectWidth = m_CoordinateWidth * (m_DataZoom.end - m_DataZoom.start) / 100;
|
||||
var startX = pointerX - selectWidth / 2;
|
||||
var endX = pointerX + selectWidth / 2;
|
||||
if (startX < coordinateX)
|
||||
if (startX < m_CoordinateX)
|
||||
{
|
||||
startX = coordinateX;
|
||||
endX = coordinateX + selectWidth;
|
||||
startX = m_CoordinateX;
|
||||
endX = m_CoordinateX + selectWidth;
|
||||
}
|
||||
else if (endX > coordinateX + coordinateWidth)
|
||||
else if (endX > m_CoordinateX + m_CoordinateWidth)
|
||||
{
|
||||
endX = coordinateX + coordinateWidth;
|
||||
startX = coordinateX + coordinateWidth - selectWidth;
|
||||
endX = m_CoordinateX + m_CoordinateWidth;
|
||||
startX = m_CoordinateX + m_CoordinateWidth - selectWidth;
|
||||
}
|
||||
m_DataZoom.start = (startX - coordinateX) / coordinateWidth * 100;
|
||||
m_DataZoom.end = (endX - coordinateX) / coordinateWidth * 100;
|
||||
m_DataZoom.start = (startX - m_CoordinateX) / m_CoordinateWidth * 100;
|
||||
m_DataZoom.end = (endX - m_CoordinateX) / m_CoordinateWidth * 100;
|
||||
RefreshDataZoomLabel();
|
||||
RefreshChart();
|
||||
}
|
||||
@@ -1687,7 +1694,7 @@ namespace XCharts
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (!IsInCooridate(pos) && !m_DataZoom.IsInSelectedZoom(pos, coordinateX, chartY, coordinateWidth))
|
||||
if (!IsInCooridate(pos) && !m_DataZoom.IsInSelectedZoom(pos, m_CoordinateX, chartY, m_CoordinateWidth))
|
||||
{
|
||||
return;
|
||||
}
|
||||
@@ -1696,7 +1703,7 @@ namespace XCharts
|
||||
|
||||
private void ScaleDataZoom(float delta)
|
||||
{
|
||||
float deltaPercent = Mathf.Abs(delta / coordinateWidth * 100);
|
||||
float deltaPercent = Mathf.Abs(delta / m_CoordinateWidth * 100);
|
||||
if (delta > 0)
|
||||
{
|
||||
if (m_DataZoom.end <= m_DataZoom.start) return;
|
||||
@@ -1735,10 +1742,10 @@ namespace XCharts
|
||||
protected void CheckClipAndDrawPolygon(VertexHelper vh, Vector3 p1, Vector3 p2, Vector3 p3, Vector3 p4,
|
||||
Color32 startColor, Color32 toColor, bool clip)
|
||||
{
|
||||
p1 = ClampInChart(p1);
|
||||
p2 = ClampInChart(p2);
|
||||
p3 = ClampInChart(p3);
|
||||
p4 = ClampInChart(p4);
|
||||
ClampInChart(ref p1);
|
||||
ClampInChart(ref p2);
|
||||
ClampInChart(ref p3);
|
||||
ClampInChart(ref p4);
|
||||
if (clip)
|
||||
{
|
||||
p1 = ClampInCoordinate(p1);
|
||||
@@ -1753,10 +1760,10 @@ namespace XCharts
|
||||
protected void CheckClipAndDrawPolygon(VertexHelper vh, ref Vector3 p1, ref Vector3 p2, ref Vector3 p3, ref Vector3 p4,
|
||||
Color32 startColor, Color32 toColor, bool clip)
|
||||
{
|
||||
p1 = ClampInChart(p1);
|
||||
p2 = ClampInChart(p2);
|
||||
p3 = ClampInChart(p3);
|
||||
p4 = ClampInChart(p4);
|
||||
ClampInChart(ref p1);
|
||||
ClampInChart(ref p2);
|
||||
ClampInChart(ref p3);
|
||||
ClampInChart(ref p4);
|
||||
if (clip)
|
||||
{
|
||||
p1 = ClampInCoordinate(p1);
|
||||
@@ -1801,21 +1808,21 @@ namespace XCharts
|
||||
protected void CheckClipAndDrawZebraLine(VertexHelper vh, Vector3 p1, Vector3 p2, float size,
|
||||
float zebraWidth, float zebraGap, Color32 color, bool clip)
|
||||
{
|
||||
p1 = ClampInChart(p1);
|
||||
p2 = ClampInChart(p2);
|
||||
ClampInChart(ref p1);
|
||||
ClampInChart(ref p2);
|
||||
ChartDrawer.DrawZebraLine(vh, p1, p2, size, zebraWidth, zebraGap, color);
|
||||
}
|
||||
|
||||
protected Color GetXLerpColor(Color areaColor, Color areaToColor, Vector3 pos)
|
||||
{
|
||||
if (areaColor == areaToColor) return areaColor;
|
||||
return Color.Lerp(areaToColor, areaColor, (pos.y - coordinateY) / coordinateHeight);
|
||||
return Color.Lerp(areaToColor, areaColor, (pos.y - m_CoordinateY) / m_CoordinateHeight);
|
||||
}
|
||||
|
||||
protected Color GetYLerpColor(Color areaColor, Color areaToColor, Vector3 pos)
|
||||
{
|
||||
if (areaColor == areaToColor) return areaColor;
|
||||
return Color.Lerp(areaToColor, areaColor, (pos.x - coordinateX) / coordinateWidth);
|
||||
return Color.Lerp(areaToColor, areaColor, (pos.x - m_CoordinateX) / m_CoordinateWidth);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,7 +24,7 @@ namespace XCharts
|
||||
if (!yAxis.show) yAxis = m_YAxises[(serie.axisIndex + 1) % m_YAxises.Count];
|
||||
|
||||
var showData = serie.GetDataList(m_DataZoom);
|
||||
float categoryWidth = yAxis.GetDataWidth(coordinateHeight, showData.Count, m_DataZoom);
|
||||
float categoryWidth = yAxis.GetDataWidth(m_CoordinateHeight, showData.Count, m_DataZoom);
|
||||
float barGap = GetBarGap();
|
||||
float totalBarWidth = GetBarTotalWidth(categoryWidth, barGap);
|
||||
float barWidth = serie.GetBarWidth(categoryWidth);
|
||||
@@ -71,8 +71,8 @@ namespace XCharts
|
||||
float borderWidth = value == 0 ? 0 : itemStyle.runtimeBorderWidth;
|
||||
if (showData[i].IsDataChanged()) dataChanging = true;
|
||||
float axisLineWidth = (value < 0 ? -1 : 1) * yAxis.axisLine.width;
|
||||
float pX = seriesHig[i] + coordinateX + xAxis.runtimeZeroXOffset + axisLineWidth;
|
||||
float pY = coordinateY + i * categoryWidth;
|
||||
float pX = seriesHig[i] + m_CoordinateX + xAxis.runtimeZeroXOffset + axisLineWidth;
|
||||
float pY = m_CoordinateY + i * categoryWidth;
|
||||
if (!yAxis.boundaryGap) pY -= categoryWidth / 2;
|
||||
|
||||
var barHig = 0f;
|
||||
@@ -80,7 +80,7 @@ namespace XCharts
|
||||
if (isPercentStack)
|
||||
{
|
||||
valueTotal = GetSameStackTotalValue(serie.stack, i);
|
||||
barHig = valueTotal != 0 ? (value / valueTotal * coordinateWidth) : 0;
|
||||
barHig = valueTotal != 0 ? (value / valueTotal * m_CoordinateWidth) : 0;
|
||||
seriesHig[i] += barHig;
|
||||
}
|
||||
else
|
||||
@@ -88,7 +88,7 @@ namespace XCharts
|
||||
valueTotal = xMaxValue - xMinValue;
|
||||
if (valueTotal != 0)
|
||||
barHig = (xMinValue > 0 ? value - xMinValue : value)
|
||||
/ valueTotal * coordinateWidth;
|
||||
/ valueTotal * m_CoordinateWidth;
|
||||
seriesHig[i] += barHig;
|
||||
}
|
||||
|
||||
@@ -165,7 +165,7 @@ namespace XCharts
|
||||
var xAxis = m_XAxises[serie.axisIndex];
|
||||
if (!xAxis.show) xAxis = m_XAxises[(serie.axisIndex + 1) % m_XAxises.Count];
|
||||
|
||||
float categoryWidth = xAxis.GetDataWidth(coordinateWidth, showData.Count, m_DataZoom);
|
||||
float categoryWidth = xAxis.GetDataWidth(m_CoordinateWidth, showData.Count, m_DataZoom);
|
||||
float barGap = GetBarGap();
|
||||
float totalBarWidth = GetBarTotalWidth(categoryWidth, barGap);
|
||||
float barWidth = serie.GetBarWidth(categoryWidth);
|
||||
@@ -208,8 +208,8 @@ namespace XCharts
|
||||
float value = serieData.GetCurrData(1, dataChangeDuration, yAxis.inverse);
|
||||
float borderWidth = value == 0 ? 0 : itemStyle.runtimeBorderWidth;
|
||||
if (serieData.IsDataChanged()) dataChanging = true;
|
||||
float pX = coordinateX + i * categoryWidth;
|
||||
float zeroY = coordinateY + yAxis.runtimeZeroYOffset;
|
||||
float pX = m_CoordinateX + i * categoryWidth;
|
||||
float zeroY = m_CoordinateY + yAxis.runtimeZeroYOffset;
|
||||
if (!xAxis.boundaryGap) pX -= categoryWidth / 2;
|
||||
float axisLineWidth = (value < 0 ? -1 : 1) * xAxis.axisLine.width;
|
||||
float pY = seriesHig[i] + zeroY + axisLineWidth;
|
||||
@@ -219,7 +219,7 @@ namespace XCharts
|
||||
if (isPercentStack)
|
||||
{
|
||||
valueTotal = GetSameStackTotalValue(serie.stack, i);
|
||||
barHig = valueTotal != 0 ? (value / valueTotal * coordinateHeight) : 0;
|
||||
barHig = valueTotal != 0 ? (value / valueTotal * m_CoordinateHeight) : 0;
|
||||
seriesHig[i] += barHig;
|
||||
}
|
||||
else
|
||||
@@ -227,7 +227,7 @@ namespace XCharts
|
||||
valueTotal = yMaxValue - yMinValue;
|
||||
if (valueTotal != 0)
|
||||
barHig = (yMinValue > 0 ? value - yMinValue : value)
|
||||
/ valueTotal * coordinateHeight;
|
||||
/ valueTotal * m_CoordinateHeight;
|
||||
seriesHig[i] += barHig;
|
||||
}
|
||||
float currHig = CheckAnimation(serie, i, barHig);
|
||||
@@ -436,15 +436,15 @@ namespace XCharts
|
||||
bool highlight, float pX, float pY, float space, float barWidth, bool isYAxis)
|
||||
{
|
||||
Color color = SerieHelper.GetItemBackgroundColor(serie, serieData, m_ThemeInfo, colorIndex, highlight, false);
|
||||
if (color == Color.clear) return;
|
||||
if (ChartHelper.IsClearColor(color)) return;
|
||||
if (isYAxis)
|
||||
{
|
||||
var axis = m_YAxises[serie.axisIndex];
|
||||
var axisWidth = axis.axisLine.width;
|
||||
Vector3 plt = new Vector3(coordinateX + axisWidth, pY + space + barWidth);
|
||||
Vector3 prt = new Vector3(coordinateX + axisWidth + coordinateWidth, pY + space + barWidth);
|
||||
Vector3 prb = new Vector3(coordinateX + axisWidth + coordinateWidth, pY + space);
|
||||
Vector3 plb = new Vector3(coordinateX + axisWidth, pY + space);
|
||||
Vector3 plt = new Vector3(m_CoordinateX + axisWidth, pY + space + barWidth);
|
||||
Vector3 prt = new Vector3(m_CoordinateX + axisWidth + m_CoordinateWidth, pY + space + barWidth);
|
||||
Vector3 prb = new Vector3(m_CoordinateX + axisWidth + m_CoordinateWidth, pY + space);
|
||||
Vector3 plb = new Vector3(m_CoordinateX + axisWidth, pY + space);
|
||||
if (serie.barType == BarType.Capsule)
|
||||
{
|
||||
var radius = barWidth / 2;
|
||||
@@ -480,10 +480,10 @@ namespace XCharts
|
||||
{
|
||||
var axis = m_XAxises[serie.axisIndex];
|
||||
var axisWidth = axis.axisLine.width;
|
||||
Vector3 plb = new Vector3(pX + space, coordinateY + axisWidth);
|
||||
Vector3 plt = new Vector3(pX + space, coordinateY + coordinateHeight + axisWidth);
|
||||
Vector3 prt = new Vector3(pX + space + barWidth, coordinateY + coordinateHeight + axisWidth);
|
||||
Vector3 prb = new Vector3(pX + space + barWidth, coordinateY + axisWidth);
|
||||
Vector3 plb = new Vector3(pX + space, m_CoordinateY + axisWidth);
|
||||
Vector3 plt = new Vector3(pX + space, m_CoordinateY + m_CoordinateHeight + axisWidth);
|
||||
Vector3 prt = new Vector3(pX + space + barWidth, m_CoordinateY + m_CoordinateHeight + axisWidth);
|
||||
Vector3 prb = new Vector3(pX + space + barWidth, m_CoordinateY + axisWidth);
|
||||
if (serie.barType == BarType.Capsule)
|
||||
{
|
||||
var radius = barWidth / 2;
|
||||
|
||||
@@ -121,11 +121,11 @@ namespace XCharts
|
||||
var xAxis = m_XAxises[serie.axisIndex];
|
||||
var xCount = xAxis.data.Count;
|
||||
var yCount = yAxis.data.Count;
|
||||
var xWidth = coordinateWidth / xCount;
|
||||
var yWidth = coordinateHeight / yCount;
|
||||
var xWidth = m_CoordinateWidth / xCount;
|
||||
var yWidth = m_CoordinateHeight / yCount;
|
||||
|
||||
var zeroX = coordinateX;
|
||||
var zeroY = coordinateY;
|
||||
var zeroX = m_CoordinateX;
|
||||
var zeroY = m_CoordinateY;
|
||||
var dataList = serie.GetDataList();
|
||||
var rangeMin = m_VisualMap.rangeMin;
|
||||
var rangeMax = m_VisualMap.rangeMax;
|
||||
@@ -175,7 +175,7 @@ namespace XCharts
|
||||
var rectWid = xWidth - 2 * borderWidth;
|
||||
var rectHig = yWidth - 2 * borderWidth;
|
||||
ChartDrawer.DrawPolygon(vh, pos, rectWid / 2, rectHig / 2, color);
|
||||
if (borderWidth > 0 && borderColor != Color.clear)
|
||||
if (borderWidth > 0 && !ChartHelper.IsClearColor(borderColor))
|
||||
{
|
||||
ChartDrawer.DrawBorder(vh, pos, rectWid, rectHig, borderWidth, borderColor);
|
||||
}
|
||||
|
||||
@@ -21,6 +21,7 @@ namespace XCharts
|
||||
for (int n = 0; n < m_Series.Count; n++)
|
||||
{
|
||||
var serie = m_Series.GetSerie(n);
|
||||
if (serie.IsPerformanceMode()) continue;
|
||||
if (serie.type != SerieType.Line) continue;
|
||||
if (!serie.show || serie.symbol.type == SerieSymbolType.None) continue;
|
||||
var count = serie.dataPoints.Count;
|
||||
@@ -96,11 +97,11 @@ namespace XCharts
|
||||
Vector3 lp = Vector3.zero, np = Vector3.zero, llp = Vector3.zero, nnp = Vector3.zero;
|
||||
var yAxis = m_YAxises[serie.axisIndex];
|
||||
var xAxis = m_XAxises[serie.axisIndex];
|
||||
var zeroPos = new Vector3(coordinateX, coordinateY + yAxis.runtimeZeroYOffset);
|
||||
var zeroPos = new Vector3(m_CoordinateX, m_CoordinateY + yAxis.runtimeZeroYOffset);
|
||||
var isStack = m_Series.IsStack(serie.stack, SerieType.Line);
|
||||
if (!xAxis.show) xAxis = m_XAxises[(serie.axisIndex + 1) % m_XAxises.Count];
|
||||
float scaleWid = xAxis.GetDataWidth(coordinateWidth, showData.Count, m_DataZoom);
|
||||
float startX = coordinateX + (xAxis.boundaryGap ? scaleWid / 2 : 0);
|
||||
float scaleWid = xAxis.GetDataWidth(m_CoordinateWidth, showData.Count, m_DataZoom);
|
||||
float startX = m_CoordinateX + (xAxis.boundaryGap ? scaleWid / 2 : 0);
|
||||
int maxCount = serie.maxShow > 0 ?
|
||||
(serie.maxShow > showData.Count ? showData.Count : serie.maxShow)
|
||||
: showData.Count;
|
||||
@@ -114,7 +115,7 @@ namespace XCharts
|
||||
}
|
||||
int rate = 1;
|
||||
var sampleDist = serie.sampleDist;
|
||||
if (sampleDist > 0) rate = (int)((maxCount - serie.minShow) / (coordinateWidth / sampleDist));
|
||||
if (sampleDist > 0) rate = (int)((maxCount - serie.minShow) / (m_CoordinateWidth / sampleDist));
|
||||
if (rate < 1) rate = 1;
|
||||
var includeLastData = false;
|
||||
var totalAverage = serie.sampleAverage > 0 ? serie.sampleAverage :
|
||||
@@ -421,46 +422,46 @@ namespace XCharts
|
||||
if (xAxis.IsValue() || xAxis.IsLog())
|
||||
{
|
||||
float xValue = i > showData.Count - 1 ? 0 : showData[i].GetData(0, xAxis.inverse);
|
||||
float pX = coordinateX + xAxis.axisLine.width;
|
||||
float pY = serieHig + coordinateY + xAxis.axisLine.width;
|
||||
float pX = m_CoordinateX + xAxis.axisLine.width;
|
||||
float pY = serieHig + m_CoordinateY + xAxis.axisLine.width;
|
||||
if (xAxis.IsLog())
|
||||
{
|
||||
int minIndex = xAxis.runtimeMinLogIndex;
|
||||
float nowIndex = xAxis.GetLogValue(xValue);
|
||||
xDataHig = (nowIndex - minIndex) / (xAxis.splitNumber - 1) * coordinateWidth;
|
||||
xDataHig = (nowIndex - minIndex) / (xAxis.splitNumber - 1) * m_CoordinateWidth;
|
||||
}
|
||||
else
|
||||
{
|
||||
if ((xMaxValue - xMinValue) <= 0) xDataHig = 0;
|
||||
else xDataHig = (xValue - xMinValue) / (xMaxValue - xMinValue) * coordinateWidth;
|
||||
else xDataHig = (xValue - xMinValue) / (xMaxValue - xMinValue) * m_CoordinateWidth;
|
||||
}
|
||||
if (yAxis.IsLog())
|
||||
{
|
||||
int minIndex = yAxis.runtimeMinLogIndex;
|
||||
float nowIndex = yAxis.GetLogValue(yValue);
|
||||
yDataHig = (nowIndex - minIndex) / (yAxis.splitNumber - 1) * coordinateHeight;
|
||||
yDataHig = (nowIndex - minIndex) / (yAxis.splitNumber - 1) * m_CoordinateHeight;
|
||||
}
|
||||
else
|
||||
{
|
||||
if ((yMaxValue - yMinValue) <= 0) yDataHig = 0;
|
||||
else yDataHig = (yValue - yMinValue) / (yMaxValue - yMinValue) * coordinateHeight;
|
||||
else yDataHig = (yValue - yMinValue) / (yMaxValue - yMinValue) * m_CoordinateHeight;
|
||||
}
|
||||
np = new Vector3(pX + xDataHig, pY + yDataHig);
|
||||
}
|
||||
else
|
||||
{
|
||||
float pX = startX + i * scaleWid;
|
||||
float pY = serieHig + coordinateY + yAxis.axisLine.width;
|
||||
float pY = serieHig + m_CoordinateY + yAxis.axisLine.width;
|
||||
if (yAxis.IsLog())
|
||||
{
|
||||
int minIndex = yAxis.runtimeMinLogIndex;
|
||||
float nowIndex = yAxis.GetLogValue(yValue);
|
||||
yDataHig = (nowIndex - minIndex) / (yAxis.splitNumber - 1) * coordinateHeight;
|
||||
yDataHig = (nowIndex - minIndex) / (yAxis.splitNumber - 1) * m_CoordinateHeight;
|
||||
}
|
||||
else
|
||||
{
|
||||
if ((yMaxValue - yMinValue) <= 0) yDataHig = 0;
|
||||
else yDataHig = (yValue - yMinValue) / (yMaxValue - yMinValue) * coordinateHeight;
|
||||
else yDataHig = (yValue - yMinValue) / (yMaxValue - yMinValue) * m_CoordinateHeight;
|
||||
}
|
||||
np = new Vector3(pX, pY + yDataHig);
|
||||
}
|
||||
@@ -484,11 +485,11 @@ namespace XCharts
|
||||
Color areaColor, areaToColor;
|
||||
var xAxis = m_XAxises[serie.axisIndex];
|
||||
var yAxis = m_YAxises[serie.axisIndex];
|
||||
var zeroPos = new Vector3(coordinateX + xAxis.runtimeZeroXOffset, coordinateY);
|
||||
var zeroPos = new Vector3(m_CoordinateX + xAxis.runtimeZeroXOffset, m_CoordinateY);
|
||||
var isStack = m_Series.IsStack(serie.stack, SerieType.Line);
|
||||
if (!yAxis.show) yAxis = m_YAxises[(serie.axisIndex + 1) % m_YAxises.Count];
|
||||
float scaleWid = yAxis.GetDataWidth(coordinateHeight, showData.Count, m_DataZoom);
|
||||
float startY = coordinateY + (yAxis.boundaryGap ? scaleWid / 2 : 0);
|
||||
float scaleWid = yAxis.GetDataWidth(m_CoordinateHeight, showData.Count, m_DataZoom);
|
||||
float startY = m_CoordinateY + (yAxis.boundaryGap ? scaleWid / 2 : 0);
|
||||
int maxCount = serie.maxShow > 0 ?
|
||||
(serie.maxShow > showData.Count ? showData.Count : serie.maxShow)
|
||||
: showData.Count;
|
||||
@@ -502,7 +503,7 @@ namespace XCharts
|
||||
}
|
||||
int rate = 1;
|
||||
var sampleDist = serie.sampleDist;
|
||||
if (sampleDist > 0) rate = (int)((maxCount - serie.minShow) / (coordinateWidth / sampleDist));
|
||||
if (sampleDist > 0) rate = (int)((maxCount - serie.minShow) / (m_CoordinateWidth / sampleDist));
|
||||
if (rate < 1) rate = 1;
|
||||
var dataChanging = false;
|
||||
float dataChangeDuration = serie.animation.GetUpdateAnimationDuration();
|
||||
@@ -516,17 +517,17 @@ namespace XCharts
|
||||
}
|
||||
float value = showData[i].GetCurrData(1, dataChangeDuration, xAxis.inverse);
|
||||
float pY = startY + i * scaleWid;
|
||||
float pX = seriesHig[i] + coordinateX + yAxis.axisLine.width;
|
||||
float pX = seriesHig[i] + m_CoordinateX + yAxis.axisLine.width;
|
||||
float dataHig = 0;
|
||||
if (xAxis.IsLog())
|
||||
{
|
||||
int minIndex = xAxis.runtimeMinLogIndex;
|
||||
float nowIndex = xAxis.GetLogValue(value);
|
||||
dataHig = (nowIndex - minIndex) / (xAxis.splitNumber - 1) * coordinateWidth;
|
||||
dataHig = (nowIndex - minIndex) / (xAxis.splitNumber - 1) * m_CoordinateWidth;
|
||||
}
|
||||
else
|
||||
{
|
||||
dataHig = (value - xMinValue) / (xMaxValue - xMinValue) * coordinateWidth;
|
||||
dataHig = (value - xMinValue) / (xMaxValue - xMinValue) * m_CoordinateWidth;
|
||||
}
|
||||
np = new Vector3(pX + dataHig, pY);
|
||||
serie.dataPoints.Add(np);
|
||||
@@ -543,17 +544,17 @@ namespace XCharts
|
||||
seriesHig.Add(0);
|
||||
float value = showData[i].GetCurrData(1, dataChangeDuration, xAxis.inverse);
|
||||
float pY = startY + i * scaleWid;
|
||||
float pX = seriesHig[i] + coordinateX + yAxis.axisLine.width;
|
||||
float pX = seriesHig[i] + m_CoordinateX + yAxis.axisLine.width;
|
||||
float dataHig = 0;
|
||||
if (xAxis.IsLog())
|
||||
{
|
||||
int minIndex = xAxis.runtimeMinLogIndex;
|
||||
float nowIndex = xAxis.GetLogValue(value);
|
||||
dataHig = (nowIndex - minIndex) / (xAxis.splitNumber - 1) * coordinateWidth;
|
||||
dataHig = (nowIndex - minIndex) / (xAxis.splitNumber - 1) * m_CoordinateWidth;
|
||||
}
|
||||
else
|
||||
{
|
||||
dataHig = (value - xMinValue) / (xMaxValue - xMinValue) * coordinateWidth;
|
||||
dataHig = (value - xMinValue) / (xMaxValue - xMinValue) * m_CoordinateWidth;
|
||||
}
|
||||
np = new Vector3(pX + dataHig, pY);
|
||||
serie.dataPoints.Add(np);
|
||||
@@ -848,7 +849,7 @@ namespace XCharts
|
||||
else
|
||||
{
|
||||
var points = ((isYAxis && lp.x < zeroPos.x) || (!isYAxis && lp.y < zeroPos.y)) ? smoothPoints : smoothDownPoints;
|
||||
Vector3 aep = isYAxis ? new Vector3(zeroPos.x, zeroPos.y + coordinateHeight) : new Vector3(zeroPos.x + coordinateWidth, zeroPos.y);
|
||||
Vector3 aep = isYAxis ? new Vector3(zeroPos.x, zeroPos.y + m_CoordinateHeight) : new Vector3(zeroPos.x + m_CoordinateWidth, zeroPos.y);
|
||||
var sindex = 0;
|
||||
var eindex = 0;
|
||||
var sp = GetStartPos(points, ref sindex);
|
||||
@@ -870,9 +871,9 @@ namespace XCharts
|
||||
var sp1 = smoothDownPoints[1];
|
||||
var ep1 = smoothDownPoints[smoothDownPoints.Count - 2];
|
||||
var axisUpStart = zeroPos + (isYAxis ? Vector3.right : Vector3.up) * axis.axisLine.width;
|
||||
var axisUpEnd = axisUpStart + (isYAxis ? Vector3.up * coordinateHeight : Vector3.right * coordinateWidth);
|
||||
var axisUpEnd = axisUpStart + (isYAxis ? Vector3.up * m_CoordinateHeight : Vector3.right * m_CoordinateWidth);
|
||||
var axisDownStart = zeroPos - (isYAxis ? Vector3.right : Vector3.up) * axis.axisLine.width;
|
||||
var axisDownEnd = axisDownStart + (isYAxis ? Vector3.up * coordinateHeight : Vector3.right * coordinateWidth);
|
||||
var axisDownEnd = axisDownStart + (isYAxis ? Vector3.up * m_CoordinateHeight : Vector3.right * m_CoordinateWidth);
|
||||
var luPos = ChartHelper.GetIntersection(sp1, ep1, axisUpStart, axisUpEnd);
|
||||
var ldPos = ChartHelper.GetIntersection(sp1, ep1, axisDownStart, axisDownEnd);
|
||||
sp1 = smoothPoints[1];
|
||||
|
||||
@@ -36,10 +36,10 @@ namespace XCharts
|
||||
float xValue = serieData.GetCurrData(0, dataChangeDuration, xAxis.inverse);
|
||||
float yValue = serieData.GetCurrData(1, dataChangeDuration, yAxis.inverse);
|
||||
if (serieData.IsDataChanged()) dataChanging = true;
|
||||
float pX = coordinateX + xAxis.axisLine.width;
|
||||
float pY = coordinateY + yAxis.axisLine.width;
|
||||
float xDataHig = (xValue - xAxis.runtimeMinValue) / (xAxis.runtimeMaxValue - xAxis.runtimeMinValue) * coordinateWidth;
|
||||
float yDataHig = (yValue - yAxis.runtimeMinValue) / (yAxis.runtimeMaxValue - yAxis.runtimeMinValue) * coordinateHeight;
|
||||
float pX = m_CoordinateX + xAxis.axisLine.width;
|
||||
float pY = m_CoordinateY + yAxis.axisLine.width;
|
||||
float xDataHig = (xValue - xAxis.runtimeMinValue) / (xAxis.runtimeMaxValue - xAxis.runtimeMinValue) * m_CoordinateWidth;
|
||||
float yDataHig = (yValue - yAxis.runtimeMinValue) / (yAxis.runtimeMaxValue - yAxis.runtimeMinValue) * m_CoordinateHeight;
|
||||
var pos = new Vector3(pX + xDataHig, pY + yDataHig);
|
||||
serie.dataPoints.Add(pos);
|
||||
serieData.runtimePosition = pos;
|
||||
|
||||
@@ -1,96 +0,0 @@
|
||||
/******************************************/
|
||||
/* */
|
||||
/* Copyright (c) 2018 monitor1394 */
|
||||
/* https://github.com/monitor1394 */
|
||||
/* */
|
||||
/******************************************/
|
||||
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace XCharts
|
||||
{
|
||||
public class LabelObject
|
||||
{
|
||||
private GameObject m_GameObject;
|
||||
private bool m_LabelAutoSize = true;
|
||||
private float m_LabelPaddingLeftRight = 3f;
|
||||
private float m_LabelPaddingTopBottom = 3f;
|
||||
private Text m_LabelText;
|
||||
private RectTransform m_LabelRect;
|
||||
private Image m_IconImage;
|
||||
// private RectTransform m_IconRect;
|
||||
|
||||
public Image icon { get { return m_IconImage; } }
|
||||
public Text label { get { return m_LabelText; } }
|
||||
|
||||
public LabelObject()
|
||||
{
|
||||
}
|
||||
|
||||
public void SetLabel(GameObject labelObj, bool autoSize, float paddingLeftRight, float paddingTopBottom)
|
||||
{
|
||||
m_GameObject = labelObj;
|
||||
m_LabelAutoSize = autoSize;
|
||||
m_LabelPaddingLeftRight = paddingLeftRight;
|
||||
m_LabelPaddingTopBottom = paddingTopBottom;
|
||||
m_LabelText = labelObj.GetComponentInChildren<Text>();
|
||||
m_LabelRect = m_LabelText.GetComponent<RectTransform>();
|
||||
}
|
||||
|
||||
public void SetIcon(Image image)
|
||||
{
|
||||
m_IconImage = image;
|
||||
if (image != null)
|
||||
{
|
||||
// m_IconRect = m_IconImage.GetComponent<RectTransform>();
|
||||
}
|
||||
}
|
||||
|
||||
public void SetIconSprite(Sprite sprite)
|
||||
{
|
||||
if (m_IconImage != null) m_IconImage.sprite = sprite;
|
||||
}
|
||||
|
||||
public void SetIconSize(float width, float height)
|
||||
{
|
||||
if (m_LabelRect != null) m_LabelRect.sizeDelta = new Vector3(width, height);
|
||||
}
|
||||
|
||||
public void SetIconActive(bool flag)
|
||||
{
|
||||
ChartHelper.SetActive(m_IconImage, flag);
|
||||
}
|
||||
|
||||
public void SetPosition(Vector3 position)
|
||||
{
|
||||
if (m_GameObject != null)
|
||||
{
|
||||
m_GameObject.transform.localPosition = position;
|
||||
}
|
||||
}
|
||||
|
||||
public void SetActive(bool flag)
|
||||
{
|
||||
ChartHelper.SetActive(m_GameObject, flag);
|
||||
}
|
||||
|
||||
public bool SetText(string text)
|
||||
{
|
||||
if (m_LabelText && !m_LabelText.text.Equals(text))
|
||||
{
|
||||
m_LabelText.text = text;
|
||||
if (m_LabelAutoSize)
|
||||
{
|
||||
var newSize = string.IsNullOrEmpty(text) ? Vector2.zero :
|
||||
new Vector2(m_LabelText.preferredWidth + m_LabelPaddingLeftRight * 2,
|
||||
m_LabelText.preferredHeight + m_LabelPaddingTopBottom * 2);
|
||||
var sizeChange = newSize.x != m_LabelRect.sizeDelta.x || newSize.y != m_LabelRect.sizeDelta.y;
|
||||
if (sizeChange) m_LabelRect.sizeDelta = newSize;
|
||||
return sizeChange;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f4e7ef04b9a0e4526b49bf63967cfef4
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -6,13 +6,24 @@
|
||||
/******************************************/
|
||||
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace XCharts
|
||||
{
|
||||
internal static class ListPool<T>
|
||||
{
|
||||
private static readonly ObjectPool<List<T>> s_ListPool = new ObjectPool<List<T>>(null, Clear);
|
||||
static void Clear(List<T> l) { l.Clear(); }
|
||||
private static readonly ObjectPool<List<T>> s_ListPool = new ObjectPool<List<T>>(OnGet, OnClear);
|
||||
static void OnGet(List<T> l)
|
||||
{
|
||||
if (l.Capacity < 50)
|
||||
{
|
||||
l.Capacity = 50;
|
||||
}
|
||||
}
|
||||
static void OnClear(List<T> l)
|
||||
{
|
||||
l.Clear();
|
||||
}
|
||||
|
||||
public static List<T> Get()
|
||||
{
|
||||
@@ -23,5 +34,10 @@ namespace XCharts
|
||||
{
|
||||
s_ListPool.Release(toRelease);
|
||||
}
|
||||
|
||||
public static void ClearAll()
|
||||
{
|
||||
s_ListPool.ClearAll();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -52,5 +52,10 @@ namespace XCharts
|
||||
m_ActionOnRelease(element);
|
||||
m_Stack.Push(element);
|
||||
}
|
||||
|
||||
public void ClearAll()
|
||||
{
|
||||
m_Stack.Clear();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,6 +5,8 @@
|
||||
/* */
|
||||
/******************************************/
|
||||
|
||||
using UnityEngine;
|
||||
|
||||
namespace XCharts
|
||||
{
|
||||
internal static class SerieDataPool
|
||||
|
||||
@@ -57,6 +57,7 @@ namespace XCharts
|
||||
|
||||
public static void Release(GameObject element)
|
||||
{
|
||||
if (element == null) return;
|
||||
ChartHelper.SetActive(element, false);
|
||||
if (!Application.isPlaying) return;
|
||||
if (!m_ReleaseDic.ContainsKey(element.GetInstanceID()))
|
||||
|
||||
Reference in New Issue
Block a user