/// <summary>
 /// fix the labels after the axis data is updated
 /// </summary>
 /// <param name="parent"></param>
 partial void InnerFixLabels(AnyChart parent)
 {
     if (mAxis == null)
     {
         return;
     }
     if (((ChartMainDivisionInfo)mAxis.MainDivisions).Messure == ChartDivisionInfo.DivisionMessure.DataUnits)
     {
         SetAxis(mScroll, mParent, mAxis, mOrientation, mIsSubDivision);
         return;
     }
     for (int i = 0; i < mTexts.Count; i++)
     {
         BillboardText text = mTexts[i];
         double        min  = ((IInternalUse)parent).InternalMinValue(mAxis);
         double        max  = ((IInternalUse)parent).InternalMaxValue(mAxis);
         if (text.UserData is AxisBase.TextData)
         {
             AxisBase.TextData data   = (AxisBase.TextData)text.UserData;
             double            newVal = min * (1.0 - (double)data.interp) + max * (double)data.interp;
             string            toSet  = "";
             if (mAxis.Format == AxisFormat.Number)
             {
                 toSet = ChartAdancedSettings.Instance.FormatFractionDigits(data.fractionDigits, (float)newVal);
             }
             else
             {
                 DateTime date = ChartDateUtility.ValueToDate(newVal);
                 if (mAxis.Format == AxisFormat.DateTime)
                 {
                     toSet = ChartDateUtility.DateToDateTimeString(date, mParent.CustomDateTimeFormat);
                 }
                 else
                 {
                     if (mAxis.Format == AxisFormat.Date)
                     {
                         toSet = ChartDateUtility.DateToDateString(date);
                     }
                     else
                     {
                         toSet = ChartDateUtility.DateToTimeString(date);
                     }
                 }
             }
             toSet = data.info.TextPrefix + toSet + data.info.TextSuffix;
             ChartCommon.UpdateTextParams(text.UIText, toSet);
         }
     }
 }
Exemplo n.º 2
0
        protected void AddBillboardText(string cat, int index, BillboardText text)
        {
            if (text.UIText != null)
            {
                ChartCommon.MakeMaskable(text.UIText, false);
            }
            Dictionary <int, BillboardText> addTo;

            if (mTexts.TryGetValue(cat, out addTo) == false)
            {
                addTo = new Dictionary <int, BillboardText>(ChartCommon.DefaultIntComparer);
                mTexts.Add(cat, addTo);
            }
            addTo.Add(index, text);
        }
Exemplo n.º 3
0
        protected void SelectActiveText(BillboardText b)
        {
            TriggerActiveTextsOut();
            GameObject tx = b.UIText;

            if (tx != null)
            {
                ChartItemEvents e = tx.GetComponent <ChartItemEvents>();
                if (e != null)
                {
                    e.OnMouseHover.Invoke(e.gameObject);
                    AddActiveText(b);
                }
            }
        }
