增加双坐标轴支持

This commit is contained in:
monitor1394
2019-07-13 16:38:38 +08:00
parent d3f7980a6d
commit aff1b21bd3
41 changed files with 59457 additions and 1452 deletions

View File

@@ -29,15 +29,10 @@ namespace XCharts
protected override void DrawChart(VertexHelper vh)
{
base.DrawChart(vh);
if (m_YAxis.type == Axis.AxisType.Category)
if (m_YAxises[0].type == Axis.AxisType.Category)
{
var stackSeries = m_Series.GetStackSeries();
int seriesCount = stackSeries.Count;
float scaleWid = m_YAxis.GetDataWidth(coordinateHig, m_DataZoom);
float barWid = m_Bar.barWidth > 1 ? m_Bar.barWidth : scaleWid * m_Bar.barWidth;
float offset = m_Bar.inSameBar ?
(scaleWid - barWid - m_Bar.space * (seriesCount - 1)) / 2 :
(scaleWid - barWid * seriesCount - m_Bar.space * (seriesCount - 1)) / 2;
int serieCount = 0;
for (int j = 0; j < seriesCount; j++)
{
@@ -48,6 +43,14 @@ namespace XCharts
Serie serie = serieList[n];
if (!m_Legend.IsActive(serie.name)) continue;
Color color = m_ThemeInfo.GetColor(serieCount);
var xAxis = m_XAxises[serie.axisIndex];
var yAxis = m_YAxises[serie.axisIndex];
if (!yAxis.show) yAxis = m_YAxises[(serie.axisIndex + 1) % m_YAxises.Count];
float scaleWid = yAxis.GetDataWidth(coordinateHig, m_DataZoom);
float barWid = m_Bar.barWidth > 1 ? m_Bar.barWidth : scaleWid * m_Bar.barWidth;
float offset = m_Bar.inSameBar ?
(scaleWid - barWid - m_Bar.space * (seriesCount - 1)) / 2 :
(scaleWid - barWid * seriesCount - m_Bar.space * (seriesCount - 1)) / 2;
int maxCount = maxShowDataNumber > 0 ?
(maxShowDataNumber > serie.data.Count ? serie.data.Count : maxShowDataNumber)
: serie.data.Count;
@@ -58,11 +61,11 @@ namespace XCharts
seriesCurrHig[i] = 0;
}
float value = serie.data[i];
float pX = seriesCurrHig[i] + zeroX + m_Coordinate.tickness;
float pY = coordinateY + i * scaleWid;
if (!m_YAxis.boundaryGap) pY -= scaleWid / 2;
float barHig = (minValue > 0 ? value - minValue : value)
/ (maxValue - minValue) * coordinateWid;
float pX = seriesCurrHig[i] + coordinateX + xAxis.zeroXOffset + m_Coordinate.tickness;
float pY = coordinateY + +i * scaleWid;
if (!yAxis.boundaryGap) pY -= scaleWid / 2;
float barHig = (xAxis.minValue > 0 ? value - xAxis.minValue : value)
/ (xAxis.maxValue - xAxis.minValue) * coordinateWid;
float space = m_Bar.inSameBar ? offset :
offset + j * (barWid + m_Bar.space);
seriesCurrHig[i] += barHig;
@@ -85,27 +88,38 @@ namespace XCharts
{
if (m_Tooltip.crossLabel)
{
Vector3 sp = new Vector2(m_Tooltip.pointerPos.x, zeroY);
Vector3 ep = new Vector2(m_Tooltip.pointerPos.x, zeroY + coordinateHig);
DrawSplitLine(vh, false, Axis.SplitLineType.Dashed, sp, ep, m_ThemeInfo.tooltipLineColor);
float splitWidth = m_YAxis.GetSplitWidth(coordinateHig, m_DataZoom);
float pY = zeroY + (m_Tooltip.dataIndex - 1) * splitWidth +
(m_YAxis.boundaryGap ? splitWidth / 2 : 0);
sp = new Vector2(coordinateX, pY);
ep = new Vector2(coordinateX + coordinateWid, pY);
DrawSplitLine(vh, true, Axis.SplitLineType.Dashed, sp, ep, m_ThemeInfo.tooltipLineColor);
for (int i = 0; i < m_YAxises.Count; i++)
{
var yAxis = m_YAxises[i];
if (!yAxis.show) continue;
Vector3 sp = new Vector2(m_Tooltip.pointerPos.x, coordinateY);
Vector3 ep = new Vector2(m_Tooltip.pointerPos.x, coordinateY + coordinateHig);
DrawSplitLine(vh, false, Axis.SplitLineType.Dashed, sp, ep, m_ThemeInfo.tooltipLineColor);
float splitWidth = yAxis.GetSplitWidth(coordinateHig, m_DataZoom);
float pY = zeroY + (m_Tooltip.yValues[i] - 1) * splitWidth +
(yAxis.boundaryGap ? splitWidth / 2 : 0);
sp = new Vector2(coordinateX, pY);
ep = new Vector2(coordinateX + coordinateWid, pY);
DrawSplitLine(vh, true, Axis.SplitLineType.Solid, sp, ep, m_ThemeInfo.tooltipLineColor);
}
}
else
{
float tooltipSplitWid = scaleWid < 1 ? 1 : scaleWid;
float pX = coordinateX + coordinateWid;
float pY = coordinateY + scaleWid * (m_Tooltip.dataIndex - 1) -
(m_YAxis.boundaryGap ? 0 : scaleWid / 2);
Vector3 p1 = new Vector3(coordinateX, pY);
Vector3 p2 = new Vector3(coordinateX, pY + tooltipSplitWid);
Vector3 p3 = new Vector3(pX, pY + tooltipSplitWid);
Vector3 p4 = new Vector3(pX, pY);
ChartHelper.DrawPolygon(vh, p1, p2, p3, p4, m_ThemeInfo.tooltipFlagAreaColor);
for (int i = 0; i < m_YAxises.Count; i++)
{
var yAxis = m_YAxises[i];
if (!yAxis.show) continue;
float splitWidth = yAxis.GetSplitWidth(coordinateHig, m_DataZoom);
float tooltipSplitWid = splitWidth < 1 ? 1 : splitWidth;
float pX = coordinateX + coordinateWid;
float pY = coordinateY + splitWidth * (m_Tooltip.yValues[i] - 1) -
(yAxis.boundaryGap ? 0 : splitWidth / 2);
Vector3 p1 = new Vector3(coordinateX, pY);
Vector3 p2 = new Vector3(coordinateX, pY + tooltipSplitWid);
Vector3 p3 = new Vector3(pX, pY + tooltipSplitWid);
Vector3 p4 = new Vector3(pX, pY);
ChartHelper.DrawPolygon(vh, p1, p2, p3, p4, m_ThemeInfo.tooltipFlagAreaColor);
}
}
}
}
@@ -113,11 +127,6 @@ namespace XCharts
{
var stackSeries = m_Series.GetStackSeries();
int seriesCount = stackSeries.Count;
float scaleWid = m_XAxis.GetDataWidth(coordinateWid, m_DataZoom);
float barWid = m_Bar.barWidth > 1 ? m_Bar.barWidth : scaleWid * m_Bar.barWidth;
float offset = m_Bar.inSameBar ?
(scaleWid - barWid - m_Bar.space * (seriesCount - 1)) / 2 :
(scaleWid - barWid * seriesCount - m_Bar.space * (seriesCount - 1)) / 2;
int serieCount = 0;
for (int j = 0; j < seriesCount; j++)
{
@@ -129,6 +138,14 @@ namespace XCharts
if (!m_Legend.IsActive(serie.name)) continue;
Color color = m_ThemeInfo.GetColor(serieCount);
List<float> showData = serie.GetData(m_DataZoom);
var yAxis = m_YAxises[serie.axisIndex];
var xAxis = m_XAxises[serie.axisIndex];
if (!xAxis.show) xAxis = m_XAxises[(serie.axisIndex + 1) % m_XAxises.Count];
float scaleWid = xAxis.GetDataWidth(coordinateWid, m_DataZoom);
float barWid = m_Bar.barWidth > 1 ? m_Bar.barWidth : scaleWid * m_Bar.barWidth;
float offset = m_Bar.inSameBar ?
(scaleWid - barWid - m_Bar.space * (seriesCount - 1)) / 2 :
(scaleWid - barWid * seriesCount - m_Bar.space * (seriesCount - 1)) / 2;
int maxCount = maxShowDataNumber > 0 ?
(maxShowDataNumber > showData.Count ? showData.Count : maxShowDataNumber)
: showData.Count;
@@ -140,10 +157,11 @@ namespace XCharts
}
float value = showData[i];
float pX = zeroX + i * scaleWid;
if (!m_XAxis.boundaryGap) pX -= scaleWid / 2;
float zeroY = coordinateY + yAxis.zeroYOffset;
if (!xAxis.boundaryGap) pX -= scaleWid / 2;
float pY = seriesCurrHig[i] + zeroY + m_Coordinate.tickness;
float barHig = (minValue > 0 ? value - minValue : value)
/ (maxValue - minValue) * coordinateHig;
float barHig = (yAxis.minValue > 0 ? value - yAxis.minValue : value)
/ (yAxis.maxValue - yAxis.minValue) * coordinateHig;
seriesCurrHig[i] += barHig;
float space = m_Bar.inSameBar ? offset :
offset + j * (barWid + m_Bar.space);
@@ -166,28 +184,39 @@ namespace XCharts
{
if (m_Tooltip.crossLabel)
{
Vector3 sp = new Vector2(zeroX, m_Tooltip.pointerPos.y);
Vector3 ep = new Vector2(zeroX + coordinateWid, m_Tooltip.pointerPos.y);
DrawSplitLine(vh, true, Axis.SplitLineType.Dashed, sp, ep, m_ThemeInfo.tooltipLineColor);
for (int i = 0; i < m_XAxises.Count; i++)
{
var xAxis = m_XAxises[i];
if (!xAxis.show) continue;
Vector3 sp = new Vector2(coordinateX, m_Tooltip.pointerPos.y);
Vector3 ep = new Vector2(coordinateX + coordinateWid, m_Tooltip.pointerPos.y);
DrawSplitLine(vh, true, Axis.SplitLineType.Dashed, sp, ep, m_ThemeInfo.tooltipLineColor);
float splitWidth = m_XAxis.GetSplitWidth(coordinateWid, m_DataZoom);
float px = zeroX + (m_Tooltip.dataIndex - 1) * splitWidth
+ (m_XAxis.boundaryGap ? splitWidth / 2 : 0);
sp = new Vector2(px, coordinateY);
ep = new Vector2(px, coordinateY + coordinateHig);
DrawSplitLine(vh, false, Axis.SplitLineType.Dashed, sp, ep, m_ThemeInfo.tooltipLineColor);
float splitWidth = xAxis.GetSplitWidth(coordinateWid, m_DataZoom);
float px = coordinateX + (m_Tooltip.xValues[i] - 1) * splitWidth
+ (xAxis.boundaryGap ? splitWidth / 2 : 0);
sp = new Vector2(px, coordinateY);
ep = new Vector2(px, coordinateY + coordinateHig);
DrawSplitLine(vh, false, Axis.SplitLineType.Solid, sp, ep, m_ThemeInfo.tooltipLineColor);
}
}
else
{
float tooltipSplitWid = scaleWid < 1 ? 1 : scaleWid;
float pX = coordinateX + scaleWid * (m_Tooltip.dataIndex - 1) -
(m_XAxis.boundaryGap ? 0 : scaleWid / 2);
float pY = coordinateY + coordinateHig;
Vector3 p1 = new Vector3(pX, coordinateY);
Vector3 p2 = new Vector3(pX, pY);
Vector3 p3 = new Vector3(pX + tooltipSplitWid, pY);
Vector3 p4 = new Vector3(pX + tooltipSplitWid, coordinateY);
ChartHelper.DrawPolygon(vh, p1, p2, p3, p4, m_ThemeInfo.tooltipFlagAreaColor);
for (int i = 0; i < m_XAxises.Count; i++)
{
var xAxis = m_XAxises[i];
if (!xAxis.show) continue;
float splitWidth = xAxis.GetSplitWidth(coordinateWid, m_DataZoom);
float tooltipSplitWid = splitWidth < 1 ? 1 : splitWidth;
float pX = coordinateX + splitWidth * (m_Tooltip.xValues[i] - 1) -
(xAxis.boundaryGap ? 0 : splitWidth / 2);
float pY = coordinateY + coordinateHig;
Vector3 p1 = new Vector3(pX, coordinateY);
Vector3 p2 = new Vector3(pX, pY);
Vector3 p3 = new Vector3(pX + tooltipSplitWid, pY);
Vector3 p4 = new Vector3(pX + tooltipSplitWid, coordinateY);
ChartHelper.DrawPolygon(vh, p1, p2, p3, p4, m_ThemeInfo.tooltipFlagAreaColor);
}
}
}
}

View File

@@ -1,6 +1,8 @@
using System;
using System.Net.Mime;
using System;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
namespace XCharts
{
@@ -30,268 +32,6 @@ namespace XCharts
Dotted
}
[System.Serializable]
public class AxisTick
{
[SerializeField] private bool m_Show;
[SerializeField] private bool m_AlignWithLabel;
[SerializeField] private bool m_Inside;
[SerializeField] private float m_Length;
public bool show { get { return m_Show; } set { m_Show = value; } }
public bool alignWithLabel { get { return m_AlignWithLabel; } set { m_AlignWithLabel = value; } }
public bool inside { get { return m_Inside; } set { m_Inside = value; } }
public float length { get { return m_Length; } set { m_Length = value; } }
public static AxisTick defaultTick
{
get
{
var tick = new AxisTick
{
m_Show = true,
m_AlignWithLabel = false,
m_Inside = false,
m_Length = 5f
};
return tick;
}
}
}
[System.Serializable]
public class AxisLine
{
[SerializeField] private bool m_Show;
[SerializeField] private bool m_Symbol;
[SerializeField] private float m_SymbolWidth;
[SerializeField] private float m_SymbolHeight;
[SerializeField] private float m_SymbolOffset;
[SerializeField] private float m_SymbolDent;
public bool show { get { return m_Show; } set { m_Show = value; } }
public bool symbol { get { return m_Symbol; } set { m_Symbol = value; } }
public float symbolWidth { get { return m_SymbolWidth; } set { m_SymbolWidth = value; } }
public float symbolHeight { get { return m_SymbolHeight; } set { m_SymbolHeight = value; } }
public float symbolOffset { get { return m_SymbolOffset; } set { m_SymbolOffset = value; } }
public float symbolDent { get { return m_SymbolDent; } set { m_SymbolDent = value; } }
public static AxisLine defaultAxisLine
{
get
{
var axisLine = new AxisLine
{
m_Show = true,
m_Symbol = false,
m_SymbolWidth = 10,
m_SymbolHeight = 15,
m_SymbolOffset = 0,
m_SymbolDent = 3,
};
return axisLine;
}
}
}
[Serializable]
public class AxisName
{
[Serializable]
public enum Location
{
Start,
Middle,
End
}
[SerializeField] private bool m_Show;
[SerializeField] private string m_Name;
[SerializeField] private Location m_Location;
[SerializeField] private float m_Gap;
[SerializeField] private float m_Rotate;
[SerializeField] private Color m_Color;
[SerializeField] private int m_FontSize;
[SerializeField] private FontStyle m_FontStyle;
public bool show { get { return m_Show; } set { m_Show = value; } }
public string name { get { return m_Name; } set { m_Name = value; } }
public Location location { get { return m_Location; } set { m_Location = value; } }
public float gap { get { return m_Gap; } set { m_Gap = value; } }
public float rotate { get { return m_Rotate; } set { m_Rotate = value; } }
public Color color { get { return m_Color; } set { m_Color = value; } }
public int fontSize { get { return m_FontSize; } set { m_FontSize = value; } }
public FontStyle fontStyle { get { return m_FontStyle; } set { m_FontStyle = value; } }
public static AxisName defaultAxisName
{
get
{
return new AxisName()
{
m_Show = false,
m_Name = "axisName",
m_Location = Location.End,
m_Gap = 5,
m_Rotate = 0,
m_Color = Color.clear,
m_FontSize = 18,
m_FontStyle = FontStyle.Normal
};
}
}
public void Copy(AxisName other)
{
m_Show = other.show;
m_Name = other.name;
m_Location = other.location;
m_Gap = other.gap;
m_Rotate = other.rotate;
m_Color = other.color;
m_FontSize = other.fontSize;
m_FontStyle = other.fontStyle;
}
public override bool Equals(object obj)
{
if (obj == null || GetType() != obj.GetType())
{
return false;
}
var other = (AxisName)obj;
return m_Show == other.show &&
m_Name.Equals(other.name) &&
m_Location == other.location &&
m_Gap == other.gap &&
m_Rotate == other.rotate &&
m_Color == other.color &&
m_FontSize == other.fontSize &&
m_FontStyle == other.fontStyle;
}
public override int GetHashCode()
{
return base.GetHashCode();
}
}
/// <summary>
/// Split area of axis in grid area, not shown by default.
/// </summary>
[Serializable]
public class SplitArea
{
[SerializeField] private bool m_Show;
[SerializeField] private List<Color> m_Color;
/// <summary>
/// Set this to true to show the splitArea.
/// </summary>
/// <value>false</value>
public bool show { get { return m_Show; } set { m_Show = value; } }
/// <summary>
/// Color of split area. SplitArea color could also be set in color array,
/// which the split lines would take as their colors in turns.
/// Dark and light colors in turns are used by default.
/// </summary>
/// <value>['rgba(250,250,250,0.3)','rgba(200,200,200,0.3)']</value>
public List<Color> color { get { return m_Color; } set { m_Color = value; } }
public static SplitArea defaultSplitArea
{
get
{
return new SplitArea()
{
m_Show = false,
m_Color = new List<Color>(){
new Color32(250,250,250,77),
new Color32(200,200,200,77)
}
};
}
}
public Color getColor(int index)
{
var i = index % color.Count;
return color[i];
}
}
[Serializable]
public class AxisLabel
{
[SerializeField] private bool m_Show;
[SerializeField] private int m_Interval;
[SerializeField] private bool m_Inside;
[SerializeField] private float m_Rotate;
[SerializeField] private float m_Margin;
[SerializeField] private Color m_Color;
[SerializeField] private int m_FontSize;
[SerializeField] private FontStyle m_FontStyle;
public bool show { get { return m_Show; } set { m_Show = value; } }
public int interval { get { return m_Interval; } set { m_Interval = value; } }
public bool inside { get { return m_Inside; } set { m_Inside = value; } }
public float rotate { get { return m_Rotate; } set { m_Rotate = value; } }
public float margin { get { return m_Margin; } set { m_Margin = value; } }
public Color color { get { return m_Color; } set { m_Color = value; } }
public int fontSize { get { return m_FontSize; } set { m_FontSize = value; } }
public FontStyle fontStyle { get { return m_FontStyle; } set { m_FontStyle = value; } }
public static AxisLabel defaultAxisLabel
{
get
{
return new AxisLabel()
{
m_Show = true,
m_Interval = 0,
m_Inside = false,
m_Rotate = 0,
m_Margin = 8,
m_Color = Color.clear,
m_FontSize = 18,
m_FontStyle = FontStyle.Normal
};
}
}
public void Copy(AxisLabel other)
{
m_Show = other.show;
m_Interval = other.interval;
m_Inside = other.inside;
m_Rotate = other.rotate;
m_Margin = other.margin;
m_Color = other.color;
m_FontSize = other.fontSize;
m_FontStyle = other.fontStyle;
}
public override bool Equals(object obj)
{
if (obj == null || GetType() != obj.GetType())
{
return false;
}
var other = (AxisLabel)obj;
return m_Show == other.show &&
m_Interval.Equals(other.interval) &&
m_Inside == other.inside &&
m_Rotate == other.rotate &&
m_Margin == other.margin &&
m_Color == other.color &&
m_FontSize == other.fontSize &&
m_FontStyle == other.fontStyle;
}
public override int GetHashCode()
{
return base.GetHashCode();
}
}
[SerializeField] protected bool m_Show = true;
[SerializeField] protected AxisType m_Type;
[SerializeField] protected AxisMinMaxType m_MinMaxType;
@@ -306,7 +46,7 @@ namespace XCharts
[SerializeField] protected AxisName m_AxisName = AxisName.defaultAxisName;
[SerializeField] protected AxisTick m_AxisTick = AxisTick.defaultTick;
[SerializeField] protected AxisLabel m_AxisLabel = AxisLabel.defaultAxisLabel;
[SerializeField] protected SplitArea m_SplitArea = SplitArea.defaultSplitArea;
[SerializeField] protected AxisSplitArea m_SplitArea = AxisSplitArea.defaultSplitArea;
public bool show { get { return m_Show; } set { m_Show = value; } }
public AxisType type { get { return m_Type; } set { m_Type = value; } }
@@ -323,12 +63,23 @@ namespace XCharts
public AxisName axisName { get { return m_AxisName; } set { m_AxisName = value; } }
public AxisTick axisTick { get { return m_AxisTick; } set { m_AxisTick = value; } }
public AxisLabel axisLabel { get { return m_AxisLabel; } set { m_AxisLabel = value; } }
public SplitArea splitArea { get { return m_SplitArea; } set { m_SplitArea = value; } }
public AxisSplitArea splitArea { get { return m_SplitArea; } set { m_SplitArea = value; } }
public int filterStart { get; set; }
public int filterEnd { get; set; }
public List<string> filterData { get; set; }
public float minValue { get; set; }
public float maxValue { get; set; }
public float zeroXOffset { get; set; }
public float zeroYOffset { get; set; }
private List<Text> m_AxisLabelTextList = new List<Text>();
public List<Text> axisLabelTextList { get { return m_AxisLabelTextList; } set { m_AxisLabelTextList = value; } }
private GameObject m_TooltipLabel;
private Text m_TooltipLabelText;
private RectTransform m_TooltipLabelRect;
public void Copy(Axis other)
{
m_Show = other.show;
@@ -351,6 +102,16 @@ namespace XCharts
m_Data.Clear();
}
public bool IsCategory()
{
return type == AxisType.Category;
}
public bool IsValue()
{
return type == AxisType.Value;
}
public void AddData(string category, int maxDataNumber)
{
if (maxDataNumber > 0)
@@ -494,6 +255,95 @@ namespace XCharts
return coordinateWidth / num;
}
public void UpdateLabelText(DataZoom dataZoom)
{
for (int i = 0; i < axisLabelTextList.Count; i++)
{
axisLabelTextList[i].text = GetScaleName(i, minValue, maxValue, dataZoom);
}
}
public void SetTooltipLabel(GameObject label)
{
m_TooltipLabel = label;
m_TooltipLabelRect = label.GetComponent<RectTransform>();
m_TooltipLabelText = label.GetComponentInChildren<Text>();
m_TooltipLabel.SetActive(true);
}
public void SetTooltipLabelColor(Color bgColor, Color textColor)
{
m_TooltipLabel.GetComponent<Image>().color = bgColor;
m_TooltipLabelText.color = textColor;
}
public void SetTooltipLabelActive(bool flag)
{
if (m_TooltipLabel && m_TooltipLabel.activeInHierarchy != flag)
{
m_TooltipLabel.SetActive(flag);
}
}
public void UpdateTooptipLabelText(string text)
{
if (m_TooltipLabelText)
{
m_TooltipLabelText.text = text;
m_TooltipLabelRect.sizeDelta = new Vector2(m_TooltipLabelText.preferredWidth + 8,
m_TooltipLabelText.preferredHeight + 8);
}
}
public void UpdateTooltipLabelPos(Vector2 pos)
{
if (m_TooltipLabel)
{
m_TooltipLabel.transform.localPosition = pos;
}
}
public void AdjustMinMaxValue(int minValue, int maxValue, out int tempMinValue, out int tempMaxValue)
{
tempMinValue = minValue;
tempMaxValue = maxValue;
if (minMaxType == Axis.AxisMinMaxType.Custom)
{
if (min != 0 || max != 0)
{
tempMinValue = min;
tempMaxValue = max;
}
}
else
{
switch (minMaxType)
{
case Axis.AxisMinMaxType.Default:
if (minValue > 0 && maxValue > 0)
{
tempMinValue = 0;
tempMaxValue = ChartHelper.GetMaxDivisibleValue(maxValue);
}
else if (minValue < 0 && maxValue < 0)
{
tempMinValue = ChartHelper.GetMinDivisibleValue(minValue);
tempMaxValue = 0;
}
else
{
tempMinValue = ChartHelper.GetMinDivisibleValue(minValue);
tempMaxValue = ChartHelper.GetMaxDivisibleValue(maxValue);
}
break;
case Axis.AxisMinMaxType.MinMax:
tempMinValue = ChartHelper.GetMinDivisibleValue(minValue);
tempMaxValue = ChartHelper.GetMaxDivisibleValue(maxValue);
break;
}
}
}
public override bool Equals(object obj)
{
if (ReferenceEquals(null, obj))
@@ -562,6 +412,26 @@ namespace XCharts
[System.Serializable]
public class XAxis : Axis
{
public XAxis Clone()
{
var axis = new XAxis();
axis.show = show;
axis.type = type;
axis.min = min;
axis.max = max;
axis.splitNumber = splitNumber;
axis.showSplitLine = showSplitLine;
axis.splitLineType = splitLineType;
axis.boundaryGap = boundaryGap;
axis.axisName.Copy(axisName);
axis.axisLabel.Copy(axisLabel);
axis.data.Clear();
foreach (var d in data) axis.data.Add(d);
return axis;
}
public static XAxis defaultXAxis
{
get
@@ -589,6 +459,25 @@ namespace XCharts
[System.Serializable]
public class YAxis : Axis
{
public YAxis Clone()
{
var axis = new YAxis();
axis.show = show;
axis.type = type;
axis.min = min;
axis.max = max;
axis.splitNumber = splitNumber;
axis.showSplitLine = showSplitLine;
axis.splitLineType = splitLineType;
axis.boundaryGap = boundaryGap;
axis.axisName.Copy(axisName);
axis.axisLabel.Copy(axisLabel);
axis.data.Clear();
foreach (var d in data) axis.data.Add(d);
return axis;
}
public static YAxis defaultYAxis
{
get

View File

@@ -0,0 +1,78 @@
using System;
using UnityEngine;
namespace XCharts
{
[Serializable]
public class AxisLabel
{
[SerializeField] private bool m_Show;
[SerializeField] private int m_Interval;
[SerializeField] private bool m_Inside;
[SerializeField] private float m_Rotate;
[SerializeField] private float m_Margin;
[SerializeField] private Color m_Color;
[SerializeField] private int m_FontSize;
[SerializeField] private FontStyle m_FontStyle;
public bool show { get { return m_Show; } set { m_Show = value; } }
public int interval { get { return m_Interval; } set { m_Interval = value; } }
public bool inside { get { return m_Inside; } set { m_Inside = value; } }
public float rotate { get { return m_Rotate; } set { m_Rotate = value; } }
public float margin { get { return m_Margin; } set { m_Margin = value; } }
public Color color { get { return m_Color; } set { m_Color = value; } }
public int fontSize { get { return m_FontSize; } set { m_FontSize = value; } }
public FontStyle fontStyle { get { return m_FontStyle; } set { m_FontStyle = value; } }
public static AxisLabel defaultAxisLabel
{
get
{
return new AxisLabel()
{
m_Show = true,
m_Interval = 0,
m_Inside = false,
m_Rotate = 0,
m_Margin = 8,
m_Color = Color.clear,
m_FontSize = 18,
m_FontStyle = FontStyle.Normal
};
}
}
public void Copy(AxisLabel other)
{
m_Show = other.show;
m_Interval = other.interval;
m_Inside = other.inside;
m_Rotate = other.rotate;
m_Margin = other.margin;
m_Color = other.color;
m_FontSize = other.fontSize;
m_FontStyle = other.fontStyle;
}
public override bool Equals(object obj)
{
if (obj == null || GetType() != obj.GetType())
{
return false;
}
var other = (AxisLabel)obj;
return m_Show == other.show &&
m_Interval.Equals(other.interval) &&
m_Inside == other.inside &&
m_Rotate == other.rotate &&
m_Margin == other.margin &&
m_Color == other.color &&
m_FontSize == other.fontSize &&
m_FontStyle == other.fontStyle;
}
public override int GetHashCode()
{
return base.GetHashCode();
}
}
}

View File

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

View File

@@ -0,0 +1,39 @@
using UnityEngine;
namespace XCharts
{
[System.Serializable]
public class AxisLine
{
[SerializeField] private bool m_Show;
[SerializeField] private bool m_Symbol;
[SerializeField] private float m_SymbolWidth;
[SerializeField] private float m_SymbolHeight;
[SerializeField] private float m_SymbolOffset;
[SerializeField] private float m_SymbolDent;
public bool show { get { return m_Show; } set { m_Show = value; } }
public bool symbol { get { return m_Symbol; } set { m_Symbol = value; } }
public float symbolWidth { get { return m_SymbolWidth; } set { m_SymbolWidth = value; } }
public float symbolHeight { get { return m_SymbolHeight; } set { m_SymbolHeight = value; } }
public float symbolOffset { get { return m_SymbolOffset; } set { m_SymbolOffset = value; } }
public float symbolDent { get { return m_SymbolDent; } set { m_SymbolDent = value; } }
public static AxisLine defaultAxisLine
{
get
{
var axisLine = new AxisLine
{
m_Show = true,
m_Symbol = false,
m_SymbolWidth = 10,
m_SymbolHeight = 15,
m_SymbolOffset = 0,
m_SymbolDent = 3,
};
return axisLine;
}
}
}
}

View File

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

View File

@@ -0,0 +1,86 @@
using System;
using UnityEngine;
namespace XCharts
{
[Serializable]
public class AxisName
{
[Serializable]
public enum Location
{
Start,
Middle,
End
}
[SerializeField] private bool m_Show;
[SerializeField] private string m_Name;
[SerializeField] private Location m_Location;
[SerializeField] private float m_Gap;
[SerializeField] private float m_Rotate;
[SerializeField] private Color m_Color;
[SerializeField] private int m_FontSize;
[SerializeField] private FontStyle m_FontStyle;
public bool show { get { return m_Show; } set { m_Show = value; } }
public string name { get { return m_Name; } set { m_Name = value; } }
public Location location { get { return m_Location; } set { m_Location = value; } }
public float gap { get { return m_Gap; } set { m_Gap = value; } }
public float rotate { get { return m_Rotate; } set { m_Rotate = value; } }
public Color color { get { return m_Color; } set { m_Color = value; } }
public int fontSize { get { return m_FontSize; } set { m_FontSize = value; } }
public FontStyle fontStyle { get { return m_FontStyle; } set { m_FontStyle = value; } }
public static AxisName defaultAxisName
{
get
{
return new AxisName()
{
m_Show = false,
m_Name = "axisName",
m_Location = Location.End,
m_Gap = 5,
m_Rotate = 0,
m_Color = Color.clear,
m_FontSize = 18,
m_FontStyle = FontStyle.Normal
};
}
}
public void Copy(AxisName other)
{
m_Show = other.show;
m_Name = other.name;
m_Location = other.location;
m_Gap = other.gap;
m_Rotate = other.rotate;
m_Color = other.color;
m_FontSize = other.fontSize;
m_FontStyle = other.fontStyle;
}
public override bool Equals(object obj)
{
if (obj == null || GetType() != obj.GetType())
{
return false;
}
var other = (AxisName)obj;
return m_Show == other.show &&
m_Name.Equals(other.name) &&
m_Location == other.location &&
m_Gap == other.gap &&
m_Rotate == other.rotate &&
m_Color == other.color &&
m_FontSize == other.fontSize &&
m_FontStyle == other.fontStyle;
}
public override int GetHashCode()
{
return base.GetHashCode();
}
}
}

View File

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

View File

@@ -0,0 +1,50 @@
using System;
using System.Collections.Generic;
using UnityEngine;
namespace XCharts
{
/// <summary>
/// Split area of axis in grid area, not shown by default.
/// </summary>
[Serializable]
public class AxisSplitArea
{
[SerializeField] private bool m_Show;
[SerializeField] private List<Color> m_Color;
/// <summary>
/// Set this to true to show the splitArea.
/// </summary>
/// <value>false</value>
public bool show { get { return m_Show; } set { m_Show = value; } }
/// <summary>
/// Color of split area. SplitArea color could also be set in color array,
/// which the split lines would take as their colors in turns.
/// Dark and light colors in turns are used by default.
/// </summary>
/// <value>['rgba(250,250,250,0.3)','rgba(200,200,200,0.3)']</value>
public List<Color> color { get { return m_Color; } set { m_Color = value; } }
public static AxisSplitArea defaultSplitArea
{
get
{
return new AxisSplitArea()
{
m_Show = false,
m_Color = new List<Color>(){
new Color32(250,250,250,77),
new Color32(200,200,200,77)
}
};
}
}
public Color getColor(int index)
{
var i = index % color.Count;
return color[i];
}
}
}

View File

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

View File

@@ -0,0 +1,34 @@
using UnityEngine;
namespace XCharts
{
[System.Serializable]
public class AxisTick
{
[SerializeField] private bool m_Show;
[SerializeField] private bool m_AlignWithLabel;
[SerializeField] private bool m_Inside;
[SerializeField] private float m_Length;
public bool show { get { return m_Show; } set { m_Show = value; } }
public bool alignWithLabel { get { return m_AlignWithLabel; } set { m_AlignWithLabel = value; } }
public bool inside { get { return m_Inside; } set { m_Inside = value; } }
public float length { get { return m_Length; } set { m_Length = value; } }
public static AxisTick defaultTick
{
get
{
var tick = new AxisTick
{
m_Show = true,
m_AlignWithLabel = false,
m_Inside = false,
m_Length = 5f
};
return tick;
}
}
}
}

View File

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

View File

@@ -24,7 +24,7 @@ namespace XCharts
[SerializeField] protected Title m_Title = Title.defaultTitle;
[SerializeField] protected Legend m_Legend = Legend.defaultLegend;
[SerializeField] protected Tooltip m_Tooltip = Tooltip.defaultTooltip;
[SerializeField] protected Series m_Series;
[SerializeField] protected Series m_Series = Series.defaultSeries;
[SerializeField] protected bool m_Large;
[SerializeField] protected int m_MinShowDataNumber;
@@ -264,15 +264,10 @@ namespace XCharts
var parent = tooltipObject.transform;
ChartHelper.HideAllObject(tooltipObject.transform);
GameObject content = ChartHelper.AddTooltipContent("content", parent, m_ThemeInfo.font);
GameObject labelX = ChartHelper.AddTooltipLabel("label_x", parent, m_ThemeInfo.font, new Vector2(0.5f, 1));
GameObject labelY = ChartHelper.AddTooltipLabel("label_y", parent, m_ThemeInfo.font, new Vector2(1, 0.5f));
m_Tooltip.SetObj(tooltipObject);
m_Tooltip.SetContentObj(content);
m_Tooltip.SetLabelObj(labelX, labelY);
m_Tooltip.SetContentBackgroundColor(m_ThemeInfo.tooltipBackgroundColor);
m_Tooltip.SetContentTextColor(m_ThemeInfo.tooltipTextColor);
m_Tooltip.SetLabelBackgroundColor(m_ThemeInfo.tooltipLabelColor);
m_Tooltip.SetLabelTextColor(m_ThemeInfo.tooltipTextColor);
m_Tooltip.SetActive(false);
}
@@ -283,8 +278,7 @@ namespace XCharts
protected float GetMaxValue(int index)
{
if (m_Series == null) return 100;
else return m_Series.GetMaxValue(index);
return m_Series.GetMaxValue(index);
}
private void CheckSize()
@@ -336,7 +330,6 @@ namespace XCharts
}
return;
}
m_Tooltip.SetLabelActive(m_Tooltip.crossLabel);
m_Tooltip.dataIndex = 0;
Vector2 local;
@@ -378,6 +371,7 @@ namespace XCharts
{
InitTitle();
InitLegend();
InitTooltip();
}
protected virtual void OnThemeChanged()

View File

@@ -28,8 +28,8 @@ namespace XCharts
{
m_Left = 40f,
m_Right = 80f,
m_Top = 40f,
m_Bottom = 25f,
m_Top = 50f,
m_Bottom = 30f,
m_Tickness = 0.6f,
m_FontSize = 16,
};

File diff suppressed because it is too large Load Diff

View File

@@ -63,6 +63,9 @@ namespace XCharts
[SerializeField] private DataZoomType m_Type;
[SerializeField] private FilterMode m_FilterMode;
[SerializeField] private Orient m_Orient;
[SerializeField] private int m_XAxisIndex;
[SerializeField] private int m_YAxisIndex;
[SerializeField] private bool m_ShowDataShadow;
[SerializeField] private bool m_ShowDetail;
[SerializeField] private bool m_ZoomLock;
@@ -85,6 +88,8 @@ namespace XCharts
/// Specify whether the layout of dataZoom component is horizontal or vertical.
/// </summary>
public Orient orient { get { return m_Orient; } set { m_Orient = value; } }
public int xAxisIndex { get { return m_XAxisIndex; } set { m_XAxisIndex = value; } }
public int yAxisIndex { get { return m_YAxisIndex; } set { m_YAxisIndex = value; } }
/// <summary>
/// Whether to show data shadow, to indicate the data tendency in brief.
/// default:true
@@ -165,6 +170,8 @@ namespace XCharts
m_Type = DataZoomType.Slider,
filterMode = FilterMode.None,
orient = Orient.Horizonal,
xAxisIndex = 0,
yAxisIndex = 0,
showDataShadow = true,
showDetail = false,
zoomLock = false,

View File

@@ -171,6 +171,15 @@ namespace XCharts
}
}
public string GetData(int index)
{
if (index >= 0 && index < m_Data.Count)
{
return m_Data[index];
}
return null;
}
public void SetActive(int index, bool flag)
{
m_DataActiveList[index] = flag;

View File

@@ -213,5 +213,14 @@ namespace XCharts
}
}
}
public float GetIndicatorMax(int index)
{
if (index >= 0 && index < m_IndicatorList.Count)
{
return m_IndicatorList[index].max;
}
return 0;
}
}
}

