private void DrawLabel(Serie serie, int dataIndex, SerieData serieData, Color serieColor) { if (serieData.labelObject == null) { return; } var currAngle = serieData.runtimePieHalfAngle; var isHighlight = (serieData.highlighted && serie.emphasis.label.show); var serieLabel = SerieHelper.GetSerieLabel(serie, serieData); var showLabel = ((serieLabel.show || isHighlight) && serieData.canShowLabel); if (showLabel || serieData.iconStyle.show) { serieData.SetLabelActive(showLabel); float rotate = 0; bool isInsidePosition = serieLabel.position == SerieLabel.Position.Inside; if (serieLabel.rotate > 0 && isInsidePosition) { if (currAngle > 180) { rotate += 270 - currAngle; } else { rotate += -(currAngle - 90); } } Color color = serieColor; if (isHighlight) { if (!ChartHelper.IsClearColor(serie.emphasis.label.color)) { color = serie.emphasis.label.color; } } else if (!ChartHelper.IsClearColor(serieLabel.color)) { color = serieLabel.color; } else { color = isInsidePosition ? Color.white : serieColor; } var fontSize = isHighlight ? serie.emphasis.label.fontSize : serieLabel.fontSize; var fontStyle = isHighlight ? serie.emphasis.label.fontStyle : serieLabel.fontStyle; serieData.labelObject.label.color = color; serieData.labelObject.label.fontSize = fontSize; serieData.labelObject.label.fontStyle = fontStyle; serieData.labelObject.SetLabelRotate(rotate); SerieLabelHelper.UpdatePieLabelPosition(serie, serieData); if (!string.IsNullOrEmpty(serieLabel.formatter)) { var value = serieData.data[1]; var total = serie.yTotal; var content = SerieLabelHelper.GetFormatterContent(serie, serieData, value, total, serieLabel); if (serieData.labelObject.SetText(content)) { RefreshChart(); } } else { if (serieData.labelObject.SetText(serieData.name)) { RefreshChart(); } } serieData.labelObject.SetPosition(SerieLabelHelper.GetRealLabelPosition(serieData, serieLabel)); if (showLabel) { serieData.labelObject.SetLabelPosition(serieLabel.offset); } else { serieData.SetLabelActive(false); } } else { serieData.SetLabelActive(false); } serieData.labelObject.UpdateIcon(serieData.iconStyle); }
private void InitLegend() { m_Legend.OnChanged(); TextAnchor anchor = m_Legend.location.textAnchor; Vector2 anchorMin = m_Legend.location.anchorMin; Vector2 anchorMax = m_Legend.location.anchorMax; Vector2 pivot = m_Legend.location.pivot; var legendObject = ChartHelper.AddObject(s_LegendObjectName, transform, anchorMin, anchorMax, pivot, new Vector2(chartWidth, chartHeight)); legendObject.transform.localPosition = m_Legend.location.GetPosition(chartWidth, chartHeight); m_LegendRealShowName = m_Series.GetSerieNameList(); List <string> datas; if (m_Legend.show && m_Legend.data.Count > 0) { datas = new List <string>(); for (int i = 0; i < m_LegendRealShowName.Count; i++) { if (m_Legend.data.Contains(m_LegendRealShowName[i])) { datas.Add(m_LegendRealShowName[i]); } } } else { datas = m_LegendRealShowName; } int totalLegend = 0; for (int i = 0; i < datas.Count; i++) { if (!m_Series.IsLegalLegendName(datas[i])) { continue; } totalLegend++; } m_Legend.RemoveButton(); ChartHelper.DestroyAllChildren(legendObject.transform); if (!m_Legend.show) { return; } for (int i = 0; i < datas.Count; i++) { if (!m_Series.IsLegalLegendName(datas[i])) { continue; } string legendName = m_Legend.GetFormatterContent(datas[i]); var readIndex = m_LegendRealShowName.IndexOf(datas[i]); var objName = s_LegendObjectName + "_" + i + "_" + datas[i]; Button btn = ChartHelper.AddButtonObject(objName, legendObject.transform, m_ThemeInfo.font, m_Legend.itemFontSize, m_ThemeInfo.legendTextColor, anchor, anchorMin, anchorMax, pivot, new Vector2(m_Legend.itemWidth, m_Legend.itemHeight)); var bgColor = IsActiveByLegend(datas[i]) ? m_ThemeInfo.GetColor(readIndex) : m_ThemeInfo.legendUnableColor; m_Legend.SetButton(legendName, btn, totalLegend); m_Legend.UpdateButtonColor(legendName, bgColor); btn.GetComponentInChildren <Text>().text = legendName; ChartHelper.ClearEventListener(btn.gameObject); ChartHelper.AddEventListener(btn.gameObject, EventTriggerType.PointerDown, (data) => { if (data.selectedObject == null || m_Legend.selectedMode == Legend.SelectedMode.None) { return; } var temp = data.selectedObject.name.Split('_'); string selectedName = temp[2]; int clickedIndex = int.Parse(temp[1]); if (m_Legend.selectedMode == Legend.SelectedMode.Multiple) { OnLegendButtonClick(clickedIndex, selectedName, !IsActiveByLegend(selectedName)); } else { var btnList = m_Legend.buttonList.Values.ToArray(); if (btnList.Length == 1) { OnLegendButtonClick(0, selectedName, !IsActiveByLegend(selectedName)); } else { for (int n = 0; n < btnList.Length; n++) { temp = btnList[n].name.Split('_'); selectedName = temp[2]; var index = int.Parse(temp[1]); OnLegendButtonClick(n, selectedName, index == clickedIndex ? true : false); } } } }); ChartHelper.AddEventListener(btn.gameObject, EventTriggerType.PointerEnter, (data) => { if (btn == null) { return; } var temp = btn.name.Split('_'); string selectedName = temp[2]; int index = int.Parse(temp[1]); OnLegendButtonEnter(index, selectedName); }); ChartHelper.AddEventListener(btn.gameObject, EventTriggerType.PointerExit, (data) => { if (btn == null) { return; } var temp = btn.name.Split('_'); string selectedName = temp[2]; int index = int.Parse(temp[1]); OnLegendButtonExit(index, selectedName); }); } if (m_Legend.selectedMode == Legend.SelectedMode.Single) { for (int n = 0; n < m_LegendRealShowName.Count; n++) { OnLegendButtonClick(n, m_LegendRealShowName[n], n == 0 ? true : false); } } }
protected override void OnDisable() { base.OnDisable(); ChartHelper.ActiveAllObject(transform, false); }
/// <summary> /// 绘制(圆角)边框 /// </summary> /// <param name="vh"></param> /// <param name="center"></param> /// <param name="rectWidth"></param> /// <param name="rectHeight"></param> /// <param name="borderWidth"></param> /// <param name="color"></param> /// <param name="rotate"></param> /// <param name="cornerRadius"></param> public static void DrawBorder(VertexHelper vh, Vector3 center, float rectWidth, float rectHeight, float borderWidth, Color32 color, float rotate = 0, float[] cornerRadius = null) { if (borderWidth == 0 || color == Color.clear) { return; } var halfWid = rectWidth / 2; var halfHig = rectHeight / 2; var lbIn = new Vector3(center.x - halfWid, center.y - halfHig); var lbOt = new Vector3(center.x - halfWid - borderWidth, center.y - halfHig - borderWidth); var ltIn = new Vector3(center.x - halfWid, center.y + halfHig); var ltOt = new Vector3(center.x - halfWid - borderWidth, center.y + halfHig + borderWidth); var rtIn = new Vector3(center.x + halfWid, center.y + halfHig); var rtOt = new Vector3(center.x + halfWid + borderWidth, center.y + halfHig + borderWidth); var rbIn = new Vector3(center.x + halfWid, center.y - halfHig); var rbOt = new Vector3(center.x + halfWid + borderWidth, center.y - halfHig - borderWidth); float brLt = 0, brRt = 0, brRb = 0, brLb = 0; bool needRound = false; InitCornerRadius(cornerRadius, rectWidth, rectHeight, ref brLt, ref brRt, ref brRb, ref brLb, ref needRound); var tempCenter = Vector3.zero; if (needRound) { var lbIn2 = lbIn; var lbOt2 = lbOt; var ltIn2 = ltIn; var ltOt2 = ltOt; var rtIn2 = rtIn; var rtOt2 = rtOt; var rbIn2 = rbIn; var rbOt2 = rbOt; if (brLt > 0) { tempCenter = new Vector3(center.x - halfWid + brLt, center.y + halfHig - brLt); DrawDoughnut(vh, tempCenter, brLt, brLt + borderWidth, color, Color.clear, 2, 270, 360); ltIn = tempCenter + brLt * Vector3.left; ltOt = tempCenter + (brLt + borderWidth) * Vector3.left; ltIn2 = tempCenter + brLt * Vector3.up; ltOt2 = tempCenter + (brLt + borderWidth) * Vector3.up; } if (brRt > 0) { tempCenter = new Vector3(center.x + halfWid - brRt, center.y + halfHig - brRt); DrawDoughnut(vh, tempCenter, brRt, brRt + borderWidth, color, Color.clear, 2, 0, 90); rtIn = tempCenter + brRt * Vector3.up; rtOt = tempCenter + (brRt + borderWidth) * Vector3.up; rtIn2 = tempCenter + brRt * Vector3.right; rtOt2 = tempCenter + (brRt + borderWidth) * Vector3.right; } if (brRb > 0) { tempCenter = new Vector3(center.x + halfWid - brRb, center.y - halfHig + brRb); DrawDoughnut(vh, tempCenter, brRb, brRb + borderWidth, color, Color.clear, 2, 90, 180); rbIn = tempCenter + brRb * Vector3.right; rbOt = tempCenter + (brRb + borderWidth) * Vector3.right; rbIn2 = tempCenter + brRb * Vector3.down; rbOt2 = tempCenter + (brRb + borderWidth) * Vector3.down; } if (brLb > 0) { tempCenter = new Vector3(center.x - halfWid + brLb, center.y - halfHig + brLb); DrawDoughnut(vh, tempCenter, brLb, brLb + borderWidth, color, Color.clear, 2, 180, 270); lbIn = tempCenter + brLb * Vector3.left; lbOt = tempCenter + (brLb + borderWidth) * Vector3.left; lbIn2 = tempCenter + brLb * Vector3.down; lbOt2 = tempCenter + (brLb + borderWidth) * Vector3.down; } DrawPolygon(vh, lbIn, lbOt, ltOt, ltIn, color); DrawPolygon(vh, ltIn2, ltOt2, rtOt, rtIn, color); DrawPolygon(vh, rtIn2, rtOt2, rbOt, rbIn, color); DrawPolygon(vh, rbIn2, rbOt2, lbOt2, lbIn2, color); } else { if (rotate > 0) { lbIn = ChartHelper.RotateRound(lbIn, center, Vector3.forward, rotate); lbOt = ChartHelper.RotateRound(lbOt, center, Vector3.forward, rotate); ltIn = ChartHelper.RotateRound(ltIn, center, Vector3.forward, rotate); ltOt = ChartHelper.RotateRound(ltOt, center, Vector3.forward, rotate); rtIn = ChartHelper.RotateRound(rtIn, center, Vector3.forward, rotate); rtOt = ChartHelper.RotateRound(rtOt, center, Vector3.forward, rotate); rbIn = ChartHelper.RotateRound(rbIn, center, Vector3.forward, rotate); rbOt = ChartHelper.RotateRound(rbOt, center, Vector3.forward, rotate); } DrawPolygon(vh, lbIn, lbOt, ltOt, ltIn, color); DrawPolygon(vh, ltIn, ltOt, rtOt, rtIn, color); DrawPolygon(vh, rtIn, rtOt, rbOt, rbIn, color); DrawPolygon(vh, rbIn, rbOt, lbOt, lbIn, color); } }
private void InitLegend() { m_Legend.OnChanged(); TextAnchor anchor = m_Legend.location.runtimeTextAnchor; Vector2 anchorMin = m_Legend.location.runtimeAnchorMin; Vector2 anchorMax = m_Legend.location.runtimeAnchorMax; Vector2 pivot = m_Legend.location.runtimePivot; var legendObject = ChartHelper.AddObject(s_LegendObjectName, transform, anchorMin, anchorMax, pivot, new Vector2(chartWidth, chartHeight)); legendObject.transform.localPosition = GetLegendPosition(); m_LegendRealShowName = m_Series.GetSerieNameList(); List <string> datas; if (m_Legend.show && m_Legend.data.Count > 0) { datas = new List <string>(); for (int i = 0; i < m_LegendRealShowName.Count; i++) { if (m_Legend.data.Contains(m_LegendRealShowName[i])) { datas.Add(m_LegendRealShowName[i]); } } } else { datas = m_LegendRealShowName; } int totalLegend = 0; for (int i = 0; i < datas.Count; i++) { if (!m_Series.IsLegalLegendName(datas[i])) { continue; } totalLegend++; } m_Legend.RemoveButton(); ChartHelper.HideAllObject(legendObject); if (!m_Legend.show) { return; } for (int i = 0; i < datas.Count; i++) { if (!m_Series.IsLegalLegendName(datas[i])) { continue; } string legendName = m_Legend.GetFormatterContent(datas[i]); var readIndex = m_LegendRealShowName.IndexOf(datas[i]); var active = IsActiveByLegend(datas[i]); var bgColor = LegendHelper.GetIconColor(m_Legend, readIndex, themeInfo, active); var item = LegendHelper.AddLegendItem(m_Legend, i, datas[i], legendObject.transform, m_ThemeInfo, legendName, bgColor, active); m_Legend.SetButton(legendName, item, totalLegend); ChartHelper.ClearEventListener(item.button.gameObject); ChartHelper.AddEventListener(item.button.gameObject, EventTriggerType.PointerDown, (data) => { if (data.selectedObject == null || m_Legend.selectedMode == Legend.SelectedMode.None) { return; } var temp = data.selectedObject.name.Split('_'); string selectedName = temp[1]; int clickedIndex = int.Parse(temp[0]); if (m_Legend.selectedMode == Legend.SelectedMode.Multiple) { OnLegendButtonClick(clickedIndex, selectedName, !IsActiveByLegend(selectedName)); } else { var btnList = m_Legend.buttonList.Values.ToArray(); if (btnList.Length == 1) { OnLegendButtonClick(0, selectedName, !IsActiveByLegend(selectedName)); } else { for (int n = 0; n < btnList.Length; n++) { temp = btnList[n].name.Split('_'); selectedName = btnList[n].legendName; var index = btnList[n].index; OnLegendButtonClick(n, selectedName, index == clickedIndex ? true : false); } } } }); ChartHelper.AddEventListener(item.button.gameObject, EventTriggerType.PointerEnter, (data) => { if (item.button == null) { return; } var temp = item.button.name.Split('_'); string selectedName = temp[1]; int index = int.Parse(temp[0]); OnLegendButtonEnter(index, selectedName); }); ChartHelper.AddEventListener(item.button.gameObject, EventTriggerType.PointerExit, (data) => { if (item.button == null) { return; } var temp = item.button.name.Split('_'); string selectedName = temp[1]; int index = int.Parse(temp[0]); OnLegendButtonExit(index, selectedName); }); } if (m_Legend.selectedMode == Legend.SelectedMode.Single) { for (int n = 0; n < m_LegendRealShowName.Count; n++) { OnLegendButtonClick(n, m_LegendRealShowName[n], n == 0 ? true : false); } } LegendHelper.ResetItemPosition(m_Legend); }
public void Copy(AxisSplitArea splitArea) { show = splitArea.show; color.Clear(); ChartHelper.CopyList(color, splitArea.color); }
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(); } }
public string GetFormatterContent(float value, float minValue, float maxValue, bool isLog = false) { if (showAsPositiveNumber && value < 0) { value = Mathf.Abs(value); } if (string.IsNullOrEmpty(m_Formatter)) { if (isLog) { if (value - (int)value == 0) { return(ChartCached.IntToStr((int)value)); } else { return(ChartCached.FloatToStr(value)); } } if (minValue >= -1 && minValue <= 1 && maxValue >= -1 && maxValue <= 1) { int minAcc = ChartHelper.GetFloatAccuracy(minValue); int maxAcc = ChartHelper.GetFloatAccuracy(maxValue); int curAcc = ChartHelper.GetFloatAccuracy(value); int acc = Mathf.Max(Mathf.Max(minAcc, maxAcc), curAcc); return(ChartCached.FloatToStr(value, acc, m_ForceENotation)); } else if (value - (int)value == 0) { return(ChartCached.IntToStr((int)value)); } else { return(ChartCached.FloatToStr(value, 1)); } } else if (m_Formatter.Contains("{value")) { var content = m_Formatter; if (content.Contains("{value:f0}")) { content = m_Formatter.Replace("{value:f0}", ChartCached.IntToStr((int)value)); } if (content.Contains("{value:f2}")) { content = m_Formatter.Replace("{value:f2}", ChartCached.FloatToStr(value, 2)); } else if (content.Contains("{value:f1}")) { content = m_Formatter.Replace("{value:f1}", ChartCached.FloatToStr(value, 1)); } else if (content.Contains("{value}")) { if (value - (int)value == 0) { content = m_Formatter.Replace("{value}", ChartCached.IntToStr((int)value)); } else { content = m_Formatter.Replace("{value}", ChartCached.FloatToStr(value, 1)); } } content = content.Replace("\\n", "\n"); content = content.Replace("<br/>", "\n"); return(content); } else { return(value.ToString(m_Formatter)); } }
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); } }
protected void DrawHeatmapSerie(VertexHelper vh, int colorIndex, Serie serie) { if (serie.animation.HasFadeOut()) { return; } var yAxis = m_YAxes[serie.yAxisIndex]; var xAxis = m_XAxes[serie.xAxisIndex]; xAxis.boundaryGap = true; yAxis.boundaryGap = true; var grid = GetSerieGridOrDefault(serie); var xCount = xAxis.data.Count; var yCount = yAxis.data.Count; var xWidth = grid.runtimeWidth / xCount; var yWidth = grid.runtimeHeight / yCount; var zeroX = grid.runtimeX; var zeroY = grid.runtimeY; var dataList = serie.GetDataList(); var rangeMin = visualMap.rangeMin; var rangeMax = visualMap.rangeMax; var color = m_Theme.GetColor(serie.index); var borderWidth = serie.itemStyle.show ? serie.itemStyle.borderWidth : 0; var borderColor = serie.itemStyle.opacity > 0 ? serie.itemStyle.borderColor : ChartConst.clearColor32; borderColor.a = (byte)(borderColor.a * serie.itemStyle.opacity); var borderToColor = serie.itemStyle.opacity > 0 ? serie.itemStyle.borderToColor : ChartConst.clearColor32; borderToColor.a = (byte)(borderToColor.a * serie.itemStyle.opacity); serie.dataPoints.Clear(); serie.animation.InitProgress(1, 0, xCount); var animationIndex = serie.animation.GetCurrIndex(); var dataChangeDuration = serie.animation.GetUpdateAnimationDuration(); var dataChanging = false; for (int i = 0; i < xCount; i++) { for (int j = 0; j < yCount; j++) { var dataIndex = i * yCount + j; if (dataIndex >= dataList.Count) { continue; } var serieData = dataList[dataIndex]; var dimension = VisualMapHelper.GetDimension(visualMap, serieData.data.Count); if (serie.IsIgnoreIndex(dataIndex, dimension)) { serie.dataPoints.Add(Vector3.zero); continue; } var value = serieData.GetCurrData(dimension, dataChangeDuration, yAxis.inverse, yAxis.runtimeMinValue, yAxis.runtimeMaxValue); if (serieData.IsDataChanged()) { dataChanging = true; } var pos = new Vector3(zeroX + (i + (xAxis.boundaryGap ? 0.5f : 0)) * xWidth, zeroY + (j + (yAxis.boundaryGap ? 0.5f : 0)) * yWidth); serie.dataPoints.Add(pos); serieData.canShowLabel = false; if (value == 0) { continue; } if (visualMap.enable) { if ((value < rangeMin && rangeMin != visualMap.min) || (value > rangeMax && rangeMax != visualMap.max)) { continue; } if (!visualMap.IsInSelectedValue(value)) { continue; } color = visualMap.GetColor(value); } if (animationIndex >= 0 && i > animationIndex) { continue; } serieData.canShowLabel = true; var emphasis = (tooltip.show && i == (int)tooltip.runtimeXValues[0] && j == (int)tooltip.runtimeYValues[0]) || visualMap.runtimeSelectedIndex > 0; var rectWid = xWidth - 2 * borderWidth; var rectHig = yWidth - 2 * borderWidth; UGL.DrawRectangle(vh, pos, rectWid / 2, rectHig / 2, color); if (borderWidth > 0 && !ChartHelper.IsClearColor(borderColor)) { UGL.DrawBorder(vh, pos, rectWid, rectHig, borderWidth, borderColor, borderToColor); } if (visualMap.hoverLink && emphasis && serie.emphasis.show && serie.emphasis.itemStyle.borderWidth > 0) { var emphasisBorderWidth = serie.emphasis.itemStyle.borderWidth; var emphasisBorderColor = serie.emphasis.itemStyle.opacity > 0 ? serie.emphasis.itemStyle.borderColor : ChartConst.clearColor32; var emphasisBorderToColor = serie.emphasis.itemStyle.opacity > 0 ? serie.emphasis.itemStyle.borderToColor : ChartConst.clearColor32; UGL.DrawBorder(vh, pos, rectWid, rectHig, emphasisBorderWidth, emphasisBorderColor, emphasisBorderToColor); } } } if (!serie.animation.IsFinish()) { serie.animation.CheckProgress(xCount); m_IsPlayingAnimation = true; RefreshPainter(serie); } if (dataChanging) { RefreshPainter(serie); } }
/// <summary> /// 是否需要显示边框。 /// </summary> public bool NeedShowBorder() { return(borderWidth != 0 && !ChartHelper.IsClearColor(borderColor)); }
protected override void DrawChart(VertexHelper vh) { base.DrawChart(vh); serieNameSet.Clear(); int serieNameCount = -1; bool isClickOffset = false; bool isDataHighlight = false; for (int i = 0; i < m_Series.Count; i++) { var serie = m_Series.series[i]; serie.index = i; var data = serie.data; serie.animation.InitProgress(data.Count, 0, 360); if (!serie.show) { continue; } if (!serie.animation.NeedAnimation(i)) { break; } bool isFinish = true; if (serie.pieClickOffset) { isClickOffset = true; } PieTempData tempData; if (i < m_PieTempDataList.Count) { tempData = m_PieTempDataList[i]; tempData.angleList.Clear(); } else { tempData = new PieTempData(); m_PieTempDataList.Add(tempData); } tempData.angleList.Clear(); tempData.dataMax = serie.yMax; tempData.dataTotal = serie.yTotal; UpdatePieCenter(serie); float totalDegree = 360; float startDegree = 0; int showdataCount = 0; foreach (var sd in serie.data) { if (sd.show && serie.pieRoseType == RoseType.Area) { showdataCount++; } sd.canShowLabel = false; } for (int n = 0; n < data.Count; n++) { var serieData = data[n]; float value = serieData.data[1]; string dataName = serieData.name; Color color; if (string.IsNullOrEmpty(dataName)) { serieNameCount++; color = m_ThemeInfo.GetColor(serieNameCount); } else if (!serieNameSet.ContainsKey(dataName)) { serieNameSet.Add(dataName, serieNameCount); serieNameCount++; color = m_ThemeInfo.GetColor(serieNameCount); } else { color = m_ThemeInfo.GetColor(serieNameSet[dataName]); } if (!serieData.show) { tempData.angleList.Add(0); continue; } float degree = serie.pieRoseType == RoseType.Area ? (totalDegree / showdataCount) : (totalDegree * value / tempData.dataTotal); float toDegree = startDegree + degree; float outSideRadius = serie.pieRoseType > 0 ? tempData.insideRadius + (tempData.outsideRadius - tempData.insideRadius) * value / tempData.dataMax : tempData.outsideRadius; if (serieData.highlighted) { isDataHighlight = true; color *= 1.2f; outSideRadius += m_Pie.tooltipExtraRadius; } var offset = serie.pieSpace; if (serie.pieClickOffset && serieData.selected) { offset += m_Pie.selectedOffset; } var halfDegree = (toDegree - startDegree) / 2; float currAngle = startDegree + halfDegree; float currRad = currAngle * Mathf.Deg2Rad; float currSin = Mathf.Sin(currRad); float currCos = Mathf.Cos(currRad); var center = tempData.center; var currDegree = toDegree; if (serie.animation.CheckDetailBreak(n, toDegree)) { isFinish = false; currDegree = serie.animation.GetCurrDetail(); } if (offset > 0) { float offsetRadius = serie.pieSpace / Mathf.Sin(halfDegree * Mathf.Deg2Rad); var insideRadius = tempData.insideRadius - offsetRadius; var outsideRadius = outSideRadius - offsetRadius; if (serie.pieClickOffset && serieData.selected) { offsetRadius += m_Pie.selectedOffset; if (insideRadius > 0) { insideRadius += m_Pie.selectedOffset; } outsideRadius += m_Pie.selectedOffset; } var offestCenter = new Vector3(center.x + offsetRadius * currSin, center.y + offsetRadius * currCos); ChartHelper.DrawDoughnut(vh, offestCenter, insideRadius, outsideRadius, startDegree, currDegree, color); } else { ChartHelper.DrawDoughnut(vh, center, tempData.insideRadius, outSideRadius, startDegree, currDegree, color); } serieData.canShowLabel = currDegree >= currAngle; if (currDegree >= currAngle) { DrawLabelLine(vh, serie, tempData, outSideRadius, center, currAngle, color); } isDrawPie = true; tempData.angleList.Add(toDegree); startDegree = toDegree; if (isFinish) { serie.animation.SetDataFinish(n); } else { break; } } if (!serie.animation.IsFinish()) { float duration = serie.animation.duration > 0 ? (float)serie.animation.duration / 1000 : 1; float speed = 360 / duration; float symbolSpeed = serie.symbol.size / duration; serie.animation.CheckProgress(Time.deltaTime * speed); serie.animation.CheckSymbol(Time.deltaTime * symbolSpeed, serie.symbol.size); RefreshChart(); } } DrawLabelBackground(vh); raycastTarget = isClickOffset && isDataHighlight; }
internal void SetTooltipLabelActive(bool flag) { ChartHelper.SetActive(m_TooltipLabel, flag); }
private void DrawYLineSerie(VertexHelper vh, int serieIndex, Color color, Serie serie, ref int dataCount, ref List <Vector3> points, ref List <int> pointSerieIndexs, ref List <float> seriesHig) { if (!IsActive(serie.index)) { return; } lastPoints.Clear(); lastSmoothPoints.Clear(); smoothPoints.Clear(); Vector3 lp = Vector3.zero; Vector3 np = Vector3.zero; 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 = coordinateY + (yAxis.boundaryGap ? scaleWid / 2 : 0); int maxCount = maxShowDataNumber > 0 ? (maxShowDataNumber > serie.yData.Count ? serie.yData.Count : maxShowDataNumber) : serie.yData.Count; dataCount = (maxCount - minShowDataNumber); if (m_Line.area && points.Count > 0) { if (!m_Line.smooth && points.Count > 0) { for (int m = points.Count - dataCount; m < points.Count; m++) { lastPoints.Add(points[m]); } } else if (m_Line.smooth && smoothPoints.Count > 0) { for (int m = 0; m < smoothPoints.Count; m++) { lastSmoothPoints.Add(smoothPoints[m]); } smoothPoints.Clear(); } } int smoothPointCount = 1; if (seriesHig.Count < minShowDataNumber) { for (int i = 0; i < minShowDataNumber; i++) { seriesHig.Add(0); } } for (int i = minShowDataNumber; i < maxCount; i++) { if (i >= seriesHig.Count) { seriesHig.Add(0); } float value = serie.yData[i]; float pY = startY + i * scaleWid; float pX = seriesHig[i] + coordinateX + m_Coordinate.tickness; float dataHig = (value - xAxis.minValue) / (xAxis.maxValue - xAxis.minValue) * coordinateWid; np = new Vector3(pX + dataHig, pY); if (i > 0) { if (m_Line.step) { Vector2 middle1, middle2; switch (m_Line.stepTpe) { case Line.StepType.Start: middle1 = new Vector2(np.x, lp.y); middle2 = new Vector2(np.x, lp.y - m_Line.tickness); ChartHelper.DrawLine(vh, lp, middle1, m_Line.tickness, color); ChartHelper.DrawLine(vh, middle2, np, m_Line.tickness, color); if (m_Line.area) { Color areaColor = new Color(color.r, color.g, color.b, color.a * 0.75f); ChartHelper.DrawPolygon(vh, new Vector2(coordinateX, middle1.y), middle1, np, new Vector2(coordinateX, np.y), areaColor); } break; case Line.StepType.Middle: middle1 = new Vector2(lp.x, (lp.y + np.y) / 2 + m_Line.tickness); middle2 = new Vector2(np.x, (lp.y + np.y) / 2 - m_Line.tickness); ChartHelper.DrawLine(vh, lp, middle1, m_Line.tickness, color); ChartHelper.DrawLine(vh, new Vector2(middle1.x, middle1.y - m_Line.tickness), new Vector2(middle2.x, middle2.y + m_Line.tickness), m_Line.tickness, color); ChartHelper.DrawLine(vh, middle2, np, m_Line.tickness, color); if (m_Line.area) { Color areaColor = new Color(color.r, color.g, color.b, color.a * 0.75f); ChartHelper.DrawPolygon(vh, new Vector2(coordinateX, lp.y), lp, middle1, new Vector2(coordinateX, middle1.y), areaColor); ChartHelper.DrawPolygon(vh, new Vector2(coordinateX, middle2.y + 2 * m_Line.tickness), new Vector2(middle2.x, middle2.y + 2 * m_Line.tickness), np, new Vector2(coordinateX, np.y), areaColor); } break; case Line.StepType.End: middle1 = new Vector2(np.x, lp.y); middle2 = new Vector2(np.x, lp.y - m_Line.tickness); ChartHelper.DrawLine(vh, lp, middle1, m_Line.tickness, color); ChartHelper.DrawLine(vh, middle2, np, m_Line.tickness, color); if (m_Line.area) { Color areaColor = new Color(color.r, color.g, color.b, color.a * 0.75f); ChartHelper.DrawPolygon(vh, new Vector2(coordinateX, lp.y), middle1, new Vector2(np.x, np.y), new Vector2(coordinateX, np.y), areaColor); } break; } } else if (m_Line.smooth) { ChartHelper.GetBezierListVertical(ref smoothSegmentPoints, lp, np, m_Line.smoothStyle); Vector3 start, to; start = smoothSegmentPoints[0]; for (int k = 1; k < smoothSegmentPoints.Count; k++) { smoothPoints.Add(smoothSegmentPoints[k]); to = smoothSegmentPoints[k]; ChartHelper.DrawLine(vh, start, to, m_Line.tickness, color); if (m_Line.area) { Vector3 alp = new Vector3(start.x, start.y - m_Line.tickness); Vector3 anp = new Vector3(to.x, to.y - m_Line.tickness); Vector3 tnp = serieIndex > 0 ? (smoothPointCount > lastSmoothPoints.Count - 1 ? new Vector3(lastSmoothPoints[lastSmoothPoints.Count - 1].x, lastSmoothPoints[lastSmoothPoints.Count - 1].y + m_Line.tickness) : new Vector3(lastSmoothPoints[smoothPointCount].x, lastSmoothPoints[smoothPointCount].y + m_Line.tickness)) : new Vector3(coordinateX + m_Coordinate.tickness, to.y); Vector3 tlp = serieIndex > 0 ? (smoothPointCount > lastSmoothPoints.Count - 1 ? new Vector3(lastSmoothPoints[lastSmoothPoints.Count - 2].x, lastSmoothPoints[lastSmoothPoints.Count - 2].y + m_Line.tickness) : new Vector3(lastSmoothPoints[smoothPointCount - 1].x, lastSmoothPoints[smoothPointCount - 1].y + m_Line.tickness)) : new Vector3(coordinateX + m_Coordinate.tickness, start.y); Color areaColor = new Color(color.r, color.g, color.b, color.a * 0.75f); ChartHelper.DrawPolygon(vh, alp, anp, tnp, tlp, areaColor); } smoothPointCount++; start = to; } } else { ChartHelper.DrawLine(vh, lp, np, m_Line.tickness, color); if (m_Line.area) { Vector3 alp = new Vector3(lp.x, lp.y); Vector3 anp = new Vector3(np.x, np.y); Color areaColor = new Color(color.r, color.g, color.b, color.a * 0.75f); var cross = ChartHelper.GetIntersection(lp, np, new Vector3(coordinateX, coordinateY), new Vector3(coordinateX, coordinateY + coordinateHig)); if (cross == Vector3.zero) { Vector3 tnp = serieIndex > 0 ? new Vector3(lastPoints[i].x + m_Coordinate.tickness, lastPoints[i].y) : new Vector3(coordinateX + m_Coordinate.tickness, np.y); Vector3 tlp = serieIndex > 0 ? new Vector3(lastPoints[i - 1].x + m_Coordinate.tickness, lastPoints[i - 1].y) : new Vector3(coordinateX + m_Coordinate.tickness, lp.y); ChartHelper.DrawPolygon(vh, alp, anp, tnp, tlp, areaColor); } else { Vector3 cross1 = new Vector3(cross.x + (alp.x > coordinateX ? m_Coordinate.tickness : -m_Coordinate.tickness), cross.y); Vector3 cross2 = new Vector3(cross.x + (anp.x > coordinateX ? m_Coordinate.tickness : -m_Coordinate.tickness), cross.y); Vector3 xp1 = new Vector3(coordinateX + (alp.x > coordinateX ? m_Coordinate.tickness : -m_Coordinate.tickness), alp.y); Vector3 xp2 = new Vector3(coordinateX + (anp.x > coordinateX ? m_Coordinate.tickness : -m_Coordinate.tickness), anp.y); ChartHelper.DrawTriangle(vh, alp, cross1, xp1, areaColor); ChartHelper.DrawTriangle(vh, anp, cross2, xp2, areaColor); } } } } if (serie.symbol.type != SerieSymbolType.None || m_Line.area) { points.Add(np); pointSerieIndexs.Add(serie.index); } seriesHig[i] += dataHig; lp = np; } }
/// <summary> /// 调整最大最小值 /// </summary> /// <param name="minValue"></param> /// <param name="maxValue"></param> public static void AdjustMinMaxValue(Axis axis, ref double minValue, ref double maxValue, bool needFormat, int ceilRate = 0) { if (axis.type == Axis.AxisType.Log) { int minSplit = 0; int maxSplit = 0; maxValue = ChartHelper.GetMaxLogValue(maxValue, axis.logBase, axis.logBaseE, out maxSplit); minValue = ChartHelper.GetMinLogValue(minValue, axis.logBase, axis.logBaseE, out minSplit); axis.splitNumber = (minSplit > 0 && maxSplit > 0) ? (maxSplit + minSplit - 1) : (maxSplit + minSplit); return; } if (axis.minMaxType == Axis.AxisMinMaxType.Custom) { if (axis.min != 0 || axis.max != 0) { if (axis.inverse) { minValue = -axis.max; maxValue = -axis.min; } else { minValue = axis.min; maxValue = axis.max; } } } else { if (ceilRate == 0) { ceilRate = axis.ceilRate; } switch (axis.minMaxType) { case Axis.AxisMinMaxType.Default: if (minValue == 0 && maxValue == 0) { } else if (minValue > 0 && maxValue > 0) { minValue = 0; maxValue = needFormat ? ChartHelper.GetMaxDivisibleValue(maxValue, ceilRate) : maxValue; } else if (minValue < 0 && maxValue < 0) { minValue = needFormat ? ChartHelper.GetMinDivisibleValue(minValue, ceilRate) : minValue; maxValue = 0; } else { minValue = needFormat ? ChartHelper.GetMinDivisibleValue(minValue, ceilRate) : minValue; maxValue = needFormat ? ChartHelper.GetMaxDivisibleValue(maxValue, ceilRate) : maxValue; } break; case Axis.AxisMinMaxType.MinMax: minValue = needFormat ? ChartHelper.GetMinDivisibleValue(minValue, ceilRate) : minValue; maxValue = needFormat ? ChartHelper.GetMaxDivisibleValue(maxValue, ceilRate) : maxValue; break; } } double tempRange = maxValue - minValue; if (axis.runtimeMinMaxRange != tempRange) { axis.runtimeMinMaxRange = tempRange; if (axis.type == Axis.AxisType.Value && axis.interval > 0) { axis.SetComponentDirty(); } } }
private void InitAngleAxis(AngleAxis axis) { var m_Polar = GetPolar(axis.polarIndex); if (m_Polars == null) { return; } PolarHelper.UpdatePolarCenter(m_Polar, m_ChartPosition, m_ChartWidth, m_ChartHeight); var radius = m_Polar.runtimeRadius; axis.axisLabelTextList.Clear(); string objName = "axis_angle" + 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 splitNumber = AxisHelper.GetSplitNumber(axis, radius, null); var totalAngle = axis.runtimeStartAngle; var total = 360; var cenPos = m_Polar.runtimeCenterPos; var txtHig = axis.axisLabel.textStyle.GetFontSize(m_Theme.axis) + 2; var margin = axis.axisLabel.margin; var isCategory = axis.IsCategory(); var isPercentStack = SeriesHelper.IsPercentStack(m_Series, SerieType.Bar); for (int i = 0; i < splitNumber; i++) { float scaleAngle = AxisHelper.GetScaleWidth(axis, total, 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(scaleAngle, txtHig), axis.axisLabel.textStyle, m_Theme.axis); txt.SetAlignment(TextAnchor.MiddleCenter); txt.SetText(AxisHelper.GetLabelName(axis, total, i, axis.runtimeMinValue, axis.runtimeMaxValue, null, isPercentStack)); txt.SetActive(axis.show && (axis.axisLabel.interval == 0 || i % (axis.axisLabel.interval + 1) == 0)); var pos = ChartHelper.GetPos(cenPos, radius + margin, isCategory ? (totalAngle + scaleAngle / 2) : totalAngle, true); AxisHelper.AdjustCircleLabelPos(txt, pos, cenPos, txtHig, Vector3.zero); if (i == 0) { axis.axisLabel.SetRelatedText(txt, scaleAngle); } axis.axisLabelTextList.Add(txt); totalAngle += scaleAngle; } if (tooltip.runtimeGameObject) { Vector2 privot = new Vector2(0.5f, 0.5f); var labelParent = tooltip.runtimeGameObject.transform; GameObject labelObj = ChartHelper.AddTooltipLabel(ChartCached.GetAxisTooltipLabel(objName), labelParent, m_Theme, privot, privot, privot, new Vector2(10, txtHig)); axis.SetTooltipLabel(labelObj); axis.SetTooltipLabelColor(m_Theme.tooltip.labelBackgroundColor, m_Theme.tooltip.labelTextColor); axis.SetTooltipLabelActive(axis.show && tooltip.show && tooltip.type == Tooltip.Type.Corss); } }
private void DrawXCategory(VertexHelper vh) { 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>(); List <Color> colorList = new List <Color>(); int dataCount = 0; for (int j = 0; j < seriesCount; j++) { var seriesCurrHig = new Dictionary <int, float>(); var serieList = stackSeries[j]; for (int n = 0; n < serieList.Count; n++) { Serie serie = serieList[n]; if (!IsActive(serie.name)) { continue; } List <Vector3> lastPoints = new List <Vector3>(); List <Vector3> lastSmoothPoints = new List <Vector3>(); List <float> serieData = serie.GetData(m_DataZoom); Color color = m_ThemeInfo.GetColor(serieCount); Vector3 lp = Vector3.zero; Vector3 np = Vector3.zero; float startX = zeroX + (m_XAxis.boundaryGap ? scaleWid / 2 : 0); int maxCount = maxShowDataNumber > 0 ? (maxShowDataNumber > serieData.Count ? serieData.Count : maxShowDataNumber) : serieData.Count; dataCount = (maxCount - minShowDataNumber); if (m_Line.area && points.Count > 0) { if (!m_Line.smooth && points.Count > 0) { for (int m = points.Count - dataCount; m < points.Count; m++) { lastPoints.Add(points[m]); } } else if (m_Line.smooth && smoothPoints.Count > 0) { for (int m = 0; m < smoothPoints.Count; m++) { lastSmoothPoints.Add(smoothPoints[m]); } smoothPoints.Clear(); } } int smoothPointCount = 1; for (int i = minShowDataNumber; i < maxCount; i++) { if (!seriesCurrHig.ContainsKey(i)) { seriesCurrHig[i] = 0; } float value = serieData[i]; float pX = startX + i * scaleWid; float pY = seriesCurrHig[i] + coordinateY + m_Coordinate.tickness; float dataHig = (value - minValue) / (maxValue - minValue) * coordinateHig; np = new Vector3(pX, pY + dataHig); if (i > 0) { if (m_Line.step) { Vector2 middle1, middle2; switch (m_Line.stepTpe) { case Line.StepType.Start: middle1 = new Vector2(lp.x, np.y + m_Line.tickness); middle2 = new Vector2(lp.x - m_Line.tickness, np.y); ChartHelper.DrawLine(vh, lp, middle1, m_Line.tickness, color); ChartHelper.DrawLine(vh, middle2, np, m_Line.tickness, color); if (m_Line.area) { Color areaColor = new Color(color.r, color.g, color.b, color.a * 0.75f); ChartHelper.DrawPolygon(vh, new Vector2(middle1.x, zeroY), middle1, np, new Vector2(np.x, zeroY), areaColor); } break; case Line.StepType.Middle: middle1 = new Vector2((lp.x + np.x) / 2 + m_Line.tickness, lp.y); middle2 = new Vector2((lp.x + np.x) / 2 - m_Line.tickness, np.y); ChartHelper.DrawLine(vh, lp, middle1, m_Line.tickness, color); ChartHelper.DrawLine(vh, new Vector2(middle1.x - m_Line.tickness, middle1.y), new Vector2(middle2.x + m_Line.tickness, middle2.y), m_Line.tickness, color); ChartHelper.DrawLine(vh, middle2, np, m_Line.tickness, color); if (m_Line.area) { Color areaColor = new Color(color.r, color.g, color.b, color.a * 0.75f); ChartHelper.DrawPolygon(vh, new Vector2(lp.x, zeroY), lp, middle1, new Vector2(middle1.x, zeroY), areaColor); ChartHelper.DrawPolygon(vh, new Vector2(middle2.x + 2 * m_Line.tickness, zeroY), new Vector2(middle2.x + 2 * m_Line.tickness, middle2.y), np, new Vector2(np.x, zeroY), areaColor); } break; case Line.StepType.End: middle1 = new Vector2(np.x + m_Line.tickness, lp.y); middle2 = new Vector2(np.x, lp.y); ChartHelper.DrawLine(vh, lp, middle1, m_Line.tickness, color); ChartHelper.DrawLine(vh, middle2, np, m_Line.tickness, color); if (m_Line.area) { Color areaColor = new Color(color.r, color.g, color.b, color.a * 0.75f); ChartHelper.DrawPolygon(vh, new Vector2(lp.x, zeroY), lp, new Vector2(middle1.x - m_Line.tickness, middle1.y), new Vector2(middle1.x - m_Line.tickness, zeroY), areaColor); } break; } } else if (m_Line.smooth) { var list = ChartHelper.GetBezierList(lp, np, m_Line.smoothStyle); Vector3 start, to; start = list[0]; for (int k = 1; k < list.Length; k++) { smoothPoints.Add(list[k]); to = list[k]; ChartHelper.DrawLine(vh, start, to, m_Line.tickness, color); if (m_Line.area) { Vector3 alp = new Vector3(start.x, start.y - m_Line.tickness); Vector3 anp = new Vector3(to.x, to.y - m_Line.tickness); Vector3 tnp = serieCount > 0 ? (smoothPointCount > lastSmoothPoints.Count - 1 ? new Vector3(lastSmoothPoints[lastSmoothPoints.Count - 1].x, lastSmoothPoints[lastSmoothPoints.Count - 1].y + m_Line.tickness) : new Vector3(lastSmoothPoints[smoothPointCount].x, lastSmoothPoints[smoothPointCount].y + m_Line.tickness)) : new Vector3(to.x, zeroY + m_Coordinate.tickness); Vector3 tlp = serieCount > 0 ? (smoothPointCount > lastSmoothPoints.Count - 1 ? new Vector3(lastSmoothPoints[lastSmoothPoints.Count - 2].x, lastSmoothPoints[lastSmoothPoints.Count - 2].y + m_Line.tickness) : new Vector3(lastSmoothPoints[smoothPointCount - 1].x, lastSmoothPoints[smoothPointCount - 1].y + m_Line.tickness)) : new Vector3(start.x, zeroY + m_Coordinate.tickness); Color areaColor = new Color(color.r, color.g, color.b, color.a * 0.75f); ChartHelper.DrawPolygon(vh, alp, anp, tnp, tlp, areaColor); } smoothPointCount++; start = to; } } else { ChartHelper.DrawLine(vh, lp, np, m_Line.tickness, color); if (m_Line.area) { Vector3 alp = new Vector3(lp.x, lp.y - m_Line.tickness); Vector3 anp = new Vector3(np.x, np.y - m_Line.tickness); Color areaColor = new Color(color.r, color.g, color.b, color.a * 0.75f); var cross = ChartHelper.GetIntersection(lp, np, new Vector3(zeroX, zeroY), new Vector3(zeroX + coordinateWid, zeroY)); if (cross == Vector3.zero) { Vector3 tnp = serieCount > 0 ? new Vector3(lastPoints[i].x, lastPoints[i].y + m_Line.tickness) : new Vector3(np.x, zeroY + m_Coordinate.tickness); Vector3 tlp = serieCount > 0 ? new Vector3(lastPoints[i - 1].x, lastPoints[i - 1].y + m_Line.tickness) : new Vector3(lp.x, zeroY + m_Coordinate.tickness); ChartHelper.DrawPolygon(vh, alp, anp, tnp, tlp, areaColor); } else { Vector3 cross1 = new Vector3(cross.x, cross.y + (alp.y > zeroY ? m_Coordinate.tickness : -m_Coordinate.tickness)); Vector3 cross2 = new Vector3(cross.x, cross.y + (anp.y > zeroY ? m_Coordinate.tickness : -m_Coordinate.tickness)); Vector3 xp1 = new Vector3(alp.x, zeroY + (alp.y > zeroY ? m_Coordinate.tickness : -m_Coordinate.tickness)); Vector3 xp2 = new Vector3(anp.x, zeroY + (anp.y > zeroY ? m_Coordinate.tickness : -m_Coordinate.tickness)); ChartHelper.DrawTriangle(vh, alp, cross1, xp1, areaColor); ChartHelper.DrawTriangle(vh, anp, cross2, xp2, areaColor); } } } } if (m_Line.point) { points.Add(np); colorList.Add(color); } seriesCurrHig[i] += dataHig; lp = np; } if (serie.show) { serieCount++; } } // draw point if (m_Line.point) { for (int i = 0; i < points.Count; i++) { Vector3 p = points[i]; float pointWid = m_Line.pointWidth; if (m_Tooltip.show && i % dataCount == m_Tooltip.dataIndex - 1) { pointWid = pointWid * 1.8f; } if (m_Theme == Theme.Dark) { ChartHelper.DrawCricle(vh, p, pointWid, colorList[i], (int)m_Line.pointWidth * 5); } else { ChartHelper.DrawCricle(vh, p, pointWid, Color.white); ChartHelper.DrawDoughnut(vh, p, pointWid - m_Line.tickness, pointWid, 0, 360, colorList[i]); } } } } //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) { 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); } } }
private void DrawYBarSerie(VertexHelper vh, int serieIndex, int stackCount, Serie serie, int colorIndex, ref List <float> seriesHig) { if (!IsActive(serie.name)) { return; } 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 categoryWidth = yAxis.GetDataWidth(coordinateHig, m_DataZoom); float barGap = GetBarGap(); float totalBarWidth = GetBarTotalWidth(categoryWidth, barGap); float barWidth = serie.GetBarWidth(categoryWidth); float offset = (categoryWidth - totalBarWidth) / 2; float barGapWidth = barWidth + barWidth * barGap; float space = serie.barGap == -1 ? offset : offset + m_BarLastOffset; var showData = serie.GetDataList(m_DataZoom); int maxCount = maxShowDataNumber > 0 ? (maxShowDataNumber > showData.Count ? showData.Count : maxShowDataNumber) : showData.Count; if (seriesHig.Count < minShowDataNumber) { for (int i = 0; i < minShowDataNumber; i++) { seriesHig.Add(0); } } for (int i = minShowDataNumber; i < maxCount; i++) { if (i >= seriesHig.Count) { seriesHig.Add(0); } float value = showData[i].data[1]; float pX = seriesHig[i] + coordinateX + xAxis.zeroXOffset + yAxis.axisLine.width; float pY = coordinateY + +i * categoryWidth; if (!yAxis.boundaryGap) { pY -= categoryWidth / 2; } float barHig = (xAxis.minValue > 0 ? value - xAxis.minValue : value) / (xAxis.maxValue - xAxis.minValue) * coordinateWid; seriesHig[i] += barHig; Vector3 p1 = new Vector3(pX, pY + space + barWidth); Vector3 p2 = new Vector3(pX + barHig, pY + space + barWidth); Vector3 p3 = new Vector3(pX + barHig, pY + space); Vector3 p4 = new Vector3(pX, pY + space); serie.dataPoints.Add(new Vector3(pX + barHig, pY + space + barWidth / 2)); var highlight = (m_Tooltip.show && m_Tooltip.IsSelected(i)) || serie.data[i].highlighted || serie.highlighted; if (serie.show) { Color areaColor = serie.GetAreaColor(m_ThemeInfo, colorIndex, highlight); Color areaToColor = serie.GetAreaToColor(m_ThemeInfo, colorIndex, highlight); ChartHelper.DrawPolygon(vh, p1, p2, p3, p4, areaColor, areaToColor); } } if (!m_Series.IsStack(serie.stack, SerieType.Bar)) { m_BarLastOffset += barGapWidth; } }
private void DrawData(VertexHelper vh) { int indicatorNum = m_Radar.indicatorList.Count; var angle = 2 * Mathf.PI / indicatorNum; var p = new Vector3(m_RadarCenterX, m_RadarCenterY); Vector3 startPoint = Vector3.zero; Vector3 toPoint = Vector3.zero; Vector3 firstPoint = Vector3.zero; dataPosList.Clear(); dataPosList.Capacity = m_Series.Count; for (int i = 0; i < m_Series.Count; i++) { if (!IsActive(i)) { dataPosList.Add(new List <Vector3>()); continue; } var dataList = m_Series.series[i].yData; var color = m_ThemeInfo.GetColor(i); var areaColor = color; areaColor.a = (byte)m_Radar.areaAipha; List <Vector3> pointList = new List <Vector3>(dataList.Count); dataPosList.Add(pointList); for (int j = 0; j < dataList.Count; j++) { 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; var currAngle = j * angle; if (j == 0) { startPoint = new Vector3(p.x + radius * Mathf.Sin(currAngle), p.y + radius * Mathf.Cos(currAngle)); firstPoint = startPoint; } else { toPoint = new Vector3(p.x + radius * Mathf.Sin(currAngle), p.y + radius * Mathf.Cos(currAngle)); if (m_Radar.area) { ChartHelper.DrawTriangle(vh, p, startPoint, toPoint, areaColor); } ChartHelper.DrawLine(vh, startPoint, toPoint, m_Radar.lineTickness, color); startPoint = toPoint; } pointList.Add(startPoint); } if (m_Radar.area) { ChartHelper.DrawTriangle(vh, p, startPoint, firstPoint, areaColor); } ChartHelper.DrawLine(vh, startPoint, firstPoint, m_Radar.lineTickness, color); foreach (var point in pointList) { float radius = m_Radar.linePointSize - m_Radar.lineTickness * 2; ChartHelper.DrawCricle(vh, point, radius, Color.white); ChartHelper.DrawDoughnut(vh, point, radius, m_Radar.linePointSize, 0, 360, color); } } }
private void DrawCapsuleBar(VertexHelper vh, Serie serie, SerieData serieData, ItemStyle itemStyle, int colorIndex, bool highlight, float space, float barWidth, float pX, float pY, Vector3 plb, Vector3 plt, Vector3 prt, Vector3 prb, bool isYAxis, Grid grid) { var areaColor = SerieHelper.GetItemColor(serie, serieData, m_Theme, colorIndex, highlight); var areaToColor = SerieHelper.GetItemToColor(serie, serieData, m_Theme, colorIndex, highlight); DrawBarBackground(vh, serie, serieData, itemStyle, colorIndex, highlight, pX, pY, space, barWidth, isYAxis, grid); var borderWidth = itemStyle.runtimeBorderWidth; var radius = barWidth / 2 - borderWidth; var isGradient = !ChartHelper.IsValueEqualsColor(areaColor, areaToColor); if (isYAxis) { var diff = Vector3.right * radius; if (plt.x < prt.x) { var pcl = (plt + plb) / 2 + diff; var pcr = (prt + prb) / 2 - diff; if (pcr.x > pcl.x) { if (isGradient) { var barLen = prt.x - plt.x; var rectStartColor = Color32.Lerp(areaColor, areaToColor, radius / barLen); var rectEndColor = Color32.Lerp(areaColor, areaToColor, (barLen - radius) / barLen); CheckClipAndDrawPolygon(vh, plb + diff, plt + diff, prt - diff, prb - diff, rectStartColor, rectEndColor, serie.clip, grid); UGL.DrawSector(vh, pcl, radius, areaColor, rectStartColor, 180, 360, 1, isYAxis); UGL.DrawSector(vh, pcr, radius, rectEndColor, areaToColor, 0, 180, 1, isYAxis); } else { CheckClipAndDrawPolygon(vh, plb + diff, plt + diff, prt - diff, prb - diff, areaColor, areaToColor, serie.clip, grid); UGL.DrawSector(vh, pcl, radius, areaColor, 180, 360); UGL.DrawSector(vh, pcr, radius, areaToColor, 0, 180); } } } else if (plt.x > prt.x) { var pcl = (plt + plb) / 2 - diff; var pcr = (prt + prb) / 2 + diff; if (pcr.x < pcl.x) { if (isGradient) { var barLen = plt.x - prt.x; var rectStartColor = Color32.Lerp(areaColor, areaToColor, radius / barLen); var rectEndColor = Color32.Lerp(areaColor, areaToColor, (barLen - radius) / barLen); CheckClipAndDrawPolygon(vh, plb - diff, plt - diff, prt + diff, prb + diff, rectStartColor, rectEndColor, serie.clip, grid); UGL.DrawSector(vh, pcl, radius, rectStartColor, areaColor, 0, 180, 1, isYAxis); UGL.DrawSector(vh, pcr, radius, areaToColor, rectEndColor, 180, 360, 1, isYAxis); } else { CheckClipAndDrawPolygon(vh, plb - diff, plt - diff, prt + diff, prb + diff, areaColor, areaToColor, serie.clip, grid); UGL.DrawSector(vh, pcl, radius, areaColor, 0, 180); UGL.DrawSector(vh, pcr, radius, areaToColor, 180, 360); } } } } else { var diff = Vector3.up * radius; if (plt.y > plb.y) { var pct = (plt + prt) / 2 - diff; var pcb = (plb + prb) / 2 + diff; if (pct.y > pcb.y) { if (isGradient) { var barLen = plt.y - plb.y; var rectStartColor = Color32.Lerp(areaColor, areaToColor, radius / barLen); var rectEndColor = Color32.Lerp(areaColor, areaToColor, (barLen - radius) / barLen); CheckClipAndDrawPolygon(vh, prb + diff, plb + diff, plt - diff, prt - diff, rectStartColor, rectEndColor, serie.clip, grid); UGL.DrawSector(vh, pct, radius, rectEndColor, areaToColor, 270, 450, 1, isYAxis); UGL.DrawSector(vh, pcb, radius, rectStartColor, areaColor, 90, 270, 1, isYAxis); } else { CheckClipAndDrawPolygon(vh, prb + diff, plb + diff, plt - diff, prt - diff, areaColor, areaToColor, serie.clip, grid); UGL.DrawSector(vh, pct, radius, areaToColor, 270, 450); UGL.DrawSector(vh, pcb, radius, areaColor, 90, 270); } } } else if (plt.y < plb.y) { var pct = (plt + prt) / 2 + diff; var pcb = (plb + prb) / 2 - diff; if (pct.y < pcb.y) { if (isGradient) { var barLen = plb.y - plt.y; var rectStartColor = Color32.Lerp(areaColor, areaToColor, radius / barLen); var rectEndColor = Color32.Lerp(areaColor, areaToColor, (barLen - radius) / barLen); CheckClipAndDrawPolygon(vh, prb - diff, plb - diff, plt + diff, prt + diff, rectStartColor, rectEndColor, serie.clip, grid); UGL.DrawSector(vh, pct, radius, rectEndColor, areaToColor, 90, 270, 1, isYAxis); UGL.DrawSector(vh, pcb, radius, rectStartColor, areaColor, 270, 450, 1, isYAxis); } else { CheckClipAndDrawPolygon(vh, prb - diff, plb - diff, plt + diff, prt + diff, areaColor, areaToColor, serie.clip, grid); UGL.DrawSector(vh, pct, radius, areaToColor, 90, 270); UGL.DrawSector(vh, pcb, radius, areaColor, 270, 450); } } } } }
private void DrawData(VertexHelper vh) { Vector3 startPoint = Vector3.zero; Vector3 toPoint = Vector3.zero; Vector3 firstPoint = Vector3.zero; serieNameSet.Clear(); int serieNameCount = -1; for (int i = 0; i < m_Series.Count; i++) { var serie = m_Series.series[i]; var radar = m_Radars[serie.radarIndex]; int indicatorNum = radar.indicatorList.Count; var angle = 2 * Mathf.PI / indicatorNum; Vector3 p = radar.centerPos; if (!IsActive(i)) { continue; } for (int j = 0; j < serie.data.Count; j++) { var serieData = serie.data[j]; int key = i * 100 + j; if (!radar.dataPosList.ContainsKey(key)) { radar.dataPosList.Add(i * 100 + j, new List <Vector3>(serieData.data.Count)); } else { radar.dataPosList[key].Clear(); } string dataName = serieData.name; int serieIndex = 0; if (string.IsNullOrEmpty(dataName)) { serieNameCount++; serieIndex = serieNameCount; } else if (!serieNameSet.ContainsKey(dataName)) { serieNameSet.Add(dataName, serieNameCount); serieNameCount++; serieIndex = serieNameCount; } else { serieIndex = serieNameSet[dataName]; } if (!serieData.show) { continue; } var isHighlight = serie.highlighted || serieData.highlighted || (m_Tooltip.show && m_Tooltip.dataIndex[0] == i && m_Tooltip.dataIndex[1] == j); var areaColor = serie.GetAreaColor(m_ThemeInfo, serieIndex, isHighlight); var lineColor = serie.GetLineColor(m_ThemeInfo, serieIndex, isHighlight); int dataCount = radar.indicatorList.Count; List <Vector3> pointList = radar.dataPosList[key]; for (int n = 0; n < dataCount; n++) { if (n >= serieData.data.Count) { break; } float min = radar.GetIndicatorMin(n); float max = radar.GetIndicatorMax(n); float value = serieData.data[n]; if (max == 0) { serie.GetMinMaxData(n, out min, out max); min = radar.GetIndicatorMin(n); } var radius = max < 0 ? radar.actualRadius - radar.actualRadius * value / max : radar.actualRadius * value / max; var currAngle = n * angle; if (n == 0) { startPoint = new Vector3(p.x + radius * Mathf.Sin(currAngle), p.y + radius * Mathf.Cos(currAngle)); firstPoint = startPoint; } else { toPoint = new Vector3(p.x + radius * Mathf.Sin(currAngle), p.y + radius * Mathf.Cos(currAngle)); if (serie.areaStyle.show) { ChartHelper.DrawTriangle(vh, p, startPoint, toPoint, areaColor); } if (serie.lineStyle.show) { ChartHelper.DrawLine(vh, startPoint, toPoint, serie.lineStyle.width, lineColor); } startPoint = toPoint; } pointList.Add(startPoint); } if (serie.areaStyle.show) { ChartHelper.DrawTriangle(vh, p, startPoint, firstPoint, areaColor); } if (serie.lineStyle.show) { ChartHelper.DrawLine(vh, startPoint, firstPoint, serie.lineStyle.width, lineColor); } if (serie.symbol.type != SerieSymbolType.None) { var symbolSize = (isHighlight ? serie.symbol.selectedSize : serie.symbol.size); float symbolRadius = symbolSize - serie.lineStyle.width * 2; var symbolColor = serie.symbol.color != Color.clear ? serie.symbol.color : lineColor; symbolColor.a *= serie.symbol.opacity; foreach (var point in pointList) { DrawSymbol(vh, serie.symbol.type, symbolSize, serie.lineStyle.width, point, symbolColor); } } } } }
private void DrawBarBackground(VertexHelper vh, Serie serie, SerieData serieData, ItemStyle itemStyle, int colorIndex, bool highlight, float pX, float pY, float space, float barWidth, bool isYAxis, Grid grid) { var color = SerieHelper.GetItemBackgroundColor(serie, serieData, m_Theme, colorIndex, highlight, false); if (ChartHelper.IsClearColor(color)) { return; } if (isYAxis) { var axis = m_YAxes[serie.yAxisIndex]; var axisWidth = axis.axisLine.GetWidth(m_Theme.axis.lineWidth); Vector3 plt = new Vector3(grid.runtimeX + axisWidth, pY + space + barWidth); Vector3 prt = new Vector3(grid.runtimeX + axisWidth + grid.runtimeWidth, pY + space + barWidth); Vector3 prb = new Vector3(grid.runtimeX + axisWidth + grid.runtimeWidth, pY + space); Vector3 plb = new Vector3(grid.runtimeX + axisWidth, pY + space); if (serie.barType == BarType.Capsule) { var radius = barWidth / 2; var diff = Vector3.right * radius; var pcl = (plt + plb) / 2 + diff; var pcr = (prt + prb) / 2 - diff; CheckClipAndDrawPolygon(vh, plb + diff, plt + diff, prt - diff, prb - diff, color, color, serie.clip, grid); UGL.DrawSector(vh, pcl, radius, color, 180, 360); UGL.DrawSector(vh, pcr, radius, color, 0, 180); if (itemStyle.NeedShowBorder()) { var borderWidth = itemStyle.borderWidth; var borderColor = itemStyle.borderColor; var smoothness = settings.cicleSmoothness; var inRadius = radius - borderWidth; var outRadius = radius; var p1 = plb + diff + Vector3.up * borderWidth / 2; var p2 = prb - diff + Vector3.up * borderWidth / 2; var p3 = plt + diff - Vector3.up * borderWidth / 2; var p4 = prt - diff - Vector3.up * borderWidth / 2; UGL.DrawLine(vh, p1, p2, borderWidth / 2, borderColor); UGL.DrawLine(vh, p3, p4, borderWidth / 2, borderColor); UGL.DrawDoughnut(vh, pcl, inRadius, outRadius, borderColor, ChartConst.clearColor32, 180, 360, smoothness); UGL.DrawDoughnut(vh, pcr, inRadius, outRadius, borderColor, ChartConst.clearColor32, 0, 180, smoothness); } } else { CheckClipAndDrawPolygon(vh, ref plb, ref plt, ref prt, ref prb, color, color, serie.clip, grid); } } else { var axis = m_XAxes[serie.xAxisIndex]; var axisWidth = axis.axisLine.GetWidth(m_Theme.axis.lineWidth); Vector3 plb = new Vector3(pX + space, grid.runtimeY + axisWidth); Vector3 plt = new Vector3(pX + space, grid.runtimeY + grid.runtimeHeight + axisWidth); Vector3 prt = new Vector3(pX + space + barWidth, grid.runtimeY + grid.runtimeHeight + axisWidth); Vector3 prb = new Vector3(pX + space + barWidth, grid.runtimeY + axisWidth); if (serie.barType == BarType.Capsule) { var radius = barWidth / 2; var diff = Vector3.up * radius; var pct = (plt + prt) / 2 - diff; var pcb = (plb + prb) / 2 + diff; CheckClipAndDrawPolygon(vh, prb + diff, plb + diff, plt - diff, prt - diff, color, color, serie.clip, grid); UGL.DrawSector(vh, pct, radius, color, 270, 450); UGL.DrawSector(vh, pcb, radius, color, 90, 270); if (itemStyle.NeedShowBorder()) { var borderWidth = itemStyle.borderWidth; var borderColor = itemStyle.borderColor; var smoothness = settings.cicleSmoothness; var inRadius = radius - borderWidth; var outRadius = radius; var p1 = plb + diff + Vector3.right * borderWidth / 2; var p2 = plt - diff + Vector3.right * borderWidth / 2; var p3 = prb + diff - Vector3.right * borderWidth / 2; var p4 = prt - diff - Vector3.right * borderWidth / 2; UGL.DrawLine(vh, p1, p2, borderWidth / 2, borderColor); UGL.DrawLine(vh, p3, p4, borderWidth / 2, borderColor); UGL.DrawDoughnut(vh, pct, inRadius, outRadius, borderColor, ChartConst.clearColor32, 270, 450, smoothness); UGL.DrawDoughnut(vh, pcb, inRadius, outRadius, borderColor, ChartConst.clearColor32, 90, 270, smoothness); } } else { CheckClipAndDrawPolygon(vh, ref prb, ref plb, ref plt, ref prt, color, color, serie.clip, grid); } } }
/// <summary> /// 移除所有图表子节点,会自动重现初始化。 /// </summary> public void RemoveChartObject() { ChartHelper.DestroyAllChildren(transform); //SetAllComponentDirty(); }
private void DrawSerie(VertexHelper vh, Serie serie) { if (serie.animation.HasFadeOut()) { return; } var vessel = GetVessel(serie.vesselIndex); if (vessel == null) { return; } var cenPos = vessel.runtimeCenterPos; var radius = vessel.runtimeInnerRadius; var serieData = serie.GetSerieData(0); if (serieData == null) { return; } var value = serieData.GetData(1); if (serie.runtimeCheckValue != value) { serie.runtimeCheckValue = value; m_UpdateLabelText = true; } if (serieData.labelPosition != cenPos) { serieData.labelPosition = cenPos; m_UpdateLabelText = true; } if (value == 0) { return; } var colorIndex = m_LegendRealShowName.IndexOf(serie.name); var realHig = (value - serie.min) / (serie.max - serie.min) * radius * 2; serie.animation.InitProgress(1, 0, realHig); var hig = serie.animation.IsFinish() ? realHig : serie.animation.GetCurrDetail(); var a = Mathf.Abs(radius - hig + (hig > radius ? serie.waveHeight : -serie.waveHeight)); var diff = Mathf.Sqrt(radius * radius - Mathf.Pow(a, 2)); var color = SerieHelper.GetItemColor(serie, serieData, m_ThemeInfo, colorIndex, false); var toColor = SerieHelper.GetItemToColor(serie, serieData, m_ThemeInfo, colorIndex, false); var isNeedGradient = !ChartHelper.IsValueEqualsColor(color, toColor); var isFull = hig >= 2 * radius; if (hig >= 2 * radius) { hig = 2 * radius; } if (isFull && !isNeedGradient) { ChartDrawer.DrawCricle(vh, cenPos, radius, toColor, m_Settings.cicleSmoothness); } else { var startY = cenPos.y - radius + hig; var waveStartPos = new Vector3(cenPos.x - diff, startY); var waveEndPos = new Vector3(cenPos.x + diff, startY); var startX = hig > radius ? cenPos.x - radius : waveStartPos.x; var endX = hig > radius ? cenPos.x + radius : waveEndPos.x; var step = vessel.smoothness; if (step < 0.5f) { step = 0.5f; } var lup = hig > radius ? new Vector3(cenPos.x - radius, cenPos.y) : waveStartPos; var ldp = lup; var nup = Vector3.zero; var ndp = Vector3.zero; var angle = 0f; serie.runtimeWaveSpeed += serie.waveSpeed * Time.deltaTime; var isStarted = false; var isEnded = false; var waveHeight = isFull ? 0 : serie.waveHeight; while (startX < endX) { startX += step; if (startX > endX) { startX = endX; } if (startX > waveStartPos.x && !isStarted) { startX = waveStartPos.x; isStarted = true; } if (startX > waveEndPos.x && !isEnded) { startX = waveEndPos.x; isEnded = true; } var py = Mathf.Sqrt(Mathf.Pow(radius, 2) - Mathf.Pow(Mathf.Abs(cenPos.x - startX), 2)); if (startX < waveStartPos.x || startX > waveEndPos.x) { nup = new Vector3(startX, cenPos.y + py); } else { var py2 = waveHeight * Mathf.Sin(1 / serie.waveLength * angle + serie.runtimeWaveSpeed + serie.waveOffset); var nupY = waveStartPos.y + py2; if (nupY > cenPos.y + py) { nupY = cenPos.y + py; } else if (nupY < cenPos.y - py) { nupY = cenPos.y - py; } nup = new Vector3(startX, nupY); angle += step; } ndp = new Vector3(startX, cenPos.y - py); if (!ChartHelper.IsValueEqualsColor(color, toColor)) { var colorMin = cenPos.y - radius; var colorMax = startY + serie.waveHeight; var tcolor1 = Color.Lerp(color, toColor, 1 - (lup.y - colorMin) / (colorMax - colorMin)); var tcolor2 = Color.Lerp(color, toColor, 1 - (ldp.y - colorMin) / (colorMax - colorMin)); ChartDrawer.DrawPolygon(vh, lup, nup, ndp, ldp, tcolor1, tcolor2); } else { ChartDrawer.DrawPolygon(vh, lup, nup, ndp, ldp, color); } lup = nup; ldp = ndp; } } if (serie.waveSpeed != 0 && Application.isPlaying && !isFull) { RefreshChart(); } if (!serie.animation.IsFinish()) { serie.animation.CheckProgress(realHig); m_IsPlayingAnimation = true; RefreshChart(); } }
protected override void OnDisable() { base.OnDisable(); ChartHelper.HideAllObject(transform); }
public static Color GetSubTextColor(Title title, ThemeInfo themeInfo) { return(!ChartHelper.IsClearColor(title.subTextStyle.color) ? title.subTextStyle.color : (Color)themeInfo.titleSubTextColor); }
protected override void OnEnable() { base.OnEnable(); ChartHelper.ActiveAllObject(transform, true); }
private void InitLegend(Legend legend) { legend.painter = null; // legend component does not need to paint legend.refreshComponent = delegate() { legend.OnChanged(); var legendObject = ChartHelper.AddObject(s_LegendObjectName + legend.index, transform, m_ChartMinAnchor, m_ChartMaxAnchor, m_ChartPivot, m_ChartSizeDelta); legend.gameObject = legendObject; legendObject.hideFlags = chartHideFlags; SeriesHelper.UpdateSerieNameList(m_Series, ref m_LegendRealShowName); List <string> datas; if (legend.show && legend.data.Count > 0) { datas = new List <string>(); for (int i = 0; i < m_LegendRealShowName.Count; i++) { if (legend.data.Contains(m_LegendRealShowName[i])) { datas.Add(m_LegendRealShowName[i]); } } } else { datas = m_LegendRealShowName; } int totalLegend = 0; for (int i = 0; i < datas.Count; i++) { if (!SeriesHelper.IsLegalLegendName(datas[i])) { continue; } totalLegend++; } legend.RemoveButton(); ChartHelper.HideAllObject(legendObject); if (!legend.show) { return; } for (int i = 0; i < datas.Count; i++) { if (!SeriesHelper.IsLegalLegendName(datas[i])) { continue; } string legendName = legend.GetFormatterContent(datas[i]); var readIndex = m_LegendRealShowName.IndexOf(datas[i]); var active = IsActiveByLegend(datas[i]); var bgColor = LegendHelper.GetIconColor(legend, readIndex, theme, m_Series, datas[i], active); var item = LegendHelper.AddLegendItem(legend, i, datas[i], legendObject.transform, m_Theme, legendName, bgColor, active); legend.SetButton(legendName, item, totalLegend); ChartHelper.ClearEventListener(item.button.gameObject); ChartHelper.AddEventListener(item.button.gameObject, EventTriggerType.PointerDown, (data) => { if (data.selectedObject == null || legend.selectedMode == Legend.SelectedMode.None) { return; } var temp = data.selectedObject.name.Split('_'); string selectedName = temp[1]; int clickedIndex = int.Parse(temp[0]); if (legend.selectedMode == Legend.SelectedMode.Multiple) { OnLegendButtonClick(clickedIndex, selectedName, !IsActiveByLegend(selectedName)); } else { var btnList = legend.buttonList.Values.ToArray(); if (btnList.Length == 1) { OnLegendButtonClick(0, selectedName, !IsActiveByLegend(selectedName)); } else { for (int n = 0; n < btnList.Length; n++) { temp = btnList[n].name.Split('_'); selectedName = btnList[n].legendName; var index = btnList[n].index; OnLegendButtonClick(n, selectedName, index == clickedIndex ? true : false); } } } }); ChartHelper.AddEventListener(item.button.gameObject, EventTriggerType.PointerEnter, (data) => { if (item.button == null) { return; } var temp = item.button.name.Split('_'); string selectedName = temp[1]; int index = int.Parse(temp[0]); OnLegendButtonEnter(index, selectedName); }); ChartHelper.AddEventListener(item.button.gameObject, EventTriggerType.PointerExit, (data) => { if (item.button == null) { return; } var temp = item.button.name.Split('_'); string selectedName = temp[1]; int index = int.Parse(temp[0]); OnLegendButtonExit(index, selectedName); }); } if (legend.selectedMode == Legend.SelectedMode.Single) { for (int n = 0; n < m_LegendRealShowName.Count; n++) { OnLegendButtonClick(n, m_LegendRealShowName[n], n == 0 ? true : false); } } LegendHelper.ResetItemPosition(legend, m_ChartPosition, m_ChartWidth, m_ChartHeight); }; legend.refreshComponent(); }
private void InitBackground() { if (!transform.parent) { return; } int childCount = transform.parent.childCount; if (childCount > 2) { m_Background.runtimeActive = false; } else if (childCount == 1) { m_Background.runtimeActive = true; } else { m_Background.runtimeActive = false; for (int i = 0; i < childCount; i++) { if (transform.parent.GetChild(i).name.StartsWith(s_BackgroundObjectName)) { m_Background.runtimeActive = true; break; } } } if (!m_Background.runtimeActive || m_IsControlledByLayout) { //find old gameobject and delete var objName = s_BackgroundObjectName + GetInstanceID(); ChartHelper.DestoryGameObject(transform.parent, objName); ChartHelper.DestoryGameObject(m_BackgroundRoot); return; } if (!m_Background.show) { ChartHelper.DestoryGameObject(m_BackgroundRoot); return; } var backgroundName = s_BackgroundObjectName; m_BackgroundRoot = ChartHelper.AddObject(backgroundName, transform.parent, m_ChartMinAnchor, m_ChartMaxAnchor, m_ChartPivot, m_ChartSizeDelta); m_BackgroundRoot.hideFlags = chartHideFlags; var backgroundImage = ChartHelper.GetOrAddComponent <Image>(m_BackgroundRoot); var backgroundRect = m_BackgroundRoot.GetComponent <RectTransform>(); backgroundRect.position = rectTransform.position; backgroundImage.sprite = m_Background.image; backgroundImage.type = m_Background.imageType; backgroundImage.color = m_Background.imageColor; m_BackgroundRoot.SetActive(m_Background.show); var siblindIndex = rectTransform.GetSiblingIndex(); if (siblindIndex == 0) { backgroundRect.SetSiblingIndex(0); } else { backgroundRect.SetSiblingIndex(rectTransform.GetSiblingIndex() - 1); } }
private void DrawLabelLine(VertexHelper vh, Serie serie, SerieData serieData, Color color) { var serieLabel = SerieHelper.GetSerieLabel(serie, serieData); if (serieLabel.show && serieLabel.position == SerieLabel.Position.Outside && serieLabel.line) { var insideRadius = serieData.runtimePieInsideRadius; var outSideRadius = serieData.runtimePieOutsideRadius; var center = serie.runtimeCenterPos; var currAngle = serieData.runtimePieHalfAngle; if (!ChartHelper.IsClearColor(serieLabel.lineColor)) { color = serieLabel.lineColor; } else if (serieLabel.lineType == SerieLabel.LineType.HorizontalLine) { color *= color; } float currSin = Mathf.Sin(currAngle * Mathf.Deg2Rad); float currCos = Mathf.Cos(currAngle * Mathf.Deg2Rad); var radius1 = serieLabel.lineType == SerieLabel.LineType.HorizontalLine ? serie.runtimeOutsideRadius : outSideRadius; var radius2 = serie.runtimeOutsideRadius + serieLabel.lineLength1; var radius3 = insideRadius + (outSideRadius - insideRadius) / 2; if (radius1 < serie.runtimeInsideRadius) { radius1 = serie.runtimeInsideRadius; } radius1 -= 0.1f; var pos0 = new Vector3(center.x + radius3 * currSin, center.y + radius3 * currCos); var pos1 = new Vector3(center.x + radius1 * currSin, center.y + radius1 * currCos); var pos2 = serieData.labelPosition; if (pos2.x == 0) { pos2 = new Vector3(center.x + radius2 * currSin, center.y + radius2 * currCos); } float tx, ty; Vector3 pos3, pos4, pos6; var horizontalLineCircleRadius = serieLabel.lineWidth * 4f; var lineCircleDiff = horizontalLineCircleRadius - 0.3f; if (currAngle < 90) { ty = serieLabel.lineWidth * Mathf.Cos((90 - currAngle) * Mathf.Deg2Rad); tx = serieLabel.lineWidth * Mathf.Sin((90 - currAngle) * Mathf.Deg2Rad); pos3 = new Vector3(pos2.x - tx, pos2.y + ty - serieLabel.lineWidth); var r4 = Mathf.Sqrt(radius1 * radius1 - Mathf.Pow(currCos * radius3, 2)) - currSin * radius3; r4 += serieLabel.lineLength1 - lineCircleDiff; pos6 = pos0 + Vector3.right * lineCircleDiff; pos4 = pos6 + Vector3.right * r4; } else if (currAngle < 180) { ty = serieLabel.lineWidth * Mathf.Sin((180 - currAngle) * Mathf.Deg2Rad); tx = serieLabel.lineWidth * Mathf.Cos((180 - currAngle) * Mathf.Deg2Rad); pos3 = new Vector3(pos2.x - tx, pos2.y - ty + serieLabel.lineWidth); var r4 = Mathf.Sqrt(radius1 * radius1 - Mathf.Pow(currCos * radius3, 2)) - currSin * radius3; r4 += serieLabel.lineLength1 - lineCircleDiff; pos6 = pos0 + Vector3.right * lineCircleDiff; pos4 = pos6 + Vector3.right * r4; } else if (currAngle < 270) { ty = serieLabel.lineWidth * Mathf.Sin((180 + currAngle) * Mathf.Deg2Rad); tx = serieLabel.lineWidth * Mathf.Cos((180 + currAngle) * Mathf.Deg2Rad); var currSin1 = Mathf.Sin((360 - currAngle) * Mathf.Deg2Rad); var currCos1 = Mathf.Cos((360 - currAngle) * Mathf.Deg2Rad); pos3 = new Vector3(pos2.x + tx, pos2.y - ty + serieLabel.lineWidth); var r4 = Mathf.Sqrt(radius1 * radius1 - Mathf.Pow(currCos1 * radius3, 2)) - currSin1 * radius3; r4 += serieLabel.lineLength1 - lineCircleDiff; pos6 = pos0 + Vector3.left * lineCircleDiff; pos4 = pos6 + Vector3.left * r4; } else { ty = serieLabel.lineWidth * Mathf.Cos((90 + currAngle) * Mathf.Deg2Rad); tx = serieLabel.lineWidth * Mathf.Sin((90 + currAngle) * Mathf.Deg2Rad); pos3 = new Vector3(pos2.x + tx, pos2.y + ty - serieLabel.lineWidth); var currSin1 = Mathf.Sin((360 - currAngle) * Mathf.Deg2Rad); var currCos1 = Mathf.Cos((360 - currAngle) * Mathf.Deg2Rad); var r4 = Mathf.Sqrt(radius1 * radius1 - Mathf.Pow(currCos1 * radius3, 2)) - currSin1 * radius3; r4 += serieLabel.lineLength1 - lineCircleDiff; pos6 = pos0 + Vector3.left * lineCircleDiff; pos4 = pos6 + Vector3.left * r4; } var pos5 = new Vector3(currAngle > 180 ? pos3.x - serieLabel.lineLength2 : pos3.x + serieLabel.lineLength2, pos3.y); switch (serieLabel.lineType) { case SerieLabel.LineType.BrokenLine: ChartDrawer.DrawLine(vh, pos1, pos2, serieLabel.lineWidth, color); ChartDrawer.DrawLine(vh, pos3, pos5, serieLabel.lineWidth, color); break; case SerieLabel.LineType.Curves: ChartDrawer.DrawCurves(vh, pos1, pos5, pos1, pos2, serieLabel.lineWidth, color, m_Settings.lineSmoothness); break; case SerieLabel.LineType.HorizontalLine: ChartDrawer.DrawCricle(vh, pos0, horizontalLineCircleRadius, color); ChartDrawer.DrawLine(vh, pos6, pos4, serieLabel.lineWidth, color); break; } } }