Added support for pie charts
This commit is contained in:
parent
9761ede5c4
commit
1439a7e289
@ -1,7 +1,6 @@
|
|||||||
|
|
||||||
# https://github.com/jheinen/GR.jl
|
# https://github.com/jheinen/GR.jl
|
||||||
|
|
||||||
|
|
||||||
function _initialize_backend(::GRPackage; kw...)
|
function _initialize_backend(::GRPackage; kw...)
|
||||||
@eval begin
|
@eval begin
|
||||||
import GR
|
import GR
|
||||||
@ -9,7 +8,6 @@ function _initialize_backend(::GRPackage; kw...)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
const gr_linetype = Dict(
|
const gr_linetype = Dict(
|
||||||
:auto => 1, :solid => 1, :dash => 2, :dot => 3, :dashdot => 4,
|
:auto => 1, :solid => 1, :dash => 2, :dot => 3, :dashdot => 4,
|
||||||
:dashdotdot => -1 )
|
:dashdotdot => -1 )
|
||||||
@ -18,7 +16,8 @@ const gr_markertype = Dict(
|
|||||||
:auto => 1, :none => -1, :ellipse => -1, :rect => -7, :diamond => -13,
|
:auto => 1, :none => -1, :ellipse => -1, :rect => -7, :diamond => -13,
|
||||||
:utriangle => -3, :dtriangle => -5, :pentagon => -21, :hexagon => -22,
|
:utriangle => -3, :dtriangle => -5, :pentagon => -21, :hexagon => -22,
|
||||||
:heptagon => -23, :octagon => -24, :cross => 2, :xcross => 5,
|
:heptagon => -23, :octagon => -24, :cross => 2, :xcross => 5,
|
||||||
:star4 => -25, :star5 => -26, :star6 => -27, :star7 => -28, :star8 => -29 )
|
:star4 => -25, :star5 => -26, :star6 => -27, :star7 => -28, :star8 => -29,
|
||||||
|
:vline => -30, :hline => -31 )
|
||||||
|
|
||||||
const gr_halign = Dict(:left => 1, :hcenter => 2, :right => 3)
|
const gr_halign = Dict(:left => 1, :hcenter => 2, :right => 3)
|
||||||
const gr_valign = Dict(:top => 1, :vcenter => 3, :bottom => 5)
|
const gr_valign = Dict(:top => 1, :vcenter => 3, :bottom => 5)
|
||||||
@ -122,6 +121,10 @@ function gr_display(plt::Plot{GRPackage}, clear=true, update=true,
|
|||||||
end
|
end
|
||||||
cmap = true
|
cmap = true
|
||||||
x, y, H = Base.hist2d(E, xbins, ybins)
|
x, y, H = Base.hist2d(E, xbins, ybins)
|
||||||
|
elseif p[:linetype] == :pie
|
||||||
|
axes_2d = false
|
||||||
|
xmin, xmax, ymin, ymax = 0, 1, 0, 1
|
||||||
|
x, y = p[:x], p[:y]
|
||||||
else
|
else
|
||||||
if p[:linetype] in [:contour, :surface]
|
if p[:linetype] in [:contour, :surface]
|
||||||
cmap = true
|
cmap = true
|
||||||
@ -131,16 +134,18 @@ function gr_display(plt::Plot{GRPackage}, clear=true, update=true,
|
|||||||
end
|
end
|
||||||
x, y = p[:x], p[:y]
|
x, y = p[:x], p[:y]
|
||||||
end
|
end
|
||||||
xmin = min(minimum(x), xmin)
|
if p[:linetype] != :pie
|
||||||
xmax = max(maximum(x), xmax)
|
xmin = min(minimum(x), xmin)
|
||||||
if p[:linetype] == :ohlc
|
xmax = max(maximum(x), xmax)
|
||||||
for val in y
|
if p[:linetype] == :ohlc
|
||||||
ymin = min(val.open, val.high, val.low, val.close, ymin)
|
for val in y
|
||||||
ymax = max(val.open, val.high, val.low, val.close, ymax)
|
ymin = min(val.open, val.high, val.low, val.close, ymin)
|
||||||
|
ymax = max(val.open, val.high, val.low, val.close, ymax)
|
||||||
|
end
|
||||||
|
else
|
||||||
|
ymin = min(minimum(y), ymin)
|
||||||
|
ymax = max(maximum(y), ymax)
|
||||||
end
|
end
|
||||||
else
|
|
||||||
ymin = min(minimum(y), ymin)
|
|
||||||
ymax = max(maximum(y), ymax)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -197,13 +202,14 @@ function gr_display(plt::Plot{GRPackage}, clear=true, update=true,
|
|||||||
GR.setwindow(xmin, xmax, ymin, ymax)
|
GR.setwindow(xmin, xmax, ymin, ymax)
|
||||||
GR.setscale(scale)
|
GR.setscale(scale)
|
||||||
|
|
||||||
|
diag = sqrt((viewport[2] - viewport[1])^2 + (viewport[4] - viewport[3])^2)
|
||||||
|
charheight = max(0.018 * diag, 0.01)
|
||||||
|
GR.setcharheight(charheight)
|
||||||
|
GR.settextcolorind(fg)
|
||||||
|
|
||||||
if axes_2d
|
if axes_2d
|
||||||
diag = sqrt((viewport[2] - viewport[1])^2 + (viewport[4] - viewport[3])^2)
|
|
||||||
GR.setlinewidth(1)
|
GR.setlinewidth(1)
|
||||||
GR.setlinecolorind(fg)
|
GR.setlinecolorind(fg)
|
||||||
charheight = max(0.018 * diag, 0.01)
|
|
||||||
GR.setcharheight(charheight)
|
|
||||||
GR.settextcolorind(fg)
|
|
||||||
ticksize = 0.0075 * diag
|
ticksize = 0.0075 * diag
|
||||||
if fg == 1
|
if fg == 1
|
||||||
GR.grid(xtick, ytick, 0, 0, majorx, majory)
|
GR.grid(xtick, ytick, 0, 0, majorx, majory)
|
||||||
@ -474,8 +480,33 @@ function gr_display(plt::Plot{GRPackage}, clear=true, update=true,
|
|||||||
GR.polyline([i, i], [y[i].low, y[i].high])
|
GR.polyline([i, i], [y[i].low, y[i].high])
|
||||||
GR.polyline([i, i+ticksize], [y[i].close, y[i].close])
|
GR.polyline([i, i+ticksize], [y[i].close, y[i].close])
|
||||||
end
|
end
|
||||||
elseif p[:linetype] in [:pie]
|
elseif p[:linetype] == :pie
|
||||||
println("TODO: add support for linetype $(p[:linetype])")
|
GR.selntran(0)
|
||||||
|
GR.settextalign(GR.TEXT_HALIGN_CENTER, GR.TEXT_VALIGN_HALF)
|
||||||
|
GR.setfillintstyle(GR.INTSTYLE_SOLID)
|
||||||
|
xmin, xmax, ymin, ymax = viewport
|
||||||
|
ymax -= 0.05 * (xmax - xmin)
|
||||||
|
xcenter = 0.5 * (xmin + xmax)
|
||||||
|
ycenter = 0.5 * (ymin + ymax)
|
||||||
|
if xmax - xmin > ymax - ymin
|
||||||
|
r = 0.5 * (ymax - ymin)
|
||||||
|
xmin, xmax = xcenter - r, xcenter + r
|
||||||
|
else
|
||||||
|
r = 0.5 * (xmax - xmin)
|
||||||
|
ymin, ymax = ycenter - r, ycenter + r
|
||||||
|
end
|
||||||
|
x, y = p[:x], p[:y]
|
||||||
|
total = sum(y)
|
||||||
|
a1 = 0
|
||||||
|
for i in 1:length(y)
|
||||||
|
a2 = round(Int, a1 + (y[i] / total) * 360.0)
|
||||||
|
GR.setfillcolorind(980 + (i-1) % 20)
|
||||||
|
GR.fillarc(xmin, xmax, ymin, ymax, a1, a2)
|
||||||
|
GR.text(xcenter + 0.5 * r * cos(0.5 * (a1 + a2) * pi / 180),
|
||||||
|
ycenter + 0.5 * r * sin(0.5 * (a1 + a2) * pi / 180), string(x[i]))
|
||||||
|
a1 = a2
|
||||||
|
end
|
||||||
|
GR.selntran(1)
|
||||||
end
|
end
|
||||||
GR.restorestate()
|
GR.restorestate()
|
||||||
end
|
end
|
||||||
@ -576,7 +607,6 @@ function gr_display(subplt::Subplot{GRPackage})
|
|||||||
end
|
end
|
||||||
|
|
||||||
function _create_plot(pkg::GRPackage; kw...)
|
function _create_plot(pkg::GRPackage; kw...)
|
||||||
isijulia() && GR.inline("svg")
|
|
||||||
d = Dict(kw)
|
d = Dict(kw)
|
||||||
Plot(nothing, pkg, 0, d, Dict[])
|
Plot(nothing, pkg, 0, d, Dict[])
|
||||||
end
|
end
|
||||||
@ -639,7 +669,6 @@ end
|
|||||||
# ----------------------------------------------------------------
|
# ----------------------------------------------------------------
|
||||||
|
|
||||||
function Base.writemime(io::IO, m::MIME"image/png", plt::PlottingObject{GRPackage})
|
function Base.writemime(io::IO, m::MIME"image/png", plt::PlottingObject{GRPackage})
|
||||||
#isijulia() && return
|
|
||||||
GR.emergencyclosegks()
|
GR.emergencyclosegks()
|
||||||
ENV["GKS_WSTYPE"] = "png"
|
ENV["GKS_WSTYPE"] = "png"
|
||||||
gr_display(plt)
|
gr_display(plt)
|
||||||
@ -648,7 +677,6 @@ function Base.writemime(io::IO, m::MIME"image/png", plt::PlottingObject{GRPackag
|
|||||||
end
|
end
|
||||||
|
|
||||||
function Base.writemime(io::IO, m::MIME"image/svg+xml", plt::PlottingObject{GRPackage})
|
function Base.writemime(io::IO, m::MIME"image/svg+xml", plt::PlottingObject{GRPackage})
|
||||||
isijulia() || return
|
|
||||||
GR.emergencyclosegks()
|
GR.emergencyclosegks()
|
||||||
ENV["GKS_WSTYPE"] = "svg"
|
ENV["GKS_WSTYPE"] = "svg"
|
||||||
gr_display(plt)
|
gr_display(plt)
|
||||||
@ -656,6 +684,22 @@ function Base.writemime(io::IO, m::MIME"image/svg+xml", plt::PlottingObject{GRPa
|
|||||||
write(io, readall("gks.svg"))
|
write(io, readall("gks.svg"))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function Base.writemime(io::IO, m::MIME"application/pdf", plt::PlottingObject{GRPackage})
|
||||||
|
GR.emergencyclosegks()
|
||||||
|
ENV["GKS_WSTYPE"] = "pdf"
|
||||||
|
gr_display(plt)
|
||||||
|
GR.emergencyclosegks()
|
||||||
|
write(io, readall("gks.pdf"))
|
||||||
|
end
|
||||||
|
|
||||||
|
function Base.writemime(io::IO, m::MIME"application/postscript", plt::PlottingObject{GRPackage})
|
||||||
|
GR.emergencyclosegks()
|
||||||
|
ENV["GKS_WSTYPE"] = "ps"
|
||||||
|
gr_display(plt)
|
||||||
|
GR.emergencyclosegks()
|
||||||
|
write(io, readall("gks.ps"))
|
||||||
|
end
|
||||||
|
|
||||||
function Base.display(::PlotsDisplay, plt::Plot{GRPackage})
|
function Base.display(::PlotsDisplay, plt::Plot{GRPackage})
|
||||||
gr_display(plt)
|
gr_display(plt)
|
||||||
end
|
end
|
||||||
|
|||||||
@ -240,11 +240,8 @@ supportedTypes(::GRPackage) = [:none, :line, :path, :steppre, :steppost, :sticks
|
|||||||
:scatter, :heatmap, :hexbin, :hist, :density, :bar,
|
:scatter, :heatmap, :hexbin, :hist, :density, :bar,
|
||||||
:hline, :vline, :contour, :path3d, :scatter3d, :surface,
|
:hline, :vline, :contour, :path3d, :scatter3d, :surface,
|
||||||
:wireframe, :ohlc, :pie]
|
:wireframe, :ohlc, :pie]
|
||||||
supportedStyles(::GRPackage) = [:auto, :solid, :dash, :dot, :dashdot]
|
supportedStyles(::GRPackage) = [:auto, :solid, :dash, :dot, :dashdot, :dashdotdot]
|
||||||
supportedMarkers(::GRPackage) = [:auto, :none, :ellipse, :rect, :diamond, :utriangle,
|
supportedMarkers(::GRPackage) = vcat(_allMarkers, Shape)
|
||||||
:dtriangle, :pentagon, :hexagon, :heptagon,
|
|
||||||
:octagon, :cross, :xcross, :star4, :star5, :star6,
|
|
||||||
:star7, :star8]
|
|
||||||
supportedScales(::GRPackage) = [:identity, :log10]
|
supportedScales(::GRPackage) = [:identity, :log10]
|
||||||
subplotSupported(::GRPackage) = true
|
subplotSupported(::GRPackage) = true
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user