Skip to content

Commit

Permalink
add support for different line break symbols in tracker (closes beluc…
Browse files Browse the repository at this point in the history
…ha#15 by archer0302)
  • Loading branch information
belucha committed Jan 24, 2024
1 parent 08865ed commit 4c32f34
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 3 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.MD
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
6 changes: 3 additions & 3 deletions OxyPlot.Blazor/BlazorSvgFragmentRenderContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ namespace OxyPlot.Blazor
using System.Linq;
using System.Text;
using Microsoft.AspNetCore.Components.Rendering;
using System.Text.RegularExpressions;


/// <summary>
/// Provides a render context for scalable vector graphics output.
/// </summary>
public class BlazorSvgFragmentRenderContext : ClippingRenderContext
public partial class BlazorSvgFragmentRenderContext : ClippingRenderContext
{
/// <summary>
/// Tooltip(title) for next svg element
Expand Down Expand Up @@ -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;
Expand Down
35 changes: 35 additions & 0 deletions OxyPlot.Blazor/Helpers.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// --------------------------------------------------------------------------------------------------------------------
// <copyright file="BlazorSvgRenderContext.cs" company="OxyPlot">
// Copyright (c) 2014 OxyPlot contributors
// </copyright>
// <summary>
// Provides a render context for scalable vector graphics output.
// </summary>
// --------------------------------------------------------------------------------------------------------------------

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

/// <summary>
/// Splits the text at \r\n or \n or \r into multiple lines
/// </summary>
/// <param name="input"></param>
/// <returns>the array of lines</returns>
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
}
}
}

0 comments on commit 4c32f34

Please sign in to comment.