Exemplo n.º 4
0
        protected override void OnItemHoverted(object userData)
        {
            base.OnItemHoverted(userData);
            List <BillboardText> catgoryTexts;
            RadarEventArgs       args = userData as RadarEventArgs;

            if (args == null)
            {
                return;
            }
            foreach (BillboardText t in mActiveTexts)
            {
                if (t.UIText == null)
                {
                    continue;
                }
                foreach (ChartItemEffect effect in t.UIText.GetComponents <ChartItemEffect>())
                {
                    effect.TriggerOut(false);
                }
            }

            mActiveTexts.Clear();


            if (mTexts.TryGetValue(args.Category, out catgoryTexts))
            {
                if (args.Index < catgoryTexts.Count)
                {
                    BillboardText b = catgoryTexts[args.Index];
                    mActiveTexts.Add(b);
                    GameObject t = b.UIText;
                    if (t != null)
                    {
                        foreach (ChartItemEffect effect in t.GetComponents <ChartItemEffect>())
                        {
                            effect.TriggerIn(false);
                        }
                    }
                }
            }
            mOccupiedCateogies.Add(args.Category);
            if (PointHovered != null)
            {
                PointHovered.Invoke(args);
            }
        }
        public virtual BillboardText AddText(AnyChart chart, MonoBehaviour prefab, Transform parentTransform, int fontSize, float fontSharpness, string text, float x, float y, float z, float angle, object userData)
        {
            BillboardText recycled = null;

            if (RecycleText == true)
            {
                if (mRecycled.TryGetValue(text, out recycled))
                {
                    recycled.SetVisible(true);
                    recycled.Recycled = false;
                    mRecycled.Remove(text);
                }
                else
                {
                    if (mCached.Count > 0)
                    {
                        recycled = mCached[mCached.Count - 1];
                        recycled.SetVisible(true);
                        recycled.Recycled = false;
                        mCached.RemoveAt(mCached.Count - 1);
                    }
                    else
                    {
                        recycled = null;
                    }
                }
            }

            BillboardText billboardText = ChartCommon.CreateBillboardText(recycled, prefab, parentTransform, text, x, y, z, angle, null, ((IInternalUse)chart).HideHierarchy, fontSize, fontSharpness);

            if (billboardText == null)
            {
                return(null);
            }
            billboardText.Recycled = false;
            billboardText.UserData = userData;
            if (recycled == null)
            {
                mText.Add(billboardText);
            }
            mCurrentTexts.Add(billboardText);
            return(billboardText);
        }
        void DestoryBillboard(BillboardText t)
        {
            t.Recycled = false;
            Text          uiText = t.UIText;
            TextDirection d      = t.Direction;

            if (uiText != null && uiText.gameObject != null)
            {
                ChartCommon.SafeDestroy(uiText.gameObject);
            }
            if (d != null && d.gameObject != null)
            {
                ChartCommon.SafeDestroy(d.gameObject);
            }
            if (t != null)
            {
                ChartCommon.SafeDestroy(t.gameObject);
            }
        }
Exemplo n.º 7
0
 protected void AddActiveText(BillboardText b)
 {
     mActiveTexts.Add(b);
 }
Exemplo n.º 8
0
        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);
        }
Exemplo n.º 9
0
        /// <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);
        }
Exemplo n.º 10
0
        /// <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 && mGroupLabels.Alignment != GroupLabelAlignment.FirstBar))
            {
                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);
            }
            // double prevValue = 0.0;
            double zero = (-min / total);

            zero = Math.Max(0, Math.Min(1, zero)) * heightRatio;
            double prevInterp = 0.0;

            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;
                if (Stacked)
                {
                    interp = (amount - min) / total;
                }
                interp = Math.Max(0, Math.Min(1, interp));  // clamp to [0,1]
                AddBarToChart(finalDepth, amount, prevInterp, pos, interp - prevInterp, category, group, rowIndex, i, zero);
                if (Stacked)
                {
                    prevInterp = interp;
                }
            }
        }
        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);
        }
        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);
        }
        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);
        }
Exemplo n.º 14
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;
            }
        }
Exemplo n.º 15
0
        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);
                    }
                }
            }
        }
        internal static BillboardText CreateBillboardText(BillboardText item, Text prefab, Transform parentTransform, string text, float x, float y, float z, float angle, Transform relativeFrom, bool hideHirarechy, int fontSize, float sharpness)
        {
            if (item != null)
            {
                return(UpdateBillboardText(item, parentTransform, text, x, y, z, angle, relativeFrom, hideHirarechy));
            }
            if (prefab == null || prefab.gameObject == null)
            {
                GameObject g = Resources.Load("Chart And Graph/DefaultText") as GameObject;
                prefab = g.GetComponent <Text>();
            }

            GameObject UIText    = (GameObject)GameObject.Instantiate(prefab.gameObject);
            GameObject billboard = new GameObject();

            ChartCommon.HideObject(billboard, hideHirarechy);

            if (parentTransform != null)
            {
                billboard.transform.SetParent(parentTransform, false);
                UIText.transform.SetParent(parentTransform, false);
            }

            BillboardText billboardText = billboard.AddComponent <BillboardText>();

            billboard.AddComponent <ChartItem>();
            TextDirection direction = UIText.GetComponent <TextDirection>();
            Text          TextObj   = UIText.GetComponent <Text>();

            if (direction != null)
            {
                TextObj = direction.Text;
                if (relativeFrom != null)
                {
                    direction.SetRelativeTo(relativeFrom, billboard.transform);
                }
                else
                {
                    direction.SetDirection(angle);
                }
            }

            if (billboardText == null || TextObj == null)
            {
                SafeDestroy(UIText);
                SafeDestroy(billboard);
                return(null);
            }

            sharpness                    = Mathf.Clamp(sharpness, 1f, 3f);
            TextObj.fontSize             = (int)(fontSize * sharpness);
            TextObj.horizontalOverflow   = HorizontalWrapMode.Overflow;
            TextObj.verticalOverflow     = VerticalWrapMode.Overflow;
            TextObj.resizeTextForBestFit = false;
            billboardText.Scale          = 1f / sharpness;

            TextObj.text            = text;
            billboardText.UIText    = TextObj;
            billboardText.Direction = direction;
            if (direction != null)
            {
                billboardText.RectTransformOverride = direction.GetComponent <RectTransform>();
            }
            else
            {
                billboardText.RectTransformOverride = null;
            }
            billboard.transform.localPosition = new Vector3(x, y, z);
            return(billboardText);
        }
