示例#1
0
        public static void Generate2dMesh(IChartMesh mesh, float startAngle, float angleSpan, float radius, float innerRadius, int segments)
        {
            float segmentAngle = angleSpan / segments;
            float currentAngle = startAngle;
            float segmenUv     = 1f / segments;
            float currentUv    = 0f;
            float cos          = Mathf.Cos(currentAngle);
            float sin          = Mathf.Sin(currentAngle);

            UIVertex prevInnerVertex = ChartCommon.CreateVertex(new Vector3(cos * innerRadius, sin * innerRadius, 0f), new Vector2(currentUv, 0f));
            UIVertex prevOuterVertex = ChartCommon.CreateVertex(new Vector3(cos * radius, sin * radius, 0f), new Vector2(currentUv, 1f));

            for (int i = 1; i < segments + 1; i++)
            {
                currentUv    += segmenUv;
                currentAngle += segmentAngle;
                cos           = Mathf.Cos(currentAngle);
                sin           = Mathf.Sin(currentAngle);

                UIVertex innerVertex = ChartCommon.CreateVertex(new Vector3(cos * innerRadius, sin * innerRadius, 0f), new Vector2(currentUv, 0f));
                UIVertex outerVertex = ChartCommon.CreateVertex(new Vector3(cos * radius, sin * radius, 0f), new Vector2(currentUv, 1f));
                mesh.AddQuad(prevInnerVertex, innerVertex, prevOuterVertex, outerVertex);
                prevInnerVertex = innerVertex;
                prevOuterVertex = outerVertex;
            }
        }
示例#2
0
 /// <summary>
 /// sets the uv of a chart mesh based on the current length and offset
 /// </summary>
 /// <param name="mesh"></param>
 /// <param name="length"></param>
 /// <param name="offset"></param>
 private void SetMeshUv(IChartMesh mesh, float length, float offset)
 {
     if (length < 0)
     {
         offset -= length;
     }
     mesh.Length = length;
     mesh.Offset = offset;
 }
#pragma warning restore 0672

        void FillChartMesh(IChartMesh mesh)
        {
            UIVertex v1 = vertices[0];
            UIVertex v2 = vertices[1];
            UIVertex v3 = vertices[2];
            UIVertex v4 = vertices[3];

            v1.position += (Vector3)(normals[0] * mInset);
            v2.position += (Vector3)(normals[1] * mInset);
            v3.position += (Vector3)(normals[2] * mInset);
            v4.position += (Vector3)(normals[3] * mInset);

            Vector2 inter;

            if (ChartCommon.SegmentIntersection(v1.position, v3.position, v2.position, v4.position, out inter))
            {
                v3.position = inter;
                v4.position = inter;
            }

            mesh.AddQuad(v1, v2, v3, v4);
        }
示例#4
0
        /// <summary>
        /// used internally , adds the axis main divisions to the chart mesh
        /// </summary>
        /// <param name="parent"></param>
        /// <param name="parentTransform"></param>
        /// <param name="mesh"></param>
        /// <param name="orientation"></param>

        internal void AddMainDivisionToChartMesh(double scrollOffset, AnyChart parent, Transform parentTransform, IChartMesh mesh, ChartOrientation orientation)
        {
            double maxValue = ((IInternalUse)parent).InternalMaxValue(this);
            double minValue = ((IInternalUse)parent).InternalMinValue(this);
            double range    = maxValue - minValue;
            double?gap      = GetMainGap(parent, range);

            if (gap.HasValue == false)
            {
                return;
            }
            mesh.Tile = ChartCommon.GetTiling(MainDivisions.MaterialTiling);
            if ((MainDivisions.Alignment & ChartDivisionAligment.Opposite) == ChartDivisionAligment.Opposite)
            {
                DrawDivisions(scrollOffset, parent, parentTransform, MainDivisions, mesh, 0, orientation, gap.Value, false, -1);
            }
            if ((MainDivisions.Alignment & ChartDivisionAligment.Standard) == ChartDivisionAligment.Standard)
            {
                DrawDivisions(scrollOffset, parent, parentTransform, MainDivisions, mesh, 0, orientation, gap.Value, true, -1);
            }
        }
