@@ -4,6 +4,8 @@ use plotly::{
4
4
//DashType,
5
5
Font ,
6
6
HoverInfo ,
7
+ //Marker,
8
+ //MarkerSymbol,
7
9
Mode ,
8
10
Side ,
9
11
Title ,
@@ -12,45 +14,69 @@ use plotly::{
12
14
Layout , Plot , Scatter ,
13
15
} ;
14
16
15
- use serde:: Serialize ;
16
-
17
17
mod context;
18
18
pub use context:: PlotContext ;
19
19
20
+ use serde:: Serialize ;
21
+
20
22
use cggtts:: prelude:: Epoch ;
21
23
24
+ /*
25
+ * Builds a default chart, 2D, X = time axis
26
+ */
27
+ pub fn build_chart_epoch_axis < T : Clone + Default + Serialize > (
28
+ name : & str ,
29
+ mode : Mode ,
30
+ epochs : Vec < Epoch > ,
31
+ data_y : Vec < T > ,
32
+ ) -> Box < Scatter < f64 , T > > {
33
+ let txt: Vec < String > = epochs. iter ( ) . map ( |e| e. to_string ( ) ) . collect ( ) ;
34
+ Scatter :: new ( epochs. iter ( ) . map ( |e| e. to_mjd_utc_days ( ) ) . collect ( ) , data_y)
35
+ . mode ( mode)
36
+ //.web_gl_mode(true)
37
+ . name ( name)
38
+ . hover_text_array ( txt)
39
+ . hover_info ( HoverInfo :: All )
40
+ }
41
+
22
42
/*
23
43
* builds a standard 2D plot single Y scale,
24
44
* ready to plot data against time (`Epoch`)
25
45
*/
26
- pub fn build_default_plot ( title : & str , y_title : & str ) -> Plot {
46
+ pub fn build_timedomain_plot ( title : & str , y_title : & str ) -> Plot {
27
47
build_plot (
28
48
title,
29
49
Side :: Top ,
30
50
Font :: default ( ) ,
31
- "Epoch " ,
51
+ "MJD " ,
32
52
y_title,
33
53
( true , true ) , // y=0 lines
34
54
true , // show legend
35
55
true , // autosize
56
+ true , // show tick labels
57
+ 0.25 , // ticks dx
58
+ "{:05}" , // ticks fmt
36
59
)
37
60
}
38
61
39
62
/*
40
63
* build a standard 2D plot dual Y axes,
41
64
* to plot against `Epochs`
42
65
*/
43
- pub fn build_default_2y_plot ( title : & str , y1_title : & str , y2_title : & str ) -> Plot {
66
+ pub fn build_timedomain_2y_plot ( title : & str , y1_title : & str , y2_title : & str ) -> Plot {
44
67
build_plot_2y (
45
68
title,
46
69
Side :: Top ,
47
70
Font :: default ( ) ,
48
- "Epoch " ,
71
+ "MJD " ,
49
72
y1_title,
50
73
y2_title,
51
74
( false , false ) , // y=0 lines
52
75
true , // show legend
53
76
true , // autosize
77
+ true , // show x tick label
78
+ 0.25 , // dx tick
79
+ "{:05}" , // x tick fmt
54
80
)
55
81
}
56
82
@@ -66,14 +92,19 @@ fn build_plot(
66
92
zero_line : ( bool , bool ) , // plots a bold line @ (x=0,y=0)
67
93
show_legend : bool ,
68
94
auto_size : bool ,
95
+ show_xtick_labels : bool ,
96
+ dx_tick : f64 ,
97
+ x_tick_fmt : & str ,
69
98
) -> Plot {
70
99
let layout = Layout :: new ( )
71
100
. title ( Title :: new ( title) . font ( title_font) )
72
101
. x_axis (
73
102
Axis :: new ( )
74
103
. title ( Title :: new ( x_axis_title) . side ( title_side) )
75
104
. zero_line ( zero_line. 0 )
76
- . show_tick_labels ( false ) ,
105
+ . show_tick_labels ( show_xtick_labels)
106
+ . dtick ( dx_tick)
107
+ . tick_format ( x_tick_fmt) ,
77
108
)
78
109
. y_axis (
79
110
Axis :: new ( )
@@ -97,14 +128,19 @@ fn build_plot_2y(
97
128
zero_line : ( bool , bool ) , // plots a bold line @ (x=0,y=0)
98
129
show_legend : bool ,
99
130
auto_size : bool ,
131
+ show_xtick_labels : bool ,
132
+ dx_tick : f64 ,
133
+ xtick_fmt : & str ,
100
134
) -> Plot {
101
135
let layout = Layout :: new ( )
102
136
. title ( Title :: new ( title) . font ( title_font) )
103
137
. x_axis (
104
138
Axis :: new ( )
105
139
. title ( Title :: new ( x_title) . side ( title_side) )
106
140
. zero_line ( zero_line. 0 )
107
- . show_tick_labels ( false ) ,
141
+ . show_tick_labels ( show_xtick_labels)
142
+ . dtick ( dx_tick)
143
+ . tick_format ( xtick_fmt) ,
108
144
)
109
145
. y_axis (
110
146
Axis :: new ( )
@@ -124,21 +160,3 @@ fn build_plot_2y(
124
160
p. set_layout ( layout) ;
125
161
p
126
162
}
127
-
128
- /*
129
- * Builds a default chart, 2D, X = time axis
130
- */
131
- pub fn build_chart_epoch_axis < T : Clone + Default + Serialize > (
132
- name : & str ,
133
- mode : Mode ,
134
- epochs : Vec < Epoch > ,
135
- data_y : Vec < T > ,
136
- ) -> Box < Scatter < f64 , T > > {
137
- let txt: Vec < String > = epochs. iter ( ) . map ( |e| e. to_string ( ) ) . collect ( ) ;
138
- Scatter :: new ( epochs. iter ( ) . map ( |e| e. to_utc_seconds ( ) ) . collect ( ) , data_y)
139
- . mode ( mode)
140
- //.web_gl_mode(true)
141
- . name ( name)
142
- . hover_text_array ( txt)
143
- . hover_info ( HoverInfo :: All )
144
- }
0 commit comments