private void InitRadiusAxis(RadiusAxis axis) { PolarHelper.UpdatePolarCenter(m_Polar, m_ChartPosition, m_ChartWidth, m_ChartHeight); var radius = m_Polar.runtimeRadius; axis.axisLabelTextList.Clear(); string objName = "axis_radius"; var axisObj = ChartHelper.AddObject(objName, transform, chartAnchorMin, chartAnchorMax, chartPivot, new Vector2(chartWidth, chartHeight)); axisObj.transform.localPosition = Vector3.zero; axisObj.SetActive(axis.show && axis.axisLabel.show); axisObj.hideFlags = chartHideFlags; ChartHelper.HideAllObject(axisObj); var labelColor = ChartHelper.IsClearColor(axis.axisLabel.color) ? (Color)m_ThemeInfo.axisTextColor : axis.axisLabel.color; int splitNumber = AxisHelper.GetSplitNumber(axis, radius, null); float totalWidth = 0; var startAngle = m_AngleAxis.runtimeStartAngle; var cenPos = m_Polar.runtimeCenterPos; var txtHig = axis.axisLabel.fontSize + 2; var dire = ChartHelper.GetDire(startAngle, true).normalized; var tickVetor = ChartHelper.GetVertialDire(dire) * (m_RadiusAxis.axisTick.length + m_RadiusAxis.axisLabel.margin); for (int i = 0; i < splitNumber; i++) { float labelWidth = AxisHelper.GetScaleWidth(axis, radius, i, null); bool inside = axis.axisLabel.inside; Text txt = ChartHelper.AddTextObject(objName + i, axisObj.transform, m_ThemeInfo.font, labelColor, TextAnchor.MiddleCenter, new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f), new Vector2(labelWidth, txtHig), axis.axisLabel.fontSize, axis.axisLabel.rotate, axis.axisLabel.fontStyle); if (i == 0) { axis.axisLabel.SetRelatedText(txt, labelWidth); } var isPercentStack = SeriesHelper.IsPercentStack(m_Series, SerieType.Bar); txt.text = AxisHelper.GetLabelName(axis, radius, i, axis.runtimeMinValue, axis.runtimeMaxValue, null, isPercentStack); txt.gameObject.SetActive(axis.show && (axis.axisLabel.interval == 0 || i % (axis.axisLabel.interval + 1) == 0)); var pos = ChartHelper.GetPos(cenPos, totalWidth, startAngle, true) + tickVetor; txt.transform.localPosition = pos; AxisHelper.AdjustRadiusAxisLabelPos(txt, pos, cenPos, txtHig, Vector3.zero); axis.axisLabelTextList.Add(txt); totalWidth += labelWidth; } if (m_Tooltip.runtimeGameObject) { Vector2 privot = new Vector2(0.5f, 1); var labelParent = m_Tooltip.runtimeGameObject.transform; GameObject labelObj = ChartHelper.AddTooltipLabel(ChartCached.GetAxisTooltipLabel(objName), labelParent, m_ThemeInfo.font, privot); axis.SetTooltipLabel(labelObj); axis.SetTooltipLabelColor(m_ThemeInfo.tooltipBackgroundColor, m_ThemeInfo.tooltipTextColor); axis.SetTooltipLabelActive(axis.show && m_Tooltip.show && m_Tooltip.type == Tooltip.Type.Corss); } }
protected override void CheckTootipArea(Vector2 local) { var dist = Vector2.Distance(local, m_Polar.runtimeCenterPos); if (dist > m_Polar.runtimeRadius) { m_Tooltip.runtimeAngle = -1; if (m_Tooltip.IsActive()) { foreach (var kv in m_Tooltip.runtimeSerieIndex) { var serie = m_Series.GetSerie(kv.Key); foreach (var dataIndex in kv.Value) { serie.GetSerieData(dataIndex).highlighted = false; } } m_Tooltip.ClearSerieDataIndex(); m_Tooltip.SetActive(false); m_AngleAxis.SetTooltipLabelActive(false); m_RadiusAxis.SetTooltipLabelActive(false); RefreshChart(); } return; } m_Tooltip.ClearSerieDataIndex(); Vector2 dir = local - new Vector2(m_Polar.runtimeCenterPos.x, m_Polar.runtimeCenterPos.y); float angle = ChartHelper.GetAngle360(Vector2.up, dir); foreach (var serie in m_Series.list) { switch (serie.type) { case SerieType.Line: bool refresh = false; var count = serie.data.Count; SerieHelper.UpdateMinMaxData(serie, 1, -1); var diff = (serie.runtimeDataMax - serie.runtimeDataMin) / (count - 1); for (int j = 0; j < count; j++) { var serieData = serie.data[j]; var flag = Mathf.Abs(serieData.runtimeAngle - angle) < Mathf.Abs(diff / 2); if (serieData.highlighted != flag) { refresh = true; } serieData.highlighted = flag; if (flag) { m_Tooltip.runtimeAngle = (serieData.runtimeAngle - m_AngleAxis.runtimeStartAngle + 360) % 360; m_Tooltip.AddSerieDataIndex(serie.index, j); } } if (refresh) { RefreshChart(); } break; case SerieType.Bar: break; case SerieType.Scatter: case SerieType.EffectScatter: break; } } m_Tooltip.UpdateContentPos(local + m_Tooltip.offset); UpdateTooltip(); if (m_Tooltip.type == Tooltip.Type.Corss) { RefreshChart(); } }
private void InitRadiusAxis(RadiusAxis axis) { var m_Polar = GetPolar(axis.index); if (m_Polars == null) { return; } var m_AngleAxis = GetAngleAxis(m_Polar.index); if (m_AngleAxis == null) { return; } PolarHelper.UpdatePolarCenter(m_Polar, m_ChartPosition, m_ChartWidth, m_ChartHeight); axis.axisLabelTextList.Clear(); var radius = m_Polar.runtimeRadius; var objName = "axis_radius" + axis.index; var axisObj = ChartHelper.AddObject(objName, transform, graphAnchorMin, graphAnchorMax, chartPivot, new Vector2(chartWidth, chartHeight)); axisObj.transform.localPosition = Vector3.zero; axisObj.SetActive(axis.show && axis.axisLabel.show); axisObj.hideFlags = chartHideFlags; ChartHelper.HideAllObject(axisObj); var textStyle = axis.axisLabel.textStyle; var splitNumber = AxisHelper.GetSplitNumber(axis, radius, null); var totalWidth = 0f; var startAngle = m_AngleAxis.runtimeStartAngle; var cenPos = m_Polar.runtimeCenterPos; var txtHig = textStyle.GetFontSize(m_Theme.axis) + 2; var dire = ChartHelper.GetDire(startAngle, true).normalized; var tickWidth = axis.axisTick.GetLength(m_Theme.radiusAxis.tickWidth); var tickVetor = ChartHelper.GetVertialDire(dire) * (tickWidth + axis.axisLabel.margin); for (int i = 0; i < splitNumber; i++) { float labelWidth = AxisHelper.GetScaleWidth(axis, radius, i, null); bool inside = axis.axisLabel.inside; var txt = ChartHelper.AddTextObject(objName + i, axisObj.transform, new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f), new Vector2(labelWidth, txtHig), textStyle, m_Theme.axis); if (i == 0) { axis.axisLabel.SetRelatedText(txt, labelWidth); } var isPercentStack = SeriesHelper.IsPercentStack(m_Series, SerieType.Bar); var labelName = AxisHelper.GetLabelName(axis, radius, i, axis.runtimeMinValue, axis.runtimeMaxValue, null, isPercentStack); txt.SetAlignment(TextAnchor.MiddleCenter); txt.SetText(labelName); txt.SetActive(axis.show && (axis.axisLabel.interval == 0 || i % (axis.axisLabel.interval + 1) == 0)); var pos = ChartHelper.GetPos(cenPos, totalWidth, startAngle, true) + tickVetor; txt.SetLocalPosition(pos); AxisHelper.AdjustRadiusAxisLabelPos(txt, pos, cenPos, txtHig, Vector3.zero); axis.axisLabelTextList.Add(txt); totalWidth += labelWidth; } if (tooltip.runtimeGameObject) { Vector2 privot = new Vector2(0.5f, 1); var labelParent = tooltip.runtimeGameObject.transform; var labelName = ChartCached.GetAxisTooltipLabel(objName); GameObject labelObj = ChartHelper.AddTooltipLabel(labelName, labelParent, m_Theme, privot); axis.SetTooltipLabel(labelObj); axis.SetTooltipLabelColor(m_Theme.tooltip.labelBackgroundColor, m_Theme.tooltip.labelTextColor); axis.SetTooltipLabelActive(axis.show && tooltip.show && tooltip.type == Tooltip.Type.Corss); } }