示例#5
0
        /// <summary>
        /// used internally , adds the axis sub divisions to the chart mesh
        /// </summary>
        /// <param name="parent"></param>
        /// <param name="parentTransform"></param>
        /// <param name="mesh"></param>
        /// <param name="orientation"></param>
        internal void AddSubdivisionToChartMesh(double scrollOffset, AnyChart parent, Transform parentTransform, IChartMesh mesh, ChartOrientation orientation)
        {
            int total = SubDivisions.Total;

            if (total <= 1) // no need for more
            {
                return;
            }
            double maxValue = ((IInternalUse)parent).InternalMaxValue(this);
            double minValue = ((IInternalUse)parent).InternalMinValue(this);
            double range    = maxValue - minValue;
            double?gap      = GetMainGap(parent, range);

            if (gap.HasValue == false)
            {
                return;
            }
            double subGap = gap.Value / (total);

            mesh.Tile = ChartCommon.GetTiling(SubDivisions.MaterialTiling);
            if ((SubDivisions.Alignment & ChartDivisionAligment.Opposite) == ChartDivisionAligment.Opposite)
            {
                DrawDivisions(scrollOffset, parent, parentTransform, SubDivisions, mesh, 0, orientation, subGap, false, gap.Value);
            }
            if ((SubDivisions.Alignment & ChartDivisionAligment.Standard) == ChartDivisionAligment.Standard)
            {
                DrawDivisions(scrollOffset, parent, parentTransform, SubDivisions, mesh, 0, orientation, subGap, true, gap.Value);
            }
        }
