void TrimItem(float x1, float y1, float x2, float y2, bool xAxis, bool oposite, ref Vector2 from, ref Vector2 to) { Vector2 seg1 = new Vector2(x1, y1); Vector2 seg2 = new Vector2(x2, y2); Vector2 point; if (ChartCommon.SegmentIntersection(seg1, seg2, from, to, out point) == false) { return; } if (xAxis) { if ((to.y > from.y) ^ oposite) { from = point; } else { to = point; } return; } if ((to.x > from.x) ^ oposite) { from = point; } else { to = point; } }
#pragma warning restore 0672 void FillChartMesh(IChartMesh mesh) { UIVertex v1 = vertices[0]; UIVertex v2 = vertices[1]; UIVertex v3 = vertices[2]; UIVertex v4 = vertices[3]; v1.position += (Vector3)(normals[0] * mInset); v2.position += (Vector3)(normals[1] * mInset); v3.position += (Vector3)(normals[2] * mInset); v4.position += (Vector3)(normals[3] * mInset); Vector2 inter; if (ChartCommon.SegmentIntersection(v1.position, v3.position, v2.position, v4.position, out inter)) { v3.position = inter; v4.position = inter; } mesh.AddQuad(v1, v2, v3, v4); }
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); for (int i = 0; i < mTransformed.Count; i++) { float transX = mTransformed[i].x; if (minViewX > transX || maxViewX < transX) { 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; } } 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 < mTransformed.Count; i++) { length += (float)(((Vector3)mTransformed[i - 1]) - (Vector3)mTransformed[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); }