protected override GameObject CreateAxisObject(float thickness, Vector3[] path)
        {
            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));
            GameObject conatiner = ChartCommon.CreateChartItem();

            ChartCommon.HideObject(conatiner, hideHierarchy);
            conatiner.transform.SetParent(transform, false);
            conatiner.transform.localScale    = new Vector3(1f, 1f, 1f);
            conatiner.transform.localPosition = Vector3.zero;
            conatiner.transform.localRotation = Quaternion.identity;

            if (AxisLineMaterial != null && AxisThickness > 0f)
            {
                CanvasLines lines = CreateLinesObject(conatiner);
                lines.material  = AxisLineMaterial;
                lines.Thickness = thickness;
                lines.SetLines(seg);
            }

            if (AxisPointMaterial != null && AxisPointSize > 0f)
            {
                CanvasLines points = CreateLinesObject(conatiner);
                points.material = AxisPointMaterial;
                points.MakePointRender(AxisPointSize);
                points.SetLines(seg);
            }

            return(conatiner);
        }
Beispiel #2
0
        private CanvasLines CreateDataObject(GraphData.CategoryData data, GameObject rectMask)
        {
            GameObject obj = new GameObject("Lines", typeof(RectTransform));

            ChartCommon.HideObject(obj, hideHierarchy);
            obj.AddComponent <ChartItem>();
            RectTransform t = obj.GetComponent <RectTransform>();

            obj.AddComponent <CanvasRenderer>();

            //  Canvas c = obj.AddComponent<Canvas>();

            //c.pixelPerfect = false;
            //obj.AddComponent<GraphicRaycaster>();

            CanvasLines lines = obj.AddComponent <CanvasLines>();

            lines.maskable = true;

            t.SetParent(rectMask.transform, false);
            t.localScale       = new Vector3(1f, 1f, 1f);
            t.anchorMin        = new Vector2(0f, 0f);
            t.anchorMax        = new Vector2(0f, 0f);
            t.anchoredPosition = Vector3.zero;
            t.localRotation    = Quaternion.identity;
            return(lines);
        }
        protected CanvasLines CreateLinesObject(GameObject conatiner)
        {
            GameObject obj = ChartCommon.CreateCanvasChartItem();

            ChartCommon.HideObject(obj, hideHierarchy);
            obj.AddComponent <ChartItem>();
            obj.AddComponent <CanvasRenderer>();
            CanvasLines lines = obj.AddComponent <CanvasLines>();

            obj.transform.SetParent(conatiner.transform, false);
            obj.transform.localScale    = new Vector3(1f, 1f, 1f);
            obj.transform.localPosition = Vector3.zero;
            obj.transform.localRotation = Quaternion.identity;
            return(lines);
        }
 private CanvasLines AddLineRenderer(GameObject topObject, CanvasLines.LineSegement line)
 {
     GameObject obj = ChartCommon.CreateCanvasChartItem();
     obj.transform.SetParent(topObject.transform);
     obj.transform.localScale = new Vector3(1f, 1f, 1f);
     obj.transform.localPosition = new Vector3(0f, 0f, 0f);
     obj.transform.localRotation = Quaternion.identity;
     CanvasLines lines = obj.AddComponent<CanvasLines>();
     lines.raycastTarget = false;
     var lst = new List<CanvasLines.LineSegement>();
     lst.Add(line);
     lines.SetLines(lst);
     lines.Thickness = LineThicknessLink;
     lines.material = LineMaterialLink;
     return lines;
 }
        private CanvasLines CreateDataObject(GraphData.CategoryData data, GameObject rectMask, bool mask)
        {
            GameObject obj = new GameObject("Lines", typeof(RectTransform));

            ChartCommon.HideObject(obj, hideHierarchy);
            obj.AddComponent <ChartItem>();

            var rend = obj.AddComponent <CanvasRenderer>();

            rend.cullTransparentMesh = false;

            CenterObject(obj, rectMask.GetComponent <RectTransform>());
            //  Canvas c = obj.AddComponent<Canvas>();

            //c.pixelPerfect = false;
            //obj.AddComponent<GraphicRaycaster>();
            CanvasLines lines = obj.AddComponent <CanvasLines>();

            lines.maskable = true;

            return(lines);
        }
Beispiel #6
0
        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;
            }
        }
        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);
        }