Skip to content

Commit cedb4ef

Browse files
committed
use mjd as x axis labels, and improve x axis display
Signed-off-by: Guillaume W. Bres <[email protected]>
1 parent 7db3c71 commit cedb4ef

File tree

3 files changed

+70
-38
lines changed

3 files changed

+70
-38
lines changed

cggtts-cli/src/plot/context.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
use super::{build_default_2y_plot, build_default_plot, Plot};
1+
use super::{build_timedomain_2y_plot, build_timedomain_plot, Plot};
2+
23
use plotly::Trace;
34

45
/// Plot Context
@@ -17,12 +18,12 @@ impl PlotContext {
1718
let len = self.plots.len() - 1;
1819
self.plots.get_mut(len)
1920
}*/
20-
pub fn add_cartesian2d_plot(&mut self, title: &str, y_label: &str) {
21-
self.plots.push(build_default_plot(title, y_label));
21+
pub fn add_timedomain_plot(&mut self, title: &str, y_label: &str) {
22+
self.plots.push(build_timedomain_plot(title, y_label));
2223
}
23-
pub fn add_cartesian2d_2y_plot(&mut self, title: &str, y1_label: &str, y2_label: &str) {
24+
pub fn add_timedomain_2y_plot(&mut self, title: &str, y1_label: &str, y2_label: &str) {
2425
self.plots
25-
.push(build_default_2y_plot(title, y1_label, y2_label));
26+
.push(build_timedomain_2y_plot(title, y1_label, y2_label));
2627
}
2728
pub fn add_trace(&mut self, trace: Box<dyn Trace>) {
2829
let len = self.plots.len() - 1;

cggtts-cli/src/plot/mod.rs

Lines changed: 44 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ use plotly::{
44
//DashType,
55
Font,
66
HoverInfo,
7+
//Marker,
8+
//MarkerSymbol,
79
Mode,
810
Side,
911
Title,
@@ -12,45 +14,69 @@ use plotly::{
1214
Layout, Plot, Scatter,
1315
};
1416

15-
use serde::Serialize;
16-
1717
mod context;
1818
pub use context::PlotContext;
1919

20+
use serde::Serialize;
21+
2022
use cggtts::prelude::Epoch;
2123

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+
2242
/*
2343
* builds a standard 2D plot single Y scale,
2444
* ready to plot data against time (`Epoch`)
2545
*/
26-
pub fn build_default_plot(title: &str, y_title: &str) -> Plot {
46+
pub fn build_timedomain_plot(title: &str, y_title: &str) -> Plot {
2747
build_plot(
2848
title,
2949
Side::Top,
3050
Font::default(),
31-
"Epoch",
51+
"MJD",
3252
y_title,
3353
(true, true), // y=0 lines
3454
true, // show legend
3555
true, // autosize
56+
true, // show tick labels
57+
0.25, // ticks dx
58+
"{:05}", // ticks fmt
3659
)
3760
}
3861

3962
/*
4063
* build a standard 2D plot dual Y axes,
4164
* to plot against `Epochs`
4265
*/
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 {
4467
build_plot_2y(
4568
title,
4669
Side::Top,
4770
Font::default(),
48-
"Epoch",
71+
"MJD",
4972
y1_title,
5073
y2_title,
5174
(false, false), // y=0 lines
5275
true, // show legend
5376
true, // autosize
77+
true, // show x tick label
78+
0.25, // dx tick
79+
"{:05}", // x tick fmt
5480
)
5581
}
5682

@@ -66,14 +92,19 @@ fn build_plot(
6692
zero_line: (bool, bool), // plots a bold line @ (x=0,y=0)
6793
show_legend: bool,
6894
auto_size: bool,
95+
show_xtick_labels: bool,
96+
dx_tick: f64,
97+
x_tick_fmt: &str,
6998
) -> Plot {
7099
let layout = Layout::new()
71100
.title(Title::new(title).font(title_font))
72101
.x_axis(
73102
Axis::new()
74103
.title(Title::new(x_axis_title).side(title_side))
75104
.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),
77108
)
78109
.y_axis(
79110
Axis::new()
@@ -97,14 +128,19 @@ fn build_plot_2y(
97128
zero_line: (bool, bool), // plots a bold line @ (x=0,y=0)
98129
show_legend: bool,
99130
auto_size: bool,
131+
show_xtick_labels: bool,
132+
dx_tick: f64,
133+
xtick_fmt: &str,
100134
) -> Plot {
101135
let layout = Layout::new()
102136
.title(Title::new(title).font(title_font))
103137
.x_axis(
104138
Axis::new()
105139
.title(Title::new(x_title).side(title_side))
106140
.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),
108144
)
109145
.y_axis(
110146
Axis::new()
@@ -124,21 +160,3 @@ fn build_plot_2y(
124160
p.set_layout(layout);
125161
p
126162
}
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-
}

cggtts-cli/src/processing.rs

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
1-
use crate::plot::{build_chart_epoch_axis, PlotContext};
21
use cggtts::prelude::{Epoch, CGGTTS};
32
use itertools::Itertools;
43
use plotly::common::Mode;
54
use std::collections::HashMap;
65

6+
use crate::plot::{
7+
//build_timedomain_plot,
8+
build_chart_epoch_axis,
9+
PlotContext,
10+
};
11+
712
pub fn single_clock(cggtts: &CGGTTS, ctx: &mut PlotContext) {
813
let sv: Vec<_> = cggtts.tracks().map(|trk| trk.sv).unique().collect();
914
let codes: Vec<_> = cggtts
@@ -13,7 +18,11 @@ pub fn single_clock(cggtts: &CGGTTS, ctx: &mut PlotContext) {
1318
.collect();
1419

1520
//REFSV/SRSV analysis
16-
ctx.add_cartesian2d_2y_plot(&format!("{} REFSV/SRSV", cggtts.station), "REFSV", "SRSV");
21+
ctx.add_timedomain_2y_plot(
22+
&format!("{} REFSV/SRSV", cggtts.station),
23+
"REFSV [s]",
24+
"SRSV [s/s]",
25+
);
1726
for sv in &sv {
1827
for code in &codes {
1928
let epochs: Vec<_> = cggtts
@@ -63,10 +72,10 @@ pub fn single_clock(cggtts: &CGGTTS, ctx: &mut PlotContext) {
6372
}
6473

6574
//REFSYS/SRSYS analysis
66-
ctx.add_cartesian2d_2y_plot(
75+
ctx.add_timedomain_2y_plot(
6776
&format!("{} REFSYS/SRSYS", cggtts.station),
68-
"REFSYS",
69-
"SRSYS",
77+
"REFSYS [s]",
78+
"SRSYS [s/s]",
7079
);
7180
for sv in &sv {
7281
for code in &codes {
@@ -117,7 +126,11 @@ pub fn single_clock(cggtts: &CGGTTS, ctx: &mut PlotContext) {
117126
}
118127

119128
//TROPO
120-
ctx.add_cartesian2d_2y_plot(&format!("{} MDTR/SMDT", cggtts.station), "MDTR", "SMDT");
129+
ctx.add_timedomain_2y_plot(
130+
&format!("{} MDTR/SMDT", cggtts.station),
131+
"MDTR [s]",
132+
"SMDT [s/s]",
133+
);
121134
for sv in &sv {
122135
for code in &codes {
123136
let epochs: Vec<_> = cggtts
@@ -183,7 +196,7 @@ pub fn clock_comparison(pool: &Vec<CGGTTS>, ctx: &mut PlotContext) {
183196
.collect();
184197

185198
for i in 1..pool.len() {
186-
ctx.add_cartesian2d_plot(
199+
ctx.add_timedomain_plot(
187200
&format!("{}-{}", ref_clock.station, pool[i].station),
188201
"Delta [s]",
189202
);

0 commit comments

Comments
 (0)