Skip to content

Commit 7834887

Browse files
author
Mohammed Sadique
committed
cheat sheet
1 parent b7761aa commit 7834887

2 files changed

Lines changed: 0 additions & 235 deletions

File tree

docs/cheatsheets/cheatsheet1.pdf

313 KB
Binary file not shown.

lib/matplotex/figure/cast.ex

Lines changed: 0 additions & 235 deletions
Original file line numberDiff line numberDiff line change
@@ -15,64 +15,9 @@ defmodule Matplotex.Figure.Cast do
1515
alias Matplotex.Figure.Dataset
1616
@xtick_type "figure.x_tick"
1717
@ytick_type "figure.y_tick"
18-
# @stroke_grid "#F3CC9C"
19-
# @stroke_width_grid 1
2018
@lowest_tick 0
2119
@zero_to_move 0
2220

23-
# def cast_spines(
24-
# %Figure{
25-
# axes:
26-
# %{
27-
# coords: %Coords{
28-
# bottom_left: {blx, bly},
29-
# bottom_right: {brx, bry},
30-
# top_left: {tlx, tly},
31-
# top_right: {trx, yrt}
32-
# },
33-
# element: elements
34-
# } = axes
35-
# } = figure
36-
# ) do
37-
# # Four Line struct representing each corners
38-
# left = %Line{
39-
# x1: blx,
40-
# y1: bly,
41-
# x2: tlx,
42-
# y2: tly,
43-
# type: "spine.left"
44-
# }
45-
46-
# right = %Line{
47-
# x1: brx,
48-
# y1: bry,
49-
# x2: trx,
50-
# y2: yrt,
51-
# type: "spine.right"
52-
# }
53-
54-
# top = %Line{
55-
# x1: tlx,
56-
# y1: tly,
57-
# x2: trx,
58-
# y2: yrt,
59-
# type: "spine.top"
60-
# }
61-
62-
# bottom = %Line{
63-
# x1: blx,
64-
# y1: bly,
65-
# x2: brx,
66-
# y2: bry,
67-
# type: "spine.bottom"
68-
# }
69-
70-
# %Figure{figure | axes: %{axes | element: elements ++ [left, right, top, bottom]}}
71-
# end
72-
73-
# def cast_spines(_figure) do
74-
# raise ArgumentError, message: "Figure does't contain enough data to proceed"
75-
# end
7621

