1
在最近的c#wpf應用程序中,我使用了oxyplot進行趨勢分析。這是一個在體積數據上具有高性能的好工具。我從LiveChart移動到Oxyplot。如何根據軸範圍實現截面背景? TargetEffectOxyPlot:如何根據軸範圍添加背景
我已經嘗試修改ThreeColorLineSeries,現在我可以根據設置喜和下限渲染線。但對於背景,它不起作用。
using System.Collections.Generic;
/// <summary>
/// Represents a two-color line series.
/// </summary>
public class FourColorLineSeries : LineSeries
{
/// <summary>
/// The default low color.
/// </summary>
private OxyColor defaultColorLoPre;
/// <summary>
/// The default low color.
/// </summary>
private OxyColor defaultColorLo;
/// <summary>
/// The default hi color.
/// </summary>
private OxyColor defaultColorLoLo;
/// <summary>
/// The default low color.
/// </summary>
private OxyColor defaultColorHiPre;
/// <summary>
/// The default low color.
/// </summary>
private OxyColor defaultColorHi;
/// <summary>
/// The default hi color.
/// </summary>
private OxyColor defaultColorHiHi;
/// <summary>
/// Initializes a new instance of the <see cref = "FourColorLineSeries" /> class.
/// </summary>
public FourColorLineSeries()
{
this.LimitHiPre = 1.0;
this.ColorHiPre = OxyColors.Green;
this.LineStyleHiPre = LineStyle.Solid;
this.LimitHi = 2.0;
this.ColorHi = OxyColors.Yellow;
this.LineStyleHi = LineStyle.Solid;
this.LimitHiHi = 5.0;
this.ColorHiHi = OxyColors.Red;
this.LineStyleHiHi = LineStyle.Solid;
this.LimitLoPre = -1.0;
this.ColorLoPre = OxyColors.Green;
this.LineStyleLoPre = LineStyle.Solid;
this.LimitLo = -2.0;
this.ColorLo = OxyColors.Yellow;
this.LineStyleLo = LineStyle.Solid;
this.LimitLoLo = -5.0;
this.ColorLoLo = OxyColors.Red;
this.LineStyleLoLo = LineStyle.Solid;
}
/// <summary>
/// Gets or sets the color for the part of the line that is below the limit.
/// </summary>
public OxyColor ColorLoPre { get; set; }
/// <summary>
/// Gets or sets the color for the part of the line that is below the limit.
/// </summary>
public OxyColor ColorLo { get; set; }
/// <summary>
/// Gets or sets the color for the part of the line that is above the limit.
/// </summary>
public OxyColor ColorLoLo { get; set; }
/// <summary>
/// Gets or sets the color for the part of the line that is below the limit.
/// </summary>
public OxyColor ColorHiPre { get; set; }
/// <summary>
/// Gets or sets the color for the part of the line that is below the limit.
/// </summary>
public OxyColor ColorHi { get; set; }
/// <summary>
/// Gets or sets the color for the part of the line that is above the limit.
/// </summary>
public OxyColor ColorHiHi { get; set; }
/// <summary>
/// Gets the actual low pre color.
/// </summary>
/// <value>The actual color.</value>
public OxyColor ActualColorLoPre
{
get { return this.ColorLoPre.GetActualColor(this.defaultColorLoPre); }
}
/// <summary>
/// Gets the actual low color.
/// </summary>
/// <value>The actual color.</value>
public OxyColor ActualColorLo
{
get { return this.ColorLo.GetActualColor(this.defaultColorLo); }
}
/// <summary>
/// Gets the actual low low color.
/// </summary>
/// <value>The actual color.</value>
public OxyColor ActualColorLoLo
{
get { return this.ColorLoLo.GetActualColor(this.defaultColorLoLo); }
}
/// <summary>
/// Gets the actual hi pre color.
/// </summary>
/// <value>The actual color.</value>
public OxyColor ActualColorHiPre
{
get { return this.ColorHiPre.GetActualColor(this.defaultColorHiPre); }
}
/// <summary>
/// Gets the actual hi color.
/// </summary>
/// <value>The actual color.</value>
public OxyColor ActualColorHi
{
get { return this.ColorHi.GetActualColor(this.defaultColorHi); }
}
/// <summary>
/// Gets the actual low color.
/// </summary>
/// <value>The actual color.</value>
public OxyColor ActualColorHiHi
{
get { return this.ColorHiHi.GetActualColor(this.defaultColorHiHi); }
}
/// <summary>
/// Gets or sets the high limit.
/// </summary>
/// <remarks>The parts of the line that is below this limit will be rendered with ColorHi.
/// The parts of the line that is above the limit will be rendered with Color.</remarks>
public double LimitLoPre { get; set; }
/// <summary>
/// Gets or sets the low limit.
/// </summary>
/// <remarks>The parts of the line that is below this limit will be rendered with ColorLo.
/// The parts of the line that is above the limit will be rendered with Color.</remarks>
public double LimitLo { get; set; }
/// <summary>
/// Gets or sets the pre limit.
/// </summary>
/// <remarks>The parts of the line that is below this limit will be rendered with ColorPre.
/// The parts of the line that is above the limit will be rendered with Color.</remarks>
public double LimitLoLo { get; set; }
/// <summary>
/// Gets or sets the high limit.
/// </summary>
/// <remarks>The parts of the line that is below this limit will be rendered with ColorHi.
/// The parts of the line that is above the limit will be rendered with Color.</remarks>
public double LimitHiPre { get; set; }
/// <summary>
/// Gets or sets the low limit.
/// </summary>
/// <remarks>The parts of the line that is below this limit will be rendered with ColorLo.
/// The parts of the line that is above the limit will be rendered with Color.</remarks>
public double LimitHi { get; set; }
/// <summary>
/// Gets or sets the pre limit.
/// </summary>
/// <remarks>The parts of the line that is below this limit will be rendered with ColorPre.
/// The parts of the line that is above the limit will be rendered with Color.</remarks>
public double LimitHiHi { get; set; }
/// <summary>
/// Gets or sets the dash array for the rendered line that is above the limit (overrides <see cref="LineStyle" />).
/// </summary>
/// <value>The dash array.</value>
/// <remarks>If this is not <c>null</c> it overrides the <see cref="LineStyle" /> property.</remarks>
public double[] DashesHi { get; set; }
/// <summary>
/// Gets or sets the dash array for the rendered line that is below the limit (overrides <see cref="LineStyle" />).
/// </summary>
/// <value>The dash array.</value>
/// <remarks>If this is not <c>null</c> it overrides the <see cref="LineStyle" /> property.</remarks>
public double[] DashesLo { get; set; }
/// <summary>
/// Gets or sets the dash array for the rendered line that is below the limit (overrides <see cref="LineStyle" />).
/// </summary>
/// <value>The dash array.</value>
/// <remarks>If this is not <c>null</c> it overrides the <see cref="LineStyle" /> property.</remarks>
public double[] DashesLoPre { get; set; }
/// <summary>
/// Gets or sets the dash array for the rendered line that is above the limit (overrides <see cref="LineStyle" />).
/// </summary>
/// <value>The dash array.</value>
/// <remarks>If this is not <c>null</c> it overrides the <see cref="LineStyle" /> property.</remarks>
public double[] DashesLoLo { get; set; }
/// <summary>
/// Gets or sets the dash array for the rendered line that is below the limit (overrides <see cref="LineStyle" />).
/// </summary>
/// <value>The dash array.</value>
/// <remarks>If this is not <c>null</c> it overrides the <see cref="LineStyle" /> property.</remarks>
public double[] DashesHiPre { get; set; }
/// <summary>
/// Gets or sets the dash array for the rendered line that is below the limit (overrides <see cref="LineStyle" />).
/// </summary>
/// <value>The dash array.</value>
/// <remarks>If this is not <c>null</c> it overrides the <see cref="LineStyle" /> property.</remarks>
public double[] DashesHiHi { get; set; }
/// <summary>
/// Gets or sets the line style for the part of the line that is above the limit.
/// </summary>
/// <value>The line style.</value>
public LineStyle LineStyleLoPre { get; set; }
/// <summary>
/// Gets or sets the line style for the part of the line that is below the limit.
/// </summary>
/// <value>The line style.</value>
public LineStyle LineStyleLo { get; set; }
/// <summary>
/// Gets or sets the line style for the part of the line that is below the limit.
/// </summary>
/// <value>The line style.</value>
public LineStyle LineStyleLoLo { get; set; }
/// <summary>
/// Gets or sets the line style for the part of the line that is above the limit.
/// </summary>
/// <value>The line style.</value>
public LineStyle LineStyleHiPre { get; set; }
/// <summary>
/// Gets or sets the line style for the part of the line that is below the limit.
/// </summary>
/// <value>The line style.</value>
public LineStyle LineStyleHi { get; set; }
/// <summary>
/// Gets or sets the line style for the part of the line that is below the limit.
/// </summary>
/// <value>The line style.</value>
public LineStyle LineStyleHiHi { get; set; }
/// <summary>
/// Gets the actual line style for the part of the line that is above the limit.
/// </summary>
/// <value>The line style.</value>
public LineStyle ActualLineStyleHi
{
get
{
return this.LineStyleHi != LineStyle.Automatic ? this.LineStyleHi : LineStyle.Solid;
}
}
/// <summary>
/// Gets the actual line style for the part of the line that is above the limit.
/// </summary>
/// <value>The line style.</value>
public LineStyle ActualLineStyleHiHi
{
get
{
return this.LineStyleHiHi != LineStyle.Automatic ? this.LineStyleHiHi : LineStyle.Solid;
}
}
/// <summary>
/// Gets the actual line style for the part of the line that is above the limit.
/// </summary>
/// <value>The line style.</value>
public LineStyle ActualLineStyleHiPre
{
get
{
return this.LineStyleHiPre != LineStyle.Automatic ? this.LineStyleHiPre : LineStyle.Solid;
}
}
/// <summary>
/// Gets the actual line style for the part of the line that is above the limit.
/// </summary>
/// <value>The line style.</value>
public LineStyle ActualLineStyleLoPre
{
get
{
return this.LineStyleLoPre != LineStyle.Automatic ? this.LineStyleLoPre : LineStyle.Solid;
}
}
/// <summary>
/// Gets the actual line style for the part of the line that is below the limit.
/// </summary>
/// <value>The line style.</value>
public LineStyle ActualLineStyleLo
{
get
{
return this.LineStyleLo != LineStyle.Automatic ? this.LineStyleLo : LineStyle.Solid;
}
}
/// <summary>
/// Gets the actual line style for the part of the line that is below the limit.
/// </summary>
/// <value>The line style.</value>
public LineStyle ActualLineStyleLoLo
{
get
{
return this.LineStyleLoLo != LineStyle.Automatic ? this.LineStyleLoLo : LineStyle.Solid;
}
}
/// <summary>
/// Gets the actual dash array for the line that is above the limit.
/// </summary>
protected double[] ActualDashArrayHi
{
get
{
return this.DashesHi ?? this.ActualLineStyleHi.GetDashArray();
}
}
/// <summary>
/// Gets the actual dash array for the line that is below the limit.
/// </summary>
protected double[] ActualDashArrayLo
{
get
{
return this.DashesLo ?? this.ActualLineStyleLo.GetDashArray();
}
}
/// <summary>
/// Gets the actual dash array for the line that is below the limit.
/// </summary>
protected double[] ActualDashArrayLoPre
{
get
{
return this.DashesLoPre ?? this.ActualLineStyleLoPre.GetDashArray();
}
}
/// <summary>
/// Gets the actual dash array for the line that is above the limit.
/// </summary>
protected double[] ActualDashArrayHiHi
{
get
{
return this.DashesHiHi ?? this.ActualLineStyleHiHi.GetDashArray();
}
}
/// <summary>
/// Gets the actual dash array for the line that is below the limit.
/// </summary>
protected double[] ActualDashArrayLoLo
{
get
{
return this.DashesLoLo ?? this.ActualLineStyleLoLo.GetDashArray();
}
}
/// <summary>
/// Gets the actual dash array for the line that is below the limit.
/// </summary>
protected double[] ActualDashArrayHiPre
{
get
{
return this.DashesHiPre ?? this.ActualLineStyleHiPre.GetDashArray();
}
}
/// <summary>
/// Sets the default values.
/// </summary>
protected internal override void SetDefaultValues()
{
base.SetDefaultValues();
if (this.ColorLoPre.IsAutomatic())
{
this.defaultColorLoPre = this.PlotModel.GetDefaultColor();
}
if (this.LineStyleLoPre == LineStyle.Automatic)
{
this.LineStyleLoPre = this.PlotModel.GetDefaultLineStyle();
}
if (this.ColorHiPre.IsAutomatic())
{
this.defaultColorHiPre = this.PlotModel.GetDefaultColor();
}
if (this.LineStyleHiPre == LineStyle.Automatic)
{
this.LineStyleHiPre = this.PlotModel.GetDefaultLineStyle();
}
if (this.ColorLo.IsAutomatic())
{
this.defaultColorLo = this.PlotModel.GetDefaultColor();
}
if (this.LineStyleLo == LineStyle.Automatic)
{
this.LineStyleLo = this.PlotModel.GetDefaultLineStyle();
}
if (this.ColorLoLo.IsAutomatic())
{
this.defaultColorLoLo = this.PlotModel.GetDefaultColor();
}
if (this.LineStyleLoLo == LineStyle.Automatic)
{
this.LineStyleLoLo = this.PlotModel.GetDefaultLineStyle();
}
if (this.ColorHi.IsAutomatic())
{
this.defaultColorHi = this.PlotModel.GetDefaultColor();
}
if (this.LineStyleHi == LineStyle.Automatic)
{
this.LineStyleHi = this.PlotModel.GetDefaultLineStyle();
}
if (this.ColorHiHi.IsAutomatic())
{
this.defaultColorHiHi = this.PlotModel.GetDefaultColor();
}
if (this.LineStyleHiHi == LineStyle.Automatic)
{
this.LineStyleHiHi = this.PlotModel.GetDefaultLineStyle();
}
}
/// <summary>
/// Renders the smoothed line.
/// </summary>
/// <param name="rc">The render context.</param>
/// <param name="clippingRect">The clipping rectangle.</param>
/// <param name="pointsToRender">The points.</param>
protected override void RenderLine(IRenderContext rc, OxyRect clippingRect, IList<ScreenPoint> pointsToRender)
{
var bottom = clippingRect.Bottom;
var top = clippingRect.Top;
// todo: this does not work when y axis is reversed
var yLoPre = this.YAxis.Transform(this.LimitLoPre);
var yLo = this.YAxis.Transform(this.LimitLo);
var yLoLo = this.YAxis.Transform(this.LimitLoLo);
var yHiPre = this.YAxis.Transform(this.LimitHiPre);
var yHi = this.YAxis.Transform(this.LimitHi);
var yHiHi = this.YAxis.Transform(this.LimitHiHi);
if (yLoPre< clippingRect.Top)
{
yLoPre = clippingRect.Top;
}
if (yLoPre > clippingRect.Bottom)
{
yLoPre = clippingRect.Bottom;
}
if (yHiPre < clippingRect.Top)
{
yHiPre = clippingRect.Top;
}
if (yHiPre > clippingRect.Bottom)
{
yHiPre = clippingRect.Bottom;
}
if (yLo < clippingRect.Top)
{
yLo = clippingRect.Top;
}
if (yLo > clippingRect.Bottom)
{
yLo = clippingRect.Bottom;
}
if (yLoLo < clippingRect.Top)
{
yLoLo = clippingRect.Top;
}
if (yLoLo > clippingRect.Bottom)
{
yLoLo = clippingRect.Bottom;
}
if (yHi < clippingRect.Top)
{
yHi = clippingRect.Top;
}
if (yHi > clippingRect.Bottom)
{
yHi = clippingRect.Bottom;
}
if (yHiHi < clippingRect.Top)
{
yHiHi = clippingRect.Top;
}
if (yHiHi > clippingRect.Bottom)
{
yHiHi = clippingRect.Bottom;
}
clippingRect = new OxyRect(clippingRect.Left, top, clippingRect.Width, yHiHi - top);
rc.DrawClippedLine(
clippingRect,
pointsToRender,
this.MinimumSegmentLength * this.MinimumSegmentLength,
this.GetSelectableColor(this.ActualColorHiHi),
this.StrokeThickness,
this.ActualDashArrayHiHi,
this.LineJoin,
false);
clippingRect = new OxyRect(clippingRect.Left, yHiHi, clippingRect.Width, yHi - yHiHi);
rc.DrawClippedLine(
clippingRect,
pointsToRender,
this.MinimumSegmentLength * this.MinimumSegmentLength,
this.GetSelectableColor(this.ActualColorHi),
this.StrokeThickness,
this.ActualDashArrayHi,
this.LineJoin,
false);
clippingRect = new OxyRect(clippingRect.Left, yHi, clippingRect.Width, yHiPre - yHi);
rc.DrawClippedLine(
clippingRect,
pointsToRender,
this.MinimumSegmentLength * this.MinimumSegmentLength,
this.GetSelectableColor(this.ActualColorHiPre),
this.StrokeThickness,
this.ActualDashArrayHiPre,
this.LineJoin,
false);
clippingRect = new OxyRect(clippingRect.Left, yHiPre, clippingRect.Width, yLoPre - yHiPre);
rc.DrawClippedLine(
clippingRect,
pointsToRender,
this.MinimumSegmentLength * this.MinimumSegmentLength,
this.GetSelectableColor(this.ActualColor),
this.StrokeThickness,
this.ActualDashArray,
this.LineJoin,
false);
clippingRect = new OxyRect(clippingRect.Left, yLoPre, clippingRect.Width, yLo - yLoPre);
rc.DrawClippedLine(
clippingRect,
pointsToRender,
this.MinimumSegmentLength * this.MinimumSegmentLength,
this.GetSelectableColor(this.ActualColorLoPre),
this.StrokeThickness,
this.ActualDashArrayLoPre,
this.LineJoin,
false);
clippingRect = new OxyRect(clippingRect.Left, yLo, clippingRect.Width, yLoLo - yLo);
rc.DrawClippedLine(
clippingRect,
pointsToRender,
this.MinimumSegmentLength * this.MinimumSegmentLength,
this.GetSelectableColor(this.ActualColorLo),
this.StrokeThickness,
this.ActualDashArrayLo,
this.LineJoin,
false);
clippingRect = new OxyRect(clippingRect.Left, yLoLo, clippingRect.Width, bottom - yLoLo);
rc.DrawClippedLine(
clippingRect,
pointsToRender,
this.MinimumSegmentLength * this.MinimumSegmentLength,
this.GetSelectableColor(this.ActualColorLoLo),
this.StrokeThickness,
this.ActualDashArrayLoLo,
this.LineJoin,
false);
}
}
}