@@ -28,6 +28,7 @@ defmodule FullstackWeb.Public.TransactionsLive.PublicTransactions do
28
28
socket =
29
29
socket
30
30
|> assign ( :info , Financial . build_transactions_analytics ( params ) )
31
+ |> assign ( :customers , Financial . build_customers_analytics ( params ) )
31
32
|> assign ( :devices , Devices . list_devices ( ) )
32
33
|> assign ( :form , to_form ( params ) )
33
34
|> make_test_data ( )
@@ -70,8 +71,8 @@ defmodule FullstackWeb.Public.TransactionsLive.PublicTransactions do
70
71
end
71
72
72
73
defp make_plot ( data , bar_options , selected_bar ) do
73
- series_cols = [ "Count" , "Amount "]
74
- test_data = Dataset . new ( data , [ "Day " | series_cols ] )
74
+ series_cols = [ "customers " ]
75
+ test_data = Dataset . new ( data , [ "Month " | series_cols ] )
75
76
76
77
options = [
77
78
type: :grouped ,
@@ -80,18 +81,18 @@ defmodule FullstackWeb.Public.TransactionsLive.PublicTransactions do
80
81
show_selected: "no" ,
81
82
show_axislabels: "yes" ,
82
83
# custom_value_scale: "no",
83
- title: "Sales " ,
84
- subtitle: "Month" ,
84
+ title: "New Customers " ,
85
+ subtitle: "Per Month" ,
85
86
colour_scheme: :default ,
86
87
legend_setting: :legend_right ,
87
- mapping: % { category_col: "Day " , value_cols: series_cols } ,
88
+ mapping: % { category_col: "Month " , value_cols: series_cols } ,
88
89
data_labels: true ,
89
90
phx_event_handler: "chart1_bar_clicked" ,
90
91
colour_palette: :default
91
92
]
92
93
93
94
Plot . new ( test_data , BarChart , 500 , 400 , options )
94
- |> Plot . axis_labels ( "Day " , "Count / Amount " )
95
+ |> Plot . axis_labels ( "Month " , "New Customers " )
95
96
|> Plot . to_svg ( )
96
97
end
97
98
@@ -139,6 +140,14 @@ defmodule FullstackWeb.Public.TransactionsLive.PublicTransactions do
139
140
assign ( socket , test_data: result )
140
141
end
141
142
143
+ def format_trx_period ( value ) when value <= 0.0 , do: ""
144
+
145
+ def format_trx_period ( value ) do
146
+ value
147
+ |> round ( )
148
+ |> Timex . month_name ( )
149
+ end
150
+
142
151
def build_pointplot ( dataset , chart_options ) do
143
152
module =
144
153
case chart_options . type do
@@ -154,6 +163,7 @@ defmodule FullstackWeb.Public.TransactionsLive.PublicTransactions do
154
163
colour_palette: :defatult ,
155
164
# custom_x_scale: custom_x_scale,
156
165
# custom_y_scale: custom_y_scale,
166
+ custom_x_formatter: & format_trx_period / 1 ,
157
167
# custom_y_formatter: y_tick_formatter,
158
168
smoothed: chart_options . smoothed == "yes"
159
169
]
@@ -185,17 +195,17 @@ defmodule FullstackWeb.Public.TransactionsLive.PublicTransactions do
185
195
defp make_point_data ( socket ) do
186
196
options =
187
197
% {
188
- series: 4 ,
189
- points: 30 ,
190
- title: nil ,
198
+ series: 2 ,
199
+ points: 12 ,
200
+ title: "Sales / Transactions" ,
191
201
type: "line" ,
192
202
smoothed: "yes" ,
193
203
colour_scheme: "default" ,
194
- legend_setting: "legend_none " ,
195
- custom_x_scale: "no " ,
204
+ legend_setting: "legend_right " ,
205
+ custom_x_scale: "yes " ,
196
206
custom_y_scale: "no" ,
197
207
custom_y_ticks: "no" ,
198
- time_series: "no "
208
+ time_series: "yes "
199
209
}
200
210
201
211
time_series = options . time_series == "yes"
@@ -214,22 +224,22 @@ defmodule FullstackWeb.Public.TransactionsLive.PublicTransactions do
214
224
215
225
series_data =
216
226
for s <- 1 .. series do
217
- val = s * 8.0 + random_within_range ( x * ( 0.1 * s ) , x * ( 0.35 * s ) )
218
- # simulate nils in data
219
- case s == 2 and ( ( i > 3 and i < 6 ) or ( i > 7 and i < 10 ) ) do
220
- true -> nil
221
- _ -> val
222
- end
227
+ s * 8.0 + random_within_range ( x * ( 0.1 * s ) , x * ( 0.35 * s ) )
223
228
end
224
229
225
- [ calc_x ( x , i , time_series ) | series_data ]
230
+ [ i | series_data ]
231
+ ## [calc_x(x, i, time_series) | series_data]
226
232
end
227
233
234
+ dbg ( data )
235
+
228
236
series_cols =
229
237
for s <- 1 .. series do
230
238
"Series #{ s } "
231
239
end
232
240
241
+ dbg ( series_cols )
242
+
233
243
test_data =
234
244
case needs_update do
235
245
true -> Dataset . new ( data , [ "X" | series_cols ] )
0 commit comments