在我的WPF项目中,我使用Dynamic data display进行制图。 我在某个地方看到,如果你放大得很深,这是一个常见的错误,就是线条会消失(不会被绘制)。
有没有人可以解决这个错误?
答案 0 :(得分: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));
虽然不是错误的确切解决方案,但您至少应该能够阻止用户体验它。
答案 1 :(得分:1)
有关详细信息,请参阅https://dynamicdatadisplay.codeplex.com/discussions/484160
在LineGraph.cs
中,方法OnRenderCore
。
从
context.BeginFigure(FilteredPoints.StartPoint, false, false);
到
context.BeginFigure(FilteredPoints.StartPoint, true, false);