Merge pull request #208 from pkofod/newpgf
Further changes to PGFPlots backend.
This commit is contained in:
commit
db118d4f5a
@ -8,86 +8,82 @@ function _initialize_backend(::PGFPlotsBackend; kw...)
|
|||||||
end
|
end
|
||||||
# TODO: other initialization
|
# TODO: other initialization
|
||||||
end
|
end
|
||||||
|
const _pgfplots_linestyles = KW(
|
||||||
|
:solid => "solid",
|
||||||
|
:dash => "dashed",
|
||||||
|
:dot => "dotted",
|
||||||
|
:dashdot => "dashdotted",
|
||||||
|
:dashdotdot => "dashdotdotted"
|
||||||
|
)
|
||||||
|
|
||||||
_pgfplots_get_color(c) = "{rgb,1:red,$(float(c.r));green,$(float(c.g));blue,$(float(c.b))}"
|
const _pgfplots_markers = KW(
|
||||||
|
:none => "mark = none,",
|
||||||
|
:cross => "mark = +,",
|
||||||
|
:xcross => "mark = x,",
|
||||||
|
:utriangle => "mark = triangle*,",
|
||||||
|
:dtriangle => "mark = triangle*,",
|
||||||
|
:ellipse => "mark = o*,",
|
||||||
|
:rect => "mark = square*,",
|
||||||
|
:star5 => "mark = star,",
|
||||||
|
:star6 => "mark = asterisk,",
|
||||||
|
:diamond => "mark = diamond*,",
|
||||||
|
:pentagon => "mark = pentagon*,"
|
||||||
|
)
|
||||||
|
|
||||||
function _pgfplots_get_linestyle!(kwargs, plt)
|
function _pgfplots_get_color(kwargs, symb)
|
||||||
linestyle = plt[:linestyle]
|
c = typeof(kwargs[symb]) == Symbol ? convertColor(kwargs[symb]) : kwargs[symb].c
|
||||||
if linestyle == :dash
|
"{rgb,1:red,$(float(c.r));green,$(float(c.g));blue,$(float(c.b))}"
|
||||||
kwargs[:style] *= "dashed,"
|
|
||||||
elseif linestyle == :dot
|
|
||||||
kwargs[:style] *= "dotted,"
|
|
||||||
elseif linestyle == :dashdot
|
|
||||||
kwargs[:style] *= "dashdotted,"
|
|
||||||
elseif linestyle == :dashdotdot
|
|
||||||
kwargs[:style] *= "dashdotdotted,"
|
|
||||||
end
|
end
|
||||||
|
|
||||||
kwargs[:style] *= (haskey(plt, :linewidth) && plt[:linewidth] != :auto) ? "line width = $(plt[:linewidth]) pt," : "line width = 1 pt,"
|
function _pgfplots_get_linestyle!(kwargs, plt)
|
||||||
|
ls = plt[:linestyle]
|
||||||
|
if haskey(_pgfplots_linestyles, ls)
|
||||||
|
kwargs[:style] *= _pgfplots_linestyles[ls]*","
|
||||||
|
end
|
||||||
|
|
||||||
|
kwargs[:style] *= "line width = $(plt[:linewidth]) pt"*","
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
function _pgfplots_get_marker!(kwargs, plt)
|
function _pgfplots_get_marker!(kwargs, plt)
|
||||||
# Control marker shape
|
# Control marker shape
|
||||||
mark = plt[:markershape]
|
mark = plt[:markershape]
|
||||||
if mark in (:none,:n, :no)
|
kwargs[:style] *= _pgfplots_markers[mark]
|
||||||
kwargs[:style] *= "mark = none,"
|
|
||||||
elseif mark in (:auto, :a)
|
|
||||||
kwargs[:style] *= "mark = *,"
|
|
||||||
elseif mark in (:cross, :+, :plus)
|
|
||||||
kwargs[:style] *= "mark = +,"
|
|
||||||
elseif mark in (:xcross ,:X, :x)
|
|
||||||
kwargs[:style] *= "mark = x,"
|
|
||||||
elseif mark in (:utriangle, :^, :uptri, :uptriangle, :ut, :utri,
|
|
||||||
:dtriangle, :V, :downtri, :downtriangle, :dt ,:dtri, :v)
|
|
||||||
kwargs[:style] *= "mark = triangle*,"
|
|
||||||
elseif mark in (:ellipse, :c, :circle)
|
|
||||||
kwargs[:style] *= "mark = o*,"
|
|
||||||
elseif mark in (:rect ,:r, :sq, :square)
|
|
||||||
kwargs[:style] *= "mark = square*,"
|
|
||||||
elseif mark in (:star5 ,:s, :star, :star1)
|
|
||||||
kwargs[:style] *= "mark = star,"
|
|
||||||
elseif mark in (:star6,)
|
|
||||||
kwargs[:style] *= "mark = asterisk,"
|
|
||||||
elseif mark in (:diamond, :d)
|
|
||||||
kwargs[:style] *= "mark = diamond*,"
|
|
||||||
elseif mark in (:pentagon ,:p, :pent)
|
|
||||||
kwargs[:style] *= "mark = pentagon*,"
|
|
||||||
end
|
|
||||||
|
|
||||||
# Control marker size
|
# Control marker size
|
||||||
kwargs[:style] *= "mark size = $(plt[:markersize]/2),"
|
kwargs[:style] *= "mark size = $(plt[:markersize]/2),"
|
||||||
|
|
||||||
# Control marker colors and alphas
|
# Control marker colors and alphas
|
||||||
marker_fill = plt[:markercolor].c
|
|
||||||
α = plt[:markeralpha] == nothing ? 1.0 : plt[:markeralpha]
|
α = plt[:markeralpha] == nothing ? 1.0 : plt[:markeralpha]
|
||||||
marker_stroke = plt[:markerstrokecolor].c
|
kwargs[:style] *= "mark options = {color=$(_pgfplots_get_color(plt, :markerstrokecolor)),"
|
||||||
kwargs[:style] *= "mark options = {color="*_pgfplots_get_color(marker_stroke)*","
|
kwargs[:style] *= mark == :dtriangle ? "rotate=180," : ""
|
||||||
kwargs[:style] *= mark in (:dtriangle, :V, :downtri, :downtriangle, :dt ,:dtri, :v) ? "rotate=180," : ""
|
kwargs[:style] *= "fill=$(_pgfplots_get_color(plt, :markercolor)),"
|
||||||
kwargs[:style] *= "fill="*_pgfplots_get_color(marker_fill)*","
|
|
||||||
kwargs[:style] *= "fill opacity = $α,"
|
kwargs[:style] *= "fill opacity = $α,"
|
||||||
markerstrokestyle = plt[:markerstrokestyle]
|
markstrokestyle = plt[:markerstrokestyle]
|
||||||
if markerstrokestyle == :solid
|
if haskey(_pgfplots_linestyles, markstrokestyle)
|
||||||
kwargs[:style] *= "solid,"
|
kwargs[:style] *= _pgfplots_linestyles[markstrokestyle]
|
||||||
elseif markerstrokestyle == :dash
|
|
||||||
kwargs[:style] *= "dashed,"
|
|
||||||
elseif markerstrokestyle == :dot
|
|
||||||
kwargs[:style] *= "dotted,"
|
|
||||||
elseif markerstrokestyle == :dashdot
|
|
||||||
kwargs[:style] *= "dashdotted,"
|
|
||||||
elseif markerstrokestyle == :dashdotdot
|
|
||||||
kwargs[:style] *= "dashdotdotted,"
|
|
||||||
end
|
end
|
||||||
kwargs[:style] *= "},"
|
kwargs[:style] *= "},"
|
||||||
end
|
end
|
||||||
|
|
||||||
function _pgfplots_get_series_color!(kwargs, plt)
|
function _pgfplots_get_series_color!(kwargs, plt)
|
||||||
color = plt[:seriescolor].c
|
|
||||||
α = plt[:seriesalpha] == nothing ? 1.0 : plt[:seriesalpha]
|
α = plt[:seriesalpha] == nothing ? 1.0 : plt[:seriesalpha]
|
||||||
kwargs[:style] *= "color="*_pgfplots_get_color(color)*","
|
kwargs[:style] *= "color=$(_pgfplots_get_color(plt, :seriescolor)),"
|
||||||
kwargs[:style] *= "draw opacity = $α,"
|
kwargs[:style] *= "draw opacity = $α,"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function _pgfplots_get_line_color!(kwargs, plt)
|
||||||
|
α = plt[:linealpha] == nothing ? 1.0 : plt[:linealpha]
|
||||||
|
kwargs[:style] *= "color=$(_pgfplots_get_color(plt, :linecolor)),"
|
||||||
|
kwargs[:style] *= "draw opacity = $α,"
|
||||||
|
end
|
||||||
|
|
||||||
|
function _pgfplots_get_fill_color!(kwargs, plt)
|
||||||
|
α = plt[:fillalpha] == nothing ? 1.0 : plt[:fillalpha]
|
||||||
|
kwargs[:style] *= "fill=$(_pgfplots_get_color(plt, :fillcolor)),"
|
||||||
|
kwargs[:style] *= "fill opacity = $α,"
|
||||||
|
end
|
||||||
|
|
||||||
function _pgfplots_get_plot_kwargs(plt)
|
function _pgfplots_get_plot_kwargs(plt)
|
||||||
kwargs = KW()
|
kwargs = KW()
|
||||||
kwargs[:style] = ""
|
kwargs[:style] = ""
|
||||||
@ -119,12 +115,16 @@ function _pgfplots_axis(plt_series)
|
|||||||
#TODO patch this in PGFPlots.jl instead; the problem is that PGFPlots will
|
#TODO patch this in PGFPlots.jl instead; the problem is that PGFPlots will
|
||||||
# save _all_ data points in the figure which can be quite heavy
|
# save _all_ data points in the figure which can be quite heavy
|
||||||
plt_hist = hist(plt_series[:y])
|
plt_hist = hist(plt_series[:y])
|
||||||
plt_kwargs[:style] *= "ybar interval, mark = none"
|
plt_kwargs[:style] *= "ybar interval,"
|
||||||
|
_pgfplots_get_line_color!(plt_kwargs, plt_series)
|
||||||
|
_pgfplots_get_fill_color!(plt_kwargs, plt_series)
|
||||||
PGFPlots.Linear(plt_hist[1][1:end-1]+plt_hist[1].step/2, plt_hist[2]; plt_kwargs...)
|
PGFPlots.Linear(plt_hist[1][1:end-1]+plt_hist[1].step/2, plt_hist[2]; plt_kwargs...)
|
||||||
elseif line_type == :hist2d
|
elseif line_type == :hist2d
|
||||||
PGFPlots.Histogram2(plt_series[:x], plt_series[:y])
|
PGFPlots.Histogram2(plt_series[:x], plt_series[:y])
|
||||||
elseif line_type == :bar
|
elseif line_type == :bar
|
||||||
plt_kwargs[:style] *= "ybar, mark = none"
|
plt_kwargs[:style] *= "ybar,"
|
||||||
|
_pgfplots_get_line_color!(plt_kwargs, plt_series)
|
||||||
|
_pgfplots_get_fill_color!(plt_kwargs, plt_series)
|
||||||
PGFPlots.Linear(plt_series[:x], plt_series[:y]; plt_kwargs...)
|
PGFPlots.Linear(plt_series[:x], plt_series[:y]; plt_kwargs...)
|
||||||
elseif line_type == :sticks || line_type == :ysticks
|
elseif line_type == :sticks || line_type == :ysticks
|
||||||
plt_kwargs[:style] *= "ycomb"
|
plt_kwargs[:style] *= "ycomb"
|
||||||
@ -207,10 +207,10 @@ end
|
|||||||
|
|
||||||
function _pgfplots_get_axis_kwargs(d)
|
function _pgfplots_get_axis_kwargs(d)
|
||||||
axisargs = KW()
|
axisargs = KW()
|
||||||
axisargs[:style] = "{"
|
|
||||||
for arg in (:xlabel, :ylabel, :zlabel, :title)
|
for arg in (:xlabel, :ylabel, :zlabel, :title)
|
||||||
axisargs[arg] = d[arg]
|
axisargs[arg] = d[arg]
|
||||||
end
|
end
|
||||||
|
axisargs[:style] = ""
|
||||||
axisargs[:style] *= d[:xflip] == true ? "x dir=reverse," : ""
|
axisargs[:style] *= d[:xflip] == true ? "x dir=reverse," : ""
|
||||||
axisargs[:style] *= d[:yflip] == true ? "y dir=reverse," : ""
|
axisargs[:style] *= d[:yflip] == true ? "y dir=reverse," : ""
|
||||||
if d[:xscale] in (:log, :log2, :ln, :log10)
|
if d[:xscale] in (:log, :log2, :ln, :log10)
|
||||||
@ -237,12 +237,9 @@ function _pgfplots_get_axis_kwargs(d)
|
|||||||
axisargs[:style] *= "log basis x=10,"
|
axisargs[:style] *= "log basis x=10,"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
axisargs[:style] *= "},"
|
|
||||||
|
|
||||||
# Control background color
|
# Control background color
|
||||||
bg_color = d[:background_color].c
|
axisargs[:style] *= "axis background/.style={fill=$(_pgfplots_get_color(d, :background_color))},"
|
||||||
axisargs[:style] *= "axis background/.style={fill={rgb,1:red,$(float(bg_color.r));green,$(float(bg_color.g));blue,$(float(bg_color.b))},}"
|
|
||||||
|
|
||||||
# Control x/y-limits
|
# Control x/y-limits
|
||||||
if d[:xlims] !== :auto
|
if d[:xlims] !== :auto
|
||||||
axisargs[:xmin] = d[:xlims][1]
|
axisargs[:xmin] = d[:xlims][1]
|
||||||
@ -253,10 +250,11 @@ function _pgfplots_get_axis_kwargs(d)
|
|||||||
axisargs[:ymax] = d[:ylims][2]
|
axisargs[:ymax] = d[:ylims][2]
|
||||||
end
|
end
|
||||||
if d[:grid] == true
|
if d[:grid] == true
|
||||||
axisargs[:style] = "grid = major"
|
axisargs[:style] *= "grid = major"
|
||||||
elseif d[:grid] == false
|
elseif d[:grid] == false
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
axisargs
|
axisargs
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@ -648,8 +648,8 @@ supportedArgs(::PGFPlotsBackend) = [
|
|||||||
:background_color,
|
:background_color,
|
||||||
# :color_palette,
|
# :color_palette,
|
||||||
# :fillrange,
|
# :fillrange,
|
||||||
# :fillcolor,
|
:fillcolor,
|
||||||
# :fillalpha,
|
:fillalpha,
|
||||||
# :foreground_color,
|
# :foreground_color,
|
||||||
# :group,
|
# :group,
|
||||||
# :label,
|
# :label,
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user