Skip to content

Commit

Permalink
Print TODO messages for missing features
Browse files Browse the repository at this point in the history
  • Loading branch information
jheinen committed Jan 5, 2016
1 parent b3613b6 commit c5d2181
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 18 deletions.
50 changes: 35 additions & 15 deletions src/backends/gr.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
# https://github.com/jheinen/GR.jl

const gr_linetype = Dict(
:auto => 0, :solid => 1, :dash => 2, :dot => 3, :dashdot => 4,
:auto => 1, :solid => 1, :dash => 2, :dot => 3, :dashdot => 4,
:dashdotdot => -1 )

const gr_markertype = Dict(
:none => 1, :ellipse => -1, :rect => -7, :diamond => -13,
:utriangle => -3, :dtriangle => -5, :pentagon => -14,
:auto => 1, :ellipse => -1, :rect => -7, :diamond => -13,
:utriangle => -3, :dtriangle => -5, :pentagon => -14, :hexagon => 3,
:cross => 2, :xcross => 5, :star5 => 3 )

function gr_display(plt::Plot{GRPackage})
Expand Down Expand Up @@ -37,8 +37,13 @@ function gr_display(plt::Plot{GRPackage})
x, y = p[:x], p[:y]
xmin = min(minimum(x), xmin)
xmax = max(maximum(x), xmax)
ymin = min(minimum(y), ymin)
ymax = max(maximum(y), ymax)
# catch exception for OHLC vectors
try
ymin = min(minimum(y), ymin)
ymax = max(maximum(y), ymax)
catch MethodError
ymin, ymax = 0, 1
end
end

scale = d[:scale]
Expand Down Expand Up @@ -101,16 +106,27 @@ function gr_display(plt::Plot{GRPackage})
GR.savestate()
haskey(d, :linewidth) && GR.setlinewidth(d[:linewidth])
haskey(d, :linestyle) && GR.setlinetype(gr_linetype[d[:linestyle]])
haskey(d, :markersize) && GR.setmarkersize(d[:markersize])
haskey(d, :markershape) && GR.setmarkertype(gr_markertype[d[:markershape]])
if haskey(d, :markersize)
typeof(d[:markersize]) <: Number && GR.setmarkersize(d[:markersize] / 4.0)
else
println("TODO: multiple marker sizes")
end
if haskey(d, :markershape)

This comment has been minimized.

Copy link
@tbreloff

tbreloff Jan 5, 2016

I think haskey(d, :markersize) and haskey(d, :markershape) will always be true... did you mean to check the type here?

This comment has been minimized.

Copy link
@jheinen

jheinen Jan 5, 2016

Author Owner
  • only want to set the markersize, if it is a number (and not a vector)
  • only want to set the markertype, if it is a predefined symbol
typeof(d[:markershape]) == Symbol && GR.setmarkertype(gr_markertype[d[:markershape]])
else
println("TODO: user-defined marker shapes")
end
GR.settextalign(GR.TEXT_HALIGN_LEFT, GR.TEXT_VALIGN_HALF)

GR.uselinespec(" ")
for p in plt.seriesargs
GR.uselinespec("")
if p[:linetype] == :path
GR.polyline(p[:x], p[:y])
elseif p[:linetype] == :scatter
GR.polymarker(p[:x], p[:y])
else
println("TODO: add support for linetype $(p[:linetype])")
end
end

Expand All @@ -131,6 +147,7 @@ function gr_display(plt::Plot{GRPackage})
GR.setlinewidth(1)
GR.drawrect(px - 0.06, px + w + 0.02, py + 0.03, py - 0.03 * length(plt.seriesargs))
haskey(d, :linewidth) && GR.setlinewidth(d[:linewidth])
GR.uselinespec(" ")
for p in plt.seriesargs
GR.uselinespec("")
if p[:linetype] == :path
Expand All @@ -155,6 +172,9 @@ end

function _add_series(::GRPackage, plt::Plot; kw...)
d = Dict(kw)
if d[:markershape] == :none
d[:markershape] = :ellipse
end

This comment has been minimized.

Copy link
@tbreloff

tbreloff Jan 5, 2016

Does this make it impossible to have lines without markers?

