【问题标题】:Line disappearing on zooming (using "Dynamic data display")缩放时线条消失(使用“动态数据显示”)
【发布时间】:2012-09-27 09:52:02
【问题描述】:

在我的 WPF 项目中,我使用Dynamic data display 绘制图表。 我在某处读到,如果您放大非常深,线条消失(未绘制)是一个常见错误。

有没有人解决这个错误?

【问题讨论】:

    标签: c# wpf dynamic-data-display


    【解决方案1】:

    虽然不是针对您的错误的确切解决方案,但您可以通过使用缩放限制将用户放大得太深来阻止用户。这样,用户将永远不会通过放大那么深来体验这个错误。您可以找到此错误发生的缩放比例,并限制该 DataRect 的缩放比例。我编写了自己的类来限制 D3 中的缩放,并将为您提供。

    这里:

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Windows;
    
    namespace Microsoft.Research.DynamicDataDisplay.ViewportRestrictions {
    /// <summary>
    /// Represents a restriction, which limits the maximal size of <see cref="Viewport"/>'s Visible property.
    /// </summary>
    public class ZoomInRestriction : ViewportRestriction {
        /// <summary>
        /// Initializes a new instance of the <see cref="MaximalSizeRestriction"/> class.
        /// </summary>
        public ZoomInRestriction() { }
    
        /// <summary>
        /// Initializes a new instance of the <see cref="MaximalSizeRestriction"/> class with the given maximal size of Viewport's Visible.
        /// </summary>
        /// <param name="maxSize">Maximal size of Viewport's Visible.</param>
        public ZoomInRestriction(double height, double width) {
            Height = height;
            Width = width;
        }
    
        private double height;
        private double width;
    
        public double Height {
            get { return height; }
            set {
                if (height != value) {
                    height = value;
                    RaiseChanged();
                }
            }
        }
    
        public double Width {
            get { return width; }
            set {
                if (width != value) {
                    width = value;
                    RaiseChanged();
                }
            }
        }
    
        /// <summary>
        /// Applies the specified old data rect.
        /// </summary>
        /// <param name="oldDataRect">The old data rect.</param>
        /// <param name="newDataRect">The new data rect.</param>
        /// <param name="viewport">The viewport.</param>
        /// <returns></returns>
        public override DataRect Apply(DataRect oldDataRect, DataRect newDataRect, Viewport2D viewport) {
            if ((newDataRect.Width < width || newDataRect.Height < height)) {
                return oldDataRect;
            }
            return newDataRect;
        }
    }
    }
    

    现在您可以在代码中使用它来实现这样的限制:

    plotter.Viewport.Restrictions.Add(new ZoomInRestriction(height, width));
    

    虽然不是该错误的确切解决方案,但您至少应该能够阻止用户体验它。

    【讨论】:

    • 谢谢 - 这是一个“很高兴拥有” - 但目前不是解决方案。不管怎么说,还是要谢谢你! :-)
    • 谢谢杰森,这太棒了!当放大得太远时,我的图表会暂时冻结 - 这会阻止这种情况的发生,并将用户限制为我们的应用程序的合理值,例如 10 毫秒。我的标签和刻度提供者不提供小于 1ms 的值,所以问题可能就在于此 - 当轴变为空白时,它必须陷入某种级联并且缩小暂时不会响应。无所事事!
    【解决方案2】:

    详情请见https://dynamicdatadisplay.codeplex.com/discussions/484160

    LineGraph.cs,方法OnRenderCore。 从

    替换以下行
    context.BeginFigure(FilteredPoints.StartPoint, false, false);
    

    context.BeginFigure(FilteredPoints.StartPoint, true, false);
    

    【讨论】:

      猜你喜欢
      • 2017-02-21
      • 1970-01-01
      • 2015-06-10
      • 1970-01-01
      • 2020-10-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多