Current section

Files

Jump to
matplotex lib matplotex element rad_legend.ex
Raw

lib/matplotex/element/rad_legend.ex

defmodule Matplotex.Element.RadLegend do
@moduledoc false
alias Matplotex.Element.Label
alias Matplotex.Element
alias Matplotex.Element.Rect
use Element
@stroke_width 1
@stroke "rgba(0,0,0,0)"
@legend_size 20 / 96
@label_type "legend.label"
defstruct [
:type,
:x,
:y,
:color,
:label,
width: @legend_size,
height: @legend_size,
label_margin: @legend_size,
stroke: @stroke,
stroke_width: @stroke_width
]
@impl Element
def assemble(legend) do
"""
#{Rect.assemble(legend)}
#{Element.assemble(legend.label)}
"""
end
def with_label(
%__MODULE__{
label: text,
x: x,
y: y,
width: width,
height: height
} = legend,
legend_font
) do
%{
legend
| label:
%Label{
x: x + width,
y: y + height / 2,
text: text,
type: @label_type
}
|> Label.cast_label(legend_font)
}
end
end