@@ -30,7 +30,10 @@ defmodule Matplotex.Figure.Areal do
3030 alias Matplotex.Figure.Dataset
3131
3232 alias Matplotex.Figure.Text
33+ alias Matplotex.Figure.Areal.Region
34+ alias Matplotex.Figure.RcParams
3335 @ default_tick_minimum 0
36+ @ zero_to_move 0
3437 def add_label ( % __MODULE__ { label: nil } = axes , { key , label } , opts ) when is_binary ( label ) do
3538 label =
3639 Map . new ( )
@@ -143,7 +146,7 @@ defmodule Matplotex.Figure.Areal do
143146
144147 def materialized_by_region ( figure ) do
145148 figure
146- |> Lead . set_regions ( )
149+ |> Lead . set_regions_areal ( )
147150 |> Cast . cast_xticks_by_region ( )
148151 |> Cast . cast_yticks_by_region ( )
149152 |> Cast . cast_hgrids_by_region ( )
@@ -211,11 +214,119 @@ defmodule Matplotex.Figure.Areal do
211214 def set_frame_size ( % __MODULE__ { } = axes , frame_size ) do
212215 % __MODULE__ { axes | size: frame_size }
213216 end
217+
218+ def set_region_title (
219+ % Figure {
220+ axes:
221+ % {
222+ title: title ,
223+ region_x: % Region { width: region_x_width } ,
224+ region_y: % Region { height: region_y_height } = region_y ,
225+ region_title: region_title ,
226+ size: { _f_width , _f_height } ,
227+ border: { lx , _by , _ , ty }
228+ } = axes ,
229+ rc_params: % RcParams { title_font: title_font }
230+ } = figure
231+ ) do
232+ space_for_title = Lead . height_required_for_text ( title_font , title )
233+
234+ { x_region_title , y_region_title } =
235+ Algebra . transform_given_point ( @ zero_to_move , - space_for_title , lx , ty )
236+
237+ % Figure {
238+ figure
239+ | axes: % {
240+ axes
241+ | region_title: % Region {
242+ region_title
243+ | x: x_region_title ,
244+ y: y_region_title + space_for_title ,
245+ width: region_x_width ,
246+ height: space_for_title
247+ } ,
248+ region_y: % Region {
249+ region_y
250+ | height: region_y_height - space_for_title
251+ }
252+ }
253+ }
254+ end
255+
256+ def set_region_title ( figure ) , do: figure
257+
258+
259+ def set_region_legend (
260+ % Figure {
261+ axes:
262+ % {
263+ show_legend: true ,
264+ region_x: % Region { width: region_x_width } = region_x ,
265+ region_title: % Region { height: region_title_height } ,
266+ region_legend: region_legend ,
267+ size: { f_width , _f_height } ,
268+ border: { _lx , by , rx , ty }
269+ } = axes ,
270+ rc_params: % RcParams { legend_width: legend_width }
271+ } = figure
272+ ) do
273+ region_legend_width = f_width * legend_width
274+ region_x_width_after_legend = region_x_width - region_legend_width
275+
276+ { x_region_legend , y_region_legend } =
277+ Algebra . transform_given_point ( - region_legend_width , - region_title_height , rx , ty , 0 )
278+
279+ % Figure {
280+ figure
281+ | axes: % {
282+ axes
283+ | region_x: % Region {
284+ region_x
285+ | width: region_x_width_after_legend
286+ } ,
287+ region_legend: % Region {
288+ region_legend
289+ | x: x_region_legend ,
290+ y: y_region_legend ,
291+ width: region_legend_width ,
292+ height: y_region_legend - by
293+ }
294+ }
295+ }
296+ end
297+ def set_region_legend ( figure ) , do: figure
298+ def set_region_content (
299+ % Figure {
300+ axes:
301+ % {
302+ region_x: % Region { x: x_region_x , width: region_x_width } ,
303+ region_y: % Region { y: y_region_y , height: region_y_height } ,
304+ region_content: region_content
305+ } = axes
306+ } = figure
307+ ) do
308+ % Figure {
309+ figure
310+ | axes: % {
311+ axes
312+ | region_content: % Region {
313+ region_content
314+ | x: x_region_x ,
315+ y: y_region_y ,
316+ width: region_x_width ,
317+ height: region_y_height
318+ }
319+ }
320+ }
321+ end
322+ def set_region_content ( figure ) , do: figure
214323 end
215324 end
325+
216326 def transformation ( { _labelx , x } , { _labely , y } , xminmax , yminmax , width , height , transition ) do
217327 transformation ( x , y , xminmax , yminmax , width , height , transition )
218328 end
329+
219330 def transformation ( { _label , x } , y , xminmax , yminmax , width , height , transition ) do
220331 transformation ( x , y , xminmax , yminmax , width , height , transition )
221332 end
@@ -224,7 +335,6 @@ defmodule Matplotex.Figure.Areal do
224335 transformation ( x , y , xminmax , yminmax , width , height , transition )
225336 end
226337
227-
228338 def transformation (
229339 x ,
230340 y ,
@@ -246,11 +356,11 @@ defmodule Matplotex.Figure.Areal do
246356 x
247357 |> Enum . zip ( y )
248358 |> Enum . map ( fn { x , y } ->
249-
250359 x
251360 |> transformation ( y , xlim , ylim , width , height , transition )
252361 |> Algebra . flip_y_coordinate ( )
253362 end )
363+
254364 % Dataset { dataset | transformed: transformed }
255365 end
256366end
0 commit comments