From c273bf6a7bb7afea9e7167077dda712348e2aaa3 Mon Sep 17 00:00:00 2001 From: Fedor Bezrukov Date: Sun, 18 Mar 2018 17:25:45 +0000 Subject: [PATCH 1/5] Partial attempt to fix label scaling to atomatically scientific notation. Note, that the logic of replacing scientific notation in GR backend is a bit dodgy. --- src/axes.jl | 2 +- src/backends/gr.jl | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/axes.jl b/src/axes.jl index 855f8d97..1cecd211 100644 --- a/src/axes.jl +++ b/src/axes.jl @@ -212,7 +212,7 @@ function optimal_ticks_and_labels(axis::Axis, ticks = nothing) formatter = axis[:formatter] if formatter == :auto # the default behavior is to make strings of the scaled values and then apply the labelfunc - map(labelfunc(scale, backend()), Showoff.showoff(scaled_ticks, :plain)) + map(labelfunc(scale, backend()), Showoff.showoff(scaled_ticks, :auto)) elseif formatter == :scientific Showoff.showoff(unscaled_ticks, :scientific) else diff --git a/src/backends/gr.jl b/src/backends/gr.jl index 7ff6f606..f259f143 100644 --- a/src/backends/gr.jl +++ b/src/backends/gr.jl @@ -223,7 +223,7 @@ function gr_polaraxes(rmin::Real, rmax::Real, sp::Subplot) sinf = sind.(a) cosf = cosd.(a) rtick_values, rtick_labels = get_ticks(yaxis) - if yaxis[:formatter] == :scientific && yaxis[:ticks] in (:auto, :native) + if (yaxis[:formatter] == :scientific || contains(rtick_labels,"×10") )&& yaxis[:ticks] in (:auto, :native) rtick_labels = convert_sci_unicode(rtick_labels) end @@ -889,7 +889,7 @@ function gr_display(sp::Subplot{GRBackend}, w, h, viewport_canvas) # ensure correct dispatch in gr_text for automatic log ticks if xaxis[:scale] in _logScales dv = string(dv, "\\ ") - elseif xaxis[:formatter] == :scientific + elseif xaxis[:formatter] == :scientific || contains(dv,"×10") dv = convert_sci_unicode(dv) end end @@ -908,7 +908,7 @@ function gr_display(sp::Subplot{GRBackend}, w, h, viewport_canvas) # ensure correct dispatch in gr_text for automatic log ticks if yaxis[:scale] in _logScales dv = string(dv, "\\ ") - elseif yaxis[:formatter] == :scientific + elseif yaxis[:formatter] == :scientific || contains(dv,"×10") dv = convert_sci_unicode(dv) end end From 6b6394ba9779b1351f8bb3cb5d067071877a8dea Mon Sep 17 00:00:00 2001 From: Fedor Bezrukov Date: Mon, 19 Mar 2018 03:15:14 +0000 Subject: [PATCH 2/5] Fixed bug introduced into GR Polar plot --- src/backends/gr.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/backends/gr.jl b/src/backends/gr.jl index f259f143..692f33c8 100644 --- a/src/backends/gr.jl +++ b/src/backends/gr.jl @@ -223,7 +223,7 @@ function gr_polaraxes(rmin::Real, rmax::Real, sp::Subplot) sinf = sind.(a) cosf = cosd.(a) rtick_values, rtick_labels = get_ticks(yaxis) - if (yaxis[:formatter] == :scientific || contains(rtick_labels,"×10") )&& yaxis[:ticks] in (:auto, :native) + if (yaxis[:formatter] == :scientific || any(contains.(rtick_labels,"×10"))) && yaxis[:ticks] in (:auto, :native) rtick_labels = convert_sci_unicode(rtick_labels) end From 4e5c88eb74a11e9c7a77a1bf663d81de44603f28 Mon Sep 17 00:00:00 2001 From: Fedor Bezrukov Date: Wed, 21 Mar 2018 00:12:57 +0000 Subject: [PATCH 3/5] Fixed unicode display for plotly() --- src/backends/web.jl | 1 + 1 file changed, 1 insertion(+) diff --git a/src/backends/web.jl b/src/backends/web.jl index 36fd5d06..e38ad782 100644 --- a/src/backends/web.jl +++ b/src/backends/web.jl @@ -12,6 +12,7 @@ function standalone_html(plt::AbstractPlot; title::AbstractString = get(plt.attr $title + $(html_head(plt)) From bd06f0c71306192caa5d26c5987c225686884a06 Mon Sep 17 00:00:00 2001 From: Fedor Bezrukov Date: Wed, 21 Mar 2018 09:54:52 +0000 Subject: [PATCH 4/5] Fixed broken behaviour for function :formatter, and pgfplots --- src/backends/gr.jl | 8 ++++---- src/backends/pgfplots.jl | 3 ++- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/backends/gr.jl b/src/backends/gr.jl index 692f33c8..88fcad36 100644 --- a/src/backends/gr.jl +++ b/src/backends/gr.jl @@ -223,8 +223,8 @@ function gr_polaraxes(rmin::Real, rmax::Real, sp::Subplot) sinf = sind.(a) cosf = cosd.(a) rtick_values, rtick_labels = get_ticks(yaxis) - if (yaxis[:formatter] == :scientific || any(contains.(rtick_labels,"×10"))) && yaxis[:ticks] in (:auto, :native) - rtick_labels = convert_sci_unicode(rtick_labels) + if yaxis[:formatter] in (:scientific, :auto) && yaxis[:ticks] in (:auto, :native) + rtick_labels = convert_sci_unicode.(rtick_labels) end #draw angular grid @@ -889,7 +889,7 @@ function gr_display(sp::Subplot{GRBackend}, w, h, viewport_canvas) # ensure correct dispatch in gr_text for automatic log ticks if xaxis[:scale] in _logScales dv = string(dv, "\\ ") - elseif xaxis[:formatter] == :scientific || contains(dv,"×10") + elseif xaxis[:formatter] in (:scientific, :auto) dv = convert_sci_unicode(dv) end end @@ -908,7 +908,7 @@ function gr_display(sp::Subplot{GRBackend}, w, h, viewport_canvas) # ensure correct dispatch in gr_text for automatic log ticks if yaxis[:scale] in _logScales dv = string(dv, "\\ ") - elseif yaxis[:formatter] == :scientific || contains(dv,"×10") + elseif yaxis[:formatter] in (:scientific, :auto) dv = convert_sci_unicode(dv) end end diff --git a/src/backends/pgfplots.jl b/src/backends/pgfplots.jl index ef2920ad..0f28ac57 100644 --- a/src/backends/pgfplots.jl +++ b/src/backends/pgfplots.jl @@ -329,7 +329,8 @@ function pgf_axis(sp::Subplot, letter) push!(style, string(letter, "ticklabels = {\$", join(tick_labels,"\$,\$"), "\$}")) elseif axis[:showaxis] tick_labels = ispolar(sp) && letter == :x ? [ticks[2][3:end]..., "0", "45"] : ticks[2] - tick_labels = axis[:formatter] == :scientific ? string.("\$", convert_sci_unicode.(tick_labels), "\$") : tick_labels + tick_labels = ( axis[:formatter] in (:scientific, :auto) ? + string.("\$", convert_sci_unicode.(tick_labels), "\$") : tick_labels ) push!(style, string(letter, "ticklabels = {", join(tick_labels,","), "}")) else push!(style, string(letter, "ticklabels = {}")) From 92f9ccce5c58c5412a2cbebb9ec30b75260fa4fb Mon Sep 17 00:00:00 2001 From: Fedor Bezrukov Date: Wed, 21 Mar 2018 23:58:26 +0000 Subject: [PATCH 5/5] Added :plain formatter --- src/axes.jl | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/axes.jl b/src/axes.jl index 1cecd211..089840ac 100644 --- a/src/axes.jl +++ b/src/axes.jl @@ -213,11 +213,19 @@ function optimal_ticks_and_labels(axis::Axis, ticks = nothing) if formatter == :auto # the default behavior is to make strings of the scaled values and then apply the labelfunc map(labelfunc(scale, backend()), Showoff.showoff(scaled_ticks, :auto)) + elseif formatter == :plain + # Leave the numbers in plain format + map(labelfunc(scale, backend()), Showoff.showoff(scaled_ticks, :plain)) elseif formatter == :scientific Showoff.showoff(unscaled_ticks, :scientific) else # there was an override for the formatter... use that on the unscaled ticks map(formatter, unscaled_ticks) + # if the formatter left us with numbers, still apply the default formatter + # However it leave us with the problem of unicode number decoding by the backend + # if eltype(unscaled_ticks) <: Number + # Showoff.showoff(unscaled_ticks, :auto) + # end end else # no finite ticks to show...