-
Notifications
You must be signed in to change notification settings - Fork 55
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: allow LinePlot to be drawn in steps #99
base: master
Are you sure you want to change the base?
Changes from 4 commits
b4c2705
b62c8e0
f5a781d
9a75931
a53f01f
1eb2156
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -69,10 +69,10 @@ defmodule Contex.SVG do | |
] | ||
end | ||
|
||
def line(points, smoothed, opts \\ []) do | ||
def line(points, plot_style, opts \\ []) do | ||
attrs = opts_to_attrs(opts) | ||
|
||
path = path(points, smoothed) | ||
path = path(points, plot_style) | ||
|
||
[ | ||
"<path d=\"", | ||
|
@@ -85,7 +85,11 @@ defmodule Contex.SVG do | |
|
||
defp path([], _), do: "" | ||
|
||
defp path(points, false) do | ||
defp path(points, nil), do: path(points, :smooth) | ||
defp path(points, true), do: path(points, IO.inspect(:smooth)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would be good to remove the calls to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Removed the whole distinction on the function level and moved the mapping to the calling function, as you suggested above. |
||
defp path(points, false), do: path(points, IO.inspect(:direct)) | ||
|
||
defp path(points, :direct) do | ||
Enum.reduce(points, :first, fn {x, y}, acc -> | ||
coord = ~s|#{x} #{y}| | ||
|
||
|
@@ -94,9 +98,28 @@ defmodule Contex.SVG do | |
_ -> [acc, [" L ", coord]] | ||
end | ||
end) | ||
|> IO.inspect() | ||
end | ||
|
||
defp path(points, :step) do | ||
Enum.reduce(points, :first, fn {x, y}, acc -> | ||
coord = ~s|#{x} #{y}| | ||
|
||
case acc do | ||
:first -> | ||
["M ", coord] | ||
|
||
_ -> | ||
previous_coord = acc |> List.last() | ||
previous_y = previous_coord |> String.split(" ") |> List.last() | ||
new_x = x | ||
acc ++ [" L ", ~s|#{new_x} #{previous_y}|, " L ", coord] | ||
end | ||
end) | ||
|> IO.inspect() | ||
end | ||
|
||
defp path(points, true) do | ||
defp path(points, :smooth) do | ||
# Use Catmull-Rom curve - see http://schepers.cc/getting-to-the-point | ||
# First point stays as-is. Subsequent points are draw using SVG cubic-spline | ||
# where control points are calculated as follows: | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be:
(i.e.
:smoothed
atom set)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah - I see what you've done - the true/false is handled in the path logic. I think it's better to definitively set the plot_style here for a couple of reasons:
so something like:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Adjusted to