Exemplo n.º 17
0
    public void ApplyTextPosition()
    {
        //if (mUnderCanvas)
        //{
        Camera = EnsureCamera();

        if (mParent != null && mParent.VRSpaceText)
        {
            mCanvas.transform.rotation = Quaternion.LookRotation(new Vector3(transform.position.x, 0, transform.position.z) - new Vector3(Camera.transform.position.x, 0, Camera.transform.position.z), Vector3.up);
//            mCanvas.transform.rotation = Camera.transform.rotation;
            mCanvas.transform.localScale = new Vector3(mParent.VRSpaceScale, mParent.VRSpaceScale, mParent.VRSpaceScale);
        }

        float scale = 1f;

        if (mPrivateParent != null && mPrivateParent.KeepOrthoSize)
        {
            if (Camera != null && Camera.orthographic && Camera.orthographicSize > 0.1f)
            {
                scale = 5f / Camera.orthographicSize;
            }
        }

        if (Mathf.Abs(mPrevScale - scale) < 0.01f)
        {
            mInvalidated = false;
        }

        //if (mInvalidated == false)
        // {
        mText.RemoveAll(x =>
        {
            if (x == null)
            {
                return(true);
            }
            BillboardText billboard = x;
            if (mInvalidated == false || billboard.transform.hasChanged || mCanvas.transform.hasChanged)
            {
                billboard.Rect.transform.position     = billboard.transform.position;
                billboard.UIText.transform.localScale = new Vector3(billboard.Scale * scale, billboard.Scale * scale, 1f);
                billboard.transform.hasChanged        = false;
            }
            return(false);
        });

        mInvalidated = true;

        // }
        return;
        //}

/*        Canvas canvas = SafeCanvas;
 *      if (mParent != null)
 *      {
 *          Camera = mParent.TextCamera;
 *          PlaneDistance = mParent.TextIdleDistance;
 *          canvas.planeDistance = PlaneDistance;
 *      }
 *
 *      Camera cam = EnsureCamera();
 *      if (cam == null)
 *      {
 *          if (mWarn == false)
 *              Debug.LogWarning("Chart Warning: No main camera set , please set the Chart's camera using \"TextCamera\" in the inspector");
 *          mWarn = true;
 *          return;
 *      }
 *      mWarn = false;
 *      Vector3 planeCenter;
 *      Vector3 planeNormal;
 *      CalculatePlane(cam, mRect, out planeCenter, out planeNormal);
 *      //Debug.DrawLine(planeCenter, planeCenter+ planeNormal,Color.red);
 *      foreach (BillboardText text in mText)
 *      {
 *          //  RectTransformUtility.
 *          Vector3 point = text.transform.position;
 *          Vector3 pointOnPlane = ProjectPointOnPlane(planeNormal, planeCenter, text.transform.position);
 *          //Debug.DrawLine(point, pointOnPlane);
 *          Vector3 worldVec = (pointOnPlane - point);
 *          Vector3 vec = mRect.worldToLocalMatrix * worldVec;
 *          float dist = vec.magnitude;
 *          if (Vector3.Dot(worldVec, cam.transform.forward) > 0)
 *              dist = -dist;
 *
 *          Vector2 viewport = cam.WorldToViewportPoint(pointOnPlane);
 *        //  Debug.DrawLine(viewport, pointOnPlane);
 * //            Vector3 anchored = new Vector3(
 * //              (mRect.sizeDelta.x * viewport.x) - (mRect.sizeDelta.x * mRect.anchorMin.x),
 *  //            (mRect.sizeDelta.y * viewport.y) - (mRect.sizeDelta.y * mRect.anchorMin.y),
 *    //          dist);
 *          Vector2 screen = RectTransformUtility.WorldToScreenPoint(cam,pointOnPlane);
 *          Vector2 pos;
 *          RectTransformUtility.ScreenPointToLocalPointInRectangle(mRect, screen, cam, out pos);
 *          //            float scaleDist = mPlaneDistance + worldVec.magnitude;
 *          //          if (scaleDist <= 0)
 *          //            scaleDist = 0.1f;
 *          // float scale = scaleDist/ mPlaneDistance;
 *          //text.Rect.localScale = new Vector3(scale, scale, 1f);
 *          text.Rect.localPosition = new Vector3(pos.x, pos.y , dist);
 *      }*/
    }
