public void AddLinearCurveToCategory(string category, DoubleVector2 toPoint, double pointSize = -1f) { if (mData.ContainsKey(category) == false) { Debug.LogWarning("Invalid category name. Make sure the category is present in the graph"); return; } CategoryData data = (CategoryData)mData[category]; if (data.IsBezierCurve == false) { Debug.LogWarning("Category is not Bezier curve. use AddPointToCategory instead "); return; } if (data.Data.Count == 0) { Debug.LogWarning("Initial not set for this category, call is ignored. Call SetCurveInitialPoint to create a new curve"); return; } List <DoubleVector3> points = data.Data; DoubleVector3 last = points[points.Count - 1]; DoubleVector3 c1 = DoubleVector3.Lerp(last, toPoint.ToDoubleVector3(), 1f / 3f); DoubleVector3 c2 = DoubleVector3.Lerp(last, toPoint.ToDoubleVector3(), 2f / 3f); AddCurveToCategory(category, c1.ToDoubleVector2(), c2.ToDoubleVector2(), toPoint, pointSize); }
public void AddCurveToCategory(string category, DoubleVector2 controlPointA, DoubleVector2 controlPointB, DoubleVector2 toPoint, double pointSize = -1f) { if (mData.ContainsKey(category) == false) { Debug.LogWarning("Invalid category name. Make sure the category is present in the graph"); return; } CategoryData data = (CategoryData)mData[category]; if (data.IsBezierCurve == false) { Debug.LogWarning("Category is not Bezier curve. use AddPointToCategory instead "); return; } if (data.Data.Count == 0) { Debug.LogWarning("Initial not set for this category, call is ignored. Call SetCurveInitialPoint to create a new curve"); return; } List <DoubleVector3> points = data.Data; if (points.Count > 0 && points[points.Count - 1].x > toPoint.x) { Debug.LogWarning("Curves must be added sequentialy according to the x axis. toPoint.x is smaller then the previous point x value"); return; } data.Regenerate = true; DoubleVector2 min = min3(controlPointA, controlPointB, toPoint); DoubleVector2 max = max3(controlPointA, controlPointB, toPoint); if (data.MaxRadius.HasValue == false || data.MaxRadius.Value < pointSize) { data.MaxRadius = pointSize; } if (data.MaxX.HasValue == false || data.MaxX.Value < max.x) { data.MaxX = max.x; } if (data.MinX.HasValue == false || data.MinX.Value > min.x) { data.MinX = min.x; } if (data.MaxY.HasValue == false || data.MaxY.Value < max.y) { data.MaxY = max.y; } if (data.MinY.HasValue == false || data.MinY.Value > min.y) { data.MinY = min.y; } points.Add(controlPointA.ToDoubleVector3()); points.Add(controlPointB.ToDoubleVector3()); points.Add(new DoubleVector3(toPoint.x, toPoint.y, pointSize)); RaiseDataChanged(); }
public GraphEventArgs(int index, Vector3 position, DoubleVector2 value, float magnitude, string category, string xString, string yString) { Position = position; Value = value; Category = category; XString = xString; YString = yString; Index = index; Magnitude = magnitude; }
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; } }
private DoubleVector2 min3(DoubleVector2 a, DoubleVector2 b, DoubleVector2 c) { return(new DoubleVector2(min3(a.x, b.x, c.x), min3(a.y, b.y, c.y))); }
protected DoubleVector4 TransformPoint(Rect viewRect, Vector3 point, DoubleVector2 min, DoubleVector2 range) { return(interpolateInRect(viewRect, new DoubleVector3((point.x - min.x) / range.x, (point.y - min.y) / range.y))); }
private DoubleVector2 max3(DoubleVector2 a, DoubleVector2 b, DoubleVector2 c) { return new DoubleVector2(max3(a.x, b.x, c.x), max3(a.y, b.y, c.y)); }