Vector3 AlignTextPosition(AlignedItemLabels labels, PieObject obj, out CanvasLines.LineSegement line, float modifiedRaidus) { line = null; float angle = obj.StartAngle + obj.AngleSpan * 0.5f; Vector3 position = new Vector3(labels.Seperation, labels.Location.Breadth, labels.Location.Depth); position = Quaternion.AngleAxis(angle, Vector3.forward) * position; float alignRadius = (modifiedRaidus + TorusRadius) * 0.5f; Vector3 atAngle = (Vector3)ChartCommon.FromPolar(angle, 1f); if (labels.Alignment == ChartLabelAlignment.Top) { alignRadius = Mathf.Max(modifiedRaidus, TorusRadius); Vector3 basePosition = atAngle * alignRadius; Vector3 end = basePosition + position; end -= (position.normalized * LineSpacingLink); Vector4[] arr = new Vector4[] { basePosition, end }; arr[0].w = -1f; arr[1].w = -1f; line = new CanvasLines.LineSegement(arr); } position += atAngle * alignRadius; return(position); }
public void SetDirection(float angle) { SetDirection(ChartCommon.FromPolar(angle, Length)); }
private void GeneratePie(bool update) { if (mFixPositionPie == null) { update = false; } if (update == false) { ClearChart(); } else { EnsureTextController(); } if (((IInternalPieData)Data).InternalDataSource == null) { return; } double[,] data = ((IInternalPieData)Data).InternalDataSource.getRawData(); int rowCount = data.GetLength(0); int columnCount = data.GetLength(1); if (rowCount != 1) // row count for pie must be 1 { return; } double total = 0.0; for (int i = 0; i < columnCount; ++i) { double val = Math.Max(data[0, i], 0); total += val; } float start = startAngle; if (clockWise) { start -= angleSpan; } float totalGaps = columnCount * spacingAngle; float spanWithoutGaps = angleSpan - totalGaps; if (spanWithoutGaps < 0f) { spanWithoutGaps = 0f; } if (mFixPositionPie == null) { mFixPositionPie = new GameObject("FixPositionPie", typeof(ChartItem)); ChartCommon.HideObject(mFixPositionPie, hideHierarchy); mFixPositionPie.transform.SetParent(transform, false); if (IsCanvas) { var rectTrans = mFixPositionPie.AddComponent <RectTransform>(); rectTrans.anchorMax = new Vector2(0.5f, 0.5f); rectTrans.anchorMin = new Vector2(0.5f, 0.5f); rectTrans.pivot = new Vector2(0.5f, 0.5f); rectTrans.anchoredPosition = new Vector2(0.5f, 0.5f); } } for (int i = 0; i < columnCount; ++i) { object userData = ((IInternalPieData)Data).InternalDataSource.Columns[i].UserData; float radiusScale = 1f; float depthScale = 1f; float depthOffset = 0f; if (userData != null && userData is PieData.CategoryData) { radiusScale = ((PieData.CategoryData)userData).RadiusScale; depthScale = ((PieData.CategoryData)userData).DepthScale; depthOffset = ((PieData.CategoryData)userData).DepthOffset; } if (radiusScale <= 0.001f) { radiusScale = 1f; } if (depthScale <= 0.001f) { depthScale = 1f; } string name = ((IInternalPieData)Data).InternalDataSource.Columns[i].Name; double amount = Math.Max(data[0, i], 0); if (amount == 0f) { continue; } float weight = (float)(amount / total); float currentSpan = spanWithoutGaps * weight; GameObject pieObject = null; IPieGenerator generator = null; PieObject dataObject; CanvasLines.LineSegement line; float modifiedRadius = Mathf.Max(radius * radiusScale, torusRadius); // float modifiedDepth = d float lineAngle = start + currentSpan * 0.5f; if (mPies.TryGetValue(name, out dataObject)) { dataObject.StartAngle = start; dataObject.AngleSpan = currentSpan; generator = dataObject.Generator; if (dataObject.ItemLabel) { Vector3 labelPos = AlignTextPosition(mItemLabels, dataObject, out line, modifiedRadius); dataObject.ItemLabel.transform.localPosition = labelPos; string toSet = ChartAdancedSettings.Instance.FormatFractionDigits(mItemLabels.FractionDigits, amount, CustomNumberFormat); toSet = mItemLabels.TextFormat.Format(toSet, name, ""); ChartCommon.UpdateTextParams(dataObject.ItemLabel.UIText, toSet); if (dataObject.ItemLine != null) { var lst = new List <CanvasLines.LineSegement>(); lst.Add(line); dataObject.ItemLine.SetLines(lst); } } if (dataObject.CategoryLabel != null) { Vector3 labelPos = AlignTextPosition(mCategoryLabels, dataObject, out line, modifiedRadius); dataObject.CategoryLabel.transform.localPosition = labelPos; if (dataObject.CategoryLine != null) { var lst = new List <CanvasLines.LineSegement>(); lst.Add(line); dataObject.CategoryLine.SetLines(lst); } } Vector2 add = ChartCommon.FromPolar(start + currentSpan * 0.5f, Extrusion); dataObject.TopObject.transform.localPosition = new Vector3(add.x, add.y, 0f); } else { GameObject topObject = new GameObject(); if (IsCanvas) { topObject.AddComponent <RectTransform>(); } ChartCommon.HideObject(topObject, hideHierarchy); topObject.AddComponent <ChartItem>(); topObject.transform.SetParent(mFixPositionPie.transform); topObject.transform.localPosition = new Vector3(); topObject.transform.localRotation = Quaternion.identity; topObject.transform.localScale = new Vector3(1f, 1f, 1f); generator = PreparePieObject(out pieObject); ChartCommon.EnsureComponent <ChartItem>(pieObject); ChartMaterialController control = ChartCommon.EnsureComponent <ChartMaterialController>(pieObject); control.Materials = Data.GetMaterial(name); control.Refresh(); dataObject = new PieObject(); dataObject.StartAngle = start; dataObject.AngleSpan = currentSpan; dataObject.TopObject = topObject; dataObject.Generator = generator; dataObject.category = name; var pieInfo = pieObject.AddComponent <PieInfo>(); pieInfo.pieObject = dataObject; pieObject.transform.SetParent(topObject.transform); Vector2 add = ChartCommon.FromPolar(start + currentSpan * 0.5f, Extrusion); pieObject.transform.localPosition = new Vector3(0f, 0f, 0f); pieObject.transform.localScale = new Vector3(1f, 1f, 1f); pieObject.transform.localRotation = Quaternion.identity; mPies.Add(name, dataObject); topObject.transform.localPosition = new Vector3(add.x, add.y, 0f); CharItemEffectController effect = ChartCommon.EnsureComponent <CharItemEffectController>(pieObject); effect.WorkOnParent = true; effect.InitialScale = false; ChartItemEvents[] events = pieObject.GetComponentsInChildren <ChartItemEvents>(); for (int j = 0; j < events.Length; ++j) { if (events[j] == null) { continue; } InternalItemEvents comp = (InternalItemEvents)events[j]; comp.Parent = this; comp.UserData = dataObject; } if (mItemLabels != null) { Vector3 labelPos = AlignTextPosition(mItemLabels, dataObject, out line, modifiedRadius); if (line != null && IsUnderCanvas) { dataObject.ItemLine = AddLineRenderer(topObject, line); } string toSet = ChartAdancedSettings.Instance.FormatFractionDigits(mItemLabels.FractionDigits, amount, CustomNumberFormat); toSet = mItemLabels.TextFormat.Format(toSet, name, ""); BillboardText billboard = ChartCommon.CreateBillboardText(null, mItemLabels.TextPrefab, topObject.transform, toSet, labelPos.x, labelPos.y, labelPos.z, lineAngle, topObject.transform, hideHierarchy, mItemLabels.FontSize, mItemLabels.FontSharpness); dataObject.ItemLabel = billboard; TextController.AddText(billboard); } if (mCategoryLabels != null) { Vector3 labelPos = AlignTextPosition(mCategoryLabels, dataObject, out line, modifiedRadius); if (line != null && IsUnderCanvas) { dataObject.CategoryLine = AddLineRenderer(topObject, line); } string toSet = name; toSet = mCategoryLabels.TextFormat.Format(toSet, "", ""); BillboardText billboard = ChartCommon.CreateBillboardText(null, mCategoryLabels.TextPrefab, topObject.transform, toSet, labelPos.x, labelPos.y, labelPos.z, lineAngle, topObject.transform, hideHierarchy, mCategoryLabels.FontSize, mCategoryLabels.FontSharpness); dataObject.CategoryLabel = billboard; TextController.AddText(billboard); } } float maxDepth = Mathf.Max(OuterDepthLink, InnerDepthLink); float depthSize = maxDepth * depthScale; if (pieObject != null) { float depthStart = (maxDepth - depthSize) * 0.5f; pieObject.transform.localPosition = new Vector3(0f, 0f, depthStart - depthSize * depthOffset); } dataObject.Value = (float)data[0, i]; generator.Generate(Mathf.Deg2Rad * start, Mathf.Deg2Rad * currentSpan, modifiedRadius, torusRadius, meshSegements, OuterDepthLink * depthScale, InnerDepthLink * depthScale); start += spacingAngle + currentSpan; } }