mirror of
https://github.com/XCharts-Team/XCharts.git
synced 2026-05-20 15:30:09 +00:00
Tooltip增加crossLabel显示十字准星指示器
This commit is contained in:
@@ -4,8 +4,6 @@ using UnityEngine.UI;
|
||||
|
||||
namespace XCharts
|
||||
{
|
||||
|
||||
|
||||
[AddComponentMenu("XCharts/BarChart", 13)]
|
||||
[ExecuteInEditMode]
|
||||
[RequireComponent(typeof(RectTransform))]
|
||||
@@ -89,14 +87,28 @@ namespace XCharts
|
||||
}
|
||||
if (m_Tooltip.show && m_Tooltip.dataIndex > 0)
|
||||
{
|
||||
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);
|
||||
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);
|
||||
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);
|
||||
}
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
@@ -149,14 +161,30 @@ namespace XCharts
|
||||
}
|
||||
if (m_Tooltip.show && m_Tooltip.dataIndex > 0)
|
||||
{
|
||||
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);
|
||||
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);
|
||||
|
||||
float splitWidth = m_XAxis.GetSplitWidth(coordinateWid);
|
||||
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);
|
||||
}
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -244,10 +244,21 @@ namespace XCharts
|
||||
|
||||
private void InitTooltip()
|
||||
{
|
||||
GameObject obj = ChartHelper.AddTooltipObject("tooltip", transform, m_ThemeInfo.font);
|
||||
m_Tooltip.SetObj(obj);
|
||||
m_Tooltip.SetBackgroundColor(m_ThemeInfo.tooltipBackgroundColor);
|
||||
m_Tooltip.SetTextColor(m_ThemeInfo.tooltipTextColor);
|
||||
var tooltipObject = ChartHelper.AddObject("tooltip", transform, chartAnchorMin,
|
||||
chartAnchorMax, chartPivot, new Vector2(chartWidth, chartHeight));
|
||||
tooltipObject.transform.localPosition = Vector3.zero;
|
||||
DestroyImmediate(tooltipObject.GetComponent<Image>());
|
||||
ChartHelper.HideAllObject(tooltipObject.transform);
|
||||
GameObject content = ChartHelper.AddTooltipContent("content", tooltipObject.transform, m_ThemeInfo.font);
|
||||
GameObject labelX = ChartHelper.AddTooltipLabel("label_x", tooltipObject.transform, m_ThemeInfo.font, new Vector2(0.5f, 1));
|
||||
GameObject labelY = ChartHelper.AddTooltipLabel("label_y", tooltipObject.transform, 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);
|
||||
}
|
||||
|
||||
@@ -302,7 +313,9 @@ namespace XCharts
|
||||
private void CheckTooltip()
|
||||
{
|
||||
if (!m_Tooltip.show || !m_Tooltip.isInited) return;
|
||||
m_Tooltip.SetLabelActive(m_Tooltip.crossLabel);
|
||||
m_Tooltip.dataIndex = 0;
|
||||
|
||||
Vector2 local;
|
||||
|
||||
if (!RectTransformUtility.ScreenPointToLocalPointInRectangle(rectTransform,
|
||||
@@ -312,7 +325,7 @@ namespace XCharts
|
||||
if (local.x < 0 || local.x > chartWidth ||
|
||||
local.y < 0 || local.y > chartHeight)
|
||||
return;
|
||||
|
||||
m_Tooltip.pointerPos = local;
|
||||
CheckTootipArea(local);
|
||||
}
|
||||
|
||||
@@ -342,6 +355,7 @@ namespace XCharts
|
||||
}
|
||||
InitTitle();
|
||||
InitLegend();
|
||||
InitTooltip();
|
||||
}
|
||||
|
||||
protected virtual void OnTitleChanged()
|
||||
|
||||
@@ -129,9 +129,9 @@ namespace XCharts
|
||||
}
|
||||
if (m_Tooltip.dataIndex > 0)
|
||||
{
|
||||
m_Tooltip.UpdatePos(new Vector2(local.x + 18, local.y - 25));
|
||||
m_Tooltip.UpdateContentPos(new Vector2(local.x + 18, local.y - 25));
|
||||
RefreshTooltip();
|
||||
if (m_Tooltip.lastDataIndex != m_Tooltip.dataIndex)
|
||||
if (m_Tooltip.lastDataIndex != m_Tooltip.dataIndex || m_Tooltip.crossLabel)
|
||||
{
|
||||
RefreshChart();
|
||||
}
|
||||
@@ -152,8 +152,9 @@ namespace XCharts
|
||||
m_Tooltip.SetActive(true);
|
||||
if (m_Series.Count == 1)
|
||||
{
|
||||
string txt = tempAxis.GetData(index) + ": " + m_Series.GetData(0, index);
|
||||
m_Tooltip.UpdateTooltipText(txt);
|
||||
float value = m_Series.GetData(0, index);
|
||||
string txt = tempAxis.GetData(index) + ": " + value;
|
||||
m_Tooltip.UpdateContentText(txt);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -171,9 +172,33 @@ namespace XCharts
|
||||
}
|
||||
|
||||
}
|
||||
m_Tooltip.UpdateTooltipText(sb.ToString());
|
||||
m_Tooltip.UpdateContentText(sb.ToString());
|
||||
}
|
||||
var pos = m_Tooltip.GetPos();
|
||||
if(m_XAxis.type == Axis.AxisType.Value)
|
||||
{
|
||||
float hig = (maxValue - minValue) * (m_Tooltip.pointerPos.x - zeroX) / coordinateWid;
|
||||
m_Tooltip.UpdateLabelText(hig.ToString("f2"),tempAxis.GetData(index));
|
||||
float splitWidth = m_YAxis.GetSplitWidth(coordinateHig);
|
||||
float py = zeroY + (m_Tooltip.dataIndex - 1) * splitWidth
|
||||
+ (m_YAxis.boundaryGap ? splitWidth / 2 : 0);
|
||||
Vector2 xLabelPos = new Vector2(m_Tooltip.pointerPos.x,coordinateY- 4 * m_Coordinate.tickness);
|
||||
Vector2 yLabelPos = new Vector2(coordinateX - 6 * m_Coordinate.tickness,py);
|
||||
m_Tooltip.UpdateLabelPos(xLabelPos, yLabelPos);
|
||||
}
|
||||
else
|
||||
{
|
||||
float hig = (maxValue - minValue) * (m_Tooltip.pointerPos.y - zeroY) / coordinateHig;
|
||||
m_Tooltip.UpdateLabelText(tempAxis.GetData(index), hig.ToString("f2"));
|
||||
float splitWidth = m_XAxis.GetSplitWidth(coordinateWid);
|
||||
float px = zeroX + (m_Tooltip.dataIndex - 1) * splitWidth
|
||||
+ (m_XAxis.boundaryGap ? splitWidth / 2 : 0);
|
||||
Vector2 xLabelPos = new Vector2(px, coordinateY - 6 * m_Coordinate.tickness);
|
||||
Vector2 yLabelPos = new Vector2(coordinateX - 4 * m_Coordinate.tickness, m_Tooltip.pointerPos.y);
|
||||
m_Tooltip.UpdateLabelPos(xLabelPos, yLabelPos);
|
||||
}
|
||||
|
||||
|
||||
var pos = m_Tooltip.GetContentPos();
|
||||
if (pos.x + m_Tooltip.width > chartWidth)
|
||||
{
|
||||
pos.x = chartWidth - m_Tooltip.width;
|
||||
@@ -182,7 +207,7 @@ namespace XCharts
|
||||
{
|
||||
pos.y = m_Tooltip.height;
|
||||
}
|
||||
m_Tooltip.UpdatePos(pos);
|
||||
m_Tooltip.UpdateContentPos(pos);
|
||||
}
|
||||
|
||||
TextGenerationSettings GetTextSetting()
|
||||
@@ -293,12 +318,13 @@ namespace XCharts
|
||||
{
|
||||
if (m_XAxis.boundaryGap)
|
||||
{
|
||||
return new Vector3(coordinateX + (i + 1) * scaleWid, coordinateY - m_XAxis.axisTick.length - 5, 0);
|
||||
return new Vector3(coordinateX + (i + 1) * scaleWid,
|
||||
coordinateY - m_XAxis.axisTick.length - 12, 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
return new Vector3(coordinateX + (i + 1 - 0.5f) * scaleWid,
|
||||
coordinateY - m_XAxis.axisTick.length - 10, 0);
|
||||
coordinateY - m_XAxis.axisTick.length - 12, 0);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -396,12 +422,14 @@ namespace XCharts
|
||||
maxValue = tempMaxValue;
|
||||
if (m_XAxis.type == Axis.AxisType.Value)
|
||||
{
|
||||
m_ZeroXOffset = minValue > 0 ? 0 : Mathf.Abs(minValue) * (coordinateWid / (Mathf.Abs(minValue) + Mathf.Abs(maxValue)));
|
||||
m_ZeroXOffset = minValue > 0 ? 0 :
|
||||
Mathf.Abs(minValue) * (coordinateWid / (Mathf.Abs(minValue) + Mathf.Abs(maxValue)));
|
||||
OnXMaxValueChanged();
|
||||
}
|
||||
else if (m_YAxis.type == Axis.AxisType.Value)
|
||||
{
|
||||
m_ZeroYOffset = minValue > 0 ? 0 : Mathf.Abs(minValue) * (coordinateHig / (Mathf.Abs(minValue) + Mathf.Abs(maxValue)));
|
||||
m_ZeroYOffset = minValue > 0 ? 0 :
|
||||
Mathf.Abs(minValue) * (coordinateHig / (Mathf.Abs(minValue) + Mathf.Abs(maxValue)));
|
||||
OnYMaxValueChanged();
|
||||
}
|
||||
RefreshChart();
|
||||
@@ -470,7 +498,7 @@ namespace XCharts
|
||||
if (m_YAxis.showSplitLine)
|
||||
{
|
||||
DrawSplitLine(vh, true, m_YAxis.splitLineType, new Vector3(coordinateX, pY),
|
||||
new Vector3(coordinateX + coordinateWid, pY));
|
||||
new Vector3(coordinateX + coordinateWid, pY), m_ThemeInfo.axisSplitLineColor);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -487,13 +515,13 @@ namespace XCharts
|
||||
if (m_XAxis.axisTick.show)
|
||||
{
|
||||
pY += zeroY - m_XAxis.axisTick.length - 2;
|
||||
ChartHelper.DrawLine(vh, new Vector3(pX, zeroY), new Vector3(pX, pY), m_Coordinate.tickness,
|
||||
m_ThemeInfo.axisLineColor);
|
||||
ChartHelper.DrawLine(vh, new Vector3(pX, zeroY), new Vector3(pX, pY),
|
||||
m_Coordinate.tickness, m_ThemeInfo.axisLineColor);
|
||||
}
|
||||
if (m_XAxis.showSplitLine)
|
||||
{
|
||||
DrawSplitLine(vh, false, m_XAxis.splitLineType, new Vector3(pX, coordinateY),
|
||||
new Vector3(pX, coordinateY + coordinateHig));
|
||||
new Vector3(pX, coordinateY + coordinateHig), m_ThemeInfo.axisSplitLineColor);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -534,8 +562,8 @@ namespace XCharts
|
||||
#endregion
|
||||
}
|
||||
|
||||
private void DrawSplitLine(VertexHelper vh, bool isYAxis, Axis.SplitLineType type, Vector3 startPos,
|
||||
Vector3 endPos)
|
||||
protected void DrawSplitLine(VertexHelper vh, bool isYAxis, Axis.SplitLineType type,
|
||||
Vector3 startPos, Vector3 endPos, Color color)
|
||||
{
|
||||
switch (type)
|
||||
{
|
||||
@@ -552,22 +580,21 @@ namespace XCharts
|
||||
{
|
||||
var toX = startX + dashLen;
|
||||
ChartHelper.DrawLine(vh, new Vector3(startX, startY), new Vector3(toX, startY),
|
||||
m_Coordinate.tickness, m_ThemeInfo.axisSplitLineColor);
|
||||
m_Coordinate.tickness, color);
|
||||
startX += dashLen * 2;
|
||||
}
|
||||
else
|
||||
{
|
||||
var toY = startY + dashLen;
|
||||
ChartHelper.DrawLine(vh, new Vector3(startX, startY), new Vector3(startX, toY),
|
||||
m_Coordinate.tickness, m_ThemeInfo.axisSplitLineColor);
|
||||
m_Coordinate.tickness, color);
|
||||
startY += dashLen * 2;
|
||||
}
|
||||
|
||||
}
|
||||
break;
|
||||
case Axis.SplitLineType.Solid:
|
||||
ChartHelper.DrawLine(vh, startPos, endPos, m_Coordinate.tickness,
|
||||
m_ThemeInfo.axisSplitLineColor);
|
||||
ChartHelper.DrawLine(vh, startPos, endPos, m_Coordinate.tickness, color);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,6 +26,8 @@ namespace XCharts
|
||||
[SerializeField] private Color32 m_TooltipBackgroundColor;
|
||||
[SerializeField] private Color32 m_TooltipFlagAreaColor;
|
||||
[SerializeField] private Color32 m_TooltipTextColor;
|
||||
[SerializeField] private Color32 m_TooltipLabelColor;
|
||||
[SerializeField] private Color32 m_TooltipLineColor;
|
||||
[SerializeField] private Color32[] m_ColorPalette;
|
||||
|
||||
public Font font { get { return m_Font; } set { m_Font = value; } }
|
||||
@@ -40,6 +42,8 @@ namespace XCharts
|
||||
public Color32 tooltipBackgroundColor { get { return m_TooltipBackgroundColor; } set { m_TooltipBackgroundColor = value; } }
|
||||
public Color32 tooltipFlagAreaColor { get { return m_TooltipFlagAreaColor; } set { m_TooltipFlagAreaColor = value; } }
|
||||
public Color32 tooltipTextColor { get { return m_TooltipTextColor; } set { m_TooltipTextColor = value; } }
|
||||
public Color32 tooltipLabelColor { get { return m_TooltipLabelColor; } set { m_TooltipLabelColor = value; } }
|
||||
public Color32 tooltipLineColor { get { return m_TooltipLineColor; } set { m_TooltipLineColor = value; } }
|
||||
public Color32[] colorPalette { get { return m_ColorPalette; } set { m_ColorPalette = value; } }
|
||||
|
||||
public Color32 GetColor(int index)
|
||||
@@ -65,6 +69,8 @@ namespace XCharts
|
||||
m_AxisSplitLineColor = theme.m_AxisSplitLineColor;
|
||||
m_TooltipBackgroundColor = theme.m_TooltipBackgroundColor;
|
||||
m_TooltipTextColor = theme.m_TooltipTextColor;
|
||||
m_TooltipLabelColor = theme.m_TooltipLabelColor;
|
||||
m_TooltipLineColor = theme.m_TooltipLineColor;
|
||||
m_ColorPalette = new Color32[theme.m_ColorPalette.Length];
|
||||
for (int i = 0; i < theme.m_ColorPalette.Length; i++)
|
||||
{
|
||||
@@ -90,6 +96,8 @@ namespace XCharts
|
||||
m_TooltipBackgroundColor = GetColor("#515151B5"),
|
||||
m_TooltipTextColor = GetColor("#FFFFFFFF"),
|
||||
m_TooltipFlagAreaColor = GetColor("#51515120"),
|
||||
m_TooltipLabelColor = GetColor("#292929FF"),
|
||||
m_TooltipLineColor = GetColor("#29292964"),
|
||||
m_ColorPalette = new Color32[]
|
||||
{
|
||||
new Color32(194, 53, 49, 255),
|
||||
@@ -126,6 +134,8 @@ namespace XCharts
|
||||
m_TooltipBackgroundColor = GetColor("#515151B5"),
|
||||
m_TooltipTextColor = GetColor("#FFFFFFFF"),
|
||||
m_TooltipFlagAreaColor = GetColor("#51515120"),
|
||||
m_TooltipLabelColor = GetColor("#292929FF"),
|
||||
m_TooltipLineColor = GetColor("#29292964"),
|
||||
m_ColorPalette = new Color32[]
|
||||
{
|
||||
new Color32(55, 162, 218, 255),
|
||||
@@ -164,6 +174,8 @@ namespace XCharts
|
||||
m_TooltipBackgroundColor = GetColor("#515151B5"),
|
||||
m_TooltipTextColor = GetColor("#FFFFFFFF"),
|
||||
m_TooltipFlagAreaColor = GetColor("#51515120"),
|
||||
m_TooltipLabelColor = GetColor("#A7A7A7FF"),
|
||||
m_TooltipLineColor = GetColor("#eee"),
|
||||
m_ColorPalette = new Color32[]
|
||||
{
|
||||
new Color32(221, 107, 102, 255),
|
||||
|
||||
@@ -8,16 +8,27 @@ namespace XCharts
|
||||
public class Tooltip
|
||||
{
|
||||
[SerializeField] private bool m_Show;
|
||||
[SerializeField] private bool m_CrossLabel;
|
||||
|
||||
[NonSerialized] private GameObject m_GameObject;
|
||||
[NonSerialized] private Text m_Text;
|
||||
[NonSerialized] private RectTransform m_BackgroudRect;
|
||||
[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; } }
|
||||
public bool crossLabel { get { return m_CrossLabel; } set { m_CrossLabel = value; } }
|
||||
|
||||
public int dataIndex { get; set; }
|
||||
public int lastDataIndex { get; set; }
|
||||
public float width { get { return m_BackgroudRect.sizeDelta.x; } }
|
||||
public float height { get { return m_BackgroudRect.sizeDelta.y; } }
|
||||
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 static Tooltip defaultTooltip
|
||||
@@ -26,7 +37,8 @@ namespace XCharts
|
||||
{
|
||||
var tooltip = new Tooltip
|
||||
{
|
||||
m_Show = true
|
||||
m_Show = true,
|
||||
m_CrossLabel = false
|
||||
};
|
||||
return tooltip;
|
||||
}
|
||||
@@ -35,29 +47,73 @@ namespace XCharts
|
||||
public void SetObj(GameObject obj)
|
||||
{
|
||||
m_GameObject = obj;
|
||||
m_BackgroudRect = m_GameObject.GetComponent<RectTransform>();
|
||||
m_Text = m_GameObject.GetComponentInChildren<Text>();
|
||||
}
|
||||
|
||||
public void SetBackgroundColor(Color color)
|
||||
public void SetContentObj(GameObject content)
|
||||
{
|
||||
m_GameObject.GetComponent<Image>().color = color;
|
||||
m_Content = content;
|
||||
m_ContentRect = m_Content.GetComponent<RectTransform>();
|
||||
m_ContentText = m_Content.GetComponentInChildren<Text>();
|
||||
}
|
||||
|
||||
public void SetTextColor(Color color)
|
||||
public void SetLabelObj(GameObject labelX,GameObject labelY)
|
||||
{
|
||||
if (m_Text)
|
||||
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>();
|
||||
}
|
||||
|
||||
public void SetContentBackgroundColor(Color color)
|
||||
{
|
||||
m_Content.GetComponent<Image>().color = color;
|
||||
}
|
||||
|
||||
public void SetContentTextColor(Color color)
|
||||
{
|
||||
if (m_ContentText)
|
||||
{
|
||||
m_Text.color = color;
|
||||
m_ContentText.color = color;
|
||||
}
|
||||
}
|
||||
|
||||
public void UpdateTooltipText(string txt)
|
||||
public void SetLabelBackgroundColor(Color color)
|
||||
{
|
||||
if (m_Text)
|
||||
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)
|
||||
{
|
||||
m_Text.text = txt;
|
||||
m_BackgroudRect.sizeDelta = new Vector2(m_Text.preferredWidth + 8, m_Text.preferredHeight + 8);
|
||||
m_ContentText.text = txt;
|
||||
m_ContentRect.sizeDelta = new Vector2(m_ContentText.preferredWidth + 8,
|
||||
m_ContentText.preferredHeight + 8);
|
||||
}
|
||||
}
|
||||
|
||||
public void UpdateLabelText(string labelX,string labelY)
|
||||
{
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -67,16 +123,34 @@ namespace XCharts
|
||||
m_GameObject.SetActive(flag);
|
||||
}
|
||||
|
||||
public void UpdatePos(Vector2 pos)
|
||||
public void SetLabelActive(bool flag)
|
||||
{
|
||||
if(m_GameObject)
|
||||
m_GameObject.transform.localPosition = pos;
|
||||
if (m_LabelX && m_LabelX.activeInHierarchy != flag) m_LabelX.SetActive(flag);
|
||||
if (m_LabelY && m_LabelY.activeInHierarchy != flag) m_LabelY.SetActive(flag);
|
||||
}
|
||||
|
||||
public Vector3 GetPos()
|
||||
public void UpdateContentPos(Vector2 pos)
|
||||
{
|
||||
if (m_GameObject)
|
||||
return m_GameObject.transform.localPosition;
|
||||
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)
|
||||
return m_Content.transform.localPosition;
|
||||
else
|
||||
return Vector3.zero;
|
||||
}
|
||||
|
||||
@@ -220,7 +220,13 @@ namespace XCharts
|
||||
+ (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.tooltipFlagAreaColor);
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -249,7 +255,7 @@ namespace XCharts
|
||||
Color color = m_ThemeInfo.GetColor(serieCount);
|
||||
Vector3 lp = Vector3.zero;
|
||||
Vector3 np = Vector3.zero;
|
||||
float startY = coordinateY + (m_YAxis.boundaryGap ? scaleWid / 2 : 0);
|
||||
float startY = zeroY + (m_YAxis.boundaryGap ? scaleWid / 2 : 0);
|
||||
int maxCount = maxShowDataNumber > 0 ?
|
||||
(maxShowDataNumber > serie.data.Count ? serie.data.Count : maxShowDataNumber)
|
||||
: serie.data.Count;
|
||||
@@ -281,7 +287,7 @@ namespace XCharts
|
||||
}
|
||||
float value = serie.data[i];
|
||||
float pY = startY + i * scaleWid;
|
||||
float pX = seriesCurrHig[i] + zeroY + m_Coordinate.tickness;
|
||||
float pX = seriesCurrHig[i] + zeroX + m_Coordinate.tickness;
|
||||
float dataHig = value / (maxValue - minValue) * coordinateWid;
|
||||
np = new Vector3(pX + dataHig, pY);
|
||||
|
||||
@@ -402,6 +408,12 @@ namespace XCharts
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -169,7 +169,7 @@ namespace XCharts
|
||||
}
|
||||
if (m_Tooltip.dataIndex > 0)
|
||||
{
|
||||
m_Tooltip.UpdatePos(new Vector2(local.x + 18, local.y - 25));
|
||||
m_Tooltip.UpdateContentPos(new Vector2(local.x + 18, local.y - 25));
|
||||
RefreshTooltip();
|
||||
if (m_Tooltip.lastDataIndex != m_Tooltip.dataIndex)
|
||||
{
|
||||
@@ -209,9 +209,9 @@ namespace XCharts
|
||||
txt += m_Pie.name + "\n";
|
||||
}
|
||||
txt += string.Format("<color=#{0}>● </color>{1}: {2}", strColor, key, value);
|
||||
m_Tooltip.UpdateTooltipText(txt);
|
||||
m_Tooltip.UpdateContentText(txt);
|
||||
|
||||
var pos = m_Tooltip.GetPos();
|
||||
var pos = m_Tooltip.GetContentPos();
|
||||
if (pos.x + m_Tooltip.width > chartWidth)
|
||||
{
|
||||
pos.x = chartWidth - m_Tooltip.width;
|
||||
@@ -220,7 +220,7 @@ namespace XCharts
|
||||
{
|
||||
pos.y = m_Tooltip.height;
|
||||
}
|
||||
m_Tooltip.UpdatePos(pos);
|
||||
m_Tooltip.UpdateContentPos(pos);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -299,7 +299,7 @@ namespace XCharts
|
||||
}
|
||||
if (m_Tooltip.dataIndex > 0)
|
||||
{
|
||||
m_Tooltip.UpdatePos(new Vector2(local.x + 18, local.y - 25));
|
||||
m_Tooltip.UpdateContentPos(new Vector2(local.x + 18, local.y - 25));
|
||||
RefreshTooltip();
|
||||
if (m_Tooltip.lastDataIndex != m_Tooltip.dataIndex)
|
||||
{
|
||||
@@ -331,9 +331,9 @@ namespace XCharts
|
||||
sb.Append("\n");
|
||||
sb.AppendFormat("{0}: {1}", key, value);
|
||||
}
|
||||
m_Tooltip.UpdateTooltipText(sb.ToString());
|
||||
m_Tooltip.UpdateContentText(sb.ToString());
|
||||
|
||||
var pos = m_Tooltip.GetPos();
|
||||
var pos = m_Tooltip.GetContentPos();
|
||||
if (pos.x + m_Tooltip.width > chartWidth)
|
||||
{
|
||||
pos.x = chartWidth - m_Tooltip.width;
|
||||
@@ -342,7 +342,7 @@ namespace XCharts
|
||||
{
|
||||
pos.y = m_Tooltip.height;
|
||||
}
|
||||
m_Tooltip.UpdatePos(pos);
|
||||
m_Tooltip.UpdateContentPos(pos);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,12 +11,12 @@ namespace XCharts
|
||||
private static float CRICLE_SMOOTHNESS = 1f;
|
||||
private static UIVertex[] vertex = new UIVertex[4];
|
||||
|
||||
public static void HideAllObject(GameObject obj, string match)
|
||||
public static void HideAllObject(GameObject obj, string match = null)
|
||||
{
|
||||
HideAllObject(obj.transform, match);
|
||||
}
|
||||
|
||||
public static void HideAllObject(Transform parent, string match)
|
||||
public static void HideAllObject(Transform parent, string match = null)
|
||||
{
|
||||
for (int i = 0; i < parent.childCount; i++)
|
||||
{
|
||||
@@ -138,7 +138,7 @@ namespace XCharts
|
||||
return btnObj.GetComponent<Button>();
|
||||
}
|
||||
|
||||
public static GameObject AddTooltipObject(string name, Transform parent, Font font)
|
||||
public static GameObject AddTooltipContent(string name, Transform parent, Font font)
|
||||
{
|
||||
var anchorMax = new Vector2(0, 1);
|
||||
var anchorMin = new Vector2(0, 1);
|
||||
@@ -151,9 +151,27 @@ namespace XCharts
|
||||
anchorMin, anchorMax, pivot, sizeDelta);
|
||||
txt.text = "Text";
|
||||
txt.transform.localPosition = new Vector2(3, -3);
|
||||
tooltipObj.transform.localPosition = Vector3.zero;
|
||||
return tooltipObj;
|
||||
}
|
||||
|
||||
public static GameObject AddTooltipLabel(string name, Transform parent, Font font, Vector2 pivot)
|
||||
{
|
||||
var anchorMax = new Vector2(0, 0);
|
||||
var anchorMin = new Vector2(0, 0);
|
||||
var sizeDelta = new Vector2(100, 50);
|
||||
GameObject labelObj = AddObject(name, parent, anchorMin, anchorMax, pivot, sizeDelta);
|
||||
labelObj.transform.localPosition = Vector3.zero;
|
||||
var img = GetOrAddComponent<Image>(labelObj);
|
||||
img.color = Color.black;
|
||||
Text txt = AddTextObject("Text", labelObj.transform, font, Color.white, TextAnchor.MiddleCenter,
|
||||
new Vector2(0, 0), new Vector2(1, 1), new Vector2(1,1), sizeDelta, 16);
|
||||
txt.GetComponent<RectTransform>().offsetMin = Vector2.zero;
|
||||
txt.GetComponent<RectTransform>().offsetMax = Vector2.zero;
|
||||
txt.text = "Text";
|
||||
return labelObj;
|
||||
}
|
||||
|
||||
public static void DrawLine(VertexHelper vh, Vector3 p1, Vector3 p2, float size, Color32 color)
|
||||
{
|
||||
Vector3 v = Vector3.Cross(p2 - p1, Vector3.forward).normalized * size;
|
||||
|
||||
Reference in New Issue
Block a user