shape linetype; supported in gadfly; gadfly cleanup

This commit is contained in:
Thomas Breloff 2016-03-16 13:12:01 -04:00
parent 16799d8b75
commit 7531c48e38
5 changed files with 430 additions and 459 deletions

View File

@ -11,7 +11,7 @@ const _3dTypes = [:path3d, :scatter3d, :surface, :wireframe]
const _allTypes = vcat([ const _allTypes = vcat([
:none, :line, :path, :steppre, :steppost, :sticks, :scatter, :none, :line, :path, :steppre, :steppost, :sticks, :scatter,
:heatmap, :hexbin, :hist, :hist2d, :hist3d, :density, :bar, :hline, :vline, :ohlc, :heatmap, :hexbin, :hist, :hist2d, :hist3d, :density, :bar, :hline, :vline, :ohlc,
:contour, :pie :contour, :pie, :shape
], _3dTypes) ], _3dTypes)
@compat const _typeAliases = Dict( @compat const _typeAliases = Dict(
:n => :none, :n => :none,
@ -35,6 +35,9 @@ const _allTypes = vcat([
:line3d => :path3d, :line3d => :path3d,
:surf => :surface, :surf => :surface,
:wire => :wireframe, :wire => :wireframe,
:shapes => :shape,
:poly => :shape,
:polygon => :shape,
) )
ishistlike(lt::Symbol) = lt in (:hist, :density) ishistlike(lt::Symbol) = lt in (:hist, :density)
@ -515,7 +518,7 @@ function processFillArg(d::Dict, arg)
d[:fillalpha] = arg d[:fillalpha] = arg
elseif !handleColors!(d, arg, :fillcolor) elseif !handleColors!(d, arg, :fillcolor)
d[:fillrange] = arg d[:fillrange] = arg
end end
end end
@ -801,5 +804,3 @@ function getSeriesArgs(pkg::AbstractBackend, plotargs::Dict, kw, commandIndex::I
d d
end end

File diff suppressed because it is too large Load Diff

View File

@ -81,7 +81,7 @@ supportedArgs(::GadflyBackend) = [
supportedAxes(::GadflyBackend) = [:auto, :left] supportedAxes(::GadflyBackend) = [:auto, :left]
supportedTypes(::GadflyBackend) = [:none, :line, :path, :steppre, :steppost, :sticks, supportedTypes(::GadflyBackend) = [:none, :line, :path, :steppre, :steppost, :sticks,
:scatter, :hist2d, :hexbin, :hist, :bar, :scatter, :hist2d, :hexbin, :hist, :bar,
:hline, :vline, :contour] :hline, :vline, :contour, :shape]
supportedStyles(::GadflyBackend) = [:auto, :solid, :dash, :dot, :dashdot, :dashdotdot] supportedStyles(::GadflyBackend) = [:auto, :solid, :dash, :dot, :dashdot, :dashdotdot]
supportedMarkers(::GadflyBackend) = vcat(_allMarkers, Shape) supportedMarkers(::GadflyBackend) = vcat(_allMarkers, Shape)
supportedScales(::GadflyBackend) = [:identity, :ln, :log2, :log10, :asinh, :sqrt] supportedScales(::GadflyBackend) = [:identity, :ln, :log2, :log10, :asinh, :sqrt]
@ -770,4 +770,3 @@ supportedStyles(::PGFPlotsBackend) = [:auto, :solid] #, :dash, :dot, :dashdot, :
supportedMarkers(::PGFPlotsBackend) = [:none, :auto, :ellipse] #, :rect, :diamond, :utriangle, :dtriangle, :cross, :xcross, :star5] #vcat(_allMarkers, Shape) supportedMarkers(::PGFPlotsBackend) = [:none, :auto, :ellipse] #, :rect, :diamond, :utriangle, :dtriangle, :cross, :xcross, :star5] #vcat(_allMarkers, Shape)
supportedScales(::PGFPlotsBackend) = [:identity] #, :log, :log2, :log10, :asinh, :sqrt] supportedScales(::PGFPlotsBackend) = [:identity] #, :log, :log2, :log10, :asinh, :sqrt]
subplotSupported(::PGFPlotsBackend) = false subplotSupported(::PGFPlotsBackend) = false

View File

@ -3,6 +3,9 @@ immutable Shape
vertices::AVec vertices::AVec
end end
get_xs(shape::Shape) = Float64[v[1] for v in shape.vertices]
get_ys(shape::Shape) = Float64[v[2] for v in shape.vertices]
"get an array of tuples of points on a circle with radius `r`" "get an array of tuples of points on a circle with radius `r`"
function partialcircle(start_θ, end_θ, n = 20, r=1) function partialcircle(start_θ, end_θ, n = 20, r=1)
@compat(Tuple{Float64,Float64})[(r*cos(u),r*sin(u)) for u in linspace(start_θ, end_θ, n)] @compat(Tuple{Float64,Float64})[(r*cos(u),r*sin(u)) for u in linspace(start_θ, end_θ, n)]
@ -48,7 +51,7 @@ function makecross(; offset = -0.5, radius = 1.0)
z1 = z2 - π/8 z1 = z2 - π/8
outercircle = partialcircle(z1, z1 + 2π, 9, radius) outercircle = partialcircle(z1, z1 + 2π, 9, radius)
innercircle = partialcircle(z2, z2 + 2π, 5, 0.5radius) innercircle = partialcircle(z2, z2 + 2π, 5, 0.5radius)
Shape(weave(outercircle, innercircle, Shape(weave(outercircle, innercircle,
ordering=Vector[outercircle,innercircle,outercircle])[1:end-2]) ordering=Vector[outercircle,innercircle,outercircle])[1:end-2])
end end
@ -87,7 +90,7 @@ end
"Create a Font from a list of unordered features" "Create a Font from a list of unordered features"
function font(args...) function font(args...)
# defaults # defaults
family = "Helvetica" family = "Helvetica"
pointsize = 14 pointsize = 14
@ -266,7 +269,7 @@ end
BezierCurve, BezierCurve,
curve_points, curve_points,
directed_curve directed_curve
typealias P2 FixedSizeArrays.Vec{2,Float64} typealias P2 FixedSizeArrays.Vec{2,Float64}
typealias P3 FixedSizeArrays.Vec{3,Float64} typealias P3 FixedSizeArrays.Vec{3,Float64}
@ -298,7 +301,7 @@ end
miny, maxy = minimum(yview), maximum(yview) miny, maxy = minimum(yview), maximum(yview)
diffpct = P2(diff[1] / (maxx - minx), diffpct = P2(diff[1] / (maxx - minx),
diff[2] / (maxy - miny)) diff[2] / (maxy - miny))
# these points give the initial/final "rise" # these points give the initial/final "rise"
# vertical_offset = P2(0, (maxy - miny) * max(0.03, min(abs(0.5diffpct[2]), 1.0))) # vertical_offset = P2(0, (maxy - miny) * max(0.03, min(abs(0.5diffpct[2]), 1.0)))
vertical_offset = P2(0, max(0.15, 0.5norm(diff))) vertical_offset = P2(0, max(0.15, 0.5norm(diff)))
@ -319,7 +322,7 @@ end
else else
[] []
end end
BezierCurve([p, upper_control, inside_control_points..., lower_control, q]) BezierCurve([p, upper_control, inside_control_points..., lower_control, q])
end end

View File

@ -444,6 +444,37 @@ function createKWargsList{T<:Real}(plt::AbstractPlot, x::AMat{T}, y::AMat{T}, zm
createKWargsList(plt, Any[x], Any[y]; d...) #kw..., z = surf, linetype = :contour) createKWargsList(plt, Any[x], Any[y]; d...) #kw..., z = surf, linetype = :contour)
end end
# plotting arbitrary shapes/polygons
function createKWargsList(plt::AbstractPlot, shape::Shape; kw...)
x, y = unzip(shape.vertices)
createKWargsList(plt, x, y; linetype = :shape, kw...)
end
function shape_coords(shapes::AVec{Shape})
xs = map(get_xs, shapes)
ys = map(get_ys, shapes)
x, y = unzip(shapes[1].vertices)
for shape in shapes[2:end]
tmpx, tmpy = unzip(shape.vertices)
x = vcat(x, NaN, tmpx)
y = vcat(y, NaN, tmpy)
end
x, y
end
function createKWargsList(plt::AbstractPlot, shapes::AVec{Shape}; kw...)
x, y = shape_coords(shapes)
createKWargsList(plt, x, y; linetype = :shape, kw...)
end
function createKWargsList(plt::AbstractPlot, shapes::AMat{Shape}; kw...)
x, y = [], []
for j in 1:size(shapes, 2)
tmpx, tmpy = shape_coords(vec(shapes[:,j]))
push!(x, tmpx)
push!(y, tmpy)
end
createKWargsList(plt, x, y; linetype = :shape, kw...)
end
function createKWargsList(plt::AbstractPlot, surf::Surface; kw...) function createKWargsList(plt::AbstractPlot, surf::Surface; kw...)
createKWargsList(plt, 1:size(surf.surf,1), 1:size(surf.surf,2), convert(Matrix{Float64}, surf.surf); kw...) createKWargsList(plt, 1:size(surf.surf,1), 1:size(surf.surf,2), convert(Matrix{Float64}, surf.surf); kw...)