From 68bd0cac81bda8b24d2752c20ea5774ca4612038 Mon Sep 17 00:00:00 2001 From: capdiem Date: Thu, 27 Jul 2023 13:54:01 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=86=95=20feat(ECharts):=20support=20for?= =?UTF-8?q?=20verbatim=20text=20of=20function=20string=20(#1449)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Masa.Blazor/Components/ECharts/MECharts.razor.cs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/Masa.Blazor/Components/ECharts/MECharts.razor.cs b/src/Masa.Blazor/Components/ECharts/MECharts.razor.cs index 7c3cdc8301..50e1c287c5 100644 --- a/src/Masa.Blazor/Components/ECharts/MECharts.razor.cs +++ b/src/Masa.Blazor/Components/ECharts/MECharts.razor.cs @@ -202,9 +202,18 @@ public async Task SetOption(object? option = null, bool notMerge = true, bool la if (IncludeFunctionsInOption && IsAnyFunction(option, out var optionJson)) { + // unescape verbatim text + optionJson = Regex.Unescape(optionJson); + + // remove the double quotes around the function optionJson = FormatFunction(optionJson); + + // remove the double quotes around the lambda optionJson = FormatLambda(optionJson); + + // convert unicode to string optionJson = Unicode2String(optionJson); + await _echarts.SetJsonOptionAsync(optionJson, notMerge, lazyUpdate); } else @@ -232,6 +241,7 @@ public static bool IsAnyFunction(object option, out string optionJson) PropertyNamingPolicy = JsonNamingPolicy.CamelCase }); + // check if the option contains "function" or "=>" return optionJson.Contains("function") || optionJson.Contains("=\\u003e", StringComparison.OrdinalIgnoreCase); }