diff --git a/CHANGELOG.MD b/CHANGELOG.MD index 9f69346..c8ea5b9 100644 --- a/CHANGELOG.MD +++ b/CHANGELOG.MD @@ -1,3 +1,5 @@ + +- add support for different line break symbols in tracker (closes #15 by archer0302) ## 2023-05-16 v2.5.7 - improve: svg clip path id is not regenerated on upon every update (only for dynamic data) diff --git a/OxyPlot.Blazor/BlazorSvgFragmentRenderContext.cs b/OxyPlot.Blazor/BlazorSvgFragmentRenderContext.cs index 0d3ad3f..3ebd340 100644 --- a/OxyPlot.Blazor/BlazorSvgFragmentRenderContext.cs +++ b/OxyPlot.Blazor/BlazorSvgFragmentRenderContext.cs @@ -15,12 +15,12 @@ namespace OxyPlot.Blazor using System.Linq; using System.Text; using Microsoft.AspNetCore.Components.Rendering; - using System.Text.RegularExpressions; + /// /// Provides a render context for scalable vector graphics output. /// - public class BlazorSvgFragmentRenderContext : ClippingRenderContext + public partial class BlazorSvgFragmentRenderContext : ClippingRenderContext { /// /// Tooltip(title) for next svg element @@ -584,7 +584,7 @@ public override void DrawText( return; } - var lines = Regex.Split(text, "(\r\n|\n|\r)"); + var lines = Helpers.SplitToLines(text); var textSize = MeasureText(text, fontFamily, fontSize, fontWeight); var lineHeight = textSize.Height / lines.Length; diff --git a/OxyPlot.Blazor/Helpers.cs b/OxyPlot.Blazor/Helpers.cs new file mode 100644 index 0000000..26f502b --- /dev/null +++ b/OxyPlot.Blazor/Helpers.cs @@ -0,0 +1,35 @@ +// -------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2014 OxyPlot contributors +// +// +// Provides a render context for scalable vector graphics output. +// +// -------------------------------------------------------------------------------------------------------------------- + +namespace OxyPlot.Blazor +{ + using System.Text.RegularExpressions; + + internal partial class Helpers + { +#if NET7_0_OR_GREATER + [GeneratedRegex("(\r\n|\n|\r)", RegexOptions.CultureInvariant)] + private static partial Regex LineSplitterRegex(); +#endif + + /// + /// Splits the text at \r\n or \n or \r into multiple lines + /// + /// + /// the array of lines + public static string[] SplitToLines(string input) + { +#if NET7_0_OR_GREATER + return LineSplitterRegex().Split(input); +#else + return Regex.Split(input, "(\r\n|\n|\r)", RegexOptions.Compiled | RegexOptions.CultureInvariant); +#endif + } + } +}