diff --git a/src/guide.jl b/src/guide.jl index 3bcba1d50..e4d09903e 100644 --- a/src/guide.jl +++ b/src/guide.jl @@ -56,6 +56,7 @@ function render(guide::PanelBackground, theme::Gadfly.Theme, rectangle(), svgclass("guide background"), stroke(theme.panel_stroke), + linewidth(theme.line_width), fill(theme.panel_fill), fillopacity(theme.panel_opacity), svgattribute("pointer-events", "visible")) @@ -607,29 +608,43 @@ function render(guide::XTicks, theme::Gadfly.Theme, return PositionedGuide[] end - # grid lines + # grid lines and tick marks + tick_length = 0.01*max(w,h) static_grid_lines = compose!( context(withoutjs=true), - line([[(t, 0h), (t, 1h)] for t in grids[gridvisibility]]), - stroke(theme.grid_color), linewidth(theme.grid_line_width), - strokedash(theme.grid_strokedash), - svgclass("guide xgridlines yfixed")) + svgclass("guide xgridlines yfixed"), + (context(), + stroke(theme.tick_color), + line([[(t, 0h), (t, 0h + tick_length)] for t in grids[gridvisibility]]), + line([[(t, 1h), (t, 1h - tick_length)] for t in grids[gridvisibility]])), + (context(), + line([[(t, 0h), (t, 1h)] for t in grids[gridvisibility]]), + stroke(theme.grid_color), + strokedash(theme.grid_strokedash))) if dynamic dynamic_grid_lines = compose!( context(withjs=true), - line([[(t, 0h), (t, 1h)] for t in grids]), - visible(gridvisibility), - stroke(theme.grid_color), linewidth(theme.grid_line_width), - strokedash(theme.grid_strokedash), - svgclass("guide xgridlines yfixed"), - svgattribute("gadfly:scale", scale), - jsplotdata("focused_xgrid_color", - "\"#$(hex(theme.grid_color_focused))\""), - jsplotdata("unfocused_xgrid_color", - "\"#$(hex(theme.grid_color))\"")) + visible(gridvisibility), + (context(), + (context(), + line([[(t, 0h), (t, 0h + tick_length)] for t in grids]), + line([[(t, 1h), (t, 1h - tick_length)] for t in grids])), + stroke(theme.tick_color), + svgclass("guide xgridlines yfixed"), + svgattribute("gadfly:scale", scale)), + (context(), + line([[(t, 0h), (t, 1h)] for t in grids]), + stroke(theme.grid_color), + strokedash(theme.grid_strokedash), + svgclass("guide xgridlines yfixed"), + svgattribute("gadfly:scale", scale), + jsplotdata("focused_xgrid_color", + "\"#$(hex(theme.grid_color_focused))\""), + jsplotdata("unfocused_xgrid_color", + "\"#$(hex(theme.grid_color))\""))) grid_lines = compose!(context(), static_grid_lines, dynamic_grid_lines) else grid_lines = compose!(context(), static_grid_lines) @@ -787,29 +802,44 @@ function render(guide::YTicks, theme::Gadfly.Theme, return PositionedGuide[] end - # grid lines + # grid lines and tick marks + tick_length = 0.01*max(w,h) static_grid_lines = compose!( context(withoutjs=true), - line([[(0w, t), (1w, t)] for t in grids[gridvisibility]]), - stroke(theme.grid_color), linewidth(theme.grid_line_width), - strokedash(theme.grid_strokedash), - svgclass("guide ygridlines xfixed")) + svgclass("guide ygridlines xfixed"), + (context(), + stroke(theme.tick_color), + line([[(0w, t), (0w + tick_length, t)] for t in grids[gridvisibility]]), + line([[(1w, t), (1w - tick_length, t)] for t in grids[gridvisibility]])), + (context(), + line([[(0w, t), (1w, t)] for t in grids[gridvisibility]]), + stroke(theme.grid_color), + strokedash(theme.grid_strokedash))) + if dynamic dynamic_grid_lines = compose!( context(withjs=true), - line([[(0w, t), (1w, t)] for t in grids]), - visible(gridvisibility), - stroke(theme.grid_color), linewidth(theme.grid_line_width), - strokedash(theme.grid_strokedash), - svgclass("guide ygridlines xfixed"), - svgattribute("gadfly:scale", scale), - jsplotdata("focused_ygrid_color", - "\"#$( hex(theme.grid_color_focused))\""), - jsplotdata("unfocused_ygrid_color", - "\"#$(hex(theme.grid_color))\"")) + visible(gridvisibility), + (context(), + (context(), + line([[(0w, t), (0w + tick_length, t)] for t in grids]), + line([[(1w, t), (1w - tick_length, t)] for t in grids])), + stroke(theme.tick_color), + svgclass("guide ygridlines xfixed"), + svgattribute("gadfly:scale", scale)), + (context(), + line([[(0w, t), (1w, t)] for t in grids]), + stroke(theme.grid_color), + strokedash(theme.grid_strokedash), + svgclass("guide ygridlines xfixed"), + svgattribute("gadfly:scale", scale), + jsplotdata("focused_ygrid_color", + "\"#$(hex(theme.grid_color_focused))\""), + jsplotdata("unfocused_ygrid_color", + "\"#$(hex(theme.grid_color))\""))) grid_lines = compose!(context(), static_grid_lines, dynamic_grid_lines) else grid_lines = compose!(context(), static_grid_lines) @@ -856,7 +886,7 @@ function render(guide::YTicks, theme::Gadfly.Theme, penalty=hpenalty), hlayout) vlayout = ctxpromise() do draw_context - static_grid_lines = compose!( + static_labels = compose!( context(), text([1.0w - padding], ticks[tickvisibility], labels[tickvisibility], [hcenter], [vbottom], @@ -867,7 +897,7 @@ function render(guide::YTicks, theme::Gadfly.Theme, fontsize(theme.minor_label_font_size), svgclass("guide ylabels")) - dynamic_grid_lines = compose!( + dynamic_labels = compose!( context(), text([1.0w - padding], ticks, labels, [hcenter], [vbottom], @@ -880,7 +910,7 @@ function render(guide::YTicks, theme::Gadfly.Theme, svgattribute("gadfly:scale", scale), svgclass("guide ylabels")) - return compose!(context(), static_grid_lines, dynamic_grid_lines) + return compose!(context(), static_labels, dynamic_labels) end vlayout_context = compose!(context(minwidth=maximum(label_heights[tickvisibility]), diff --git a/src/theme.jl b/src/theme.jl index 078ac04dc..fd34ee194 100644 --- a/src/theme.jl +++ b/src/theme.jl @@ -62,7 +62,7 @@ function default_middle_color(fill_color::TransparentColor) fill_color.alpha) end - + get_stroke_vector(::@compat(Void)) = [] get_stroke_vector(vec::AbstractVector) = vec function get_stroke_vector(linestyle::Symbol) @@ -89,7 +89,7 @@ end # Width of lines in the line geometry. line_width, Measure, 0.3mm - # type of dash style (a Compose.StrokeDash object which takes a vector of sold/missing/solid/missing/... + # type of dash style (a Compose.StrokeDash object which takes a vector of sold/missing/solid/missing/... # lengths which are applied cyclically) line_style, Maybe(Vector), nothing @@ -202,6 +202,9 @@ end rug_size, Measure, 2.0mm + # Management of axis-margin ticks. + tick_color, ColorOrNothing, nothing + # TODO: This stuff is too incomprehensible to be in theme, I think. Put it # somewhere else. @@ -224,4 +227,3 @@ end const default_theme = Theme() - diff --git a/test/tick_color.jl b/test/tick_color.jl new file mode 100644 index 000000000..bc586adc9 --- /dev/null +++ b/test/tick_color.jl @@ -0,0 +1,3 @@ +using Gadfly + +p = plot(x=rand(10), y=rand(10),Theme(panel_stroke=colorant"black", tick_color=colorant"black"))