From 0ace28b784d8f254cd1521f6f7d5910c46428914 Mon Sep 17 00:00:00 2001 From: Daniel Schwabeneder Date: Wed, 21 Mar 2018 11:42:01 +0100 Subject: [PATCH] extend straightline data beyond axes limits --- src/utils.jl | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/utils.jl b/src/utils.jl index 933ea2c6..e8ded4ec 100644 --- a/src/utils.jl +++ b/src/utils.jl @@ -1103,14 +1103,14 @@ function straightline_data(series) end function straightline_data(xl, yl, x, y) - if y[1] == y[2] + x_vals, y_vals = if y[1] == y[2] if x[1] == x[2] error("Two identical points cannot be used to describe a straight line.") else - return [xl[1], xl[2]], [y[1], y[2]] + [xl[1], xl[2]], [y[1], y[2]] end elseif x[1] == x[2] - return [x[1], x[2]], [yl[1], yl[2]] + [x[1], x[2]], [yl[1], yl[2]] else # get a and b from the line y = a * x + b through the points given by # the coordinates x and x @@ -1118,8 +1118,15 @@ function straightline_data(xl, yl, x, y) a = (y[1] - y[2]) / (x[1] - x[2]) # get the data values xdata = [clamp(x[1] + (x[1] - x[2]) * (ylim - y[1]) / (y[1] - y[2]), xl...) for ylim in yl] - return xdata, a .* xdata .+ b + + xdata, a .* xdata .+ b end + # expand the data outside the axis limits, by a certain factor too improve + # plotly(js) and interactive behaviour + factor = 100 + x_vals = x_vals .+ (x_vals[2] - x_vals[1]) .* factor .* [-1, 1] + y_vals = y_vals .+ (y_vals[2] - y_vals[1]) .* factor .* [-1, 1] + return x_vals, y_vals end function shape_data(series)