View File

@@ -1,4 +1,5 @@
using System.Collections.Generic;
using System.ComponentModel;
using UnityEngine;
namespace XCharts
@@ -12,10 +13,11 @@ namespace XCharts
Bar
}
[SerializeField] private bool m_Show = true;
[SerializeField][DefaultValue("true")] private bool m_Show;
[SerializeField] private SerieType m_Type;
[SerializeField] private string m_Name;
[SerializeField] private string m_Stack;
[SerializeField] private int m_AxisIndex;
[SerializeField] private List<float> m_Data = new List<float>();
[SerializeField] private bool m_Flodout;
@@ -23,6 +25,7 @@ namespace XCharts
public SerieType type { get { return m_Type; } set { m_Type = value; } }
public string name { get { return m_Name; } set { m_Name = value; } }
public string stack { get { return m_Stack; } set { m_Stack = value; } }
public int axisIndex { get { return m_AxisIndex; } set { m_AxisIndex = value; } }
public List<float> data { get { return m_Data; } set { m_Data = value; } }
public int filterStart { get; set; }

View File

@@ -18,7 +18,9 @@ namespace XCharts
{
var series = new Series
{
m_Series = new List<Serie>()
m_Series = new List<Serie>(){new Serie(){
show = true,
}}
};
return series;
}
@@ -173,7 +175,16 @@ namespace XCharts
}
}
public void GetMinMaxValue(DataZoom dataZoom, out int minVaule, out int maxValue)
public bool IsUsedAxisIndex(int axisIndex)
{
foreach (var serie in series)
{
if (serie.axisIndex == axisIndex) return true;
}
return false;
}
public void GetMinMaxValue(DataZoom dataZoom, int axisIndex, out int minVaule, out int maxValue)
{
float min = int.MaxValue;
float max = int.MinValue;
@@ -186,6 +197,7 @@ namespace XCharts
for (int i = 0; i < ss.Value.Count; i++)
{
var serie = ss.Value[i];
if (serie.axisIndex != axisIndex) continue;
var showData = serie.GetData(dataZoom);
for (int j = 0; j < showData.Count; j++)
{
@@ -209,21 +221,14 @@ namespace XCharts
{
for (int i = 0; i < m_Series.Count; i++)
{
if (m_Series[i].axisIndex != axisIndex) continue;
if (IsActive(i))
{
if (dataZoom != null && dataZoom.show)
var showData = m_Series[i].GetData(dataZoom);
foreach (var data in showData)
{
var showData = m_Series[i].GetData(dataZoom);
foreach (var data in showData)
{
if (data > max) max = data;
if (data < min) min = data;
}
}
else
{
if (m_Series[i].Max > max) max = m_Series[i].Max;
if (m_Series[i].Min < min) min = m_Series[i].Min;
if (data > max) max = data;
if (data < min) min = data;
}
}
}
@@ -261,6 +266,27 @@ namespace XCharts
return ChartHelper.GetMaxDivisibleValue(max);
}
public float GetMinValue(int index)
{
float max = int.MinValue;
float min = int.MaxValue;
for (int i = 0; i < m_Series.Count; i++)
{
var showData = m_Series[i].data;
if (showData[index] > max)
{
max = Mathf.Ceil(showData[index]);
}
if (showData[index] < min)
{
min = Mathf.Ceil(showData[index]);
}
}
if (min < 1 && min > -1) return min;
if (min < 0 && max < 0) min = max;
return ChartHelper.GetMinDivisibleValue(min);
}
public bool IsStack()
{
HashSet<string> sets = new HashSet<string>();

View File

@@ -102,7 +102,7 @@ namespace XCharts
m_AxisTextColor = GetColor("#514D4D"),
m_AxisLineColor = GetColor("#514D4D"),
m_AxisSplitLineColor = GetColor("#51515120"),
m_TooltipBackgroundColor = GetColor("#515151B5"),
m_TooltipBackgroundColor = GetColor("#515151C8"),
m_TooltipTextColor = GetColor("#FFFFFFFF"),
m_TooltipFlagAreaColor = GetColor("#51515120"),
m_TooltipLabelColor = GetColor("#292929FF"),
@@ -143,7 +143,7 @@ namespace XCharts
m_AxisTextColor = GetColor("#514D4D"),
m_AxisLineColor = GetColor("#514D4D"),
m_AxisSplitLineColor = GetColor("#51515120"),
m_TooltipBackgroundColor = GetColor("#515151B5"),
m_TooltipBackgroundColor = GetColor("#515151C8"),
m_TooltipTextColor = GetColor("#FFFFFFFF"),
m_TooltipFlagAreaColor = GetColor("#51515120"),
m_TooltipLabelColor = GetColor("#292929FF"),
@@ -186,7 +186,7 @@ namespace XCharts
m_AxisTextColor = GetColor("#eee"),
m_AxisLineColor = GetColor("#eee"),
m_AxisSplitLineColor = GetColor("#aaa"),
m_TooltipBackgroundColor = GetColor("#515151B5"),
m_TooltipBackgroundColor = GetColor("#515151C8"),
m_TooltipTextColor = GetColor("#FFFFFFFF"),
m_TooltipFlagAreaColor = GetColor("#51515120"),
m_TooltipLabelColor = GetColor("#A7A7A7FF"),

View File

@@ -1,4 +1,5 @@
using System;
using System.Xml;
using System;
using UnityEngine;
using UnityEngine.UI;
@@ -12,24 +13,22 @@ namespace XCharts
[NonSerialized] private GameObject m_GameObject;
[NonSerialized] private GameObject m_Content;
[NonSerialized] private GameObject m_LabelX;
[NonSerialized] private GameObject m_LabelY;
[NonSerialized] private Text m_ContentText;
[NonSerialized] private Text m_LabelTextX;
[NonSerialized] private Text m_LabelTextY;
[NonSerialized] private RectTransform m_ContentRect;
[NonSerialized] private RectTransform m_LabelRectX;
[NonSerialized] private RectTransform m_LabelRectY;
public bool show { get { return m_Show; } set { m_Show = value; SetActive(value); } }
public bool crossLabel { get { return m_CrossLabel; } set { m_CrossLabel = value; } }
public int dataIndex { get; set; }
public float[] xValues { get; set; }
public float[] yValues { get; set; }
public int lastDataIndex { get; set; }
public Vector2 pointerPos { get; set; }
public float width { get { return m_ContentRect.sizeDelta.x; } }
public float height { get { return m_ContentRect.sizeDelta.y; } }
public bool isInited { get { return m_GameObject != null; } }
public GameObject gameObject { get { return m_GameObject; } }
public static Tooltip defaultTooltip
{
@@ -38,7 +37,9 @@ namespace XCharts
var tooltip = new Tooltip
{
m_Show = true,
m_CrossLabel = false
m_CrossLabel = false,
xValues = new float[2],
yValues = new float[2],
};
return tooltip;
}
@@ -57,16 +58,9 @@ namespace XCharts
m_ContentText = m_Content.GetComponentInChildren<Text>();
}
public void SetLabelObj(GameObject labelX, GameObject labelY)
{
m_LabelX = labelX;
m_LabelRectX = labelX.GetComponent<RectTransform>();
m_LabelTextX = labelX.GetComponentInChildren<Text>();
m_LabelY = labelY;
m_LabelRectY = labelY.GetComponent<RectTransform>();
m_LabelTextY = labelY.GetComponentInChildren<Text>();
m_LabelX.SetActive(false);
m_LabelY.SetActive(false);
public void UpdateToTop(){
int count = m_GameObject.transform.parent.childCount;
m_GameObject.GetComponent<RectTransform>().SetSiblingIndex(count - 1);
}
public void SetContentBackgroundColor(Color color)
@@ -82,18 +76,6 @@ namespace XCharts
}
}
public void SetLabelBackgroundColor(Color color)
{
m_LabelX.GetComponent<Image>().color = color;
m_LabelY.GetComponent<Image>().color = color;
}
public void SetLabelTextColor(Color color)
{
m_LabelTextX.color = color;
m_LabelTextY.color = color;
}
public void UpdateContentText(string txt)
{
if (m_ContentText)
@@ -104,20 +86,11 @@ namespace XCharts
}
}
public void UpdateLabelText(string labelX, string labelY)
public void ClearValue()
{
if (m_LabelTextX)
{
m_LabelTextX.text = labelX;
m_LabelRectX.sizeDelta = new Vector2(m_LabelTextX.preferredWidth + 8,
m_LabelTextX.preferredHeight + 8);
}
if (m_LabelTextY)
{
m_LabelTextY.text = labelY;
m_LabelRectY.sizeDelta = new Vector2(m_LabelTextY.preferredWidth + 8,
m_LabelTextY.preferredHeight + 8);
}
dataIndex = 0;
xValues[0] = xValues[1] = 0;
yValues[0] = yValues[1] = 0;
}
public void SetActive(bool flag)
@@ -127,30 +100,12 @@ namespace XCharts
m_GameObject.SetActive(flag);
}
public void SetLabelActive(bool flag)
{
if (m_LabelX && m_LabelX.activeInHierarchy != flag) m_LabelX.SetActive(flag);
if (m_LabelY && m_LabelY.activeInHierarchy != flag) m_LabelY.SetActive(flag);
}
public void UpdateContentPos(Vector2 pos)
{
if (m_Content)
m_Content.transform.localPosition = pos;
}
public void UpdateLabelPos(Vector2 xLabelPos, Vector2 yLabelPos)
{
if (m_LabelX)
{
m_LabelX.transform.localPosition = xLabelPos;
}
if (m_LabelY)
{
m_LabelY.transform.localPosition = yLabelPos;
}
}
public Vector3 GetContentPos()
{
if (m_Content)

View File

@@ -22,7 +22,7 @@ namespace XCharts
{
base.DrawChart(vh);
if (m_XAxis.type == Axis.AxisType.Category)
if (m_XAxises[0].type == Axis.AxisType.Category)
{
DrawXCategory(vh);
}
@@ -36,7 +36,7 @@ namespace XCharts
{
var stackSeries = m_Series.GetStackSeries();
int seriesCount = stackSeries.Count;
float scaleWid = m_XAxis.GetDataWidth(coordinateWid, m_DataZoom);
int serieCount = 0;
List<Vector3> points = new List<Vector3>();
List<Vector3> smoothPoints = new List<Vector3>();
@@ -58,7 +58,11 @@ namespace XCharts
Color color = m_ThemeInfo.GetColor(serieCount);
Vector3 lp = Vector3.zero;
Vector3 np = Vector3.zero;
float startX = zeroX + (m_XAxis.boundaryGap ? scaleWid / 2 : 0);
var yAxis = m_YAxises[serie.axisIndex];
var xAxis = m_XAxises[serie.axisIndex];
if (!xAxis.show) xAxis = m_XAxises[(serie.axisIndex + 1) % m_XAxises.Count];
float scaleWid = xAxis.GetDataWidth(coordinateWid, m_DataZoom);
float startX = zeroX + (xAxis.boundaryGap ? scaleWid / 2 : 0);
int maxCount = maxShowDataNumber > 0 ?
(maxShowDataNumber > serieData.Count ? serieData.Count : maxShowDataNumber)
: serieData.Count;
@@ -91,7 +95,7 @@ namespace XCharts
float value = serieData[i];
float pX = startX + i * scaleWid;
float pY = seriesCurrHig[i] + coordinateY + m_Coordinate.tickness;
float dataHig = (value - minValue) / (maxValue - minValue) * coordinateHig;
float dataHig = (value - yAxis.minValue) / (yAxis.maxValue - yAxis.minValue) * coordinateHig;
np = new Vector3(pX, pY + dataHig);
if (i > 0)
@@ -256,17 +260,22 @@ namespace XCharts
//draw tooltip line
if (m_Tooltip.show && m_Tooltip.dataIndex > 0)
{
float splitWidth = m_XAxis.GetSplitWidth(coordinateWid, m_DataZoom);
float px = zeroX + (m_Tooltip.dataIndex - 1) * splitWidth
+ (m_XAxis.boundaryGap ? splitWidth / 2 : 0);
Vector2 sp = new Vector2(px, coordinateY);
Vector2 ep = new Vector2(px, coordinateY + coordinateHig);
ChartHelper.DrawLine(vh, sp, ep, m_Coordinate.tickness, m_ThemeInfo.tooltipLineColor);
if (m_Tooltip.crossLabel)
for (int i = 0; i < m_XAxises.Count; i++)
{
sp = new Vector2(zeroX, m_Tooltip.pointerPos.y);
ep = new Vector2(zeroX + coordinateWid, m_Tooltip.pointerPos.y);
DrawSplitLine(vh, true, Axis.SplitLineType.Dashed, sp, ep, m_ThemeInfo.tooltipLineColor);
var axis = m_XAxises[i];
if (!axis.show) continue;
float splitWidth = axis.GetSplitWidth(coordinateWid, m_DataZoom);
float px = zeroX + (m_Tooltip.xValues[i] - 1) * splitWidth
+ (axis.boundaryGap ? splitWidth / 2 : 0);
Vector2 sp = new Vector2(px, coordinateY);
Vector2 ep = new Vector2(px, coordinateY + coordinateHig);
ChartHelper.DrawLine(vh, sp, ep, m_Coordinate.tickness, m_ThemeInfo.tooltipLineColor);
if (m_Tooltip.crossLabel)
{
sp = new Vector2(zeroX, m_Tooltip.pointerPos.y);
ep = new Vector2(zeroX + coordinateWid, m_Tooltip.pointerPos.y);
DrawSplitLine(vh, true, Axis.SplitLineType.Dashed, sp, ep, m_ThemeInfo.tooltipLineColor);
}
}
}
}
@@ -275,7 +284,6 @@ namespace XCharts
{
var stackSeries = m_Series.GetStackSeries();
int seriesCount = stackSeries.Count;
float scaleWid = m_YAxis.GetDataWidth(coordinateHig, m_DataZoom);
int serieCount = 0;
List<Vector3> points = new List<Vector3>();
List<Vector3> smoothPoints = new List<Vector3>();
@@ -296,7 +304,11 @@ namespace XCharts
Color color = m_ThemeInfo.GetColor(serieCount);
Vector3 lp = Vector3.zero;
Vector3 np = Vector3.zero;
float startY = zeroY + (m_YAxis.boundaryGap ? scaleWid / 2 : 0);
var xAxis = m_XAxises[serie.axisIndex];
var yAxis = m_YAxises[serie.axisIndex];
if (!yAxis.show) yAxis = m_YAxises[(serie.axisIndex + 1) % m_YAxises.Count];
float scaleWid = yAxis.GetDataWidth(coordinateHig, m_DataZoom);
float startY = zeroY + (yAxis.boundaryGap ? scaleWid / 2 : 0);
int maxCount = maxShowDataNumber > 0 ?
(maxShowDataNumber > serie.data.Count ? serie.data.Count : maxShowDataNumber)
: serie.data.Count;
@@ -329,7 +341,7 @@ namespace XCharts
float value = serie.data[i];
float pY = startY + i * scaleWid;
float pX = seriesCurrHig[i] + coordinateX + m_Coordinate.tickness;
float dataHig = (value - minValue) / (maxValue - minValue) * coordinateWid;
float dataHig = (value - xAxis.minValue) / (xAxis.maxValue - xAxis.minValue) * coordinateWid;
np = new Vector3(pX + dataHig, pY);
if (i > 0)
@@ -493,16 +505,21 @@ namespace XCharts
//draw tooltip line
if (m_Tooltip.show && m_Tooltip.dataIndex > 0)
{
float splitWidth = m_YAxis.GetSplitWidth(coordinateHig, m_DataZoom);
float pY = zeroY + (m_Tooltip.dataIndex - 1) * splitWidth + (m_YAxis.boundaryGap ? splitWidth / 2 : 0);
Vector2 sp = new Vector2(coordinateX, pY);
Vector2 ep = new Vector2(coordinateX + coordinateWid, pY);
ChartHelper.DrawLine(vh, sp, ep, m_Coordinate.tickness, m_ThemeInfo.tooltipFlagAreaColor);
if (m_Tooltip.crossLabel)
for (int i = 0; i < m_YAxises.Count; i++)
{
sp = new Vector2(m_Tooltip.pointerPos.x, zeroY);
ep = new Vector2(m_Tooltip.pointerPos.x, zeroY + coordinateHig);
DrawSplitLine(vh, false, Axis.SplitLineType.Dashed, sp, ep, m_ThemeInfo.tooltipLineColor);
var axis = m_YAxises[i];
if (!axis.show) continue;
float splitWidth = axis.GetSplitWidth(coordinateHig, m_DataZoom);
float pY = zeroY + (m_Tooltip.yValues[i] - 1) * splitWidth + (axis.boundaryGap ? splitWidth / 2 : 0);
Vector2 sp = new Vector2(coordinateX, pY);
Vector2 ep = new Vector2(coordinateX + coordinateWid, pY);
ChartHelper.DrawLine(vh, sp, ep, m_Coordinate.tickness, m_ThemeInfo.tooltipFlagAreaColor);
if (m_Tooltip.crossLabel)
{
sp = new Vector2(m_Tooltip.pointerPos.x, zeroY);
ep = new Vector2(m_Tooltip.pointerPos.x, zeroY + coordinateHig);
DrawSplitLine(vh, false, Axis.SplitLineType.Dashed, sp, ep, m_ThemeInfo.tooltipLineColor);
}
}
}
}

View File

@@ -230,7 +230,8 @@ namespace XCharts
}
m_Tooltip.SetActive(true);
string strColor = ColorUtility.ToHtmlStringRGBA(m_ThemeInfo.GetColor(index));
string key = m_Legend.data[index];
string key = m_Series.series[index].name;
if (string.IsNullOrEmpty(key)) key = m_Legend.GetData(index);
float value = m_Series.series[index].data[0];
string txt = "";
if (!string.IsNullOrEmpty(m_Pie.name))

View File

@@ -83,6 +83,7 @@ namespace XCharts
{
UpdateRadarCenter();
InitIndicator();
m_Tooltip.UpdateToTop();
}
private Vector3 GetIndicatorPosition(int i)
@@ -159,8 +160,8 @@ namespace XCharts
dataPosList.Add(pointList);
for (int j = 0; j < dataList.Count; j++)
{
var max = m_Radar.indicatorList[j].max > 0 ?
m_Radar.indicatorList[j].max :
var max = m_Radar.GetIndicatorMax(j) > 0 ?
m_Radar.GetIndicatorMax(j) :
GetMaxValue(j);
var radius = max < 0 ? m_Radar.radius - m_Radar.radius * dataList[j] / max
: m_Radar.radius * dataList[j] / max;