Exemplo n.º 18
0
    public void AddText(BillboardText billboard)
    {
        if (billboard == null)
        {
            return;
        }
        if (billboard.UIText == null)
        {
            return;
        }

        mInvalidated = false;
        mText.Add(billboard);
        var rect = billboard.Rect;

        EnsureCanvas();

        if (rect == null)
        {
            var           meshObj = billboard.UIText;
            TextDirection dir     = meshObj.GetComponent <TextDirection>();
            if (dir != null)
            {
                dir.SetTextController(this);
            }

            billboard.parent = null;
            meshObj.transform.SetParent(transform, false);
            if (mParent != null)
            {
                meshObj.layer = mParent.gameObject.layer;
            }

            //  meshObj.transform.localRotation = Quaternion.identity;
            meshObj.transform.position = billboard.transform.position;
            //  meshObj.transform.localScale = new Vector3(1f, 1f, 1f);

            meshObj.transform.localScale = new Vector3(billboard.Scale * mInnerScale, billboard.Scale * mInnerScale, 1f);
        }
        else
        {
            TextDirection dir = rect.GetComponent <TextDirection>();
            if (dir != null)
            {
                dir.SetTextController(this);
            }

            GameObject    obj = ChartCommon.CreateCanvasChartItem();
            RectTransform t   = obj.GetComponent <RectTransform>();
            obj.AddComponent <Canvas>();
            var addUnder = mAddCanvasUnder;
            if (addUnder == null)
            {
                addUnder = gameObject;
            }

            obj.transform.SetParent(addUnder.transform, false);
            obj.transform.localPosition = Vector3.zero;
            //  obj.transform.localRotation = Quaternion.identity;
            obj.transform.localScale = new Vector3(1f, 1f, 1f);

            billboard.parent = t;
            billboard.Rect.SetParent(t, false);
            if (mParent != null)
            {
                obj.layer = mParent.gameObject.layer;
                billboard.Rect.gameObject.layer = mParent.gameObject.layer;
            }
            //  billboard.Rect.localRotation = Quaternion.identity;
            billboard.Rect.localPosition = Vector3.zero;
            billboard.Rect.localScale    = new Vector3(1f, 1f, 1f);

            //    rect.anchoredPosition3D = new Vector3();
            if (dir == null)
            {
                rect.anchorMin = Vector2.zero;
                rect.anchorMax = Vector2.zero;
            }

            billboard.parent.position = billboard.transform.position;

            billboard.UIText.transform.localScale = new Vector3(billboard.Scale * mInnerScale, billboard.Scale * mInnerScale, 1f);
        }



        //Vector3 scale = new Vector3(1f/transform.lossyScale.x, 1f/transform.lossyScale.y, 1f/transform.lossyScale.z);//SafeCanvas.transform.localScale;
        //Vector3 scale = SafeCanvas.transform.localScale;

        //if (mUnderCanvas)
        //  billboard.UIText.transform.localScale = scale;
        //else



        //        ContentSizeFitter fitter = billboard.UIText.gameObject.GetComponent<ContentSizeFitter>();
        //        if(fitter == null)
        //            fitter = billboard.UIText.gameObject.AddComponent<ContentSizeFitter>();
        //        fitter.verticalFit = ContentSizeFitter.FitMode.PreferredSize;
        //        fitter.horizontalFit = ContentSizeFitter.FitMode.PreferredSize;
    }
