From 865ac52442db347a88e35e788d80ed6f0d8df464 Mon Sep 17 00:00:00 2001 From: Daniel Schwabeneder Date: Sat, 23 Jun 2018 19:39:25 +0200 Subject: [PATCH 1/6] pgf_thickness_scaling for series linewidths and markers --- src/backends/pgfplots.jl | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/backends/pgfplots.jl b/src/backends/pgfplots.jl index 19155c92..baa2eec0 100644 --- a/src/backends/pgfplots.jl +++ b/src/backends/pgfplots.jl @@ -149,6 +149,10 @@ function pgf_colormap(grad::ColorGradient) end,", ") end +pgf_thickness_scaling(plt::Plot) = plt[:thickness_scaling] * plt[:dpi] / DPI +pgf_thickness_scaling(sp::Subplot) = pgf_thickness_scaling(sp.plt) +pgf_thickness_scaling(series) = pgf_thickness_scaling(series[:subplot]) + function pgf_fillstyle(d, i = 1) cstr,a = pgf_color(get_fillcolor(d, i)) fa = get_fillalpha(d, i) @@ -167,7 +171,7 @@ function pgf_linestyle(d, i = 1) """ color = $cstr, draw opacity=$a, - line width=$(get_linewidth(d, i)), + line width=$(pgf_thickness_scaling(d) * get_linewidth(d, i)), $(get(_pgfplots_linestyles, get_linestyle(d, i), "solid"))""" end @@ -177,11 +181,11 @@ function pgf_marker(d, i = 1) cstr_stroke, a_stroke = pgf_color(plot_color(get_markerstrokecolor(d, i), get_markerstrokealpha(d, i))) """ mark = $(get(_pgfplots_markers, shape, "*")), - mark size = $(0.5 * _cycle(d[:markersize], i)), + mark size = $(pgf_thickness_scaling(d) * 0.5 * _cycle(d[:markersize], i)), mark options = { color = $cstr_stroke, draw opacity = $a_stroke, fill = $cstr, fill opacity = $a, - line width = $(_cycle(d[:markerstrokewidth], i)), + line width = $(pgf_thickness_scaling(d) * _cycle(d[:markerstrokewidth], i)), rotate = $(shape == :dtriangle ? 180 : 0), $(get(_pgfplots_linestyles, _cycle(d[:markerstrokestyle], i), "solid")) }""" From 624a181b23b363dbdc4c9173e515851a4a7be5d3 Mon Sep 17 00:00:00 2001 From: Daniel Schwabeneder Date: Sat, 23 Jun 2018 21:47:01 +0200 Subject: [PATCH 2/6] implement axis and grid arguments and corresponding thickness_scaling --- src/backends/pgfplots.jl | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/src/backends/pgfplots.jl b/src/backends/pgfplots.jl index baa2eec0..53a30aec 100644 --- a/src/backends/pgfplots.jl +++ b/src/backends/pgfplots.jl @@ -162,17 +162,21 @@ function pgf_fillstyle(d, i = 1) "fill = $cstr, fill opacity=$a" end -function pgf_linestyle(d, i = 1) - cstr,a = pgf_color(get_linecolor(d, i)) - la = get_linealpha(d, i) - if la != nothing - a = la - end +function pgf_linestyle(linewidth::Real, color, alpha = 1, linestyle = "solid") + cstr, a = pgf_color(plot_color(color, alpha)) """ color = $cstr, - draw opacity=$a, - line width=$(pgf_thickness_scaling(d) * get_linewidth(d, i)), - $(get(_pgfplots_linestyles, get_linestyle(d, i), "solid"))""" + draw opacity = $a, + line width = $linewidth, + $(get(_pgfplots_linestyles, linestyle, "solid"))""" +end + +function pgf_linestyle(d, i = 1) + lw = pgf_thickness_scaling(d) * get_linewidth(d, i) + lc = get_linecolor(d, i) + la = get_linealpha(d, i) + ls = get_linestyle(d, i) + return pgf_linestyle(lw, lc, la, ls) end function pgf_marker(d, i = 1) @@ -431,6 +435,7 @@ function pgf_axis(sp::Subplot, letter) push!(style, string(letter, "ticklabels = {}")) end push!(style, string(letter, "tick align = ", (axis[:tick_direction] == :out ? "outside" : "inside"))) + push!(style, string(letter, " grid style = {", pgf_linestyle(pgf_thickness_scaling(sp) * axis[:gridlinewidth], axis[:foreground_color_grid], axis[:gridalpha], axis[:gridstyle]), "}")) end # framestyle @@ -443,7 +448,7 @@ function pgf_axis(sp::Subplot, letter) if framestyle == :zerolines push!(style, string("extra ", letter, " ticks = 0")) push!(style, string("extra ", letter, " tick labels = ")) - push!(style, string("extra ", letter, " tick style = {grid = major, major grid style = {color = black, draw opacity=1.0, line width=0.5), solid}}")) + push!(style, string("extra ", letter, " tick style = {grid = major, major grid style = {", pgf_linestyle(pgf_thickness_scaling(sp), axis[:foreground_color_axis], 1.0), "}}")) end if !axis[:showaxis] @@ -451,6 +456,8 @@ function pgf_axis(sp::Subplot, letter) end if !axis[:showaxis] || framestyle in (:zerolines, :grid, :none) push!(style, string(letter, " axis line style = {draw opacity = 0}")) + else + push!(style, string(letter, " axis line style = {", pgf_linestyle(pgf_thickness_scaling(sp), axis[:foreground_color_axis], 1.0), "}")) end # return the style list and KW args @@ -505,6 +512,8 @@ function _update_plot_object(plt::Plot{PGFPlotsBackend}) if haskey(_pgfplots_legend_pos, legpos) kw[:legendPos] = _pgfplots_legend_pos[legpos] end + cstr, a = pgf_color(plot_color(sp[:background_color_legend])) + push!(style, string("legend style = {", pgf_linestyle(pgf_thickness_scaling(sp), sp[:foreground_color_legend], 1.0, "solid"), ",", "fill = $cstr", "}")) if any(s[:seriestype] == :contour for s in series_list(sp)) kw[:view] = "{0}{90}" From 77a82eaa6aac21d6ee715288c09457a6e9218bc2 Mon Sep 17 00:00:00 2001 From: Daniel Schwabeneder Date: Sat, 23 Jun 2018 23:24:09 +0200 Subject: [PATCH 3/6] implent font size and colors --- src/backends/pgfplots.jl | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/src/backends/pgfplots.jl b/src/backends/pgfplots.jl index 53a30aec..572c0ee2 100644 --- a/src/backends/pgfplots.jl +++ b/src/backends/pgfplots.jl @@ -8,11 +8,12 @@ end const _pgfplots_attr = merge_with_base_supported([ :annotations, - # :background_color_legend, + :background_color_legend, :background_color_inside, # :background_color_outside, - # :foreground_color_legend, :foreground_color_grid, :foreground_color_axis, - # :foreground_color_text, :foreground_color_border, + # :foreground_color_legend, + :foreground_color_grid, :foreground_color_axis, + :foreground_color_text, :foreground_color_border, :label, :seriescolor, :seriesalpha, :linecolor, :linestyle, :linewidth, :linealpha, @@ -162,8 +163,8 @@ function pgf_fillstyle(d, i = 1) "fill = $cstr, fill opacity=$a" end -function pgf_linestyle(linewidth::Real, color, alpha = 1, linestyle = "solid") - cstr, a = pgf_color(plot_color(color, alpha)) +function pgf_linestyle(linewidth::Real, color, α = 1, linestyle = "solid") + cstr, a = pgf_color(plot_color(color, α)) """ color = $cstr, draw opacity = $a, @@ -179,6 +180,11 @@ function pgf_linestyle(d, i = 1) return pgf_linestyle(lw, lc, la, ls) end +function pgf_font(fontsize, thickness_scaling = 1, font = "\\selectfont") + fs = fontsize * thickness_scaling + return string("{\\fontsize{", fs, " pt}{", 1.3fs, " pt}", font, "}") +end + function pgf_marker(d, i = 1) shape = _cycle(d[:markershape], i) cstr, a = pgf_color(plot_color(get_markercolor(d, i), get_markeralpha(d, i))) @@ -381,6 +387,10 @@ function pgf_axis(sp::Subplot, letter) # Add ticklabel rotations push!(style, "$(letter)ticklabel style={rotate = $(axis[:rotation])}") + # Add label font + cstr, α = pgf_color(plot_color(axis[:guidefontcolor])) + push!(style, string(letter, "label style = {font = ", pgf_font(axis[:guidefontsize], pgf_thickness_scaling(sp)), ", color = ", cstr, ", draw opacity = ", α, "}")) + # flip/reverse? axis[:flip] && push!(style, "$letter dir=reverse") @@ -435,6 +445,8 @@ function pgf_axis(sp::Subplot, letter) push!(style, string(letter, "ticklabels = {}")) end push!(style, string(letter, "tick align = ", (axis[:tick_direction] == :out ? "outside" : "inside"))) + cstr, α = pgf_color(plot_color(axis[:tickfontcolor])) + push!(style, string(letter, "ticklabel style = {font = ", pgf_font(axis[:tickfontsize], pgf_thickness_scaling(sp)), ", color = ", cstr, ", draw opacity = ", α, "}")) push!(style, string(letter, " grid style = {", pgf_linestyle(pgf_thickness_scaling(sp) * axis[:gridlinewidth], axis[:foreground_color_grid], axis[:gridalpha], axis[:gridstyle]), "}")) end @@ -502,6 +514,8 @@ function _update_plot_object(plt::Plot{PGFPlotsBackend}) if sp[:title] != "" kw[:title] = "$(sp[:title])" + cstr, α = pgf_color(plot_color(sp[:titlefontcolor])) + push!(style, string("title style = {font = ", pgf_font(sp[:titlefontsize], pgf_thickness_scaling(sp)), ", color = ", cstr, ", draw opacity = ", α, "}")) end if sp[:aspect_ratio] in (1, :equal) @@ -513,7 +527,7 @@ function _update_plot_object(plt::Plot{PGFPlotsBackend}) kw[:legendPos] = _pgfplots_legend_pos[legpos] end cstr, a = pgf_color(plot_color(sp[:background_color_legend])) - push!(style, string("legend style = {", pgf_linestyle(pgf_thickness_scaling(sp), sp[:foreground_color_legend], 1.0, "solid"), ",", "fill = $cstr", "}")) + push!(style, string("legend style = {", pgf_linestyle(pgf_thickness_scaling(sp), sp[:foreground_color_legend], 1.0, "solid"), ",", "fill = $cstr,", "font = ", pgf_font(sp[:legendfontsize], pgf_thickness_scaling(sp)), "}")) if any(s[:seriestype] == :contour for s in series_list(sp)) kw[:view] = "{0}{90}" From 652e2f27b6b44bf0a109752bcd163aa154097d57 Mon Sep 17 00:00:00 2001 From: Daniel Schwabeneder Date: Sat, 23 Jun 2018 23:38:38 +0200 Subject: [PATCH 4/6] implement font rotation --- src/backends/pgfplots.jl | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/src/backends/pgfplots.jl b/src/backends/pgfplots.jl index 572c0ee2..dce8350a 100644 --- a/src/backends/pgfplots.jl +++ b/src/backends/pgfplots.jl @@ -384,12 +384,9 @@ function pgf_axis(sp::Subplot, letter) # axis guide kw[Symbol(letter,:label)] = axis[:guide] - # Add ticklabel rotations - push!(style, "$(letter)ticklabel style={rotate = $(axis[:rotation])}") - # Add label font cstr, α = pgf_color(plot_color(axis[:guidefontcolor])) - push!(style, string(letter, "label style = {font = ", pgf_font(axis[:guidefontsize], pgf_thickness_scaling(sp)), ", color = ", cstr, ", draw opacity = ", α, "}")) + push!(style, string(letter, "label style = {font = ", pgf_font(axis[:guidefontsize], pgf_thickness_scaling(sp)), ", color = ", cstr, ", draw opacity = ", α, ", rotate = ", axis[:guidefontrotation], "}")) # flip/reverse? axis[:flip] && push!(style, "$letter dir=reverse") @@ -446,7 +443,7 @@ function pgf_axis(sp::Subplot, letter) end push!(style, string(letter, "tick align = ", (axis[:tick_direction] == :out ? "outside" : "inside"))) cstr, α = pgf_color(plot_color(axis[:tickfontcolor])) - push!(style, string(letter, "ticklabel style = {font = ", pgf_font(axis[:tickfontsize], pgf_thickness_scaling(sp)), ", color = ", cstr, ", draw opacity = ", α, "}")) + push!(style, string(letter, "ticklabel style = {font = ", pgf_font(axis[:tickfontsize], pgf_thickness_scaling(sp)), ", color = ", cstr, ", draw opacity = ", α, ", rotate = ", axis[:tickfontrotation], "}")) push!(style, string(letter, " grid style = {", pgf_linestyle(pgf_thickness_scaling(sp) * axis[:gridlinewidth], axis[:foreground_color_grid], axis[:gridalpha], axis[:gridstyle]), "}")) end @@ -515,7 +512,7 @@ function _update_plot_object(plt::Plot{PGFPlotsBackend}) if sp[:title] != "" kw[:title] = "$(sp[:title])" cstr, α = pgf_color(plot_color(sp[:titlefontcolor])) - push!(style, string("title style = {font = ", pgf_font(sp[:titlefontsize], pgf_thickness_scaling(sp)), ", color = ", cstr, ", draw opacity = ", α, "}")) + push!(style, string("title style = {font = ", pgf_font(sp[:titlefontsize], pgf_thickness_scaling(sp)), ", color = ", cstr, ", draw opacity = ", α, ", rotate = ", sp[:titlefontrotation], "}")) end if sp[:aspect_ratio] in (1, :equal) From 2652990432e0c125a73c23ba4d61dfbe2ad3a26a Mon Sep 17 00:00:00 2001 From: Daniel Schwabeneder Date: Sat, 23 Jun 2018 23:44:43 +0200 Subject: [PATCH 5/6] annotations --- src/backends/pgfplots.jl | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/src/backends/pgfplots.jl b/src/backends/pgfplots.jl index dce8350a..ac54173c 100644 --- a/src/backends/pgfplots.jl +++ b/src/backends/pgfplots.jl @@ -201,17 +201,18 @@ function pgf_marker(d, i = 1) }""" end -function pgf_add_annotation!(o,x,y,val) +function pgf_add_annotation!(o, x, y, val, thickness_scaling = 1) # Construct the style string. # Currently supports color and orientation cstr,a = pgf_color(val.font.color) push!(o, PGFPlots.Plots.Node(val.str, # Annotation Text - x, y, - style=""" - $(get(_pgf_annotation_halign,val.font.halign,"")), - color=$cstr, draw opacity=$(convert(Float16,a)), - rotate=$(val.font.rotation) - """)) + x, y, + style=""" + $(get(_pgf_annotation_halign,val.font.halign,"")), + color=$cstr, draw opacity=$(convert(Float16,a)), + rotate=$(val.font.rotation), + font=$(pgf_font(val.font.pointsize, thickness_scaling)) + """)) end # -------------------------------------------------------------------------------------- @@ -578,13 +579,13 @@ function _update_plot_object(plt::Plot{PGFPlotsBackend}) # add series annotations anns = series[:series_annotations] for (xi,yi,str,fnt) in EachAnn(anns, series[:x], series[:y]) - pgf_add_annotation!(o, xi, yi, PlotText(str, fnt)) + pgf_add_annotation!(o, xi, yi, PlotText(str, fnt), pgf_thickness_scaling(series)) end end # add the annotations for ann in sp[:annotations] - pgf_add_annotation!(o, locate_annotation(sp, ann...)...) + pgf_add_annotation!(o, locate_annotation(sp, ann...)..., pgf_thickness_scaling(sp)) end From 440622830a75ccd8b868340c55534f35c6a5677b Mon Sep 17 00:00:00 2001 From: Daniel Schwabeneder Date: Sun, 24 Jun 2018 00:34:11 +0200 Subject: [PATCH 6/6] disregard dpi for pgfplots --- src/backends/pgfplots.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/backends/pgfplots.jl b/src/backends/pgfplots.jl index ac54173c..aae1a356 100644 --- a/src/backends/pgfplots.jl +++ b/src/backends/pgfplots.jl @@ -150,7 +150,7 @@ function pgf_colormap(grad::ColorGradient) end,", ") end -pgf_thickness_scaling(plt::Plot) = plt[:thickness_scaling] * plt[:dpi] / DPI +pgf_thickness_scaling(plt::Plot) = plt[:thickness_scaling] pgf_thickness_scaling(sp::Subplot) = pgf_thickness_scaling(sp.plt) pgf_thickness_scaling(series) = pgf_thickness_scaling(series[:subplot])