make it work on all backends

This commit is contained in:
Daniel Schwabeneder 2017-08-10 20:49:03 +02:00
parent c60d66d94a
commit 2dd99d053a
5 changed files with 49 additions and 24 deletions

View File

@ -676,17 +676,29 @@ function text_model(font, pivot)
end end
end end
function gl_draw_axes_2d(sp::Plots.Subplot{Plots.GLVisualizeBackend}, model, area) 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] 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 = [] axis_vis = []
if sp[:grid] if !(xaxis[:grid] in (nothing, false))
grid = draw_grid_lines(sp, grid_segs, 1f0, :dot, model, RGBA(c, 0.3f0)) grid = draw_grid_lines(sp, xgrid_segs, 1f0, :dot, model, RGBA(xgc, 0.3f0))
push!(axis_vis, grid) push!(axis_vis, grid)
end end
if alpha(xaxis[:foreground_color_border]) > 0 if !(yaxis[:grid] in (nothing, false))
spine = draw_grid_lines(sp, spine_segs, 1f0, :solid, model, RGBA(c, 1.0f0)) 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) push!(axis_vis, spine)
end end
fcolor = Plots.gl_color(xaxis[:foreground_color_axis]) fcolor = Plots.gl_color(xaxis[:foreground_color_axis])

View File

@ -691,10 +691,15 @@ function gr_display(sp::Subplot{GRBackend}, w, h, viewport_canvas)
ticksize = 0.01 * (viewport_plotarea[2] - viewport_plotarea[1]) ticksize = 0.01 * (viewport_plotarea[2] - viewport_plotarea[1])
# GR.setlinetype(GR.LINETYPE_DOTTED) # GR.setlinetype(GR.LINETYPE_DOTTED)
# if sp[:grid] if !(xaxis[:grid] in (nothing, false))
GR.grid3d(xtick, 0, ztick, xmin, ymax, zmin, 2, 0, 2) GR.grid3d(xtick, 0, 0, xmin, ymax, zmin, 2, 0, 0)
GR.grid3d(0, ytick, 0, xmin, ymax, zmin, 0, 2, 0) end
# 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(xtick, 0, ztick, xmin, ymin, zmin, 2, 0, 2, -ticksize)
GR.axes3d(0, ytick, 0, xmax, ymin, zmin, 0, 2, 0, ticksize) GR.axes3d(0, ytick, 0, xmax, ymin, zmin, 0, 2, 0, ticksize)

View File

@ -18,7 +18,8 @@ Add in functionality to Plots.jl:
const _inspectdr_attr = merge_with_base_supported([ const _inspectdr_attr = merge_with_base_supported([
:annotations, :annotations,
:background_color_legend, :background_color_inside, :background_color_outside, :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, :foreground_color_axis, :foreground_color_border, :foreground_color_guide, :foreground_color_text,
:label, :label,
:linecolor, :linestyle, :linewidth, :linealpha, :linecolor, :linestyle, :linewidth, :linealpha,
@ -334,15 +335,18 @@ end
# --------------------------------------------------------------------------- # ---------------------------------------------------------------------------
function _inspectdr_setupsubplot(sp::Subplot{InspectDRBackend}) function _inspectdr_setupsubplot(sp::Subplot{InspectDRBackend})
const gridon = InspectDR.GridRect(vmajor=true, hmajor=true)
const gridoff = InspectDR.GridRect()
const plot = sp.o const plot = sp.o
const strip = plot.strips[1] #Only 1 strip supported with Plots.jl 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] 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) plot.xscale = _inspectdr_getscale(xaxis[:scale], false)
strip.yscale = _inspectdr_getscale(yaxis[:scale], true) strip.yscale = _inspectdr_getscale(yaxis[:scale], true)
xmin, xmax = axis_limits(xaxis) xmin, xmax = axis_limits(xaxis)

View File

@ -266,6 +266,11 @@ function pgf_axis(sp::Subplot, letter)
push!(style, "$(letter)majorticks=false") push!(style, "$(letter)majorticks=false")
end end
# grid on or off
if !(axis[:grid] in (nothing, false))
push!(style, "$(letter)majorgrids = true")
end
# limits # limits
# TODO: support zlims # TODO: support zlims
if letter != :z if letter != :z
@ -324,7 +329,6 @@ function _update_plot_object(plt::Plot{PGFPlotsBackend})
kw[:title] = "$(sp[:title])" kw[:title] = "$(sp[:title])"
end end
sp[:grid] && push!(style, "grid = major")
if sp[:aspect_ratio] in (1, :equal) if sp[:aspect_ratio] in (1, :equal)
kw[:axisEqual] = "true" kw[:axisEqual] = "true"
end end

View File

@ -5,8 +5,7 @@ const _plotly_attr = merge_with_base_supported([
:annotations, :annotations,
:background_color_legend, :background_color_inside, :background_color_outside, :background_color_legend, :background_color_inside, :background_color_outside,
:foreground_color_legend, :foreground_color_guide, :foreground_color_legend, :foreground_color_guide,
:foreground_color_grid, :foreground_color_grid, :foreground_color_axis,
# :foreground_color_axis,
:foreground_color_text, :foreground_color_border, :foreground_color_text, :foreground_color_border,
:foreground_color_title, :foreground_color_title,
:label, :label,
@ -214,6 +213,7 @@ function plotly_axis(axis::Axis, sp::Subplot)
letter = axis[:letter] letter = axis[:letter]
ax = KW( ax = KW(
:title => axis[:guide], :title => axis[:guide],
:gridcolor => rgba_string(axis[:foreground_color_grid]),
:showgrid => !(axis[:grid] in (nothing, false)), :showgrid => !(axis[:grid] in (nothing, false)),
:zeroline => false, :zeroline => false,
:ticks => "inside", :ticks => "inside",
@ -230,8 +230,8 @@ function plotly_axis(axis::Axis, sp::Subplot)
ax[:titlefont] = plotly_font(axis[:guidefont], axis[:foreground_color_guide]) ax[:titlefont] = plotly_font(axis[:guidefont], axis[:foreground_color_guide])
ax[:type] = plotly_scale(axis[:scale]) ax[:type] = plotly_scale(axis[:scale])
ax[:tickfont] = plotly_font(axis[:tickfont], axis[:foreground_color_text]) ax[:tickfont] = plotly_font(axis[:tickfont], axis[:foreground_color_text])
ax[:tickcolor] = rgba_string(axis[:foreground_color_border]) ax[:tickcolor] = rgba_string(axis[:foreground_color_axis])
ax[:linecolor] = rgba_string(axis[:foreground_color_grid]) ax[:linecolor] = rgba_string(axis[:foreground_color_axis])
# lims # lims
lims = axis[:lims] lims = axis[:lims]