コード例 #1
0
 /// <summary>
 /// Initializes a new instance of the <see cref="RangeChangedEventArgs"/> class.
 /// </summary>
 /// <param name="minimumX">The minimum x value.</param>
 /// <param name="maximumX">The maximum x value.</param>
 /// <param name="minimumY">The minimum y value.</param>
 /// <param name="maximumY">The maximum y value.</param>
 public RangeChangedEventArgs(GraphDataPoint minimumX, GraphDataPoint maximumX, GraphDataPoint minimumY, GraphDataPoint maximumY) : this()
 {
     MinimumX = minimumX;
     MaximumX = maximumX;
     MinimumY = minimumY;
     MaximumY = maximumY;
 }
コード例 #2
0
    void Update()
    {
        if (AnimationType != GraphAnimationType.None)
        {
            if (AnimationDelay >= AnimationTime)
            {
                if (AnimationType == GraphAnimationType.Update)
                {
                    YMax       = TargetYMax;
                    DataPoints = TargetDataPoints;
                }

                ShowBarGraph(DataPoints, YMax, YStep, BarSpacing, AxisColor, AxisStepColor, Font);
                AnimationType = GraphAnimationType.None;
                if (AnimationCallback != null)
                {
                    AnimationCallback();
                }
            }
            else
            {
                float r = AnimationDelay / AnimationTime;

                switch (AnimationType)
                {
                case GraphAnimationType.Init:
                    float curValue  = MaxValue * r;
                    float curHeight = MaxBarHeight * r;

                    for (int i = 0; i < DataPoints.Count; i++)
                    {
                        float barX = (i + 1) * XStep;
                        float barValue, barHeight;
                        if (DataPoints[i].Value < curValue)
                        {
                            barValue  = DataPoints[i].Value;
                            barHeight = (barValue / YMax) * (GraphHeight - YMarginTop);
                        }
                        else
                        {
                            barValue  = curValue;
                            barHeight = curHeight;
                        }
                        Vector2       pos  = new Vector2(barX, barHeight / 2);
                        Vector2       size = new Vector2(BarWidth, barHeight);
                        RectTransform rect = Bars[i].GetComponent <RectTransform>();
                        rect.anchoredPosition = pos;
                        rect.sizeDelta        = size;

                        float barLabelY = barHeight + FontSize;
                        BarLabels[i].GetComponent <RectTransform>().anchoredPosition = new Vector2(barX, barLabelY);
                        BarLabels[i].text = barValue.ToString("0.0") + "%";
                    }
                    break;

                case GraphAnimationType.Update:
                    List <GraphDataPoint> tmpDataPoints = new List <GraphDataPoint>();
                    float tmpYMax = 0;
                    for (int i = 0; i < TargetDataPoints.Count; i++)
                    {
                        float          value        = SourceDataPoints[i].Value + (TargetDataPoints[i].Value - SourceDataPoints[i].Value) * r;
                        GraphDataPoint tmpDataPoint = new GraphDataPoint(TargetDataPoints[i].Label, value, TargetDataPoints[i].Color, TargetDataPoints[i].Icons, TargetDataPoints[i].IconTooltipTitles, TargetDataPoints[i].IconTooltipTexts);
                        tmpDataPoints.Add(tmpDataPoint);

                        tmpYMax = SourceYMax + (TargetYMax - SourceYMax) * r;
                    }
                    ShowBarGraph(tmpDataPoints, tmpYMax, YStep, BarSpacing, AxisColor, AxisStepColor, Font, stopAnimation: false);
                    break;
                }

                AnimationDelay += Time.deltaTime * AnimationSpeedModifier;
            }
        }
    }
コード例 #3
0
        /// <summary>
        /// Arranges the series of data points and returns a series of drawing points.
        /// </summary>
        /// <param name="surface">The target graph surface.</param>
        /// <param name="series">The instance of the current rendered data series.</param>
        /// <param name="range">Instance of graph range.</param>
        /// <param name="xx">Collection of x coordinates.</param>
        /// <param name="yy">Collection of y coordinates.</param>
        /// <param name="minimumX">The minimum x coordinates value.</param>
        /// <param name="maximumX">The maximum x coordinates value.</param>
        /// <param name="minimumY">The minimum y coordinates value.</param>
        /// <param name="maximumY">The maximum y coordinates value.</param>
        /// <returns></returns>
        public override IEnumerable <PointF> Render(IGraphSurface <TDataSeries> surface, TDataSeries series, IGraphRange range, List <GraphDataPoint> xx, List <GraphDataPoint> yy, GraphDataPoint minimumX, GraphDataPoint maximumX, GraphDataPoint minimumY, GraphDataPoint maximumY)
        {
            var dxList = xx.Select(x => x.ComputeRelativePosition(minimumX, maximumX)).ToList();
            var dyList = yy.Select(x => x.ComputeRelativePosition(minimumY, maximumY)).ToList();

            if (maximumX - minimumX > range.MaximumX)
            {
                var offset = ((maximumX - minimumX) - range.MaximumX) + minimumX;

                for (int i = 0; i < xx.Count; i++)
                {
                    if (xx[i] < offset)
                    {
                        xx.RemoveAt(i);
                        yy.RemoveAt(i);
                        i--;
                    }
                    else
                    {
                        break;
                    }
                }
            }

            List <PointF> points = new List <PointF>();

            for (int i = 0; i < dxList.Count; i++)
            {
                float image_x = ConvertXValueToRendererValue(surface, dxList[i]);
                float image_y = (float)Math.Min(ConvertYValueToRendererValue(surface, dyList[i]), surface.GetSize().Height - 2);

                PointF point = new PointF(image_x, image_y);
                points.Add(point);
            }

            return(points);
        }