diff --git a/src/args.jl b/src/args.jl index 0f2b3c61..b79b5ea8 100644 --- a/src/args.jl +++ b/src/args.jl @@ -193,9 +193,6 @@ const _plot_defaults = KW( :show => false, :layout => 1, :link => :none, - # :linkx => false, - # :linky => false, - # :linkfunc => nothing, :overwrite_figure => true, :html_output_format => :auto, ) diff --git a/src/axes.jl b/src/axes.jl index 814f8b10..72b5067e 100644 --- a/src/axes.jl +++ b/src/axes.jl @@ -161,8 +161,9 @@ function expand_extrema!(sp::Subplot, d::KW) if fr == nothing && d[:seriestype] == :bar fr = 0.0 end - expand_extrema!(sp.attr[vert ? :yaxis : :xaxis], fr) - # @show d[:fillrange] d[:bar_width] + if fr != nothing + expand_extrema!(sp.attr[vert ? :yaxis : :xaxis], fr) + end # expand for bar_width if d[:seriestype] == :bar diff --git a/src/backends/plotly.jl b/src/backends/plotly.jl index 8687e642..3761fb30 100644 --- a/src/backends/plotly.jl +++ b/src/backends/plotly.jl @@ -82,71 +82,6 @@ function _initialize_backend(::PlotlyBackend; kw...) # TODO: other initialization end -# --------------------------------------------------------------------------- - -# function _create_plot(pkg::PlotlyBackend, d::KW) -# # TODO: create the window/canvas/context that is the plot within the backend (call it `o`) -# # TODO: initialize the plot... title, xlabel, bgcolor, etc -# Plot(nothing, pkg, 0, d, KW[]) -# end - - -# function _series_added(::PlotlyBackend, plt::Plot, d::KW) -# # TODO: add one series to the underlying package -# push!(plt.seriesargs, d) -# plt -# end - -# function _add_annotations{X,Y,V}(plt::Plot{PlotlyBackend}, anns::AVec{@compat(Tuple{X,Y,V})}) -# # set or add to the annotation_list -# if haskey(plt.attr, :annotation_list) -# append!(plt.attr[:annotation_list], anns) -# else -# plt.attr[:annotation_list] = anns -# end -# end - -# ---------------------------------------------------------------- - -# function _before_update_plot(plt::Plot{PlotlyBackend}) -# end -# -# # TODO: override this to update plot items (title, xlabel, etc) after creation -# function _update_plot_object(plt::Plot{PlotlyBackend}, d::KW) -# end - -# function _update_plot_pos_size(plt::Plot{PlotlyBackend}, d::KW) -# end - -# ---------------------------------------------------------------- - -# accessors for x/y data - -# function getxy(plt::Plot{PlotlyBackend}, i::Int) -# d = plt.seriesargs[i] -# d[:x], d[:y] -# end -# -# function setxy!{X,Y}(plt::Plot{PlotlyBackend}, xy::Tuple{X,Y}, i::Integer) -# d = plt.seriesargs[i] -# d[:x], d[:y] = xy -# plt -# end - -# ---------------------------------------------------------------- - -# function _create_subplot(subplt::Subplot{PlotlyBackend}, 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{PlotlyBackend}, isx::Bool) -# # TODO: call expand limits for each plot data -# end -# -# function _remove_axis(plt::Plot{PlotlyBackend}, isx::Bool) -# # TODO: if plot is inner subplot, might need to remove ticks or axis labels -# end # ---------------------------------------------------------------- @@ -214,30 +149,11 @@ use_axis_field(ticks) = !(ticks in (nothing, :none)) # this method gets the start/end in percentage of the canvas for this axis direction function plotly_domain(sp::Subplot, letter) figw, figh = sp.plt.attr[:size] - # @show letter,figw,figh sp.plotarea pcts = bbox_to_pcts(sp.plotarea, figw*px, figh*px) - # @show pcts i1,i2 = (letter == :x ? (1,3) : (2,4)) - # @show i1,i2 [pcts[i1], pcts[i1]+pcts[i2]] end -# # TODO: this should actually take into account labels, font sizes, etc -# # sets (left, top, right, bottom) -# function plotly_minpad(sp::Subplot) -# (12mm, 2mm, 2mm, 8mm) -# end -# -# function _update_min_padding!(sp::Subplot{PlotlyBackend}) -# sp.minpad = plotly_minpad(sp) -# end - -# tickssym(letter) = Symbol(letter * "ticks") -# limssym(letter) = Symbol(letter * "lims") -# flipsym(letter) = Symbol(letter * "flip") -# scalesym(letter) = Symbol(letter * "scale") -# labelsym(letter) = Symbol(letter * "label") -# rotationsym(letter) = Symbol(letter * "rotation") function plotly_axis(axis::Axis, sp::Subplot) letter = axis[:letter] @@ -493,12 +409,6 @@ function plotly_series(plt::Plot, series::Series) elseif st == :pie d_out[:type] = "pie" d_out[:labels] = pie_labels(sp, series) - # d_out[:labels] = if haskey(d,:x_discrete_indices) - # dvals = sp.attr[:xaxis].d[:discrete_values] - # [dvals[idx] for idx in d[:x_discrete_indices]] - # else - # d[:x] - # end d_out[:values] = y d_out[:hoverinfo] = "label+percent+name" @@ -604,25 +514,16 @@ end # ---------------------------------------------------------------- -# # compute layout bboxes -# function plotly_finalize(plt::Plot) -# w, h = plt.attr[:size] -# plt.layout.bbox = BoundingBox(0mm, 0mm, w*px, h*px) -# update_child_bboxes!(plt.layout) -# end function _writemime(io::IO, ::MIME"image/png", plt::Plot{PlotlyBackend}) - # plotly_finalize(plt) writemime_png_from_html(io, plt) end function _writemime(io::IO, ::MIME"text/html", plt::Plot{PlotlyBackend}) - # plotly_finalize(plt) write(io, html_head(plt) * html_body(plt)) end # function Base.display(::PlotsDisplay, plt::Plot{PlotlyBackend}) function _display(plt::Plot{PlotlyBackend}) - # plotly_finalize(plt) standalone_html_window(plt) end diff --git a/src/backends/pyplot.jl b/src/backends/pyplot.jl index 617b2706..05cc15d6 100644 --- a/src/backends/pyplot.jl +++ b/src/backends/pyplot.jl @@ -1025,7 +1025,7 @@ function _before_layout_calcs(plt::Plot{PyPlotBackend}) ax[field][:set_text](attr[:title]) ax[field][:set_fontsize](attr[:titlefont].pointsize) ax[field][:set_color](getPyPlotColor(attr[:foreground_color_title])) - ax[:set_title](attr[:title], loc = loc) + # ax[:set_title](attr[:title], loc = loc) end # axis attributes diff --git a/src/plot.jl b/src/plot.jl index 88a16bd3..d36c79be 100644 --- a/src/plot.jl +++ b/src/plot.jl @@ -43,26 +43,13 @@ When you pass in matrices, it splits by columns. See the documentation for more # this creates a new plot with args/kw and sets it to be the current plot function plot(args...; kw...) - # pkg = backend() d = KW(kw) preprocessArgs!(d) - # create an empty Plot, update the args using the inputs, then pass it - # to the backend to finish backend-specific initialization + # create an empty Plot then process plt = Plot() - # _update_plot_args(plt, d) - # plt.o = _create_backend_figure(plt) - # - # # create the layout and subplots from the inputs - # plt.layout, plt.subplots, plt.spmap = build_layout(plt.attr) - # for (idx,sp) in enumerate(plt.subplots) - # sp.plt = plt - # sp.attr[:subplot_index] = idx - # _update_subplot_args(plt, sp, copy(d), idx) - # end - - # now update the plot - _plot!(plt, d, args...) + plt.user_attr = d + _plot!(plt, args...) end # build a new plot from existing plots @@ -88,6 +75,9 @@ function plot(plt1::Plot, plts_tail::Plot...; kw...) # note: all subplots and series "belong" to this new plot... plt = Plot() + # TODO: build the user_attr dict by creating "Any matrices" for the args of each subplot + + # TODO: replace this with proper processing from a merged user_attr KW # update plot args, first with existing plots, then override with d for p in plts _update_plot_args(plt, p.attr) @@ -137,7 +127,8 @@ end function plot!(plt::Plot, args...; kw...) d = KW(kw) preprocessArgs!(d) - _plot!(plt, d, args...) + merge!(plt.user_attr, d) + _plot!(plt, args...) end function strip_first_letter(s::Symbol) @@ -173,21 +164,6 @@ function _apply_series_recipe(plt::Plot, d::KW) # adjust extrema and discrete info if !(st in (:image, :histogram, :histogram2d)) expand_extrema!(sp, d) - # for letter in (:x, :y, :z) - # data = d[letter] - # axis = sp.attr[Symbol(letter, "axis")] - # if eltype(data) <: Number - # expand_extrema!(axis, data) - # elseif isa(data, Surface) && eltype(data.surf) <: Number - # expand_extrema!(axis, data) - # elseif data != nothing - # # TODO: need more here... gotta track the discrete reference value - # # as well as any coord offset (think of boxplot shape coords... they all - # # correspond to the same x-value) - # # @show letter,eltype(data),typeof(data) - # d[letter], d[Symbol(letter,"_discrete_indices")] = discrete_value!(axis, data) - # end - # end end @@ -197,6 +173,7 @@ function _apply_series_recipe(plt::Plot, d::KW) series = Series(d) push!(plt.series_list, series) # @show series + _series_added(plt, series) else @@ -224,15 +201,8 @@ end # this is the core plotting function. recursively apply recipes to build # a list of series KW dicts. # note: at entry, we only have those preprocessed args which were passed in... no default values yet -function _plot!(plt::Plot, d::KW, args...) - # # just in case the backend needs to set up the plot (make it current or something) - # _prepare_plot_object(plt) - # - # # first apply any args for the subplots - # for (idx,sp) in enumerate(plt.subplots) - # _update_subplot_args(plt, sp, d, idx) - # end - +function _plot!(plt::Plot, args...) + d = plt.user_attr d[:plot_object] = plt # the grouping mechanism is a recipe on a GroupBy object @@ -329,7 +299,6 @@ function _plot!(plt::Plot, d::KW, args...) for (idx,sp) in enumerate(plt.subplots) sp.plt = plt sp.attr[:subplot_index] = idx - # _update_subplot_args(plt, sp, copy(d), idx) end plt.init = true @@ -340,6 +309,7 @@ function _plot!(plt::Plot, d::KW, args...) # first apply any args for the subplots for (idx,sp) in enumerate(plt.subplots) + DD(d,"$idx") _update_subplot_args(plt, sp, d, idx) end diff --git a/src/types.jl b/src/types.jl index 8021f299..d475ecaf 100644 --- a/src/types.jl +++ b/src/types.jl @@ -65,6 +65,7 @@ type Plot{T<:AbstractBackend} <: AbstractPlot{T} backend::T # the backend type n::Int # number of series attr::KW # arguments for the whole plot + user_attr::KW # raw arg inputs (after aliases). these are used as the input dict in `_plot!` series_list::Vector{Series} # arguments for each series o # the backend's plot object subplots::Vector{Subplot} @@ -74,7 +75,7 @@ type Plot{T<:AbstractBackend} <: AbstractPlot{T} end function Plot() - Plot(backend(), 0, KW(), Series[], nothing, + Plot(backend(), 0, KW(), KW(), Series[], nothing, Subplot[], SubplotMap(), EmptyLayout(), false) end