From 04a435768477d6f6fd7063937299dc94d83ded0d Mon Sep 17 00:00:00 2001 From: Thomas Breloff Date: Fri, 7 Oct 2016 12:14:06 -0400 Subject: [PATCH] fix plotly aspect_ratio and reword arg desc; closes #523 --- src/arg_desc.jl | 2 +- src/backends/plotly.jl | 11 +++++++---- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/arg_desc.jl b/src/arg_desc.jl index 06f525bb..f6365571 100644 --- a/src/arg_desc.jl +++ b/src/arg_desc.jl @@ -85,7 +85,7 @@ const _arg_desc = KW( :grid => "Bool. Show the grid lines?", :annotations => "(x,y,text) tuple(s). Can be a single tuple or a list of them. Text can be String or PlotText (created with `text(args...)`) Add one-off text annotations at the x,y coordinates.", :projection => "Symbol or String. '3d' or 'polar'", -:aspect_ratio => "Symbol (:equal) or Number (width to height ratio of plot area).", +:aspect_ratio => "Symbol (:equal) or Number. Plot area is resized so that 1 y-unit is the same size as `apect_ratio` x-units.", :margin => "Measure (multiply by `mm`, `px`, etc). Base for individual margins... not directly used. Specifies the extra padding around subplots.", :left_margin => "Measure (multiply by `mm`, `px`, etc) or `:match` (matches `:margin`). Specifies the extra padding to the left of the subplot.", :top_margin => "Measure (multiply by `mm`, `px`, etc) or `:match` (matches `:margin`). Specifies the extra padding on the top of the subplot.", diff --git a/src/backends/plotly.jl b/src/backends/plotly.jl index 956cddb9..be88f4a9 100644 --- a/src/backends/plotly.jl +++ b/src/backends/plotly.jl @@ -162,14 +162,17 @@ function plotly_apply_aspect_ratio(sp::Subplot, plotarea, pcts) if aspect_ratio == :equal aspect_ratio = 1.0 end + xmin,xmax = axis_limits(sp[:xaxis]) + ymin,ymax = axis_limits(sp[:yaxis]) + want_ratio = ((xmax-xmin) / (ymax-ymin)) / aspect_ratio parea_ratio = width(plotarea) / height(plotarea) - if aspect_ratio > parea_ratio + if want_ratio > parea_ratio # need to shrink y - ratio = parea_ratio / aspect_ratio + ratio = parea_ratio / want_ratio pcts[2], pcts[4] = shrink_by(pcts[2], pcts[4], ratio) - elseif aspect_ratio < parea_ratio + elseif want_ratio < parea_ratio # need to shrink x - ratio = aspect_ratio / parea_ratio + ratio = want_ratio / parea_ratio pcts[1], pcts[3] = shrink_by(pcts[1], pcts[3], ratio) end pcts