extend straightline data beyond axes limits

This commit is contained in:
Daniel Schwabeneder 2018-03-21 11:42:01 +01:00
parent 1c0a731ff6
commit 0ace28b784

View File

@ -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)