11defmodule Matplotex.Figure.Areal.ScatterTest do
2+ alias Matplotex.Figure.Areal
3+ alias Matplotex.Figure.Dataset
24 alias Matplotex.Figure.Areal.Scatter
35 alias Matplotex.Figure
46 use Matplotex.PlotCase
@@ -12,6 +14,51 @@ defmodule Matplotex.Figure.Areal.ScatterTest do
1214 assert % Figure { axes: % { data: { x , _y } , element: elements } } = Scatter . materialize ( figure )
1315 assert Enum . count ( elements , fn elem -> elem . type == "plot.marker" end ) == length ( x )
1416 end
17+
18+ test "generates elements with various saizes if it passed a size attrbute" do
19+ x = [ 1 , 2 , 3 , 4 , 5 ]
20+ y = [ 10 , 20 , 30 , 40 , 50 ]
21+ sizes = [ 1 , 2 , 3 , 4 , 5 ]
22+
23+ assert % Figure { axes: % { element: elements } } =
24+ x |> Matplotex . scatter ( y , sizes: sizes ) |> Figure . materialize ( )
25+
26+ [ h | tail ] =
27+ elements
28+ |> Enum . filter ( fn x -> x . type == "plot.marker" end )
29+ |> Enum . map ( fn x ->
30+ x . r
31+ end )
32+
33+ refute Enum . all? ( tail , fn x -> x == h end )
34+ end
35+
36+ test "generates elements with various saizes and colors if it passed a size and color attrbute" do
37+ x = [ 1 , 2 , 3 , 4 , 5 ]
38+ y = [ 10 , 20 , 30 , 40 , 50 ]
39+ sizes = [ 1 , 2 , 3 , 4 , 5 ]
40+
41+ assert % Figure { axes: % { element: elements } } =
42+ x |> Matplotex . scatter ( y , sizes: sizes , colors: sizes ) |> Figure . materialize ( )
43+
44+ [ h | tail ] =
45+ elements
46+ |> Enum . filter ( fn x -> x . type == "plot.marker" end )
47+ |> Enum . map ( fn x ->
48+ x . r
49+ end )
50+
51+ refute Enum . all? ( tail , fn x -> x == h end )
52+
53+ [ h | tail ] =
54+ elements
55+ |> Enum . filter ( fn x -> x . type == "plot.marker" end )
56+ |> Enum . map ( fn x ->
57+ x . fill
58+ end )
59+
60+ refute Enum . all? ( tail , fn x -> x == h end )
61+ end
1562 end
1663
1764 describe "generate_ticks/2" do
@@ -24,4 +71,99 @@ defmodule Matplotex.Figure.Areal.ScatterTest do
2471 assert length ( ticks ) == 6
2572 end
2673 end
74+
75+ describe "do_transform" do
76+ test "zips transformed values with sizes if the dataset contains sizes in eaqual size" do
77+ x = [ 1 , 2 , 3 , 4 , 5 ]
78+ y = [ 10 , 20 , 30 , 40 , 50 ]
79+ sizes = [ 1 , 2 , 3 , 4 , 5 ]
80+ width = 2
81+ height = 2
82+
83+ assert % Figure { axes: % { dataset: [ dataset ] } } =
84+ x |> Matplotex . scatter ( y , figsize: { width , height } , sizes: sizes )
85+
86+ assert % Dataset { transformed: transformed } =
87+ Areal . do_transform (
88+ dataset ,
89+ Enum . min_max ( x ) ,
90+ Enum . min_max ( y ) ,
91+ width ,
92+ height ,
93+ { 0 , 0 }
94+ )
95+
96+ assert Enum . all? ( transformed , & match? ( { { _ , _ } , _ } , & 1 ) )
97+ end
98+
99+ test "zips transformed values with marker size if colors exist without sizes" do
100+ x = [ 1 , 2 , 3 , 4 , 5 ]
101+ y = [ 10 , 20 , 30 , 40 , 50 ]
102+ colors = [ 1 , 2 , 3 , 4 , 5 ]
103+ width = 2
104+ height = 2
105+
106+ assert % Figure { axes: % { dataset: [ % Dataset { marker_size: _marker_size } = dataset ] } } =
107+ x |> Matplotex . scatter ( y , figsize: { width , height } , colors: colors )
108+
109+ assert % Dataset { transformed: transformed } =
110+ Areal . do_transform (
111+ dataset ,
112+ Enum . min_max ( x ) ,
113+ Enum . min_max ( y ) ,
114+ width ,
115+ height ,
116+ { 0 , 0 }
117+ )
118+
119+ assert Enum . all? ( transformed , & match? ( { { { _ , _ } , _marker_size } , _ } , & 1 ) )
120+ end
121+
122+ test "zips transformed values with colors if the dataset contanis colors" do
123+ x = [ 1 , 2 , 3 , 4 , 5 ]
124+ y = [ 10 , 20 , 30 , 40 , 50 ]
125+ colors = [ 1 , 2 , 3 , 4 , 5 ]
126+ width = 2
127+ height = 2
128+
129+ assert % Figure { axes: % { dataset: [ dataset ] } } =
130+ x |> Matplotex . scatter ( y , figsize: { width , height } , colors: colors )
131+
132+ assert % Dataset { transformed: transformed } =
133+ Areal . do_transform (
134+ dataset ,
135+ Enum . min_max ( x ) ,
136+ Enum . min_max ( y ) ,
137+ width ,
138+ height ,
139+ { 0 , 0 }
140+ )
141+
142+ assert Enum . all? ( transformed , & match? ( { { { _ , _ } , _ } , _ } , & 1 ) )
143+ end
144+
145+ test "zips both size and colors if the dataset contains size and color" do
146+ x = [ 1 , 2 , 3 , 4 , 5 ]
147+ y = [ 10 , 20 , 30 , 40 , 50 ]
148+ sizes = [ 1 , 2 , 3 , 4 , 5 ]
149+ colors = [ 1 , 2 , 3 , 4 , 5 ]
150+ width = 2
151+ height = 2
152+
153+ assert % Figure { axes: % { dataset: [ dataset ] } } =
154+ x |> Matplotex . scatter ( y , figsize: { width , height } , sizes: sizes , colors: colors )
155+
156+ assert % Dataset { transformed: transformed } =
157+ Areal . do_transform (
158+ dataset ,
159+ Enum . min_max ( x ) ,
160+ Enum . min_max ( y ) ,
161+ width ,
162+ height ,
163+ { 0 , 0 }
164+ )
165+
166+ assert Enum . all? ( transformed , & match? ( { { { _ , _ } , _ } , _ } , & 1 ) )
167+ end
168+ end
27169end
0 commit comments