From 2dd99d053a3b65eff2797f1f13bdd796f1be5d01 Mon Sep 17 00:00:00 2001 From: Daniel Schwabeneder Date: Thu, 10 Aug 2017 20:49:03 +0200 Subject: [PATCH] make it work on all backends --- src/backends/glvisualize.jl | 24 ++++++++++++++++++------ src/backends/gr.jl | 13 +++++++++---- src/backends/inspectdr.jl | 16 ++++++++++------ src/backends/pgfplots.jl | 12 ++++++++---- src/backends/plotly.jl | 8 ++++---- 5 files changed, 49 insertions(+), 24 deletions(-) diff --git a/src/backends/glvisualize.jl b/src/backends/glvisualize.jl index 3484131b..118db197 100644 --- a/src/backends/glvisualize.jl +++ b/src/backends/glvisualize.jl @@ -676,17 +676,29 @@ function text_model(font, pivot) end end function gl_draw_axes_2d(sp::Plots.Subplot{Plots.GLVisualizeBackend}, model, area) - xticks, yticks, spine_segs, grid_segs = Plots.axis_drawing_info(sp) + xticks, yticks, xspine_segs, yspine_segs, xgrid_segs, ygrid_segs = Plots.axis_drawing_info(sp) xaxis = sp[:xaxis]; yaxis = sp[:yaxis] - c = Colors.color(Plots.gl_color(sp[:foreground_color_grid])) + xgc = Colors.color(Plots.gl_color(xaxis[:foreground_color_grid])) + ygc = Colors.color(Plots.gl_color(yaxis[:foreground_color_grid])) axis_vis = [] - if sp[:grid] - grid = draw_grid_lines(sp, grid_segs, 1f0, :dot, model, RGBA(c, 0.3f0)) + if !(xaxis[:grid] in (nothing, false)) + grid = draw_grid_lines(sp, xgrid_segs, 1f0, :dot, model, RGBA(xgc, 0.3f0)) push!(axis_vis, grid) end - if alpha(xaxis[:foreground_color_border]) > 0 - spine = draw_grid_lines(sp, spine_segs, 1f0, :solid, model, RGBA(c, 1.0f0)) + if !(yaxis[:grid] in (nothing, false)) + grid = draw_grid_lines(sp, ygrid_segs, 1f0, :dot, model, RGBA(ygc, 0.3f0)) + push!(axis_vis, grid) + end + + xac = Colors.color(Plots.gl_color(xaxis[:foreground_color_axis])) + yac = Colors.color(Plots.gl_color(yaxis[:foreground_color_axis])) + if alpha(xaxis[:foreground_color_axis]) > 0 + spine = draw_grid_lines(sp, xspine_segs, 1f0, :solid, model, RGBA(xac, 1.0f0)) + push!(axis_vis, spine) + end + if alpha(yaxis[:foreground_color_axis]) > 0 + spine = draw_grid_lines(sp, yspine_segs, 1f0, :solid, model, RGBA(yac, 1.0f0)) push!(axis_vis, spine) end fcolor = Plots.gl_color(xaxis[:foreground_color_axis]) diff --git a/src/backends/gr.jl b/src/backends/gr.jl index e2e42a26..a0a9171d 100644 --- a/src/backends/gr.jl +++ b/src/backends/gr.jl @@ -691,10 +691,15 @@ function gr_display(sp::Subplot{GRBackend}, w, h, viewport_canvas) ticksize = 0.01 * (viewport_plotarea[2] - viewport_plotarea[1]) # GR.setlinetype(GR.LINETYPE_DOTTED) - # if sp[:grid] - GR.grid3d(xtick, 0, ztick, xmin, ymax, zmin, 2, 0, 2) - GR.grid3d(0, ytick, 0, xmin, ymax, zmin, 0, 2, 0) - # end + if !(xaxis[:grid] in (nothing, false)) + GR.grid3d(xtick, 0, 0, xmin, ymax, zmin, 2, 0, 0) + end + if !(yaxis[:grid] in (nothing, false)) + GR.grid3d(0, ytick, 0, xmin, ymax, zmin, 0, 2, 0) + end + if !(zaxis[:grid] in (nothing, false)) + GR.grid3d(0, 0, ztick, xmin, ymax, zmin, 0, 0, 2) + end GR.axes3d(xtick, 0, ztick, xmin, ymin, zmin, 2, 0, 2, -ticksize) GR.axes3d(0, ytick, 0, xmax, ymin, zmin, 0, 2, 0, ticksize) diff --git a/src/backends/inspectdr.jl b/src/backends/inspectdr.jl index d7ef859c..1feda4ba 100644 --- a/src/backends/inspectdr.jl +++ b/src/backends/inspectdr.jl @@ -18,7 +18,8 @@ Add in functionality to Plots.jl: const _inspectdr_attr = merge_with_base_supported([ :annotations, :background_color_legend, :background_color_inside, :background_color_outside, - :foreground_color_grid, :foreground_color_legend, :foreground_color_title, + # :foreground_color_grid, + :foreground_color_legend, :foreground_color_title, :foreground_color_axis, :foreground_color_border, :foreground_color_guide, :foreground_color_text, :label, :linecolor, :linestyle, :linewidth, :linealpha, @@ -334,15 +335,18 @@ end # --------------------------------------------------------------------------- function _inspectdr_setupsubplot(sp::Subplot{InspectDRBackend}) - const gridon = InspectDR.GridRect(vmajor=true, hmajor=true) - const gridoff = InspectDR.GridRect() const plot = sp.o const strip = plot.strips[1] #Only 1 strip supported with Plots.jl - #No independent control of grid??? - strip.grid = sp[:grid]? gridon: gridoff - xaxis = sp[:xaxis]; yaxis = sp[:yaxis] + xgrid_show = !(xaxis[:grid] in (nothing, false)) + ygrid_show = !(yaxis[:grid] in (nothing, false)) + + strip.grid = InspectDR.GridRect( + vmajor=xgrid_show, # vminor=xgrid_show, + hmajor=ygrid_show, # hminor=ygrid_show, + ) + plot.xscale = _inspectdr_getscale(xaxis[:scale], false) strip.yscale = _inspectdr_getscale(yaxis[:scale], true) xmin, xmax = axis_limits(xaxis) diff --git a/src/backends/pgfplots.jl b/src/backends/pgfplots.jl index c44c10ae..cbbd645b 100644 --- a/src/backends/pgfplots.jl +++ b/src/backends/pgfplots.jl @@ -98,7 +98,7 @@ const _pgf_series_extrastyle = KW( :xsticks => "xcomb", ) -# PGFPlots uses the anchors to define orientations for example to align left +# PGFPlots uses the anchors to define orientations for example to align left # one needs to use the right edge as anchor const _pgf_annotation_halign = KW( :center => "", @@ -121,7 +121,7 @@ function pgf_color(grad::ColorGradient) end # Generates a colormap for pgfplots based on a ColorGradient -function pgf_colormap(grad::ColorGradient) +function pgf_colormap(grad::ColorGradient) join(map(grad.colors) do c @sprintf("rgb=(%.8f,%.8f,%.8f)", red(c), green(c),blue(c)) end,", ") @@ -266,6 +266,11 @@ function pgf_axis(sp::Subplot, letter) push!(style, "$(letter)majorticks=false") end + # grid on or off + if !(axis[:grid] in (nothing, false)) + push!(style, "$(letter)majorgrids = true") + end + # limits # TODO: support zlims if letter != :z @@ -324,7 +329,6 @@ function _update_plot_object(plt::Plot{PGFPlotsBackend}) kw[:title] = "$(sp[:title])" end - sp[:grid] && push!(style, "grid = major") if sp[:aspect_ratio] in (1, :equal) kw[:axisEqual] = "true" end @@ -360,7 +364,7 @@ function _update_plot_object(plt::Plot{PGFPlotsBackend}) kw[:colorbar] = "true" end # goto is needed to break out of col and series for - @goto colorbar_end + @goto colorbar_end end end end diff --git a/src/backends/plotly.jl b/src/backends/plotly.jl index 0a1e25aa..d558d941 100644 --- a/src/backends/plotly.jl +++ b/src/backends/plotly.jl @@ -5,8 +5,7 @@ const _plotly_attr = merge_with_base_supported([ :annotations, :background_color_legend, :background_color_inside, :background_color_outside, :foreground_color_legend, :foreground_color_guide, - :foreground_color_grid, - # :foreground_color_axis, + :foreground_color_grid, :foreground_color_axis, :foreground_color_text, :foreground_color_border, :foreground_color_title, :label, @@ -214,6 +213,7 @@ function plotly_axis(axis::Axis, sp::Subplot) letter = axis[:letter] ax = KW( :title => axis[:guide], + :gridcolor => rgba_string(axis[:foreground_color_grid]), :showgrid => !(axis[:grid] in (nothing, false)), :zeroline => false, :ticks => "inside", @@ -230,8 +230,8 @@ function plotly_axis(axis::Axis, sp::Subplot) ax[:titlefont] = plotly_font(axis[:guidefont], axis[:foreground_color_guide]) ax[:type] = plotly_scale(axis[:scale]) ax[:tickfont] = plotly_font(axis[:tickfont], axis[:foreground_color_text]) - ax[:tickcolor] = rgba_string(axis[:foreground_color_border]) - ax[:linecolor] = rgba_string(axis[:foreground_color_grid]) + ax[:tickcolor] = rgba_string(axis[:foreground_color_axis]) + ax[:linecolor] = rgba_string(axis[:foreground_color_axis]) # lims lims = axis[:lims]