1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
use std::env::args;
extern crate cairo;
extern crate gio;
extern crate gtk;
#[allow(unused_imports)]
use self::gio::prelude::*;
use self::gtk::prelude::*;
use self::gtk::DrawingArea;
use self::cairo::Context;
use self::cairo::enums::{FontSlant, FontWeight};
#[allow(unused_imports)]
use self::cairo::MatrixTrait;
mod chart_prop;
pub use self::chart_prop::ChartProp;
mod axis_prop;
pub use self::axis_prop::AxisProp;
mod chart;
pub use self::chart::Chart;
mod window;
mod axis_drawer;
mod charts;
pub use self::charts::histogram::Histogram;
pub use self::charts::box_whisker_plot::BoxWhiskerPlot;
pub use self::charts::doughnut_chart::DoughnutChart;
pub use self::charts::pie_chart::PieChart;
pub use self::charts::vertical_bar_chart::VerticalBarChart;
pub use self::charts::radar_chart::RadarChart;
pub use self::charts::area_chart::AreaChart;
pub use self::charts::stacked_area_chart::StackedAreaChart;
pub use self::charts::line_chart::LineChart;
pub use self::charts::xy_scatter_plot::XYScatterPlot;
pub use self::charts::bubble_chart::BubbleChart;
pub(in chart_builder) fn get_percentage_in_bounds(value: f64, min: f64, max: f64) -> f64 {
(value - min) / (max - min)
}
pub fn remove_outliers(data: &Vec<f64>) -> Vec<f64> {
let mut sorted_data = data.clone();
sorted_data.sort_unstable_by(|a, b| a.partial_cmp(b).unwrap());
use chart_builder::axis_prop::percentile;
let lq = percentile(&sorted_data, 0.25);
let uq = percentile(&sorted_data, 0.75);
let iqr = uq - lq;
let lower_limit = lq - iqr * 1.5;
let upper_limit = uq + iqr * 1.5;
sorted_data.retain(|&i|i >= lower_limit && i <= upper_limit);
sorted_data
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn get_percentage_in_bounds_tests() {
assert_eq!(get_percentage_in_bounds(0.0, 0.0, 10.0), 0.0);
assert_eq!(get_percentage_in_bounds(10.0, 0.0, 10.0), 1.0);
assert_eq!(get_percentage_in_bounds(5.0, 0.0, 10.0), 0.5);
assert_eq!(get_percentage_in_bounds(2.0, 0.0, 10.0), 0.2);
assert_eq!(get_percentage_in_bounds(7.0, 0.0, 10.0), 0.7);
assert_eq!(get_percentage_in_bounds(-2.0, 0.0, 10.0), -0.2);
assert_eq!(get_percentage_in_bounds(12.0, 0.0, 10.0), 1.2);
}
#[test]
fn remove_outliers_tests() {
let vec_1: Vec<f64> = vec![1.0,2.0,3.0,4.0,5.0,6.0,7.0,8.0];
let result_1 = vec![1.0,2.0,3.0,4.0,5.0,6.0,7.0,8.0];
let outlier_res_1 = remove_outliers(&vec_1);
assert_eq!(outlier_res_1, result_1);
let vec_2: Vec<f64> = vec![1.0,2.0,3.0,4.0,5.0,6.0,7.0,8.0,40.0];
let result_2 = vec![1.0,2.0,3.0,4.0,5.0,6.0,7.0,8.0];
let outlier_res_2 = remove_outliers(&vec_2);
assert_eq!(outlier_res_2, result_2);
let vec_3: Vec<f64> = vec![1.0,2.0,3.0,4.0,5.0,6.0,7.0,8.0,-40.0];
let result_3= vec![1.0,2.0,3.0,4.0,5.0,6.0,7.0,8.0];
let outlier_res_3 = remove_outliers(&vec_3);
assert_eq!(outlier_res_3, result_3);
}
}