1

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

有没有人解决这个错误?

4

2 回答 2

3

虽然不是针对您的错误的精确解决方案,但您可以通过使用缩放限制将用户放大得太深来阻止用户。这样,用户将永远不会通过放大那么深来体验这个错误。您可以找到此错误发生的缩放比例,并限制该 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));

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

于 2012-11-09T15:38:35.777 回答
1

有关详细信息,请参阅https://dynamicdatadisplay.codeplex.com/discussions/484160

LineGraph.cs,方法OnRenderCore。替换以下行

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

context.BeginFigure(FilteredPoints.StartPoint, true, false);
于 2016-06-02T12:32:44.963 回答