This comment has been minimized.

Copy link
@jheinen

jheinen Jan 5, 2016

Author Owner

In GR you can mix lines and symbols - may be I did not fully understand the meaning of markershape.

This comment has been minimized.

Copy link
@tbreloff

tbreloff Jan 5, 2016

Yes, same in Plots, but I'm saying that markershape/markersize will still be in the dictionary even if there's no marker. When in doubt, you can place a call to dumpdict(d, "myprefix", true) inside your method to see what the dictionary looks like. Try this with each of the following calls to see the differences:

plot(rand(10))
plot(rand(10), m = (10, :hex))
scatter(rand(10))
push!(plt.seriesargs, d)
plt
end
Expand Down Expand Up @@ -188,23 +208,22 @@ end

# ----------------------------------------------------------------

# accessors for x/y data

function Base.getindex(plt::Plot{GRPackage}, i::Int)
series = plt.o.lines[i]
series.x, series.y
d = plt.seriesargs[i]
d[:x], d[:y]
end

function Base.setindex!(plt::Plot{GRPackage}, xy::Tuple, i::Integer)
series = plt.o.lines[i]
series.x, series.y = xy
d = plt.seriesargs[i]
d[:x], d[:y] = xy
plt
end

# ----------------------------------------------------------------

function _create_subplot(subplt::Subplot{GRPackage}, isbefore::Bool)
# TODO: build the underlying Subplot object. this is where you might layout the panes within a GUI window, for example
true
end

function _expand_limits(lims, plt::Plot{GRPackage}, isx::Bool)
Expand All @@ -218,7 +237,8 @@ end
# ----------------------------------------------------------------

function Base.writemime(io::IO, ::MIME"image/png", plt::PlottingObject{GRPackage})
# TODO: write a png to io
isijulia() && return
println("TODO: write a png to io")
end

function Base.display(::PlotsDisplay, plt::Plot{GRPackage})
Expand Down
7 changes: 4 additions & 3 deletions src/backends/supported.jl
Original file line number Diff line number Diff line change
Expand Up @@ -234,10 +234,11 @@ supportedArgs(::GRPackage) = [
]
supportedAxes(::GRPackage) = _allAxes
supportedTypes(::GRPackage) = [:none, :line, :path, :steppre, :steppost, :sticks,
:scatter, :heatmap, :hexbin, :hist, :density, :bar,
:hline, :vline, :contour, :path3d, :scatter3d, :surface, :wireframe]
:scatter, :heatmap, :hexbin, :hist, :density, :bar,
:hline, :vline, :contour, :path3d, :scatter3d, :surface,
:wireframe, :ohlc, :pie]
supportedStyles(::GRPackage) = [:auto, :solid, :dash, :dot, :dashdot]
supportedMarkers(::GRPackage) = [:none, :ellipse, :rect, :diamond, :utriangle, :dtriangle, :pentagon, :cross, :xcross, :star5]
supportedMarkers(::GRPackage) = vcat([:none, :ellipse, :rect, :diamond, :utriangle, :dtriangle, :pentagon, :hexagon, :cross, :xcross, :star5], Shape)

This comment has been minimized.

Copy link
@tbreloff

tbreloff Jan 5, 2016

I don't think you're supporting custom shapes yet, right? This change is premature.

This comment has been minimized.

Copy link
@jheinen

jheinen Jan 5, 2016

Author Owner

My plan was to use the GR.drawpath() function to draw custom shapes. Right now, it's still on the TODo list :-(

supportedScales(::GRPackage) = [:identity, :log10]
subplotSupported(::GRPackage) = true

Expand Down

2 comments on commit c5d2181

@tbreloff
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also:

This branch is 1 commit ahead, 6 commits behind tbreloff:dev.

The commit history in Plots is going to get increasingly messy unless you periodically re-branch from the latest tbreloff:dev. Ideally you can get in the habit of rebasing on top of my dev branch to avoid the merging. See: http://docs.julialang.org/en/stable/manual/packages/#squashing-and-rebasing

@jheinen
Copy link
Owner Author

@jheinen jheinen commented on c5d2181 Jan 5, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry - I'll clean up tomorrow ...

Please sign in to comment.