Exemplo n.º 19
0
    public void ShowDialog(string text, Vector3 worldPosition)
    {
        BillboardText bbText = Prefabs.Instantiate <BillboardText>();

        bbText.Initialize(text, worldPosition, worldSpaceCanvas, null, Color.white, true, -1);
    }
Exemplo n.º 20
0
    public void ShowBillboardText(string text, Vector3 worldPosition, Sprite icon = null, Color color = default(Color), bool isDialog = false, int fontSize = -1)
    {
        BillboardText bbText = Prefabs.Instantiate <BillboardText>();

        bbText.Initialize(text, worldPosition, worldSpaceCanvas, icon, color, isDialog, fontSize);
    }
        internal static BillboardText CreateBillboardText(BillboardText item, MonoBehaviour prefab, Transform parentTransform, string text, float x, float y, float z, float angle, Transform relativeFrom, bool hideHirarechy, int fontSize, float sharpness)
        {
            if (item != null)
            {
                return(UpdateBillboardText(item, parentTransform, text, x, y, z, angle, relativeFrom, hideHirarechy, prefab != null && prefab.transform.localScale.y < 0));
            }
            if (prefab == null || prefab.gameObject == null)
            {
                GameObject g = Resources.Load("Chart And Graph/DefaultText") as GameObject;
                prefab = g.GetComponent <Text>();
            }

            GameObject UIText    = (GameObject)GameObject.Instantiate(prefab.gameObject);
            GameObject billboard = new GameObject();

            ChartCommon.HideObject(billboard, hideHirarechy);
            if (parentTransform.GetComponent <RectTransform>())
            {
                billboard.AddComponent <RectTransform>();
            }

            if (parentTransform != null)
            {
                billboard.transform.SetParent(parentTransform, false);
                UIText.transform.SetParent(parentTransform, false);
            }

            BillboardText billboardText = billboard.AddComponent <BillboardText>();

            billboard.AddComponent <ChartItem>();
            TextDirection direction = UIText.GetComponent <TextDirection>();

            GameObject obj = null;

            if (direction != null)
            {
                obj = direction.Text.gameObject;
                if (relativeFrom != null)
                {
                    direction.SetRelativeTo(relativeFrom, billboard.transform);
                }
                //  else
                direction.SetDirection(angle);
            }

            if (obj == null)
            {
                obj = UIText;
            }
            sharpness = Mathf.Clamp(sharpness, 1f, 3f);
            bool setParams = SetTextParams(obj, text, fontSize, sharpness);

            if (billboardText == null || setParams == false)
            {
                SafeDestroy(UIText);
                SafeDestroy(billboard);
                return(null);
            }


            if (prefab != null && prefab.transform.localScale.y < 0)
            {
                billboardText.YMirror = true;
            }
            billboardText.Scale     = (1f / sharpness);
            billboardText.UIText    = obj;
            billboardText.Direction = direction;
            if (direction != null)
            {
                billboardText.RectTransformOverride = direction.GetComponent <RectTransform>();
            }
            else
            {
                billboardText.RectTransformOverride = null;
            }
            billboard.transform.localPosition = new Vector3(x, y, z);
            return(billboardText);
        }
        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);
                        }
                    }
                }
            }
        }
