make it work for gr, pyplot and plotly(js)
This commit is contained in:
parent
6b814b8dca
commit
c60d66d94a
@ -943,7 +943,6 @@ const _match_map = KW(
|
|||||||
:background_color_legend => :background_color_subplot,
|
:background_color_legend => :background_color_subplot,
|
||||||
:background_color_inside => :background_color_subplot,
|
:background_color_inside => :background_color_subplot,
|
||||||
:foreground_color_legend => :foreground_color_subplot,
|
:foreground_color_legend => :foreground_color_subplot,
|
||||||
:foreground_color_grid => :foreground_color_subplot,
|
|
||||||
:foreground_color_title => :foreground_color_subplot,
|
:foreground_color_title => :foreground_color_subplot,
|
||||||
:left_margin => :margin,
|
:left_margin => :margin,
|
||||||
:top_margin => :margin,
|
:top_margin => :margin,
|
||||||
@ -957,6 +956,7 @@ const _match_map2 = KW(
|
|||||||
:foreground_color_subplot => :foreground_color,
|
:foreground_color_subplot => :foreground_color,
|
||||||
:foreground_color_axis => :foreground_color_subplot,
|
:foreground_color_axis => :foreground_color_subplot,
|
||||||
:foreground_color_border => :foreground_color_subplot,
|
:foreground_color_border => :foreground_color_subplot,
|
||||||
|
:foreground_color_grid => :foreground_color_subplot,
|
||||||
:foreground_color_guide => :foreground_color_subplot,
|
:foreground_color_guide => :foreground_color_subplot,
|
||||||
:foreground_color_text => :foreground_color_subplot,
|
:foreground_color_text => :foreground_color_subplot,
|
||||||
)
|
)
|
||||||
@ -1091,7 +1091,6 @@ function _update_subplot_colors(sp::Subplot)
|
|||||||
# foreground colors
|
# foreground colors
|
||||||
color_or_nothing!(sp.attr, :foreground_color_subplot)
|
color_or_nothing!(sp.attr, :foreground_color_subplot)
|
||||||
color_or_nothing!(sp.attr, :foreground_color_legend)
|
color_or_nothing!(sp.attr, :foreground_color_legend)
|
||||||
color_or_nothing!(sp.attr, :foreground_color_grid)
|
|
||||||
color_or_nothing!(sp.attr, :foreground_color_title)
|
color_or_nothing!(sp.attr, :foreground_color_title)
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
@ -1143,6 +1142,7 @@ function _update_axis_colors(axis::Axis)
|
|||||||
color_or_nothing!(axis.d, :foreground_color_border)
|
color_or_nothing!(axis.d, :foreground_color_border)
|
||||||
color_or_nothing!(axis.d, :foreground_color_guide)
|
color_or_nothing!(axis.d, :foreground_color_guide)
|
||||||
color_or_nothing!(axis.d, :foreground_color_text)
|
color_or_nothing!(axis.d, :foreground_color_text)
|
||||||
|
color_or_nothing!(axis.d, :foreground_color_grid)
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
58
src/axes.jl
58
src/axes.jl
@ -490,38 +490,50 @@ function axis_drawing_info(sp::Subplot)
|
|||||||
ymin, ymax = axis_limits(yaxis)
|
ymin, ymax = axis_limits(yaxis)
|
||||||
xticks = get_ticks(xaxis)
|
xticks = get_ticks(xaxis)
|
||||||
yticks = get_ticks(yaxis)
|
yticks = get_ticks(yaxis)
|
||||||
spine_segs = Segments(2)
|
xspine_segs = Segments(2)
|
||||||
grid_segs = Segments(2)
|
yspine_segs = Segments(2)
|
||||||
|
xgrid_segs = Segments(2)
|
||||||
|
ygrid_segs = Segments(2)
|
||||||
|
|
||||||
|
f = scalefunc(yaxis[:scale])
|
||||||
|
invf = invscalefunc(yaxis[:scale])
|
||||||
|
t1 = invf(f(ymin) + 0.015*(f(ymax)-f(ymin)))
|
||||||
|
t2 = invf(f(ymax) - 0.015*(f(ymax)-f(ymin)))
|
||||||
|
|
||||||
if !(xaxis[:ticks] in (nothing, false))
|
if !(xaxis[:ticks] in (nothing, false))
|
||||||
f = scalefunc(yaxis[:scale])
|
push!(xspine_segs, (xmin,ymin), (xmax,ymin)) # bottom spine
|
||||||
invf = invscalefunc(yaxis[:scale])
|
# push!(xspine_segs, (xmin,ymax), (xmax,ymax)) # top spine
|
||||||
t1 = invf(f(ymin) + 0.015*(f(ymax)-f(ymin)))
|
|
||||||
t2 = invf(f(ymax) - 0.015*(f(ymax)-f(ymin)))
|
|
||||||
|
|
||||||
push!(spine_segs, (xmin,ymin), (xmax,ymin)) # bottom spine
|
|
||||||
# push!(spine_segs, (xmin,ymax), (xmax,ymax)) # top spine
|
|
||||||
for xtick in xticks[1]
|
for xtick in xticks[1]
|
||||||
push!(spine_segs, (xtick, ymin), (xtick, t1)) # bottom tick
|
push!(xspine_segs, (xtick, ymin), (xtick, t1)) # bottom tick
|
||||||
push!(grid_segs, (xtick, t1), (xtick, t2)) # vertical grid
|
# push!(xspine_segs, (xtick, ymax), (xtick, t2)) # top tick
|
||||||
# push!(spine_segs, (xtick, ymax), (xtick, t2)) # top tick
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if !(xaxis[:grid] in (nothing, false))
|
||||||
|
for xtick in xticks[1]
|
||||||
|
push!(xgrid_segs, (xtick, t1), (xtick, t2)) # vertical grid
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
f = scalefunc(xaxis[:scale])
|
||||||
|
invf = invscalefunc(xaxis[:scale])
|
||||||
|
t1 = invf(f(xmin) + 0.015*(f(xmax)-f(xmin)))
|
||||||
|
t2 = invf(f(xmax) - 0.015*(f(xmax)-f(xmin)))
|
||||||
|
|
||||||
if !(yaxis[:ticks] in (nothing, false))
|
if !(yaxis[:ticks] in (nothing, false))
|
||||||
f = scalefunc(xaxis[:scale])
|
push!(yspine_segs, (xmin,ymin), (xmin,ymax)) # left spine
|
||||||
invf = invscalefunc(xaxis[:scale])
|
# push!(yspine_segs, (xmax,ymin), (xmax,ymax)) # right spine
|
||||||
t1 = invf(f(xmin) + 0.015*(f(xmax)-f(xmin)))
|
|
||||||
t2 = invf(f(xmax) - 0.015*(f(xmax)-f(xmin)))
|
|
||||||
|
|
||||||
push!(spine_segs, (xmin,ymin), (xmin,ymax)) # left spine
|
|
||||||
# push!(spine_segs, (xmax,ymin), (xmax,ymax)) # right spine
|
|
||||||
for ytick in yticks[1]
|
for ytick in yticks[1]
|
||||||
push!(spine_segs, (xmin, ytick), (t1, ytick)) # left tick
|
push!(yspine_segs, (xmin, ytick), (t1, ytick)) # left tick
|
||||||
push!(grid_segs, (t1, ytick), (t2, ytick)) # horizontal grid
|
# push!(yspine_segs, (xmax, ytick), (t2, ytick)) # right tick
|
||||||
# push!(spine_segs, (xmax, ytick), (t2, ytick)) # right tick
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
xticks, yticks, spine_segs, grid_segs
|
if !(yaxis[:grid] in (nothing, false))
|
||||||
|
for ytick in yticks[1]
|
||||||
|
push!(ygrid_segs, (t1, ytick), (t2, ytick)) # horizontal grid
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
xticks, yticks, xspine_segs, yspine_segs, xgrid_segs, ygrid_segs
|
||||||
end
|
end
|
||||||
|
|||||||
@ -691,10 +691,10 @@ 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 sp[:grid]
|
||||||
GR.grid3d(xtick, 0, ztick, xmin, ymax, zmin, 2, 0, 2)
|
GR.grid3d(xtick, 0, ztick, xmin, ymax, zmin, 2, 0, 2)
|
||||||
GR.grid3d(0, ytick, 0, xmin, ymax, zmin, 0, 2, 0)
|
GR.grid3d(0, ytick, 0, xmin, ymax, zmin, 0, 2, 0)
|
||||||
end
|
# 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)
|
||||||
|
|
||||||
@ -709,23 +709,31 @@ function gr_display(sp::Subplot{GRBackend}, w, h, viewport_canvas)
|
|||||||
GR.setwindow(xmin, xmax, ymin, ymax)
|
GR.setwindow(xmin, xmax, ymin, ymax)
|
||||||
end
|
end
|
||||||
|
|
||||||
xticks, yticks, spine_segs, grid_segs = axis_drawing_info(sp)
|
xticks, yticks, xspine_segs, yspine_segs, xgrid_segs, ygrid_segs = axis_drawing_info(sp)
|
||||||
# @show xticks yticks #spine_segs grid_segs
|
# @show xticks yticks #spine_segs grid_segs
|
||||||
|
|
||||||
# draw the grid lines
|
# draw the grid lines
|
||||||
if sp[:grid]
|
if !(xaxis[:grid] in (nothing, false))
|
||||||
# gr_set_linecolor(sp[:foreground_color_grid])
|
# gr_set_linecolor(sp[:foreground_color_grid])
|
||||||
# GR.grid(xtick, ytick, 0, 0, majorx, majory)
|
# GR.grid(xtick, ytick, 0, 0, majorx, majory)
|
||||||
gr_set_line(1, :dot, sp[:foreground_color_grid])
|
gr_set_line(1, :dot, xaxis[:foreground_color_grid])
|
||||||
GR.settransparency(0.5)
|
GR.settransparency(0.5)
|
||||||
gr_polyline(coords(grid_segs)...)
|
gr_polyline(coords(xgrid_segs)...)
|
||||||
|
end
|
||||||
|
if !(yaxis[:grid] in (nothing, false))
|
||||||
|
gr_set_line(1, :dot, yaxis[:foreground_color_grid])
|
||||||
|
GR.settransparency(0.5)
|
||||||
|
gr_polyline(coords(ygrid_segs)...)
|
||||||
end
|
end
|
||||||
GR.settransparency(1.0)
|
GR.settransparency(1.0)
|
||||||
|
|
||||||
# spine (border) and tick marks
|
# spine (border) and tick marks
|
||||||
gr_set_line(1, :solid, sp[:xaxis][:foreground_color_axis])
|
gr_set_line(1, :solid, xaxis[:foreground_color_axis])
|
||||||
GR.setclip(0)
|
GR.setclip(0)
|
||||||
gr_polyline(coords(spine_segs)...)
|
gr_polyline(coords(xspine_segs)...)
|
||||||
|
gr_set_line(1, :solid, yaxis[:foreground_color_axis])
|
||||||
|
GR.setclip(0)
|
||||||
|
gr_polyline(coords(yspine_segs)...)
|
||||||
GR.setclip(1)
|
GR.setclip(1)
|
||||||
|
|
||||||
if !(xticks in (nothing, false))
|
if !(xticks in (nothing, false))
|
||||||
|
|||||||
@ -5,7 +5,8 @@ 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_axis,
|
:foreground_color_grid,
|
||||||
|
# :foreground_color_axis,
|
||||||
:foreground_color_text, :foreground_color_border,
|
:foreground_color_text, :foreground_color_border,
|
||||||
:foreground_color_title,
|
:foreground_color_title,
|
||||||
:label,
|
:label,
|
||||||
@ -213,7 +214,7 @@ function plotly_axis(axis::Axis, sp::Subplot)
|
|||||||
letter = axis[:letter]
|
letter = axis[:letter]
|
||||||
ax = KW(
|
ax = KW(
|
||||||
:title => axis[:guide],
|
:title => axis[:guide],
|
||||||
:showgrid => sp[:grid],
|
:showgrid => !(axis[:grid] in (nothing, false)),
|
||||||
:zeroline => false,
|
:zeroline => false,
|
||||||
:ticks => "inside",
|
:ticks => "inside",
|
||||||
)
|
)
|
||||||
@ -230,7 +231,7 @@ function plotly_axis(axis::Axis, sp::Subplot)
|
|||||||
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_border])
|
||||||
ax[:linecolor] = rgba_string(axis[:foreground_color_border])
|
ax[:linecolor] = rgba_string(axis[:foreground_color_grid])
|
||||||
|
|
||||||
# lims
|
# lims
|
||||||
lims = axis[:lims]
|
lims = axis[:lims]
|
||||||
|
|||||||
@ -1064,8 +1064,8 @@ function _before_layout_calcs(plt::Plot{PyPlotBackend})
|
|||||||
lab[:set_family](axis[:tickfont].family)
|
lab[:set_family](axis[:tickfont].family)
|
||||||
lab[:set_rotation](axis[:rotation])
|
lab[:set_rotation](axis[:rotation])
|
||||||
end
|
end
|
||||||
if sp[:grid]
|
if !(axis[:grid] in (nothing, false))
|
||||||
fgcolor = py_color(sp[:foreground_color_grid])
|
fgcolor = py_color(axis[:foreground_color_grid])
|
||||||
pyaxis[:grid](true, color = fgcolor, linestyle = ":")
|
pyaxis[:grid](true, color = fgcolor, linestyle = ":")
|
||||||
ax[:set_axisbelow](true)
|
ax[:set_axisbelow](true)
|
||||||
end
|
end
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user