7722
def cast_spines_by_region(
7823
%Figure{
@@ -158,37 +103,6 @@ defmodule Matplotex.Figure.Cast do
158103
%Figure{figure | axes: %{axes | element: element ++ [left, right, top, bottom]}}
159104
end
160105

161-
# def cast_title(
162-
# %Figure{
163-
# axes:
164-
# %{
165-
# region_title: region_title,
166-
# title: title,
167-
# element: elements
168-
# } = axes,
169-
# rc_params: %RcParams{title_font: title_font}
170-
# } = figure
171-
# ) do
172-
# {ttx, tty} = calculate_center(region_title, :x)
173-
174-
# title =
175-
# %Label{
176-
# type: "figure.title",
177-
# x: ttx,
178-
# y: tty,
179-
# text: title
180-
# }
181-
# |> merge_structs(title_font)
182-
183-
# %Figure{figure | axes: %{axes | element: elements ++ [title]}}
184-
# end
185-
186-
# def cast_title(%Figure{axes: %{show_title: false}} = figure), do: figure
187-
188-
# def cast_title(_figure) do
189-
# raise ArgumentError, message: "Invalid figure to cast title"
190-
# end
191-
192106
def cast_title_by_region(
193107
%Figure{
194108
axes:
@@ -214,44 +128,13 @@ defmodule Matplotex.Figure.Cast do
214128
%Figure{figure | axes: %{axes | element: elements ++ [title]}}
215129
end
216130

217-
# def cast_label(%Figure{axes: %{label: nil}} = figure), do: figure
218-
219-
# def cast_label(figure) do
220-
# figure
221-
# |> cast_xlabel()
222-
# |> cast_ylabel()
223-
# end
224131

225132
def cast_label_by_region(figure) do
226133
figure
227134
|> cast_xlabel_by_region()
228135
|> cast_ylabel_by_region()
229136
end
230137

231-
# def cast_xlabel(
232-
# %Figure{
233-
# axes: %{label: %{x: x_label}, coords: coords, element: element} = axes,
234-
# rc_params: %RcParams{x_label_font: label_font}
235-
# } = figure
236-
# )
237-
# when not is_nil(x_label) do
238-
# xlabel_coords = Map.get(coords, :x_label)
239-
# {x, y} = calculate_center(coords, xlabel_coords, :x)
240-
241-
# x_label =
242-
# %Label{
243-
# type: "figure.x_label",
244-
# x: x,
245-
# y: y,
246-
# text: x_label
247-
# }
248-
# |> merge_structs(label_font)
249-
250-
# element = element ++ [x_label]
251-
# %Figure{figure | axes: %{axes | element: element}}
252-
# end
253-
254-
# def cast_xlabel(figure), do: figure
255138

256139
def cast_xlabel_by_region(
257140
%Figure{
@@ -278,33 +161,6 @@ defmodule Matplotex.Figure.Cast do
278161

279162
def cast_xlabel_by_region(figure), do: figure
280163

281-
# def cast_ylabel(
282-
# %Figure{
283-
# axes: %{label: %{y: y_label}, coords: coords, element: element} = axes,
284-
# rc_params: %RcParams{y_label_font: label_font}
285-
# } = figure
286-
# )
287-
# when not is_nil(y_label) do
288-
# ylabel_coords = Map.get(coords, :y_label)
289-
290-
# {x, y} = calculate_center(coords, ylabel_coords, :y)
291-
292-
# y_label =
293-
# %Label{
294-
# type: "figure.y_label",
295-
# x: x,
296-
# y: y,
297-
# text: y_label,
298-
# rotate: rotate_label(:y)
299-
# }
300-
# |> merge_structs(label_font)
301-
302-
# element = element ++ [y_label]
303-
# %Figure{figure | axes: %{axes | element: element}}
304-
# end
305-
306-
# def cast_ylabel(figure), do: figure
307-
308164
def cast_ylabel_by_region(
309165
%Figure{
310166
axes: %{label: %{y: y_label}, region_y: region_y, element: element} = axes,
@@ -521,37 +377,6 @@ defmodule Matplotex.Figure.Cast do
521377

522378
def cast_yticks_by_region(figure), do: figure
523379

524-
# def cast_hgrids(%Figure{axes: %{coords: %{hgrids: nil}}} = figure), do: figure
525-
# def cast_hgrids(%Figure{axes: %{show_h_grid: false}} = figure), do: figure
526-
527-
# def cast_hgrids(
528-
# %Figure{
529-
# axes:
530-
# %{
531-
# show_h_grid: true,
532-
# coords: %Coords{hgrids: hgrids, top_right: {rightx, _topy}},
533-
# element: elements
534-
# } = axes
535-
# } = figure
536-
# ) do
537-
# hgrid_elements =
538-
# Enum.map(hgrids, fn {x, y} ->
539-
# %Line{
540-
# x1: x,
541-
# x2: rightx,
542-
# y1: y,
543-
# y2: y,
544-
# type: "figure.h_grid",
545-
# stroke: @stroke_grid,
546-
# stroke_width: @stroke_width_grid
547-
# }
548-
# end)
549-
550-
# elements = elements ++ hgrid_elements
551-
552-
# %Figure{figure | axes: %{axes | element: elements}}
553-
# end
554-
555380
def cast_hgrids_by_region(
556381
%Figure{
557382
axes:
@@ -585,37 +410,6 @@ defmodule Matplotex.Figure.Cast do
585410

586411
def cast_hgrids_by_region(figure), do: figure
587412

588-
# def cast_vgrids(%Figure{axes: %{coords: %{vgrids: nil}}} = figure), do: figure
589-
# def cast_vgrids(%Figure{axes: %{show_v_grid: false}} = figure), do: figure
590-
591-
# def cast_vgrids(
592-
# %Figure{
593-
# axes:
594-
# %{
595-
# show_v_grid: true,
596-
# coords: %Coords{vgrids: vgrids, top_right: {_rightx, topy}},
597-
# element: elements
598-
# } = axes
599-
# } = figure
600-
# ) do
601-
# vgrid_elements =
602-
# Enum.map(vgrids, fn {x, y} ->
603-
# %Line{
604-
# x1: x,
605-
# x2: x,
606-
# y1: y,
607-
# y2: topy,
608-
# type: "figure.v_grid",
609-
# stroke: @stroke_grid,
610-
# stroke_width: @stroke_width_grid
611-
# }
612-
# end)
613-
614-
# elements = elements ++ vgrid_elements
615-
616-
# %Figure{figure | axes: %{axes | element: elements}}
617-
# end
618-
619413
def cast_vgrids_by_region(
620414
%Figure{
621415
axes:
@@ -699,14 +493,6 @@ defmodule Matplotex.Figure.Cast do
699493

700494
def cast_legends(figure), do: figure
701495

702-
# defp calculate_center(%Coords{bottom_left: bottom_left, bottom_right: bottom_right}, {x, y}, :x) do
703-
# {calculate_distance(bottom_left, bottom_right) / 2 + x, y}
704-
# end
705-
706-
# defp calculate_center(%Coords{bottom_left: bottom_left, top_left: top_left}, {x, y}, :y) do
707-
# {x, calculate_distance(bottom_left, top_left) / 2 + y}
708-
# end
709-
710496
defp calculate_center(%Region{x: x, y: y, width: width}, :x) do
711497
{calculate_distance({x, y}, {x + width, y}) / 2 + x, y}
712498
end
@@ -715,12 +501,6 @@ defmodule Matplotex.Figure.Cast do
715501
{x, calculate_distance({x, y}, {x, y + height}) / 2 + y}
716502
end
717503

718-
# defp merge_structs(%module{} = st, sst) do
719-
# sst = Map.from_struct(sst)
720-
# params = st |> Map.from_struct() |> Map.merge(sst)
721-
# struct(module, params)
722-
# end
723-
724504
defp calculate_distance({x1, y1}, {x2, y2}) do
725505
:math.sqrt((x2 - x1) ** 2 + (y2 - y1) ** 2)
726506
end
@@ -758,19 +538,4 @@ defmodule Matplotex.Figure.Cast do
758538
tick >= min && tick <= max
759539
end)
760540
end
761-
762-
# defp append_lim([first | [second | _]] = ticks, {min, max}) do
763-
# with_min =
764-
# if Enum.min(ticks) > min + (second - first) do
765-
# [min] ++ ticks
766-
# else
767-
# ticks
768-
# end
769-
770-
# if Enum.max(with_min) < max - (second - first) do
771-
# with_min ++ [max]
772-
# else
773-
# with_min
774-
# end
775-
# end
776541
end

0 commit comments

Comments
 (0)