Exemplo n.º 23
0
        public override void GenerateRealtime()
        {
            if (SupressRealtimeGeneration)
            {
                return;
            }
            base.GenerateRealtime();

            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);

            Transform parentT = transform;

            if (mFixPosition != null)
            {
                parentT = mFixPosition.transform;
            }

            ClearBillboardCategories();

            foreach (GraphData.CategoryData data in ((IInternalGraphData)Data).Categories)
            {
                CategoryObject obj = null;

                if (mCategoryObjects.TryGetValue(data.Name, out obj) == false)
                {
                    continue;
                }

                mClipped.Clear();
                mTmpData.Clear();

                mTmpData.AddRange(data.getPoints());
                Rect uv;// = new Rect(0f, 0f, 1f, 1f);
                int  refrenceIndex = ClipPoints(mTmpData, mClipped, out uv);
                //mClipped.AddRange(mTmpData);
                TransformPoints(mClipped, mTransformed, viewRect, min, max);
                mTmpToRemove.Clear();
                int range = refrenceIndex + mClipped.Count;
                foreach (int key in obj.mCahced.Keys)
                {
                    if (key < refrenceIndex || key > range)
                    {
                        mTmpToRemove.Add(key);
                    }
                }

                for (int i = 0; i < mTmpToRemove.Count; i++)
                {
                    obj.mCahced.Remove(mTmpToRemove[i]);
                }

                obj.mCahced.Remove(mTmpData.Count - 1); // never store the last point cache , it might be intepolating by the realtime feature

                if (mTmpData.Count == 0)
                {
                    continue;
                }
                if (mItemLabels != null && mItemLabels.isActiveAndEnabled && obj.mItemLabels != null)
                {
                    Rect textRect = viewRect;
                    textRect.xMin -= 1f;
                    textRect.yMin -= 1f;
                    textRect.xMax += 1f;
                    textRect.yMax += 1f;

                    CanvasChartMesh m = obj.mItemLabels;
                    m.Clear();

                    for (int i = 0; i < mTransformed.Count; i++)
                    {
                        if (mTransformed[i].w == 0.0)
                        {
                            continue;
                        }
                        Vector3 labelPos = ((Vector3)mTransformed[i]) + new Vector3(mItemLabels.Location.Breadth, mItemLabels.Seperation, mItemLabels.Location.Depth);
                        if (mItemLabels.Alignment == ChartLabelAlignment.Base)
                        {
                            labelPos.y -= (float)mTransformed[i].y;
                        }
                        if (textRect.Contains((Vector2)(mTransformed[i])) == false)
                        {
                            continue;
                        }
                        string toSet      = null;
                        int    pointIndex = i + refrenceIndex;
                        if (obj.mCahced.TryGetValue(pointIndex, out toSet) == false)
                        {
                            DoubleVector3 pointValue = mTmpData[i + refrenceIndex];
                            string        xFormat    = StringFromAxisFormat(pointValue.x, mHorizontalAxis, mItemLabels.FractionDigits, true);
                            string        yFormat    = StringFromAxisFormat(pointValue.y, mVerticalAxis, mItemLabels.FractionDigits, false);
                            FormatItem(mRealtimeStringBuilder, xFormat, yFormat);
                            string formatted = mRealtimeStringBuilder.ToString();
                            mItemLabels.TextFormat.Format(mRealtimeStringBuilder, formatted, data.Name, "");
                            toSet = mRealtimeStringBuilder.ToString();
                            obj.mCahced[pointIndex] = toSet;
                        }
                        BillboardText billboard = m.AddText(this, mItemLabels.TextPrefab, parentT, mItemLabels.FontSize, mItemLabels.FontSharpness, toSet, labelPos.x, labelPos.y, labelPos.z, 0f, null);
                        AddBillboardText(data.Name, i + refrenceIndex, billboard);
                    }

                    m.DestoryRecycled();
                    if (m.TextObjects != null)
                    {
                        foreach (BillboardText text in m.TextObjects)
                        {
                            ((IInternalUse)this).InternalTextController.AddText(text);
                        }
                    }
                }

                if (obj.mDots != null)
                {
                    Rect  pickRect = viewRect;
                    float halfSize = (float)(data.PointSize * 0.5f);
                    pickRect.xMin -= halfSize;
                    pickRect.yMin -= halfSize;
                    pickRect.xMax += halfSize;
                    pickRect.yMax += halfSize;
                    obj.mDots.SetViewRect(pickRect, uv);
                    obj.mDots.ModifyLines(mTransformed);
                    obj.mDots.SetRefrenceIndex(refrenceIndex);
                }

                if (obj.mLines != null)
                {
                    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;
                    }
                    obj.mLines.Tiling = tiling;
                    obj.mLines.SetViewRect(viewRect, uv);
                    obj.mLines.ModifyLines(mTransformed);
                    obj.mLines.SetRefrenceIndex(refrenceIndex);
                }

                if (obj.mFill != null)
                {
                    obj.mFill.SetViewRect(viewRect, uv);
                    obj.mFill.ModifyLines(mTransformed);
                    obj.mFill.SetRefrenceIndex(refrenceIndex);
                }
            }
        }
        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);
            }
        }
 private void GetBillboardRefAndInvokePeriodicDisable()
 {
     refScript = GetComponent <BillboardText>();
     Invoke("periodicDisable", 1f + (RandomGen.Next(0, 199) * 0.01f));
 }
Exemplo n.º 26
0
        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;
            }
        }