public void Initialize() { // Initialize the plot model = new PlotModel(); xAxis = new LinearAxis() { Position = AxisPosition.Bottom, Minimum = 0, Maximum = roc.window.TotalMilliseconds, IsAxisVisible = true, IsZoomEnabled = false, IsPanEnabled = false, MinimumPadding = 0, MaximumPadding = 0, Key = "time", LabelFormatter = (arg) => { var d = DateTime.FromFileTime((long)arg); return(d.Hour.ToString("00") + ":" + d.Minute.ToString("00") + ":" + d.Second.ToString("00")); }, Font = model.DefaultFont, FontSize = 15, TextColor = OxyColors.Black, AxislineThickness = 0, AxislineStyle = LineStyle.None, MajorGridlineStyle = LineStyle.None, MinorGridlineStyle = LineStyle.None, AxisTickToLabelDistance = 0, AxisTitleDistance = 0, }; var baseUnit = manifold.primarySensor.unit.standardUnit; primaryAxis = new MinMaxLineAxis() { Position = AxisPosition.Left, Minimum = 0, Maximum = 100, IsAxisVisible = true, IsZoomEnabled = false, IsPanEnabled = false, Key = "first", Font = model.DefaultFont, FontSize = 15, TextColor = OxyColors.Black, AxislineThickness = 0, AxislineStyle = LineStyle.None, MajorGridlineStyle = LineStyle.None, MinorGridlineStyle = LineStyle.None, }; secondaryAxis = new MinMaxLineAxis() { Position = AxisPosition.Right, Minimum = 0, Maximum = 100, IsAxisVisible = true, IsZoomEnabled = false, IsPanEnabled = false, Key = "second", Font = model.DefaultFont, FontSize = 15, TextColor = OxyColors.Black, AxislineThickness = 0, AxislineStyle = LineStyle.None, MajorGridlineStyle = LineStyle.None, MinorGridlineStyle = LineStyle.None, }; if (showLabels) { primaryAxis.LabelFormatter = (arg) => { var u = manifold.primarySensor.unit; var p = SensorUtils.ToFormattedString(u.standardUnit.OfScalar(arg).ConvertTo(u), true); return(p); }; secondaryAxis.LabelFormatter = (arg) => { if (manifold.secondarySensor != null) { var u = manifold.secondarySensor.unit; return(SensorUtils.ToFormattedString(u.standardUnit.OfScalar(arg).ConvertTo(u), true)); } else { return(""); } }; xAxis.FontSize = 15; primaryAxis.FontSize = 15; secondaryAxis.FontSize = 15; } else { xAxis.FontSize = 10; } primarySeries = new LineSeries() { StrokeThickness = 1, Color = OxyColors.Red, MarkerType = MarkerType.None, MarkerSize = 0, MarkerStroke = OxyColors.Transparent, MarkerStrokeThickness = 0, YAxisKey = "first", }; secondarySeries = new LineSeries() { StrokeThickness = 1, Color = OxyColors.Blue, MarkerType = MarkerType.None, MarkerSize = 0, MarkerStroke = OxyColors.Transparent, MarkerStrokeThickness = 0, YAxisKey = "second", }; // model.PlotMargins = new OxyThickness(0, -5, 0, 2 + (showLabels ? xAxis.FontSize : 10) - 10); model.PlotMargins = new OxyThickness(0, -7, 0, 2 + (showLabels ? xAxis.FontSize : 10) - 10); model.PlotType = PlotType.XY; model.Axes.Add(xAxis); model.Axes.Add(primaryAxis); model.Axes.Add(secondaryAxis); model.Series.Add(primarySeries); model.Series.Add(secondarySeries); model.PlotAreaBorderThickness = new OxyThickness(1); model.PlotAreaBorderColor = OxyColors.Black; plot.Model = model; }
/// <summary> /// Updates the axis to the given state. /// </summary> /// <param name="axis">Axis.</param> private void UpdateAxis(MinMaxLineAxis axis, Sensor sensor, Scalar min, Scalar max, Unit u, int major = 2, int minor = 5) { var su = u.standardUnit; var minMag = min.ConvertTo(u).amount; var maxMag = max.ConvertTo(u).amount; minMag = minMag.TruncateToSignifiantDigits(2); maxMag = maxMag.RoundToSignificantDigits(2); if (maxMag - minMag == 0) { if (minMag == 0) { minMag -= u.OfScalar(1).amount; maxMag += u.OfScalar(1).amount; } else { var del = Math.Pow(10, Math.Floor(Math.Log10(minMag)) - 1); minMag -= del; maxMag += del; } } var determineDifference = DetermineMinimumBounds(sensor); minMag = u.OfScalar(minMag).ConvertTo(su).amount; maxMag = u.OfScalar(maxMag).ConvertTo(su).amount; var diff = (maxMag - minMag); if (minMag < sensor.minMeasurement.ConvertTo(su).amount) { minMag = sensor.minMeasurement.ConvertTo(su).amount; } var range = sensor.range.ConvertTo(su) * 0.05; if (diff < range.magnitude) { diff = range.magnitude; maxMag = minMag + diff; } var mod = diff / major; axis.SetMinMax(minMag, maxMag); axis.Minimum = minMag; axis.Maximum = maxMag; var padding = diff * 0.20; axis.MajorStep = mod; axis.MinimumMajorStep = mod; axis.Minimum -= padding; axis.Maximum += padding; axis.MajorTickSize = 10; axis.TicklineColor = OxyColors.Black; axis.MinimumPadding = 0.25; axis.MaximumPadding = 0.25; axis.AxislineStyle = LineStyle.Solid; axis.AxislineThickness = 1; axis.AxisTickToLabelDistance = -(MeasureTextWidth(axis) + axis.MajorTickSize + 5); }