Skip to content

Commit

Permalink
Add rankdir option
Browse files Browse the repository at this point in the history
  • Loading branch information
acalejos committed Dec 26, 2023
1 parent cbdcdda commit 0edbe26
Showing 1 changed file with 23 additions and 15 deletions.
38 changes: 23 additions & 15 deletions lib/exgboost/plotting.ex
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ defmodule EXGBoost.Plotting do
@plotting_params [
rankdir: [
doc: "Determines the direction of the graph.",
type: {:in, [:tb, :lr]},
type: {:in, [:tb, :lr, :bt, :rl]},
default: :tb
],
autosize: [
Expand Down Expand Up @@ -424,10 +424,10 @@ defmodule EXGBoost.Plotting do
%{
"as" =>
case opts[:rankdir] do
:tb ->
vertical when vertical in [:tb, :bt] ->
["x", "y", "depth", "children"]

:lr ->
horizontal when horizontal in [:lr, :rl] ->
["y", "x", "depth", "children"]
end,
"method" => "tidy",
Expand Down Expand Up @@ -548,10 +548,10 @@ defmodule EXGBoost.Plotting do
%{
"as" =>
case opts[:rankdir] do
:tb ->
vertical when vertical in [:tb, :bt] ->
["x", "y", "depth", "children"]

:lr ->
horizontal when horizontal in [:lr, :rl] ->
["y", "x", "depth", "children"]
end,
"method" => "tidy",
Expand All @@ -562,8 +562,16 @@ defmodule EXGBoost.Plotting do
"separation" => %{"signal" => "false"},
"type" => "tree"
},
%{"as" => "y", "expr" => "datum.y+(height/10)", "type" => "formula"},
%{"as" => "x", "expr" => "datum.x+(width/2)", "type" => "formula"},
%{
"as" => "y",
"expr" => "#{if opts[:rankdir] == :bt, do: -1, else: 1}*(datum.y+(height/10))",
"type" => "formula"
},
%{
"as" => "x",
"expr" => "#{if opts[:rankdir] == :rl, do: -1, else: 1}*(datum.x+(width/2))",
"type" => "formula"
},
%{"as" => "xscaled", "expr" => "scale('xscale',datum.x)", "type" => "formula"},
%{"as" => "parent", "expr" => "datum.parentid", "type" => "formula"}
]
Expand Down Expand Up @@ -639,40 +647,40 @@ defmodule EXGBoost.Plotting do
"sourceX" => %{
"expr" =>
case opts[:rankdir] do
:tb ->
vertical when vertical in [:tb, :bt] ->
"scale('xscale', datum.source.x)"

:lr ->
horizontal when horizontal in [:lr, :rl] ->
"scale('xscale', datum.source.x) + scaledNodeWidth/2"
end
},
"sourceY" => %{
"expr" =>
case opts[:rankdir] do
:tb ->
vertical when vertical in [:tb, :bt] ->
"scale('yscale', datum.source.y)"

:lr ->
horizontal when horizontal in [:lr, :rl] ->
"scale('yscale', datum.source.y) - scaledNodeHeight/2"
end
},
"targetX" => %{
"expr" =>
case opts[:rankdir] do
:tb ->
vertical when vertical in [:tb, :bt] ->
"scale('xscale', datum.target.x)"

:lr ->
horizontal when horizontal in [:lr, :rl] ->
"scale('xscale', datum.target.x) - scaledNodeWidth/2"
end
},
"targetY" => %{
"expr" =>
case opts[:rankdir] do
:tb ->
vertical when vertical in [:tb, :bt] ->
"scale('yscale', datum.target.y) - scaledNodeHeight"

:lr ->
horizontal when horizontal in [:lr, :rl] ->
"scale('yscale', datum.target.y) - scaledNodeHeight/2"
end
},
Expand Down

0 comments on commit 0edbe26

Please sign in to comment.