示例#6
0
        private void DrawDivisions(double scrollOffset, AnyChart parent, Transform parentTransform, ChartDivisionInfo info, IChartMesh mesh, int group, ChartOrientation orientation, double gap, bool oppositeSide, double mainGap)
        {
            //scrollOffset = -scrollOffset;
            double        parentSize = (orientation == ChartOrientation.Vertical) ? ((IInternalUse)parent).InternalTotalHeight : ((IInternalUse)parent).InternalTotalWidth;
            DoubleVector3 startPosition, lengthDirection, advanceDirection;

            GetDirectionVectors(parent, info, orientation, 0f, oppositeSide, out startPosition, out lengthDirection, out advanceDirection);
            double markDepth  = ChartCommon.GetAutoDepth(parent, orientation, info);
            double length     = ChartCommon.GetAutoLength(parent, orientation, info);
            double backLength = (orientation == ChartOrientation.Vertical) ? ((IInternalUse)parent).InternalTotalWidth : ((IInternalUse)parent).InternalTotalHeight;

            if (info.MarkBackLength.Automatic == false)
            {
                backLength = info.MarkBackLength.Value;
            }

            double totaluv = Math.Abs(length);

            if (backLength != 0 && markDepth > 0)
            {
                totaluv += Math.Abs(backLength) + Math.Abs(markDepth);
            }

            DoubleVector3 halfThickness = advanceDirection * (info.MarkThickness * 0.5f);
            // if (scrollOffset != 0f)
            //     last--;

            bool   hasValues = ((IInternalUse)parent).InternalHasValues(this);
            double maxValue  = ((IInternalUse)parent).InternalMaxValue(this);
            double minValue  = ((IInternalUse)parent).InternalMinValue(this);
            double range     = maxValue - minValue;

            float AutoAxisDepth = Depth.Value;

//            float scrollFactor = (scrollOffset / (float)(maxValue - minValue));
            //scrollOffset = scrollFactor * parentSize;

            if (Depth.Automatic)
            {
                AutoAxisDepth = (float)((((IInternalUse)parent).InternalTotalDepth) - markDepth);
            }

            double startValue = (scrollOffset + minValue);
            double endValue   = (scrollOffset + maxValue) + double.Epsilon;
            double direction  = 1.0;
            Func <double, double> ValueToPosition = x => ((x - startValue) / range) * parentSize;

            if (startValue > endValue)
            {
                direction = -1.0;
                //ValueToPosition = x => (1.0- ((x - startValue) / range)) * parentSize;
            }
            gap = Math.Abs(gap);
            double fraction     = gap - (scrollOffset - Math.Floor((scrollOffset / gap) - double.Epsilon) * gap);
            double mainfraction = -1f;
            double currentMain  = 0f;

            if (mainGap > 0f)
            {
                mainfraction = mainGap - (scrollOffset - Math.Floor((scrollOffset / mainGap) - double.Epsilon) * mainGap);
                currentMain  = (scrollOffset + minValue + mainfraction);
            }

            int i = 0;

            mTmpToRemove.Clear();
            double startRange = startValue + fraction;

            foreach (double key in mFormats.Keys)
            {
                if (key * direction > endValue * direction || key * direction < startRange * direction)
                {
                    mTmpToRemove.Add(key);
                }
            }
            for (int k = 0; k < mTmpToRemove.Count; k++)
            {
                mFormats.Remove(mTmpToRemove[k]);
            }
            for (double current = startRange; direction *current <= direction *endValue; current += gap * direction)
            {
                ++i;
                if (i > 3000)
                {
                    break;
                }

                if (mainGap > 0.0)
                {
                    if (Math.Abs(current - currentMain) < 0.00001)
                    {
                        currentMain += mainGap;
                        continue;
                    }
                    if (current > currentMain)
                    {
                        currentMain += mainGap;
                    }
                }

                double offset = ValueToPosition(current);
                if (offset < 0 || offset > parentSize)
                {
                    continue;
                }
                DoubleVector3 start = startPosition + advanceDirection * offset;
                DoubleVector3 size  = halfThickness + length * lengthDirection;
                start -= halfThickness;
                //size += halfThickness;
                float uvoffset = 0f;

                Rect r = ChartCommon.FixRect(new Rect((float)start.x, (float)start.y, (float)size.x, (float)size.y));

                SetMeshUv(mesh, (float)(-length / totaluv), uvoffset);
                uvoffset += Math.Abs(mesh.Length);

                mesh.AddXYRect(r, group, AutoAxisDepth);
                if (hasValues)
                {
                    double val    = Math.Round(current * 1000.0) / 1000.0;
                    string toSet  = "";
                    double keyVal = val;// (int)Math.Round(val);
                    var    dic    = (orientation == ChartOrientation.Horizontal) ? parent.HorizontalValueToStringMap : parent.VerticalValueToStringMap;
                    if (!(Math.Abs(val - keyVal) < 0.001 && dic.TryGetValue(keyVal, out toSet)))
                    {
                        if (mFormats.TryGetValue(val, out toSet) == false)
                        {
                            if (format == AxisFormat.Number)
                            {
                                toSet = ChartAdancedSettings.Instance.FormatFractionDigits(info.FractionDigits, val);
                            }
                            else
                            {
                                DateTime date = ChartDateUtility.ValueToDate(val);
                                if (format == AxisFormat.DateTime)
                                {
                                    toSet = ChartDateUtility.DateToDateTimeString(date, parent.CustomDateTimeFormat);
                                }
                                else
                                {
                                    if (format == AxisFormat.Date)
                                    {
                                        toSet = ChartDateUtility.DateToDateString(date);
                                    }
                                    else
                                    {
                                        toSet = ChartDateUtility.DateToTimeString(date);
                                    }
                                }
                            }
                            toSet         = info.TextPrefix + toSet + info.TextSuffix;
                            mFormats[val] = toSet;
                        }
                    }
                    else
                    {
                        toSet = info.TextPrefix + toSet + info.TextSuffix;
                    }


                    DoubleVector3 textPos = new DoubleVector3(start.x, start.y);
                    textPos += lengthDirection * info.TextSeperation;
                    TextData userData = new TextData();
                    userData.interp         = (float)(offset / parentSize);
                    userData.info           = info;
                    userData.fractionDigits = info.FractionDigits;
                    mesh.AddText(parent, info.TextPrefab, parentTransform, info.FontSize, info.FontSharpness, toSet, (float)textPos.x, (float)textPos.y, AutoAxisDepth + info.TextDepth, 0f, userData);
                }

                if (markDepth > 0)
                {
                    if (orientation == ChartOrientation.Horizontal)
                    {
                        SetMeshUv(mesh, (float)(markDepth / totaluv), uvoffset);
                        r = ChartCommon.FixRect(new Rect((float)start.x, AutoAxisDepth, (float)size.x, (float)markDepth));
                        mesh.AddXZRect(r, group, (float)start.y);
                    }
                    else
                    {
                        SetMeshUv(mesh, (float)(-markDepth / totaluv), uvoffset);
                        r = ChartCommon.FixRect(new Rect((float)start.y, AutoAxisDepth, (float)size.y, (float)markDepth));
                        mesh.AddYZRect(r, group, (float)start.x);
                    }

                    uvoffset += Math.Abs(mesh.Length);

                    if (backLength != 0)
                    {
                        SetMeshUv(mesh, (float)(backLength / totaluv), uvoffset);
                        uvoffset += Math.Abs(mesh.Length);
                        DoubleVector3 backSize = halfThickness + backLength * lengthDirection;
                        Rect          backR    = ChartCommon.FixRect(new Rect((float)start.x, (float)start.y, (float)backSize.x, (float)backSize.y));
                        mesh.AddXYRect(backR, group, (float)(AutoAxisDepth + markDepth));
                    }
                }
            }
            //   Debug.Log("start");
            //   Debug.Log(mFormats.Count);
            //   Debug.Log(cached);
        }
#pragma warning restore 0672

        void FillChartMesh(IChartMesh mesh)
        {
            PieMesh.Generate2dMesh(mesh, mStartAngle, mAngleSpan, mRadius, mInnerRadius, mSegements);
        }