some noinlines

This commit is contained in:
Chris Rackauckas 2019-08-24 00:59:19 -04:00
parent 122a470078
commit 3310025602

View File

@ -74,15 +74,15 @@ const gr_font_family = Dict{String,Int}(
convert(Int, GR.inqcolorfromrgb(red(c), green(c), blue(c))) convert(Int, GR.inqcolorfromrgb(red(c), green(c), blue(c)))
end end
gr_set_linecolor(c) = GR.setlinecolorind(gr_getcolorind(_cycle(c,1))) @noinline gr_set_linecolor(c) = GR.setlinecolorind(gr_getcolorind(_cycle(c,1)))
gr_set_fillcolor(c) = GR.setfillcolorind(gr_getcolorind(_cycle(c,1))) @noinline gr_set_fillcolor(c) = GR.setfillcolorind(gr_getcolorind(_cycle(c,1)))
gr_set_markercolor(c) = GR.setmarkercolorind(gr_getcolorind(_cycle(c,1))) @noinline gr_set_markercolor(c) = GR.setmarkercolorind(gr_getcolorind(_cycle(c,1)))
gr_set_textcolor(c) = GR.settextcolorind(gr_getcolorind(_cycle(c,1))) @noinline gr_set_textcolor(c) = GR.settextcolorind(gr_getcolorind(_cycle(c,1)))
gr_set_transparency(α::Real) = GR.settransparency(clamp(α, 0, 1)) @noinline gr_set_transparency(α::Real) = GR.settransparency(clamp(α, 0, 1))
gr_set_transparency(::Nothing) = GR.settransparency(1) @noinline gr_set_transparency(::Nothing) = GR.settransparency(1)
gr_set_transparency(c, α) = gr_set_transparency(α) @noinline gr_set_transparency(c, α) = gr_set_transparency(α)
gr_set_transparency(c::Colorant, ::Nothing) = gr_set_transparency(c) @noinline gr_set_transparency(c::Colorant, ::Nothing) = gr_set_transparency(c)
gr_set_transparency(c::Colorant) = GR.settransparency(alpha(c)) @noinline gr_set_transparency(c::Colorant) = GR.settransparency(alpha(c))
const _gr_arrow_map = Dict{Symbol,Int}( const _gr_arrow_map = Dict{Symbol,Int}(
:simple => 1, :simple => 1,
@ -93,7 +93,7 @@ const _gr_arrow_map = Dict{Symbol,Int}(
:closed => 6, :closed => 6,
:open => 5, :open => 5,
) )
gr_set_arrowstyle(s::Symbol) = GR.setarrowstyle(get(_gr_arrow_map, s, 1)) @noinline gr_set_arrowstyle(s::Symbol) = GR.setarrowstyle(get(_gr_arrow_map, s, 1))
# -------------------------------------------------------------------------------------- # --------------------------------------------------------------------------------------
@ -142,7 +142,7 @@ function gr_polyline(x, y, func = GR.polyline; arrowside = :none, arrowstyle = :
end end
end end
gr_inqtext(x, y, s::Symbol) = gr_inqtext(x, y, string(s)) @noinline gr_inqtext(x, y, s::Symbol) = gr_inqtext(x, y, string(s))
@noinline function gr_inqtext(x, y, s) @noinline function gr_inqtext(x, y, s)
if length(s) >= 2 && s[1] == '$' && s[end] == '$' if length(s) >= 2 && s[1] == '$' && s[end] == '$'
@ -154,7 +154,7 @@ gr_inqtext(x, y, s::Symbol) = gr_inqtext(x, y, string(s))
end end
end end
gr_text(x, y, s::Symbol) = gr_text(x, y, string(s)) @noinline gr_text(x, y, s::Symbol) = gr_text(x, y, string(s))
@noinline function gr_text(x, y, s) @noinline function gr_text(x, y, s)
if length(s) >= 2 && s[1] == '$' && s[end] == '$' if length(s) >= 2 && s[1] == '$' && s[end] == '$'
@ -382,7 +382,7 @@ const gr_plot_size = [600.0, 400.0]
const gr_colorbar_ratio = 0.1 const gr_colorbar_ratio = 0.1
function gr_viewport_from_bbox(sp::Subplot{GRBackend}, bb::BoundingBox, w, h, viewport_canvas) @noinline function gr_viewport_from_bbox(sp::Subplot{GRBackend}, bb::BoundingBox, w, h, viewport_canvas)
viewport = zeros(4) viewport = zeros(4)
viewport[1] = viewport_canvas[2] * (left(bb) / w) viewport[1] = viewport_canvas[2] * (left(bb) / w)
viewport[2] = viewport_canvas[2] * (right(bb) / w) viewport[2] = viewport_canvas[2] * (right(bb) / w)
@ -423,7 +423,7 @@ end
end end
@noinline function gr_set_viewport_polar() @noinline function gr_set_viewport_polar()
xmin, xmax, ymin, ymax = viewport_plotarea xmin::Float64, xmax::Float64, ymin::Float64, ymax::Float64 = viewport_plotarea
ymax -= 0.05 * (xmax - xmin) ymax -= 0.05 * (xmax - xmin)
xcenter = 0.5 * (xmin + xmax) xcenter = 0.5 * (xmin + xmax)
ycenter = 0.5 * (ymin + ymax) ycenter = 0.5 * (ymin + ymax)
@ -459,7 +459,7 @@ end
levels levels
end end
function gr_colorbar_colors(series::Series, clims)::Vector{Int} @noinline function gr_colorbar_colors(series::Series, clims)::Vector{Int}
if iscontour(series) if iscontour(series)
levels = gr_contour_levels(series, clims) levels = gr_contour_levels(series, clims)
if isfilledcontour(series) if isfilledcontour(series)
@ -556,6 +556,8 @@ function gr_legend_pos(sp::Subplot, w, h)
s = sp[:legend] s = sp[:legend]
typeof(s) <: Symbol || return gr_legend_pos(s, w, h) typeof(s) <: Symbol || return gr_legend_pos(s, w, h)
str = string(s) str = string(s)
xpos::Float64 = 0.0
ypos::Float64 = 0.0
if str == "best" if str == "best"
str = "topright" str = "topright"
end end
@ -599,8 +601,8 @@ function gr_legend_pos(sp::Subplot, w, h)
end end
@noinline function gr_legend_pos(v::Tuple{S,T},w,h) where {S<:Real, T<:Real} @noinline function gr_legend_pos(v::Tuple{S,T},w,h) where {S<:Real, T<:Real}
xpos = v[1] * (viewport_plotarea[2] - viewport_plotarea[1]) + viewport_plotarea[1] xpos::Float64 = v[1] * (viewport_plotarea[2] - viewport_plotarea[1]) + viewport_plotarea[1]
ypos = v[2] * (viewport_plotarea[4] - viewport_plotarea[3]) + viewport_plotarea[3] ypos::Float64 = v[2] * (viewport_plotarea[4] - viewport_plotarea[3]) + viewport_plotarea[3]
(xpos,ypos) (xpos,ypos)
end end
@ -623,7 +625,7 @@ end
color !== nothing && gr_set_gradient(color) color !== nothing && gr_set_gradient(color)
end end
function gr_get_color(series::Series) @noinline function gr_get_color(series::Series)
st = series[:seriestype] st = series[:seriestype]
if st in (:surface, :heatmap) || isfilledcontour(series) if st in (:surface, :heatmap) || isfilledcontour(series)
series[:fillcolor] series[:fillcolor]
@ -689,7 +691,7 @@ function gr_display(plt::Plot, fmt="")
end end
function gr_set_xticks_font(sp) @noinline function gr_set_xticks_font(sp)
flip = sp[:yaxis][:flip] flip = sp[:yaxis][:flip]
mirror = sp[:xaxis][:mirror] mirror = sp[:xaxis][:mirror]
gr_set_font(tickfont(sp[:xaxis]), gr_set_font(tickfont(sp[:xaxis]),
@ -700,7 +702,7 @@ function gr_set_xticks_font(sp)
end end
function gr_set_yticks_font(sp) @noinline function gr_set_yticks_font(sp)
flip = sp[:xaxis][:flip] flip = sp[:xaxis][:flip]
mirror = sp[:yaxis][:mirror] mirror = sp[:yaxis][:mirror]
gr_set_font(tickfont(sp[:yaxis]), gr_set_font(tickfont(sp[:yaxis]),
@ -710,7 +712,7 @@ function gr_set_yticks_font(sp)
return flip, mirror return flip, mirror
end end
function gr_text_size(str) @noinline function gr_text_size(str)
GR.savestate() GR.savestate()
GR.selntran(0) GR.selntran(0)
xs, ys = gr_inqtext(0, 0, string(str)) xs, ys = gr_inqtext(0, 0, string(str))
@ -722,7 +724,7 @@ function gr_text_size(str)
return w, h return w, h
end end
function gr_text_size(str, rot) @noinline function gr_text_size(str, rot)
GR.savestate() GR.savestate()
GR.selntran(0) GR.selntran(0)
xs, ys = gr_inqtext(0, 0, string(str)) xs, ys = gr_inqtext(0, 0, string(str))
@ -737,7 +739,7 @@ end
@noinline text_box_width(w, h, rot) = abs(cosd(rot)) * w + abs(cosd(rot + 90)) * h @noinline text_box_width(w, h, rot) = abs(cosd(rot)) * w + abs(cosd(rot + 90)) * h
@noinline text_box_height(w, h, rot) = abs(sind(rot)) * w + abs(sind(rot + 90)) * h @noinline text_box_height(w, h, rot) = abs(sind(rot)) * w + abs(sind(rot + 90)) * h
function gr_get_ticks_size(ticks, rot) @noinline function gr_get_ticks_size(ticks, rot)
w, h = 0.0, 0.0 w, h = 0.0, 0.0
for (cv, dv) in zip(ticks...) for (cv, dv) in zip(ticks...)
wi, hi = gr_text_size(dv, rot) wi, hi = gr_text_size(dv, rot)
@ -747,7 +749,7 @@ function gr_get_ticks_size(ticks, rot)
return w, h return w, h
end end
function gr_xaxis_height(sp) @noinline function gr_xaxis_height(sp)
xaxis = sp[:xaxis] xaxis = sp[:xaxis]
xticks, yticks = axis_drawing_info(sp)[1:2] xticks, yticks = axis_drawing_info(sp)[1:2]
gr_set_font(tickfont(xaxis)) gr_set_font(tickfont(xaxis))
@ -759,7 +761,7 @@ function gr_xaxis_height(sp)
return h return h
end end
function gr_yaxis_width(sp) @noinline function gr_yaxis_width(sp)
yaxis = sp[:yaxis] yaxis = sp[:yaxis]
xticks, yticks = axis_drawing_info(sp)[1:2] xticks, yticks = axis_drawing_info(sp)[1:2]
gr_set_font(tickfont(yaxis)) gr_set_font(tickfont(yaxis))
@ -779,10 +781,10 @@ function _update_min_padding!(sp::Subplot{GRBackend})
end end
end end
# Add margin given by the user # Add margin given by the user
leftpad = 2mm + sp[:left_margin] leftpad::AbsoluteLength = 2mm + sp[:left_margin]
toppad = 2mm + sp[:top_margin] toppad::AbsoluteLength = 2mm + sp[:top_margin]
rightpad = 2mm + sp[:right_margin] rightpad::AbsoluteLength = 2mm + sp[:right_margin]
bottompad = 2mm + sp[:bottom_margin] bottompad::AbsoluteLength = 2mm + sp[:bottom_margin]
# Add margin for title # Add margin for title
if sp[:title] != "" if sp[:title] != ""
gr_set_font(titlefont(sp)) gr_set_font(titlefont(sp))
@ -853,6 +855,7 @@ function gr_display(sp::Subplot{GRBackend}, w, h, viewport_canvas)
ratio = sp[:aspect_ratio] ratio = sp[:aspect_ratio]
if ratio != :none if ratio != :none
(function ()
if ratio == :equal if ratio == :equal
ratio = 1 ratio = 1
end end
@ -869,14 +872,16 @@ function gr_display(sp::Subplot{GRBackend}, w, h, viewport_canvas)
viewport_plotarea[3] = viewport_center - 0.5 * viewport_size viewport_plotarea[3] = viewport_center - 0.5 * viewport_size
viewport_plotarea[4] = viewport_center + 0.5 * viewport_size viewport_plotarea[4] = viewport_center + 0.5 * viewport_size
end end
end)()
end end
# calculate legend size # calculate legend size
# has to be done now due to a potential adjustment to the plotarea given an outer legend. # has to be done now due to a potential adjustment to the plotarea given an outer legend.
legendn = 0 legendn::Int = 0
legendw = 0 legendw::Float64 = 0.0
legendi = 0 legendi::Int = 0
if sp[:legend] != :none if sp[:legend] != :none
(function ()
GR.savestate() GR.savestate()
GR.selntran(0) GR.selntran(0)
GR.setscale(0) GR.setscale(0)
@ -902,6 +907,7 @@ function gr_display(sp::Subplot{GRBackend}, w, h, viewport_canvas)
GR.setscale(1) GR.setscale(1)
GR.selntran(1) GR.selntran(1)
GR.restorestate() GR.restorestate()
end)()
end end
dy = _gr_point_mult[1] * sp[:legendfontsize] * 1.75 dy = _gr_point_mult[1] * sp[:legendfontsize] * 1.75
@ -964,10 +970,11 @@ function gr_display(sp::Subplot{GRBackend}, w, h, viewport_canvas)
zaxis = sp[:zaxis] zaxis = sp[:zaxis]
# set the scale flags and window # set the scale flags and window
xmin, xmax, ymin, ymax = data_lims xmin::Float64, xmax::Float64, ymin::Float64, ymax::Float64 = data_lims
scaleop = 0 scaleop = 0
xtick, ytick = 1, 1 xtick, ytick = 1, 1
if xmax > xmin && ymax > ymin if xmax > xmin && ymax > ymin
(function ()
# NOTE: for log axes, the major_x and major_y - if non-zero (omit labels) - control the minor grid lines (1 = draw 9 minor grid lines, 2 = no minor grid lines) # NOTE: for log axes, the major_x and major_y - if non-zero (omit labels) - control the minor grid lines (1 = draw 9 minor grid lines, 2 = no minor grid lines)
# NOTE: for log axes, the x_tick and y_tick - if non-zero (omit axes) - only affect the output appearance (1 = nomal, 2 = scientiic notation) # NOTE: for log axes, the x_tick and y_tick - if non-zero (omit axes) - only affect the output appearance (1 = nomal, 2 = scientiic notation)
xaxis[:scale] == :log10 && (scaleop |= GR.OPTION_X_LOG) xaxis[:scale] == :log10 && (scaleop |= GR.OPTION_X_LOG)
@ -994,6 +1001,7 @@ function gr_display(sp::Subplot{GRBackend}, w, h, viewport_canvas)
# NOTE: setwindow sets the "data coordinate" limits of the current "viewport" # NOTE: setwindow sets the "data coordinate" limits of the current "viewport"
GR.setwindow(xmin, xmax, ymin, ymax) GR.setwindow(xmin, xmax, ymin, ymax)
GR.setscale(scaleop) GR.setscale(scaleop)
end)()
end end
# draw the axes # draw the axes
@ -1263,6 +1271,7 @@ function gr_display(sp::Subplot{GRBackend}, w, h, viewport_canvas)
end end
if st in (:path, :scatter, :straightline) if st in (:path, :scatter, :straightline)
(@noinline function ()
if x !== nothing && length(x) > 1 if x !== nothing && length(x) > 1
lz = series[:line_z] lz = series[:line_z]
segments = iter_segments(series) segments = iter_segments(series)
@ -1297,9 +1306,9 @@ function gr_display(sp::Subplot{GRBackend}, w, h, viewport_canvas)
if series[:markershape] != :none if series[:markershape] != :none
gr_draw_markers(series, x, y, clims) gr_draw_markers(series, x, y, clims)
end end
end)()
elseif st == :contour elseif st == :contour
(function () (@noinline function ()
GR.setspace(clims[1], clims[2], 0, 90) GR.setspace(clims[1], clims[2], 0, 90)
GR.setlinetype(gr_linetype[get_linestyle(series)]) GR.setlinetype(gr_linetype[get_linestyle(series)])
GR.setlinewidth(max(0, get_linewidth(series) / (sum(gr_plot_size) * 0.001))) GR.setlinewidth(max(0, get_linewidth(series) / (sum(gr_plot_size) * 0.001)))
@ -1318,7 +1327,7 @@ function gr_display(sp::Subplot{GRBackend}, w, h, viewport_canvas)
end end
end)() end)()
elseif st in [:surface, :wireframe] elseif st in [:surface, :wireframe]
(function () (@noinline function ()
if st == :surface if st == :surface
if length(x) == length(y) == length(z) if length(x) == length(y) == length(z)
GR.trisurface(x, y, z) GR.trisurface(x, y, z)
@ -1335,13 +1344,13 @@ function gr_display(sp::Subplot{GRBackend}, w, h, viewport_canvas)
end end
end)() end)()
elseif st == :volume elseif st == :volume
(function () (@noinline function ()
sp[:legend] = :none sp[:legend] = :none
GR.gr3.clear() GR.gr3.clear()
dmin, dmax = GR.gr3.volume(y.v, 0) dmin, dmax = GR.gr3.volume(y.v, 0)
end)() end)()
elseif st == :heatmap elseif st == :heatmap
(function () (@noinline function ()
zmin, zmax = clims zmin, zmax = clims
if !ispolar(sp) if !ispolar(sp)
xmin, xmax, ymin, ymax = xy_lims xmin, xmax, ymin, ymax = xy_lims
@ -1364,7 +1373,7 @@ function gr_display(sp::Subplot{GRBackend}, w, h, viewport_canvas)
end end
end)() end)()
elseif st in (:path3d, :scatter3d) elseif st in (:path3d, :scatter3d)
(function () (@noinline function ()
# draw path # draw path
if st == :path3d if st == :path3d
if length(x) > 1 if length(x) > 1
@ -1387,7 +1396,7 @@ function gr_display(sp::Subplot{GRBackend}, w, h, viewport_canvas)
end)() end)()
# TODO: replace with pie recipe # TODO: replace with pie recipe
elseif st == :pie elseif st == :pie
(function () (@noinline function ()
GR.selntran(0) GR.selntran(0)
GR.setfillintstyle(GR.INTSTYLE_SOLID) GR.setfillintstyle(GR.INTSTYLE_SOLID)
xmin, xmax, ymin, ymax = viewport_plotarea xmin, xmax, ymin, ymax = viewport_plotarea
@ -1435,7 +1444,7 @@ function gr_display(sp::Subplot{GRBackend}, w, h, viewport_canvas)
GR.selntran(1) GR.selntran(1)
end)() end)()
elseif st == :shape elseif st == :shape
(function () (@noinline function ()
x, y = shape_data(series) x, y = shape_data(series)
for (i,rng) in enumerate(iter_segments(x, y)) for (i,rng) in enumerate(iter_segments(x, y))
if length(rng) > 1 if length(rng) > 1
@ -1460,7 +1469,7 @@ function gr_display(sp::Subplot{GRBackend}, w, h, viewport_canvas)
end end
end)() end)()
elseif st == :image elseif st == :image
(function () (@noinline function ()
z = transpose_z(series, series[:z].surf, true)' z = transpose_z(series, series[:z].surf, true)'
w, h = size(z) w, h = size(z)
xmin, xmax = ignorenan_extrema(series[:x]); ymin, ymax = ignorenan_extrema(series[:y]) xmin, xmax = ignorenan_extrema(series[:x]); ymin, ymax = ignorenan_extrema(series[:y])
@ -1492,7 +1501,7 @@ function gr_display(sp::Subplot{GRBackend}, w, h, viewport_canvas)
# add the legend # add the legend
if sp[:legend] != :none if sp[:legend] != :none
(function () (@noinline function ()
GR.savestate() GR.savestate()
GR.selntran(0) GR.selntran(0)
GR.setscale(0) GR.setscale(0)