Skip to content

Commit a5c5473

Browse files
committed
Add dominant-baseline and text-anchor attrs so that they are customizable
1 parent 38f4b03 commit a5c5473

1 file changed

Lines changed: 12 additions & 8 deletions

File tree

lib/plox/helpers/axis.ex

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ defmodule Plox.Helpers.Axis do
3232
attr :ticks, :integer, doc: "Optional number of labels to render (not to be used with `:step`)"
3333
attr :step, :any, doc: "Optional size of step between label values (not to be used with `:ticks`)"
3434
attr :start, :any, doc: "Optional starting value for labels"
35+
attr :"dominant-baseline", :any, default: nil
36+
attr :"text-anchor", :any, default: "middle"
3537
attr :rest, :global, include: Constants.svg_presentation_attrs()
3638

3739
slot :inner_block, required: true
@@ -42,8 +44,8 @@ defmodule Plox.Helpers.Axis do
4244
:for={value <- scale_values(@axis, Map.take(assigns, [:ticks, :step, :start]))}
4345
x={@axis[value]}
4446
y={below_graph(@axis.dimensions, @gap)}
45-
text-anchor="middle"
46-
dominant-baseline="hanging"
47+
dominant-baseline={assigns[:"dominant-baseline"] || "hanging"}
48+
text-anchor={assigns[:"text-anchor"]}
4749
{@rest}
4850
>
4951
{render_slot(@inner_block, value)}
@@ -57,8 +59,8 @@ defmodule Plox.Helpers.Axis do
5759
:for={value <- scale_values(@axis, Map.take(assigns, [:ticks, :step, :start]))}
5860
x={@axis[value]}
5961
y={above_graph(@axis.dimensions, @gap)}
60-
text-anchor="middle"
61-
dominant-baseline="text-bottom"
62+
dominant-baseline={assigns[:"dominant-baseline"] || "text-bottom"}
63+
text-anchor={assigns[:"text-anchor"]}
6264
{@rest}
6365
>
6466
{render_slot(@inner_block, value)}
@@ -85,6 +87,8 @@ defmodule Plox.Helpers.Axis do
8587
attr :ticks, :integer, doc: "Optional number of labels to render (not to be used with `:step`)"
8688
attr :step, :any, doc: "Optional size of step between label values (not to be used with `:ticks`)"
8789
attr :start, :any, doc: "Optional starting value for labels"
90+
attr :"dominant-baseline", :any, default: "middle"
91+
attr :"text-anchor", :any, default: nil
8892
attr :rest, :global, include: Constants.svg_presentation_attrs()
8993

9094
slot :inner_block, required: true
@@ -95,8 +99,8 @@ defmodule Plox.Helpers.Axis do
9599
:for={value <- scale_values(@axis, Map.take(assigns, [:ticks, :step, :start]))}
96100
x={left_of_graph(@axis.dimensions, @gap)}
97101
y={@axis[value]}
98-
text-anchor="end"
99-
dominant-baseline="middle"
102+
dominant-baseline={assigns[:"dominant-baseline"]}
103+
text-anchor={assigns[:"text-anchor"] || "end"}
100104
{@rest}
101105
>
102106
{render_slot(@inner_block, value)}
@@ -110,8 +114,8 @@ defmodule Plox.Helpers.Axis do
110114
:for={value <- scale_values(@axis, Map.take(assigns, [:ticks, :step, :start]))}
111115
x={right_of_graph(@axis.dimensions, @gap)}
112116
y={@axis[value]}
113-
text-anchor="start"
114-
dominant-baseline="middle"
117+
dominant-baseline={assigns[:"dominant-baseline"]}
118+
text-anchor={assigns[:"text-anchor"] || "start"}
115119
{@rest}
116120
>
117121
{render_slot(@inner_block, value)}

0 commit comments

Comments
 (0)