Fix LaTeXStrings support for UnicodePlots and InspectDR (#3879)

* fix LaTeXStrings support for UnicodePlots and InspectDR

* rename & fix
This commit is contained in:
t-bltg 2021-11-03 09:22:37 +01:00 committed by Zhanibek
parent 1431054f54
commit 5251da1570
6 changed files with 20 additions and 9 deletions

View File

@ -31,6 +31,7 @@ Showoff = "992d4aef-0814-514b-bc4d-f2e9a6c4116f"
SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"
Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2"
StatsBase = "2913bbd2-ae8a-5f71-8c99-4fb6c76f3a91"
UnicodeFun = "1cfade01-22cf-5700-b092-accc4b62d6e1"
UUIDs = "cf7118a7-6976-5b1a-9a39-7adc72f591a4"
[compat]
@ -52,6 +53,7 @@ Requires = "1"
Scratch = "1"
Showoff = "0.3.1, 1.0"
StatsBase = "0.32 - 0.33"
UnicodeFun = "0.4"
UnicodePlots = "2.4"
julia = "1.5"

View File

@ -29,9 +29,10 @@ import RecipesBase: plot, plot!, animate, is_explicit
using Base.Meta
@reexport using PlotUtils
@reexport using PlotThemes
import Showoff
import UnicodeFun
import StatsBase
import Downloads
import Showoff
import JSON
using Requires

View File

@ -70,7 +70,7 @@ function _inspectdr_add_annotations(plot, x, y, val::PlotText)
color = _inspectdr_mapcolor(val.font.color),
)
ann = InspectDR.atext(
val.str,
texmath2unicode(val.str),
x = x,
y = y,
font = fnt,
@ -384,9 +384,9 @@ function _inspectdr_setupsubplot(sp::Subplot{InspectDRBackend})
_inspectdr_setticks(sp, plot, strip, xaxis, yaxis)
a = plot.annotation
a.title = sp[:title]
a.xlabel = xaxis[:guide]
a.ylabels = [yaxis[:guide]]
a.title = texmath2unicode(sp[:title])
a.xlabel = texmath2unicode(xaxis[:guide])
a.ylabels = [texmath2unicode(yaxis[:guide])]
#Modify base layout of new object:
l = plot.layout.defaults = deepcopy(InspectDR.defaults.plotlayout)

View File

@ -42,9 +42,9 @@ function unicodeplots_rebuild(plt::Plot{UnicodePlotsBackend})
kw = (
compact = true,
title = sp[:title],
xlabel = xaxis[:guide],
ylabel = yaxis[:guide],
title = texmath2unicode(sp[:title]),
xlabel = texmath2unicode(xaxis[:guide]),
ylabel = texmath2unicode(yaxis[:guide]),
xscale = xaxis[:scale],
yscale = yaxis[:scale],
border = isijulia() ? :ascii : :solid,
@ -63,7 +63,7 @@ function unicodeplots_rebuild(plt::Plot{UnicodePlotsBackend})
o,
x,
y,
val.str;
texmath2unicode(val.str);
color = up_color(val.font.color),
halign = val.font.halign,
valign = val.font.valign,

View File

@ -1221,6 +1221,7 @@ function mesh3d_triangles(x, y, z, cns::Tuple{Array,Array,Array})
end
return X, Y, Z
end
function mesh3d_triangles(x, y, z, cns::AbstractVector{NTuple{3,Int}})
X = zeros(eltype(x), 4length(cns))
Y = zeros(eltype(y), 4length(cns))
@ -1251,3 +1252,5 @@ const _attrsymbolcache = Dict{Symbol,Dict{Symbol,Symbol}}()
get_attr_symbol(letter::Symbol, keyword::String) = get_attr_symbol(letter, Symbol(keyword))
get_attr_symbol(letter::Symbol, keyword::Symbol) = _attrsymbolcache[letter][keyword]
texmath2unicode(s::AbstractString, pat=r"\$([^$]+)\$") = replace(s, pat => m->UnicodeFun.to_latex(m[2:(length(m)-1)]))

View File

@ -199,6 +199,11 @@ end
@test Plots.process_clims(nothing) ==
Plots.process_clims(missing) ==
Plots.process_clims(:auto)
@test (==)(
Plots.texmath2unicode(raw"Equation $y = \alpha \cdot x + \beta$ and eqn $y = \sin(x)^2$"),
raw"Equation y = α ⋅ x + β and eqn y = sin(x)²"
)
end
@testset "Backends" begin