extend straightline data beyond axes limits
This commit is contained in:
parent
1c0a731ff6
commit
0ace28b784
15
src/utils.jl
15
src/utils.jl
@ -1103,14 +1103,14 @@ function straightline_data(series)
|
|||||||
end
|
end
|
||||||
|
|
||||||
function straightline_data(xl, yl, x, y)
|
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]
|
if x[1] == x[2]
|
||||||
error("Two identical points cannot be used to describe a straight line.")
|
error("Two identical points cannot be used to describe a straight line.")
|
||||||
else
|
else
|
||||||
return [xl[1], xl[2]], [y[1], y[2]]
|
[xl[1], xl[2]], [y[1], y[2]]
|
||||||
end
|
end
|
||||||
elseif x[1] == x[2]
|
elseif x[1] == x[2]
|
||||||
return [x[1], x[2]], [yl[1], yl[2]]
|
[x[1], x[2]], [yl[1], yl[2]]
|
||||||
else
|
else
|
||||||
# get a and b from the line y = a * x + b through the points given by
|
# get a and b from the line y = a * x + b through the points given by
|
||||||
# the coordinates x and x
|
# 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])
|
a = (y[1] - y[2]) / (x[1] - x[2])
|
||||||
# get the data values
|
# get the data values
|
||||||
xdata = [clamp(x[1] + (x[1] - x[2]) * (ylim - y[1]) / (y[1] - y[2]), xl...) for ylim in yl]
|
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
|
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
|
end
|
||||||
|
|
||||||
function shape_data(series)
|
function shape_data(series)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user