コード例 #1
0
        public void Update()
        {
            if (!BeginValue.Equals(EndValue))
            {
                double vunit      = GetUnitValue();
                uint   defaultDec = DefaultDecLength;

                var valStrs = new List <string>();

start:
                valStrs.Clear();

                for (int i = 0; i < _scaleTextBlocks.Count; i++)
                {
                    double dv = Utile.MathNoRound(BeginValue + i * vunit, defaultDec);
                    if (double.IsNaN(dv))
                    {
                        return;
                    }

                    string v;
                    if (string.IsNullOrWhiteSpace(ValueFormat))
                    {
                        v = string.Format("{0:N" + defaultDec + "}", dv);
                        if (ScaleConvertValue != null)
                        {
                            var args = new ScaleValueConverterArgs(i, defaultDec, v);
                            ScaleConvertValue(args);
                            v = args.NewValue != null?args.NewValue.ToString() : string.Empty;
                        }
                    }
                    else
                    {
                        v = string.Format(ValueFormat, dv);
                    }

                    if (AutoExtendDec && defaultDec < MaxExtendDec)
                    {
                        foreach (var obj in valStrs)
                        {
                            if (obj.StartsWith(v))
                            {
                                defaultDec += 1;
                                goto start;
                            }
                        }
                    }

                    valStrs.Add(_scaleTextBlocks[i].Text);
                    _scaleTextBlocks[i].Text = v;
                }
            }

            for (int i = 0; i < _scaleTextBlocks.Count; i++)
            {
                switch (Direction)
                {
                case ScaleLabelDirection.Left:
                case ScaleLabelDirection.Right:

                    double h = _scaleTextBlocks[i].ActualHeight / 2;
                    if (i == 0)
                    {
                        _scaleTextBlocks[i].Margin = new Thickness(0, -h, 0, 0);
                    }
                    else if (i == ScaleLabelCount - 1)
                    {
                        _scaleTextBlocks[i].Margin = new Thickness(0, 0, 0, -h);
                    }

                    break;

                case ScaleLabelDirection.Bottom:
                case ScaleLabelDirection.Top:
                    double w = _scaleTextBlocks[i].ActualWidth / 2;
                    if (i == 0)
                    {
                        _scaleTextBlocks[i].Margin = new Thickness(-w, 0, 0, 0);
                    }
                    else if (i == ScaleLabelCount - 1)
                    {
                        _scaleTextBlocks[i].Margin = new Thickness(0, 0, -w, 0);
                    }

                    break;
                }
            }
        }
コード例 #2
0
        /// <summary>
        /// 刻度更新
        /// </summary>
        private void UpdateScales()
        {
            if (_rangePanel == null)
            {
                return;
            }
            uint   defaultDec = DefaultDecLength;
            double vunit      = GetUnitValue();
            double unit       = GetUnitSize();
            var    valStrs    = new List <string>();

            if (BeginValue.Equals(EndValue))
            {
                for (int i = 0; i < ScaleLabelCount; i++)
                {
                    valStrs.Add("--:--:--");
                }
                UpdateScales2(Direction, valStrs, unit);
                return;
            }
            if (vunit.Equals(0) || unit.Equals(0))
            {
                return;
            }
start:
            valStrs.Clear();

            for (int i = 0; i < ScaleLabelCount; i++)
            {
                double dv = Utile.MathNoRound(BeginValue + i * vunit, defaultDec);
                if (double.IsNaN(dv))
                {
                    return;
                }
                string v;
                if (string.IsNullOrWhiteSpace(ValueFormat))
                {
                    v = string.Format("{0:N" + defaultDec + "}", dv);
                    if (ScaleConvertValue != null)
                    {
                        var args = new ScaleValueConverterArgs(i, defaultDec, v);
                        ScaleConvertValue(args);
                        v = args.NewValue != null?args.NewValue.ToString() : string.Empty;
                    }
                }
                else
                {
                    v = string.Format(ValueFormat, dv);
                }

                if (AutoExtendDec && defaultDec < MaxExtendDec)
                {
                    foreach (var obj in valStrs)
                    {
                        if (obj.StartsWith(v))
                        {
                            defaultDec += 1;
                            goto start;
                        }
                    }
                }
                valStrs.Add(v);
            }

            UpdateScales2(Direction, valStrs, unit);
        }