/// <summary> /// /// </summary> /// <param name="mesh"></param> /// <param name="orientedPosition"></param> private void AddRowToChartMesh(double[,] data, int rowIndex, double orientedPosition, double depth) { if (((IInternalBarData)Data).InternalDataSource == null) { return; } int columnCount = data.GetLength(1); double barFullSize = BarSeperationLink.Breadth; double totalSize = ((columnCount - 1) * (barFullSize)); double totalDepth = columnCount * BarSeperationLink.Depth; double start = orientedPosition - totalSize * 0.5f; double min = ((IInternalBarData)Data).GetMinValue(); double max = ((IInternalBarData)Data).GetMaxValue(); double total = max - min; string group = ((IInternalBarData)Data).InternalDataSource.Rows[rowIndex].Name; if (mGroupLabels != null && mGroupLabels.isActiveAndEnabled && (mGroupLabels.Alignment != GroupLabelAlignment.BarBottom && mGroupLabels.Alignment != GroupLabelAlignment.BarTop)) { GroupObject groupObj = new GroupObject(); groupObj.start = (float)start; groupObj.depth = (float)depth; groupObj.totalSize = (float)totalSize; groupObj.totalDepth = (float)totalDepth; groupObj.rowIndex = rowIndex; Vector3 position = AlignGroupLabel(groupObj); string toSet = mGroupLabels.TextFormat.Format(group, "", ""); float angle = 45f; // if(mGroupLabels.Alignment == GroupLabelAlignment.) BillboardText billboard = ChartCommon.CreateBillboardText(null, mGroupLabels.TextPrefab, transform, toSet, position.x, position.y, position.z, angle, null, hideHierarchy, mGroupLabels.FontSize, mGroupLabels.FontSharpness); billboard.UserData = new LabelPositionInfo(mGroupLabels, groupObj); TextController.AddText(billboard); } for (int i = 0; i < columnCount; i++) { string category = ((IInternalBarData)Data).InternalDataSource.Columns[i].Name; double rowInterp = (((float)i) / ((float)columnCount - 1)); if (double.IsInfinity(rowInterp) || double.IsNaN(rowInterp)) // calculate limit for 0/0 { rowInterp = 0.0; } double pos = rowInterp * totalSize; double finalDepth = depth + rowInterp * totalDepth; pos += start;// - barFullSize * 0.5f; double amount = data[rowIndex, i]; double interp = (amount - min) / total; interp = Math.Max(0, Math.Min(1, interp)); // clamp to [0,1] AddBarToChart(finalDepth, amount, pos, interp, category, group, rowIndex, i); } }
public override void InternalGenerateChart() { if (gameObject.activeInHierarchy == false) { return; } base.InternalGenerateChart(); if (FitToContainer) { RectTransform trans = GetComponent <RectTransform>(); widthRatio = trans.rect.width; heightRatio = trans.rect.height; } ClearChart(); if (Data == null) { return; } GenerateAxis(true); double minX = ((IInternalGraphData)Data).GetMinValue(0, false); double minY = ((IInternalGraphData)Data).GetMinValue(1, false); double maxX = ((IInternalGraphData)Data).GetMaxValue(0, false); double maxY = ((IInternalGraphData)Data).GetMaxValue(1, false); double xScroll = GetScrollOffset(0); double yScroll = GetScrollOffset(1); double xSize = maxX - minX; double ySize = maxY - minY; double xOut = minX + xScroll + xSize; double yOut = minY + yScroll + ySize; DoubleVector3 min = new DoubleVector3(xScroll + minX, yScroll + minY); DoubleVector3 max = new DoubleVector3(xOut, yOut); Rect viewRect = new Rect(0f, 0f, widthRatio, heightRatio); int index = 0; int total = ((IInternalGraphData)Data).TotalCategories + 1; bool edit = false; ClearBillboard(); mActiveTexts.Clear(); GameObject mask = CreateRectMask(viewRect); foreach (GraphData.CategoryData data in ((IInternalGraphData)Data).Categories) { mClipped.Clear(); DoubleVector3[] points = data.getPoints().ToArray(); Rect uv; int refrenceIndex = ClipPoints(points, mClipped, out uv); TransformPoints(mClipped, mTransformed, viewRect, min, max); if (points.Length == 0 && ChartCommon.IsInEditMode) { edit = true; int tmpIndex = total - 1 - index; float y1 = (((float)tmpIndex) / (float)total); float y2 = (((float)tmpIndex + 1) / (float)total); DoubleVector3 pos1 = ChartCommon.interpolateInRect(viewRect, new DoubleVector3(0f, y1, -1f)).ToDoubleVector3(); DoubleVector3 pos2 = ChartCommon.interpolateInRect(viewRect, new DoubleVector3(0.5f, y2, -1f)).ToDoubleVector3(); DoubleVector3 pos3 = ChartCommon.interpolateInRect(viewRect, new DoubleVector3(1f, y1, -1f)).ToDoubleVector3(); points = new DoubleVector3[] { pos1, pos2, pos3 }; mTransformed.AddRange(points.Select(x => (Vector4)x.ToVector3())); index++; } List <CanvasLines.LineSegement> list = new List <CanvasLines.LineSegement>(); list.Add(new CanvasLines.LineSegement(mTransformed)); CategoryObject categoryObj = new CategoryObject(); if (data.FillMaterial != null) { CanvasLines fill = CreateDataObject(data, mask); fill.material = data.FillMaterial; fill.SetRefrenceIndex(refrenceIndex); fill.SetLines(list); fill.SetViewRect(viewRect, uv); fill.MakeFillRender(viewRect, data.StetchFill); categoryObj.mFill = fill; } if (data.LineMaterial != null) { CanvasLines lines = CreateDataObject(data, mask); float tiling = 1f; if (data.LineTiling.EnableTiling == true && data.LineTiling.TileFactor > 0f) { float length = 0f; for (int i = 1; i < mTransformed.Count; i++) { length += (mTransformed[i - 1] - mTransformed[i]).magnitude; } tiling = length / data.LineTiling.TileFactor; } if (tiling <= 0.0001f) { tiling = 1f; } lines.SetViewRect(viewRect, uv); lines.Thickness = (float)data.LineThickness; lines.Tiling = tiling; lines.SetRefrenceIndex(refrenceIndex); lines.material = data.LineMaterial; lines.SetHoverPrefab(data.LineHoverPrefab); lines.SetLines(list); categoryObj.mLines = lines; } //if (data.PointMaterial != null) //{ CanvasLines dots = CreateDataObject(data, mask); categoryObj.mDots = dots; dots.material = data.PointMaterial; dots.SetLines(list); Rect pickRect = viewRect; float halfSize = (float)data.PointSize * 0.5f; pickRect.xMin -= halfSize; pickRect.yMin -= halfSize; pickRect.xMax += halfSize; pickRect.yMax += halfSize; dots.SetViewRect(pickRect, uv); dots.SetRefrenceIndex(refrenceIndex); dots.SetHoverPrefab(data.PointHoverPrefab); if (data.PointMaterial != null) { dots.MakePointRender((float)data.PointSize); } else { dots.MakePointRender(0f); } if (mItemLabels != null && mItemLabels.isActiveAndEnabled) { CanvasChartMesh m = new CanvasChartMesh(true); m.RecycleText = true; categoryObj.mItemLabels = m; Rect textRect = viewRect; textRect.xMin -= 1f; textRect.yMin -= 1f; textRect.xMax += 1f; textRect.yMax += 1f; for (int i = 0; i < mTransformed.Count; i++) { if (mTransformed[i].w == 0f) { continue; } DoubleVector2 pointValue = new DoubleVector2(mTransformed[i]); if (textRect.Contains(pointValue.ToVector2()) == false) { continue; } if (edit == false) { pointValue = Data.GetPoint(data.Name, i + refrenceIndex).ToDoubleVector2(); } string xFormat = StringFromAxisFormat(pointValue.x, mHorizontalAxis, mItemLabels.FractionDigits, true); string yFormat = StringFromAxisFormat(pointValue.y, mVerticalAxis, mItemLabels.FractionDigits, false); Vector3 labelPos = ((Vector3)mTransformed[i]) + new Vector3(mItemLabels.Location.Breadth, mItemLabels.Seperation, mItemLabels.Location.Depth); if (mItemLabels.Alignment == ChartLabelAlignment.Base) { labelPos.y -= mTransformed[i].y; } FormatItem(mRealtimeStringBuilder, xFormat, yFormat); string formatted = mRealtimeStringBuilder.ToString(); string toSet = mItemLabels.TextFormat.Format(formatted, data.Name, ""); BillboardText billboard = m.AddText(this, mItemLabels.TextPrefab, transform, mItemLabels.FontSize, mItemLabels.FontSharpness, toSet, labelPos.x, labelPos.y, labelPos.z, 0f, null); // BillboardText billboard = ChartCommon.CreateBillboardText(null,mItemLabels.TextPrefab, transform, toSet, labelPos.x, labelPos.y, labelPos.z, 0f, null, hideHierarchy, mItemLabels.FontSize, mItemLabels.FontSharpness); TextController.AddText(billboard); AddBillboardText(data.Name, i + refrenceIndex, billboard); } } string catName = data.Name; dots.Hover += (idx, t, d, pos) => { Dots_Hover(catName, idx, pos); }; dots.Click += (idx, t, d, pos) => { Dots_Click(catName, idx, pos); }; dots.Leave += () => { Dots_Leave(catName); }; mCategoryObjects[catName] = categoryObj; } }
public override void InternalGenerateChart() { if (gameObject.activeInHierarchy == false) { return; } base.InternalGenerateChart(); ClearChart(); if (Data == null) { return; } double minX = (float)((IInternalGraphData)Data).GetMinValue(0, false); double minY = (float)((IInternalGraphData)Data).GetMinValue(1, false); double maxX = (float)((IInternalGraphData)Data).GetMaxValue(0, false); double maxY = (float)((IInternalGraphData)Data).GetMaxValue(1, false); DoubleVector3 min = new DoubleVector3(minX, minY); DoubleVector3 max = new DoubleVector3(maxX, maxY); Rect viewRect = new Rect(0f, 0f, widthRatio, heightRatio); int index = 0; int total = ((IInternalGraphData)Data).TotalCategories + 1; double positiveDepth = 0f; double maxThickness = 0f; bool edit = false; m3DTexts.Clear(); mActiveTexts.Clear(); foreach (GraphData.CategoryData data in ((IInternalGraphData)Data).Categories) { maxThickness = Math.Max(data.LineThickness, maxThickness); DoubleVector3[] points = data.getPoints().ToArray(); TransformPoints(points, viewRect, min, max); if (points.Length == 0 && ChartCommon.IsInEditMode) { edit = true; int tmpIndex = total - 1 - index; float y1 = (((float)tmpIndex) / (float)total); float y2 = (((float)tmpIndex + 1) / (float)total); DoubleVector3 pos1 = ChartCommon.interpolateInRect(viewRect, new DoubleVector3(0f, y1, -1f)).ToDoubleVector3(); DoubleVector3 pos2 = ChartCommon.interpolateInRect(viewRect, new DoubleVector3(0.5f, y2, -1f)).ToDoubleVector3(); DoubleVector3 pos3 = ChartCommon.interpolateInRect(viewRect, new DoubleVector3(1f, y1, -1f)).ToDoubleVector3(); points = new DoubleVector3[] { pos1, pos2, pos3 }; index++; } /*if (data.FillMaterial != null) * { * CanvasLines fill = CreateDataObject(data); * fill.material = data.FillMaterial; * fill.SetLines(list); * fill.MakeFillRender(viewRect, data.StetchFill); * }*/ if (data.Depth > 0) { positiveDepth = Math.Max(positiveDepth, data.Depth); } // if (data.DotPrefab != null) //{ for (int i = 0; i < points.Length; i++) { DoubleVector3 pointValue = points[i]; if (edit == false) { pointValue = Data.GetPoint(data.Name, i); } string xFormat = StringFromAxisFormat(pointValue.x, mHorizontalAxis); string yFormat = StringFromAxisFormat(pointValue.y, mVerticalAxis); GraphEventArgs args = new GraphEventArgs(i, (points[i] + new DoubleVector3(0.0, 0.0, data.Depth)).ToVector3(), pointValue.ToDoubleVector2(), (float)pointValue.z, data.Name, xFormat, yFormat); GameObject point = CreatePointObject(data); ChartItemEvents[] events = point.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 = args; } double pointSize = points[i].z * data.PointSize; if (pointSize < 0f) { pointSize = data.PointSize; } point.transform.localScale = new DoubleVector3(pointSize, pointSize, pointSize).ToVector3(); if (data.PointMaterial != null) { Renderer rend = point.GetComponent <Renderer>(); if (rend != null) { rend.material = data.PointMaterial; } ChartMaterialController controller = point.GetComponent <ChartMaterialController>(); if (controller != null && controller.Materials != null) { Color hover = controller.Materials.Hover; Color selected = controller.Materials.Selected; controller.Materials = new ChartDynamicMaterial(data.PointMaterial, hover, selected); } } DoubleVector3 position = points[i]; position.z = data.Depth; point.transform.localPosition = position.ToVector3(); if (mItemLabels != null && mItemLabels.isActiveAndEnabled) { Vector3 labelPos = (points[i] + new DoubleVector3(mItemLabels.Location.Breadth, mItemLabels.Seperation, mItemLabels.Location.Depth + data.Depth)).ToVector3(); if (mItemLabels.Alignment == ChartLabelAlignment.Base) { labelPos.y -= (float)points[i].y; } FormatItem(mRealtimeStringBuilder, xFormat, yFormat); string formatted = mRealtimeStringBuilder.ToString(); string toSet = mItemLabels.TextFormat.Format(formatted, data.Name, ""); BillboardText billboard = ChartCommon.CreateBillboardText(null, mItemLabels.TextPrefab, transform, toSet, labelPos.x, labelPos.y, labelPos.z, 0f, null, hideHierarchy, mItemLabels.FontSize, mItemLabels.FontSharpness); TextController.AddText(billboard); AddBillboardText(data.Name, billboard); } } //} for (int i = 0; i < points.Length; i++) { points[i].z = 0f; } Vector3[] floatPoints = points.Select(x => x.ToVector3()).ToArray(); if (data.LinePrefab != null) { PathGenerator lines = CreateLineObject(data); // float tiling = 1f; if (data.LineTiling.EnableTiling == true && data.LineTiling.TileFactor > 0f) { float length = 0f; for (int i = 1; i < points.Length; i++) { length += (float)(points[i - 1] - points[i]).magnitude; } // tiling = length / data.LineTiling.TileFactor; } lines.Generator(floatPoints, (float)data.LineThickness, false); Vector3 tmp = lines.transform.localPosition; tmp.z = (float)data.Depth; lines.transform.localPosition = tmp; if (data.LineMaterial != null) { Renderer rend = lines.GetComponent <Renderer>(); if (rend != null) { rend.material = data.LineMaterial; } ChartMaterialController controller = lines.GetComponent <ChartMaterialController>(); if (controller != null && controller.Materials != null) { Color hover = controller.Materials.Hover; Color selected = controller.Materials.Selected; controller.Materials = new ChartDynamicMaterial(data.LineMaterial, hover, selected); } } } totalDepth = (float)(positiveDepth + maxThickness * 2f); if (data.FillPrefab != null) { FillPathGenerator fill = CreateFillObject(data); Vector3 tmp = fill.transform.localPosition; tmp.z = (float)data.Depth; fill.transform.localPosition = tmp; if (data.LinePrefab == null || !(data.LinePrefab is SmoothPathGenerator)) { fill.SetLineSmoothing(false, 0, 0f); } else { SmoothPathGenerator smooth = ((SmoothPathGenerator)data.LinePrefab); fill.SetLineSmoothing(true, smooth.JointSmoothing, smooth.JointSize); } fill.SetGraphBounds(viewRect.yMin, viewRect.yMax); fill.SetStrechFill(data.StetchFill); fill.Generator(floatPoints, (float)data.LineThickness * 1.01f, false); if (data.FillMaterial != null) { Renderer rend = fill.GetComponent <Renderer>(); if (rend != null) { rend.material = data.FillMaterial; } ChartMaterialController controller = fill.GetComponent <ChartMaterialController>(); if (controller != null && controller.Materials != null) { Color hover = controller.Materials.Hover; Color selected = controller.Materials.Selected; controller.Materials = new ChartDynamicMaterial(data.FillMaterial, hover, selected); } } } } GenerateAxis(true); }
/// <summary> /// Creates a single bar game object using the chart parameters and the bar prefab /// </summary> /// <param name="innerPosition">the local position of the bar in the chart</param> /// <returns>the new bar game object</returns> private GameObject CreateBar(Vector3 innerPosition, double value, float size, float elevation, float normalizedSize, string category, string group, int index, int categoryIndex) { if (BarPrefabLink == null) { GameObject dummy = new GameObject(); dummy.AddComponent <ChartItem>(); dummy.transform.parent = transform; return(dummy); } GameObject topLevel = new GameObject(); topLevel.AddComponent <ChartItem>(); topLevel.layer = gameObject.layer; topLevel.transform.SetParent(transform, false); topLevel.transform.localScale = new Vector3(1f, 1f, 1f); topLevel.transform.localPosition = innerPosition; GameObject obj = (GameObject)GameObject.Instantiate(BarPrefabLink); Vector3 initialScale = obj.transform.localScale; obj.transform.SetParent(topLevel.transform, false); obj.transform.localScale = new Vector3(1f, 1f, 1f); CharItemEffectController effect = obj.GetComponent <CharItemEffectController>(); if (effect == null) { effect = obj.AddComponent <CharItemEffectController>(); } effect.WorkOnParent = true; effect.InitialScale = false; BarInfo inf = obj.AddComponent <BarInfo>(); obj.AddComponent <ChartItem>(); topLevel.transform.localRotation = Quaternion.identity; obj.transform.localRotation = Quaternion.identity; obj.transform.localPosition = Vector3.zero; ChartCommon.HideObject(obj, hideHierarchy); IBarGenerator generator = obj.GetComponent <IBarGenerator>(); obj.layer = gameObject.layer; // put the bar on the same layer as this object BarObject barObj = new BarObject(); ChartCommon.HideObject(topLevel, hideHierarchy); barObj.Bar = generator; barObj.BarGameObject = obj; barObj.InitialScale = initialScale; barObj.TopObject = topLevel; barObj.InnerPosition = innerPosition; barObj.Size = size; barObj.Category = category; barObj.Group = group; barObj.Value = value; barObj.Elevation = elevation; inf.BarObject = barObj; mBars.Add(new ChartItemIndex(index, categoryIndex), barObj); ChartItemEvents[] events = obj.GetComponentsInChildren <ChartItemEvents>(); for (int i = 0; i < events.Length; ++i) { if (events[i] == null) { continue; } InternalItemEvents comp = (InternalItemEvents)events[i]; comp.Parent = this; comp.UserData = barObj; } ChartMaterialController[] materialController = obj.GetComponentsInChildren <ChartMaterialController>(); for (int i = 0; i < materialController.Length; i++) { ChartMaterialController m = materialController[i]; ChartDynamicMaterial mat = Data.GetMaterial(category); if (mat != null) { m.Materials = mat; m.Refresh(); } } float ySize = 1f * size * initialScale.y; if (generator != null) { generator.Generate(normalizedSize, ySize); } SetBarSize(obj, new Vector3(BarSizeLink.Breadth * initialScale.x, ySize, BarSizeLink.Depth * initialScale.z), elevation); if (mItemLabels != null && mItemLabels.isActiveAndEnabled) { string toSet = mItemLabels.TextFormat.Format(ChartAdancedSettings.Instance.FormatFractionDigits(mItemLabels.FractionDigits, value), category, group); Vector3 labelPos = AlignLabel(mItemLabels, innerPosition, size + elevation); float angle = 45f; if (mItemLabels.Alignment == ChartLabelAlignment.Base) { angle = -45f; } BillboardText billboard = ChartCommon.CreateBillboardText(null, mItemLabels.TextPrefab, topLevel.transform, toSet, labelPos.x, labelPos.y, labelPos.z, angle, obj.transform, hideHierarchy, mItemLabels.FontSize, mItemLabels.FontSharpness); // billboard.UserData = // billboard.UIText.fontSize = ItemLabels.FontSize; // billboard.transform.parent =; barObj.ItemLabel = billboard; TextController.AddText(billboard); } if (mGroupLabels != null && mGroupLabels.isActiveAndEnabled) { if (mGroupLabels.Alignment == GroupLabelAlignment.BarBottom || mGroupLabels.Alignment == GroupLabelAlignment.BarTop || (mGroupLabels.Alignment == GroupLabelAlignment.FirstBar && index == 0)) { Vector3 labelPos = AlignLabel(mGroupLabels, innerPosition, size + elevation); string toSet = mGroupLabels.TextFormat.Format(group, category, group); // float angle = 45f; BillboardText billboard = ChartCommon.CreateBillboardText(null, mGroupLabels.TextPrefab, topLevel.transform, toSet, labelPos.x, labelPos.y, labelPos.z, 0f, obj.transform, hideHierarchy, mGroupLabels.FontSize, mGroupLabels.FontSharpness); barObj.GroupLabel = billboard; TextController.AddText(billboard); } } if (mCategoryLabels != null && mCategoryLabels.isActiveAndEnabled) { if (mCategoryLabels.VisibleLabels != CategoryLabels.ChartCategoryLabelOptions.FirstOnly || index == 0) { Vector3 labelPos = AlignLabel(mCategoryLabels, innerPosition, size + elevation); string toSet = mCategoryLabels.TextFormat.Format(category, category, group); float angle = 45f; if (mCategoryLabels.Alignment == ChartLabelAlignment.Base) { angle = -45f; } BillboardText billboard = ChartCommon.CreateBillboardText(null, mCategoryLabels.TextPrefab, topLevel.transform, toSet, labelPos.x, labelPos.y, labelPos.z, angle, obj.transform, hideHierarchy, mCategoryLabels.FontSize, mCategoryLabels.FontSharpness); barObj.CategoryLabel = billboard; TextController.AddText(billboard); } } if (Orientation == ChartOrientation.Horizontal) { obj.transform.localRotation = Quaternion.Euler(0f, 0, -90f); } return(obj); }
protected override GameObject CreateCategoryObject(Vector3[] path, int category) { Vector3[] newPath = new Vector3[path.Length + 1]; path.CopyTo(newPath, 0); newPath[path.Length] = path[0]; path = newPath; List <CanvasLines.LineSegement> seg = new List <CanvasLines.LineSegement>(); seg.Add(new CanvasLines.LineSegement(path)); RadarChartData.CategoryData cat = ((IInternalRadarData)DataSource).getCategoryData(category); GameObject container = ChartCommon.CreateChartItem(); ChartCommon.HideObject(container, hideHierarchy); container.transform.SetParent(transform, false); container.transform.localScale = new Vector3(1f, 1f, 1f); container.transform.localPosition = Vector3.zero; container.transform.localRotation = Quaternion.identity; if (cat.FillMaterial != null) { RadarFill fill = CreateFillObject(container); fill.material = cat.FillMaterial; fill.SetPath(path, Radius); } if (cat.LineMaterial != null && cat.LineThickness > 0) { CanvasLines lines = CreateLinesObject(container); lines.material = cat.LineMaterial; lines.Thickness = cat.LineThickness; lines.SetHoverPrefab(cat.LineHover); lines.SetLines(seg); } if (cat.PointMaterial != null && cat.PointSize > 0f) { CanvasLines points = CreateLinesObject(container); points.material = cat.PointMaterial; points.MakePointRender(cat.PointSize); points.SetHoverPrefab(cat.PointHover); points.SetLines(seg); string name = cat.Name; points.Hover += (int arg1, int t, object d, Vector2 arg2) => Points_Hover(name, arg1, arg2); points.Leave += () => Points_Leave(name); points.Click += (int arg1, int t, object d, Vector2 arg2) => Points_Click(name, arg1, arg2); } if (mCategoryLabels != null && mCategoryLabels.isActiveAndEnabled) { for (int i = 0; i < path.Length - 1; i++) { string group = DataSource.GetGroupName(i); double val = DataSource.GetValue(cat.Name, group); Vector3 labelPos = path[i]; Vector3 dir = labelPos.normalized; labelPos += dir * mCategoryLabels.Seperation; labelPos += new Vector3(mCategoryLabels.Location.Breadth, 0f, mCategoryLabels.Location.Depth); int fractionDigits = 2; if (mItemLabels != null) { fractionDigits = mItemLabels.FractionDigits; } string toSet = mCategoryLabels.TextFormat.Format(ChartAdancedSettings.Instance.FormatFractionDigits(fractionDigits, val, CustomNumberFormat), cat.Name, group); BillboardText billboard = ChartCommon.CreateBillboardText(null, mCategoryLabels.TextPrefab, transform, toSet, labelPos.x, labelPos.y, labelPos.z, 0f, null, hideHierarchy, mCategoryLabels.FontSize, mCategoryLabels.FontSharpness); TextController.AddText(billboard); AddBillboardText(cat.Name, billboard); } } return(container); }
void GenerateItemLabels(bool realTime, CategoryObject categoryObj, CandleChartData.CategoryData data, Rect viewRect, int refrenceIndex, bool edit) { if (mItemLabels != null && mItemLabels.isActiveAndEnabled) { CanvasChartMesh m = null; if (realTime) { m = categoryObj.mItemLabels; if (m == null) { return; } m.Clear(); } else { m = new CanvasChartMesh(true); m.RecycleText = true; categoryObj.mItemLabels = m; } Rect textRect = viewRect; textRect.xMin -= 1f; textRect.yMin -= 1f; textRect.xMax += 1f; textRect.yMax += 1f; for (int i = 0; i < mTransformed.Count; i++) { Vector2 pointValue = mTransformed[i].MidPoint.ToVector2(); if (textRect.Contains(pointValue) == false) { continue; } CandleChartData.CandleValue candleVal = mTransformed[i]; int candleIndex = i + refrenceIndex; if (edit == false) { candleVal = data.Data[i + refrenceIndex]; } Vector3 labelPos = ((Vector3)pointValue) + new Vector3(mItemLabels.Location.Breadth, mItemLabels.Seperation, mItemLabels.Location.Depth); if (mItemLabels.Alignment == ChartLabelAlignment.Base) { labelPos.y -= (float)mTransformed[i].MidPoint.y; } string toSet; if (realTime == false || categoryObj.mCahced.TryGetValue(candleIndex, out toSet) == false) { string Open = StringFromAxisFormat(new DoubleVector3(candleVal.Start, candleVal.Open, 0.0), mVerticalAxis, false); string Close = StringFromAxisFormat(new DoubleVector3(candleVal.Start, candleVal.Close, 0.0), mVerticalAxis, false); string High = StringFromAxisFormat(new DoubleVector3(candleVal.Start, candleVal.High, 0.0), mVerticalAxis, false); string Low = StringFromAxisFormat(new DoubleVector3(candleVal.Start, candleVal.Low, 0.0), mVerticalAxis, false); string Start = StringFromAxisFormat(new DoubleVector3(candleVal.Start, candleVal.Open, 0.0), mHorizontalAxis, true); string Duration = StringFromAxisFormat(new DoubleVector3(candleVal.Duration, candleVal.Open, 0.0), mHorizontalAxis, true); FormatItem(mRealtimeStringBuilder, Open, Close, High, Low, Start, Duration); toSet = mItemLabels.TextFormat.Format(mRealtimeStringBuilder.ToString(), data.Name, ""); categoryObj.mCahced[candleIndex] = toSet; } labelPos -= new Vector3(CanvasFitOffset.x * TotalWidth, CanvasFitOffset.y * TotalHeight, 0f); BillboardText billboard = m.AddText(this, mItemLabels.TextPrefab, transform, mItemLabels.FontSize, mItemLabels.FontSharpness, toSet, labelPos.x, labelPos.y, labelPos.z, 0f, null); TextController.AddText(billboard); AddBillboardText(data.Name, i + refrenceIndex, billboard); } if (realTime) { m.DestoryRecycled(); if (m.TextObjects != null) { foreach (BillboardText text in m.TextObjects) { ((IInternalUse)this).InternalTextController.AddText(text); } } } } }
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; } }
public override void InternalGenerateChart() { if (gameObject.activeInHierarchy == false) { return; } ClearChart(); base.InternalGenerateChart(); if (((IInternalRadarData)Data).InternalDataSource == null) { return; } double[,] data = ((IInternalRadarData)Data).InternalDataSource.getRawData(); int rowCount = data.GetLength(0); int columnCount = data.GetLength(1); //restrict to 3 groups if (rowCount < 3) { return; } mDirections = new Vector3[rowCount]; float[] angles = new float[rowCount]; for (int i = 0; i < rowCount; i++) { float angle = (float)((((float)i) / (float)rowCount) * Math.PI * 2f) + Angle * Mathf.Deg2Rad; angles[i] = angle; mDirections[i] = new Vector3(Mathf.Cos(angle), Mathf.Sin(angle), 0f); } Vector3[] path = new Vector3[rowCount]; Vector3 zAdd = Vector3.zero; for (int i = 0; i < TotalAxisDevisions; i++) { float rad = Radius * ((float)(i + 1) / (float)TotalAxisDevisions); for (int j = 0; j < rowCount; j++) { path[j] = (mDirections[j] * rad) + zAdd; } // path[rowCount] = path[0]; zAdd.z += AxisAdd; GameObject axisObject = CreateAxisObject(AxisThickness, path); mAxisObjects.Add(axisObject); axisObject.transform.SetParent(transform, false); } if (mGroupLabels != null && mGroupLabels.isActiveAndEnabled) { for (int i = 0; i < rowCount; i++) { string group = Data.GetGroupName(i); Vector3 basePosition = mDirections[i] * Radius; Vector3 breadthAxis = Vector3.Cross(mDirections[i], Vector3.forward); Vector3 position = basePosition + mDirections[i] * mGroupLabels.Seperation; position += breadthAxis * mGroupLabels.Location.Breadth; position += new Vector3(0f, 0f, mGroupLabels.Location.Depth); string toSet = mGroupLabels.TextFormat.Format(group, "", ""); BillboardText billboard = ChartCommon.CreateBillboardText(null, mGroupLabels.TextPrefab, transform, toSet, position.x, position.y, position.z, angles[i], transform, hideHierarchy, mGroupLabels.FontSize, mGroupLabels.FontSharpness); billboard.UserData = group; TextController.AddText(billboard); } } double maxValue = Data.GetMaxValue(); if (maxValue > 0.000001f) { for (int i = 0; i < columnCount; i++) { for (int j = 0; j < rowCount; j++) { float rad = ((float)(data[j, i] / maxValue)) * Radius; path[j] = mDirections[j] * rad; } // path[rowCount] = path[0]; GameObject category = CreateCategoryObject(path, i); category.transform.SetParent(transform, false); } if (mItemLabels != null && mItemLabels.isActiveAndEnabled) { float angle = mItemLabels.Location.Breadth; float blend = (angle / 360f); blend -= Mathf.Floor(blend); blend *= rowCount; int index = (int)blend; int nextIndex = (index + 1) % rowCount; blend = blend - Mathf.Floor(blend); for (int i = 0; i < TotalAxisDevisions; i++) { float factor = ((float)(i + 1) / (float)TotalAxisDevisions); float rad = Radius * factor + mItemLabels.Seperation; string value = ChartAdancedSettings.Instance.FormatFractionDigits(mItemLabels.FractionDigits, (float)(maxValue * factor)); Vector3 position = Vector3.Lerp(mDirections[index], mDirections[nextIndex], blend) * rad; position.z = mItemLabels.Location.Depth; string toSet = mItemLabels.TextFormat.Format(value, "", ""); BillboardText billboard = ChartCommon.CreateBillboardText(null, mItemLabels.TextPrefab, transform, toSet, position.x, position.y, position.z, 0f, transform, hideHierarchy, mItemLabels.FontSize, mItemLabels.FontSharpness); billboard.UserData = (float)(maxValue * factor); TextController.AddText(billboard); } } } }
protected override GameObject CreateCategoryObject(Vector3[] path, int category) { RadarChartData.CategoryData cat = ((IInternalRadarData)DataSource).getCategoryData(category); GameObject container = ChartCommon.CreateChartItem(); ChartCommon.HideObject(container, hideHierarchy); container.transform.SetParent(transform, false); container.transform.localScale = new Vector3(1f, 1f, 1f); container.transform.localPosition = new Vector3(0f, 0f, cat.Seperation); container.transform.localRotation = Quaternion.identity; if (cat.FillMaterial != null) { RadarFillGenerator fill = CreateFillObject(container); fill.Smoothing = cat.FillSmoothing; Renderer rend = fill.GetComponent <Renderer>(); if (rend != null) { rend.material = cat.FillMaterial; } fill.Generate(path, Radius, cat.Curve); } if (cat.LinePrefab != null && cat.LineMaterial != null && cat.LineThickness > 0) { GameObject line = CreatePrefab(container, cat.LinePrefab.gameObject); PathGenerator pathGen = line.GetComponent <PathGenerator>(); Renderer rend = line.GetComponent <Renderer>(); if (rend != null) { rend.material = cat.LineMaterial; } pathGen.Generator(path, cat.LineThickness, true); } GameObject prefab = cat.PointPrefab; if (prefab == null) { if (mEmptyPointPrefab == null) { mEmptyPointPrefab = (GameObject)Resources.Load("Chart And Graph/SelectHandle"); } prefab = mEmptyPointPrefab; } if (prefab != null) { for (int i = 0; i < path.Length; i++) { GameObject point = CreatePrefab(container, prefab); string group = DataSource.GetGroupName(i); double value = DataSource.GetValue(cat.Name, group); RadarEventArgs args = new RadarEventArgs(cat.Name, group, value, path[i], i); point.transform.localPosition = path[i]; point.transform.localScale = new Vector3(cat.PointSize, cat.PointSize, cat.PointSize); Renderer rend = point.GetComponent <Renderer>(); if (rend != null) { rend.material = cat.PointMaterial; } ChartMaterialController controller = point.GetComponent <ChartMaterialController>(); if (controller != null && controller.Materials != null) { Color hover = controller.Materials.Hover; Color selected = controller.Materials.Selected; controller.Materials = new ChartDynamicMaterial(cat.PointMaterial, hover, selected); } ChartItemEvents[] events = point.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 = args; } } } if (mCategoryLabels != null && mCategoryLabels.isActiveAndEnabled) { for (int i = 0; i < path.Length; i++) { string group = DataSource.GetGroupName(i); double val = DataSource.GetValue(cat.Name, group); Vector3 labelPos = path[i]; Vector3 dir = labelPos.normalized; labelPos += dir * mCategoryLabels.Seperation; labelPos += new Vector3(mCategoryLabels.Location.Breadth, 0f, mCategoryLabels.Location.Depth); int fractionDigits = 2; if (mItemLabels != null) { fractionDigits = mItemLabels.FractionDigits; } string toSet = mCategoryLabels.TextFormat.Format(ChartAdancedSettings.Instance.FormatFractionDigits(fractionDigits, val), cat.Name, group); BillboardText billboard = ChartCommon.CreateBillboardText(null, mCategoryLabels.TextPrefab, transform, toSet, labelPos.x, labelPos.y, labelPos.z, 0f, null, hideHierarchy, mCategoryLabels.FontSize, mCategoryLabels.FontSharpness); TextController.AddText(billboard); AddBillboardText(cat.Name, billboard); } } return(container); }
private void GeneratePyramid(bool update) { if (update == false) { ClearChart(); } else { EnsureTextController(); } if (((IInternalPyramidData)Data).InternalDataSource == null) { return; } double[,] data = ((IInternalPyramidData)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; } var rectTrans = GetComponent <RectTransform>(); totalHeight = rectTrans.rect.height; totalWidth = rectTrans.rect.width; float baseX1 = 0; float baseX2 = totalWidth; float accumilatedHeight = 0; float?firstCenterHeight = null; float acummilatedWeight = 0; for (int i = 0; i < columnCount; ++i) { object userData = ((IInternalPyramidData)Data).InternalDataSource.Columns[i].UserData; var categoryData = ((PyramidData.CategoryData)userData); string name = ((IInternalPyramidData)Data).InternalDataSource.Columns[i].Name; double amount = Math.Max(data[0, i], 0); if (amount == 0f) { continue; } float weight = (float)(amount / total); float actualHeight = totalHeight * weight; float slopeRight = categoryData.RightSlope; float slopeLeft = categoryData.LeftSlope; float atan; switch (slope) { case SlopeType.Center: atan = -Mathf.Atan2(totalHeight, totalWidth * 0.5f) * Mathf.Rad2Deg + 90; slopeRight = atan; slopeLeft = atan; break; case SlopeType.Left: atan = -Mathf.Atan2(totalHeight, totalWidth) * Mathf.Rad2Deg + 90; slopeLeft = 0; slopeRight = atan; break; case SlopeType.Right: atan = -Mathf.Atan2(totalHeight, totalWidth) * Mathf.Rad2Deg + 90; slopeLeft = atan; slopeRight = 0; break; default: break; } GameObject pyramidObject = null; GameObject pyramidBackObject = null; IPyramidGenerator generator = null; IPyramidGenerator backgenerator = null; PyramidObject dataObject; float centerHeight = actualHeight * 0.5f + accumilatedHeight; float unblendedHeight = centerHeight; if (firstCenterHeight.HasValue == false) { firstCenterHeight = centerHeight; } centerHeight = Mathf.Lerp(firstCenterHeight.Value, centerHeight, categoryData.PositionBlend); if (mPyramids.TryGetValue(name, out dataObject)) { pyramidBackObject = dataObject.backObject; pyramidObject = dataObject.pyramidObject; backgenerator = dataObject.BackGenerator; generator = dataObject.Generator; generator.SetParams(baseX1, baseX2, totalWidth, slopeLeft, slopeRight, actualHeight, inset, 0f, 1f); if (backgenerator != null) { backgenerator.SetParams(baseX1, baseX2, totalWidth, slopeLeft, slopeRight, actualHeight, 0f, acummilatedWeight, acummilatedWeight + weight); } if (dataObject.ItemLabel) { Vector3 labelPos = AlignTextPosition(mItemLabels, dataObject, generator, centerHeight); dataObject.ItemLabel.transform.localPosition = labelPos; ChartCommon.UpdateTextParams(dataObject.ItemLabel.UIText, categoryData.Title); } } else { dataObject = new PyramidObject(); if (backMaterial != null) { var backGenerator = PreparePyramidObject(out pyramidBackObject); backGenerator.SetParams(baseX1, baseX2, totalWidth, slopeLeft, slopeRight, actualHeight, 0f, acummilatedWeight, acummilatedWeight + weight); dataObject.backObject = pyramidBackObject; dataObject.BackGenerator = backGenerator; ChartCommon.HideObject(pyramidBackObject, hideHierarchy); pyramidBackObject.transform.SetParent(transform, false); ChartCommon.EnsureComponent <ChartItem>(pyramidBackObject); ChartMaterialController backcontrol = ChartCommon.EnsureComponent <ChartMaterialController>(pyramidBackObject); backcontrol.Materials = new ChartDynamicMaterial(backMaterial); foreach (var itemEffect in pyramidBackObject.GetComponents <ChartItemEffect>()) { ChartCommon.SafeDestroy(itemEffect); } ChartCommon.SafeDestroy(backGenerator.ContainerObject); } generator = PreparePyramidObject(out pyramidObject); generator.SetParams(baseX1, baseX2, totalWidth, slopeLeft, slopeRight, actualHeight, inset, 0f, 1f); ChartCommon.HideObject(pyramidObject, hideHierarchy); pyramidObject.transform.SetParent(transform, false); ChartCommon.EnsureComponent <ChartItem>(pyramidObject); ChartMaterialController control = ChartCommon.EnsureComponent <ChartMaterialController>(pyramidObject); control.Materials = Data.GetMaterial(name); control.Refresh(); dataObject.Generator = generator; dataObject.category = name; dataObject.pyramidObject = pyramidObject; mPyramids.Add(name, dataObject); CharItemEffectController effect = ChartCommon.EnsureComponent <CharItemEffectController>(pyramidObject); effect.WorkOnParent = false; effect.InitialScale = false; ChartItemEvents[] events = pyramidObject.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, generator, 0f); float angle = justification == JustificationType.LeftAligned ? -180f : 180f; BillboardText billboard = ChartCommon.CreateBillboardText(null, mItemLabels.TextPrefab, dataObject.pyramidObject.transform, categoryData.Title, labelPos.x, labelPos.y, labelPos.z, angle, null, hideHierarchy, mItemLabels.FontSize, mItemLabels.FontSharpness); dataObject.ItemLabel = billboard; dataObject.ItemLabel.transform.localPosition = labelPos; TextController.AddText(billboard); } } dataObject.Text = categoryData.Text; dataObject.Title = categoryData.Title; if (IsCanvas) { if (pyramidObject != null) { Vector2 actualPosition = new Vector2(0.5f, centerHeight) + categoryData.Shift; actualPosition = new Vector2(actualPosition.x, actualPosition.y / TotalHeight); var objectRect = pyramidObject.GetComponent <RectTransform>(); objectRect.pivot = new Vector2(0.5f, 0.5f); objectRect.anchorMin = actualPosition; objectRect.anchorMax = actualPosition; objectRect.anchoredPosition = new Vector2(); objectRect.sizeDelta = new Vector2(totalWidth, actualHeight); } if (pyramidBackObject != null) { Vector2 actualPosition = new Vector2(0.5f, unblendedHeight); actualPosition = new Vector2(actualPosition.x, actualPosition.y / TotalHeight); var objectRect = pyramidBackObject.GetComponent <RectTransform>(); objectRect.pivot = new Vector2(0f, 0f); objectRect.anchorMin = actualPosition; objectRect.anchorMax = actualPosition; objectRect.anchoredPosition = new Vector2(); } } accumilatedHeight += actualHeight; acummilatedWeight += weight; if (backgenerator != null) { backgenerator.Generate(); } generator.Generate(); generator.GetUpperBase(out baseX1, out baseX2); generator.ApplyInfo(categoryData.Title, categoryData.Text, categoryData.Image, categoryData.Scale); generator.SetAlpha(categoryData.Alpha); } }
public override void InternalGenerateChart() { if (gameObject.activeInHierarchy == false) { return; } base.InternalGenerateChart(); ClearChart(); if (Data == null) { return; } double minX = ((IInternalGraphData)Data).GetMinValue(0, false); double minY = ((IInternalGraphData)Data).GetMinValue(1, false); double maxX = ((IInternalGraphData)Data).GetMaxValue(0, false); double maxY = ((IInternalGraphData)Data).GetMaxValue(1, false); double xScroll = GetScrollOffset(0); double yScroll = GetScrollOffset(1); double xSize = maxX - minX; double ySize = maxY - minY; double xOut = minX + xScroll + xSize; double yOut = minY + yScroll + ySize; DoubleVector3 min = new DoubleVector3(xScroll + minX, yScroll + minY); DoubleVector3 max = new DoubleVector3(xOut, yOut); Rect viewRect = new Rect(0f, 0f, widthRatio, heightRatio); int index = 0; int total = ((IInternalGraphData)Data).TotalCategories + 1; double positiveDepth = 0f; double maxThickness = 0f; bool edit = false; m3DTexts.Clear(); mActiveTexts.Clear(); foreach (GraphData.CategoryData data in ((IInternalGraphData)Data).Categories) { mClipped.Clear(); maxThickness = Math.Max(data.LineThickness, maxThickness); DoubleVector3[] points = data.getPoints().ToArray(); Rect uv; int refrenceIndex = ClipPoints(points, mClipped, out uv); TransformPoints(mClipped, mTransformed, viewRect, min, max); if (points.Length == 0 && ChartCommon.IsInEditMode) { edit = true; int tmpIndex = total - 1 - index; float y1 = (((float)tmpIndex) / (float)total); float y2 = (((float)tmpIndex + 1) / (float)total); DoubleVector3 pos1 = ChartCommon.interpolateInRect(viewRect, new DoubleVector3(0f, y1, -1f)).ToDoubleVector3(); DoubleVector3 pos2 = ChartCommon.interpolateInRect(viewRect, new DoubleVector3(0.5f, y2, -1f)).ToDoubleVector3(); DoubleVector3 pos3 = ChartCommon.interpolateInRect(viewRect, new DoubleVector3(1f, y1, -1f)).ToDoubleVector3(); points = new DoubleVector3[] { pos1, pos2, pos3 }; mTransformed.AddRange(points.Select(x => (Vector4)x.ToVector3())); index++; } /*if (data.FillMaterial != null) * { * CanvasLines fill = CreateDataObject(data); * fill.material = data.FillMaterial; * fill.SetLines(list); * fill.MakeFillRender(viewRect, data.StetchFill); * }*/ if (data.Depth > 0) { positiveDepth = Math.Max(positiveDepth, data.Depth); } // if (data.DotPrefab != null) //{ float minViewX = Math.Min(viewRect.xMin, viewRect.xMax); float maxViewX = Math.Max(viewRect.xMin, viewRect.xMax); float minViewY = Math.Min(viewRect.yMin, viewRect.yMax); float maxViewY = Math.Max(viewRect.yMin, viewRect.yMax); for (int i = 0; i < mTransformed.Count; i++) { float transX = mTransformed[i].x; float transY = mTransformed[i].y; if (minViewX > transX || maxViewX < transX) { continue; } if (minViewX > transY || maxViewX < transY) { continue; } DoubleVector3 pointValue = points[i]; if (edit == false) { pointValue = Data.GetPoint(data.Name, i + refrenceIndex); } string xFormat = StringFromAxisFormat(pointValue, mHorizontalAxis, true); string yFormat = StringFromAxisFormat(pointValue, mVerticalAxis, false); GraphEventArgs args = new GraphEventArgs(i, (mTransformed[i] + new Vector4(0f, 0f, (float)data.Depth)), pointValue.ToDoubleVector2(), (float)pointValue.z, data.Name, xFormat, yFormat); GameObject point = CreatePointObject(data); ChartItemEvents[] events = point.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 = args; } double pointSize = mTransformed[i].w * data.PointSize; if (pointSize < 0f) { pointSize = data.PointSize; } point.transform.localScale = new DoubleVector3(pointSize, pointSize, pointSize).ToVector3(); if (data.PointMaterial != null) { Renderer rend = point.GetComponent <Renderer>(); if (rend != null) { rend.material = data.PointMaterial; } ChartMaterialController controller = point.GetComponent <ChartMaterialController>(); if (controller != null && controller.Materials != null) { Color hover = controller.Materials.Hover; Color selected = controller.Materials.Selected; controller.Materials = new ChartDynamicMaterial(data.PointMaterial, hover, selected); } } DoubleVector3 position = new DoubleVector3(mTransformed[i]); position.z = data.Depth; point.transform.localPosition = position.ToVector3(); if (mItemLabels != null && mItemLabels.isActiveAndEnabled) { Vector3 labelPos = (new DoubleVector3(mTransformed[i]) + new DoubleVector3(mItemLabels.Location.Breadth, mItemLabels.Seperation, mItemLabels.Location.Depth + data.Depth)).ToVector3(); if (mItemLabels.Alignment == ChartLabelAlignment.Base) { labelPos.y -= (float)mTransformed[i].y; } FormatItem(mRealtimeStringBuilder, xFormat, yFormat); string formatted = mRealtimeStringBuilder.ToString(); string toSet = mItemLabels.TextFormat.Format(formatted, data.Name, ""); BillboardText billboard = ChartCommon.CreateBillboardText(null, mItemLabels.TextPrefab, transform, toSet, labelPos.x, labelPos.y, labelPos.z, 0f, null, hideHierarchy, mItemLabels.FontSize, mItemLabels.FontSharpness); TextController.AddText(billboard); AddBillboardText(data.Name, billboard); } } //} for (int i = 0; i < mTransformed.Count; i++) { var t = mTransformed[i]; t.z = 0f; t.w = 0f; mTransformed[i] = t; } Vector3[] floatPoints = mTransformed.Select(x => (Vector3)x).ToArray(); if (floatPoints.Length >= 2) { Vector2 res; float maxF = Math.Max(floatPoints[0].y, floatPoints[1].y); float minF = Math.Min(floatPoints[0].y, floatPoints[1].y); float firstX = viewRect.x; float secondX = viewRect.x + viewRect.width; if (min.x > max.x) { float tmp = firstX; firstX = secondX; secondX = tmp; } if (ChartCommon.SegmentIntersection(floatPoints[0], floatPoints[1], new Vector3(firstX, maxF, 0f), new Vector3(firstX, minF, 0f), out res)) { floatPoints[0] = res; } Vector3 last = floatPoints[floatPoints.Length - 1]; Vector3 secondLast = floatPoints[floatPoints.Length - 2]; maxF = Math.Max(last.y, secondLast.y); minF = Math.Min(last.y, secondLast.y); if (ChartCommon.SegmentIntersection(last, secondLast, new Vector3(secondX, maxF, 0f), new Vector3(secondX, minF, 0f), out res)) { floatPoints[floatPoints.Length - 1] = res; } } List <List <Vector3> > clippedLines = new List <List <Vector3> >(8); List <List <Vector3> > fillClippedLines = new List <List <Vector3> >(8); List <Vector3> current = null; List <Vector3> currentFill = null; for (int i = 1; i < floatPoints.Length; i++) { Vector3 v1 = floatPoints[i - 1]; Vector3 v2 = floatPoints[i]; bool last = i == floatPoints.Length - 1; if ((v1.y <= minViewY && v2.y <= minViewY)) { continue; } if (currentFill == null) { currentFill = new List <Vector3>(30); fillClippedLines.Add(currentFill); } if ((v1.y >= maxViewY && v2.y >= maxViewY)) { currentFill.Add(new Vector3(v1.x, maxViewY, v1.z)); if (last) { currentFill.Add(new Vector3(v2.x, maxViewY, v2.z)); } continue; } if (current == null) { current = new List <Vector3>(30); clippedLines.Add(current); } if ((v1.y >= minViewY && v2.y >= minViewY) && (v1.y <= maxViewY && v2.y <= maxViewY)) { current.Add(v1); currentFill.Add(v1); if (last) { current.Add(v2); currentFill.Add(v2); } continue; } if (v1.y <= minViewY) { var v = ChartCommon.LineCrossing(v1, v2, minViewY); current.Add(v); currentFill.Add(v); } else { if (v1.y >= maxViewY) { var v = ChartCommon.LineCrossing(v1, v2, maxViewY); current.Add(v); currentFill.Add(new Vector3(v1.x, maxViewY, v1.z)); currentFill.Add(v); } else { current.Add(v1); currentFill.Add(v1); } } if (v2.y <= minViewY) { var v = ChartCommon.LineCrossing(v1, v2, minViewY); current.Add(v); currentFill.Add(v); currentFill = null; } else { if (v2.y >= maxViewY) { var v = ChartCommon.LineCrossing(v1, v2, maxViewY); current.Add(v); currentFill.Add(v); if (last) { currentFill.Add(new Vector3(v2.x, maxViewY, v2.z)); } } else { current.Add(v2); if (last) { currentFill.Add(v2); } } } current = null; } if (data.LinePrefab != null) { for (int i = 0; i < clippedLines.Count; i++) { if (clippedLines[i].Count == 0) { continue; } PathGenerator lines = CreateLineObject(data); // float tiling = 1f; if (data.LineTiling.EnableTiling == true && data.LineTiling.TileFactor > 0f) { float length = 0f; for (int j = 1; j < mTransformed.Count; j++) { length += (float)(((Vector3)mTransformed[j - 1]) - (Vector3)mTransformed[j]).magnitude; } // tiling = length / data.LineTiling.TileFactor; } lines.Generator(clippedLines[i].ToArray(), (float)data.LineThickness, false); Vector3 tmp = lines.transform.localPosition; tmp.z = (float)data.Depth; lines.transform.localPosition = tmp; if (data.LineMaterial != null) { Renderer rend = lines.GetComponent <Renderer>(); if (rend != null) { rend.material = data.LineMaterial; } ChartMaterialController controller = lines.GetComponent <ChartMaterialController>(); if (controller != null && controller.Materials != null) { Color hover = controller.Materials.Hover; Color selected = controller.Materials.Selected; controller.Materials = new ChartDynamicMaterial(data.LineMaterial, hover, selected); } } } } totalDepth = (float)(positiveDepth + maxThickness * 2f); if (data.FillPrefab != null) { for (int i = 0; i < fillClippedLines.Count; i++) { if (fillClippedLines[i].Count == 0) { continue; } FillPathGenerator fill = CreateFillObject(data); Vector3 tmp = fill.transform.localPosition; tmp.z = (float)data.Depth; fill.transform.localPosition = tmp; if (data.LinePrefab == null || !(data.LinePrefab is SmoothPathGenerator)) { fill.SetLineSmoothing(false, 0, 0f); } else { SmoothPathGenerator smooth = ((SmoothPathGenerator)data.LinePrefab); fill.SetLineSmoothing(true, smooth.JointSmoothing, smooth.JointSize); } fill.SetGraphBounds(viewRect.yMin, viewRect.yMax); fill.SetStrechFill(data.StetchFill); fill.Generator(fillClippedLines[i].ToArray(), (float)data.LineThickness * 1.01f, false); if (data.FillMaterial != null) { Renderer rend = fill.GetComponent <Renderer>(); if (rend != null) { rend.material = data.FillMaterial; } ChartMaterialController controller = fill.GetComponent <ChartMaterialController>(); if (controller != null && controller.Materials != null) { Color hover = controller.Materials.Hover; Color selected = controller.Materials.Selected; controller.Materials = new ChartDynamicMaterial(data.FillMaterial, hover, selected); } } } } } GenerateAxis(true); }
private void btnExport_Click(object sender, EventArgs e) { if (frmListProject.OpenPro != -1) { // Update ProjectShape pro = new ProjectShape(); pro.IDPro = frmListProject.OpenPro; pro.Note = frmOutliner.note; ProjectController.AddProject(pro); Shape sp = new Shape(); sp.ID = root.IdObj; sp.LocationX = root.Point.X; sp.LocationY = root.Point.Y; sp.Witdh = root.Witdh; sp.Height = root.Height; sp.NameShape = root.Name; sp.IDPro = frmListProject.OpenPro; ShapeController.AddShape(sp); foreach (var shape in root.lstObj) { sp.ID = shape.IdObj; sp.LocationX = shape.Point.X; sp.LocationY = shape.Point.Y; sp.Witdh = shape.Witdh; sp.Height = shape.Height; sp.NameShape = shape.Name; sp.IDPro = frmListProject.OpenPro; if (shape.Name == "Curve") { sp.LocationX2 = shape.P2.X; sp.LocationY2 = shape.P2.Y; } ShapeController.AddShape(sp); } Infor t = new Infor(); foreach (var temp in lstRt) { t.ID = Convert.ToInt32(temp.Tag); t.LocationX = temp.Location.X; t.LocationY = temp.Location.Y; t.Witdh = temp.Size.Width; t.Height = temp.Size.Height; t.Description = temp.Text; TextController.AddText(t); } } else { // Add new var lst = ProjectController.getListProject(frmMain.idPro); while (lst.Count() > 0) { frmMain.idPro++; lst = ProjectController.getListProject(frmMain.idPro); } ; ProjectShape pro = new ProjectShape(); pro.IDPro = frmMain.idPro; pro.Note = frmOutliner.note; ProjectController.AddProject(pro); Shape sp = new Shape(); // Lưu root var c = ShapeController.CheckShape(root.IdObj); while (c.Count() > 0) { root.IdObj = root.IdObj + 1; c = ShapeController.CheckShape(root.IdObj); } sp.ID = root.IdObj; sp.LocationX = root.Point.X; sp.LocationY = root.Point.Y; sp.Witdh = root.Witdh; sp.Height = root.Height; sp.NameShape = root.Name; sp.IDPro = pro.IDPro; ShapeController.AddShape(sp); foreach (var shape in root.lstObj) { // Lưu shape var d = ShapeController.CheckShape(shape.IdObj); while (d.Count() > 0) { shape.IdObj = shape.IdObj + 1; d = ShapeController.CheckShape(shape.IdObj); } sp.ID = shape.IdObj; sp.LocationX = shape.Point.X; sp.LocationY = shape.Point.Y; sp.Witdh = shape.Witdh; sp.Height = shape.Height; sp.NameShape = shape.Name; sp.IDPro = pro.IDPro; if (shape.Name == "Curve") { sp.LocationX2 = shape.P2.X; sp.LocationY2 = shape.P2.Y; } ShapeController.AddShape(sp); } Infor t = new Infor(); foreach (var temp in lstRt) { t.ID = Convert.ToInt32(temp.Tag); t.LocationX = temp.Location.X; t.LocationY = temp.Location.Y; t.Witdh = temp.Size.Width; t.Height = temp.Size.Height; t.Description = temp.Text; TextController.AddText(t); } } }