Beispiel #1
0
 public void InitTicks(double[] ticks)
 {
     if (ticks == null || ticks.Length == 0)
     {
         return;
     }
     shouldRound = true;
     try
     {
         double start  = ticks[0];
         double finish = ticks[ticks.Length - 1];
         if (start == finish)
         {
             shouldRound = false;
             return;
         }
         double delta = finish - start;
         rounding = (int)Math.Round(Math.Log10(delta));
         double newStart  = RoundHelper.Round(start, rounding);
         double newFinish = RoundHelper.Round(finish, rounding);
         if (newStart == newFinish)
         {
             rounding--;
         }
     }
     catch (Exception ex)
     {
         System.Diagnostics.Debug.WriteLine(ex.Message);
     }
 }
Beispiel #2
0
        public void InitTicks(TickInfo[] ticks)
        {
            if (ticks == null || ticks.Length == 0 || (!(ticks.First().Value is double)))
            {
                return;
            }

            shouldRound = true;
            try
            {
                double start  = (double)ticks[0].Value;
                double finish = (double)ticks[ticks.Length - 1].Value;

                if (start == finish)
                {
                    shouldRound = false;
                    DebugTraceLog.WriteLine("shouldRound = false;");
                    return;
                }

                double delta = finish - start;

                rounding = (int)Math.Round(Math.Log10(delta));

                double newStart  = RoundHelper.Round(start, rounding);
                double newFinish = RoundHelper.Round(finish, rounding);
                if (newStart == newFinish)
                {
                    rounding--;
                }
            }
            catch
            {
            }
        }
Beispiel #3
0
        private string GetStringCore(object value)
        {
            string res;

            if (value is double && shouldRound)
            {
                int round = Math.Min(15, Math.Max(-15, rounding - 2));
                res = RoundHelper.Round((double)value, round).ToString();
            }
            else
            {
                res = value.ToString();
            }
            return(res);
        }
Beispiel #4
0
        protected virtual double CalculateTickStep(double ss, double ee, int count)
        {
            double delta = ee - ss;

            int log = (int)Math.Round(Math.Log10(delta));

            double newStart = RoundHelper.Round(ss, log);

            double newStop = RoundHelper.Round(ee, log);

            if (newStart == newStop)
            {
                log--;
                newStart = RoundHelper.Round(ss, log);
                newStop  = RoundHelper.Round(newStop, log);
            }

            if (newStop < newStart)
            {
                var t = newStart;
                newStart = newStop;
                newStop  = t;
            }

            // calculating step between ticks
            double unroundedStep = (newStop - newStart) / count;
            int    stepLog       = log;
            // trying to round step
            double step = RoundHelper.Round(unroundedStep, stepLog);

            if (step == 0)
            {
                stepLog--;
                step = RoundHelper.Round(unroundedStep, stepLog);
                if (step == 0)
                {
                    // step will not be rounded if attempts to be rounded to zero.
                    step = unroundedStep;
                }
            }

            return(step);
        }
Beispiel #5
0
        public double[] CreateTicks(Range <double> value, bool only_inside = true)
        {
            double start  = value.Min;
            double finish = value.Max;
            double d      = finish - start;

            if (d == 0)
            {
                return new double[] { start, finish }
            }
            ;

            double        temp  = CalculateInterval();
            double        min   = Math.Floor(start / temp);
            double        max   = Math.Floor(finish / temp);
            int           count = (int)(max - min + 1);
            List <double> res   = new List <double>();
            double        x0    = min * temp;

            for (int i = 0; i < count + 1; i++)
            {
                double v = RoundHelper.Round(x0 + i * temp, beta);
                if (only_inside)
                {
                    if (v >= start && v <= finish)
                    {
                        res.Add(v);
                    }
                }
                else
                {
                    res.Add(v);
                }
            }
            return(res.ToArray());
        }
    }
Beispiel #6
0
        public override IEnumerable <TickInfo> Ticks()
        {
            if (start == stop)
            {
                yield break;
            }
#if true
            double ss = start < stop ? start : stop;

            double ee = start > stop ? start : stop;

            double delta = ee - ss;

            int log = (int)Math.Round(Math.Log10(delta));

            double newStart = RoundHelper.Round(ss, log);

            double newStop = RoundHelper.Round(ee, log);

            if (newStart == newStop)
            {
                log--;
                newStart = RoundHelper.Round(ss, log);
                newStop  = RoundHelper.Round(newStop, log);
            }

            // calculating step between ticks
            double unroundedStep = (newStop - newStart) / tickCount;
            int    stepLog       = log;
            // trying to round step
            double step = RoundHelper.Round(unroundedStep, stepLog);
            if (step == 0)
            {
                stepLog--;
                step = RoundHelper.Round(unroundedStep, stepLog);
                if (step == 0)
                {
                    // step will not be rounded if attempts to be rounded to zero.
                    step = unroundedStep;
                }
            }

            if (step != 0.0)
            {
                ticks = CreateTicks(ss, ee, step);
            }
            else
            {
                ticks = new double[] { };
            }

            int index = 0;
            if (start < stop)
            {
                while (index < ticks.Length)
                {
                    if (ticks[index] >= start && ticks[index] <= stop)
                    {
                        var value = ticks[index];
                        var pos   = this.ToPixels(value);

                        yield return(new TickInfo(value, pos, true));
                    }
                    index++;
                }
            }
            else
            {
                while (index < ticks.Length)
                {
                    if (ticks[index] <= start && ticks[index] >= stop)
                    {
                        var value = ticks[index];
                        var pos   = this.ToPixels(value);

                        yield return(new TickInfo(value, pos, true));
                    }
                    index++;
                }
            }
#else
            double longTickStep = this.LongTickStep;

            double longTickAnchor = NearestLongTick();

            double longTickPos = longTickAnchor;

            int longTickProcessed = 0;

            int    minorTickCount = this.MinorTickCount;
            double minorTikcStep  = longTickStep / (minorTickCount + 1);

            double minorTickPos;

            if (start < stop)
            {
                while (longTickPos <= stop)
                {
                    if (longTickPos >= start)
                    {
                        var val = longTickPos;
                        var pos = this.ToPixels(longTickPos, isRevert);

                        yield return(new TickInfo(val, pos, true));
                    }

                    if (this.ShowMinorTick)
                    {
                        for (int i = 1; i <= minorTickCount; i++)
                        {
                            minorTickPos = longTickPos + minorTikcStep * i;
                            if (minorTickPos >= start && minorTickPos <= stop)
                            {
                                yield return(new TickInfo(minorTickPos, this.ToPixels(minorTickPos, isRevert), false));
                            }
                        }
                    }

                    longTickPos = longTickAnchor + (++longTickProcessed) * longTickStep;
                }
            }
            else // start > stop
            {
                while (longTickPos >= stop)
                {
                    if (longTickPos <= start)
                    {
                        yield return(new TickInfo(longTickPos, this.ToPixels(longTickPos, isRevert), true));
                    }

                    if (this.ShowMinorTick)
                    {
                        for (int i = 1; i <= minorTickCount; i++)
                        {
                            minorTickPos = longTickPos - minorTikcStep * i;
                            if (minorTickPos <= start && minorTickPos >= stop)
                            {
                                yield return(new TickInfo(minorTickPos, this.ToPixels(minorTickPos, isRevert), false));
                            }
                        }
                    }

                    longTickPos = longTickAnchor - (++longTickProcessed) * longTickStep;
                }
            }
#endif
        }